aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorStefan Richter <stefanr@s5r6.in-berlin.de>2006-09-17 12:17:19 -0400
committerStefan Richter <stefanr@s5r6.in-berlin.de>2006-09-17 12:19:31 -0400
commit9b4f2e9576658c4e52d95dc8d309f51b2e2db096 (patch)
tree7b1902b0f931783fccc6fee45c6f9c16b4fde5ce /drivers
parent3c6c65f5ed5a6d307bd607aecd06d658c0934d88 (diff)
parent803db244b9f71102e366fd689000c1417b9a7508 (diff)
ieee1394: merge from Linus
Conflicts: drivers/ieee1394/hosts.c Patch "lockdep: annotate ieee1394 skb-queue-head locking" was meddling with patch "ieee1394: fix kerneldoc of hpsb_alloc_host". Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/Kconfig16
-rw-r--r--drivers/acpi/Makefile2
-rw-r--r--drivers/acpi/ac.c36
-rw-r--r--drivers/acpi/acpi_memhotplug.c39
-rw-r--r--drivers/acpi/asus_acpi.c335
-rw-r--r--drivers/acpi/battery.c53
-rw-r--r--drivers/acpi/bus.c13
-rw-r--r--drivers/acpi/button.c14
-rw-r--r--drivers/acpi/cm_sbs.c113
-rw-r--r--drivers/acpi/container.c2
-rw-r--r--drivers/acpi/dispatcher/dsinit.c10
-rw-r--r--drivers/acpi/dispatcher/dsmethod.c23
-rw-r--r--drivers/acpi/dispatcher/dswexec.c4
-rw-r--r--drivers/acpi/dock.c14
-rw-r--r--drivers/acpi/ec.c2
-rw-r--r--drivers/acpi/event.c2
-rw-r--r--drivers/acpi/events/evregion.c44
-rw-r--r--drivers/acpi/events/evxface.c44
-rw-r--r--drivers/acpi/events/evxfregn.c13
-rw-r--r--drivers/acpi/executer/exconfig.c1
-rw-r--r--drivers/acpi/executer/exconvrt.c3
-rw-r--r--drivers/acpi/executer/exmutex.c4
-rw-r--r--drivers/acpi/executer/exsystem.c8
-rw-r--r--drivers/acpi/fan.c12
-rw-r--r--drivers/acpi/glue.c8
-rw-r--r--drivers/acpi/hotkey.c291
-rw-r--r--drivers/acpi/i2c_ec.c406
-rw-r--r--drivers/acpi/i2c_ec.h23
-rw-r--r--drivers/acpi/namespace/nsalloc.c13
-rw-r--r--drivers/acpi/namespace/nsxfeval.c2
-rw-r--r--drivers/acpi/numa.c4
-rw-r--r--drivers/acpi/osl.c109
-rw-r--r--drivers/acpi/parser/psutils.c2
-rw-r--r--drivers/acpi/pci_link.c22
-rw-r--r--drivers/acpi/pci_root.c20
-rw-r--r--drivers/acpi/power.c24
-rw-r--r--drivers/acpi/processor_core.c2
-rw-r--r--drivers/acpi/processor_idle.c4
-rw-r--r--drivers/acpi/processor_perflib.c6
-rw-r--r--drivers/acpi/sbs.c1769
-rw-r--r--drivers/acpi/scan.c16
-rw-r--r--drivers/acpi/sleep/proc.c6
-rw-r--r--drivers/acpi/system.c10
-rw-r--r--drivers/acpi/tables/tbget.c12
-rw-r--r--drivers/acpi/tables/tbinstal.c21
-rw-r--r--drivers/acpi/tables/tbrsdt.c27
-rw-r--r--drivers/acpi/tables/tbxface.c32
-rw-r--r--drivers/acpi/thermal.c84
-rw-r--r--drivers/acpi/utilities/utalloc.c6
-rw-r--r--drivers/acpi/utilities/utcache.c2
-rw-r--r--drivers/acpi/utilities/utdebug.c4
-rw-r--r--drivers/acpi/utilities/utdelete.c13
-rw-r--r--drivers/acpi/utilities/utmisc.c25
-rw-r--r--drivers/acpi/utilities/utmutex.c8
-rw-r--r--drivers/acpi/utilities/utstate.c7
-rw-r--r--drivers/acpi/utils.c6
-rw-r--r--drivers/acpi/video.c76
-rw-r--r--drivers/atm/Kconfig2
-rw-r--r--drivers/atm/ambassador.c3
-rw-r--r--drivers/atm/idt77252.c3
-rw-r--r--drivers/base/Kconfig2
-rw-r--r--drivers/base/bus.c5
-rw-r--r--drivers/base/core.c30
-rw-r--r--drivers/base/node.c2
-rw-r--r--drivers/base/topology.c2
-rw-r--r--drivers/block/Kconfig10
-rw-r--r--drivers/block/aoe/aoechr.c2
-rw-r--r--drivers/block/cciss.c96
-rw-r--r--drivers/block/cpqarray.c2
-rw-r--r--drivers/block/floppy.c54
-rw-r--r--drivers/block/nbd.c19
-rw-r--r--drivers/block/pktcdvd.c6
-rw-r--r--drivers/block/rd.c2
-rw-r--r--drivers/block/swim3.c230
-rw-r--r--drivers/bluetooth/bcm203x.c1
-rw-r--r--drivers/bluetooth/bluecard_cs.c1
-rw-r--r--drivers/bluetooth/bt3c_cs.c1
-rw-r--r--drivers/bluetooth/btuart_cs.c1
-rw-r--r--drivers/bluetooth/dtl1_cs.c1
-rw-r--r--drivers/bluetooth/hci_ldisc.c4
-rw-r--r--drivers/bluetooth/hci_usb.c99
-rw-r--r--drivers/bluetooth/hci_usb.h1
-rw-r--r--drivers/bluetooth/hci_vhci.c1
-rw-r--r--drivers/cdrom/cdrom.c2
-rw-r--r--drivers/cdrom/gscd.c2
-rw-r--r--drivers/char/agp/frontend.c2
-rw-r--r--drivers/char/applicom.c2
-rw-r--r--drivers/char/cs5535_gpio.c2
-rw-r--r--drivers/char/drm/radeon_state.c9
-rw-r--r--drivers/char/ds1286.c2
-rw-r--r--drivers/char/ds1302.c2
-rw-r--r--drivers/char/ds1620.c2
-rw-r--r--drivers/char/dsp56k.c2
-rw-r--r--drivers/char/dtlk.c2
-rw-r--r--drivers/char/efirtc.c2
-rw-r--r--drivers/char/ftape/zftape/zftape-init.c2
-rw-r--r--drivers/char/genrtc.c2
-rw-r--r--drivers/char/hpet.c2
-rw-r--r--drivers/char/hvc_console.c1
-rw-r--r--drivers/char/hvsi.c15
-rw-r--r--drivers/char/hw_random/core.c2
-rw-r--r--drivers/char/hw_random/geode-rng.c6
-rw-r--r--drivers/char/hw_random/intel-rng.c2
-rw-r--r--drivers/char/hw_random/omap-rng.c51
-rw-r--r--drivers/char/i8k.c2
-rw-r--r--drivers/char/ip2/ip2main.c9
-rw-r--r--drivers/char/ip27-rtc.c2
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c2
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c1
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c9
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c2
-rw-r--r--drivers/char/istallion.c2
-rw-r--r--drivers/char/ite_gpio.c2
-rw-r--r--drivers/char/keyboard.c139
-rw-r--r--drivers/char/lcd.c2
-rw-r--r--drivers/char/lp.c2
-rw-r--r--drivers/char/mem.c22
-rw-r--r--drivers/char/misc.c4
-rw-r--r--drivers/char/mmtimer.c2
-rw-r--r--drivers/char/moxa.c8
-rw-r--r--drivers/char/mwave/mwavedd.c2
-rw-r--r--drivers/char/nsc_gpio.c6
-rw-r--r--drivers/char/nvram.c2
-rw-r--r--drivers/char/nwbutton.c2
-rw-r--r--drivers/char/nwflash.c2
-rw-r--r--drivers/char/pc8736x_gpio.c58
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c2
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c2
-rw-r--r--drivers/char/pcmcia/synclink_cs.c14
-rw-r--r--drivers/char/ppdev.c2
-rw-r--r--drivers/char/random.c6
-rw-r--r--drivers/char/raw.c6
-rw-r--r--drivers/char/rio/rio_linux.c2
-rw-r--r--drivers/char/rtc.c51
-rw-r--r--drivers/char/scx200_gpio.c72
-rw-r--r--drivers/char/snsc.c9
-rw-r--r--drivers/char/snsc_event.c15
-rw-r--r--drivers/char/sonypi.c2
-rw-r--r--drivers/char/specialix.c6
-rw-r--r--drivers/char/stallion.c2
-rw-r--r--drivers/char/sx.c2
-rw-r--r--drivers/char/synclink.c14
-rw-r--r--drivers/char/synclink_gt.c28
-rw-r--r--drivers/char/synclinkmp.c14
-rw-r--r--drivers/char/sysrq.c5
-rw-r--r--drivers/char/tb0219.c2
-rw-r--r--drivers/char/tipar.c2
-rw-r--r--drivers/char/tlclk.c2
-rw-r--r--drivers/char/toshiba.c2
-rw-r--r--drivers/char/tpm/tpm.c1
-rw-r--r--drivers/char/tpm/tpm_atmel.c2
-rw-r--r--drivers/char/tpm/tpm_infineon.c2
-rw-r--r--drivers/char/tpm/tpm_nsc.c2
-rw-r--r--drivers/char/tpm/tpm_tis.c79
-rw-r--r--drivers/char/tty_io.c818
-rw-r--r--drivers/char/tty_ioctl.c59
-rw-r--r--drivers/char/vc_screen.c2
-rw-r--r--drivers/char/viotape.c2
-rw-r--r--drivers/char/vr41xx_giu.c3
-rw-r--r--drivers/char/vt.c1
-rw-r--r--drivers/char/vt_ioctl.c2
-rw-r--r--drivers/char/watchdog/Kconfig8
-rw-r--r--drivers/char/watchdog/acquirewdt.c2
-rw-r--r--drivers/char/watchdog/advantechwdt.c2
-rw-r--r--drivers/char/watchdog/alim1535_wdt.c2
-rw-r--r--drivers/char/watchdog/alim7101_wdt.c2
-rw-r--r--drivers/char/watchdog/at91_wdt.c2
-rw-r--r--drivers/char/watchdog/booke_wdt.c2
-rw-r--r--drivers/char/watchdog/cpu5wdt.c2
-rw-r--r--drivers/char/watchdog/ep93xx_wdt.c2
-rw-r--r--drivers/char/watchdog/eurotechwdt.c2
-rw-r--r--drivers/char/watchdog/i6300esb.c2
-rw-r--r--drivers/char/watchdog/i8xx_tco.c2
-rw-r--r--drivers/char/watchdog/ib700wdt.c2
-rw-r--r--drivers/char/watchdog/ibmasr.c2
-rw-r--r--drivers/char/watchdog/indydog.c2
-rw-r--r--drivers/char/watchdog/ixp2000_wdt.c2
-rw-r--r--drivers/char/watchdog/ixp4xx_wdt.c2
-rw-r--r--drivers/char/watchdog/machzwd.c2
-rw-r--r--drivers/char/watchdog/mixcomwd.c2
-rw-r--r--drivers/char/watchdog/mpc83xx_wdt.c2
-rw-r--r--drivers/char/watchdog/mpc8xx_wdt.c2
-rw-r--r--drivers/char/watchdog/mpcore_wdt.c2
-rw-r--r--drivers/char/watchdog/mv64x60_wdt.c2
-rw-r--r--drivers/char/watchdog/pcwd.c4
-rw-r--r--drivers/char/watchdog/pcwd_pci.c4
-rw-r--r--drivers/char/watchdog/pcwd_usb.c4
-rw-r--r--drivers/char/watchdog/s3c2410_wdt.c2
-rw-r--r--drivers/char/watchdog/sa1100_wdt.c2
-rw-r--r--drivers/char/watchdog/sbc60xxwdt.c2
-rw-r--r--drivers/char/watchdog/sbc8360.c6
-rw-r--r--drivers/char/watchdog/sbc_epx_c3.c2
-rw-r--r--drivers/char/watchdog/sc1200wdt.c2
-rw-r--r--drivers/char/watchdog/sc520_wdt.c2
-rw-r--r--drivers/char/watchdog/scx200_wdt.c2
-rw-r--r--drivers/char/watchdog/shwdt.c2
-rw-r--r--drivers/char/watchdog/softdog.c2
-rw-r--r--drivers/char/watchdog/w83627hf_wdt.c2
-rw-r--r--drivers/char/watchdog/w83877f_wdt.c2
-rw-r--r--drivers/char/watchdog/w83977f_wdt.c2
-rw-r--r--drivers/char/watchdog/wafer5823wdt.c2
-rw-r--r--drivers/char/watchdog/wdrtas.c4
-rw-r--r--drivers/char/watchdog/wdt.c4
-rw-r--r--drivers/char/watchdog/wdt285.c2
-rw-r--r--drivers/char/watchdog/wdt977.c2
-rw-r--r--drivers/char/watchdog/wdt_pci.c4
-rw-r--r--drivers/connector/cn_proc.c20
-rw-r--r--drivers/cpufreq/cpufreq.c119
-rw-r--r--drivers/cpufreq/cpufreq_conservative.c2
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c266
-rw-r--r--drivers/cpufreq/cpufreq_userspace.c3
-rw-r--r--drivers/crypto/padlock-aes.c9
-rw-r--r--drivers/dma/dmaengine.c20
-rw-r--r--drivers/dma/ioatdma.c10
-rw-r--r--drivers/dma/ioatdma_registers.h2
-rw-r--r--drivers/dma/iovlock.c2
-rw-r--r--drivers/edac/edac_mc.c687
-rw-r--r--drivers/edac/edac_mc.h1
-rw-r--r--drivers/fc4/fc.c4
-rw-r--r--drivers/hwmon/abituguru.c120
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c4
-rw-r--r--drivers/i2c/algos/i2c-algo-ite.c4
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c6
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.c8
-rw-r--r--drivers/i2c/algos/i2c-algo-sibyte.c4
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c17
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.h2
-rw-r--r--drivers/i2c/busses/i2c-powermac.c4
-rw-r--r--drivers/i2c/busses/scx200_acb.c27
-rw-r--r--drivers/i2c/chips/pca9539.c12
-rw-r--r--drivers/i2c/chips/tps65010.c12
-rw-r--r--drivers/i2c/i2c-core.c4
-rw-r--r--drivers/ide/Kconfig15
-rw-r--r--drivers/ide/ide-disk.c2
-rw-r--r--drivers/ide/ide-dma.c2
-rw-r--r--drivers/ide/ide-floppy.c2
-rw-r--r--drivers/ide/ide-io.c8
-rw-r--r--drivers/ide/ide-iops.c2
-rw-r--r--drivers/ide/ide-proc.c2
-rw-r--r--drivers/ide/ide-taskfile.c2
-rw-r--r--drivers/ide/ide.c5
-rw-r--r--drivers/ide/legacy/ide-cs.c81
-rw-r--r--drivers/ide/pci/aec62xx.c12
-rw-r--r--drivers/ide/pci/alim15x3.c2
-rw-r--r--drivers/ide/pci/generic.c38
-rw-r--r--drivers/ide/pci/it821x.c11
-rw-r--r--drivers/ide/pci/serverworks.c10
-rw-r--r--drivers/ide/pci/sgiioc4.c60
-rw-r--r--drivers/ide/pci/siimage.c6
-rw-r--r--drivers/ide/pci/sis5513.c2
-rw-r--r--drivers/ide/pci/via82cxxx.c3
-rw-r--r--drivers/ieee1394/hosts.c10
-rw-r--r--drivers/ieee1394/ohci1394.c4
-rw-r--r--drivers/infiniband/core/addr.c30
-rw-r--r--drivers/infiniband/core/cache.c3
-rw-r--r--drivers/infiniband/core/cm.c25
-rw-r--r--drivers/infiniband/core/cma.c24
-rw-r--r--drivers/infiniband/core/fmr_pool.c8
-rw-r--r--drivers/infiniband/core/mad.c22
-rw-r--r--drivers/infiniband/core/sa_query.c13
-rw-r--r--drivers/infiniband/core/user_mad.c87
-rw-r--r--drivers/infiniband/core/uverbs.h2
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c42
-rw-r--r--drivers/infiniband/core/uverbs_main.c8
-rw-r--r--drivers/infiniband/hw/ipath/ipath_driver.c76
-rw-r--r--drivers/infiniband/hw/ipath/ipath_keys.c15
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs.c5
-rw-r--r--drivers/infiniband/hw/mthca/mthca_allocator.c30
-rw-r--r--drivers/infiniband/hw/mthca/mthca_av.c5
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.c5
-rw-r--r--drivers/infiniband/hw/mthca/mthca_main.c6
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c11
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.h4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c68
-rw-r--r--drivers/infiniband/hw/mthca/mthca_srq.c3
-rw-r--r--drivers/infiniband/ulp/ipoib/Kconfig3
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h1
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c23
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c9
-rw-r--r--drivers/infiniband/ulp/iser/iscsi_iser.c160
-rw-r--r--drivers/infiniband/ulp/iser/iser_verbs.c2
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c36
-rw-r--r--drivers/input/evdev.c10
-rw-r--r--drivers/input/gameport/fm801-gp.c4
-rw-r--r--drivers/input/gameport/gameport.c66
-rw-r--r--drivers/input/input.c57
-rw-r--r--drivers/input/joystick/iforce/iforce-main.c19
-rw-r--r--drivers/input/joystick/spaceball.c2
-rw-r--r--drivers/input/keyboard/atkbd.c103
-rw-r--r--drivers/input/misc/wistron_btns.c4
-rw-r--r--drivers/input/mouse/logips2pp.c3
-rw-r--r--drivers/input/mouse/psmouse-base.c7
-rw-r--r--drivers/input/mouse/trackpoint.c52
-rw-r--r--drivers/input/serio/i8042-sparcio.h2
-rw-r--r--drivers/input/serio/libps2.c7
-rw-r--r--drivers/input/serio/serio.c65
-rw-r--r--drivers/isdn/hardware/eicon/divasync.h1
-rw-r--r--drivers/isdn/hisax/asuscom.c6
-rw-r--r--drivers/isdn/hisax/avm_a1.c2
-rw-r--r--drivers/isdn/hisax/avm_pci.c8
-rw-r--r--drivers/isdn/hisax/bkm_a4t.c4
-rw-r--r--drivers/isdn/hisax/bkm_a8.c16
-rw-r--r--drivers/isdn/hisax/config.c2
-rw-r--r--drivers/isdn/hisax/diva.c14
-rw-r--r--drivers/isdn/hisax/enternow_pci.c4
-rw-r--r--drivers/isdn/hisax/gazel.c8
-rw-r--r--drivers/isdn/hisax/hfc4s8s_l1.c2
-rw-r--r--drivers/isdn/hisax/hfc_2bds0.c4
-rw-r--r--drivers/isdn/hisax/hfc_2bs0.c4
-rw-r--r--drivers/isdn/hisax/hfc_pci.c6
-rw-r--r--drivers/isdn/hisax/hfcscard.c6
-rw-r--r--drivers/isdn/hisax/icc.c8
-rw-r--r--drivers/isdn/hisax/icc.h2
-rw-r--r--drivers/isdn/hisax/ipacx.c18
-rw-r--r--drivers/isdn/hisax/isurf.c4
-rw-r--r--drivers/isdn/hisax/ix1_micro.c6
-rw-r--r--drivers/isdn/hisax/jade.c6
-rw-r--r--drivers/isdn/hisax/mic.c2
-rw-r--r--drivers/isdn/hisax/netjet.c2
-rw-r--r--drivers/isdn/hisax/niccy.c4
-rw-r--r--drivers/isdn/hisax/nj_s.c4
-rw-r--r--drivers/isdn/hisax/nj_u.c4
-rw-r--r--drivers/isdn/hisax/s0box.c2
-rw-r--r--drivers/isdn/hisax/saphir.c2
-rw-r--r--drivers/isdn/hisax/sportster.c4
-rw-r--r--drivers/isdn/hisax/teleint.c2
-rw-r--r--drivers/isdn/hisax/teles0.c2
-rw-r--r--drivers/isdn/hisax/telespci.c4
-rw-r--r--drivers/isdn/hisax/w6692.c10
-rw-r--r--drivers/isdn/i4l/isdn_common.c12
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c2
-rw-r--r--drivers/leds/Kconfig7
-rw-r--r--drivers/leds/Makefile1
-rw-r--r--drivers/leds/leds-net48xx.c116
-rw-r--r--drivers/macintosh/Kconfig14
-rw-r--r--drivers/macintosh/adbhid.c14
-rw-r--r--drivers/macintosh/macio-adb.c19
-rw-r--r--drivers/macintosh/macio_asic.c152
-rw-r--r--drivers/macintosh/smu.c55
-rw-r--r--drivers/macintosh/therm_pm72.c218
-rw-r--r--drivers/macintosh/therm_pm72.h33
-rw-r--r--drivers/macintosh/via-cuda.c24
-rw-r--r--drivers/macintosh/via-pmu-backlight.c121
-rw-r--r--drivers/macintosh/via-pmu-led.c2
-rw-r--r--drivers/macintosh/via-pmu.c84
-rw-r--r--drivers/md/dm-mpath.c3
-rw-r--r--drivers/md/dm-raid1.c4
-rw-r--r--drivers/md/linear.c6
-rw-r--r--drivers/md/md.c105
-rw-r--r--drivers/md/raid1.c67
-rw-r--r--drivers/md/raid10.c4
-rw-r--r--drivers/md/raid5.c84
-rw-r--r--drivers/media/Kconfig2
-rw-r--r--drivers/media/common/saa7146_video.c2
-rw-r--r--drivers/media/dvb/b2c2/Kconfig1
-rw-r--r--drivers/media/dvb/bt8xx/Kconfig1
-rw-r--r--drivers/media/dvb/bt8xx/dst.c58
-rw-r--r--drivers/media/dvb/dvb-core/Makefile6
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c15
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig1
-rw-r--r--drivers/media/dvb/frontends/Kconfig60
-rw-r--r--drivers/media/dvb/frontends/Makefile2
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.c24
-rw-r--r--drivers/media/dvb/frontends/nxt200x.c4
-rw-r--r--drivers/media/dvb/frontends/or51211.c2
-rw-r--r--drivers/media/dvb/frontends/sp8870.c2
-rw-r--r--drivers/media/dvb/frontends/sp887x.c2
-rw-r--r--drivers/media/dvb/pluto2/Kconfig1
-rw-r--r--drivers/media/dvb/ttpci/Kconfig5
-rw-r--r--drivers/media/dvb/ttpci/av7110.c4
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c12
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c3
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c2
-rw-r--r--drivers/media/dvb/ttpci/budget-core.c57
-rw-r--r--drivers/media/dvb/ttpci/budget-patch.c2
-rw-r--r--drivers/media/dvb/ttpci/budget.c5
-rw-r--r--drivers/media/dvb/ttpci/budget.h7
-rw-r--r--drivers/media/dvb/ttusb-budget/Kconfig3
-rw-r--r--drivers/media/radio/Kconfig12
-rw-r--r--drivers/media/radio/Makefile1
-rw-r--r--drivers/media/radio/dsbr100.c (renamed from drivers/media/video/dsbr100.c)0
-rw-r--r--drivers/media/video/Kconfig24
-rw-r--r--drivers/media/video/Makefile2
-rw-r--r--drivers/media/video/bt8xx/Kconfig2
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c15
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c1
-rw-r--r--drivers/media/video/bt8xx/bttv-vbi.c15
-rw-r--r--drivers/media/video/compat_ioctl32.c54
-rw-r--r--drivers/media/video/cpia2/Kconfig2
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c4
-rw-r--r--drivers/media/video/cx88/Kconfig1
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c3
-rw-r--r--drivers/media/video/cx88/cx88-input.c2
-rw-r--r--drivers/media/video/cx88/cx88-video.c5
-rw-r--r--drivers/media/video/msp3400-driver.c10
-rw-r--r--drivers/media/video/msp3400-kthreads.c4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c8
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-io.c9
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-io.h2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-ioread.c5
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-sysfs.c85
-rw-r--r--drivers/media/video/pwc/Kconfig2
-rw-r--r--drivers/media/video/pwc/pwc-if.c1
-rw-r--r--drivers/media/video/saa7134/Kconfig1
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c10
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c16
-rw-r--r--drivers/media/video/saa7134/saa7134-oss.c10
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c6
-rw-r--r--drivers/media/video/saa7134/saa7134.h4
-rw-r--r--drivers/media/video/stradis.c1
-rw-r--r--drivers/media/video/tuner-core.c31
-rw-r--r--drivers/media/video/tuner-simple.c19
-rw-r--r--drivers/media/video/tuner-types.c24
-rw-r--r--drivers/media/video/usbvideo/Kconfig8
-rw-r--r--drivers/media/video/v4l1-compat.c4
-rw-r--r--drivers/media/video/v4l2-common.c24
-rw-r--r--drivers/media/video/videodev.c29
-rw-r--r--drivers/media/video/vivi.c4
-rw-r--r--drivers/media/video/zoran.h2
-rw-r--r--drivers/media/video/zoran_driver.c22
-rw-r--r--drivers/message/fusion/Kconfig2
-rw-r--r--drivers/message/fusion/Makefile6
-rw-r--r--drivers/message/fusion/lsi/fc_log.h89
-rw-r--r--drivers/message/fusion/lsi/mpi.h5
-rw-r--r--drivers/message/fusion/lsi/mpi_cnfg.h158
-rw-r--r--drivers/message/fusion/lsi/mpi_history.txt76
-rw-r--r--drivers/message/fusion/lsi/mpi_init.h4
-rw-r--r--drivers/message/fusion/lsi/mpi_ioc.h154
-rw-r--r--drivers/message/fusion/lsi/mpi_log_sas.h82
-rw-r--r--drivers/message/fusion/lsi/mpi_sas.h13
-rw-r--r--drivers/message/fusion/lsi/mpi_targ.h5
-rw-r--r--drivers/message/fusion/mptbase.c174
-rw-r--r--drivers/message/fusion/mptbase.h23
-rw-r--r--drivers/message/fusion/mptctl.c4
-rw-r--r--drivers/message/fusion/mptctl.h5
-rw-r--r--drivers/message/fusion/mptfc.c122
-rw-r--r--drivers/message/fusion/mptsas.c1045
-rw-r--r--drivers/message/fusion/mptscsih.c118
-rw-r--r--drivers/message/fusion/mptspi.c14
-rw-r--r--drivers/message/i2o/core.h3
-rw-r--r--drivers/message/i2o/i2o_config.c4
-rw-r--r--drivers/mfd/ucb1x00-core.c2
-rw-r--r--drivers/mfd/ucb1x00.h1
-rw-r--r--drivers/mmc/imxmmc.c69
-rw-r--r--drivers/mmc/mmc.c57
-rw-r--r--drivers/mmc/mmc_block.c60
-rw-r--r--drivers/mmc/mmc_queue.c3
-rw-r--r--drivers/mmc/sdhci.c6
-rw-r--r--drivers/mmc/wbsd.c9
-rw-r--r--drivers/mtd/devices/doc2000.c179
-rw-r--r--drivers/mtd/devices/doc2001.c179
-rw-r--r--drivers/mtd/devices/doc2001plus.c164
-rw-r--r--drivers/mtd/nand/ams-delta.c10
-rw-r--r--drivers/mtd/nand/nand_base.c26
-rw-r--r--drivers/mtd/nand/nand_ecc.c3
-rw-r--r--drivers/mtd/nand/sharpsl.c7
-rw-r--r--drivers/net/3c515.c3
-rw-r--r--drivers/net/3c59x.c170
-rw-r--r--drivers/net/8139cp.c35
-rw-r--r--drivers/net/8139too.c39
-rw-r--r--drivers/net/82596.c9
-rw-r--r--drivers/net/8390.c4
-rw-r--r--drivers/net/Kconfig43
-rw-r--r--drivers/net/Makefile3
-rw-r--r--drivers/net/ac3200.c3
-rw-r--r--drivers/net/appletalk/Kconfig2
-rw-r--r--drivers/net/appletalk/cops.c2
-rw-r--r--drivers/net/at1700.c2
-rw-r--r--drivers/net/b44.c27
-rw-r--r--drivers/net/bnx2.c81
-rw-r--r--drivers/net/bnx2.h12
-rw-r--r--drivers/net/cassini.c25
-rw-r--r--drivers/net/chelsio/sge.c2
-rw-r--r--drivers/net/cs89x0.c3
-rw-r--r--drivers/net/declance.c7
-rw-r--r--drivers/net/dl2k.c43
-rw-r--r--drivers/net/dm9000.c18
-rw-r--r--drivers/net/dummy.c1
-rw-r--r--drivers/net/e100.c6
-rw-r--r--drivers/net/e1000/e1000.h13
-rw-r--r--drivers/net/e1000/e1000_ethtool.c141
-rw-r--r--drivers/net/e1000/e1000_hw.c1819
-rw-r--r--drivers/net/e1000/e1000_hw.h386
-rw-r--r--drivers/net/e1000/e1000_main.c456
-rw-r--r--drivers/net/e1000/e1000_osdep.h13
-rw-r--r--drivers/net/e1000/e1000_param.c199
-rw-r--r--drivers/net/e2100.c4
-rw-r--r--drivers/net/eepro.c3
-rw-r--r--drivers/net/eepro100.c6
-rw-r--r--drivers/net/eexpress.c2
-rw-r--r--drivers/net/epic100.c93
-rw-r--r--drivers/net/es3210.c3
-rw-r--r--drivers/net/eth16i.c2
-rw-r--r--drivers/net/fealnx.c38
-rw-r--r--drivers/net/forcedeth.c79
-rw-r--r--drivers/net/fs_enet/Makefile6
-rw-r--r--drivers/net/fs_enet/fec.h42
-rw-r--r--drivers/net/fs_enet/fs_enet-main.c207
-rw-r--r--drivers/net/fs_enet/fs_enet-mii.c505
-rw-r--r--drivers/net/fs_enet/fs_enet.h40
-rw-r--r--drivers/net/fs_enet/mac-fcc.c32
-rw-r--r--drivers/net/fs_enet/mac-fec.c142
-rw-r--r--drivers/net/fs_enet/mac-scc.c4
-rw-r--r--drivers/net/fs_enet/mii-bitbang.c448
-rw-r--r--drivers/net/fs_enet/mii-fec.c243
-rw-r--r--drivers/net/fs_enet/mii-fixed.c91
-rw-r--r--drivers/net/gt96100eth.c3
-rw-r--r--drivers/net/gt96100eth.h2
-rw-r--r--drivers/net/hamachi.c16
-rw-r--r--drivers/net/hamradio/bpqether.c7
-rw-r--r--drivers/net/ifb.c1
-rw-r--r--drivers/net/irda/ali-ircc.c3
-rw-r--r--drivers/net/irda/smsc-ircc2.c2
-rw-r--r--drivers/net/ixgb/ixgb_main.c6
-rw-r--r--drivers/net/lance.c2
-rw-r--r--drivers/net/lne390.c2
-rw-r--r--drivers/net/loopback.c2
-rw-r--r--drivers/net/mace.c4
-rw-r--r--drivers/net/mv643xx_eth.c2
-rw-r--r--drivers/net/myri10ge/myri10ge.c60
-rw-r--r--drivers/net/natsemi.c117
-rw-r--r--drivers/net/ne2k-pci.c9
-rw-r--r--drivers/net/ni5010.c52
-rw-r--r--drivers/net/ni52.c2
-rw-r--r--drivers/net/ni65.c2
-rw-r--r--drivers/net/ns83820.c41
-rw-r--r--drivers/net/pci-skeleton.c19
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c18
-rw-r--r--drivers/net/pcnet32.c545
-rw-r--r--drivers/net/phy/Kconfig17
-rw-r--r--drivers/net/phy/Makefile1
-rw-r--r--drivers/net/phy/cicada.c42
-rw-r--r--drivers/net/phy/fixed.c358
-rw-r--r--drivers/net/phy/mdio_bus.c1
-rw-r--r--drivers/net/phy/phy.c8
-rw-r--r--drivers/net/phy/phy_device.c51
-rw-r--r--drivers/net/ppp_generic.c30
-rw-r--r--drivers/net/r8169.c40
-rw-r--r--drivers/net/s2io.c672
-rw-r--r--drivers/net/s2io.h15
-rw-r--r--drivers/net/seeq8005.c2
-rw-r--r--drivers/net/sk98lin/h/xmac_ii.h2
-rw-r--r--drivers/net/skge.c7
-rw-r--r--drivers/net/skge.h4
-rw-r--r--drivers/net/sky2.c55
-rw-r--r--drivers/net/sky2.h2
-rw-r--r--drivers/net/smc911x.c1
-rw-r--r--drivers/net/smc91x.c8
-rw-r--r--drivers/net/smc91x.h47
-rw-r--r--drivers/net/spider_net.c584
-rw-r--r--drivers/net/spider_net.h76
-rw-r--r--drivers/net/spider_net_ethtool.c13
-rw-r--r--drivers/net/starfire.c123
-rw-r--r--drivers/net/sundance.c108
-rw-r--r--drivers/net/sunhme.c9
-rw-r--r--drivers/net/sunlance.c35
-rw-r--r--drivers/net/tg3.c200
-rw-r--r--drivers/net/tg3.h8
-rw-r--r--drivers/net/tokenring/ibmtr.c4
-rw-r--r--drivers/net/tokenring/smctr.c5
-rw-r--r--drivers/net/tulip/winbond-840.c31
-rw-r--r--drivers/net/tulip/xircom_cb.c3
-rw-r--r--drivers/net/tulip/xircom_tulip_cb.c27
-rw-r--r--drivers/net/typhoon.c4
-rw-r--r--drivers/net/ucc_geth.c4278
-rw-r--r--drivers/net/ucc_geth.h1339
-rw-r--r--drivers/net/ucc_geth_phy.c801
-rw-r--r--drivers/net/ucc_geth_phy.h217
-rw-r--r--drivers/net/via-rhine.c207
-rw-r--r--drivers/net/via-velocity.c119
-rw-r--r--drivers/net/via-velocity.h4
-rw-r--r--drivers/net/wan/Kconfig12
-rw-r--r--drivers/net/wan/Makefile1
-rw-r--r--drivers/net/wan/c101.c33
-rw-r--r--drivers/net/wan/hd6457x.c26
-rw-r--r--drivers/net/wan/hdlc_cisco.c14
-rw-r--r--drivers/net/wan/hdlc_fr.c14
-rw-r--r--drivers/net/wan/hdlc_generic.c65
-rw-r--r--drivers/net/wan/hdlc_ppp.c1
-rw-r--r--drivers/net/wan/hdlc_raw.c1
-rw-r--r--drivers/net/wan/hdlc_raw_eth.c1
-rw-r--r--drivers/net/wan/hdlc_x25.c1
-rw-r--r--drivers/net/wan/n2.c3
-rw-r--r--drivers/net/wan/wanxl.c5
-rw-r--r--drivers/net/wd.c4
-rw-r--r--drivers/net/wireless/Kconfig2
-rw-r--r--drivers/net/wireless/Makefile1
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_ethtool.c2
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.c33
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.h24
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_radio.c7
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_wx.c2
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_xmit.c5
-rw-r--r--drivers/net/wireless/hostap/hostap_hw.c13
-rw-r--r--drivers/net/wireless/hostap/hostap_plx.c2
-rw-r--r--drivers/net/wireless/orinoco.c4
-rw-r--r--drivers/net/wireless/spectrum_cs.c39
-rw-r--r--drivers/net/wireless/strip.c6
-rw-r--r--drivers/net/wireless/zd1201.c2
-rw-r--r--drivers/net/wireless/zd1211rw/Kconfig19
-rw-r--r--drivers/net/wireless/zd1211rw/Makefile11
-rw-r--r--drivers/net/wireless/zd1211rw/zd_chip.c1646
-rw-r--r--drivers/net/wireless/zd1211rw/zd_chip.h827
-rw-r--r--drivers/net/wireless/zd1211rw/zd_def.h48
-rw-r--r--drivers/net/wireless/zd1211rw/zd_ieee80211.c191
-rw-r--r--drivers/net/wireless/zd1211rw/zd_ieee80211.h85
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.c1084
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.h193
-rw-r--r--drivers/net/wireless/zd1211rw/zd_netdev.c267
-rw-r--r--drivers/net/wireless/zd1211rw/zd_netdev.h45
-rw-r--r--drivers/net/wireless/zd1211rw/zd_rf.c151
-rw-r--r--drivers/net/wireless/zd1211rw/zd_rf.h82
-rw-r--r--drivers/net/wireless/zd1211rw/zd_rf_al2230.c308
-rw-r--r--drivers/net/wireless/zd1211rw/zd_rf_rf2959.c279
-rw-r--r--drivers/net/wireless/zd1211rw/zd_types.h71
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.c1309
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.h240
-rw-r--r--drivers/net/wireless/zd1211rw/zd_util.c82
-rw-r--r--drivers/net/wireless/zd1211rw/zd_util.h (renamed from drivers/w1/w1_io.h)27
-rw-r--r--drivers/net/yellowfin.c39
-rw-r--r--drivers/pci/hotplug/Kconfig12
-rw-r--r--drivers/pci/hotplug/acpiphp_core.c3
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c2
-rw-r--r--drivers/pci/hotplug/cpci_hotplug_pci.c54
-rw-r--r--drivers/pci/hotplug/pciehp.h5
-rw-r--r--drivers/pci/hotplug/pciehp_hpc.c4
-rw-r--r--drivers/pci/msi.c4
-rw-r--r--drivers/pci/pci-driver.c3
-rw-r--r--drivers/pci/pci.c11
-rw-r--r--drivers/pci/pci.h10
-rw-r--r--drivers/pci/pcie/portdrv_pci.c38
-rw-r--r--drivers/pci/probe.c1
-rw-r--r--drivers/pci/quirks.c175
-rw-r--r--drivers/pci/search.c48
-rw-r--r--drivers/pcmcia/Kconfig2
-rw-r--r--drivers/pcmcia/pcmcia_ioctl.c16
-rw-r--r--drivers/pcmcia/pcmcia_resource.c15
-rw-r--r--drivers/pnp/interface.c12
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c19
-rw-r--r--drivers/pnp/pnpbios/core.c2
-rw-r--r--drivers/rtc/Kconfig10
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/rtc-isl1208.c591
-rw-r--r--drivers/rtc/rtc-s3c.c124
-rw-r--r--drivers/rtc/rtc-vr41xx.c2
-rw-r--r--drivers/s390/block/dasd.c194
-rw-r--r--drivers/s390/block/dasd_devmap.c94
-rw-r--r--drivers/s390/block/dasd_eckd.c42
-rw-r--r--drivers/s390/block/dasd_fba.c4
-rw-r--r--drivers/s390/block/dasd_genhd.c14
-rw-r--r--drivers/s390/block/dasd_ioctl.c2
-rw-r--r--drivers/s390/block/xpram.c99
-rw-r--r--drivers/s390/char/con3215.c2
-rw-r--r--drivers/s390/char/ctrlchar.c2
-rw-r--r--drivers/s390/char/defkeymap.c6
-rw-r--r--drivers/s390/char/fs3270.c12
-rw-r--r--drivers/s390/char/keyboard.c6
-rw-r--r--drivers/s390/char/raw3270.c86
-rw-r--r--drivers/s390/char/raw3270.h2
-rw-r--r--drivers/s390/char/sclp.c10
-rw-r--r--drivers/s390/char/tape_34xx.c6
-rw-r--r--drivers/s390/char/tape_class.c10
-rw-r--r--drivers/s390/char/tape_core.c18
-rw-r--r--drivers/s390/char/tty3270.c24
-rw-r--r--drivers/s390/char/vmlogrdr.c6
-rw-r--r--drivers/s390/char/vmwatchdog.c2
-rw-r--r--drivers/s390/cio/ccwgroup.c26
-rw-r--r--drivers/s390/cio/chsc.c44
-rw-r--r--drivers/s390/cio/cio.c6
-rw-r--r--drivers/s390/cio/cio.h3
-rw-r--r--drivers/s390/cio/cmf.c5
-rw-r--r--drivers/s390/cio/css.c36
-rw-r--r--drivers/s390/cio/css.h4
-rw-r--r--drivers/s390/cio/device.c33
-rw-r--r--drivers/s390/cio/device_fsm.c109
-rw-r--r--drivers/s390/cio/device_ops.c3
-rw-r--r--drivers/s390/cio/device_pgid.c149
-rw-r--r--drivers/s390/cio/device_status.c7
-rw-r--r--drivers/s390/cio/qdio.c2
-rw-r--r--drivers/s390/net/Kconfig9
-rw-r--r--drivers/s390/net/Makefile1
-rw-r--r--drivers/s390/net/claw.c2
-rw-r--r--drivers/s390/net/ctcmain.c24
-rw-r--r--drivers/s390/net/iucv.c6
-rw-r--r--drivers/s390/net/lcs.c13
-rw-r--r--drivers/s390/net/netiucv.c82
-rw-r--r--drivers/s390/net/qeth.h73
-rw-r--r--drivers/s390/net/qeth_eddp.c5
-rw-r--r--drivers/s390/net/qeth_main.c554
-rw-r--r--drivers/s390/net/qeth_proc.c23
-rw-r--r--drivers/s390/net/qeth_sys.c68
-rw-r--r--drivers/s390/net/qeth_tso.h2
-rw-r--r--drivers/s390/net/smsgiucv.c14
-rw-r--r--drivers/s390/s390mach.c13
-rw-r--r--drivers/s390/scsi/zfcp_aux.c120
-rw-r--r--drivers/s390/scsi/zfcp_ccw.c5
-rw-r--r--drivers/s390/scsi/zfcp_def.h15
-rw-r--r--drivers/s390/scsi/zfcp_erp.c220
-rw-r--r--drivers/s390/scsi/zfcp_ext.h9
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c124
-rw-r--r--drivers/s390/scsi/zfcp_qdio.c78
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c104
-rw-r--r--drivers/sbus/sbus.c2
-rw-r--r--drivers/scsi/53c700.c56
-rw-r--r--drivers/scsi/53c700.h34
-rw-r--r--drivers/scsi/53c7xx.c8
-rw-r--r--drivers/scsi/NCR53C9x.c18
-rw-r--r--drivers/scsi/NCR_D700.c14
-rw-r--r--drivers/scsi/aacraid/comminit.c26
-rw-r--r--drivers/scsi/aha152x.c43
-rw-r--r--drivers/scsi/ahci.c27
-rw-r--r--drivers/scsi/aic7xxx/aic79xx.h1
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_core.c26
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c83
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.h12
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_proc.c19
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.c1
-rw-r--r--drivers/scsi/aic7xxx/aicasm/Makefile2
-rw-r--r--drivers/scsi/arm/Kconfig3
-rw-r--r--drivers/scsi/arm/fas216.c2
-rw-r--r--drivers/scsi/arm/scsi.h2
-rw-r--r--drivers/scsi/ata_piix.c266
-rw-r--r--drivers/scsi/atari_NCR5380.c2
-rw-r--r--drivers/scsi/atp870u.c157
-rw-r--r--drivers/scsi/constants.c126
-rw-r--r--drivers/scsi/esp.c19
-rw-r--r--drivers/scsi/hptiop.c568
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c64
-rw-r--r--drivers/scsi/ibmvscsi/iseries_vscsi.c2
-rw-r--r--drivers/scsi/ibmvscsi/rpa_vscsi.c6
-rw-r--r--drivers/scsi/ide-scsi.c2
-rw-r--r--drivers/scsi/iscsi_tcp.c353
-rw-r--r--drivers/scsi/iscsi_tcp.h2
-rw-r--r--drivers/scsi/jazz_esp.c2
-rw-r--r--drivers/scsi/libata-core.c340
-rw-r--r--drivers/scsi/libata-eh.c464
-rw-r--r--drivers/scsi/libata-scsi.c137
-rw-r--r--drivers/scsi/libiscsi.c399
-rw-r--r--drivers/scsi/lpfc/lpfc.h10
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c190
-rw-r--r--drivers/scsi/lpfc/lpfc_crtn.h2
-rw-r--r--drivers/scsi/lpfc/lpfc_ct.c13
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c92
-rw-r--r--drivers/scsi/lpfc/lpfc_hbadisc.c19
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c77
-rw-r--r--drivers/scsi/lpfc/lpfc_mbox.c16
-rw-r--r--drivers/scsi/lpfc/lpfc_mem.c5
-rw-r--r--drivers/scsi/lpfc/lpfc_nportdisc.c35
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c105
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c112
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.h22
-rw-r--r--drivers/scsi/lpfc/lpfc_version.h2
-rw-r--r--drivers/scsi/mac53c94.c2
-rw-r--r--drivers/scsi/megaraid/mega_common.h6
-rw-r--r--drivers/scsi/megaraid/megaraid_ioctl.h4
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.c42
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.h4
-rw-r--r--drivers/scsi/megaraid/megaraid_mm.c2
-rw-r--r--drivers/scsi/megaraid/megaraid_mm.h4
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c32
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.h21
-rw-r--r--drivers/scsi/mesh.c2
-rw-r--r--drivers/scsi/nsp32.c12
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.c2
-rw-r--r--drivers/scsi/pdc_adma.c3
-rw-r--r--drivers/scsi/pluto.c2
-rw-r--r--drivers/scsi/qla1280.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_attr.c120
-rw-r--r--drivers/scsi/qla2xxx/qla_dbg.c925
-rw-r--r--drivers/scsi/qla2xxx/qla_dbg.h151
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h20
-rw-r--r--drivers/scsi/qla2xxx/qla_devtbl.h17
-rw-r--r--drivers/scsi/qla2xxx/qla_fw.h4
-rw-r--r--drivers/scsi/qla2xxx/qla_gbl.h26
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c154
-rw-r--r--drivers/scsi/qla2xxx/qla_iocb.c4
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c29
-rw-r--r--drivers/scsi/qla2xxx/qla_mbx.c280
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c140
-rw-r--r--drivers/scsi/qla2xxx/qla_version.h4
-rw-r--r--drivers/scsi/qlogicpti.c4
-rw-r--r--drivers/scsi/sata_mv.c3
-rw-r--r--drivers/scsi/sata_promise.c7
-rw-r--r--drivers/scsi/sata_sil.c105
-rw-r--r--drivers/scsi/sata_sil24.c135
-rw-r--r--drivers/scsi/sata_via.c118
-rw-r--r--drivers/scsi/sata_vsc.c2
-rw-r--r--drivers/scsi/scsi.c11
-rw-r--r--drivers/scsi/scsi_debug.c1295
-rw-r--r--drivers/scsi/scsi_devinfo.c2
-rw-r--r--drivers/scsi/scsi_error.c242
-rw-r--r--drivers/scsi/scsi_ioctl.c5
-rw-r--r--drivers/scsi/scsi_lib.c210
-rw-r--r--drivers/scsi/scsi_priv.h3
-rw-r--r--drivers/scsi/scsi_sas_internal.h10
-rw-r--r--drivers/scsi/scsi_scan.c1
-rw-r--r--drivers/scsi/scsi_transport_fc.c42
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c663
-rw-r--r--drivers/scsi/scsi_transport_sas.c431
-rw-r--r--drivers/scsi/scsicam.c3
-rw-r--r--drivers/scsi/sd.c172
-rw-r--r--drivers/scsi/seagate.c2
-rw-r--r--drivers/scsi/sg.c18
-rw-r--r--drivers/scsi/sr.c7
-rw-r--r--drivers/scsi/st.c8
-rw-r--r--drivers/scsi/st.h1
-rw-r--r--drivers/scsi/sun3_NCR5380.c2
-rw-r--r--drivers/scsi/sun3x_esp.c2
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_glue.c2
-rw-r--r--drivers/scsi/wd33c93.c2
-rw-r--r--drivers/serial/8250.c25
-rw-r--r--drivers/serial/8250_pci.c51
-rw-r--r--drivers/serial/8250_pnp.c2
-rw-r--r--drivers/serial/at91_serial.c5
-rw-r--r--drivers/serial/dz.c2
-rw-r--r--drivers/serial/ip22zilog.c3
-rw-r--r--drivers/serial/mpc52xx_uart.c3
-rw-r--r--drivers/serial/pmac_zilog.c6
-rw-r--r--drivers/serial/serial_core.c21
-rw-r--r--drivers/serial/sh-sci.c4
-rw-r--r--drivers/serial/sunsab.c16
-rw-r--r--drivers/serial/sunsu.c40
-rw-r--r--drivers/serial/sunzilog.c128
-rw-r--r--drivers/serial/vr41xx_siu.c1
-rw-r--r--drivers/spi/spi.c2
-rw-r--r--drivers/usb/Kconfig3
-rw-r--r--drivers/usb/Makefile2
-rw-r--r--drivers/usb/class/cdc-acm.c49
-rw-r--r--drivers/usb/core/Kconfig3
-rw-r--r--drivers/usb/core/devio.c20
-rw-r--r--drivers/usb/core/file.c13
-rw-r--r--drivers/usb/core/hub.c10
-rw-r--r--drivers/usb/core/inode.c6
-rw-r--r--drivers/usb/gadget/Kconfig2
-rw-r--r--drivers/usb/gadget/at91_udc.c176
-rw-r--r--drivers/usb/gadget/at91_udc.h1
-rw-r--r--drivers/usb/gadget/dummy_hcd.c6
-rw-r--r--drivers/usb/gadget/epautoconf.c16
-rw-r--r--drivers/usb/gadget/ether.c53
-rw-r--r--drivers/usb/gadget/file_storage.c2
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c2
-rw-r--r--drivers/usb/gadget/rndis.c2
-rw-r--r--drivers/usb/gadget/rndis.h2
-rw-r--r--drivers/usb/gadget/serial.c2
-rw-r--r--drivers/usb/gadget/zero.c2
-rw-r--r--drivers/usb/host/ehci-au1xxx.c23
-rw-r--r--drivers/usb/host/ehci-hcd.c9
-rw-r--r--drivers/usb/host/ohci-at91.c88
-rw-r--r--drivers/usb/host/ohci-au1xxx.c6
-rw-r--r--drivers/usb/host/ohci-ep93xx.c225
-rw-r--r--drivers/usb/host/ohci-hcd.c8
-rw-r--r--drivers/usb/host/ohci-hub.c4
-rw-r--r--drivers/usb/host/pci-quirks.c8
-rw-r--r--drivers/usb/host/uhci-q.c8
-rw-r--r--drivers/usb/input/appletouch.c2
-rw-r--r--drivers/usb/input/ati_remote.c174
-rw-r--r--drivers/usb/input/hid-core.c153
-rw-r--r--drivers/usb/input/hid-input.c3
-rw-r--r--drivers/usb/input/hiddev.c72
-rw-r--r--drivers/usb/input/usbtouchscreen.c2
-rw-r--r--drivers/usb/input/yealink.c12
-rw-r--r--drivers/usb/misc/Kconfig10
-rw-r--r--drivers/usb/misc/Makefile2
-rw-r--r--drivers/usb/misc/cy7c63.c244
-rw-r--r--drivers/usb/misc/cypress_cy7c63.c284
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c2
-rw-r--r--drivers/usb/misc/usblcd.c6
-rw-r--r--drivers/usb/misc/usbtest.c5
-rw-r--r--drivers/usb/mon/mon_text.c7
-rw-r--r--drivers/usb/net/pegasus.h3
-rw-r--r--drivers/usb/net/rtl8150.c87
-rw-r--r--drivers/usb/serial/Kconfig35
-rw-r--r--drivers/usb/serial/Makefile2
-rw-r--r--drivers/usb/serial/airprime.c2
-rw-r--r--drivers/usb/serial/anydata.c123
-rw-r--r--drivers/usb/serial/ark3116.c2
-rw-r--r--drivers/usb/serial/belkin_sa.c2
-rw-r--r--drivers/usb/serial/bus.c2
-rw-r--r--drivers/usb/serial/console.c3
-rw-r--r--drivers/usb/serial/cp2101.c2
-rw-r--r--drivers/usb/serial/cyberjack.c2
-rw-r--r--drivers/usb/serial/cypress_m8.c2
-rw-r--r--drivers/usb/serial/digi_acceleport.c2
-rw-r--r--drivers/usb/serial/empeg.c2
-rw-r--r--drivers/usb/serial/ezusb.c2
-rw-r--r--drivers/usb/serial/ftdi_sio.c112
-rw-r--r--drivers/usb/serial/ftdi_sio.h30
-rw-r--r--drivers/usb/serial/funsoft.c2
-rw-r--r--drivers/usb/serial/garmin_gps.c3
-rw-r--r--drivers/usb/serial/generic.c3
-rw-r--r--drivers/usb/serial/hp4x.c2
-rw-r--r--drivers/usb/serial/io_edgeport.c2
-rw-r--r--drivers/usb/serial/io_ti.c2
-rw-r--r--drivers/usb/serial/ipaq.c28
-rw-r--r--drivers/usb/serial/ipw.c4
-rw-r--r--drivers/usb/serial/ir-usb.c2
-rw-r--r--drivers/usb/serial/keyspan.c2
-rw-r--r--drivers/usb/serial/keyspan_pda.c3
-rw-r--r--drivers/usb/serial/kl5kusb105.c2
-rw-r--r--drivers/usb/serial/kobil_sct.c2
-rw-r--r--drivers/usb/serial/mct_u232.c2
-rw-r--r--drivers/usb/serial/navman.c2
-rw-r--r--drivers/usb/serial/omninet.c2
-rw-r--r--drivers/usb/serial/option.c82
-rw-r--r--drivers/usb/serial/pl2303.c6
-rw-r--r--drivers/usb/serial/pl2303.h11
-rw-r--r--drivers/usb/serial/safe_serial.c2
-rw-r--r--drivers/usb/serial/sierra.c75
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c2
-rw-r--r--drivers/usb/serial/usb-serial.c29
-rw-r--r--drivers/usb/serial/usb-serial.h300
-rw-r--r--drivers/usb/serial/visor.c39
-rw-r--r--drivers/usb/serial/whiteheat.c2
-rw-r--r--drivers/usb/storage/scsiglue.c12
-rw-r--r--drivers/usb/storage/transport.c2
-rw-r--r--drivers/usb/storage/unusual_devs.h125
-rw-r--r--drivers/usb/storage/usb.c42
-rw-r--r--drivers/usb/storage/usb.h4
-rw-r--r--drivers/video/68328fb.c1
-rw-r--r--drivers/video/Kconfig75
-rw-r--r--drivers/video/Makefile4
-rw-r--r--drivers/video/S3triofb.c1
-rw-r--r--drivers/video/amifb.c1
-rw-r--r--drivers/video/arcfb.c1
-rw-r--r--drivers/video/asiliantfb.c1
-rw-r--r--drivers/video/atafb.c1
-rw-r--r--drivers/video/aty/aty128fb.c90
-rw-r--r--drivers/video/aty/atyfb_base.c67
-rw-r--r--drivers/video/aty/radeon_backlight.c4
-rw-r--r--drivers/video/aty/radeon_base.c19
-rw-r--r--drivers/video/aty/radeon_pm.c146
-rw-r--r--drivers/video/aty/radeonfb.h6
-rw-r--r--drivers/video/au1100fb.c18
-rw-r--r--drivers/video/backlight/Kconfig4
-rw-r--r--drivers/video/chipsfb.c4
-rw-r--r--drivers/video/cirrusfb.c1
-rw-r--r--drivers/video/console/dummycon.c2
-rw-r--r--drivers/video/console/fbcon.c1
-rw-r--r--drivers/video/console/mdacon.c5
-rw-r--r--drivers/video/console/newport_con.c1
-rw-r--r--drivers/video/console/promcon.c1
-rw-r--r--drivers/video/console/softcursor.c1
-rw-r--r--drivers/video/console/sticon.c1
-rw-r--r--drivers/video/console/vgacon.c2
-rw-r--r--drivers/video/controlfb.c1
-rw-r--r--drivers/video/cyber2000fb.c1
-rw-r--r--drivers/video/cyberfb.c1
-rw-r--r--drivers/video/dnfb.c1
-rw-r--r--drivers/video/epson1355fb.c1
-rw-r--r--drivers/video/fb_notify.c46
-rw-r--r--drivers/video/fbcmap.c1
-rw-r--r--drivers/video/fbmem.c56
-rw-r--r--drivers/video/fbmon.c1
-rw-r--r--drivers/video/g364fb.c1
-rw-r--r--drivers/video/geode/gx1fb_core.c1
-rw-r--r--drivers/video/geode/gxfb_core.c1
-rw-r--r--drivers/video/hgafb.c1
-rw-r--r--drivers/video/hitfb.c1
-rw-r--r--drivers/video/hpfb.c1
-rw-r--r--drivers/video/i810/i810_main.c1
-rw-r--r--drivers/video/igafb.c1
-rw-r--r--drivers/video/imacfb.c51
-rw-r--r--drivers/video/imsttfb.c1
-rw-r--r--drivers/video/intelfb/intelfbdrv.c2
-rw-r--r--drivers/video/intelfb/intelfbhw.c1
-rw-r--r--drivers/video/kyro/fbdev.c1
-rw-r--r--drivers/video/macfb.c1
-rw-r--r--drivers/video/matrox/g450_pll.c8
-rw-r--r--drivers/video/matrox/matroxfb_base.h1
-rw-r--r--drivers/video/maxinefb.c1
-rw-r--r--drivers/video/mbx/Makefile4
-rw-r--r--drivers/video/mbx/mbxdebugfs.c188
-rw-r--r--drivers/video/mbx/mbxfb.c683
-rw-r--r--drivers/video/mbx/reg_bits.h418
-rw-r--r--drivers/video/mbx/regs.h195
-rw-r--r--drivers/video/modedb.c1
-rw-r--r--drivers/video/neofb.c1
-rw-r--r--drivers/video/nvidia/nv_backlight.c42
-rw-r--r--drivers/video/nvidia/nv_proto.h2
-rw-r--r--drivers/video/nvidia/nvidia.c21
-rw-r--r--drivers/video/offb.c444
-rw-r--r--drivers/video/platinumfb.c1
-rw-r--r--drivers/video/pm2fb.c1
-rw-r--r--drivers/video/pm3fb.c1
-rw-r--r--drivers/video/pmag-aa-fb.c1
-rw-r--r--drivers/video/pnx4008/Makefile7
-rw-r--r--drivers/video/pnx4008/dum.h211
-rw-r--r--drivers/video/pnx4008/fbcommon.h43
-rw-r--r--drivers/video/pnx4008/pnxrgbfb.c213
-rw-r--r--drivers/video/pnx4008/sdum.c872
-rw-r--r--drivers/video/pnx4008/sdum.h139
-rw-r--r--drivers/video/pvr2fb.c1
-rw-r--r--drivers/video/q40fb.c1
-rw-r--r--drivers/video/retz3fb.c1
-rw-r--r--drivers/video/riva/fbdev.c62
-rw-r--r--drivers/video/s3c2410fb.c1
-rw-r--r--drivers/video/savage/savagefb_driver.c1
-rw-r--r--drivers/video/sis/sis_main.c6
-rw-r--r--drivers/video/skeletonfb.c1
-rw-r--r--drivers/video/sun3fb.c1
-rw-r--r--drivers/video/tdfxfb.c1
-rw-r--r--drivers/video/tgafb.c1
-rw-r--r--drivers/video/tx3912fb.c1
-rw-r--r--drivers/video/valkyriefb.c1
-rw-r--r--drivers/video/vesafb.c2
-rw-r--r--drivers/video/vfb.c1
-rw-r--r--drivers/video/vga16fb.c2
-rw-r--r--drivers/video/virgefb.c1
-rw-r--r--drivers/w1/masters/ds2482.c2
1009 files changed, 42344 insertions, 15720 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index bc2652d72fdc..56c5ba874623 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -107,7 +107,6 @@ config ACPI_BUTTON
107config ACPI_VIDEO 107config ACPI_VIDEO
108 tristate "Video" 108 tristate "Video"
109 depends on X86 109 depends on X86
110 default y
111 help 110 help
112 This driver implement the ACPI Extensions For Display Adapters 111 This driver implement the ACPI Extensions For Display Adapters
113 for integrated graphics devices on motherboard, as specified in 112 for integrated graphics devices on motherboard, as specified in
@@ -135,8 +134,7 @@ config ACPI_FAN
135 134
136config ACPI_DOCK 135config ACPI_DOCK
137 tristate "Dock" 136 tristate "Dock"
138 depends on !ACPI_IBM_DOCK 137 depends on EXPERIMENTAL
139 default y
140 help 138 help
141 This driver adds support for ACPI controlled docking stations 139 This driver adds support for ACPI controlled docking stations
142 140
@@ -214,6 +212,7 @@ config ACPI_IBM
214config ACPI_IBM_DOCK 212config ACPI_IBM_DOCK
215 bool "Legacy Docking Station Support" 213 bool "Legacy Docking Station Support"
216 depends on ACPI_IBM 214 depends on ACPI_IBM
215 depends on ACPI_DOCK=n
217 default n 216 default n
218 ---help--- 217 ---help---
219 Allows the ibm_acpi driver to handle docking station events. 218 Allows the ibm_acpi driver to handle docking station events.
@@ -352,6 +351,17 @@ config ACPI_HOTPLUG_MEMORY
352 If one selects "m," this driver can be loaded using the following 351 If one selects "m," this driver can be loaded using the following
353 command: 352 command:
354 $>modprobe acpi_memhotplug 353 $>modprobe acpi_memhotplug
354
355config ACPI_SBS
356 tristate "Smart Battery System (EXPERIMENTAL)"
357 depends on X86 && I2C
358 depends on EXPERIMENTAL
359 help
360 This driver adds support for the Smart Battery System.
361 Depends on I2C (Device Drivers ---> I2C support)
362 A "Smart Battery" is quite old and quite rare compared
363 to today's ACPI "Control Method" battery.
364
355endif # ACPI 365endif # ACPI
356 366
357endmenu 367endmenu
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index f0a68ecf1e57..bce7ca27b429 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -58,3 +58,5 @@ obj-$(CONFIG_ACPI_IBM) += ibm_acpi.o
58obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o 58obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o
59obj-y += scan.o motherboard.o 59obj-y += scan.o motherboard.o
60obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o 60obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o
61obj-y += cm_sbs.o
62obj-$(CONFIG_ACPI_SBS) += i2c_ec.o sbs.o
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 36ca365bcead..11abc7bf777e 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -50,6 +50,9 @@ ACPI_MODULE_NAME("acpi_ac")
50MODULE_DESCRIPTION(ACPI_AC_DRIVER_NAME); 50MODULE_DESCRIPTION(ACPI_AC_DRIVER_NAME);
51MODULE_LICENSE("GPL"); 51MODULE_LICENSE("GPL");
52 52
53extern struct proc_dir_entry *acpi_lock_ac_dir(void);
54extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
55
53static int acpi_ac_add(struct acpi_device *device); 56static int acpi_ac_add(struct acpi_device *device);
54static int acpi_ac_remove(struct acpi_device *device, int type); 57static int acpi_ac_remove(struct acpi_device *device, int type);
55static int acpi_ac_open_fs(struct inode *inode, struct file *file); 58static int acpi_ac_open_fs(struct inode *inode, struct file *file);
@@ -65,11 +68,11 @@ static struct acpi_driver acpi_ac_driver = {
65}; 68};
66 69
67struct acpi_ac { 70struct acpi_ac {
68 acpi_handle handle; 71 struct acpi_device * device;
69 unsigned long state; 72 unsigned long state;
70}; 73};
71 74
72static struct file_operations acpi_ac_fops = { 75static const struct file_operations acpi_ac_fops = {
73 .open = acpi_ac_open_fs, 76 .open = acpi_ac_open_fs,
74 .read = seq_read, 77 .read = seq_read,
75 .llseek = seq_lseek, 78 .llseek = seq_lseek,
@@ -88,7 +91,7 @@ static int acpi_ac_get_state(struct acpi_ac *ac)
88 if (!ac) 91 if (!ac)
89 return -EINVAL; 92 return -EINVAL;
90 93
91 status = acpi_evaluate_integer(ac->handle, "_PSR", NULL, &ac->state); 94 status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL, &ac->state);
92 if (ACPI_FAILURE(status)) { 95 if (ACPI_FAILURE(status)) {
93 ACPI_EXCEPTION((AE_INFO, status, "Error reading AC Adapter state")); 96 ACPI_EXCEPTION((AE_INFO, status, "Error reading AC Adapter state"));
94 ac->state = ACPI_AC_STATUS_UNKNOWN; 97 ac->state = ACPI_AC_STATUS_UNKNOWN;
@@ -191,11 +194,11 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
191 if (!ac) 194 if (!ac)
192 return; 195 return;
193 196
194 if (acpi_bus_get_device(ac->handle, &device)) 197 device = ac->device;
195 return;
196
197 switch (event) { 198 switch (event) {
198 case ACPI_AC_NOTIFY_STATUS: 199 case ACPI_AC_NOTIFY_STATUS:
200 case ACPI_NOTIFY_BUS_CHECK:
201 case ACPI_NOTIFY_DEVICE_CHECK:
199 acpi_ac_get_state(ac); 202 acpi_ac_get_state(ac);
200 acpi_bus_generate_event(device, event, (u32) ac->state); 203 acpi_bus_generate_event(device, event, (u32) ac->state);
201 break; 204 break;
@@ -223,7 +226,7 @@ static int acpi_ac_add(struct acpi_device *device)
223 return -ENOMEM; 226 return -ENOMEM;
224 memset(ac, 0, sizeof(struct acpi_ac)); 227 memset(ac, 0, sizeof(struct acpi_ac));
225 228
226 ac->handle = device->handle; 229 ac->device = device;
227 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME); 230 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME);
228 strcpy(acpi_device_class(device), ACPI_AC_CLASS); 231 strcpy(acpi_device_class(device), ACPI_AC_CLASS);
229 acpi_driver_data(device) = ac; 232 acpi_driver_data(device) = ac;
@@ -236,8 +239,8 @@ static int acpi_ac_add(struct acpi_device *device)
236 if (result) 239 if (result)
237 goto end; 240 goto end;
238 241
239 status = acpi_install_notify_handler(ac->handle, 242 status = acpi_install_notify_handler(device->handle,
240 ACPI_DEVICE_NOTIFY, acpi_ac_notify, 243 ACPI_ALL_NOTIFY, acpi_ac_notify,
241 ac); 244 ac);
242 if (ACPI_FAILURE(status)) { 245 if (ACPI_FAILURE(status)) {
243 result = -ENODEV; 246 result = -ENODEV;
@@ -268,8 +271,8 @@ static int acpi_ac_remove(struct acpi_device *device, int type)
268 271
269 ac = (struct acpi_ac *)acpi_driver_data(device); 272 ac = (struct acpi_ac *)acpi_driver_data(device);
270 273
271 status = acpi_remove_notify_handler(ac->handle, 274 status = acpi_remove_notify_handler(device->handle,
272 ACPI_DEVICE_NOTIFY, acpi_ac_notify); 275 ACPI_ALL_NOTIFY, acpi_ac_notify);
273 276
274 acpi_ac_remove_fs(device); 277 acpi_ac_remove_fs(device);
275 278
@@ -280,17 +283,18 @@ static int acpi_ac_remove(struct acpi_device *device, int type)
280 283
281static int __init acpi_ac_init(void) 284static int __init acpi_ac_init(void)
282{ 285{
283 int result = 0; 286 int result;
284 287
288 if (acpi_disabled)
289 return -ENODEV;
285 290
286 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir); 291 acpi_ac_dir = acpi_lock_ac_dir();
287 if (!acpi_ac_dir) 292 if (!acpi_ac_dir)
288 return -ENODEV; 293 return -ENODEV;
289 acpi_ac_dir->owner = THIS_MODULE;
290 294
291 result = acpi_bus_register_driver(&acpi_ac_driver); 295 result = acpi_bus_register_driver(&acpi_ac_driver);
292 if (result < 0) { 296 if (result < 0) {
293 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir); 297 acpi_unlock_ac_dir(acpi_ac_dir);
294 return -ENODEV; 298 return -ENODEV;
295 } 299 }
296 300
@@ -302,7 +306,7 @@ static void __exit acpi_ac_exit(void)
302 306
303 acpi_bus_unregister_driver(&acpi_ac_driver); 307 acpi_bus_unregister_driver(&acpi_ac_driver);
304 308
305 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir); 309 acpi_unlock_ac_dir(acpi_ac_dir);
306 310
307 return; 311 return;
308} 312}
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index cd57372a6729..1dda370f402b 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -80,7 +80,7 @@ struct acpi_memory_info {
80}; 80};
81 81
82struct acpi_memory_device { 82struct acpi_memory_device {
83 acpi_handle handle; 83 struct acpi_device * device;
84 unsigned int state; /* State of the memory device */ 84 unsigned int state; /* State of the memory device */
85 struct list_head res_list; 85 struct list_head res_list;
86}; 86};
@@ -129,11 +129,15 @@ acpi_memory_get_device_resources(struct acpi_memory_device *mem_device)
129 struct acpi_memory_info *info, *n; 129 struct acpi_memory_info *info, *n;
130 130
131 131
132 status = acpi_walk_resources(mem_device->handle, METHOD_NAME__CRS, 132 if (!list_empty(&mem_device->res_list))
133 return 0;
134
135 status = acpi_walk_resources(mem_device->device->handle, METHOD_NAME__CRS,
133 acpi_memory_get_resource, mem_device); 136 acpi_memory_get_resource, mem_device);
134 if (ACPI_FAILURE(status)) { 137 if (ACPI_FAILURE(status)) {
135 list_for_each_entry_safe(info, n, &mem_device->res_list, list) 138 list_for_each_entry_safe(info, n, &mem_device->res_list, list)
136 kfree(info); 139 kfree(info);
140 INIT_LIST_HEAD(&mem_device->res_list);
137 return -EINVAL; 141 return -EINVAL;
138 } 142 }
139 143
@@ -192,7 +196,7 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
192 196
193 197
194 /* Get device present/absent information from the _STA */ 198 /* Get device present/absent information from the _STA */
195 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->handle, "_STA", 199 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->device->handle, "_STA",
196 NULL, &current_status))) 200 NULL, &current_status)))
197 return -ENODEV; 201 return -ENODEV;
198 /* 202 /*
@@ -222,7 +226,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
222 return result; 226 return result;
223 } 227 }
224 228
225 node = acpi_get_node(mem_device->handle); 229 node = acpi_get_node(mem_device->device->handle);
226 /* 230 /*
227 * Tell the VM there is more memory here... 231 * Tell the VM there is more memory here...
228 * Note: Assume that this function returns zero on success 232 * Note: Assume that this function returns zero on success
@@ -230,17 +234,10 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
230 * (i.e. memory-hot-remove function) 234 * (i.e. memory-hot-remove function)
231 */ 235 */
232 list_for_each_entry(info, &mem_device->res_list, list) { 236 list_for_each_entry(info, &mem_device->res_list, list) {
233 u64 start_pfn, end_pfn; 237 if (info->enabled) { /* just sanity check...*/
234
235 start_pfn = info->start_addr >> PAGE_SHIFT;
236 end_pfn = (info->start_addr + info->length - 1) >> PAGE_SHIFT;
237
238 if (pfn_valid(start_pfn) || pfn_valid(end_pfn)) {
239 /* already enabled. try next area */
240 num_enabled++; 238 num_enabled++;
241 continue; 239 continue;
242 } 240 }
243
244 result = add_memory(node, info->start_addr, info->length); 241 result = add_memory(node, info->start_addr, info->length);
245 if (result) 242 if (result)
246 continue; 243 continue;
@@ -269,7 +266,7 @@ static int acpi_memory_powerdown_device(struct acpi_memory_device *mem_device)
269 arg_list.pointer = &arg; 266 arg_list.pointer = &arg;
270 arg.type = ACPI_TYPE_INTEGER; 267 arg.type = ACPI_TYPE_INTEGER;
271 arg.integer.value = 1; 268 arg.integer.value = 1;
272 status = acpi_evaluate_object(mem_device->handle, 269 status = acpi_evaluate_object(mem_device->device->handle,
273 "_EJ0", &arg_list, NULL); 270 "_EJ0", &arg_list, NULL);
274 /* Return on _EJ0 failure */ 271 /* Return on _EJ0 failure */
275 if (ACPI_FAILURE(status)) { 272 if (ACPI_FAILURE(status)) {
@@ -278,7 +275,7 @@ static int acpi_memory_powerdown_device(struct acpi_memory_device *mem_device)
278 } 275 }
279 276
280 /* Evalute _STA to check if the device is disabled */ 277 /* Evalute _STA to check if the device is disabled */
281 status = acpi_evaluate_integer(mem_device->handle, "_STA", 278 status = acpi_evaluate_integer(mem_device->device->handle, "_STA",
282 NULL, &current_status); 279 NULL, &current_status);
283 if (ACPI_FAILURE(status)) 280 if (ACPI_FAILURE(status))
284 return -ENODEV; 281 return -ENODEV;
@@ -398,7 +395,7 @@ static int acpi_memory_device_add(struct acpi_device *device)
398 memset(mem_device, 0, sizeof(struct acpi_memory_device)); 395 memset(mem_device, 0, sizeof(struct acpi_memory_device));
399 396
400 INIT_LIST_HEAD(&mem_device->res_list); 397 INIT_LIST_HEAD(&mem_device->res_list);
401 mem_device->handle = device->handle; 398 mem_device->device = device;
402 sprintf(acpi_device_name(device), "%s", ACPI_MEMORY_DEVICE_NAME); 399 sprintf(acpi_device_name(device), "%s", ACPI_MEMORY_DEVICE_NAME);
403 sprintf(acpi_device_class(device), "%s", ACPI_MEMORY_DEVICE_CLASS); 400 sprintf(acpi_device_class(device), "%s", ACPI_MEMORY_DEVICE_CLASS);
404 acpi_driver_data(device) = mem_device; 401 acpi_driver_data(device) = mem_device;
@@ -466,7 +463,7 @@ static acpi_status is_memory_device(acpi_handle handle)
466 463
467 info = buffer.pointer; 464 info = buffer.pointer;
468 if (!(info->valid & ACPI_VALID_HID)) { 465 if (!(info->valid & ACPI_VALID_HID)) {
469 acpi_os_free(buffer.pointer); 466 kfree(buffer.pointer);
470 return AE_ERROR; 467 return AE_ERROR;
471 } 468 }
472 469
@@ -475,7 +472,7 @@ static acpi_status is_memory_device(acpi_handle handle)
475 (strcmp(hardware_id, ACPI_MEMORY_DEVICE_HID))) 472 (strcmp(hardware_id, ACPI_MEMORY_DEVICE_HID)))
476 status = AE_ERROR; 473 status = AE_ERROR;
477 474
478 acpi_os_free(buffer.pointer); 475 kfree(buffer.pointer);
479 return status; 476 return status;
480} 477}
481 478
@@ -487,10 +484,8 @@ acpi_memory_register_notify_handler(acpi_handle handle,
487 484
488 485
489 status = is_memory_device(handle); 486 status = is_memory_device(handle);
490 if (ACPI_FAILURE(status)){ 487 if (ACPI_FAILURE(status))
491 ACPI_EXCEPTION((AE_INFO, status, "handle is no memory device"));
492 return AE_OK; /* continue */ 488 return AE_OK; /* continue */
493 }
494 489
495 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, 490 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
496 acpi_memory_device_notify, NULL); 491 acpi_memory_device_notify, NULL);
@@ -506,10 +501,8 @@ acpi_memory_deregister_notify_handler(acpi_handle handle,
506 501
507 502
508 status = is_memory_device(handle); 503 status = is_memory_device(handle);
509 if (ACPI_FAILURE(status)){ 504 if (ACPI_FAILURE(status))
510 ACPI_EXCEPTION((AE_INFO, status, "handle is no memory device"));
511 return AE_OK; /* continue */ 505 return AE_OK; /* continue */
512 }
513 506
514 status = acpi_remove_notify_handler(handle, 507 status = acpi_remove_notify_handler(handle,
515 ACPI_SYSTEM_NOTIFY, 508 ACPI_SYSTEM_NOTIFY,
diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c
index 055cfd5c8766..e9ee4c52a5f6 100644
--- a/drivers/acpi/asus_acpi.c
+++ b/drivers/acpi/asus_acpi.c
@@ -2,7 +2,7 @@
2 * asus_acpi.c - Asus Laptop ACPI Extras 2 * asus_acpi.c - Asus Laptop ACPI Extras
3 * 3 *
4 * 4 *
5 * Copyright (C) 2002, 2003, 2004 Julien Lerouge, Karol Kozimor 5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -26,11 +26,8 @@
26 * Pontus Fuchs - Helper functions, cleanup 26 * Pontus Fuchs - Helper functions, cleanup
27 * Johann Wiesner - Small compile fixes 27 * Johann Wiesner - Small compile fixes
28 * John Belmonte - ACPI code for Toshiba laptop was a good starting point. 28 * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
29 * Éric Burghard - LED display support for W1N
29 * 30 *
30 * TODO:
31 * add Fn key status
32 * Add mode selection on module loading (parameter) -> still necessary?
33 * Complete display switching -- may require dirty hacks or calling _DOS?
34 */ 31 */
35 32
36#include <linux/kernel.h> 33#include <linux/kernel.h>
@@ -42,12 +39,14 @@
42#include <acpi/acpi_bus.h> 39#include <acpi/acpi_bus.h>
43#include <asm/uaccess.h> 40#include <asm/uaccess.h>
44 41
45#define ASUS_ACPI_VERSION "0.29" 42#define ASUS_ACPI_VERSION "0.30"
46 43
47#define PROC_ASUS "asus" //the directory 44#define PROC_ASUS "asus" //the directory
48#define PROC_MLED "mled" 45#define PROC_MLED "mled"
49#define PROC_WLED "wled" 46#define PROC_WLED "wled"
50#define PROC_TLED "tled" 47#define PROC_TLED "tled"
48#define PROC_BT "bluetooth"
49#define PROC_LEDD "ledd"
51#define PROC_INFO "info" 50#define PROC_INFO "info"
52#define PROC_LCD "lcd" 51#define PROC_LCD "lcd"
53#define PROC_BRN "brn" 52#define PROC_BRN "brn"
@@ -67,9 +66,10 @@
67/* 66/*
68 * Flags for hotk status 67 * Flags for hotk status
69 */ 68 */
70#define MLED_ON 0x01 //is MLED ON ? 69#define MLED_ON 0x01 //mail LED
71#define WLED_ON 0x02 70#define WLED_ON 0x02 //wireless LED
72#define TLED_ON 0x04 71#define TLED_ON 0x04 //touchpad LED
72#define BT_ON 0x08 //internal Bluetooth
73 73
74MODULE_AUTHOR("Julien Lerouge, Karol Kozimor"); 74MODULE_AUTHOR("Julien Lerouge, Karol Kozimor");
75MODULE_DESCRIPTION(ACPI_HOTK_NAME); 75MODULE_DESCRIPTION(ACPI_HOTK_NAME);
@@ -92,7 +92,10 @@ struct model_data {
92 char *wled_status; //node to handle wled reading_______A 92 char *wled_status; //node to handle wled reading_______A
93 char *mt_tled; //method to handle tled_____________R 93 char *mt_tled; //method to handle tled_____________R
94 char *tled_status; //node to handle tled reading_______A 94 char *tled_status; //node to handle tled reading_______A
95 char *mt_lcd_switch; //method to turn LCD ON/OFF_________A 95 char *mt_ledd; //method to handle LED display______R
96 char *mt_bt_switch; //method to switch Bluetooth on/off_R
97 char *bt_status; //no model currently supports this__?
98 char *mt_lcd_switch; //method to turn LCD on/off_________A
96 char *lcd_status; //node to read LCD panel state______A 99 char *lcd_status; //node to read LCD panel state______A
97 char *brightness_up; //method to set brightness up_______A 100 char *brightness_up; //method to set brightness up_______A
98 char *brightness_down; //guess what ?______________________A 101 char *brightness_down; //guess what ?______________________A
@@ -111,27 +114,31 @@ struct asus_hotk {
111 struct acpi_device *device; //the device we are in 114 struct acpi_device *device; //the device we are in
112 acpi_handle handle; //the handle of the hotk device 115 acpi_handle handle; //the handle of the hotk device
113 char status; //status of the hotk, for LEDs, ... 116 char status; //status of the hotk, for LEDs, ...
117 u32 ledd_status; //status of the LED display
114 struct model_data *methods; //methods available on the laptop 118 struct model_data *methods; //methods available on the laptop
115 u8 brightness; //brightness level 119 u8 brightness; //brightness level
116 enum { 120 enum {
117 A1x = 0, //A1340D, A1300F 121 A1x = 0, //A1340D, A1300F
118 A2x, //A2500H 122 A2x, //A2500H
123 A4G, //A4700G
119 D1x, //D1 124 D1x, //D1
120 L2D, //L2000D 125 L2D, //L2000D
121 L3C, //L3800C 126 L3C, //L3800C
122 L3D, //L3400D 127 L3D, //L3400D
123 L3H, //L3H, but also L2000E 128 L3H, //L3H, L2000E, L5D
124 L4R, //L4500R 129 L4R, //L4500R
125 L5x, //L5800C 130 L5x, //L5800C
126 L8L, //L8400L 131 L8L, //L8400L
127 M1A, //M1300A 132 M1A, //M1300A
128 M2E, //M2400E, L4400L 133 M2E, //M2400E, L4400L
129 M6N, //M6800N 134 M6N, //M6800N, W3400N
130 M6R, //M6700R 135 M6R, //M6700R, A3000G
131 P30, //Samsung P30 136 P30, //Samsung P30
132 S1x, //S1300A, but also L1400B and M2400A (L84F) 137 S1x, //S1300A, but also L1400B and M2400A (L84F)
133 S2x, //S200 (J1 reported), Victor MP-XP7210 138 S2x, //S200 (J1 reported), Victor MP-XP7210
134 xxN, //M2400N, M3700N, M5200N, S1300N, S5200N, W1OOON 139 W1N, //W1000N
140 W5A, //W5A
141 xxN, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N
135 //(Centrino) 142 //(Centrino)
136 END_MODEL 143 END_MODEL
137 } model; //Models currently supported 144 } model; //Models currently supported
@@ -149,17 +156,8 @@ struct asus_hotk {
149 156
150static struct model_data model_conf[END_MODEL] = { 157static struct model_data model_conf[END_MODEL] = {
151 /* 158 /*
152 * Those pathnames are relative to the HOTK / ATKD device :
153 * - mt_mled
154 * - mt_wled
155 * - brightness_set
156 * - brightness_get
157 * - display_set
158 * - display_get
159 *
160 * TODO I have seen a SWBX and AIBX method on some models, like L1400B, 159 * TODO I have seen a SWBX and AIBX method on some models, like L1400B,
161 * it seems to be a kind of switch, but what for ? 160 * it seems to be a kind of switch, but what for ?
162 *
163 */ 161 */
164 162
165 { 163 {
@@ -184,6 +182,16 @@ static struct model_data model_conf[END_MODEL] = {
184 .display_get = "\\INFB"}, 182 .display_get = "\\INFB"},
185 183
186 { 184 {
185 .name = "A4G",
186 .mt_mled = "MLED",
187/* WLED present, but not controlled by ACPI */
188 .mt_lcd_switch = xxN_PREFIX "_Q10",
189 .brightness_set = "SPLV",
190 .brightness_get = "GPLV",
191 .display_set = "SDSP",
192 .display_get = "\\ADVG"},
193
194 {
187 .name = "D1x", 195 .name = "D1x",
188 .mt_mled = "MLED", 196 .mt_mled = "MLED",
189 .mt_lcd_switch = "\\Q0D", 197 .mt_lcd_switch = "\\Q0D",
@@ -302,7 +310,8 @@ static struct model_data model_conf[END_MODEL] = {
302 .brightness_set = "SPLV", 310 .brightness_set = "SPLV",
303 .brightness_get = "GPLV", 311 .brightness_get = "GPLV",
304 .display_set = "SDSP", 312 .display_set = "SDSP",
305 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"}, 313 .display_get = "\\SSTE"},
314
306 { 315 {
307 .name = "M6R", 316 .name = "M6R",
308 .mt_mled = "MLED", 317 .mt_mled = "MLED",
@@ -312,7 +321,7 @@ static struct model_data model_conf[END_MODEL] = {
312 .brightness_set = "SPLV", 321 .brightness_set = "SPLV",
313 .brightness_get = "GPLV", 322 .brightness_get = "GPLV",
314 .display_set = "SDSP", 323 .display_set = "SDSP",
315 .display_get = "\\SSTE"}, 324 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"},
316 325
317 { 326 {
318 .name = "P30", 327 .name = "P30",
@@ -345,6 +354,28 @@ static struct model_data model_conf[END_MODEL] = {
345 .brightness_down = S2x_PREFIX "_Q0A"}, 354 .brightness_down = S2x_PREFIX "_Q0A"},
346 355
347 { 356 {
357 .name = "W1N",
358 .mt_mled = "MLED",
359 .mt_wled = "WLED",
360 .mt_ledd = "SLCM",
361 .mt_lcd_switch = xxN_PREFIX "_Q10",
362 .lcd_status = "\\BKLT",
363 .brightness_set = "SPLV",
364 .brightness_get = "GPLV",
365 .display_set = "SDSP",
366 .display_get = "\\ADVG"},
367
368 {
369 .name = "W5A",
370 .mt_bt_switch = "BLED",
371 .mt_wled = "WLED",
372 .mt_lcd_switch = xxN_PREFIX "_Q10",
373 .brightness_set = "SPLV",
374 .brightness_get = "GPLV",
375 .display_set = "SDSP",
376 .display_get = "\\ADVG"},
377
378 {
348 .name = "xxN", 379 .name = "xxN",
349 .mt_mled = "MLED", 380 .mt_mled = "MLED",
350/* WLED present, but not controlled by ACPI */ 381/* WLED present, but not controlled by ACPI */
@@ -563,6 +594,36 @@ proc_write_mled(struct file *file, const char __user * buffer,
563} 594}
564 595
565/* 596/*
597 * Proc handlers for LED display
598 */
599static int
600proc_read_ledd(char *page, char **start, off_t off, int count, int *eof,
601 void *data)
602{
603 return sprintf(page, "0x%08x\n", hotk->ledd_status);
604}
605
606static int
607proc_write_ledd(struct file *file, const char __user * buffer,
608 unsigned long count, void *data)
609{
610 int value;
611
612 count = parse_arg(buffer, count, &value);
613 if (count > 0) {
614 if (!write_acpi_int
615 (hotk->handle, hotk->methods->mt_ledd, value, NULL))
616 printk(KERN_WARNING
617 "Asus ACPI: LED display write failed\n");
618 else
619 hotk->ledd_status = (u32) value;
620 } else if (count < 0)
621 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
622
623 return count;
624}
625
626/*
566 * Proc handlers for WLED 627 * Proc handlers for WLED
567 */ 628 */
568static int 629static int
@@ -581,6 +642,25 @@ proc_write_wled(struct file *file, const char __user * buffer,
581} 642}
582 643
583/* 644/*
645 * Proc handlers for Bluetooth
646 */
647static int
648proc_read_bluetooth(char *page, char **start, off_t off, int count, int *eof,
649 void *data)
650{
651 return sprintf(page, "%d\n", read_led(hotk->methods->bt_status, BT_ON));
652}
653
654static int
655proc_write_bluetooth(struct file *file, const char __user * buffer,
656 unsigned long count, void *data)
657{
658 /* Note: mt_bt_switch controls both internal Bluetooth adapter's
659 presence and its LED */
660 return write_led(buffer, count, hotk->methods->mt_bt_switch, BT_ON, 0);
661}
662
663/*
584 * Proc handlers for TLED 664 * Proc handlers for TLED
585 */ 665 */
586static int 666static int
@@ -876,6 +956,11 @@ static int asus_hotk_add_fs(struct acpi_device *device)
876 mode, device); 956 mode, device);
877 } 957 }
878 958
959 if (hotk->methods->mt_ledd) {
960 asus_proc_add(PROC_LEDD, &proc_write_ledd, &proc_read_ledd,
961 mode, device);
962 }
963
879 if (hotk->methods->mt_mled) { 964 if (hotk->methods->mt_mled) {
880 asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled, 965 asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled,
881 mode, device); 966 mode, device);
@@ -886,6 +971,11 @@ static int asus_hotk_add_fs(struct acpi_device *device)
886 mode, device); 971 mode, device);
887 } 972 }
888 973
974 if (hotk->methods->mt_bt_switch) {
975 asus_proc_add(PROC_BT, &proc_write_bluetooth,
976 &proc_read_bluetooth, mode, device);
977 }
978
889 /* 979 /*
890 * We need both read node and write method as LCD switch is also accessible 980 * We need both read node and write method as LCD switch is also accessible
891 * from keyboard 981 * from keyboard
@@ -919,6 +1009,10 @@ static int asus_hotk_remove_fs(struct acpi_device *device)
919 remove_proc_entry(PROC_MLED, acpi_device_dir(device)); 1009 remove_proc_entry(PROC_MLED, acpi_device_dir(device));
920 if (hotk->methods->mt_tled) 1010 if (hotk->methods->mt_tled)
921 remove_proc_entry(PROC_TLED, acpi_device_dir(device)); 1011 remove_proc_entry(PROC_TLED, acpi_device_dir(device));
1012 if (hotk->methods->mt_ledd)
1013 remove_proc_entry(PROC_LEDD, acpi_device_dir(device));
1014 if (hotk->methods->mt_bt_switch)
1015 remove_proc_entry(PROC_BT, acpi_device_dir(device));
922 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) 1016 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status)
923 remove_proc_entry(PROC_LCD, acpi_device_dir(device)); 1017 remove_proc_entry(PROC_LCD, acpi_device_dir(device));
924 if ((hotk->methods->brightness_up 1018 if ((hotk->methods->brightness_up
@@ -951,6 +1045,65 @@ static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
951} 1045}
952 1046
953/* 1047/*
1048 * Match the model string to the list of supported models. Return END_MODEL if
1049 * no match or model is NULL.
1050 */
1051static int asus_model_match(char *model)
1052{
1053 if (model == NULL)
1054 return END_MODEL;
1055
1056 if (strncmp(model, "L3D", 3) == 0)
1057 return L3D;
1058 else if (strncmp(model, "L2E", 3) == 0 ||
1059 strncmp(model, "L3H", 3) == 0 || strncmp(model, "L5D", 3) == 0)
1060 return L3H;
1061 else if (strncmp(model, "L3", 2) == 0 || strncmp(model, "L2B", 3) == 0)
1062 return L3C;
1063 else if (strncmp(model, "L8L", 3) == 0)
1064 return L8L;
1065 else if (strncmp(model, "L4R", 3) == 0)
1066 return L4R;
1067 else if (strncmp(model, "M6N", 3) == 0 || strncmp(model, "W3N", 3) == 0)
1068 return M6N;
1069 else if (strncmp(model, "M6R", 3) == 0 || strncmp(model, "A3G", 3) == 0)
1070 return M6R;
1071 else if (strncmp(model, "M2N", 3) == 0 ||
1072 strncmp(model, "M3N", 3) == 0 ||
1073 strncmp(model, "M5N", 3) == 0 ||
1074 strncmp(model, "M6N", 3) == 0 ||
1075 strncmp(model, "S1N", 3) == 0 ||
1076 strncmp(model, "S5N", 3) == 0 || strncmp(model, "W1N", 3) == 0)
1077 return xxN;
1078 else if (strncmp(model, "M1", 2) == 0)
1079 return M1A;
1080 else if (strncmp(model, "M2", 2) == 0 || strncmp(model, "L4E", 3) == 0)
1081 return M2E;
1082 else if (strncmp(model, "L2", 2) == 0)
1083 return L2D;
1084 else if (strncmp(model, "L8", 2) == 0)
1085 return S1x;
1086 else if (strncmp(model, "D1", 2) == 0)
1087 return D1x;
1088 else if (strncmp(model, "A1", 2) == 0)
1089 return A1x;
1090 else if (strncmp(model, "A2", 2) == 0)
1091 return A2x;
1092 else if (strncmp(model, "J1", 2) == 0)
1093 return S2x;
1094 else if (strncmp(model, "L5", 2) == 0)
1095 return L5x;
1096 else if (strncmp(model, "A4G", 3) == 0)
1097 return A4G;
1098 else if (strncmp(model, "W1N", 3) == 0)
1099 return W1N;
1100 else if (strncmp(model, "W5A", 3) == 0)
1101 return W5A;
1102 else
1103 return END_MODEL;
1104}
1105
1106/*
954 * This function is used to initialize the hotk with right values. In this 1107 * This function is used to initialize the hotk with right values. In this
955 * method, we can make all the detection we want, and modify the hotk struct 1108 * method, we can make all the detection we want, and modify the hotk struct
956 */ 1109 */
@@ -960,6 +1113,7 @@ static int asus_hotk_get_info(void)
960 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL }; 1113 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
961 union acpi_object *model = NULL; 1114 union acpi_object *model = NULL;
962 int bsts_result; 1115 int bsts_result;
1116 char *string = NULL;
963 acpi_status status; 1117 acpi_status status;
964 1118
965 /* 1119 /*
@@ -989,114 +1143,73 @@ static int asus_hotk_get_info(void)
989 printk(KERN_NOTICE " BSTS called, 0x%02x returned\n", 1143 printk(KERN_NOTICE " BSTS called, 0x%02x returned\n",
990 bsts_result); 1144 bsts_result);
991 1145
992 /* This is unlikely with implicit return */
993 if (buffer.pointer == NULL)
994 return -EINVAL;
995
996 model = (union acpi_object *) buffer.pointer;
997 /* 1146 /*
998 * Samsung P30 has a device with a valid _HID whose INIT does not 1147 * Try to match the object returned by INIT to the specific model.
999 * return anything. It used to be possible to catch this exception, 1148 * Handle every possible object (or the lack of thereof) the DSDT
1000 * but the implicit return code will now happily confuse the 1149 * writers might throw at us. When in trouble, we pass NULL to
1001 * driver. We assume that every ACPI_TYPE_STRING is a valid model 1150 * asus_model_match() and try something completely different.
1002 * identifier but it's still possible to get completely bogus data.
1003 */ 1151 */
1004 if (model->type == ACPI_TYPE_STRING) { 1152 if (buffer.pointer) {
1005 printk(KERN_NOTICE " %s model detected, ", model->string.pointer); 1153 model = (union acpi_object *)buffer.pointer;
1006 } else { 1154 switch (model->type) {
1007 if (asus_info && /* Samsung P30 */ 1155 case ACPI_TYPE_STRING:
1156 string = model->string.pointer;
1157 break;
1158 case ACPI_TYPE_BUFFER:
1159 string = model->buffer.pointer;
1160 break;
1161 default:
1162 kfree(model);
1163 break;
1164 }
1165 }
1166 hotk->model = asus_model_match(string);
1167 if (hotk->model == END_MODEL) { /* match failed */
1168 if (asus_info &&
1008 strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) { 1169 strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) {
1009 hotk->model = P30; 1170 hotk->model = P30;
1010 printk(KERN_NOTICE 1171 printk(KERN_NOTICE
1011 " Samsung P30 detected, supported\n"); 1172 " Samsung P30 detected, supported\n");
1012 } else { 1173 } else {
1013 hotk->model = M2E; 1174 hotk->model = M2E;
1014 printk(KERN_WARNING " no string returned by INIT\n"); 1175 printk(KERN_NOTICE " unsupported model %s, trying "
1015 printk(KERN_WARNING " trying default values, supply " 1176 "default values\n", string);
1016 "the developers with your DSDT\n"); 1177 printk(KERN_NOTICE
1178 " send /proc/acpi/dsdt to the developers\n");
1017 } 1179 }
1018 hotk->methods = &model_conf[hotk->model]; 1180 hotk->methods = &model_conf[hotk->model];
1019
1020 acpi_os_free(model);
1021
1022 return AE_OK; 1181 return AE_OK;
1023 } 1182 }
1024
1025 hotk->model = END_MODEL;
1026 if (strncmp(model->string.pointer, "L3D", 3) == 0)
1027 hotk->model = L3D;
1028 else if (strncmp(model->string.pointer, "L3H", 3) == 0 ||
1029 strncmp(model->string.pointer, "L2E", 3) == 0)
1030 hotk->model = L3H;
1031 else if (strncmp(model->string.pointer, "L3", 2) == 0 ||
1032 strncmp(model->string.pointer, "L2B", 3) == 0)
1033 hotk->model = L3C;
1034 else if (strncmp(model->string.pointer, "L8L", 3) == 0)
1035 hotk->model = L8L;
1036 else if (strncmp(model->string.pointer, "L4R", 3) == 0)
1037 hotk->model = L4R;
1038 else if (strncmp(model->string.pointer, "M6N", 3) == 0)
1039 hotk->model = M6N;
1040 else if (strncmp(model->string.pointer, "M6R", 3) == 0)
1041 hotk->model = M6R;
1042 else if (strncmp(model->string.pointer, "M2N", 3) == 0 ||
1043 strncmp(model->string.pointer, "M3N", 3) == 0 ||
1044 strncmp(model->string.pointer, "M5N", 3) == 0 ||
1045 strncmp(model->string.pointer, "M6N", 3) == 0 ||
1046 strncmp(model->string.pointer, "S1N", 3) == 0 ||
1047 strncmp(model->string.pointer, "S5N", 3) == 0 ||
1048 strncmp(model->string.pointer, "W1N", 3) == 0)
1049 hotk->model = xxN;
1050 else if (strncmp(model->string.pointer, "M1", 2) == 0)
1051 hotk->model = M1A;
1052 else if (strncmp(model->string.pointer, "M2", 2) == 0 ||
1053 strncmp(model->string.pointer, "L4E", 3) == 0)
1054 hotk->model = M2E;
1055 else if (strncmp(model->string.pointer, "L2", 2) == 0)
1056 hotk->model = L2D;
1057 else if (strncmp(model->string.pointer, "L8", 2) == 0)
1058 hotk->model = S1x;
1059 else if (strncmp(model->string.pointer, "D1", 2) == 0)
1060 hotk->model = D1x;
1061 else if (strncmp(model->string.pointer, "A1", 2) == 0)
1062 hotk->model = A1x;
1063 else if (strncmp(model->string.pointer, "A2", 2) == 0)
1064 hotk->model = A2x;
1065 else if (strncmp(model->string.pointer, "J1", 2) == 0)
1066 hotk->model = S2x;
1067 else if (strncmp(model->string.pointer, "L5", 2) == 0)
1068 hotk->model = L5x;
1069
1070 if (hotk->model == END_MODEL) {
1071 printk("unsupported, trying default values, supply the "
1072 "developers with your DSDT\n");
1073 hotk->model = M2E;
1074 } else {
1075 printk("supported\n");
1076 }
1077
1078 hotk->methods = &model_conf[hotk->model]; 1183 hotk->methods = &model_conf[hotk->model];
1184 printk(KERN_NOTICE " %s model detected, supported\n", string);
1079 1185
1080 /* Sort of per-model blacklist */ 1186 /* Sort of per-model blacklist */
1081 if (strncmp(model->string.pointer, "L2B", 3) == 0) 1187 if (strncmp(string, "L2B", 3) == 0)
1082 hotk->methods->lcd_status = NULL; 1188 hotk->methods->lcd_status = NULL;
1083 /* L2B is similar enough to L3C to use its settings, with this only 1189 /* L2B is similar enough to L3C to use its settings, with this only
1084 exception */ 1190 exception */
1085 else if (strncmp(model->string.pointer, "S5N", 3) == 0 || 1191 else if (strncmp(string, "A3G", 3) == 0)
1086 strncmp(model->string.pointer, "M5N", 3) == 0) 1192 hotk->methods->lcd_status = "\\BLFG";
1193 /* A3G is like M6R */
1194 else if (strncmp(string, "S5N", 3) == 0 ||
1195 strncmp(string, "M5N", 3) == 0 ||
1196 strncmp(string, "W3N", 3) == 0)
1087 hotk->methods->mt_mled = NULL; 1197 hotk->methods->mt_mled = NULL;
1088 /* S5N and M5N have no MLED */ 1198 /* S5N, M5N and W3N have no MLED */
1089 else if (strncmp(model->string.pointer, "M2N", 3) == 0 || 1199 else if (strncmp(string, "L5D", 3) == 0)
1090 strncmp(model->string.pointer, "W1N", 3) == 0) 1200 hotk->methods->mt_wled = NULL;
1201 /* L5D's WLED is not controlled by ACPI */
1202 else if (strncmp(string, "M2N", 3) == 0 ||
1203 strncmp(string, "S1N", 3) == 0)
1091 hotk->methods->mt_wled = "WLED"; 1204 hotk->methods->mt_wled = "WLED";
1092 /* M2N and W1N have a usable WLED */ 1205 /* M2N and S1N have a usable WLED */
1093 else if (asus_info) { 1206 else if (asus_info) {
1094 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0) 1207 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0)
1095 hotk->methods->mled_status = NULL; 1208 hotk->methods->mled_status = NULL;
1096 /* S1300A reports L84F, but L1400B too, account for that */ 1209 /* S1300A reports L84F, but L1400B too, account for that */
1097 } 1210 }
1098 1211
1099 acpi_os_free(model); 1212 kfree(model);
1100 1213
1101 return AE_OK; 1214 return AE_OK;
1102} 1215}
@@ -1164,8 +1277,7 @@ static int asus_hotk_add(struct acpi_device *device)
1164 /* For laptops without GPLV: init the hotk->brightness value */ 1277 /* For laptops without GPLV: init the hotk->brightness value */
1165 if ((!hotk->methods->brightness_get) 1278 if ((!hotk->methods->brightness_get)
1166 && (!hotk->methods->brightness_status) 1279 && (!hotk->methods->brightness_status)
1167 && (hotk->methods->brightness_up 1280 && (hotk->methods->brightness_up && hotk->methods->brightness_down)) {
1168 && hotk->methods->brightness_down)) {
1169 status = 1281 status =
1170 acpi_evaluate_object(NULL, hotk->methods->brightness_down, 1282 acpi_evaluate_object(NULL, hotk->methods->brightness_down,
1171 NULL, NULL); 1283 NULL, NULL);
@@ -1184,6 +1296,9 @@ static int asus_hotk_add(struct acpi_device *device)
1184 1296
1185 asus_hotk_found = 1; 1297 asus_hotk_found = 1;
1186 1298
1299 /* LED display is off by default */
1300 hotk->ledd_status = 0xFFF;
1301
1187 end: 1302 end:
1188 if (result) { 1303 if (result) {
1189 kfree(hotk); 1304 kfree(hotk);
@@ -1256,7 +1371,7 @@ static void __exit asus_acpi_exit(void)
1256 acpi_bus_unregister_driver(&asus_hotk_driver); 1371 acpi_bus_unregister_driver(&asus_hotk_driver);
1257 remove_proc_entry(PROC_ASUS, acpi_root_dir); 1372 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1258 1373
1259 acpi_os_free(asus_info); 1374 kfree(asus_info);
1260 1375
1261 return; 1376 return;
1262} 1377}
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 00b0728efe82..9810e2a55d0a 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -59,6 +59,9 @@ ACPI_MODULE_NAME("acpi_battery")
59MODULE_DESCRIPTION(ACPI_BATTERY_DRIVER_NAME); 59MODULE_DESCRIPTION(ACPI_BATTERY_DRIVER_NAME);
60MODULE_LICENSE("GPL"); 60MODULE_LICENSE("GPL");
61 61
62extern struct proc_dir_entry *acpi_lock_battery_dir(void);
63extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
64
62static int acpi_battery_add(struct acpi_device *device); 65static int acpi_battery_add(struct acpi_device *device);
63static int acpi_battery_remove(struct acpi_device *device, int type); 66static int acpi_battery_remove(struct acpi_device *device, int type);
64 67
@@ -108,7 +111,7 @@ struct acpi_battery_trips {
108}; 111};
109 112
110struct acpi_battery { 113struct acpi_battery {
111 acpi_handle handle; 114 struct acpi_device * device;
112 struct acpi_battery_flags flags; 115 struct acpi_battery_flags flags;
113 struct acpi_battery_trips trips; 116 struct acpi_battery_trips trips;
114 unsigned long alarm; 117 unsigned long alarm;
@@ -138,7 +141,7 @@ acpi_battery_get_info(struct acpi_battery *battery,
138 141
139 /* Evalute _BIF */ 142 /* Evalute _BIF */
140 143
141 status = acpi_evaluate_object(battery->handle, "_BIF", NULL, &buffer); 144 status = acpi_evaluate_object(battery->device->handle, "_BIF", NULL, &buffer);
142 if (ACPI_FAILURE(status)) { 145 if (ACPI_FAILURE(status)) {
143 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF")); 146 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF"));
144 return -ENODEV; 147 return -ENODEV;
@@ -171,7 +174,7 @@ acpi_battery_get_info(struct acpi_battery *battery,
171 } 174 }
172 175
173 end: 176 end:
174 acpi_os_free(buffer.pointer); 177 kfree(buffer.pointer);
175 178
176 if (!result) 179 if (!result)
177 (*bif) = (struct acpi_battery_info *)data.pointer; 180 (*bif) = (struct acpi_battery_info *)data.pointer;
@@ -198,7 +201,7 @@ acpi_battery_get_status(struct acpi_battery *battery,
198 201
199 /* Evalute _BST */ 202 /* Evalute _BST */
200 203
201 status = acpi_evaluate_object(battery->handle, "_BST", NULL, &buffer); 204 status = acpi_evaluate_object(battery->device->handle, "_BST", NULL, &buffer);
202 if (ACPI_FAILURE(status)) { 205 if (ACPI_FAILURE(status)) {
203 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST")); 206 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST"));
204 return -ENODEV; 207 return -ENODEV;
@@ -231,7 +234,7 @@ acpi_battery_get_status(struct acpi_battery *battery,
231 } 234 }
232 235
233 end: 236 end:
234 acpi_os_free(buffer.pointer); 237 kfree(buffer.pointer);
235 238
236 if (!result) 239 if (!result)
237 (*bst) = (struct acpi_battery_status *)data.pointer; 240 (*bst) = (struct acpi_battery_status *)data.pointer;
@@ -255,7 +258,7 @@ acpi_battery_set_alarm(struct acpi_battery *battery, unsigned long alarm)
255 258
256 arg0.integer.value = alarm; 259 arg0.integer.value = alarm;
257 260
258 status = acpi_evaluate_object(battery->handle, "_BTP", &arg_list, NULL); 261 status = acpi_evaluate_object(battery->device->handle, "_BTP", &arg_list, NULL);
259 if (ACPI_FAILURE(status)) 262 if (ACPI_FAILURE(status))
260 return -ENODEV; 263 return -ENODEV;
261 264
@@ -278,9 +281,7 @@ static int acpi_battery_check(struct acpi_battery *battery)
278 if (!battery) 281 if (!battery)
279 return -EINVAL; 282 return -EINVAL;
280 283
281 result = acpi_bus_get_device(battery->handle, &device); 284 device = battery->device;
282 if (result)
283 return result;
284 285
285 result = acpi_bus_get_status(device); 286 result = acpi_bus_get_status(device);
286 if (result) 287 if (result)
@@ -305,7 +306,7 @@ static int acpi_battery_check(struct acpi_battery *battery)
305 306
306 /* See if alarms are supported, and if so, set default */ 307 /* See if alarms are supported, and if so, set default */
307 308
308 status = acpi_get_handle(battery->handle, "_BTP", &handle); 309 status = acpi_get_handle(battery->device->handle, "_BTP", &handle);
309 if (ACPI_SUCCESS(status)) { 310 if (ACPI_SUCCESS(status)) {
310 battery->flags.alarm = 1; 311 battery->flags.alarm = 1;
311 acpi_battery_set_alarm(battery, battery->trips.warning); 312 acpi_battery_set_alarm(battery, battery->trips.warning);
@@ -556,7 +557,7 @@ static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file)
556 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data); 557 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data);
557} 558}
558 559
559static struct file_operations acpi_battery_info_ops = { 560static const struct file_operations acpi_battery_info_ops = {
560 .open = acpi_battery_info_open_fs, 561 .open = acpi_battery_info_open_fs,
561 .read = seq_read, 562 .read = seq_read,
562 .llseek = seq_lseek, 563 .llseek = seq_lseek,
@@ -564,7 +565,7 @@ static struct file_operations acpi_battery_info_ops = {
564 .owner = THIS_MODULE, 565 .owner = THIS_MODULE,
565}; 566};
566 567
567static struct file_operations acpi_battery_state_ops = { 568static const struct file_operations acpi_battery_state_ops = {
568 .open = acpi_battery_state_open_fs, 569 .open = acpi_battery_state_open_fs,
569 .read = seq_read, 570 .read = seq_read,
570 .llseek = seq_lseek, 571 .llseek = seq_lseek,
@@ -572,7 +573,7 @@ static struct file_operations acpi_battery_state_ops = {
572 .owner = THIS_MODULE, 573 .owner = THIS_MODULE,
573}; 574};
574 575
575static struct file_operations acpi_battery_alarm_ops = { 576static const struct file_operations acpi_battery_alarm_ops = {
576 .open = acpi_battery_alarm_open_fs, 577 .open = acpi_battery_alarm_open_fs,
577 .read = seq_read, 578 .read = seq_read,
578 .write = acpi_battery_write_alarm, 579 .write = acpi_battery_write_alarm,
@@ -662,12 +663,13 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
662 if (!battery) 663 if (!battery)
663 return; 664 return;
664 665
665 if (acpi_bus_get_device(handle, &device)) 666 device = battery->device;
666 return;
667 667
668 switch (event) { 668 switch (event) {
669 case ACPI_BATTERY_NOTIFY_STATUS: 669 case ACPI_BATTERY_NOTIFY_STATUS:
670 case ACPI_BATTERY_NOTIFY_INFO: 670 case ACPI_BATTERY_NOTIFY_INFO:
671 case ACPI_NOTIFY_BUS_CHECK:
672 case ACPI_NOTIFY_DEVICE_CHECK:
671 acpi_battery_check(battery); 673 acpi_battery_check(battery);
672 acpi_bus_generate_event(device, event, battery->flags.present); 674 acpi_bus_generate_event(device, event, battery->flags.present);
673 break; 675 break;
@@ -695,7 +697,7 @@ static int acpi_battery_add(struct acpi_device *device)
695 return -ENOMEM; 697 return -ENOMEM;
696 memset(battery, 0, sizeof(struct acpi_battery)); 698 memset(battery, 0, sizeof(struct acpi_battery));
697 699
698 battery->handle = device->handle; 700 battery->device = device;
699 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); 701 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
700 strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); 702 strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
701 acpi_driver_data(device) = battery; 703 acpi_driver_data(device) = battery;
@@ -708,8 +710,8 @@ static int acpi_battery_add(struct acpi_device *device)
708 if (result) 710 if (result)
709 goto end; 711 goto end;
710 712
711 status = acpi_install_notify_handler(battery->handle, 713 status = acpi_install_notify_handler(device->handle,
712 ACPI_DEVICE_NOTIFY, 714 ACPI_ALL_NOTIFY,
713 acpi_battery_notify, battery); 715 acpi_battery_notify, battery);
714 if (ACPI_FAILURE(status)) { 716 if (ACPI_FAILURE(status)) {
715 result = -ENODEV; 717 result = -ENODEV;
@@ -740,8 +742,8 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
740 742
741 battery = (struct acpi_battery *)acpi_driver_data(device); 743 battery = (struct acpi_battery *)acpi_driver_data(device);
742 744
743 status = acpi_remove_notify_handler(battery->handle, 745 status = acpi_remove_notify_handler(device->handle,
744 ACPI_DEVICE_NOTIFY, 746 ACPI_ALL_NOTIFY,
745 acpi_battery_notify); 747 acpi_battery_notify);
746 748
747 acpi_battery_remove_fs(device); 749 acpi_battery_remove_fs(device);
@@ -753,17 +755,18 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
753 755
754static int __init acpi_battery_init(void) 756static int __init acpi_battery_init(void)
755{ 757{
756 int result = 0; 758 int result;
757 759
760 if (acpi_disabled)
761 return -ENODEV;
758 762
759 acpi_battery_dir = proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir); 763 acpi_battery_dir = acpi_lock_battery_dir();
760 if (!acpi_battery_dir) 764 if (!acpi_battery_dir)
761 return -ENODEV; 765 return -ENODEV;
762 acpi_battery_dir->owner = THIS_MODULE;
763 766
764 result = acpi_bus_register_driver(&acpi_battery_driver); 767 result = acpi_bus_register_driver(&acpi_battery_driver);
765 if (result < 0) { 768 if (result < 0) {
766 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir); 769 acpi_unlock_battery_dir(acpi_battery_dir);
767 return -ENODEV; 770 return -ENODEV;
768 } 771 }
769 772
@@ -775,7 +778,7 @@ static void __exit acpi_battery_exit(void)
775 778
776 acpi_bus_unregister_driver(&acpi_battery_driver); 779 acpi_bus_unregister_driver(&acpi_battery_driver);
777 780
778 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir); 781 acpi_unlock_battery_dir(acpi_battery_dir);
779 782
780 return; 783 return;
781} 784}
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index ea5a0496a4fd..279c4bac92e5 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/ioport.h> 27#include <linux/ioport.h>
28#include <linux/kernel.h>
28#include <linux/list.h> 29#include <linux/list.h>
29#include <linux/sched.h> 30#include <linux/sched.h>
30#include <linux/pm.h> 31#include <linux/pm.h>
@@ -68,7 +69,8 @@ int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
68 69
69 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device); 70 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
70 if (ACPI_FAILURE(status) || !*device) { 71 if (ACPI_FAILURE(status) || !*device) {
71 ACPI_EXCEPTION((AE_INFO, status, "No context for object [%p]", handle)); 72 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
73 handle));
72 return -ENODEV; 74 return -ENODEV;
73 } 75 }
74 76
@@ -192,8 +194,8 @@ int acpi_bus_set_power(acpi_handle handle, int state)
192 /* Make sure this is a valid target state */ 194 /* Make sure this is a valid target state */
193 195
194 if (!device->flags.power_manageable) { 196 if (!device->flags.power_manageable) {
195 printk(KERN_DEBUG "Device `[%s]' is not power manageable", 197 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
196 device->kobj.name); 198 device->kobj.name));
197 return -ENODEV; 199 return -ENODEV;
198 } 200 }
199 /* 201 /*
@@ -738,7 +740,10 @@ static int __init acpi_init(void)
738 return -ENODEV; 740 return -ENODEV;
739 } 741 }
740 742
741 firmware_register(&acpi_subsys); 743 result = firmware_register(&acpi_subsys);
744 if (result < 0)
745 printk(KERN_WARNING "%s: firmware_register error: %d\n",
746 __FUNCTION__, result);
742 747
743 result = acpi_bus_init(); 748 result = acpi_bus_init();
744 749
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 02594639c4d9..5ef885e82c78 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -82,20 +82,19 @@ static struct acpi_driver acpi_button_driver = {
82}; 82};
83 83
84struct acpi_button { 84struct acpi_button {
85 acpi_handle handle;
86 struct acpi_device *device; /* Fixed button kludge */ 85 struct acpi_device *device; /* Fixed button kludge */
87 u8 type; 86 u8 type;
88 unsigned long pushed; 87 unsigned long pushed;
89}; 88};
90 89
91static struct file_operations acpi_button_info_fops = { 90static const struct file_operations acpi_button_info_fops = {
92 .open = acpi_button_info_open_fs, 91 .open = acpi_button_info_open_fs,
93 .read = seq_read, 92 .read = seq_read,
94 .llseek = seq_lseek, 93 .llseek = seq_lseek,
95 .release = single_release, 94 .release = single_release,
96}; 95};
97 96
98static struct file_operations acpi_button_state_fops = { 97static const struct file_operations acpi_button_state_fops = {
99 .open = acpi_button_state_open_fs, 98 .open = acpi_button_state_open_fs,
100 .read = seq_read, 99 .read = seq_read,
101 .llseek = seq_lseek, 100 .llseek = seq_lseek,
@@ -137,7 +136,7 @@ static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
137 if (!button || !button->device) 136 if (!button || !button->device)
138 return 0; 137 return 0;
139 138
140 status = acpi_evaluate_integer(button->handle, "_LID", NULL, &state); 139 status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, &state);
141 if (ACPI_FAILURE(status)) { 140 if (ACPI_FAILURE(status)) {
142 seq_printf(seq, "state: unsupported\n"); 141 seq_printf(seq, "state: unsupported\n");
143 } else { 142 } else {
@@ -282,7 +281,7 @@ static acpi_status acpi_button_notify_fixed(void *data)
282 if (!button) 281 if (!button)
283 return AE_BAD_PARAMETER; 282 return AE_BAD_PARAMETER;
284 283
285 acpi_button_notify(button->handle, ACPI_BUTTON_NOTIFY_STATUS, button); 284 acpi_button_notify(button->device->handle, ACPI_BUTTON_NOTIFY_STATUS, button);
286 285
287 return AE_OK; 286 return AE_OK;
288} 287}
@@ -303,7 +302,6 @@ static int acpi_button_add(struct acpi_device *device)
303 memset(button, 0, sizeof(struct acpi_button)); 302 memset(button, 0, sizeof(struct acpi_button));
304 303
305 button->device = device; 304 button->device = device;
306 button->handle = device->handle;
307 acpi_driver_data(device) = button; 305 acpi_driver_data(device) = button;
308 306
309 /* 307 /*
@@ -362,7 +360,7 @@ static int acpi_button_add(struct acpi_device *device)
362 button); 360 button);
363 break; 361 break;
364 default: 362 default:
365 status = acpi_install_notify_handler(button->handle, 363 status = acpi_install_notify_handler(device->handle,
366 ACPI_DEVICE_NOTIFY, 364 ACPI_DEVICE_NOTIFY,
367 acpi_button_notify, 365 acpi_button_notify,
368 button); 366 button);
@@ -420,7 +418,7 @@ static int acpi_button_remove(struct acpi_device *device, int type)
420 acpi_button_notify_fixed); 418 acpi_button_notify_fixed);
421 break; 419 break;
422 default: 420 default:
423 status = acpi_remove_notify_handler(button->handle, 421 status = acpi_remove_notify_handler(device->handle,
424 ACPI_DEVICE_NOTIFY, 422 ACPI_DEVICE_NOTIFY,
425 acpi_button_notify); 423 acpi_button_notify);
426 break; 424 break;
diff --git a/drivers/acpi/cm_sbs.c b/drivers/acpi/cm_sbs.c
new file mode 100644
index 000000000000..a01ce6700bfe
--- /dev/null
+++ b/drivers/acpi/cm_sbs.c
@@ -0,0 +1,113 @@
1/*
2 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * 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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/acpi.h>
25#include <linux/types.h>
26#include <linux/proc_fs.h>
27#include <linux/seq_file.h>
28#include <acpi/acpi_bus.h>
29#include <acpi/acpi_drivers.h>
30#include <acpi/acmacros.h>
31#include <acpi/actypes.h>
32#include <acpi/acutils.h>
33
34ACPI_MODULE_NAME("cm_sbs")
35#define ACPI_AC_CLASS "ac_adapter"
36#define ACPI_BATTERY_CLASS "battery"
37#define ACPI_SBS_COMPONENT 0x00080000
38#define _COMPONENT ACPI_SBS_COMPONENT
39static struct proc_dir_entry *acpi_ac_dir;
40static struct proc_dir_entry *acpi_battery_dir;
41
42static DEFINE_MUTEX(cm_sbs_mutex);
43
44static int lock_ac_dir_cnt;
45static int lock_battery_dir_cnt;
46
47struct proc_dir_entry *acpi_lock_ac_dir(void)
48{
49 mutex_lock(&cm_sbs_mutex);
50 if (!acpi_ac_dir)
51 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
52 if (acpi_ac_dir) {
53 lock_ac_dir_cnt++;
54 } else {
55 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
56 "Cannot create %s\n", ACPI_AC_CLASS));
57 }
58 mutex_unlock(&cm_sbs_mutex);
59 return acpi_ac_dir;
60}
61EXPORT_SYMBOL(acpi_lock_ac_dir);
62
63void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param)
64{
65 mutex_lock(&cm_sbs_mutex);
66 if (acpi_ac_dir_param)
67 lock_ac_dir_cnt--;
68 if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) {
69 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
70 acpi_ac_dir = 0;
71 }
72 mutex_unlock(&cm_sbs_mutex);
73}
74EXPORT_SYMBOL(acpi_unlock_ac_dir);
75
76struct proc_dir_entry *acpi_lock_battery_dir(void)
77{
78 mutex_lock(&cm_sbs_mutex);
79 if (!acpi_battery_dir) {
80 acpi_battery_dir =
81 proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir);
82 }
83 if (acpi_battery_dir) {
84 lock_battery_dir_cnt++;
85 } else {
86 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
87 "Cannot create %s\n", ACPI_BATTERY_CLASS));
88 }
89 mutex_unlock(&cm_sbs_mutex);
90 return acpi_battery_dir;
91}
92EXPORT_SYMBOL(acpi_lock_battery_dir);
93
94void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param)
95{
96 mutex_lock(&cm_sbs_mutex);
97 if (acpi_battery_dir_param)
98 lock_battery_dir_cnt--;
99 if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param
100 && acpi_battery_dir) {
101 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir);
102 acpi_battery_dir = 0;
103 }
104 mutex_unlock(&cm_sbs_mutex);
105 return;
106}
107EXPORT_SYMBOL(acpi_unlock_battery_dir);
108
109static int __init acpi_cm_sbs_init(void)
110{
111 return 0;
112}
113subsys_initcall(acpi_cm_sbs_init);
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 7f7e41d40a3b..871aa520ece7 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -236,7 +236,7 @@ container_walk_namespace_cb(acpi_handle handle,
236 } 236 }
237 237
238 end: 238 end:
239 acpi_os_free(buffer.pointer); 239 kfree(buffer.pointer);
240 240
241 return AE_OK; 241 return AE_OK;
242} 242}
diff --git a/drivers/acpi/dispatcher/dsinit.c b/drivers/acpi/dispatcher/dsinit.c
index daf51b5b5875..1888c055d10f 100644
--- a/drivers/acpi/dispatcher/dsinit.c
+++ b/drivers/acpi/dispatcher/dsinit.c
@@ -116,16 +116,6 @@ acpi_ds_init_one_object(acpi_handle obj_handle,
116 116
117 case ACPI_TYPE_METHOD: 117 case ACPI_TYPE_METHOD:
118 118
119 /*
120 * Set the execution data width (32 or 64) based upon the
121 * revision number of the parent ACPI table.
122 * TBD: This is really for possible future support of integer width
123 * on a per-table basis. Currently, we just use a global for the width.
124 */
125 if (info->table_desc->pointer->revision == 1) {
126 node->flags |= ANOBJ_DATA_WIDTH_32;
127 }
128
129 info->method_count++; 119 info->method_count++;
130 break; 120 break;
131 121
diff --git a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c
index a39a33f4847a..cf888add3191 100644
--- a/drivers/acpi/dispatcher/dsmethod.c
+++ b/drivers/acpi/dispatcher/dsmethod.c
@@ -134,7 +134,7 @@ acpi_ds_create_method_mutex(union acpi_operand_object *method_desc)
134 union acpi_operand_object *mutex_desc; 134 union acpi_operand_object *mutex_desc;
135 acpi_status status; 135 acpi_status status;
136 136
137 ACPI_FUNCTION_NAME(ds_create_method_mutex); 137 ACPI_FUNCTION_TRACE(ds_create_method_mutex);
138 138
139 /* Create the new mutex object */ 139 /* Create the new mutex object */
140 140
@@ -493,7 +493,7 @@ acpi_ds_restart_control_method(struct acpi_walk_state *walk_state,
493 493
494 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 494 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
495 "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n", 495 "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
496 (char *)&walk_state->method_node->name, 496 acpi_ut_get_node_name(walk_state->method_node),
497 walk_state->method_call_op, return_desc)); 497 walk_state->method_call_op, return_desc));
498 498
499 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 499 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
@@ -610,6 +610,7 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
610 610
611 acpi_os_release_mutex(method_desc->method.mutex->mutex. 611 acpi_os_release_mutex(method_desc->method.mutex->mutex.
612 os_mutex); 612 os_mutex);
613 method_desc->method.mutex->mutex.owner_thread = NULL;
613 } 614 }
614 } 615 }
615 616
@@ -620,27 +621,11 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
620 */ 621 */
621 method_node = walk_state->method_node; 622 method_node = walk_state->method_node;
622 623
623 /* Lock namespace for possible update */
624
625 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
626 if (ACPI_FAILURE(status)) {
627 return_VOID;
628 }
629
630 /*
631 * Delete any namespace entries created immediately underneath
632 * the method
633 */
634 if (method_node && method_node->child) {
635 acpi_ns_delete_namespace_subtree(method_node);
636 }
637
638 /* 624 /*
639 * Delete any namespace entries created anywhere else within 625 * Delete any namespace objects created anywhere within
640 * the namespace by the execution of this method 626 * the namespace by the execution of this method
641 */ 627 */
642 acpi_ns_delete_namespace_by_owner(method_desc->method.owner_id); 628 acpi_ns_delete_namespace_by_owner(method_desc->method.owner_id);
643 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
644 } 629 }
645 630
646 /* Decrement the thread count on the method */ 631 /* Decrement the thread count on the method */
diff --git a/drivers/acpi/dispatcher/dswexec.c b/drivers/acpi/dispatcher/dswexec.c
index b1ded62d0df1..d7a616c3104e 100644
--- a/drivers/acpi/dispatcher/dswexec.c
+++ b/drivers/acpi/dispatcher/dswexec.c
@@ -313,10 +313,10 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
313 case AML_CLASS_EXECUTE: 313 case AML_CLASS_EXECUTE:
314 case AML_CLASS_CREATE: 314 case AML_CLASS_CREATE:
315 /* 315 /*
316 * Most operators with arguments. 316 * Most operators with arguments (except create_xxx_field operators)
317 * Start a new result/operand state 317 * Start a new result/operand state
318 */ 318 */
319 if (walk_state->opcode != AML_CREATE_FIELD_OP) { 319 if (walk_state->op_info->object_type != ACPI_TYPE_BUFFER_FIELD) {
320 status = acpi_ds_result_stack_push(walk_state); 320 status = acpi_ds_result_stack_push(walk_state);
321 } 321 }
322 break; 322 break;
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 510a94524298..578b99b71d9c 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -58,8 +58,8 @@ struct dock_dependent_device {
58}; 58};
59 59
60#define DOCK_DOCKING 0x00000001 60#define DOCK_DOCKING 0x00000001
61#define DOCK_EVENT KOBJ_DOCK 61#define DOCK_EVENT 3
62#define UNDOCK_EVENT KOBJ_UNDOCK 62#define UNDOCK_EVENT 2
63 63
64static struct dock_station *dock_station; 64static struct dock_station *dock_station;
65 65
@@ -322,11 +322,10 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event)
322 322
323static void dock_event(struct dock_station *ds, u32 event, int num) 323static void dock_event(struct dock_station *ds, u32 event, int num)
324{ 324{
325 struct acpi_device *device; 325 /*
326 326 * we don't do events until someone tells me that
327 device = dock_create_acpi_device(ds->handle); 327 * they would like to have them.
328 if (device) 328 */
329 kobject_uevent(&device->kobj, num);
330} 329}
331 330
332/** 331/**
@@ -627,6 +626,7 @@ static int dock_add(acpi_handle handle)
627 INIT_LIST_HEAD(&dock_station->hotplug_devices); 626 INIT_LIST_HEAD(&dock_station->hotplug_devices);
628 spin_lock_init(&dock_station->dd_lock); 627 spin_lock_init(&dock_station->dd_lock);
629 spin_lock_init(&dock_station->hp_lock); 628 spin_lock_init(&dock_station->hp_lock);
629 ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list);
630 630
631 /* Find dependent devices */ 631 /* Find dependent devices */
632 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 632 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 8c5d7df7d343..e5d796362854 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -929,7 +929,7 @@ static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
929 return single_open(file, acpi_ec_read_info, PDE(inode)->data); 929 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
930} 930}
931 931
932static struct file_operations acpi_ec_info_ops = { 932static const struct file_operations acpi_ec_info_ops = {
933 .open = acpi_ec_info_open_fs, 933 .open = acpi_ec_info_open_fs,
934 .read = seq_read, 934 .read = seq_read,
935 .llseek = seq_lseek, 935 .llseek = seq_lseek,
diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c
index a901b23e95e7..959a893c8d1f 100644
--- a/drivers/acpi/event.c
+++ b/drivers/acpi/event.c
@@ -99,7 +99,7 @@ static unsigned int acpi_system_poll_event(struct file *file, poll_table * wait)
99 return 0; 99 return 0;
100} 100}
101 101
102static struct file_operations acpi_system_event_ops = { 102static const struct file_operations acpi_system_event_ops = {
103 .open = acpi_system_open_event, 103 .open = acpi_system_open_event,
104 .read = acpi_system_read_event, 104 .read = acpi_system_read_event,
105 .release = acpi_system_close_event, 105 .release = acpi_system_close_event,
diff --git a/drivers/acpi/events/evregion.c b/drivers/acpi/events/evregion.c
index 094a17e4c86d..21caae04fe85 100644
--- a/drivers/acpi/events/evregion.c
+++ b/drivers/acpi/events/evregion.c
@@ -528,34 +528,40 @@ acpi_ev_detach_region(union acpi_operand_object *region_obj,
528 } 528 }
529 } 529 }
530 530
531 /* Call the setup handler with the deactivate notification */ 531 /*
532 * If the region has been activated, call the setup handler
533 * with the deactivate notification
534 */
535 if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
536 region_setup = handler_obj->address_space.setup;
537 status =
538 region_setup(region_obj,
539 ACPI_REGION_DEACTIVATE,
540 handler_obj->address_space.
541 context, region_context);
532 542
533 region_setup = handler_obj->address_space.setup; 543 /* Init routine may fail, Just ignore errors */
534 status =
535 region_setup(region_obj, ACPI_REGION_DEACTIVATE,
536 handler_obj->address_space.context,
537 region_context);
538 544
539 /* Init routine may fail, Just ignore errors */ 545 if (ACPI_FAILURE(status)) {
546 ACPI_EXCEPTION((AE_INFO, status,
547 "from region handler - deactivate, [%s]",
548 acpi_ut_get_region_name
549 (region_obj->region.
550 space_id)));
551 }
540 552
541 if (ACPI_FAILURE(status)) { 553 region_obj->region.flags &=
542 ACPI_EXCEPTION((AE_INFO, status, 554 ~(AOPOBJ_SETUP_COMPLETE);
543 "from region init, [%s]",
544 acpi_ut_get_region_name
545 (region_obj->region.space_id)));
546 } 555 }
547 556
548 region_obj->region.flags &= ~(AOPOBJ_SETUP_COMPLETE);
549
550 /* 557 /*
551 * Remove handler reference in the region 558 * Remove handler reference in the region
552 * 559 *
553 * NOTE: this doesn't mean that the region goes away 560 * NOTE: this doesn't mean that the region goes away, the region
554 * The region is just inaccessible as indicated to 561 * is just inaccessible as indicated to the _REG method
555 * the _REG method
556 * 562 *
557 * If the region is on the handler's list 563 * If the region is on the handler's list, this must be the
558 * this better be the region's handler 564 * region's handler
559 */ 565 */
560 region_obj->region.handler = NULL; 566 region_obj->region.handler = NULL;
561 acpi_ut_remove_reference(handler_obj); 567 acpi_ut_remove_reference(handler_obj);
diff --git a/drivers/acpi/events/evxface.c b/drivers/acpi/events/evxface.c
index 4f948df17ab9..923fd2b46955 100644
--- a/drivers/acpi/events/evxface.c
+++ b/drivers/acpi/events/evxface.c
@@ -428,7 +428,7 @@ acpi_remove_notify_handler(acpi_handle device,
428 node = acpi_ns_map_handle_to_node(device); 428 node = acpi_ns_map_handle_to_node(device);
429 if (!node) { 429 if (!node) {
430 status = AE_BAD_PARAMETER; 430 status = AE_BAD_PARAMETER;
431 goto unlock; 431 goto unlock_and_exit;
432 } 432 }
433 433
434 /* Root Object */ 434 /* Root Object */
@@ -442,7 +442,7 @@ acpi_remove_notify_handler(acpi_handle device,
442 ((handler_type & ACPI_DEVICE_NOTIFY) && 442 ((handler_type & ACPI_DEVICE_NOTIFY) &&
443 !acpi_gbl_device_notify.handler)) { 443 !acpi_gbl_device_notify.handler)) {
444 status = AE_NOT_EXIST; 444 status = AE_NOT_EXIST;
445 goto unlock; 445 goto unlock_and_exit;
446 } 446 }
447 447
448 /* Make sure all deferred tasks are completed */ 448 /* Make sure all deferred tasks are completed */
@@ -474,7 +474,7 @@ acpi_remove_notify_handler(acpi_handle device,
474 474
475 if (!acpi_ev_is_notify_object(node)) { 475 if (!acpi_ev_is_notify_object(node)) {
476 status = AE_TYPE; 476 status = AE_TYPE;
477 goto unlock; 477 goto unlock_and_exit;
478 } 478 }
479 479
480 /* Check for an existing internal object */ 480 /* Check for an existing internal object */
@@ -482,17 +482,21 @@ acpi_remove_notify_handler(acpi_handle device,
482 obj_desc = acpi_ns_get_attached_object(node); 482 obj_desc = acpi_ns_get_attached_object(node);
483 if (!obj_desc) { 483 if (!obj_desc) {
484 status = AE_NOT_EXIST; 484 status = AE_NOT_EXIST;
485 goto unlock; 485 goto unlock_and_exit;
486 } 486 }
487 487
488 /* Object exists - make sure there's an existing handler */ 488 /* Object exists - make sure there's an existing handler */
489 489
490 if (handler_type & ACPI_SYSTEM_NOTIFY) { 490 if (handler_type & ACPI_SYSTEM_NOTIFY) {
491 notify_obj = obj_desc->common_notify.system_notify; 491 notify_obj = obj_desc->common_notify.system_notify;
492 if ((!notify_obj) || 492 if (!notify_obj) {
493 (notify_obj->notify.handler != handler)) { 493 status = AE_NOT_EXIST;
494 goto unlock_and_exit;
495 }
496
497 if (notify_obj->notify.handler != handler) {
494 status = AE_BAD_PARAMETER; 498 status = AE_BAD_PARAMETER;
495 goto unlock; 499 goto unlock_and_exit;
496 } 500 }
497 /* Make sure all deferred tasks are completed */ 501 /* Make sure all deferred tasks are completed */
498 502
@@ -510,10 +514,14 @@ acpi_remove_notify_handler(acpi_handle device,
510 514
511 if (handler_type & ACPI_DEVICE_NOTIFY) { 515 if (handler_type & ACPI_DEVICE_NOTIFY) {
512 notify_obj = obj_desc->common_notify.device_notify; 516 notify_obj = obj_desc->common_notify.device_notify;
513 if ((!notify_obj) || 517 if (!notify_obj) {
514 (notify_obj->notify.handler != handler)) { 518 status = AE_NOT_EXIST;
519 goto unlock_and_exit;
520 }
521
522 if (notify_obj->notify.handler != handler) {
515 status = AE_BAD_PARAMETER; 523 status = AE_BAD_PARAMETER;
516 goto unlock; 524 goto unlock_and_exit;
517 } 525 }
518 /* Make sure all deferred tasks are completed */ 526 /* Make sure all deferred tasks are completed */
519 527
@@ -530,9 +538,9 @@ acpi_remove_notify_handler(acpi_handle device,
530 } 538 }
531 } 539 }
532 540
533unlock: 541 unlock_and_exit:
534 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 542 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
535exit: 543 exit:
536 if (ACPI_FAILURE(status)) 544 if (ACPI_FAILURE(status))
537 ACPI_EXCEPTION((AE_INFO, status, "Removing notify handler")); 545 ACPI_EXCEPTION((AE_INFO, status, "Removing notify handler"));
538 return_ACPI_STATUS(status); 546 return_ACPI_STATUS(status);
@@ -586,7 +594,7 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
586 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); 594 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
587 if (!gpe_event_info) { 595 if (!gpe_event_info) {
588 status = AE_BAD_PARAMETER; 596 status = AE_BAD_PARAMETER;
589 goto unlock; 597 goto unlock_and_exit;
590 } 598 }
591 599
592 /* Make sure that there isn't a handler there already */ 600 /* Make sure that there isn't a handler there already */
@@ -594,7 +602,7 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
594 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == 602 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
595 ACPI_GPE_DISPATCH_HANDLER) { 603 ACPI_GPE_DISPATCH_HANDLER) {
596 status = AE_ALREADY_EXISTS; 604 status = AE_ALREADY_EXISTS;
597 goto unlock; 605 goto unlock_and_exit;
598 } 606 }
599 607
600 /* Allocate and init handler object */ 608 /* Allocate and init handler object */
@@ -602,7 +610,7 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
602 handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_handler_info)); 610 handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_handler_info));
603 if (!handler) { 611 if (!handler) {
604 status = AE_NO_MEMORY; 612 status = AE_NO_MEMORY;
605 goto unlock; 613 goto unlock_and_exit;
606 } 614 }
607 615
608 handler->address = address; 616 handler->address = address;
@@ -613,7 +621,7 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
613 621
614 status = acpi_ev_disable_gpe(gpe_event_info); 622 status = acpi_ev_disable_gpe(gpe_event_info);
615 if (ACPI_FAILURE(status)) { 623 if (ACPI_FAILURE(status)) {
616 goto unlock; 624 goto unlock_and_exit;
617 } 625 }
618 626
619 /* Install the handler */ 627 /* Install the handler */
@@ -628,9 +636,9 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
628 636
629 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 637 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
630 638
631unlock: 639 unlock_and_exit:
632 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); 640 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
633exit: 641 exit:
634 if (ACPI_FAILURE(status)) 642 if (ACPI_FAILURE(status))
635 ACPI_EXCEPTION((AE_INFO, status, 643 ACPI_EXCEPTION((AE_INFO, status,
636 "Installing notify handler failed")); 644 "Installing notify handler failed"));
diff --git a/drivers/acpi/events/evxfregn.c b/drivers/acpi/events/evxfregn.c
index e8b86a0baad0..83b12a9afa32 100644
--- a/drivers/acpi/events/evxfregn.c
+++ b/drivers/acpi/events/evxfregn.c
@@ -155,7 +155,11 @@ acpi_remove_address_space_handler(acpi_handle device,
155 /* Convert and validate the device handle */ 155 /* Convert and validate the device handle */
156 156
157 node = acpi_ns_map_handle_to_node(device); 157 node = acpi_ns_map_handle_to_node(device);
158 if (!node) { 158 if (!node ||
159 ((node->type != ACPI_TYPE_DEVICE) &&
160 (node->type != ACPI_TYPE_PROCESSOR) &&
161 (node->type != ACPI_TYPE_THERMAL) &&
162 (node != acpi_gbl_root_node))) {
159 status = AE_BAD_PARAMETER; 163 status = AE_BAD_PARAMETER;
160 goto unlock_and_exit; 164 goto unlock_and_exit;
161 } 165 }
@@ -178,6 +182,13 @@ acpi_remove_address_space_handler(acpi_handle device,
178 182
179 if (handler_obj->address_space.space_id == space_id) { 183 if (handler_obj->address_space.space_id == space_id) {
180 184
185 /* Handler must be the same as the installed handler */
186
187 if (handler_obj->address_space.handler != handler) {
188 status = AE_BAD_PARAMETER;
189 goto unlock_and_exit;
190 }
191
181 /* Matched space_id, first dereference this in the Regions */ 192 /* Matched space_id, first dereference this in the Regions */
182 193
183 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, 194 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
diff --git a/drivers/acpi/executer/exconfig.c b/drivers/acpi/executer/exconfig.c
index 83fed079a276..c8341fa5fe01 100644
--- a/drivers/acpi/executer/exconfig.c
+++ b/drivers/acpi/executer/exconfig.c
@@ -502,7 +502,6 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
502 * (Offset contains the table_id) 502 * (Offset contains the table_id)
503 */ 503 */
504 acpi_ns_delete_namespace_by_owner(table_info->owner_id); 504 acpi_ns_delete_namespace_by_owner(table_info->owner_id);
505 acpi_ut_release_owner_id(&table_info->owner_id);
506 505
507 /* Delete the table itself */ 506 /* Delete the table itself */
508 507
diff --git a/drivers/acpi/executer/exconvrt.c b/drivers/acpi/executer/exconvrt.c
index b732e399b1ef..544e81a6a438 100644
--- a/drivers/acpi/executer/exconvrt.c
+++ b/drivers/acpi/executer/exconvrt.c
@@ -170,6 +170,9 @@ acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
170 return_ACPI_STATUS(AE_NO_MEMORY); 170 return_ACPI_STATUS(AE_NO_MEMORY);
171 } 171 }
172 172
173 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
174 ACPI_FORMAT_UINT64(result)));
175
173 /* Save the Result */ 176 /* Save the Result */
174 177
175 return_desc->integer.value = result; 178 return_desc->integer.value = result;
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
index d8ac2877cf05..3a39c2e8e104 100644
--- a/drivers/acpi/executer/exmutex.c
+++ b/drivers/acpi/executer/exmutex.c
@@ -267,9 +267,9 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
267 && (obj_desc->mutex.os_mutex != ACPI_GLOBAL_LOCK)) { 267 && (obj_desc->mutex.os_mutex != ACPI_GLOBAL_LOCK)) {
268 ACPI_ERROR((AE_INFO, 268 ACPI_ERROR((AE_INFO,
269 "Thread %X cannot release Mutex [%4.4s] acquired by thread %X", 269 "Thread %X cannot release Mutex [%4.4s] acquired by thread %X",
270 walk_state->thread->thread_id, 270 (u32) walk_state->thread->thread_id,
271 acpi_ut_get_node_name(obj_desc->mutex.node), 271 acpi_ut_get_node_name(obj_desc->mutex.node),
272 obj_desc->mutex.owner_thread->thread_id)); 272 (u32) obj_desc->mutex.owner_thread->thread_id));
273 return_ACPI_STATUS(AE_AML_NOT_OWNER); 273 return_ACPI_STATUS(AE_AML_NOT_OWNER);
274 } 274 }
275 275
diff --git a/drivers/acpi/executer/exsystem.c b/drivers/acpi/executer/exsystem.c
index 6b5d1e6ce94b..28aef3e69ecc 100644
--- a/drivers/acpi/executer/exsystem.c
+++ b/drivers/acpi/executer/exsystem.c
@@ -60,7 +60,7 @@ ACPI_MODULE_NAME("exsystem")
60 * 60 *
61 * DESCRIPTION: Implements a semaphore wait with a check to see if the 61 * DESCRIPTION: Implements a semaphore wait with a check to see if the
62 * semaphore is available immediately. If it is not, the 62 * semaphore is available immediately. If it is not, the
63 * interpreter is released. 63 * interpreter is released before waiting.
64 * 64 *
65 ******************************************************************************/ 65 ******************************************************************************/
66acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout) 66acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
@@ -110,9 +110,9 @@ acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
110 * 110 *
111 * RETURN: Status 111 * RETURN: Status
112 * 112 *
113 * DESCRIPTION: Implements a semaphore wait with a check to see if the 113 * DESCRIPTION: Implements a mutex wait with a check to see if the
114 * semaphore is available immediately. If it is not, the 114 * mutex is available immediately. If it is not, the
115 * interpreter is released. 115 * interpreter is released before waiting.
116 * 116 *
117 ******************************************************************************/ 117 ******************************************************************************/
118 118
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 38acc69b21bc..045c89477e59 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -64,7 +64,7 @@ static struct acpi_driver acpi_fan_driver = {
64}; 64};
65 65
66struct acpi_fan { 66struct acpi_fan {
67 acpi_handle handle; 67 struct acpi_device * device;
68}; 68};
69 69
70/* -------------------------------------------------------------------------- 70/* --------------------------------------------------------------------------
@@ -80,7 +80,7 @@ static int acpi_fan_read_state(struct seq_file *seq, void *offset)
80 80
81 81
82 if (fan) { 82 if (fan) {
83 if (acpi_bus_get_power(fan->handle, &state)) 83 if (acpi_bus_get_power(fan->device->handle, &state))
84 seq_printf(seq, "status: ERROR\n"); 84 seq_printf(seq, "status: ERROR\n");
85 else 85 else
86 seq_printf(seq, "status: %s\n", 86 seq_printf(seq, "status: %s\n",
@@ -112,7 +112,7 @@ acpi_fan_write_state(struct file *file, const char __user * buffer,
112 112
113 state_string[count] = '\0'; 113 state_string[count] = '\0';
114 114
115 result = acpi_bus_set_power(fan->handle, 115 result = acpi_bus_set_power(fan->device->handle,
116 simple_strtoul(state_string, NULL, 0)); 116 simple_strtoul(state_string, NULL, 0));
117 if (result) 117 if (result)
118 return result; 118 return result;
@@ -120,7 +120,7 @@ acpi_fan_write_state(struct file *file, const char __user * buffer,
120 return count; 120 return count;
121} 121}
122 122
123static struct file_operations acpi_fan_state_ops = { 123static const struct file_operations acpi_fan_state_ops = {
124 .open = acpi_fan_state_open_fs, 124 .open = acpi_fan_state_open_fs,
125 .read = seq_read, 125 .read = seq_read,
126 .write = acpi_fan_write_state, 126 .write = acpi_fan_write_state,
@@ -191,12 +191,12 @@ static int acpi_fan_add(struct acpi_device *device)
191 return -ENOMEM; 191 return -ENOMEM;
192 memset(fan, 0, sizeof(struct acpi_fan)); 192 memset(fan, 0, sizeof(struct acpi_fan));
193 193
194 fan->handle = device->handle; 194 fan->device = device;
195 strcpy(acpi_device_name(device), "Fan"); 195 strcpy(acpi_device_name(device), "Fan");
196 strcpy(acpi_device_class(device), ACPI_FAN_CLASS); 196 strcpy(acpi_device_class(device), ACPI_FAN_CLASS);
197 acpi_driver_data(device) = fan; 197 acpi_driver_data(device) = fan;
198 198
199 result = acpi_bus_get_power(fan->handle, &state); 199 result = acpi_bus_get_power(device->handle, &state);
200 if (result) { 200 if (result) {
201 printk(KERN_ERR PREFIX "Reading power state\n"); 201 printk(KERN_ERR PREFIX "Reading power state\n");
202 goto end; 202 goto end;
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 8daef57b994c..10f160dc75b1 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -152,7 +152,7 @@ static int get_root_bridge_busnr(acpi_handle handle)
152 bbn = bus; 152 bbn = bus;
153 } 153 }
154 exit: 154 exit:
155 acpi_os_free(buffer.pointer); 155 kfree(buffer.pointer);
156 return (int)bbn; 156 return (int)bbn;
157} 157}
158 158
@@ -192,7 +192,7 @@ find_pci_rootbridge(acpi_handle handle, u32 lvl, void *context, void **rv)
192 find->handle = handle; 192 find->handle = handle;
193 status = AE_OK; 193 status = AE_OK;
194 exit: 194 exit:
195 acpi_os_free(buffer.pointer); 195 kfree(buffer.pointer);
196 return status; 196 return status;
197} 197}
198 198
@@ -224,7 +224,7 @@ do_acpi_find_child(acpi_handle handle, u32 lvl, void *context, void **rv)
224 info = buffer.pointer; 224 info = buffer.pointer;
225 if (info->address == find->address) 225 if (info->address == find->address)
226 find->handle = handle; 226 find->handle = handle;
227 acpi_os_free(buffer.pointer); 227 kfree(buffer.pointer);
228 } 228 }
229 return AE_OK; 229 return AE_OK;
230} 230}
@@ -330,7 +330,7 @@ static int acpi_platform_notify(struct device *dev)
330 330
331 acpi_get_name(dev->firmware_data, ACPI_FULL_PATHNAME, &buffer); 331 acpi_get_name(dev->firmware_data, ACPI_FULL_PATHNAME, &buffer);
332 DBG("Device %s -> %s\n", dev->bus_id, (char *)buffer.pointer); 332 DBG("Device %s -> %s\n", dev->bus_id, (char *)buffer.pointer);
333 acpi_os_free(buffer.pointer); 333 kfree(buffer.pointer);
334 } else 334 } else
335 DBG("Device %s -> No ACPI support\n", dev->bus_id); 335 DBG("Device %s -> No ACPI support\n", dev->bus_id);
336#endif 336#endif
diff --git a/drivers/acpi/hotkey.c b/drivers/acpi/hotkey.c
index fd81a0f5222f..1ba2db671865 100644
--- a/drivers/acpi/hotkey.c
+++ b/drivers/acpi/hotkey.c
@@ -91,6 +91,14 @@ enum {
91 HK_EVENT_ENTERRING_S5, 91 HK_EVENT_ENTERRING_S5,
92}; 92};
93 93
94enum conf_entry_enum {
95 bus_handle = 0,
96 bus_method = 1,
97 action_handle = 2,
98 method = 3,
99 LAST_CONF_ENTRY
100};
101
94/* procdir we use */ 102/* procdir we use */
95static struct proc_dir_entry *hotkey_proc_dir; 103static struct proc_dir_entry *hotkey_proc_dir;
96static struct proc_dir_entry *hotkey_config; 104static struct proc_dir_entry *hotkey_config;
@@ -184,7 +192,7 @@ static union acpi_hotkey *get_hotkey_by_event(struct
184 *hotkey_list, int event); 192 *hotkey_list, int event);
185 193
186/* event based config */ 194/* event based config */
187static struct file_operations hotkey_config_fops = { 195static const struct file_operations hotkey_config_fops = {
188 .open = hotkey_open_config, 196 .open = hotkey_open_config,
189 .read = seq_read, 197 .read = seq_read,
190 .write = hotkey_write_config, 198 .write = hotkey_write_config,
@@ -193,7 +201,7 @@ static struct file_operations hotkey_config_fops = {
193}; 201};
194 202
195/* polling based config */ 203/* polling based config */
196static struct file_operations hotkey_poll_config_fops = { 204static const struct file_operations hotkey_poll_config_fops = {
197 .open = hotkey_poll_open_config, 205 .open = hotkey_poll_open_config,
198 .read = seq_read, 206 .read = seq_read,
199 .write = hotkey_write_config, 207 .write = hotkey_write_config,
@@ -202,7 +210,7 @@ static struct file_operations hotkey_poll_config_fops = {
202}; 210};
203 211
204/* hotkey driver info */ 212/* hotkey driver info */
205static struct file_operations hotkey_info_fops = { 213static const struct file_operations hotkey_info_fops = {
206 .open = hotkey_info_open_fs, 214 .open = hotkey_info_open_fs,
207 .read = seq_read, 215 .read = seq_read,
208 .llseek = seq_lseek, 216 .llseek = seq_lseek,
@@ -210,7 +218,7 @@ static struct file_operations hotkey_info_fops = {
210}; 218};
211 219
212/* action */ 220/* action */
213static struct file_operations hotkey_action_fops = { 221static const struct file_operations hotkey_action_fops = {
214 .open = hotkey_action_open_fs, 222 .open = hotkey_action_open_fs,
215 .read = seq_read, 223 .read = seq_read,
216 .write = hotkey_execute_aml_method, 224 .write = hotkey_execute_aml_method,
@@ -219,7 +227,7 @@ static struct file_operations hotkey_action_fops = {
219}; 227};
220 228
221/* polling results */ 229/* polling results */
222static struct file_operations hotkey_polling_fops = { 230static const struct file_operations hotkey_polling_fops = {
223 .open = hotkey_polling_open_fs, 231 .open = hotkey_polling_open_fs,
224 .read = seq_read, 232 .read = seq_read,
225 .llseek = seq_lseek, 233 .llseek = seq_lseek,
@@ -244,19 +252,15 @@ static int hotkey_info_open_fs(struct inode *inode, struct file *file)
244 252
245static char *format_result(union acpi_object *object) 253static char *format_result(union acpi_object *object)
246{ 254{
247 char *buf = NULL; 255 char *buf;
248
249 buf = (char *)kmalloc(RESULT_STR_LEN, GFP_KERNEL);
250 if (buf)
251 memset(buf, 0, RESULT_STR_LEN);
252 else
253 goto do_fail;
254 256
257 buf = kzalloc(RESULT_STR_LEN, GFP_KERNEL);
258 if (!buf)
259 return NULL;
255 /* Now, just support integer type */ 260 /* Now, just support integer type */
256 if (object->type == ACPI_TYPE_INTEGER) 261 if (object->type == ACPI_TYPE_INTEGER)
257 sprintf(buf, "%d\n", (u32) object->integer.value); 262 sprintf(buf, "%d\n", (u32) object->integer.value);
258 do_fail: 263 return buf;
259 return (buf);
260} 264}
261 265
262static int hotkey_polling_seq_show(struct seq_file *seq, void *offset) 266static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
@@ -486,98 +490,102 @@ static void free_hotkey_device(union acpi_hotkey *key)
486 490
487static void free_hotkey_buffer(union acpi_hotkey *key) 491static void free_hotkey_buffer(union acpi_hotkey *key)
488{ 492{
493 /* key would never be null, action method could be */
489 kfree(key->event_hotkey.action_method); 494 kfree(key->event_hotkey.action_method);
490} 495}
491 496
492static void free_poll_hotkey_buffer(union acpi_hotkey *key) 497static void free_poll_hotkey_buffer(union acpi_hotkey *key)
493{ 498{
499 /* key would never be null, others could be*/
494 kfree(key->poll_hotkey.action_method); 500 kfree(key->poll_hotkey.action_method);
495 kfree(key->poll_hotkey.poll_method); 501 kfree(key->poll_hotkey.poll_method);
496 kfree(key->poll_hotkey.poll_result); 502 kfree(key->poll_hotkey.poll_result);
497} 503}
498static int 504static int
499init_hotkey_device(union acpi_hotkey *key, char *bus_str, char *action_str, 505init_hotkey_device(union acpi_hotkey *key, char **config_entry,
500 char *method, int std_num, int external_num) 506 int std_num, int external_num)
501{ 507{
502 acpi_handle tmp_handle; 508 acpi_handle tmp_handle;
503 acpi_status status = AE_OK; 509 acpi_status status = AE_OK;
504 510
505
506 if (std_num < 0 || IS_POLL(std_num) || !key) 511 if (std_num < 0 || IS_POLL(std_num) || !key)
507 goto do_fail; 512 goto do_fail;
508 513
509 if (!bus_str || !action_str || !method) 514 if (!config_entry[bus_handle] || !config_entry[action_handle]
515 || !config_entry[method])
510 goto do_fail; 516 goto do_fail;
511 517
512 key->link.hotkey_type = ACPI_HOTKEY_EVENT; 518 key->link.hotkey_type = ACPI_HOTKEY_EVENT;
513 key->link.hotkey_standard_num = std_num; 519 key->link.hotkey_standard_num = std_num;
514 key->event_hotkey.flag = 0; 520 key->event_hotkey.flag = 0;
515 key->event_hotkey.action_method = method; 521 key->event_hotkey.action_method = config_entry[method];
516 522
517 status = 523 status = acpi_get_handle(NULL, config_entry[bus_handle],
518 acpi_get_handle(NULL, bus_str, &(key->event_hotkey.bus_handle)); 524 &(key->event_hotkey.bus_handle));
519 if (ACPI_FAILURE(status)) 525 if (ACPI_FAILURE(status))
520 goto do_fail; 526 goto do_fail_zero;
521 key->event_hotkey.external_hotkey_num = external_num; 527 key->event_hotkey.external_hotkey_num = external_num;
522 status = 528 status = acpi_get_handle(NULL, config_entry[action_handle],
523 acpi_get_handle(NULL, action_str,
524 &(key->event_hotkey.action_handle)); 529 &(key->event_hotkey.action_handle));
525 if (ACPI_FAILURE(status)) 530 if (ACPI_FAILURE(status))
526 goto do_fail; 531 goto do_fail_zero;
527 status = acpi_get_handle(key->event_hotkey.action_handle, 532 status = acpi_get_handle(key->event_hotkey.action_handle,
528 method, &tmp_handle); 533 config_entry[method], &tmp_handle);
529 if (ACPI_FAILURE(status)) 534 if (ACPI_FAILURE(status))
530 goto do_fail; 535 goto do_fail_zero;
531 return AE_OK; 536 return AE_OK;
532 do_fail: 537do_fail_zero:
538 key->event_hotkey.action_method = NULL;
539do_fail:
533 return -ENODEV; 540 return -ENODEV;
534} 541}
535 542
536static int 543static int
537init_poll_hotkey_device(union acpi_hotkey *key, 544init_poll_hotkey_device(union acpi_hotkey *key, char **config_entry,
538 char *poll_str, 545 int std_num)
539 char *poll_method,
540 char *action_str, char *action_method, int std_num)
541{ 546{
542 acpi_status status = AE_OK; 547 acpi_status status = AE_OK;
543 acpi_handle tmp_handle; 548 acpi_handle tmp_handle;
544 549
545
546 if (std_num < 0 || IS_EVENT(std_num) || !key) 550 if (std_num < 0 || IS_EVENT(std_num) || !key)
547 goto do_fail; 551 goto do_fail;
548 552 if (!config_entry[bus_handle] ||!config_entry[bus_method] ||
549 if (!poll_str || !poll_method || !action_str || !action_method) 553 !config_entry[action_handle] || !config_entry[method])
550 goto do_fail; 554 goto do_fail;
551 555
552 key->link.hotkey_type = ACPI_HOTKEY_POLLING; 556 key->link.hotkey_type = ACPI_HOTKEY_POLLING;
553 key->link.hotkey_standard_num = std_num; 557 key->link.hotkey_standard_num = std_num;
554 key->poll_hotkey.flag = 0; 558 key->poll_hotkey.flag = 0;
555 key->poll_hotkey.poll_method = poll_method; 559 key->poll_hotkey.poll_method = config_entry[bus_method];
556 key->poll_hotkey.action_method = action_method; 560 key->poll_hotkey.action_method = config_entry[method];
557 561
558 status = 562 status = acpi_get_handle(NULL, config_entry[bus_handle],
559 acpi_get_handle(NULL, poll_str, &(key->poll_hotkey.poll_handle)); 563 &(key->poll_hotkey.poll_handle));
560 if (ACPI_FAILURE(status)) 564 if (ACPI_FAILURE(status))
561 goto do_fail; 565 goto do_fail_zero;
562 status = acpi_get_handle(key->poll_hotkey.poll_handle, 566 status = acpi_get_handle(key->poll_hotkey.poll_handle,
563 poll_method, &tmp_handle); 567 config_entry[bus_method], &tmp_handle);
564 if (ACPI_FAILURE(status)) 568 if (ACPI_FAILURE(status))
565 goto do_fail; 569 goto do_fail_zero;
566 status = 570 status =
567 acpi_get_handle(NULL, action_str, 571 acpi_get_handle(NULL, config_entry[action_handle],
568 &(key->poll_hotkey.action_handle)); 572 &(key->poll_hotkey.action_handle));
569 if (ACPI_FAILURE(status)) 573 if (ACPI_FAILURE(status))
570 goto do_fail; 574 goto do_fail_zero;
571 status = acpi_get_handle(key->poll_hotkey.action_handle, 575 status = acpi_get_handle(key->poll_hotkey.action_handle,
572 action_method, &tmp_handle); 576 config_entry[method], &tmp_handle);
573 if (ACPI_FAILURE(status)) 577 if (ACPI_FAILURE(status))
574 goto do_fail; 578 goto do_fail_zero;
575 key->poll_hotkey.poll_result = 579 key->poll_hotkey.poll_result =
576 (union acpi_object *)kmalloc(sizeof(union acpi_object), GFP_KERNEL); 580 (union acpi_object *)kmalloc(sizeof(union acpi_object), GFP_KERNEL);
577 if (!key->poll_hotkey.poll_result) 581 if (!key->poll_hotkey.poll_result)
578 goto do_fail; 582 goto do_fail_zero;
579 return AE_OK; 583 return AE_OK;
580 do_fail: 584
585do_fail_zero:
586 key->poll_hotkey.poll_method = NULL;
587 key->poll_hotkey.action_method = NULL;
588do_fail:
581 return -ENODEV; 589 return -ENODEV;
582} 590}
583 591
@@ -652,17 +660,18 @@ static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset)
652} 660}
653 661
654static int 662static int
655get_parms(char *config_record, 663get_parms(char *config_record, int *cmd, char **config_entry,
656 int *cmd, 664 int *internal_event_num, int *external_event_num)
657 char **bus_handle,
658 char **bus_method,
659 char **action_handle,
660 char **method, int *internal_event_num, int *external_event_num)
661{ 665{
666/* the format of *config_record =
667 * "1:\d+:*" : "cmd:internal_event_num"
668 * "\d+:\w+:\w+:\w+:\w+:\d+:\d+" :
669 * "cmd:bus_handle:bus_method:action_handle:method:internal_event_num:external_event_num"
670 */
662 char *tmp, *tmp1, count; 671 char *tmp, *tmp1, count;
672 int i;
663 673
664 sscanf(config_record, "%d", cmd); 674 sscanf(config_record, "%d", cmd);
665
666 if (*cmd == 1) { 675 if (*cmd == 1) {
667 if (sscanf(config_record, "%d:%d", cmd, internal_event_num) != 676 if (sscanf(config_record, "%d:%d", cmd, internal_event_num) !=
668 2) 677 2)
@@ -674,59 +683,27 @@ get_parms(char *config_record,
674 if (!tmp) 683 if (!tmp)
675 goto do_fail; 684 goto do_fail;
676 tmp++; 685 tmp++;
677 tmp1 = strchr(tmp, ':'); 686 for (i = 0; i < LAST_CONF_ENTRY; i++) {
678 if (!tmp1) 687 tmp1 = strchr(tmp, ':');
679 goto do_fail; 688 if (!tmp1) {
680 689 goto do_fail;
681 count = tmp1 - tmp; 690 }
682 *bus_handle = (char *)kmalloc(count + 1, GFP_KERNEL); 691 count = tmp1 - tmp;
683 if (!*bus_handle) 692 config_entry[i] = kzalloc(count + 1, GFP_KERNEL);
684 goto do_fail; 693 if (!config_entry[i])
685 strncpy(*bus_handle, tmp, count); 694 goto handle_failure;
686 *(*bus_handle + count) = 0; 695 strncpy(config_entry[i], tmp, count);
687 696 tmp = tmp1 + 1;
688 tmp = tmp1; 697 }
689 tmp++; 698 if (sscanf(tmp, "%d:%d", internal_event_num, external_event_num) <= 0)
690 tmp1 = strchr(tmp, ':'); 699 goto handle_failure;
691 if (!tmp1) 700 if (!IS_OTHERS(*internal_event_num)) {
692 goto do_fail; 701 return 6;
693 count = tmp1 - tmp; 702 }
694 *bus_method = (char *)kmalloc(count + 1, GFP_KERNEL); 703handle_failure:
695 if (!*bus_method) 704 while (i-- > 0)
696 goto do_fail; 705 kfree(config_entry[i]);
697 strncpy(*bus_method, tmp, count); 706do_fail:
698 *(*bus_method + count) = 0;
699
700 tmp = tmp1;
701 tmp++;
702 tmp1 = strchr(tmp, ':');
703 if (!tmp1)
704 goto do_fail;
705 count = tmp1 - tmp;
706 *action_handle = (char *)kmalloc(count + 1, GFP_KERNEL);
707 if (!*action_handle)
708 goto do_fail;
709 strncpy(*action_handle, tmp, count);
710 *(*action_handle + count) = 0;
711
712 tmp = tmp1;
713 tmp++;
714 tmp1 = strchr(tmp, ':');
715 if (!tmp1)
716 goto do_fail;
717 count = tmp1 - tmp;
718 *method = (char *)kmalloc(count + 1, GFP_KERNEL);
719 if (!*method)
720 goto do_fail;
721 strncpy(*method, tmp, count);
722 *(*method + count) = 0;
723
724 if (sscanf(tmp1 + 1, "%d:%d", internal_event_num, external_event_num) <=
725 0)
726 goto do_fail;
727
728 return 6;
729 do_fail:
730 return -1; 707 return -1;
731} 708}
732 709
@@ -736,50 +713,34 @@ static ssize_t hotkey_write_config(struct file *file,
736 size_t count, loff_t * data) 713 size_t count, loff_t * data)
737{ 714{
738 char *config_record = NULL; 715 char *config_record = NULL;
739 char *bus_handle = NULL; 716 char *config_entry[LAST_CONF_ENTRY];
740 char *bus_method = NULL;
741 char *action_handle = NULL;
742 char *method = NULL;
743 int cmd, internal_event_num, external_event_num; 717 int cmd, internal_event_num, external_event_num;
744 int ret = 0; 718 int ret = 0;
745 union acpi_hotkey *key = NULL; 719 union acpi_hotkey *key = kzalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
746 720
721 if (!key)
722 return -ENOMEM;
747 723
748 config_record = (char *)kmalloc(count + 1, GFP_KERNEL); 724 config_record = kzalloc(count + 1, GFP_KERNEL);
749 if (!config_record) 725 if (!config_record) {
726 kfree(key);
750 return -ENOMEM; 727 return -ENOMEM;
728 }
751 729
752 if (copy_from_user(config_record, buffer, count)) { 730 if (copy_from_user(config_record, buffer, count)) {
753 kfree(config_record); 731 kfree(config_record);
732 kfree(key);
754 printk(KERN_ERR PREFIX "Invalid data\n"); 733 printk(KERN_ERR PREFIX "Invalid data\n");
755 return -EINVAL; 734 return -EINVAL;
756 } 735 }
757 config_record[count] = 0; 736 ret = get_parms(config_record, &cmd, config_entry,
758 737 &internal_event_num, &external_event_num);
759 ret = get_parms(config_record,
760 &cmd,
761 &bus_handle,
762 &bus_method,
763 &action_handle,
764 &method, &internal_event_num, &external_event_num);
765
766 kfree(config_record); 738 kfree(config_record);
767 if (IS_OTHERS(internal_event_num))
768 goto do_fail;
769 if (ret != 6) { 739 if (ret != 6) {
770 do_fail:
771 kfree(bus_handle);
772 kfree(bus_method);
773 kfree(action_handle);
774 kfree(method);
775 printk(KERN_ERR PREFIX "Invalid data format ret=%d\n", ret); 740 printk(KERN_ERR PREFIX "Invalid data format ret=%d\n", ret);
776 return -EINVAL; 741 return -EINVAL;
777 } 742 }
778 743
779 key = kmalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
780 if (!key)
781 goto do_fail;
782 memset(key, 0, sizeof(union acpi_hotkey));
783 if (cmd == 1) { 744 if (cmd == 1) {
784 union acpi_hotkey *tmp = NULL; 745 union acpi_hotkey *tmp = NULL;
785 tmp = get_hotkey_by_event(&global_hotkey_list, 746 tmp = get_hotkey_by_event(&global_hotkey_list,
@@ -791,34 +752,19 @@ static ssize_t hotkey_write_config(struct file *file,
791 goto cont_cmd; 752 goto cont_cmd;
792 } 753 }
793 if (IS_EVENT(internal_event_num)) { 754 if (IS_EVENT(internal_event_num)) {
794 kfree(bus_method); 755 if (init_hotkey_device(key, config_entry,
795 ret = init_hotkey_device(key, bus_handle, action_handle, method, 756 internal_event_num, external_event_num))
796 internal_event_num, 757 goto init_hotkey_fail;
797 external_event_num); 758 } else {
798 } else 759 if (init_poll_hotkey_device(key, config_entry,
799 ret = init_poll_hotkey_device(key, bus_handle, bus_method, 760 internal_event_num))
800 action_handle, method, 761 goto init_poll_hotkey_fail;
801 internal_event_num);
802 if (ret) {
803 kfree(bus_handle);
804 kfree(action_handle);
805 if (IS_EVENT(internal_event_num))
806 free_hotkey_buffer(key);
807 else
808 free_poll_hotkey_buffer(key);
809 kfree(key);
810 printk(KERN_ERR PREFIX "Invalid hotkey\n");
811 return -EINVAL;
812 } 762 }
813 763cont_cmd:
814 cont_cmd:
815 kfree(bus_handle);
816 kfree(action_handle);
817
818 switch (cmd) { 764 switch (cmd) {
819 case 0: 765 case 0:
820 if (get_hotkey_by_event 766 if (get_hotkey_by_event(&global_hotkey_list,
821 (&global_hotkey_list, key->link.hotkey_standard_num)) 767 key->link.hotkey_standard_num))
822 goto fail_out; 768 goto fail_out;
823 else 769 else
824 hotkey_add(key); 770 hotkey_add(key);
@@ -827,6 +773,7 @@ static ssize_t hotkey_write_config(struct file *file,
827 hotkey_remove(key); 773 hotkey_remove(key);
828 break; 774 break;
829 case 2: 775 case 2:
776 /* key is kfree()ed if matched*/
830 if (hotkey_update(key)) 777 if (hotkey_update(key))
831 goto fail_out; 778 goto fail_out;
832 break; 779 break;
@@ -835,11 +782,22 @@ static ssize_t hotkey_write_config(struct file *file,
835 break; 782 break;
836 } 783 }
837 return count; 784 return count;
838 fail_out: 785
839 if (IS_EVENT(internal_event_num)) 786init_poll_hotkey_fail: /* failed init_poll_hotkey_device */
840 free_hotkey_buffer(key); 787 kfree(config_entry[bus_method]);
841 else 788 config_entry[bus_method] = NULL;
842 free_poll_hotkey_buffer(key); 789init_hotkey_fail: /* failed init_hotkey_device */
790 kfree(config_entry[method]);
791fail_out:
792 kfree(config_entry[bus_handle]);
793 kfree(config_entry[action_handle]);
794 /* No double free since elements =NULL for error cases */
795 if (IS_EVENT(internal_event_num)) {
796 if (config_entry[bus_method])
797 kfree(config_entry[bus_method]);
798 free_hotkey_buffer(key); /* frees [method] */
799 } else
800 free_poll_hotkey_buffer(key); /* frees [bus_method]+[method] */
843 kfree(key); 801 kfree(key);
844 printk(KERN_ERR PREFIX "invalid key\n"); 802 printk(KERN_ERR PREFIX "invalid key\n");
845 return -EINVAL; 803 return -EINVAL;
@@ -923,10 +881,9 @@ static ssize_t hotkey_execute_aml_method(struct file *file,
923 union acpi_hotkey *key; 881 union acpi_hotkey *key;
924 882
925 883
926 arg = (char *)kmalloc(count + 1, GFP_KERNEL); 884 arg = kzalloc(count + 1, GFP_KERNEL);
927 if (!arg) 885 if (!arg)
928 return -ENOMEM; 886 return -ENOMEM;
929 arg[count] = 0;
930 887
931 if (copy_from_user(arg, buffer, count)) { 888 if (copy_from_user(arg, buffer, count)) {
932 kfree(arg); 889 kfree(arg);
diff --git a/drivers/acpi/i2c_ec.c b/drivers/acpi/i2c_ec.c
new file mode 100644
index 000000000000..6809c283ec58
--- /dev/null
+++ b/drivers/acpi/i2c_ec.c
@@ -0,0 +1,406 @@
1/*
2 * SMBus driver for ACPI Embedded Controller ($Revision: 1.3 $)
3 *
4 * Copyright (c) 2002, 2005 Ducrot Bruno
5 * Copyright (c) 2005 Rich Townsend (tiny hacks & tweaks)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation version 2.
10 */
11
12#include <linux/version.h>
13#include <linux/module.h>
14#include <linux/slab.h>
15#include <linux/kernel.h>
16#include <linux/stddef.h>
17#include <linux/sched.h>
18#include <linux/init.h>
19#include <linux/i2c.h>
20#include <linux/acpi.h>
21#include <linux/delay.h>
22
23#include "i2c_ec.h"
24
25#define xudelay(t) udelay(t)
26#define xmsleep(t) msleep(t)
27
28#define ACPI_EC_HC_COMPONENT 0x00080000
29#define ACPI_EC_HC_CLASS "ec_hc_smbus"
30#define ACPI_EC_HC_HID "ACPI0001"
31#define ACPI_EC_HC_DRIVER_NAME "ACPI EC HC smbus driver"
32#define ACPI_EC_HC_DEVICE_NAME "EC HC smbus"
33
34#define _COMPONENT ACPI_EC_HC_COMPONENT
35
36ACPI_MODULE_NAME("acpi_smbus")
37
38static int acpi_ec_hc_add(struct acpi_device *device);
39static int acpi_ec_hc_remove(struct acpi_device *device, int type);
40
41static struct acpi_driver acpi_ec_hc_driver = {
42 .name = ACPI_EC_HC_DRIVER_NAME,
43 .class = ACPI_EC_HC_CLASS,
44 .ids = ACPI_EC_HC_HID,
45 .ops = {
46 .add = acpi_ec_hc_add,
47 .remove = acpi_ec_hc_remove,
48 },
49};
50
51/* Various bit mask for EC_SC (R) */
52#define OBF 0x01
53#define IBF 0x02
54#define CMD 0x08
55#define BURST 0x10
56#define SCI_EVT 0x20
57#define SMI_EVT 0x40
58
59/* Commands for EC_SC (W) */
60#define RD_EC 0x80
61#define WR_EC 0x81
62#define BE_EC 0x82
63#define BD_EC 0x83
64#define QR_EC 0x84
65
66/*
67 * ACPI 2.0 chapter 13 SMBus 2.0 EC register model
68 */
69
70#define ACPI_EC_SMB_PRTCL 0x00 /* protocol, PEC */
71#define ACPI_EC_SMB_STS 0x01 /* status */
72#define ACPI_EC_SMB_ADDR 0x02 /* address */
73#define ACPI_EC_SMB_CMD 0x03 /* command */
74#define ACPI_EC_SMB_DATA 0x04 /* 32 data registers */
75#define ACPI_EC_SMB_BCNT 0x24 /* number of data bytes */
76#define ACPI_EC_SMB_ALRM_A 0x25 /* alarm address */
77#define ACPI_EC_SMB_ALRM_D 0x26 /* 2 bytes alarm data */
78
79#define ACPI_EC_SMB_STS_DONE 0x80
80#define ACPI_EC_SMB_STS_ALRM 0x40
81#define ACPI_EC_SMB_STS_RES 0x20
82#define ACPI_EC_SMB_STS_STATUS 0x1f
83
84#define ACPI_EC_SMB_STATUS_OK 0x00
85#define ACPI_EC_SMB_STATUS_FAIL 0x07
86#define ACPI_EC_SMB_STATUS_DNAK 0x10
87#define ACPI_EC_SMB_STATUS_DERR 0x11
88#define ACPI_EC_SMB_STATUS_CMD_DENY 0x12
89#define ACPI_EC_SMB_STATUS_UNKNOWN 0x13
90#define ACPI_EC_SMB_STATUS_ACC_DENY 0x17
91#define ACPI_EC_SMB_STATUS_TIMEOUT 0x18
92#define ACPI_EC_SMB_STATUS_NOTSUP 0x19
93#define ACPI_EC_SMB_STATUS_BUSY 0x1A
94#define ACPI_EC_SMB_STATUS_PEC 0x1F
95
96#define ACPI_EC_SMB_PRTCL_WRITE 0x00
97#define ACPI_EC_SMB_PRTCL_READ 0x01
98#define ACPI_EC_SMB_PRTCL_QUICK 0x02
99#define ACPI_EC_SMB_PRTCL_BYTE 0x04
100#define ACPI_EC_SMB_PRTCL_BYTE_DATA 0x06
101#define ACPI_EC_SMB_PRTCL_WORD_DATA 0x08
102#define ACPI_EC_SMB_PRTCL_BLOCK_DATA 0x0a
103#define ACPI_EC_SMB_PRTCL_PROC_CALL 0x0c
104#define ACPI_EC_SMB_PRTCL_BLOCK_PROC_CALL 0x0d
105#define ACPI_EC_SMB_PRTCL_I2C_BLOCK_DATA 0x4a
106#define ACPI_EC_SMB_PRTCL_PEC 0x80
107
108/* Length of pre/post transaction sleep (msec) */
109#define ACPI_EC_SMB_TRANSACTION_SLEEP 1
110#define ACPI_EC_SMB_ACCESS_SLEEP1 1
111#define ACPI_EC_SMB_ACCESS_SLEEP2 10
112
113static int acpi_ec_smb_read(struct acpi_ec_smbus *smbus, u8 address, u8 * data)
114{
115 u8 val;
116 int err;
117
118 err = ec_read(smbus->base + address, &val);
119 if (!err) {
120 *data = val;
121 }
122 xmsleep(ACPI_EC_SMB_TRANSACTION_SLEEP);
123 return (err);
124}
125
126static int acpi_ec_smb_write(struct acpi_ec_smbus *smbus, u8 address, u8 data)
127{
128 int err;
129
130 err = ec_write(smbus->base + address, data);
131 return (err);
132}
133
134static int
135acpi_ec_smb_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
136 char read_write, u8 command, int size,
137 union i2c_smbus_data *data)
138{
139 struct acpi_ec_smbus *smbus = adap->algo_data;
140 unsigned char protocol, len = 0, pec, temp[2] = { 0, 0 };
141 int i;
142
143 if (read_write == I2C_SMBUS_READ) {
144 protocol = ACPI_EC_SMB_PRTCL_READ;
145 } else {
146 protocol = ACPI_EC_SMB_PRTCL_WRITE;
147 }
148 pec = (flags & I2C_CLIENT_PEC) ? ACPI_EC_SMB_PRTCL_PEC : 0;
149
150 switch (size) {
151
152 case I2C_SMBUS_QUICK:
153 protocol |= ACPI_EC_SMB_PRTCL_QUICK;
154 read_write = I2C_SMBUS_WRITE;
155 break;
156
157 case I2C_SMBUS_BYTE:
158 if (read_write == I2C_SMBUS_WRITE) {
159 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->byte);
160 }
161 protocol |= ACPI_EC_SMB_PRTCL_BYTE;
162 break;
163
164 case I2C_SMBUS_BYTE_DATA:
165 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
166 if (read_write == I2C_SMBUS_WRITE) {
167 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->byte);
168 }
169 protocol |= ACPI_EC_SMB_PRTCL_BYTE_DATA;
170 break;
171
172 case I2C_SMBUS_WORD_DATA:
173 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
174 if (read_write == I2C_SMBUS_WRITE) {
175 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->word);
176 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + 1,
177 data->word >> 8);
178 }
179 protocol |= ACPI_EC_SMB_PRTCL_WORD_DATA | pec;
180 break;
181
182 case I2C_SMBUS_BLOCK_DATA:
183 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
184 if (read_write == I2C_SMBUS_WRITE) {
185 len = min_t(u8, data->block[0], 32);
186 acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len);
187 for (i = 0; i < len; i++)
188 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i,
189 data->block[i + 1]);
190 }
191 protocol |= ACPI_EC_SMB_PRTCL_BLOCK_DATA | pec;
192 break;
193
194 case I2C_SMBUS_I2C_BLOCK_DATA:
195 len = min_t(u8, data->block[0], 32);
196 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
197 acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len);
198 if (read_write == I2C_SMBUS_WRITE) {
199 for (i = 0; i < len; i++) {
200 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i,
201 data->block[i + 1]);
202 }
203 }
204 protocol |= ACPI_EC_SMB_PRTCL_I2C_BLOCK_DATA;
205 break;
206
207 case I2C_SMBUS_PROC_CALL:
208 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
209 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->word);
210 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + 1, data->word >> 8);
211 protocol = ACPI_EC_SMB_PRTCL_PROC_CALL | pec;
212 read_write = I2C_SMBUS_READ;
213 break;
214
215 case I2C_SMBUS_BLOCK_PROC_CALL:
216 protocol |= pec;
217 len = min_t(u8, data->block[0], 31);
218 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
219 acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len);
220 for (i = 0; i < len; i++)
221 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i,
222 data->block[i + 1]);
223 protocol = ACPI_EC_SMB_PRTCL_BLOCK_PROC_CALL | pec;
224 read_write = I2C_SMBUS_READ;
225 break;
226
227 default:
228 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "EC SMBus adapter: "
229 "Unsupported transaction %d\n", size));
230 return (-1);
231 }
232
233 acpi_ec_smb_write(smbus, ACPI_EC_SMB_ADDR, addr << 1);
234 acpi_ec_smb_write(smbus, ACPI_EC_SMB_PRTCL, protocol);
235
236 acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0);
237
238 if (~temp[0] & ACPI_EC_SMB_STS_DONE) {
239 xudelay(500);
240 acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0);
241 }
242 if (~temp[0] & ACPI_EC_SMB_STS_DONE) {
243 xmsleep(ACPI_EC_SMB_ACCESS_SLEEP2);
244 acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0);
245 }
246 if ((~temp[0] & ACPI_EC_SMB_STS_DONE)
247 || (temp[0] & ACPI_EC_SMB_STS_STATUS)) {
248 return (-1);
249 }
250
251 if (read_write == I2C_SMBUS_WRITE) {
252 return (0);
253 }
254
255 switch (size) {
256
257 case I2C_SMBUS_BYTE:
258 case I2C_SMBUS_BYTE_DATA:
259 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA, &data->byte);
260 break;
261
262 case I2C_SMBUS_WORD_DATA:
263 case I2C_SMBUS_PROC_CALL:
264 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA, temp + 0);
265 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA + 1, temp + 1);
266 data->word = (temp[1] << 8) | temp[0];
267 break;
268
269 case I2C_SMBUS_BLOCK_DATA:
270 case I2C_SMBUS_BLOCK_PROC_CALL:
271 len = 0;
272 acpi_ec_smb_read(smbus, ACPI_EC_SMB_BCNT, &len);
273 len = min_t(u8, len, 32);
274 case I2C_SMBUS_I2C_BLOCK_DATA:
275 for (i = 0; i < len; i++)
276 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA + i,
277 data->block + i + 1);
278 data->block[0] = len;
279 break;
280 }
281
282 return (0);
283}
284
285static u32 acpi_ec_smb_func(struct i2c_adapter *adapter)
286{
287
288 return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
289 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
290 I2C_FUNC_SMBUS_BLOCK_DATA |
291 I2C_FUNC_SMBUS_PROC_CALL |
292 I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
293 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC);
294}
295
296static struct i2c_algorithm acpi_ec_smbus_algorithm = {
297 .smbus_xfer = acpi_ec_smb_access,
298 .functionality = acpi_ec_smb_func,
299};
300
301static int acpi_ec_hc_add(struct acpi_device *device)
302{
303 int status;
304 unsigned long val;
305 struct acpi_ec_hc *ec_hc;
306 struct acpi_ec_smbus *smbus;
307
308 if (!device) {
309 return -EINVAL;
310 }
311
312 ec_hc = kmalloc(sizeof(struct acpi_ec_hc), GFP_KERNEL);
313 if (!ec_hc) {
314 return -ENOMEM;
315 }
316 memset(ec_hc, 0, sizeof(struct acpi_ec_hc));
317
318 smbus = kmalloc(sizeof(struct acpi_ec_smbus), GFP_KERNEL);
319 if (!smbus) {
320 kfree(ec_hc);
321 return -ENOMEM;
322 }
323 memset(smbus, 0, sizeof(struct acpi_ec_smbus));
324
325 ec_hc->handle = device->handle;
326 strcpy(acpi_device_name(device), ACPI_EC_HC_DEVICE_NAME);
327 strcpy(acpi_device_class(device), ACPI_EC_HC_CLASS);
328 acpi_driver_data(device) = ec_hc;
329
330 status = acpi_evaluate_integer(ec_hc->handle, "_EC", NULL, &val);
331 if (ACPI_FAILURE(status)) {
332 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Error obtaining _EC\n"));
333 kfree(ec_hc);
334 kfree(smbus);
335 return -EIO;
336 }
337
338 smbus->ec = acpi_driver_data(device->parent);
339 smbus->base = (val & 0xff00ull) >> 8;
340 smbus->alert = val & 0xffull;
341
342 smbus->adapter.owner = THIS_MODULE;
343 smbus->adapter.algo = &acpi_ec_smbus_algorithm;
344 smbus->adapter.algo_data = smbus;
345
346 if (i2c_add_adapter(&smbus->adapter)) {
347 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
348 "EC SMBus adapter: Failed to register adapter\n"));
349 kfree(smbus);
350 kfree(ec_hc);
351 return -EIO;
352 }
353
354 ec_hc->smbus = smbus;
355
356 printk(KERN_INFO PREFIX "%s [%s]\n",
357 acpi_device_name(device), acpi_device_bid(device));
358
359 return AE_OK;
360}
361
362static int acpi_ec_hc_remove(struct acpi_device *device, int type)
363{
364 struct acpi_ec_hc *ec_hc;
365
366 if (!device) {
367 return -EINVAL;
368 }
369 ec_hc = acpi_driver_data(device);
370
371 i2c_del_adapter(&ec_hc->smbus->adapter);
372 kfree(ec_hc->smbus);
373 kfree(ec_hc);
374
375 return AE_OK;
376}
377
378static int __init acpi_ec_hc_init(void)
379{
380 int result;
381
382 result = acpi_bus_register_driver(&acpi_ec_hc_driver);
383 if (result < 0) {
384 return -ENODEV;
385 }
386 return 0;
387}
388
389static void __exit acpi_ec_hc_exit(void)
390{
391 acpi_bus_unregister_driver(&acpi_ec_hc_driver);
392}
393
394struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device)
395{
396 return ((struct acpi_ec_hc *)acpi_driver_data(device->parent));
397}
398
399EXPORT_SYMBOL(acpi_get_ec_hc);
400
401module_init(acpi_ec_hc_init);
402module_exit(acpi_ec_hc_exit);
403
404MODULE_LICENSE("GPL");
405MODULE_AUTHOR("Ducrot Bruno");
406MODULE_DESCRIPTION("ACPI EC SMBus driver");
diff --git a/drivers/acpi/i2c_ec.h b/drivers/acpi/i2c_ec.h
new file mode 100644
index 000000000000..7c53fb732d61
--- /dev/null
+++ b/drivers/acpi/i2c_ec.h
@@ -0,0 +1,23 @@
1/*
2 * SMBus driver for ACPI Embedded Controller ($Revision: 1.2 $)
3 *
4 * Copyright (c) 2002, 2005 Ducrot Bruno
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation version 2.
9 */
10
11struct acpi_ec_smbus {
12 struct i2c_adapter adapter;
13 union acpi_ec *ec;
14 int base;
15 int alert;
16};
17
18struct acpi_ec_hc {
19 acpi_handle handle;
20 struct acpi_ec_smbus *smbus;
21};
22
23struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device);
diff --git a/drivers/acpi/namespace/nsalloc.c b/drivers/acpi/namespace/nsalloc.c
index dc3f0739a46b..55b407aae266 100644
--- a/drivers/acpi/namespace/nsalloc.c
+++ b/drivers/acpi/namespace/nsalloc.c
@@ -386,14 +386,17 @@ void acpi_ns_delete_namespace_subtree(struct acpi_namespace_node *parent_node)
386 * specific ID. Used to delete entire ACPI tables. All 386 * specific ID. Used to delete entire ACPI tables. All
387 * reference counts are updated. 387 * reference counts are updated.
388 * 388 *
389 * MUTEX: Locks namespace during deletion walk.
390 *
389 ******************************************************************************/ 391 ******************************************************************************/
390 392
391void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id) 393void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id)
392{ 394{
393 struct acpi_namespace_node *child_node; 395 struct acpi_namespace_node *child_node;
394 struct acpi_namespace_node *deletion_node; 396 struct acpi_namespace_node *deletion_node;
395 u32 level;
396 struct acpi_namespace_node *parent_node; 397 struct acpi_namespace_node *parent_node;
398 u32 level;
399 acpi_status status;
397 400
398 ACPI_FUNCTION_TRACE_U32(ns_delete_namespace_by_owner, owner_id); 401 ACPI_FUNCTION_TRACE_U32(ns_delete_namespace_by_owner, owner_id);
399 402
@@ -401,6 +404,13 @@ void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id)
401 return_VOID; 404 return_VOID;
402 } 405 }
403 406
407 /* Lock namespace for possible update */
408
409 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
410 if (ACPI_FAILURE(status)) {
411 return_VOID;
412 }
413
404 deletion_node = NULL; 414 deletion_node = NULL;
405 parent_node = acpi_gbl_root_node; 415 parent_node = acpi_gbl_root_node;
406 child_node = NULL; 416 child_node = NULL;
@@ -469,5 +479,6 @@ void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id)
469 } 479 }
470 } 480 }
471 481
482 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
472 return_VOID; 483 return_VOID;
473} 484}
diff --git a/drivers/acpi/namespace/nsxfeval.c b/drivers/acpi/namespace/nsxfeval.c
index 6d9bd45af30a..dca6799ac678 100644
--- a/drivers/acpi/namespace/nsxfeval.c
+++ b/drivers/acpi/namespace/nsxfeval.c
@@ -133,7 +133,7 @@ acpi_evaluate_object_typed(acpi_handle handle,
133 133
134 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */ 134 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
135 135
136 acpi_os_free(return_buffer->pointer); 136 ACPI_FREE(return_buffer->pointer);
137 return_buffer->pointer = NULL; 137 return_buffer->pointer = NULL;
138 } 138 }
139 139
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index 4d622981f61a..e5e448edca41 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -259,12 +259,10 @@ int acpi_get_node(acpi_handle *handle)
259{ 259{
260 int pxm, node = -1; 260 int pxm, node = -1;
261 261
262 ACPI_FUNCTION_TRACE("acpi_get_node");
263
264 pxm = acpi_get_pxm(handle); 262 pxm = acpi_get_pxm(handle);
265 if (pxm >= 0) 263 if (pxm >= 0)
266 node = acpi_map_pxm_to_node(pxm); 264 node = acpi_map_pxm_to_node(pxm);
267 265
268 return_VALUE(node); 266 return node;
269} 267}
270EXPORT_SYMBOL(acpi_get_node); 268EXPORT_SYMBOL(acpi_get_node);
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 5a468e2779ae..507f051d1cef 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -36,7 +36,6 @@
36#include <linux/delay.h> 36#include <linux/delay.h>
37#include <linux/workqueue.h> 37#include <linux/workqueue.h>
38#include <linux/nmi.h> 38#include <linux/nmi.h>
39#include <linux/kthread.h>
40#include <acpi/acpi.h> 39#include <acpi/acpi.h>
41#include <asm/io.h> 40#include <asm/io.h>
42#include <acpi/acpi_bus.h> 41#include <acpi/acpi_bus.h>
@@ -136,23 +135,6 @@ void acpi_os_vprintf(const char *fmt, va_list args)
136#endif 135#endif
137} 136}
138 137
139
140extern int acpi_in_resume;
141void *acpi_os_allocate(acpi_size size)
142{
143 if (acpi_in_resume)
144 return kmalloc(size, GFP_ATOMIC);
145 else
146 return kmalloc(size, GFP_KERNEL);
147}
148
149void acpi_os_free(void *ptr)
150{
151 kfree(ptr);
152}
153
154EXPORT_SYMBOL(acpi_os_free);
155
156acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr) 138acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr)
157{ 139{
158 if (efi_enabled) { 140 if (efi_enabled) {
@@ -600,16 +582,6 @@ static void acpi_os_execute_deferred(void *context)
600 return; 582 return;
601} 583}
602 584
603static int acpi_os_execute_thread(void *context)
604{
605 struct acpi_os_dpc *dpc = (struct acpi_os_dpc *)context;
606 if (dpc) {
607 dpc->function(dpc->context);
608 kfree(dpc);
609 }
610 do_exit(0);
611}
612
613/******************************************************************************* 585/*******************************************************************************
614 * 586 *
615 * FUNCTION: acpi_os_execute 587 * FUNCTION: acpi_os_execute
@@ -631,10 +603,16 @@ acpi_status acpi_os_execute(acpi_execute_type type,
631 acpi_status status = AE_OK; 603 acpi_status status = AE_OK;
632 struct acpi_os_dpc *dpc; 604 struct acpi_os_dpc *dpc;
633 struct work_struct *task; 605 struct work_struct *task;
634 struct task_struct *p; 606
607 ACPI_FUNCTION_TRACE("os_queue_for_execution");
608
609 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
610 "Scheduling function [%p(%p)] for deferred execution.\n",
611 function, context));
635 612
636 if (!function) 613 if (!function)
637 return AE_BAD_PARAMETER; 614 return_ACPI_STATUS(AE_BAD_PARAMETER);
615
638 /* 616 /*
639 * Allocate/initialize DPC structure. Note that this memory will be 617 * Allocate/initialize DPC structure. Note that this memory will be
640 * freed by the callee. The kernel handles the tq_struct list in a 618 * freed by the callee. The kernel handles the tq_struct list in a
@@ -645,34 +623,27 @@ acpi_status acpi_os_execute(acpi_execute_type type,
645 * We can save time and code by allocating the DPC and tq_structs 623 * We can save time and code by allocating the DPC and tq_structs
646 * from the same memory. 624 * from the same memory.
647 */ 625 */
648 if (type == OSL_NOTIFY_HANDLER) { 626
649 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_KERNEL); 627 dpc =
650 } else { 628 kmalloc(sizeof(struct acpi_os_dpc) + sizeof(struct work_struct),
651 dpc = kmalloc(sizeof(struct acpi_os_dpc) + 629 GFP_ATOMIC);
652 sizeof(struct work_struct), GFP_ATOMIC);
653 }
654 if (!dpc) 630 if (!dpc)
655 return AE_NO_MEMORY; 631 return_ACPI_STATUS(AE_NO_MEMORY);
632
656 dpc->function = function; 633 dpc->function = function;
657 dpc->context = context; 634 dpc->context = context;
658 635
659 if (type == OSL_NOTIFY_HANDLER) { 636 task = (void *)(dpc + 1);
660 p = kthread_create(acpi_os_execute_thread, dpc, "kacpid_notify"); 637 INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc);
661 if (!IS_ERR(p)) { 638
662 wake_up_process(p); 639 if (!queue_work(kacpid_wq, task)) {
663 } else { 640 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
664 status = AE_NO_MEMORY; 641 "Call to queue_work() failed.\n"));
665 kfree(dpc); 642 kfree(dpc);
666 } 643 status = AE_ERROR;
667 } else {
668 task = (void *)(dpc + 1);
669 INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc);
670 if (!queue_work(kacpid_wq, task)) {
671 status = AE_ERROR;
672 kfree(dpc);
673 }
674 } 644 }
675 return status; 645
646 return_ACPI_STATUS(status);
676} 647}
677 648
678EXPORT_SYMBOL(acpi_os_execute); 649EXPORT_SYMBOL(acpi_os_execute);
@@ -742,7 +713,7 @@ acpi_status acpi_os_delete_semaphore(acpi_handle handle)
742 713
743 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); 714 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
744 715
745 acpi_os_free(sem); 716 kfree(sem);
746 sem = NULL; 717 sem = NULL;
747 718
748 return AE_OK; 719 return AE_OK;
@@ -775,6 +746,16 @@ acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
775 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n", 746 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
776 handle, units, timeout)); 747 handle, units, timeout));
777 748
749 /*
750 * This can be called during resume with interrupts off.
751 * Like boot-time, we should be single threaded and will
752 * always get the lock if we try -- timeout or not.
753 * If this doesn't succeed, then we will oops courtesy of
754 * might_sleep() in down().
755 */
756 if (!down_trylock(sem))
757 return AE_OK;
758
778 switch (timeout) { 759 switch (timeout) {
779 /* 760 /*
780 * No Wait: 761 * No Wait:
@@ -1122,26 +1103,6 @@ acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
1122 return (AE_OK); 1103 return (AE_OK);
1123} 1104}
1124 1105
1125/*******************************************************************************
1126 *
1127 * FUNCTION: acpi_os_acquire_object
1128 *
1129 * PARAMETERS: Cache - Handle to cache object
1130 * ReturnObject - Where the object is returned
1131 *
1132 * RETURN: Status
1133 *
1134 * DESCRIPTION: Return a zero-filled object.
1135 *
1136 ******************************************************************************/
1137
1138void *acpi_os_acquire_object(acpi_cache_t * cache)
1139{
1140 void *object = kmem_cache_zalloc(cache, GFP_KERNEL);
1141 WARN_ON(!object);
1142 return object;
1143}
1144
1145/****************************************************************************** 1106/******************************************************************************
1146 * 1107 *
1147 * FUNCTION: acpi_os_validate_interface 1108 * FUNCTION: acpi_os_validate_interface
diff --git a/drivers/acpi/parser/psutils.c b/drivers/acpi/parser/psutils.c
index 182474ae8ce9..d405387b7414 100644
--- a/drivers/acpi/parser/psutils.c
+++ b/drivers/acpi/parser/psutils.c
@@ -139,12 +139,10 @@ union acpi_parse_object *acpi_ps_alloc_op(u16 opcode)
139 /* The generic op (default) is by far the most common (16 to 1) */ 139 /* The generic op (default) is by far the most common (16 to 1) */
140 140
141 op = acpi_os_acquire_object(acpi_gbl_ps_node_cache); 141 op = acpi_os_acquire_object(acpi_gbl_ps_node_cache);
142 memset(op, 0, sizeof(struct acpi_parse_obj_common));
143 } else { 142 } else {
144 /* Extended parseop */ 143 /* Extended parseop */
145 144
146 op = acpi_os_acquire_object(acpi_gbl_ps_node_ext_cache); 145 op = acpi_os_acquire_object(acpi_gbl_ps_node_ext_cache);
147 memset(op, 0, sizeof(struct acpi_parse_obj_named));
148 } 146 }
149 147
150 /* Initialize the Op */ 148 /* Initialize the Op */
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 1badce27a83f..7f3e7e77e794 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -83,7 +83,6 @@ struct acpi_pci_link_irq {
83struct acpi_pci_link { 83struct acpi_pci_link {
84 struct list_head node; 84 struct list_head node;
85 struct acpi_device *device; 85 struct acpi_device *device;
86 acpi_handle handle;
87 struct acpi_pci_link_irq irq; 86 struct acpi_pci_link_irq irq;
88 int refcnt; 87 int refcnt;
89}; 88};
@@ -175,7 +174,7 @@ static int acpi_pci_link_get_possible(struct acpi_pci_link *link)
175 if (!link) 174 if (!link)
176 return -EINVAL; 175 return -EINVAL;
177 176
178 status = acpi_walk_resources(link->handle, METHOD_NAME__PRS, 177 status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS,
179 acpi_pci_link_check_possible, link); 178 acpi_pci_link_check_possible, link);
180 if (ACPI_FAILURE(status)) { 179 if (ACPI_FAILURE(status)) {
181 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS")); 180 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS"));
@@ -249,8 +248,7 @@ static int acpi_pci_link_get_current(struct acpi_pci_link *link)
249 acpi_status status = AE_OK; 248 acpi_status status = AE_OK;
250 int irq = 0; 249 int irq = 0;
251 250
252 251 if (!link)
253 if (!link || !link->handle)
254 return -EINVAL; 252 return -EINVAL;
255 253
256 link->irq.active = 0; 254 link->irq.active = 0;
@@ -274,7 +272,7 @@ static int acpi_pci_link_get_current(struct acpi_pci_link *link)
274 * Query and parse _CRS to get the current IRQ assignment. 272 * Query and parse _CRS to get the current IRQ assignment.
275 */ 273 */
276 274
277 status = acpi_walk_resources(link->handle, METHOD_NAME__CRS, 275 status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS,
278 acpi_pci_link_check_current, &irq); 276 acpi_pci_link_check_current, &irq);
279 if (ACPI_FAILURE(status)) { 277 if (ACPI_FAILURE(status)) {
280 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS")); 278 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS"));
@@ -360,7 +358,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
360 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG; 358 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
361 359
362 /* Attempt to set the resource */ 360 /* Attempt to set the resource */
363 status = acpi_set_current_resources(link->handle, &buffer); 361 status = acpi_set_current_resources(link->device->handle, &buffer);
364 362
365 /* check for total failure */ 363 /* check for total failure */
366 if (ACPI_FAILURE(status)) { 364 if (ACPI_FAILURE(status)) {
@@ -699,7 +697,7 @@ int acpi_pci_link_free_irq(acpi_handle handle)
699 acpi_device_bid(link->device))); 697 acpi_device_bid(link->device)));
700 698
701 if (link->refcnt == 0) { 699 if (link->refcnt == 0) {
702 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL); 700 acpi_ut_evaluate_object(link->device->handle, "_DIS", 0, NULL);
703 } 701 }
704 mutex_unlock(&acpi_link_lock); 702 mutex_unlock(&acpi_link_lock);
705 return (link->irq.active); 703 return (link->irq.active);
@@ -726,7 +724,6 @@ static int acpi_pci_link_add(struct acpi_device *device)
726 memset(link, 0, sizeof(struct acpi_pci_link)); 724 memset(link, 0, sizeof(struct acpi_pci_link));
727 725
728 link->device = device; 726 link->device = device;
729 link->handle = device->handle;
730 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME); 727 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
731 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS); 728 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
732 acpi_driver_data(device) = link; 729 acpi_driver_data(device) = link;
@@ -765,7 +762,7 @@ static int acpi_pci_link_add(struct acpi_device *device)
765 762
766 end: 763 end:
767 /* disable all links -- to be activated on use */ 764 /* disable all links -- to be activated on use */
768 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL); 765 acpi_ut_evaluate_object(device->handle, "_DIS", 0, NULL);
769 mutex_unlock(&acpi_link_lock); 766 mutex_unlock(&acpi_link_lock);
770 767
771 if (result) 768 if (result)
@@ -783,11 +780,6 @@ static int acpi_pci_link_resume(struct acpi_pci_link *link)
783 return 0; 780 return 0;
784} 781}
785 782
786/*
787 * FIXME: this is a workaround to avoid nasty warning. It will be removed
788 * after every device calls pci_disable_device in .resume.
789 */
790int acpi_in_resume;
791static int irqrouter_resume(struct sys_device *dev) 783static int irqrouter_resume(struct sys_device *dev)
792{ 784{
793 struct list_head *node = NULL; 785 struct list_head *node = NULL;
@@ -797,7 +789,6 @@ static int irqrouter_resume(struct sys_device *dev)
797 /* Make sure SCI is enabled again (Apple firmware bug?) */ 789 /* Make sure SCI is enabled again (Apple firmware bug?) */
798 acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1, ACPI_MTX_DO_NOT_LOCK); 790 acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1, ACPI_MTX_DO_NOT_LOCK);
799 791
800 acpi_in_resume = 1;
801 list_for_each(node, &acpi_link.entries) { 792 list_for_each(node, &acpi_link.entries) {
802 link = list_entry(node, struct acpi_pci_link, node); 793 link = list_entry(node, struct acpi_pci_link, node);
803 if (!link) { 794 if (!link) {
@@ -806,7 +797,6 @@ static int irqrouter_resume(struct sys_device *dev)
806 } 797 }
807 acpi_pci_link_resume(link); 798 acpi_pci_link_resume(link);
808 } 799 }
809 acpi_in_resume = 0;
810 return 0; 800 return 0;
811} 801}
812 802
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 8f10442119f0..0984a1ee24ed 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -58,7 +58,7 @@ static struct acpi_driver acpi_pci_root_driver = {
58 58
59struct acpi_pci_root { 59struct acpi_pci_root {
60 struct list_head node; 60 struct list_head node;
61 acpi_handle handle; 61 struct acpi_device * device;
62 struct acpi_pci_id id; 62 struct acpi_pci_id id;
63 struct pci_bus *bus; 63 struct pci_bus *bus;
64}; 64};
@@ -83,7 +83,7 @@ int acpi_pci_register_driver(struct acpi_pci_driver *driver)
83 list_for_each(entry, &acpi_pci_roots) { 83 list_for_each(entry, &acpi_pci_roots) {
84 struct acpi_pci_root *root; 84 struct acpi_pci_root *root;
85 root = list_entry(entry, struct acpi_pci_root, node); 85 root = list_entry(entry, struct acpi_pci_root, node);
86 driver->add(root->handle); 86 driver->add(root->device->handle);
87 n++; 87 n++;
88 } 88 }
89 89
@@ -110,7 +110,7 @@ void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
110 list_for_each(entry, &acpi_pci_roots) { 110 list_for_each(entry, &acpi_pci_roots) {
111 struct acpi_pci_root *root; 111 struct acpi_pci_root *root;
112 root = list_entry(entry, struct acpi_pci_root, node); 112 root = list_entry(entry, struct acpi_pci_root, node);
113 driver->remove(root->handle); 113 driver->remove(root->device->handle);
114 } 114 }
115} 115}
116 116
@@ -170,7 +170,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
170 memset(root, 0, sizeof(struct acpi_pci_root)); 170 memset(root, 0, sizeof(struct acpi_pci_root));
171 INIT_LIST_HEAD(&root->node); 171 INIT_LIST_HEAD(&root->node);
172 172
173 root->handle = device->handle; 173 root->device = device;
174 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME); 174 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
175 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS); 175 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
176 acpi_driver_data(device) = root; 176 acpi_driver_data(device) = root;
@@ -185,7 +185,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
185 * ------- 185 * -------
186 * Obtained via _SEG, if exists, otherwise assumed to be zero (0). 186 * Obtained via _SEG, if exists, otherwise assumed to be zero (0).
187 */ 187 */
188 status = acpi_evaluate_integer(root->handle, METHOD_NAME__SEG, NULL, 188 status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL,
189 &value); 189 &value);
190 switch (status) { 190 switch (status) {
191 case AE_OK: 191 case AE_OK:
@@ -207,7 +207,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
207 * --- 207 * ---
208 * Obtained via _BBN, if exists, otherwise assumed to be zero (0). 208 * Obtained via _BBN, if exists, otherwise assumed to be zero (0).
209 */ 209 */
210 status = acpi_evaluate_integer(root->handle, METHOD_NAME__BBN, NULL, 210 status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, NULL,
211 &value); 211 &value);
212 switch (status) { 212 switch (status) {
213 case AE_OK: 213 case AE_OK:
@@ -234,7 +234,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
234 "Wrong _BBN value, reboot" 234 "Wrong _BBN value, reboot"
235 " and use option 'pci=noacpi'\n"); 235 " and use option 'pci=noacpi'\n");
236 236
237 status = try_get_root_bridge_busnr(root->handle, &bus); 237 status = try_get_root_bridge_busnr(device->handle, &bus);
238 if (ACPI_FAILURE(status)) 238 if (ACPI_FAILURE(status))
239 break; 239 break;
240 if (bus != root->id.bus) { 240 if (bus != root->id.bus) {
@@ -294,9 +294,9 @@ static int acpi_pci_root_add(struct acpi_device *device)
294 * ----------------- 294 * -----------------
295 * Evaluate and parse _PRT, if exists. 295 * Evaluate and parse _PRT, if exists.
296 */ 296 */
297 status = acpi_get_handle(root->handle, METHOD_NAME__PRT, &handle); 297 status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
298 if (ACPI_SUCCESS(status)) 298 if (ACPI_SUCCESS(status))
299 result = acpi_pci_irq_add_prt(root->handle, root->id.segment, 299 result = acpi_pci_irq_add_prt(device->handle, root->id.segment,
300 root->id.bus); 300 root->id.bus);
301 301
302 end: 302 end:
@@ -315,7 +315,7 @@ static int acpi_pci_root_start(struct acpi_device *device)
315 315
316 316
317 list_for_each_entry(root, &acpi_pci_roots, node) { 317 list_for_each_entry(root, &acpi_pci_roots, node) {
318 if (root->handle == device->handle) { 318 if (root->device == device) {
319 pci_bus_add_devices(root->bus); 319 pci_bus_add_devices(root->bus);
320 return 0; 320 return 0;
321 } 321 }
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 224f729f700e..fec225d1b6b7 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -70,7 +70,7 @@ static struct acpi_driver acpi_power_driver = {
70}; 70};
71 71
72struct acpi_power_resource { 72struct acpi_power_resource {
73 acpi_handle handle; 73 struct acpi_device * device;
74 acpi_bus_id name; 74 acpi_bus_id name;
75 u32 system_level; 75 u32 system_level;
76 u32 order; 76 u32 order;
@@ -80,7 +80,7 @@ struct acpi_power_resource {
80 80
81static struct list_head acpi_power_resource_list; 81static struct list_head acpi_power_resource_list;
82 82
83static struct file_operations acpi_power_fops = { 83static const struct file_operations acpi_power_fops = {
84 .open = acpi_power_open_fs, 84 .open = acpi_power_open_fs,
85 .read = seq_read, 85 .read = seq_read,
86 .llseek = seq_lseek, 86 .llseek = seq_lseek,
@@ -124,7 +124,7 @@ static int acpi_power_get_state(struct acpi_power_resource *resource)
124 if (!resource) 124 if (!resource)
125 return -EINVAL; 125 return -EINVAL;
126 126
127 status = acpi_evaluate_integer(resource->handle, "_STA", NULL, &sta); 127 status = acpi_evaluate_integer(resource->device->handle, "_STA", NULL, &sta);
128 if (ACPI_FAILURE(status)) 128 if (ACPI_FAILURE(status))
129 return -ENODEV; 129 return -ENODEV;
130 130
@@ -192,7 +192,7 @@ static int acpi_power_on(acpi_handle handle)
192 return 0; 192 return 0;
193 } 193 }
194 194
195 status = acpi_evaluate_object(resource->handle, "_ON", NULL, NULL); 195 status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL);
196 if (ACPI_FAILURE(status)) 196 if (ACPI_FAILURE(status))
197 return -ENODEV; 197 return -ENODEV;
198 198
@@ -203,10 +203,8 @@ static int acpi_power_on(acpi_handle handle)
203 return -ENOEXEC; 203 return -ENOEXEC;
204 204
205 /* Update the power resource's _device_ power state */ 205 /* Update the power resource's _device_ power state */
206 result = acpi_bus_get_device(resource->handle, &device); 206 device = resource->device;
207 if (result) 207 resource->device->power.state = ACPI_STATE_D0;
208 return result;
209 device->power.state = ACPI_STATE_D0;
210 208
211 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned on\n", 209 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned on\n",
212 resource->name)); 210 resource->name));
@@ -242,7 +240,7 @@ static int acpi_power_off_device(acpi_handle handle)
242 return 0; 240 return 0;
243 } 241 }
244 242
245 status = acpi_evaluate_object(resource->handle, "_OFF", NULL, NULL); 243 status = acpi_evaluate_object(resource->device->handle, "_OFF", NULL, NULL);
246 if (ACPI_FAILURE(status)) 244 if (ACPI_FAILURE(status))
247 return -ENODEV; 245 return -ENODEV;
248 246
@@ -253,9 +251,7 @@ static int acpi_power_off_device(acpi_handle handle)
253 return -ENOEXEC; 251 return -ENOEXEC;
254 252
255 /* Update the power resource's _device_ power state */ 253 /* Update the power resource's _device_ power state */
256 result = acpi_bus_get_device(resource->handle, &device); 254 device = resource->device;
257 if (result)
258 return result;
259 device->power.state = ACPI_STATE_D3; 255 device->power.state = ACPI_STATE_D3;
260 256
261 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned off\n", 257 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned off\n",
@@ -544,14 +540,14 @@ static int acpi_power_add(struct acpi_device *device)
544 return -ENOMEM; 540 return -ENOMEM;
545 memset(resource, 0, sizeof(struct acpi_power_resource)); 541 memset(resource, 0, sizeof(struct acpi_power_resource));
546 542
547 resource->handle = device->handle; 543 resource->device = device;
548 strcpy(resource->name, device->pnp.bus_id); 544 strcpy(resource->name, device->pnp.bus_id);
549 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); 545 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
550 strcpy(acpi_device_class(device), ACPI_POWER_CLASS); 546 strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
551 acpi_driver_data(device) = resource; 547 acpi_driver_data(device) = resource;
552 548
553 /* Evalute the object to get the system level and resource order. */ 549 /* Evalute the object to get the system level and resource order. */
554 status = acpi_evaluate_object(resource->handle, NULL, NULL, &buffer); 550 status = acpi_evaluate_object(device->handle, NULL, NULL, &buffer);
555 if (ACPI_FAILURE(status)) { 551 if (ACPI_FAILURE(status)) {
556 result = -ENODEV; 552 result = -ENODEV;
557 goto end; 553 goto end;
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 52674323b14d..b13d64415b7a 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -102,7 +102,7 @@ static struct acpi_driver acpi_processor_driver = {
102#define INSTALL_NOTIFY_HANDLER 1 102#define INSTALL_NOTIFY_HANDLER 1
103#define UNINSTALL_NOTIFY_HANDLER 2 103#define UNINSTALL_NOTIFY_HANDLER 2
104 104
105static struct file_operations acpi_processor_info_fops = { 105static const struct file_operations acpi_processor_info_fops = {
106 .open = acpi_processor_info_open_fs, 106 .open = acpi_processor_info_open_fs,
107 .read = seq_read, 107 .read = seq_read,
108 .llseek = seq_lseek, 108 .llseek = seq_lseek,
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index e439eb77d283..71066066d626 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -768,7 +768,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
768 status = -EFAULT; 768 status = -EFAULT;
769 769
770 end: 770 end:
771 acpi_os_free(buffer.pointer); 771 kfree(buffer.pointer);
772 772
773 return status; 773 return status;
774} 774}
@@ -1070,7 +1070,7 @@ static int acpi_processor_power_open_fs(struct inode *inode, struct file *file)
1070 PDE(inode)->data); 1070 PDE(inode)->data);
1071} 1071}
1072 1072
1073static struct file_operations acpi_processor_power_fops = { 1073static const struct file_operations acpi_processor_power_fops = {
1074 .open = acpi_processor_power_open_fs, 1074 .open = acpi_processor_power_open_fs,
1075 .read = seq_read, 1075 .read = seq_read,
1076 .llseek = seq_lseek, 1076 .llseek = seq_lseek,
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 14a00e5a8f6a..7ba5e49ab302 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -216,7 +216,7 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr)
216 sizeof(struct acpi_pct_register)); 216 sizeof(struct acpi_pct_register));
217 217
218 end: 218 end:
219 acpi_os_free(buffer.pointer); 219 kfree(buffer.pointer);
220 220
221 return result; 221 return result;
222} 222}
@@ -294,7 +294,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
294 } 294 }
295 295
296 end: 296 end:
297 acpi_os_free(buffer.pointer); 297 kfree(buffer.pointer);
298 298
299 return result; 299 return result;
300} 300}
@@ -592,7 +592,7 @@ static int acpi_processor_get_psd(struct acpi_processor *pr)
592 } 592 }
593 593
594end: 594end:
595 acpi_os_free(buffer.pointer); 595 kfree(buffer.pointer);
596 return result; 596 return result;
597} 597}
598 598
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
new file mode 100644
index 000000000000..62bef0b3b614
--- /dev/null
+++ b/drivers/acpi/sbs.c
@@ -0,0 +1,1769 @@
1/*
2 * acpi_sbs.c - ACPI Smart Battery System Driver ($Revision: 1.16 $)
3 *
4 * Copyright (c) 2005 Rich Townsend <rhdt@bartol.udel.edu>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/kernel.h>
29#include <linux/proc_fs.h>
30#include <linux/seq_file.h>
31#include <asm/uaccess.h>
32#include <linux/acpi.h>
33#include <linux/i2c.h>
34#include <linux/delay.h>
35
36#include "i2c_ec.h"
37
38#define DEF_CAPACITY_UNIT 3
39#define MAH_CAPACITY_UNIT 1
40#define MWH_CAPACITY_UNIT 2
41#define CAPACITY_UNIT DEF_CAPACITY_UNIT
42
43#define REQUEST_UPDATE_MODE 1
44#define QUEUE_UPDATE_MODE 2
45
46#define DATA_TYPE_COMMON 0
47#define DATA_TYPE_INFO 1
48#define DATA_TYPE_STATE 2
49#define DATA_TYPE_ALARM 3
50#define DATA_TYPE_AC_STATE 4
51
52extern struct proc_dir_entry *acpi_lock_ac_dir(void);
53extern struct proc_dir_entry *acpi_lock_battery_dir(void);
54extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
55extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
56
57#define ACPI_SBS_COMPONENT 0x00080000
58#define ACPI_SBS_CLASS "sbs"
59#define ACPI_AC_CLASS "ac_adapter"
60#define ACPI_BATTERY_CLASS "battery"
61#define ACPI_SBS_HID "ACPI0002"
62#define ACPI_SBS_DRIVER_NAME "ACPI Smart Battery System Driver"
63#define ACPI_SBS_DEVICE_NAME "Smart Battery System"
64#define ACPI_SBS_FILE_INFO "info"
65#define ACPI_SBS_FILE_STATE "state"
66#define ACPI_SBS_FILE_ALARM "alarm"
67#define ACPI_BATTERY_DIR_NAME "BAT%i"
68#define ACPI_AC_DIR_NAME "AC0"
69#define ACPI_SBC_SMBUS_ADDR 0x9
70#define ACPI_SBSM_SMBUS_ADDR 0xa
71#define ACPI_SB_SMBUS_ADDR 0xb
72#define ACPI_SBS_AC_NOTIFY_STATUS 0x80
73#define ACPI_SBS_BATTERY_NOTIFY_STATUS 0x80
74#define ACPI_SBS_BATTERY_NOTIFY_INFO 0x81
75
76#define _COMPONENT ACPI_SBS_COMPONENT
77
78#define MAX_SBS_BAT 4
79#define MAX_SMBUS_ERR 1
80
81ACPI_MODULE_NAME("acpi_sbs");
82
83MODULE_AUTHOR("Rich Townsend");
84MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
85MODULE_LICENSE("GPL");
86
87static struct semaphore sbs_sem;
88
89#define UPDATE_MODE QUEUE_UPDATE_MODE
90/* REQUEST_UPDATE_MODE QUEUE_UPDATE_MODE */
91#define UPDATE_INFO_MODE 0
92#define UPDATE_TIME 60
93#define UPDATE_TIME2 0
94
95static int capacity_mode = CAPACITY_UNIT;
96static int update_mode = UPDATE_MODE;
97static int update_info_mode = UPDATE_INFO_MODE;
98static int update_time = UPDATE_TIME;
99static int update_time2 = UPDATE_TIME2;
100
101module_param(capacity_mode, int, CAPACITY_UNIT);
102module_param(update_mode, int, UPDATE_MODE);
103module_param(update_info_mode, int, UPDATE_INFO_MODE);
104module_param(update_time, int, UPDATE_TIME);
105module_param(update_time2, int, UPDATE_TIME2);
106
107static int acpi_sbs_add(struct acpi_device *device);
108static int acpi_sbs_remove(struct acpi_device *device, int type);
109static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus);
110static void acpi_sbs_update_queue(void *data);
111
112static struct acpi_driver acpi_sbs_driver = {
113 .name = ACPI_SBS_DRIVER_NAME,
114 .class = ACPI_SBS_CLASS,
115 .ids = ACPI_SBS_HID,
116 .ops = {
117 .add = acpi_sbs_add,
118 .remove = acpi_sbs_remove,
119 },
120};
121
122struct acpi_battery_info {
123 int capacity_mode;
124 s16 full_charge_capacity;
125 s16 design_capacity;
126 s16 design_voltage;
127 int vscale;
128 int ipscale;
129 s16 serial_number;
130 char manufacturer_name[I2C_SMBUS_BLOCK_MAX + 3];
131 char device_name[I2C_SMBUS_BLOCK_MAX + 3];
132 char device_chemistry[I2C_SMBUS_BLOCK_MAX + 3];
133};
134
135struct acpi_battery_state {
136 s16 voltage;
137 s16 amperage;
138 s16 remaining_capacity;
139 s16 average_time_to_empty;
140 s16 average_time_to_full;
141 s16 battery_status;
142};
143
144struct acpi_battery_alarm {
145 s16 remaining_capacity;
146};
147
148struct acpi_battery {
149 int alive;
150 int battery_present;
151 int id;
152 int init_state;
153 struct acpi_sbs *sbs;
154 struct acpi_battery_info info;
155 struct acpi_battery_state state;
156 struct acpi_battery_alarm alarm;
157 struct proc_dir_entry *battery_entry;
158};
159
160struct acpi_sbs {
161 acpi_handle handle;
162 struct acpi_device *device;
163 struct acpi_ec_smbus *smbus;
164 int sbsm_present;
165 int sbsm_batteries_supported;
166 int ac_present;
167 struct proc_dir_entry *ac_entry;
168 struct acpi_battery battery[MAX_SBS_BAT];
169 int update_info_mode;
170 int zombie;
171 int update_time;
172 int update_time2;
173 struct timer_list update_timer;
174};
175
176static void acpi_update_delay(struct acpi_sbs *sbs);
177static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type);
178
179/* --------------------------------------------------------------------------
180 SMBus Communication
181 -------------------------------------------------------------------------- */
182
183static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus)
184{
185 union i2c_smbus_data data;
186 int result = 0;
187 char *err_str;
188 int err_number;
189
190 data.word = 0;
191
192 result = smbus->adapter.algo->
193 smbus_xfer(&smbus->adapter,
194 ACPI_SB_SMBUS_ADDR,
195 0, I2C_SMBUS_READ, 0x16, I2C_SMBUS_BLOCK_DATA, &data);
196
197 err_number = (data.word & 0x000f);
198
199 switch (data.word & 0x000f) {
200 case 0x0000:
201 err_str = "unexpected bus error";
202 break;
203 case 0x0001:
204 err_str = "busy";
205 break;
206 case 0x0002:
207 err_str = "reserved command";
208 break;
209 case 0x0003:
210 err_str = "unsupported command";
211 break;
212 case 0x0004:
213 err_str = "access denied";
214 break;
215 case 0x0005:
216 err_str = "overflow/underflow";
217 break;
218 case 0x0006:
219 err_str = "bad size";
220 break;
221 case 0x0007:
222 err_str = "unknown error";
223 break;
224 default:
225 err_str = "unrecognized error";
226 }
227 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
228 "%s: ret %i, err %i\n", err_str, result, err_number));
229}
230
231static int
232acpi_sbs_smbus_read_word(struct acpi_ec_smbus *smbus, int addr, int func,
233 u16 * word,
234 void (*err_handler) (struct acpi_ec_smbus * smbus))
235{
236 union i2c_smbus_data data;
237 int result = 0;
238 int i;
239
240 if (err_handler == NULL) {
241 err_handler = acpi_battery_smbus_err_handler;
242 }
243
244 for (i = 0; i < MAX_SMBUS_ERR; i++) {
245 result =
246 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0,
247 I2C_SMBUS_READ, func,
248 I2C_SMBUS_WORD_DATA, &data);
249 if (result) {
250 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
251 "try %i: smbus->adapter.algo->smbus_xfer() failed\n",
252 i));
253 if (err_handler) {
254 err_handler(smbus);
255 }
256 } else {
257 *word = data.word;
258 break;
259 }
260 }
261
262 return result;
263}
264
265static int
266acpi_sbs_smbus_read_str(struct acpi_ec_smbus *smbus, int addr, int func,
267 char *str,
268 void (*err_handler) (struct acpi_ec_smbus * smbus))
269{
270 union i2c_smbus_data data;
271 int result = 0;
272 int i;
273
274 if (err_handler == NULL) {
275 err_handler = acpi_battery_smbus_err_handler;
276 }
277
278 for (i = 0; i < MAX_SMBUS_ERR; i++) {
279 result =
280 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0,
281 I2C_SMBUS_READ, func,
282 I2C_SMBUS_BLOCK_DATA,
283 &data);
284 if (result) {
285 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
286 "try %i: smbus->adapter.algo->smbus_xfer() failed\n",
287 i));
288 if (err_handler) {
289 err_handler(smbus);
290 }
291 } else {
292 strncpy(str, (const char *)data.block + 1,
293 data.block[0]);
294 str[data.block[0]] = 0;
295 break;
296 }
297 }
298
299 return result;
300}
301
302static int
303acpi_sbs_smbus_write_word(struct acpi_ec_smbus *smbus, int addr, int func,
304 int word,
305 void (*err_handler) (struct acpi_ec_smbus * smbus))
306{
307 union i2c_smbus_data data;
308 int result = 0;
309 int i;
310
311 if (err_handler == NULL) {
312 err_handler = acpi_battery_smbus_err_handler;
313 }
314
315 data.word = word;
316
317 for (i = 0; i < MAX_SMBUS_ERR; i++) {
318 result =
319 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0,
320 I2C_SMBUS_WRITE, func,
321 I2C_SMBUS_WORD_DATA, &data);
322 if (result) {
323 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
324 "try %i: smbus->adapter.algo"
325 "->smbus_xfer() failed\n", i));
326 if (err_handler) {
327 err_handler(smbus);
328 }
329 } else {
330 break;
331 }
332 }
333
334 return result;
335}
336
337/* --------------------------------------------------------------------------
338 Smart Battery System Management
339 -------------------------------------------------------------------------- */
340
341/* Smart Battery */
342
343static int acpi_sbs_generate_event(struct acpi_device *device,
344 int event, int state, char *bid, char *class)
345{
346 char bid_saved[5];
347 char class_saved[20];
348 int result = 0;
349
350 strcpy(bid_saved, acpi_device_bid(device));
351 strcpy(class_saved, acpi_device_class(device));
352
353 strcpy(acpi_device_bid(device), bid);
354 strcpy(acpi_device_class(device), class);
355
356 result = acpi_bus_generate_event(device, event, state);
357
358 strcpy(acpi_device_bid(device), bid_saved);
359 strcpy(acpi_device_class(device), class_saved);
360
361 return result;
362}
363
364static int acpi_battery_get_present(struct acpi_battery *battery)
365{
366 s16 state;
367 int result = 0;
368 int is_present = 0;
369
370 result = acpi_sbs_smbus_read_word(battery->sbs->smbus,
371 ACPI_SBSM_SMBUS_ADDR, 0x01,
372 &state, NULL);
373 if (result) {
374 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
375 "acpi_sbs_smbus_read_word() failed"));
376 }
377 if (!result) {
378 is_present = (state & 0x000f) & (1 << battery->id);
379 }
380 battery->battery_present = is_present;
381
382 return result;
383}
384
385static int acpi_battery_is_present(struct acpi_battery *battery)
386{
387 return (battery->battery_present);
388}
389
390static int acpi_ac_is_present(struct acpi_sbs *sbs)
391{
392 return (sbs->ac_present);
393}
394
395static int acpi_battery_select(struct acpi_battery *battery)
396{
397 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
398 int result = 0;
399 s16 state;
400 int foo;
401
402 if (battery->sbs->sbsm_present) {
403
404 /* Take special care not to knobble other nibbles of
405 * state (aka selector_state), since
406 * it causes charging to halt on SBSELs */
407
408 result =
409 acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01,
410 &state, NULL);
411 if (result) {
412 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
413 "acpi_sbs_smbus_read_word() failed\n"));
414 goto end;
415 }
416
417 foo = (state & 0x0fff) | (1 << (battery->id + 12));
418 result =
419 acpi_sbs_smbus_write_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01,
420 foo, NULL);
421 if (result) {
422 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
423 "acpi_sbs_smbus_write_word() failed\n"));
424 goto end;
425 }
426 }
427
428 end:
429 return result;
430}
431
432static int acpi_sbsm_get_info(struct acpi_sbs *sbs)
433{
434 struct acpi_ec_smbus *smbus = sbs->smbus;
435 int result = 0;
436 s16 battery_system_info;
437
438 result = acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x04,
439 &battery_system_info, NULL);
440 if (result) {
441 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
442 "acpi_sbs_smbus_read_word() failed\n"));
443 goto end;
444 }
445
446 sbs->sbsm_batteries_supported = battery_system_info & 0x000f;
447
448 end:
449
450 return result;
451}
452
453static int acpi_battery_get_info(struct acpi_battery *battery)
454{
455 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
456 int result = 0;
457 s16 battery_mode;
458 s16 specification_info;
459
460 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03,
461 &battery_mode,
462 &acpi_battery_smbus_err_handler);
463 if (result) {
464 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
465 "acpi_sbs_smbus_read_word() failed\n"));
466 goto end;
467 }
468 battery->info.capacity_mode = (battery_mode & 0x8000) >> 15;
469
470 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x10,
471 &battery->info.full_charge_capacity,
472 &acpi_battery_smbus_err_handler);
473 if (result) {
474 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
475 "acpi_sbs_smbus_read_word() failed\n"));
476 goto end;
477 }
478
479 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x18,
480 &battery->info.design_capacity,
481 &acpi_battery_smbus_err_handler);
482
483 if (result) {
484 goto end;
485 }
486
487 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x19,
488 &battery->info.design_voltage,
489 &acpi_battery_smbus_err_handler);
490 if (result) {
491 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
492 "acpi_sbs_smbus_read_word() failed\n"));
493 goto end;
494 }
495
496 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1a,
497 &specification_info,
498 &acpi_battery_smbus_err_handler);
499 if (result) {
500 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
501 "acpi_sbs_smbus_read_word() failed\n"));
502 goto end;
503 }
504
505 switch ((specification_info & 0x0f00) >> 8) {
506 case 1:
507 battery->info.vscale = 10;
508 break;
509 case 2:
510 battery->info.vscale = 100;
511 break;
512 case 3:
513 battery->info.vscale = 1000;
514 break;
515 default:
516 battery->info.vscale = 1;
517 }
518
519 switch ((specification_info & 0xf000) >> 12) {
520 case 1:
521 battery->info.ipscale = 10;
522 break;
523 case 2:
524 battery->info.ipscale = 100;
525 break;
526 case 3:
527 battery->info.ipscale = 1000;
528 break;
529 default:
530 battery->info.ipscale = 1;
531 }
532
533 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1c,
534 &battery->info.serial_number,
535 &acpi_battery_smbus_err_handler);
536 if (result) {
537 goto end;
538 }
539
540 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x20,
541 battery->info.manufacturer_name,
542 &acpi_battery_smbus_err_handler);
543 if (result) {
544 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
545 "acpi_sbs_smbus_read_str() failed\n"));
546 goto end;
547 }
548
549 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x21,
550 battery->info.device_name,
551 &acpi_battery_smbus_err_handler);
552 if (result) {
553 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
554 "acpi_sbs_smbus_read_str() failed\n"));
555 goto end;
556 }
557
558 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x22,
559 battery->info.device_chemistry,
560 &acpi_battery_smbus_err_handler);
561 if (result) {
562 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
563 "acpi_sbs_smbus_read_str() failed\n"));
564 goto end;
565 }
566
567 end:
568 return result;
569}
570
571static void acpi_update_delay(struct acpi_sbs *sbs)
572{
573 if (sbs->zombie) {
574 return;
575 }
576 if (sbs->update_time2 > 0) {
577 msleep(sbs->update_time2 * 1000);
578 }
579}
580
581static int acpi_battery_get_state(struct acpi_battery *battery)
582{
583 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
584 int result = 0;
585
586 acpi_update_delay(battery->sbs);
587 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x09,
588 &battery->state.voltage,
589 &acpi_battery_smbus_err_handler);
590 if (result) {
591 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
592 "acpi_sbs_smbus_read_word() failed\n"));
593 goto end;
594 }
595
596 acpi_update_delay(battery->sbs);
597 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0a,
598 &battery->state.amperage,
599 &acpi_battery_smbus_err_handler);
600 if (result) {
601 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
602 "acpi_sbs_smbus_read_word() failed\n"));
603 goto end;
604 }
605
606 acpi_update_delay(battery->sbs);
607 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0f,
608 &battery->state.remaining_capacity,
609 &acpi_battery_smbus_err_handler);
610 if (result) {
611 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
612 "acpi_sbs_smbus_read_word() failed\n"));
613 goto end;
614 }
615
616 acpi_update_delay(battery->sbs);
617 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x12,
618 &battery->state.average_time_to_empty,
619 &acpi_battery_smbus_err_handler);
620 if (result) {
621 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
622 "acpi_sbs_smbus_read_word() failed\n"));
623 goto end;
624 }
625
626 acpi_update_delay(battery->sbs);
627 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x13,
628 &battery->state.average_time_to_full,
629 &acpi_battery_smbus_err_handler);
630 if (result) {
631 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
632 "acpi_sbs_smbus_read_word() failed\n"));
633 goto end;
634 }
635
636 acpi_update_delay(battery->sbs);
637 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x16,
638 &battery->state.battery_status,
639 &acpi_battery_smbus_err_handler);
640 if (result) {
641 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
642 "acpi_sbs_smbus_read_word() failed\n"));
643 goto end;
644 }
645
646 acpi_update_delay(battery->sbs);
647
648 end:
649 return result;
650}
651
652static int acpi_battery_get_alarm(struct acpi_battery *battery)
653{
654 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
655 int result = 0;
656
657 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01,
658 &battery->alarm.remaining_capacity,
659 &acpi_battery_smbus_err_handler);
660 if (result) {
661 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
662 "acpi_sbs_smbus_read_word() failed\n"));
663 goto end;
664 }
665
666 acpi_update_delay(battery->sbs);
667
668 end:
669
670 return result;
671}
672
673static int acpi_battery_set_alarm(struct acpi_battery *battery,
674 unsigned long alarm)
675{
676 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
677 int result = 0;
678 s16 battery_mode;
679 int foo;
680
681 result = acpi_battery_select(battery);
682 if (result) {
683 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
684 "acpi_battery_select() failed\n"));
685 goto end;
686 }
687
688 /* If necessary, enable the alarm */
689
690 if (alarm > 0) {
691 result =
692 acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03,
693 &battery_mode,
694 &acpi_battery_smbus_err_handler);
695 if (result) {
696 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
697 "acpi_sbs_smbus_read_word() failed\n"));
698 goto end;
699 }
700
701 result =
702 acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01,
703 battery_mode & 0xbfff,
704 &acpi_battery_smbus_err_handler);
705 if (result) {
706 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
707 "acpi_sbs_smbus_write_word() failed\n"));
708 goto end;
709 }
710 }
711
712 foo = alarm / (battery->info.capacity_mode ? 10 : 1);
713 result = acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01,
714 foo,
715 &acpi_battery_smbus_err_handler);
716 if (result) {
717 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
718 "acpi_sbs_smbus_write_word() failed\n"));
719 goto end;
720 }
721
722 end:
723
724 return result;
725}
726
727static int acpi_battery_set_mode(struct acpi_battery *battery)
728{
729 int result = 0;
730 s16 battery_mode;
731
732 if (capacity_mode == DEF_CAPACITY_UNIT) {
733 goto end;
734 }
735
736 result = acpi_sbs_smbus_read_word(battery->sbs->smbus,
737 ACPI_SB_SMBUS_ADDR, 0x03,
738 &battery_mode, NULL);
739 if (result) {
740 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
741 "acpi_sbs_smbus_read_word() failed\n"));
742 goto end;
743 }
744
745 if (capacity_mode == MAH_CAPACITY_UNIT) {
746 battery_mode &= 0x7fff;
747 } else {
748 battery_mode |= 0x8000;
749 }
750 result = acpi_sbs_smbus_write_word(battery->sbs->smbus,
751 ACPI_SB_SMBUS_ADDR, 0x03,
752 battery_mode, NULL);
753 if (result) {
754 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
755 "acpi_sbs_smbus_write_word() failed\n"));
756 goto end;
757 }
758
759 result = acpi_sbs_smbus_read_word(battery->sbs->smbus,
760 ACPI_SB_SMBUS_ADDR, 0x03,
761 &battery_mode, NULL);
762 if (result) {
763 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
764 "acpi_sbs_smbus_read_word() failed\n"));
765 goto end;
766 }
767
768 end:
769 return result;
770}
771
772static int acpi_battery_init(struct acpi_battery *battery)
773{
774 int result = 0;
775
776 result = acpi_battery_select(battery);
777 if (result) {
778 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
779 "acpi_battery_init() failed\n"));
780 goto end;
781 }
782
783 result = acpi_battery_set_mode(battery);
784 if (result) {
785 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
786 "acpi_battery_set_mode() failed\n"));
787 goto end;
788 }
789
790 result = acpi_battery_get_info(battery);
791 if (result) {
792 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
793 "acpi_battery_get_info() failed\n"));
794 goto end;
795 }
796
797 result = acpi_battery_get_state(battery);
798 if (result) {
799 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
800 "acpi_battery_get_state() failed\n"));
801 goto end;
802 }
803
804 result = acpi_battery_get_alarm(battery);
805 if (result) {
806 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
807 "acpi_battery_get_alarm() failed\n"));
808 goto end;
809 }
810
811 end:
812 return result;
813}
814
815static int acpi_ac_get_present(struct acpi_sbs *sbs)
816{
817 struct acpi_ec_smbus *smbus = sbs->smbus;
818 int result = 0;
819 s16 charger_status;
820
821 result = acpi_sbs_smbus_read_word(smbus, ACPI_SBC_SMBUS_ADDR, 0x13,
822 &charger_status, NULL);
823
824 if (result) {
825 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
826 "acpi_sbs_smbus_read_word() failed\n"));
827 goto end;
828 }
829
830 sbs->ac_present = (charger_status & 0x8000) >> 15;
831
832 end:
833
834 return result;
835}
836
837/* --------------------------------------------------------------------------
838 FS Interface (/proc/acpi)
839 -------------------------------------------------------------------------- */
840
841/* Generic Routines */
842
843static int
844acpi_sbs_generic_add_fs(struct proc_dir_entry **dir,
845 struct proc_dir_entry *parent_dir,
846 char *dir_name,
847 struct file_operations *info_fops,
848 struct file_operations *state_fops,
849 struct file_operations *alarm_fops, void *data)
850{
851 struct proc_dir_entry *entry = NULL;
852
853 if (!*dir) {
854 *dir = proc_mkdir(dir_name, parent_dir);
855 if (!*dir) {
856 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
857 "proc_mkdir() failed\n"));
858 return -ENODEV;
859 }
860 (*dir)->owner = THIS_MODULE;
861 }
862
863 /* 'info' [R] */
864 if (info_fops) {
865 entry = create_proc_entry(ACPI_SBS_FILE_INFO, S_IRUGO, *dir);
866 if (!entry) {
867 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
868 "create_proc_entry() failed\n"));
869 } else {
870 entry->proc_fops = info_fops;
871 entry->data = data;
872 entry->owner = THIS_MODULE;
873 }
874 }
875
876 /* 'state' [R] */
877 if (state_fops) {
878 entry = create_proc_entry(ACPI_SBS_FILE_STATE, S_IRUGO, *dir);
879 if (!entry) {
880 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
881 "create_proc_entry() failed\n"));
882 } else {
883 entry->proc_fops = state_fops;
884 entry->data = data;
885 entry->owner = THIS_MODULE;
886 }
887 }
888
889 /* 'alarm' [R/W] */
890 if (alarm_fops) {
891 entry = create_proc_entry(ACPI_SBS_FILE_ALARM, S_IRUGO, *dir);
892 if (!entry) {
893 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
894 "create_proc_entry() failed\n"));
895 } else {
896 entry->proc_fops = alarm_fops;
897 entry->data = data;
898 entry->owner = THIS_MODULE;
899 }
900 }
901
902 return 0;
903}
904
905static void
906acpi_sbs_generic_remove_fs(struct proc_dir_entry **dir,
907 struct proc_dir_entry *parent_dir)
908{
909
910 if (*dir) {
911 remove_proc_entry(ACPI_SBS_FILE_INFO, *dir);
912 remove_proc_entry(ACPI_SBS_FILE_STATE, *dir);
913 remove_proc_entry(ACPI_SBS_FILE_ALARM, *dir);
914 remove_proc_entry((*dir)->name, parent_dir);
915 *dir = NULL;
916 }
917
918}
919
920/* Smart Battery Interface */
921
922static struct proc_dir_entry *acpi_battery_dir = NULL;
923
924static int acpi_battery_read_info(struct seq_file *seq, void *offset)
925{
926 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
927 int cscale;
928 int result = 0;
929
930 if (battery->sbs->zombie) {
931 return -ENODEV;
932 }
933
934 down(&sbs_sem);
935
936 if (update_mode == REQUEST_UPDATE_MODE) {
937 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_INFO);
938 if (result) {
939 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
940 "acpi_sbs_update_run() failed\n"));
941 }
942 }
943
944 if (acpi_battery_is_present(battery)) {
945 seq_printf(seq, "present: yes\n");
946 } else {
947 seq_printf(seq, "present: no\n");
948 goto end;
949 }
950
951 if (battery->info.capacity_mode) {
952 cscale = battery->info.vscale * battery->info.ipscale;
953 } else {
954 cscale = battery->info.ipscale;
955 }
956 seq_printf(seq, "design capacity: %i%s",
957 battery->info.design_capacity * cscale,
958 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n");
959
960 seq_printf(seq, "last full capacity: %i%s",
961 battery->info.full_charge_capacity * cscale,
962 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n");
963
964 seq_printf(seq, "battery technology: rechargeable\n");
965
966 seq_printf(seq, "design voltage: %i mV\n",
967 battery->info.design_voltage * battery->info.vscale);
968
969 seq_printf(seq, "design capacity warning: unknown\n");
970 seq_printf(seq, "design capacity low: unknown\n");
971 seq_printf(seq, "capacity granularity 1: unknown\n");
972 seq_printf(seq, "capacity granularity 2: unknown\n");
973
974 seq_printf(seq, "model number: %s\n",
975 battery->info.device_name);
976
977 seq_printf(seq, "serial number: %i\n",
978 battery->info.serial_number);
979
980 seq_printf(seq, "battery type: %s\n",
981 battery->info.device_chemistry);
982
983 seq_printf(seq, "OEM info: %s\n",
984 battery->info.manufacturer_name);
985
986 end:
987
988 up(&sbs_sem);
989
990 return result;
991}
992
993static int acpi_battery_info_open_fs(struct inode *inode, struct file *file)
994{
995 return single_open(file, acpi_battery_read_info, PDE(inode)->data);
996}
997
998static int acpi_battery_read_state(struct seq_file *seq, void *offset)
999{
1000 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
1001 int result = 0;
1002 int cscale;
1003 int foo;
1004
1005 if (battery->sbs->zombie) {
1006 return -ENODEV;
1007 }
1008
1009 down(&sbs_sem);
1010
1011 if (update_mode == REQUEST_UPDATE_MODE) {
1012 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_STATE);
1013 if (result) {
1014 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1015 "acpi_sbs_update_run() failed\n"));
1016 }
1017 }
1018
1019 if (acpi_battery_is_present(battery)) {
1020 seq_printf(seq, "present: yes\n");
1021 } else {
1022 seq_printf(seq, "present: no\n");
1023 goto end;
1024 }
1025
1026 if (battery->info.capacity_mode) {
1027 cscale = battery->info.vscale * battery->info.ipscale;
1028 } else {
1029 cscale = battery->info.ipscale;
1030 }
1031
1032 if (battery->state.battery_status & 0x0010) {
1033 seq_printf(seq, "capacity state: critical\n");
1034 } else {
1035 seq_printf(seq, "capacity state: ok\n");
1036 }
1037 if (battery->state.amperage < 0) {
1038 seq_printf(seq, "charging state: discharging\n");
1039 foo = battery->state.remaining_capacity * cscale * 60 /
1040 (battery->state.average_time_to_empty == 0 ? 1 :
1041 battery->state.average_time_to_empty);
1042 seq_printf(seq, "present rate: %i%s\n",
1043 foo, battery->info.capacity_mode ? "0 mW" : " mA");
1044 } else if (battery->state.amperage > 0) {
1045 seq_printf(seq, "charging state: charging\n");
1046 foo = (battery->info.full_charge_capacity -
1047 battery->state.remaining_capacity) * cscale * 60 /
1048 (battery->state.average_time_to_full == 0 ? 1 :
1049 battery->state.average_time_to_full);
1050 seq_printf(seq, "present rate: %i%s\n",
1051 foo, battery->info.capacity_mode ? "0 mW" : " mA");
1052 } else {
1053 seq_printf(seq, "charging state: charged\n");
1054 seq_printf(seq, "present rate: 0 %s\n",
1055 battery->info.capacity_mode ? "mW" : "mA");
1056 }
1057
1058 seq_printf(seq, "remaining capacity: %i%s",
1059 battery->state.remaining_capacity * cscale,
1060 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n");
1061
1062 seq_printf(seq, "present voltage: %i mV\n",
1063 battery->state.voltage * battery->info.vscale);
1064
1065 end:
1066
1067 up(&sbs_sem);
1068
1069 return result;
1070}
1071
1072static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
1073{
1074 return single_open(file, acpi_battery_read_state, PDE(inode)->data);
1075}
1076
1077static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
1078{
1079 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
1080 int result = 0;
1081 int cscale;
1082
1083 if (battery->sbs->zombie) {
1084 return -ENODEV;
1085 }
1086
1087 down(&sbs_sem);
1088
1089 if (update_mode == REQUEST_UPDATE_MODE) {
1090 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_ALARM);
1091 if (result) {
1092 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1093 "acpi_sbs_update_run() failed\n"));
1094 }
1095 }
1096
1097 if (!acpi_battery_is_present(battery)) {
1098 seq_printf(seq, "present: no\n");
1099 goto end;
1100 }
1101
1102 if (battery->info.capacity_mode) {
1103 cscale = battery->info.vscale * battery->info.ipscale;
1104 } else {
1105 cscale = battery->info.ipscale;
1106 }
1107
1108 seq_printf(seq, "alarm: ");
1109 if (battery->alarm.remaining_capacity) {
1110 seq_printf(seq, "%i%s",
1111 battery->alarm.remaining_capacity * cscale,
1112 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n");
1113 } else {
1114 seq_printf(seq, "disabled\n");
1115 }
1116
1117 end:
1118
1119 up(&sbs_sem);
1120
1121 return result;
1122}
1123
1124static ssize_t
1125acpi_battery_write_alarm(struct file *file, const char __user * buffer,
1126 size_t count, loff_t * ppos)
1127{
1128 struct seq_file *seq = (struct seq_file *)file->private_data;
1129 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
1130 char alarm_string[12] = { '\0' };
1131 int result, old_alarm, new_alarm;
1132
1133 if (battery->sbs->zombie) {
1134 return -ENODEV;
1135 }
1136
1137 down(&sbs_sem);
1138
1139 if (!acpi_battery_is_present(battery)) {
1140 result = -ENODEV;
1141 goto end;
1142 }
1143
1144 if (count > sizeof(alarm_string) - 1) {
1145 result = -EINVAL;
1146 goto end;
1147 }
1148
1149 if (copy_from_user(alarm_string, buffer, count)) {
1150 result = -EFAULT;
1151 goto end;
1152 }
1153
1154 alarm_string[count] = 0;
1155
1156 old_alarm = battery->alarm.remaining_capacity;
1157 new_alarm = simple_strtoul(alarm_string, NULL, 0);
1158
1159 result = acpi_battery_set_alarm(battery, new_alarm);
1160 if (result) {
1161 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1162 "acpi_battery_set_alarm() failed\n"));
1163 (void)acpi_battery_set_alarm(battery, old_alarm);
1164 goto end;
1165 }
1166 result = acpi_battery_get_alarm(battery);
1167 if (result) {
1168 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1169 "acpi_battery_get_alarm() failed\n"));
1170 (void)acpi_battery_set_alarm(battery, old_alarm);
1171 goto end;
1172 }
1173
1174 end:
1175 up(&sbs_sem);
1176
1177 if (result) {
1178 return result;
1179 } else {
1180 return count;
1181 }
1182}
1183
1184static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file)
1185{
1186 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data);
1187}
1188
1189static struct file_operations acpi_battery_info_fops = {
1190 .open = acpi_battery_info_open_fs,
1191 .read = seq_read,
1192 .llseek = seq_lseek,
1193 .release = single_release,
1194 .owner = THIS_MODULE,
1195};
1196
1197static struct file_operations acpi_battery_state_fops = {
1198 .open = acpi_battery_state_open_fs,
1199 .read = seq_read,
1200 .llseek = seq_lseek,
1201 .release = single_release,
1202 .owner = THIS_MODULE,
1203};
1204
1205static struct file_operations acpi_battery_alarm_fops = {
1206 .open = acpi_battery_alarm_open_fs,
1207 .read = seq_read,
1208 .write = acpi_battery_write_alarm,
1209 .llseek = seq_lseek,
1210 .release = single_release,
1211 .owner = THIS_MODULE,
1212};
1213
1214/* Legacy AC Adapter Interface */
1215
1216static struct proc_dir_entry *acpi_ac_dir = NULL;
1217
1218static int acpi_ac_read_state(struct seq_file *seq, void *offset)
1219{
1220 struct acpi_sbs *sbs = (struct acpi_sbs *)seq->private;
1221 int result;
1222
1223 if (sbs->zombie) {
1224 return -ENODEV;
1225 }
1226
1227 down(&sbs_sem);
1228
1229 if (update_mode == REQUEST_UPDATE_MODE) {
1230 result = acpi_sbs_update_run(sbs, DATA_TYPE_AC_STATE);
1231 if (result) {
1232 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1233 "acpi_sbs_update_run() failed\n"));
1234 }
1235 }
1236
1237 seq_printf(seq, "state: %s\n",
1238 sbs->ac_present ? "on-line" : "off-line");
1239
1240 up(&sbs_sem);
1241
1242 return 0;
1243}
1244
1245static int acpi_ac_state_open_fs(struct inode *inode, struct file *file)
1246{
1247 return single_open(file, acpi_ac_read_state, PDE(inode)->data);
1248}
1249
1250static struct file_operations acpi_ac_state_fops = {
1251 .open = acpi_ac_state_open_fs,
1252 .read = seq_read,
1253 .llseek = seq_lseek,
1254 .release = single_release,
1255 .owner = THIS_MODULE,
1256};
1257
1258/* --------------------------------------------------------------------------
1259 Driver Interface
1260 -------------------------------------------------------------------------- */
1261
1262/* Smart Battery */
1263
1264static int acpi_battery_add(struct acpi_sbs *sbs, int id)
1265{
1266 int is_present;
1267 int result;
1268 char dir_name[32];
1269 struct acpi_battery *battery;
1270
1271 battery = &sbs->battery[id];
1272
1273 battery->alive = 0;
1274
1275 battery->init_state = 0;
1276 battery->id = id;
1277 battery->sbs = sbs;
1278
1279 result = acpi_battery_select(battery);
1280 if (result) {
1281 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1282 "acpi_battery_select() failed\n"));
1283 goto end;
1284 }
1285
1286 result = acpi_battery_get_present(battery);
1287 if (result) {
1288 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1289 "acpi_battery_get_present() failed\n"));
1290 goto end;
1291 }
1292
1293 is_present = acpi_battery_is_present(battery);
1294
1295 if (is_present) {
1296 result = acpi_battery_init(battery);
1297 if (result) {
1298 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1299 "acpi_battery_init() failed\n"));
1300 goto end;
1301 }
1302 battery->init_state = 1;
1303 }
1304
1305 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1306
1307 result = acpi_sbs_generic_add_fs(&battery->battery_entry,
1308 acpi_battery_dir,
1309 dir_name,
1310 &acpi_battery_info_fops,
1311 &acpi_battery_state_fops,
1312 &acpi_battery_alarm_fops, battery);
1313 if (result) {
1314 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1315 "acpi_sbs_generic_add_fs() failed\n"));
1316 goto end;
1317 }
1318 battery->alive = 1;
1319
1320 end:
1321 return result;
1322}
1323
1324static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
1325{
1326
1327 if (sbs->battery[id].battery_entry) {
1328 acpi_sbs_generic_remove_fs(&(sbs->battery[id].battery_entry),
1329 acpi_battery_dir);
1330 }
1331}
1332
1333static int acpi_ac_add(struct acpi_sbs *sbs)
1334{
1335 int result;
1336
1337 result = acpi_ac_get_present(sbs);
1338 if (result) {
1339 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1340 "acpi_ac_get_present() failed\n"));
1341 goto end;
1342 }
1343
1344 result = acpi_sbs_generic_add_fs(&sbs->ac_entry,
1345 acpi_ac_dir,
1346 ACPI_AC_DIR_NAME,
1347 NULL, &acpi_ac_state_fops, NULL, sbs);
1348 if (result) {
1349 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1350 "acpi_sbs_generic_add_fs() failed\n"));
1351 goto end;
1352 }
1353
1354 end:
1355
1356 return result;
1357}
1358
1359static void acpi_ac_remove(struct acpi_sbs *sbs)
1360{
1361
1362 if (sbs->ac_entry) {
1363 acpi_sbs_generic_remove_fs(&sbs->ac_entry, acpi_ac_dir);
1364 }
1365}
1366
1367static void acpi_sbs_update_queue_run(unsigned long data)
1368{
1369 acpi_os_execute(OSL_GPE_HANDLER, acpi_sbs_update_queue, (void *)data);
1370}
1371
1372static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type)
1373{
1374 struct acpi_battery *battery;
1375 int result = 0;
1376 int old_ac_present;
1377 int old_battery_present;
1378 int new_ac_present;
1379 int new_battery_present;
1380 int id;
1381 char dir_name[32];
1382 int do_battery_init, do_ac_init;
1383 s16 old_remaining_capacity;
1384
1385 if (sbs->zombie) {
1386 goto end;
1387 }
1388
1389 old_ac_present = acpi_ac_is_present(sbs);
1390
1391 result = acpi_ac_get_present(sbs);
1392 if (result) {
1393 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1394 "acpi_ac_get_present() failed\n"));
1395 }
1396
1397 new_ac_present = acpi_ac_is_present(sbs);
1398
1399 do_ac_init = (old_ac_present != new_ac_present);
1400
1401 if (data_type == DATA_TYPE_AC_STATE) {
1402 goto end;
1403 }
1404
1405 for (id = 0; id < MAX_SBS_BAT; id++) {
1406 battery = &sbs->battery[id];
1407 if (battery->alive == 0) {
1408 continue;
1409 }
1410
1411 old_remaining_capacity = battery->state.remaining_capacity;
1412
1413 old_battery_present = acpi_battery_is_present(battery);
1414
1415 result = acpi_battery_select(battery);
1416 if (result) {
1417 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1418 "acpi_battery_select() failed\n"));
1419 }
1420 if (sbs->zombie) {
1421 goto end;
1422 }
1423
1424 result = acpi_battery_get_present(battery);
1425 if (result) {
1426 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1427 "acpi_battery_get_present() failed\n"));
1428 }
1429 if (sbs->zombie) {
1430 goto end;
1431 }
1432
1433 new_battery_present = acpi_battery_is_present(battery);
1434
1435 do_battery_init = ((old_battery_present != new_battery_present)
1436 && new_battery_present);
1437
1438 if (sbs->zombie) {
1439 goto end;
1440 }
1441 if (do_ac_init || do_battery_init ||
1442 update_info_mode || sbs->update_info_mode) {
1443 if (sbs->update_info_mode) {
1444 sbs->update_info_mode = 0;
1445 } else {
1446 sbs->update_info_mode = 1;
1447 }
1448 result = acpi_battery_init(battery);
1449 if (result) {
1450 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1451 "acpi_battery_init() "
1452 "failed\n"));
1453 }
1454 }
1455 if (data_type == DATA_TYPE_INFO) {
1456 continue;
1457 }
1458
1459 if (sbs->zombie) {
1460 goto end;
1461 }
1462 if (new_battery_present) {
1463 result = acpi_battery_get_alarm(battery);
1464 if (result) {
1465 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1466 "acpi_battery_get_alarm() "
1467 "failed\n"));
1468 }
1469 if (data_type == DATA_TYPE_ALARM) {
1470 continue;
1471 }
1472
1473 result = acpi_battery_get_state(battery);
1474 if (result) {
1475 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1476 "acpi_battery_get_state() "
1477 "failed\n"));
1478 }
1479 }
1480 if (sbs->zombie) {
1481 goto end;
1482 }
1483 if (data_type != DATA_TYPE_COMMON) {
1484 continue;
1485 }
1486
1487 if (old_battery_present != new_battery_present) {
1488 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1489 result = acpi_sbs_generate_event(sbs->device,
1490 ACPI_SBS_BATTERY_NOTIFY_STATUS,
1491 new_battery_present,
1492 dir_name,
1493 ACPI_BATTERY_CLASS);
1494 if (result) {
1495 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1496 "acpi_sbs_generate_event() "
1497 "failed\n"));
1498 }
1499 }
1500 if (old_remaining_capacity != battery->state.remaining_capacity) {
1501 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1502 result = acpi_sbs_generate_event(sbs->device,
1503 ACPI_SBS_BATTERY_NOTIFY_STATUS,
1504 new_battery_present,
1505 dir_name,
1506 ACPI_BATTERY_CLASS);
1507 if (result) {
1508 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1509 "acpi_sbs_generate_event() failed\n"));
1510 }
1511 }
1512
1513 }
1514 if (sbs->zombie) {
1515 goto end;
1516 }
1517 if (data_type != DATA_TYPE_COMMON) {
1518 goto end;
1519 }
1520
1521 if (old_ac_present != new_ac_present) {
1522 result = acpi_sbs_generate_event(sbs->device,
1523 ACPI_SBS_AC_NOTIFY_STATUS,
1524 new_ac_present,
1525 ACPI_AC_DIR_NAME,
1526 ACPI_AC_CLASS);
1527 if (result) {
1528 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1529 "acpi_sbs_generate_event() failed\n"));
1530 }
1531 }
1532
1533 end:
1534 return result;
1535}
1536
1537static void acpi_sbs_update_queue(void *data)
1538{
1539 struct acpi_sbs *sbs = data;
1540 unsigned long delay = -1;
1541 int result;
1542
1543 if (sbs->zombie) {
1544 goto end;
1545 }
1546
1547 result = acpi_sbs_update_run(sbs, DATA_TYPE_COMMON);
1548 if (result) {
1549 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1550 "acpi_sbs_update_run() failed\n"));
1551 }
1552
1553 if (sbs->zombie) {
1554 goto end;
1555 }
1556
1557 if (update_mode == REQUEST_UPDATE_MODE) {
1558 goto end;
1559 }
1560
1561 delay = jiffies + HZ * update_time;
1562 sbs->update_timer.data = (unsigned long)data;
1563 sbs->update_timer.function = acpi_sbs_update_queue_run;
1564 sbs->update_timer.expires = delay;
1565 add_timer(&sbs->update_timer);
1566 end:
1567 ;
1568}
1569
1570static int acpi_sbs_add(struct acpi_device *device)
1571{
1572 struct acpi_sbs *sbs = NULL;
1573 struct acpi_ec_hc *ec_hc = NULL;
1574 int result, remove_result = 0;
1575 unsigned long sbs_obj;
1576 int id, cnt;
1577 acpi_status status = AE_OK;
1578
1579 sbs = kmalloc(sizeof(struct acpi_sbs), GFP_KERNEL);
1580 if (!sbs) {
1581 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "kmalloc() failed\n"));
1582 return -ENOMEM;
1583 }
1584 memset(sbs, 0, sizeof(struct acpi_sbs));
1585
1586 cnt = 0;
1587 while (cnt < 10) {
1588 cnt++;
1589 ec_hc = acpi_get_ec_hc(device);
1590 if (ec_hc) {
1591 break;
1592 }
1593 msleep(1000);
1594 }
1595
1596 if (!ec_hc) {
1597 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1598 "acpi_get_ec_hc() failed: "
1599 "NO driver found for EC HC SMBus\n"));
1600 result = -ENODEV;
1601 goto end;
1602 }
1603
1604 sbs->device = device;
1605 sbs->smbus = ec_hc->smbus;
1606
1607 strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME);
1608 strcpy(acpi_device_class(device), ACPI_SBS_CLASS);
1609 acpi_driver_data(device) = sbs;
1610
1611 sbs->update_time = 0;
1612 sbs->update_time2 = 0;
1613
1614 result = acpi_ac_add(sbs);
1615 if (result) {
1616 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "acpi_ac_add() failed\n"));
1617 goto end;
1618 }
1619 result = acpi_evaluate_integer(device->handle, "_SBS", NULL, &sbs_obj);
1620 if (ACPI_FAILURE(result)) {
1621 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1622 "acpi_evaluate_integer() failed\n"));
1623 result = -EIO;
1624 goto end;
1625 }
1626
1627 if (sbs_obj > 0) {
1628 result = acpi_sbsm_get_info(sbs);
1629 if (result) {
1630 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1631 "acpi_sbsm_get_info() failed\n"));
1632 goto end;
1633 }
1634 sbs->sbsm_present = 1;
1635 }
1636 if (sbs->sbsm_present == 0) {
1637 result = acpi_battery_add(sbs, 0);
1638 if (result) {
1639 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1640 "acpi_battery_add() failed\n"));
1641 goto end;
1642 }
1643 } else {
1644 for (id = 0; id < MAX_SBS_BAT; id++) {
1645 if ((sbs->sbsm_batteries_supported & (1 << id))) {
1646 result = acpi_battery_add(sbs, id);
1647 if (result) {
1648 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1649 "acpi_battery_add() "
1650 "failed\n"));
1651 goto end;
1652 }
1653 }
1654 }
1655 }
1656
1657 sbs->handle = device->handle;
1658
1659 init_timer(&sbs->update_timer);
1660 if (update_mode == QUEUE_UPDATE_MODE) {
1661 status = acpi_os_execute(OSL_GPE_HANDLER,
1662 acpi_sbs_update_queue, (void *)sbs);
1663 if (status != AE_OK) {
1664 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1665 "acpi_os_execute() failed\n"));
1666 }
1667 }
1668 sbs->update_time = update_time;
1669 sbs->update_time2 = update_time2;
1670
1671 printk(KERN_INFO PREFIX "%s [%s]\n",
1672 acpi_device_name(device), acpi_device_bid(device));
1673
1674 end:
1675 if (result) {
1676 remove_result = acpi_sbs_remove(device, 0);
1677 if (remove_result) {
1678 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1679 "acpi_sbs_remove() failed\n"));
1680 }
1681 }
1682
1683 return result;
1684}
1685
1686int acpi_sbs_remove(struct acpi_device *device, int type)
1687{
1688 struct acpi_sbs *sbs = (struct acpi_sbs *)acpi_driver_data(device);
1689 int id;
1690
1691 if (!device || !sbs) {
1692 return -EINVAL;
1693 }
1694
1695 sbs->zombie = 1;
1696 sbs->update_time = 0;
1697 sbs->update_time2 = 0;
1698 del_timer_sync(&sbs->update_timer);
1699 acpi_os_wait_events_complete(NULL);
1700 del_timer_sync(&sbs->update_timer);
1701
1702 for (id = 0; id < MAX_SBS_BAT; id++) {
1703 acpi_battery_remove(sbs, id);
1704 }
1705
1706 acpi_ac_remove(sbs);
1707
1708 kfree(sbs);
1709
1710 return 0;
1711}
1712
1713static int __init acpi_sbs_init(void)
1714{
1715 int result = 0;
1716
1717 if (acpi_disabled)
1718 return -ENODEV;
1719
1720 init_MUTEX(&sbs_sem);
1721
1722 if (capacity_mode != DEF_CAPACITY_UNIT
1723 && capacity_mode != MAH_CAPACITY_UNIT
1724 && capacity_mode != MWH_CAPACITY_UNIT) {
1725 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "acpi_sbs_init: "
1726 "invalid capacity_mode = %d\n",
1727 capacity_mode));
1728 return -EINVAL;
1729 }
1730
1731 acpi_ac_dir = acpi_lock_ac_dir();
1732 if (!acpi_ac_dir) {
1733 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1734 "acpi_lock_ac_dir() failed\n"));
1735 return -ENODEV;
1736 }
1737
1738 acpi_battery_dir = acpi_lock_battery_dir();
1739 if (!acpi_battery_dir) {
1740 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1741 "acpi_lock_battery_dir() failed\n"));
1742 return -ENODEV;
1743 }
1744
1745 result = acpi_bus_register_driver(&acpi_sbs_driver);
1746 if (result < 0) {
1747 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1748 "acpi_bus_register_driver() failed\n"));
1749 return -ENODEV;
1750 }
1751
1752 return 0;
1753}
1754
1755static void __exit acpi_sbs_exit(void)
1756{
1757
1758 acpi_bus_unregister_driver(&acpi_sbs_driver);
1759
1760 acpi_unlock_ac_dir(acpi_ac_dir);
1761 acpi_ac_dir = NULL;
1762 acpi_unlock_battery_dir(acpi_battery_dir);
1763 acpi_battery_dir = NULL;
1764
1765 return;
1766}
1767
1768module_init(acpi_sbs_init);
1769module_exit(acpi_sbs_exit);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 861ac378ce42..698a1540e303 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -4,6 +4,7 @@
4 4
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/init.h> 6#include <linux/init.h>
7#include <linux/kernel.h>
7#include <linux/acpi.h> 8#include <linux/acpi.h>
8 9
9#include <acpi/acpi_drivers.h> 10#include <acpi/acpi_drivers.h>
@@ -113,6 +114,8 @@ static struct kset acpi_namespace_kset = {
113static void acpi_device_register(struct acpi_device *device, 114static void acpi_device_register(struct acpi_device *device,
114 struct acpi_device *parent) 115 struct acpi_device *parent)
115{ 116{
117 int err;
118
116 /* 119 /*
117 * Linkage 120 * Linkage
118 * ------- 121 * -------
@@ -138,7 +141,10 @@ static void acpi_device_register(struct acpi_device *device,
138 device->kobj.parent = &parent->kobj; 141 device->kobj.parent = &parent->kobj;
139 device->kobj.ktype = &ktype_acpi_ns; 142 device->kobj.ktype = &ktype_acpi_ns;
140 device->kobj.kset = &acpi_namespace_kset; 143 device->kobj.kset = &acpi_namespace_kset;
141 kobject_register(&device->kobj); 144 err = kobject_register(&device->kobj);
145 if (err < 0)
146 printk(KERN_WARNING "%s: kobject_register error: %d\n",
147 __FUNCTION__, err);
142 create_sysfs_device_files(device); 148 create_sysfs_device_files(device);
143} 149}
144 150
@@ -319,7 +325,7 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
319 goto end; 325 goto end;
320 } 326 }
321 327
322 acpi_os_free(buffer.pointer); 328 kfree(buffer.pointer);
323 329
324 device->wakeup.flags.valid = 1; 330 device->wakeup.flags.valid = 1;
325 /* Power button, Lid switch always enable wakeup */ 331 /* Power button, Lid switch always enable wakeup */
@@ -854,7 +860,7 @@ static void acpi_device_set_id(struct acpi_device *device,
854 printk(KERN_ERR "Memory allocation error\n"); 860 printk(KERN_ERR "Memory allocation error\n");
855 } 861 }
856 862
857 acpi_os_free(buffer.pointer); 863 kfree(buffer.pointer);
858} 864}
859 865
860static int acpi_device_set_context(struct acpi_device *device, int type) 866static int acpi_device_set_context(struct acpi_device *device, int type)
@@ -1450,7 +1456,9 @@ static int __init acpi_scan_init(void)
1450 if (acpi_disabled) 1456 if (acpi_disabled)
1451 return 0; 1457 return 0;
1452 1458
1453 kset_register(&acpi_namespace_kset); 1459 result = kset_register(&acpi_namespace_kset);
1460 if (result < 0)
1461 printk(KERN_ERR PREFIX "kset_register error: %d\n", result);
1454 1462
1455 result = bus_register(&acpi_bus_type); 1463 result = bus_register(&acpi_bus_type);
1456 if (result) { 1464 if (result) {
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c
index 4696a85a98b9..34962578039d 100644
--- a/drivers/acpi/sleep/proc.c
+++ b/drivers/acpi/sleep/proc.c
@@ -434,7 +434,7 @@ acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
434 PDE(inode)->data); 434 PDE(inode)->data);
435} 435}
436 436
437static struct file_operations acpi_system_wakeup_device_fops = { 437static const struct file_operations acpi_system_wakeup_device_fops = {
438 .open = acpi_system_wakeup_device_open_fs, 438 .open = acpi_system_wakeup_device_open_fs,
439 .read = seq_read, 439 .read = seq_read,
440 .write = acpi_system_write_wakeup_device, 440 .write = acpi_system_write_wakeup_device,
@@ -443,7 +443,7 @@ static struct file_operations acpi_system_wakeup_device_fops = {
443}; 443};
444 444
445#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP 445#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
446static struct file_operations acpi_system_sleep_fops = { 446static const struct file_operations acpi_system_sleep_fops = {
447 .open = acpi_system_sleep_open_fs, 447 .open = acpi_system_sleep_open_fs,
448 .read = seq_read, 448 .read = seq_read,
449 .write = acpi_system_write_sleep, 449 .write = acpi_system_write_sleep,
@@ -452,7 +452,7 @@ static struct file_operations acpi_system_sleep_fops = {
452}; 452};
453#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */ 453#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */
454 454
455static struct file_operations acpi_system_alarm_fops = { 455static const struct file_operations acpi_system_alarm_fops = {
456 .open = acpi_system_alarm_open_fs, 456 .open = acpi_system_alarm_open_fs,
457 .read = seq_read, 457 .read = seq_read,
458 .write = acpi_system_write_alarm, 458 .write = acpi_system_write_alarm,
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index c90bd2f70b3f..d86dcb3c2366 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -57,7 +57,7 @@ static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
57 return single_open(file, acpi_system_read_info, PDE(inode)->data); 57 return single_open(file, acpi_system_read_info, PDE(inode)->data);
58} 58}
59 59
60static struct file_operations acpi_system_info_ops = { 60static const struct file_operations acpi_system_info_ops = {
61 .open = acpi_system_info_open_fs, 61 .open = acpi_system_info_open_fs,
62 .read = seq_read, 62 .read = seq_read,
63 .llseek = seq_lseek, 63 .llseek = seq_lseek,
@@ -67,7 +67,7 @@ static struct file_operations acpi_system_info_ops = {
67static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t, 67static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
68 loff_t *); 68 loff_t *);
69 69
70static struct file_operations acpi_system_dsdt_ops = { 70static const struct file_operations acpi_system_dsdt_ops = {
71 .read = acpi_system_read_dsdt, 71 .read = acpi_system_read_dsdt,
72}; 72};
73 73
@@ -86,7 +86,7 @@ acpi_system_read_dsdt(struct file *file,
86 86
87 res = simple_read_from_buffer(buffer, count, ppos, 87 res = simple_read_from_buffer(buffer, count, ppos,
88 dsdt.pointer, dsdt.length); 88 dsdt.pointer, dsdt.length);
89 acpi_os_free(dsdt.pointer); 89 kfree(dsdt.pointer);
90 90
91 return res; 91 return res;
92} 92}
@@ -94,7 +94,7 @@ acpi_system_read_dsdt(struct file *file,
94static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t, 94static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
95 loff_t *); 95 loff_t *);
96 96
97static struct file_operations acpi_system_fadt_ops = { 97static const struct file_operations acpi_system_fadt_ops = {
98 .read = acpi_system_read_fadt, 98 .read = acpi_system_read_fadt,
99}; 99};
100 100
@@ -113,7 +113,7 @@ acpi_system_read_fadt(struct file *file,
113 113
114 res = simple_read_from_buffer(buffer, count, ppos, 114 res = simple_read_from_buffer(buffer, count, ppos,
115 fadt.pointer, fadt.length); 115 fadt.pointer, fadt.length);
116 acpi_os_free(fadt.pointer); 116 kfree(fadt.pointer);
117 117
118 return res; 118 return res;
119} 119}
diff --git a/drivers/acpi/tables/tbget.c b/drivers/acpi/tables/tbget.c
index 99eacceff563..7856db759af0 100644
--- a/drivers/acpi/tables/tbget.c
+++ b/drivers/acpi/tables/tbget.c
@@ -320,6 +320,16 @@ acpi_tb_get_this_table(struct acpi_pointer *address,
320 320
321 ACPI_FUNCTION_TRACE(tb_get_this_table); 321 ACPI_FUNCTION_TRACE(tb_get_this_table);
322 322
323 /* Validate minimum length */
324
325 if (header->length < sizeof(struct acpi_table_header)) {
326 ACPI_ERROR((AE_INFO,
327 "Table length (%X) is smaller than minimum (%X)",
328 header->length, sizeof(struct acpi_table_header)));
329
330 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
331 }
332
323 /* 333 /*
324 * Flags contains the current processor mode (Virtual or Physical 334 * Flags contains the current processor mode (Virtual or Physical
325 * addressing) The pointer_type is either Logical or Physical 335 * addressing) The pointer_type is either Logical or Physical
@@ -356,7 +366,7 @@ acpi_tb_get_this_table(struct acpi_pointer *address,
356 */ 366 */
357 status = acpi_os_map_memory(address->pointer.physical, 367 status = acpi_os_map_memory(address->pointer.physical,
358 (acpi_size) header->length, 368 (acpi_size) header->length,
359 (void *)&full_table); 369 ACPI_CAST_PTR(void, &full_table));
360 if (ACPI_FAILURE(status)) { 370 if (ACPI_FAILURE(status)) {
361 ACPI_ERROR((AE_INFO, 371 ACPI_ERROR((AE_INFO,
362 "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X", 372 "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X",
diff --git a/drivers/acpi/tables/tbinstal.c b/drivers/acpi/tables/tbinstal.c
index 7ca2df75bb11..1668a232fb67 100644
--- a/drivers/acpi/tables/tbinstal.c
+++ b/drivers/acpi/tables/tbinstal.c
@@ -256,7 +256,7 @@ acpi_tb_init_table_descriptor(acpi_table_type table_type,
256 256
257 status = acpi_ut_allocate_owner_id(&table_desc->owner_id); 257 status = acpi_ut_allocate_owner_id(&table_desc->owner_id);
258 if (ACPI_FAILURE(status)) { 258 if (ACPI_FAILURE(status)) {
259 return_ACPI_STATUS(status); 259 goto error_exit1;
260 } 260 }
261 261
262 /* Install the table into the global data structure */ 262 /* Install the table into the global data structure */
@@ -274,8 +274,8 @@ acpi_tb_init_table_descriptor(acpi_table_type table_type,
274 * at this location, so return an error. 274 * at this location, so return an error.
275 */ 275 */
276 if (list_head->next) { 276 if (list_head->next) {
277 ACPI_FREE(table_desc); 277 status = AE_ALREADY_EXISTS;
278 return_ACPI_STATUS(AE_ALREADY_EXISTS); 278 goto error_exit2;
279 } 279 }
280 280
281 table_desc->next = list_head->next; 281 table_desc->next = list_head->next;
@@ -335,6 +335,17 @@ acpi_tb_init_table_descriptor(acpi_table_type table_type,
335 table_info->owner_id = table_desc->owner_id; 335 table_info->owner_id = table_desc->owner_id;
336 table_info->installed_desc = table_desc; 336 table_info->installed_desc = table_desc;
337 return_ACPI_STATUS(AE_OK); 337 return_ACPI_STATUS(AE_OK);
338
339 /* Error exit with cleanup */
340
341 error_exit2:
342
343 acpi_ut_release_owner_id(&table_desc->owner_id);
344
345 error_exit1:
346
347 ACPI_FREE(table_desc);
348 return_ACPI_STATUS(status);
338} 349}
339 350
340/******************************************************************************* 351/*******************************************************************************
@@ -525,6 +536,10 @@ struct acpi_table_desc *acpi_tb_uninstall_table(struct acpi_table_desc
525 536
526 acpi_tb_delete_single_table(table_desc); 537 acpi_tb_delete_single_table(table_desc);
527 538
539 /* Free the owner ID associated with this table */
540
541 acpi_ut_release_owner_id(&table_desc->owner_id);
542
528 /* Free the table descriptor */ 543 /* Free the table descriptor */
529 544
530 next_desc = table_desc->next; 545 next_desc = table_desc->next;
diff --git a/drivers/acpi/tables/tbrsdt.c b/drivers/acpi/tables/tbrsdt.c
index abcb08c2592a..0ad3dbb9ebca 100644
--- a/drivers/acpi/tables/tbrsdt.c
+++ b/drivers/acpi/tables/tbrsdt.c
@@ -183,6 +183,17 @@ acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr)
183 183
184 ACPI_FUNCTION_ENTRY(); 184 ACPI_FUNCTION_ENTRY();
185 185
186 /* Validate minimum length */
187
188 if (table_ptr->length < sizeof(struct acpi_table_header)) {
189 ACPI_ERROR((AE_INFO,
190 "RSDT/XSDT length (%X) is smaller than minimum (%X)",
191 table_ptr->length,
192 sizeof(struct acpi_table_header)));
193
194 return (AE_INVALID_TABLE_LENGTH);
195 }
196
186 /* Search for appropriate signature, RSDT or XSDT */ 197 /* Search for appropriate signature, RSDT or XSDT */
187 198
188 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { 199 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
@@ -210,7 +221,7 @@ acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr)
210 ACPI_ERROR((AE_INFO, "Looking for XSDT")); 221 ACPI_ERROR((AE_INFO, "Looking for XSDT"));
211 } 222 }
212 223
213 ACPI_DUMP_BUFFER((char *)table_ptr, 48); 224 ACPI_DUMP_BUFFER(ACPI_CAST_PTR(char, table_ptr), 48);
214 return (AE_BAD_SIGNATURE); 225 return (AE_BAD_SIGNATURE);
215 } 226 }
216 227
@@ -258,7 +269,7 @@ acpi_status acpi_tb_get_table_rsdt(void)
258 269
259 status = acpi_tb_validate_rsdt(table_info.pointer); 270 status = acpi_tb_validate_rsdt(table_info.pointer);
260 if (ACPI_FAILURE(status)) { 271 if (ACPI_FAILURE(status)) {
261 return_ACPI_STATUS(status); 272 goto error_cleanup;
262 } 273 }
263 274
264 /* Get the number of tables defined in the RSDT or XSDT */ 275 /* Get the number of tables defined in the RSDT or XSDT */
@@ -270,14 +281,14 @@ acpi_status acpi_tb_get_table_rsdt(void)
270 281
271 status = acpi_tb_convert_to_xsdt(&table_info); 282 status = acpi_tb_convert_to_xsdt(&table_info);
272 if (ACPI_FAILURE(status)) { 283 if (ACPI_FAILURE(status)) {
273 return_ACPI_STATUS(status); 284 goto error_cleanup;
274 } 285 }
275 286
276 /* Save the table pointers and allocation info */ 287 /* Save the table pointers and allocation info */
277 288
278 status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_XSDT, &table_info); 289 status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_XSDT, &table_info);
279 if (ACPI_FAILURE(status)) { 290 if (ACPI_FAILURE(status)) {
280 return_ACPI_STATUS(status); 291 goto error_cleanup;
281 } 292 }
282 293
283 acpi_gbl_XSDT = 294 acpi_gbl_XSDT =
@@ -285,4 +296,12 @@ acpi_status acpi_tb_get_table_rsdt(void)
285 296
286 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT)); 297 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT));
287 return_ACPI_STATUS(status); 298 return_ACPI_STATUS(status);
299
300 error_cleanup:
301
302 /* Free table allocated by acpi_tb_get_table */
303
304 acpi_tb_delete_single_table(&table_info);
305
306 return_ACPI_STATUS(status);
288} 307}
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c
index 4e91f2984815..7767987be15a 100644
--- a/drivers/acpi/tables/tbxface.c
+++ b/drivers/acpi/tables/tbxface.c
@@ -134,8 +134,8 @@ ACPI_EXPORT_SYMBOL(acpi_load_tables)
134 * RETURN: Status 134 * RETURN: Status
135 * 135 *
136 * DESCRIPTION: This function is called to load a table from the caller's 136 * DESCRIPTION: This function is called to load a table from the caller's
137 * buffer. The buffer must contain an entire ACPI Table including 137 * buffer. The buffer must contain an entire ACPI Table including
138 * a valid header. The header fields will be verified, and if it 138 * a valid header. The header fields will be verified, and if it
139 * is determined that the table is invalid, the call will fail. 139 * is determined that the table is invalid, the call will fail.
140 * 140 *
141 ******************************************************************************/ 141 ******************************************************************************/
@@ -245,15 +245,18 @@ acpi_status acpi_unload_table(acpi_table_type table_type)
245 /* Find all tables of the requested type */ 245 /* Find all tables of the requested type */
246 246
247 table_desc = acpi_gbl_table_lists[table_type].next; 247 table_desc = acpi_gbl_table_lists[table_type].next;
248 if (!table_desc) {
249 return_ACPI_STATUS(AE_NOT_EXIST);
250 }
251
248 while (table_desc) { 252 while (table_desc) {
249 /* 253 /*
250 * Delete all namespace entries owned by this table. Note that these 254 * Delete all namespace objects owned by this table. Note that these
251 * entries can appear anywhere in the namespace by virtue of the AML 255 * objects can appear anywhere in the namespace by virtue of the AML
252 * "Scope" operator. Thus, we need to track ownership by an ID, not 256 * "Scope" operator. Thus, we need to track ownership by an ID, not
253 * simply a position within the hierarchy 257 * simply a position within the hierarchy
254 */ 258 */
255 acpi_ns_delete_namespace_by_owner(table_desc->owner_id); 259 acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
256 acpi_ut_release_owner_id(&table_desc->owner_id);
257 table_desc = table_desc->next; 260 table_desc = table_desc->next;
258 } 261 }
259 262
@@ -275,12 +278,12 @@ ACPI_EXPORT_SYMBOL(acpi_unload_table)
275 * see acpi_gbl_acpi_table_flag 278 * see acpi_gbl_acpi_table_flag
276 * out_table_header - pointer to the struct acpi_table_header if successful 279 * out_table_header - pointer to the struct acpi_table_header if successful
277 * 280 *
278 * DESCRIPTION: This function is called to get an ACPI table header. The caller 281 * DESCRIPTION: This function is called to get an ACPI table header. The caller
279 * supplies an pointer to a data area sufficient to contain an ACPI 282 * supplies an pointer to a data area sufficient to contain an ACPI
280 * struct acpi_table_header structure. 283 * struct acpi_table_header structure.
281 * 284 *
282 * The header contains a length field that can be used to determine 285 * The header contains a length field that can be used to determine
283 * the size of the buffer needed to contain the entire table. This 286 * the size of the buffer needed to contain the entire table. This
284 * function is not valid for the RSD PTR table since it does not 287 * function is not valid for the RSD PTR table since it does not
285 * have a standard header and is fixed length. 288 * have a standard header and is fixed length.
286 * 289 *
@@ -322,7 +325,8 @@ acpi_get_table_header(acpi_table_type table_type,
322 325
323 /* Copy the header to the caller's buffer */ 326 /* Copy the header to the caller's buffer */
324 327
325 ACPI_MEMCPY((void *)out_table_header, (void *)tbl_ptr, 328 ACPI_MEMCPY(ACPI_CAST_PTR(void, out_table_header),
329 ACPI_CAST_PTR(void, tbl_ptr),
326 sizeof(struct acpi_table_header)); 330 sizeof(struct acpi_table_header));
327 331
328 return_ACPI_STATUS(status); 332 return_ACPI_STATUS(status);
@@ -344,10 +348,10 @@ ACPI_EXPORT_SYMBOL(acpi_get_table_header)
344 * 348 *
345 * RETURN: Status 349 * RETURN: Status
346 * 350 *
347 * DESCRIPTION: This function is called to get an ACPI table. The caller 351 * DESCRIPTION: This function is called to get an ACPI table. The caller
348 * supplies an out_buffer large enough to contain the entire ACPI 352 * supplies an out_buffer large enough to contain the entire ACPI
349 * table. The caller should call the acpi_get_table_header function 353 * table. The caller should call the acpi_get_table_header function
350 * first to determine the buffer size needed. Upon completion 354 * first to determine the buffer size needed. Upon completion
351 * the out_buffer->Length field will indicate the number of bytes 355 * the out_buffer->Length field will indicate the number of bytes
352 * copied into the out_buffer->buf_ptr buffer. This table will be 356 * copied into the out_buffer->buf_ptr buffer. This table will be
353 * a complete table including the header. 357 * a complete table including the header.
@@ -417,7 +421,9 @@ acpi_get_table(acpi_table_type table_type,
417 421
418 /* Copy the table to the buffer */ 422 /* Copy the table to the buffer */
419 423
420 ACPI_MEMCPY((void *)ret_buffer->pointer, (void *)tbl_ptr, table_length); 424 ACPI_MEMCPY(ACPI_CAST_PTR(void, ret_buffer->pointer),
425 ACPI_CAST_PTR(void, tbl_ptr), table_length);
426
421 return_ACPI_STATUS(AE_OK); 427 return_ACPI_STATUS(AE_OK);
422} 428}
423 429
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index c855f4446b5f..5753d06b7860 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -162,7 +162,7 @@ struct acpi_thermal_flags {
162}; 162};
163 163
164struct acpi_thermal { 164struct acpi_thermal {
165 acpi_handle handle; 165 struct acpi_device * device;
166 acpi_bus_id name; 166 acpi_bus_id name;
167 unsigned long temperature; 167 unsigned long temperature;
168 unsigned long last_temperature; 168 unsigned long last_temperature;
@@ -176,21 +176,21 @@ struct acpi_thermal {
176 struct timer_list timer; 176 struct timer_list timer;
177}; 177};
178 178
179static struct file_operations acpi_thermal_state_fops = { 179static const struct file_operations acpi_thermal_state_fops = {
180 .open = acpi_thermal_state_open_fs, 180 .open = acpi_thermal_state_open_fs,
181 .read = seq_read, 181 .read = seq_read,
182 .llseek = seq_lseek, 182 .llseek = seq_lseek,
183 .release = single_release, 183 .release = single_release,
184}; 184};
185 185
186static struct file_operations acpi_thermal_temp_fops = { 186static const struct file_operations acpi_thermal_temp_fops = {
187 .open = acpi_thermal_temp_open_fs, 187 .open = acpi_thermal_temp_open_fs,
188 .read = seq_read, 188 .read = seq_read,
189 .llseek = seq_lseek, 189 .llseek = seq_lseek,
190 .release = single_release, 190 .release = single_release,
191}; 191};
192 192
193static struct file_operations acpi_thermal_trip_fops = { 193static const struct file_operations acpi_thermal_trip_fops = {
194 .open = acpi_thermal_trip_open_fs, 194 .open = acpi_thermal_trip_open_fs,
195 .read = seq_read, 195 .read = seq_read,
196 .write = acpi_thermal_write_trip_points, 196 .write = acpi_thermal_write_trip_points,
@@ -198,7 +198,7 @@ static struct file_operations acpi_thermal_trip_fops = {
198 .release = single_release, 198 .release = single_release,
199}; 199};
200 200
201static struct file_operations acpi_thermal_cooling_fops = { 201static const struct file_operations acpi_thermal_cooling_fops = {
202 .open = acpi_thermal_cooling_open_fs, 202 .open = acpi_thermal_cooling_open_fs,
203 .read = seq_read, 203 .read = seq_read,
204 .write = acpi_thermal_write_cooling_mode, 204 .write = acpi_thermal_write_cooling_mode,
@@ -206,7 +206,7 @@ static struct file_operations acpi_thermal_cooling_fops = {
206 .release = single_release, 206 .release = single_release,
207}; 207};
208 208
209static struct file_operations acpi_thermal_polling_fops = { 209static const struct file_operations acpi_thermal_polling_fops = {
210 .open = acpi_thermal_polling_open_fs, 210 .open = acpi_thermal_polling_open_fs,
211 .read = seq_read, 211 .read = seq_read,
212 .write = acpi_thermal_write_polling, 212 .write = acpi_thermal_write_polling,
@@ -229,7 +229,7 @@ static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
229 tz->last_temperature = tz->temperature; 229 tz->last_temperature = tz->temperature;
230 230
231 status = 231 status =
232 acpi_evaluate_integer(tz->handle, "_TMP", NULL, &tz->temperature); 232 acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
233 if (ACPI_FAILURE(status)) 233 if (ACPI_FAILURE(status))
234 return -ENODEV; 234 return -ENODEV;
235 235
@@ -248,7 +248,7 @@ static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
248 return -EINVAL; 248 return -EINVAL;
249 249
250 status = 250 status =
251 acpi_evaluate_integer(tz->handle, "_TZP", NULL, 251 acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
252 &tz->polling_frequency); 252 &tz->polling_frequency);
253 if (ACPI_FAILURE(status)) 253 if (ACPI_FAILURE(status))
254 return -ENODEV; 254 return -ENODEV;
@@ -285,7 +285,7 @@ static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
285 if (!tz) 285 if (!tz)
286 return -EINVAL; 286 return -EINVAL;
287 287
288 status = acpi_get_handle(tz->handle, "_SCP", &handle); 288 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
289 if (ACPI_FAILURE(status)) { 289 if (ACPI_FAILURE(status)) {
290 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); 290 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
291 return -ENODEV; 291 return -ENODEV;
@@ -316,7 +316,7 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
316 316
317 /* Critical Shutdown (required) */ 317 /* Critical Shutdown (required) */
318 318
319 status = acpi_evaluate_integer(tz->handle, "_CRT", NULL, 319 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
320 &tz->trips.critical.temperature); 320 &tz->trips.critical.temperature);
321 if (ACPI_FAILURE(status)) { 321 if (ACPI_FAILURE(status)) {
322 tz->trips.critical.flags.valid = 0; 322 tz->trips.critical.flags.valid = 0;
@@ -332,7 +332,7 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
332 /* Critical Sleep (optional) */ 332 /* Critical Sleep (optional) */
333 333
334 status = 334 status =
335 acpi_evaluate_integer(tz->handle, "_HOT", NULL, 335 acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
336 &tz->trips.hot.temperature); 336 &tz->trips.hot.temperature);
337 if (ACPI_FAILURE(status)) { 337 if (ACPI_FAILURE(status)) {
338 tz->trips.hot.flags.valid = 0; 338 tz->trips.hot.flags.valid = 0;
@@ -346,7 +346,7 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
346 /* Passive: Processors (optional) */ 346 /* Passive: Processors (optional) */
347 347
348 status = 348 status =
349 acpi_evaluate_integer(tz->handle, "_PSV", NULL, 349 acpi_evaluate_integer(tz->device->handle, "_PSV", NULL,
350 &tz->trips.passive.temperature); 350 &tz->trips.passive.temperature);
351 if (ACPI_FAILURE(status)) { 351 if (ACPI_FAILURE(status)) {
352 tz->trips.passive.flags.valid = 0; 352 tz->trips.passive.flags.valid = 0;
@@ -355,25 +355,25 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
355 tz->trips.passive.flags.valid = 1; 355 tz->trips.passive.flags.valid = 1;
356 356
357 status = 357 status =
358 acpi_evaluate_integer(tz->handle, "_TC1", NULL, 358 acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
359 &tz->trips.passive.tc1); 359 &tz->trips.passive.tc1);
360 if (ACPI_FAILURE(status)) 360 if (ACPI_FAILURE(status))
361 tz->trips.passive.flags.valid = 0; 361 tz->trips.passive.flags.valid = 0;
362 362
363 status = 363 status =
364 acpi_evaluate_integer(tz->handle, "_TC2", NULL, 364 acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
365 &tz->trips.passive.tc2); 365 &tz->trips.passive.tc2);
366 if (ACPI_FAILURE(status)) 366 if (ACPI_FAILURE(status))
367 tz->trips.passive.flags.valid = 0; 367 tz->trips.passive.flags.valid = 0;
368 368
369 status = 369 status =
370 acpi_evaluate_integer(tz->handle, "_TSP", NULL, 370 acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
371 &tz->trips.passive.tsp); 371 &tz->trips.passive.tsp);
372 if (ACPI_FAILURE(status)) 372 if (ACPI_FAILURE(status))
373 tz->trips.passive.flags.valid = 0; 373 tz->trips.passive.flags.valid = 0;
374 374
375 status = 375 status =
376 acpi_evaluate_reference(tz->handle, "_PSL", NULL, 376 acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
377 &tz->trips.passive.devices); 377 &tz->trips.passive.devices);
378 if (ACPI_FAILURE(status)) 378 if (ACPI_FAILURE(status))
379 tz->trips.passive.flags.valid = 0; 379 tz->trips.passive.flags.valid = 0;
@@ -393,14 +393,14 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
393 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; 393 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
394 394
395 status = 395 status =
396 acpi_evaluate_integer(tz->handle, name, NULL, 396 acpi_evaluate_integer(tz->device->handle, name, NULL,
397 &tz->trips.active[i].temperature); 397 &tz->trips.active[i].temperature);
398 if (ACPI_FAILURE(status)) 398 if (ACPI_FAILURE(status))
399 break; 399 break;
400 400
401 name[2] = 'L'; 401 name[2] = 'L';
402 status = 402 status =
403 acpi_evaluate_reference(tz->handle, name, NULL, 403 acpi_evaluate_reference(tz->device->handle, name, NULL,
404 &tz->trips.active[i].devices); 404 &tz->trips.active[i].devices);
405 if (ACPI_SUCCESS(status)) { 405 if (ACPI_SUCCESS(status)) {
406 tz->trips.active[i].flags.valid = 1; 406 tz->trips.active[i].flags.valid = 1;
@@ -424,7 +424,7 @@ static int acpi_thermal_get_devices(struct acpi_thermal *tz)
424 return -EINVAL; 424 return -EINVAL;
425 425
426 status = 426 status =
427 acpi_evaluate_reference(tz->handle, "_TZD", NULL, &tz->devices); 427 acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
428 if (ACPI_FAILURE(status)) 428 if (ACPI_FAILURE(status))
429 return -ENODEV; 429 return -ENODEV;
430 430
@@ -453,10 +453,6 @@ static int acpi_thermal_call_usermode(char *path)
453 453
454static int acpi_thermal_critical(struct acpi_thermal *tz) 454static int acpi_thermal_critical(struct acpi_thermal *tz)
455{ 455{
456 int result = 0;
457 struct acpi_device *device = NULL;
458
459
460 if (!tz || !tz->trips.critical.flags.valid) 456 if (!tz || !tz->trips.critical.flags.valid)
461 return -EINVAL; 457 return -EINVAL;
462 458
@@ -466,14 +462,10 @@ static int acpi_thermal_critical(struct acpi_thermal *tz)
466 } else if (tz->trips.critical.flags.enabled) 462 } else if (tz->trips.critical.flags.enabled)
467 tz->trips.critical.flags.enabled = 0; 463 tz->trips.critical.flags.enabled = 0;
468 464
469 result = acpi_bus_get_device(tz->handle, &device);
470 if (result)
471 return result;
472
473 printk(KERN_EMERG 465 printk(KERN_EMERG
474 "Critical temperature reached (%ld C), shutting down.\n", 466 "Critical temperature reached (%ld C), shutting down.\n",
475 KELVIN_TO_CELSIUS(tz->temperature)); 467 KELVIN_TO_CELSIUS(tz->temperature));
476 acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_CRITICAL, 468 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
477 tz->trips.critical.flags.enabled); 469 tz->trips.critical.flags.enabled);
478 470
479 acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF); 471 acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF);
@@ -483,10 +475,6 @@ static int acpi_thermal_critical(struct acpi_thermal *tz)
483 475
484static int acpi_thermal_hot(struct acpi_thermal *tz) 476static int acpi_thermal_hot(struct acpi_thermal *tz)
485{ 477{
486 int result = 0;
487 struct acpi_device *device = NULL;
488
489
490 if (!tz || !tz->trips.hot.flags.valid) 478 if (!tz || !tz->trips.hot.flags.valid)
491 return -EINVAL; 479 return -EINVAL;
492 480
@@ -496,11 +484,7 @@ static int acpi_thermal_hot(struct acpi_thermal *tz)
496 } else if (tz->trips.hot.flags.enabled) 484 } else if (tz->trips.hot.flags.enabled)
497 tz->trips.hot.flags.enabled = 0; 485 tz->trips.hot.flags.enabled = 0;
498 486
499 result = acpi_bus_get_device(tz->handle, &device); 487 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
500 if (result)
501 return result;
502
503 acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_HOT,
504 tz->trips.hot.flags.enabled); 488 tz->trips.hot.flags.enabled);
505 489
506 /* TBD: Call user-mode "sleep(S4)" function */ 490 /* TBD: Call user-mode "sleep(S4)" function */
@@ -1193,8 +1177,7 @@ static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1193 if (!tz) 1177 if (!tz)
1194 return; 1178 return;
1195 1179
1196 if (acpi_bus_get_device(tz->handle, &device)) 1180 device = tz->device;
1197 return;
1198 1181
1199 switch (event) { 1182 switch (event) {
1200 case ACPI_THERMAL_NOTIFY_TEMPERATURE: 1183 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
@@ -1293,7 +1276,7 @@ static int acpi_thermal_add(struct acpi_device *device)
1293 return -ENOMEM; 1276 return -ENOMEM;
1294 memset(tz, 0, sizeof(struct acpi_thermal)); 1277 memset(tz, 0, sizeof(struct acpi_thermal));
1295 1278
1296 tz->handle = device->handle; 1279 tz->device = device;
1297 strcpy(tz->name, device->pnp.bus_id); 1280 strcpy(tz->name, device->pnp.bus_id);
1298 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); 1281 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1299 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); 1282 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
@@ -1311,7 +1294,7 @@ static int acpi_thermal_add(struct acpi_device *device)
1311 1294
1312 acpi_thermal_check(tz); 1295 acpi_thermal_check(tz);
1313 1296
1314 status = acpi_install_notify_handler(tz->handle, 1297 status = acpi_install_notify_handler(device->handle,
1315 ACPI_DEVICE_NOTIFY, 1298 ACPI_DEVICE_NOTIFY,
1316 acpi_thermal_notify, tz); 1299 acpi_thermal_notify, tz);
1317 if (ACPI_FAILURE(status)) { 1300 if (ACPI_FAILURE(status)) {
@@ -1352,7 +1335,7 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1352 /* deferred task may reinsert timer */ 1335 /* deferred task may reinsert timer */
1353 del_timer_sync(&(tz->timer)); 1336 del_timer_sync(&(tz->timer));
1354 1337
1355 status = acpi_remove_notify_handler(tz->handle, 1338 status = acpi_remove_notify_handler(device->handle,
1356 ACPI_DEVICE_NOTIFY, 1339 ACPI_DEVICE_NOTIFY,
1357 acpi_thermal_notify); 1340 acpi_thermal_notify);
1358 1341
@@ -1376,13 +1359,28 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1376static int acpi_thermal_resume(struct acpi_device *device, int state) 1359static int acpi_thermal_resume(struct acpi_device *device, int state)
1377{ 1360{
1378 struct acpi_thermal *tz = NULL; 1361 struct acpi_thermal *tz = NULL;
1362 int i;
1379 1363
1380 if (!device || !acpi_driver_data(device)) 1364 if (!device || !acpi_driver_data(device))
1381 return -EINVAL; 1365 return -EINVAL;
1382 1366
1383 tz = (struct acpi_thermal *)acpi_driver_data(device); 1367 tz = (struct acpi_thermal *)acpi_driver_data(device);
1384 1368
1385 acpi_thermal_check(tz); 1369 acpi_thermal_get_temperature(tz);
1370
1371 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1372 if (tz->trips.active[i].flags.valid) {
1373 tz->temperature = tz->trips.active[i].temperature;
1374 tz->trips.active[i].flags.enabled = 0;
1375
1376 acpi_thermal_active(tz);
1377
1378 tz->state.active |= tz->trips.active[i].flags.enabled;
1379 tz->state.active_index = i;
1380 }
1381 }
1382
1383 acpi_thermal_check(tz);
1386 1384
1387 return AE_OK; 1385 return AE_OK;
1388} 1386}
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index 7940fc1bd69e..f6cbc0b1bfd0 100644
--- a/drivers/acpi/utilities/utalloc.c
+++ b/drivers/acpi/utilities/utalloc.c
@@ -166,10 +166,10 @@ acpi_status acpi_ut_delete_caches(void)
166 166
167 /* Free memory lists */ 167 /* Free memory lists */
168 168
169 acpi_os_free(acpi_gbl_global_list); 169 ACPI_FREE(acpi_gbl_global_list);
170 acpi_gbl_global_list = NULL; 170 acpi_gbl_global_list = NULL;
171 171
172 acpi_os_free(acpi_gbl_ns_node_list); 172 ACPI_FREE(acpi_gbl_ns_node_list);
173 acpi_gbl_ns_node_list = NULL; 173 acpi_gbl_ns_node_list = NULL;
174#endif 174#endif
175 175
@@ -285,6 +285,7 @@ acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
285 return (status); 285 return (status);
286} 286}
287 287
288#ifdef NOT_USED_BY_LINUX
288/******************************************************************************* 289/*******************************************************************************
289 * 290 *
290 * FUNCTION: acpi_ut_allocate 291 * FUNCTION: acpi_ut_allocate
@@ -360,3 +361,4 @@ void *acpi_ut_allocate_zeroed(acpi_size size,
360 361
361 return (allocation); 362 return (allocation);
362} 363}
364#endif
diff --git a/drivers/acpi/utilities/utcache.c b/drivers/acpi/utilities/utcache.c
index 56270a30718a..1a1f8109159c 100644
--- a/drivers/acpi/utilities/utcache.c
+++ b/drivers/acpi/utilities/utcache.c
@@ -162,7 +162,7 @@ acpi_status acpi_os_delete_cache(struct acpi_memory_list * cache)
162 162
163 /* Now we can delete the cache object */ 163 /* Now we can delete the cache object */
164 164
165 acpi_os_free(cache); 165 ACPI_FREE(cache);
166 return (AE_OK); 166 return (AE_OK);
167} 167}
168 168
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c
index 5ec1cfcc611d..bb1eaf9aa653 100644
--- a/drivers/acpi/utilities/utdebug.c
+++ b/drivers/acpi/utilities/utdebug.c
@@ -47,7 +47,7 @@
47ACPI_MODULE_NAME("utdebug") 47ACPI_MODULE_NAME("utdebug")
48 48
49#ifdef ACPI_DEBUG_OUTPUT 49#ifdef ACPI_DEBUG_OUTPUT
50static u32 acpi_gbl_prev_thread_id = 0xFFFFFFFF; 50static acpi_thread_id acpi_gbl_prev_thread_id;
51static char *acpi_gbl_fn_entry_str = "----Entry"; 51static char *acpi_gbl_fn_entry_str = "----Entry";
52static char *acpi_gbl_fn_exit_str = "----Exit-"; 52static char *acpi_gbl_fn_exit_str = "----Exit-";
53 53
@@ -181,7 +181,7 @@ acpi_ut_debug_print(u32 requested_debug_level,
181 if (ACPI_LV_THREADS & acpi_dbg_level) { 181 if (ACPI_LV_THREADS & acpi_dbg_level) {
182 acpi_os_printf 182 acpi_os_printf
183 ("\n**** Context Switch from TID %X to TID %X ****\n\n", 183 ("\n**** Context Switch from TID %X to TID %X ****\n\n",
184 acpi_gbl_prev_thread_id, thread_id); 184 (u32) acpi_gbl_prev_thread_id, (u32) thread_id);
185 } 185 }
186 186
187 acpi_gbl_prev_thread_id = thread_id; 187 acpi_gbl_prev_thread_id = thread_id;
diff --git a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c
index 38ebe1c54330..9d3f1149ba21 100644
--- a/drivers/acpi/utilities/utdelete.c
+++ b/drivers/acpi/utilities/utdelete.c
@@ -447,11 +447,16 @@ acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action)
447 */ 447 */
448 switch (ACPI_GET_OBJECT_TYPE(object)) { 448 switch (ACPI_GET_OBJECT_TYPE(object)) {
449 case ACPI_TYPE_DEVICE: 449 case ACPI_TYPE_DEVICE:
450 case ACPI_TYPE_PROCESSOR:
451 case ACPI_TYPE_POWER:
452 case ACPI_TYPE_THERMAL:
450 453
451 acpi_ut_update_ref_count(object->device.system_notify, 454 /* Update the notify objects for these types (if present) */
452 action); 455
453 acpi_ut_update_ref_count(object->device.device_notify, 456 acpi_ut_update_ref_count(object->common_notify.
454 action); 457 system_notify, action);
458 acpi_ut_update_ref_count(object->common_notify.
459 device_notify, action);
455 break; 460 break;
456 461
457 case ACPI_TYPE_PACKAGE: 462 case ACPI_TYPE_PACKAGE:
diff --git a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c
index 33268310c738..6d8a8211be90 100644
--- a/drivers/acpi/utilities/utmisc.c
+++ b/drivers/acpi/utilities/utmisc.c
@@ -65,7 +65,7 @@ ACPI_MODULE_NAME("utmisc")
65u8 acpi_ut_is_aml_table(struct acpi_table_header *table) 65u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
66{ 66{
67 67
68 /* Ignore tables that contain AML */ 68 /* These are the only tables that contain executable AML */
69 69
70 if (ACPI_COMPARE_NAME(table->signature, DSDT_SIG) || 70 if (ACPI_COMPARE_NAME(table->signature, DSDT_SIG) ||
71 ACPI_COMPARE_NAME(table->signature, PSDT_SIG) || 71 ACPI_COMPARE_NAME(table->signature, PSDT_SIG) ||
@@ -419,10 +419,15 @@ void acpi_ut_set_integer_width(u8 revision)
419{ 419{
420 420
421 if (revision <= 1) { 421 if (revision <= 1) {
422
423 /* 32-bit case */
424
422 acpi_gbl_integer_bit_width = 32; 425 acpi_gbl_integer_bit_width = 32;
423 acpi_gbl_integer_nybble_width = 8; 426 acpi_gbl_integer_nybble_width = 8;
424 acpi_gbl_integer_byte_width = 4; 427 acpi_gbl_integer_byte_width = 4;
425 } else { 428 } else {
429 /* 64-bit case (ACPI 2.0+) */
430
426 acpi_gbl_integer_bit_width = 64; 431 acpi_gbl_integer_bit_width = 64;
427 acpi_gbl_integer_nybble_width = 16; 432 acpi_gbl_integer_nybble_width = 16;
428 acpi_gbl_integer_byte_width = 8; 433 acpi_gbl_integer_byte_width = 8;
@@ -502,6 +507,7 @@ acpi_ut_display_init_pathname(u8 type,
502 * FUNCTION: acpi_ut_valid_acpi_char 507 * FUNCTION: acpi_ut_valid_acpi_char
503 * 508 *
504 * PARAMETERS: Char - The character to be examined 509 * PARAMETERS: Char - The character to be examined
510 * Position - Byte position (0-3)
505 * 511 *
506 * RETURN: TRUE if the character is valid, FALSE otherwise 512 * RETURN: TRUE if the character is valid, FALSE otherwise
507 * 513 *
@@ -609,7 +615,9 @@ acpi_name acpi_ut_repair_name(acpi_name name)
609 * 615 *
610 * RETURN: Status and Converted value 616 * RETURN: Status and Converted value
611 * 617 *
612 * DESCRIPTION: Convert a string into an unsigned value. 618 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
619 * 32-bit or 64-bit conversion, depending on the current mode
620 * of the interpreter.
613 * NOTE: Does not support Octal strings, not needed. 621 * NOTE: Does not support Octal strings, not needed.
614 * 622 *
615 ******************************************************************************/ 623 ******************************************************************************/
@@ -627,7 +635,7 @@ acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
627 u8 sign_of0x = 0; 635 u8 sign_of0x = 0;
628 u8 term = 0; 636 u8 term = 0;
629 637
630 ACPI_FUNCTION_TRACE(ut_stroul64); 638 ACPI_FUNCTION_TRACE_STR(ut_stroul64, string);
631 639
632 switch (base) { 640 switch (base) {
633 case ACPI_ANY_BASE: 641 case ACPI_ANY_BASE:
@@ -675,11 +683,13 @@ acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
675 } 683 }
676 } 684 }
677 685
686 /*
687 * Perform a 32-bit or 64-bit conversion, depending upon the current
688 * execution mode of the interpreter
689 */
678 dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX; 690 dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
679 691
680 /* At least one character in the string here */ 692 /* Main loop: convert the string to a 32- or 64-bit integer */
681
682 /* Main loop: convert the string to a 64-bit integer */
683 693
684 while (*string) { 694 while (*string) {
685 if (ACPI_IS_DIGIT(*string)) { 695 if (ACPI_IS_DIGIT(*string)) {
@@ -754,6 +764,9 @@ acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
754 764
755 all_done: 765 all_done:
756 766
767 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
768 ACPI_FORMAT_UINT64(return_value)));
769
757 *ret_integer = return_value; 770 *ret_integer = return_value;
758 return_ACPI_STATUS(AE_OK); 771 return_ACPI_STATUS(AE_OK);
759 772
diff --git a/drivers/acpi/utilities/utmutex.c b/drivers/acpi/utilities/utmutex.c
index dfc8f30ca892..c39062a047cd 100644
--- a/drivers/acpi/utilities/utmutex.c
+++ b/drivers/acpi/utilities/utmutex.c
@@ -244,14 +244,14 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
244 244
245 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 245 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
246 "Thread %X attempting to acquire Mutex [%s]\n", 246 "Thread %X attempting to acquire Mutex [%s]\n",
247 this_thread_id, acpi_ut_get_mutex_name(mutex_id))); 247 (u32) this_thread_id, acpi_ut_get_mutex_name(mutex_id)));
248 248
249 status = acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex, 249 status = acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex,
250 ACPI_WAIT_FOREVER); 250 ACPI_WAIT_FOREVER);
251 if (ACPI_SUCCESS(status)) { 251 if (ACPI_SUCCESS(status)) {
252 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 252 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
253 "Thread %X acquired Mutex [%s]\n", 253 "Thread %X acquired Mutex [%s]\n",
254 this_thread_id, 254 (u32) this_thread_id,
255 acpi_ut_get_mutex_name(mutex_id))); 255 acpi_ut_get_mutex_name(mutex_id)));
256 256
257 acpi_gbl_mutex_info[mutex_id].use_count++; 257 acpi_gbl_mutex_info[mutex_id].use_count++;
@@ -259,7 +259,7 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
259 } else { 259 } else {
260 ACPI_EXCEPTION((AE_INFO, status, 260 ACPI_EXCEPTION((AE_INFO, status,
261 "Thread %X could not acquire Mutex [%X]", 261 "Thread %X could not acquire Mutex [%X]",
262 this_thread_id, mutex_id)); 262 (u32) this_thread_id, mutex_id));
263 } 263 }
264 264
265 return (status); 265 return (status);
@@ -285,7 +285,7 @@ acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id)
285 285
286 this_thread_id = acpi_os_get_thread_id(); 286 this_thread_id = acpi_os_get_thread_id();
287 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 287 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
288 "Thread %X releasing Mutex [%s]\n", this_thread_id, 288 "Thread %X releasing Mutex [%s]\n", (u32) this_thread_id,
289 acpi_ut_get_mutex_name(mutex_id))); 289 acpi_ut_get_mutex_name(mutex_id)));
290 290
291 if (mutex_id > ACPI_MAX_MUTEX) { 291 if (mutex_id > ACPI_MAX_MUTEX) {
diff --git a/drivers/acpi/utilities/utstate.c b/drivers/acpi/utilities/utstate.c
index 0f5c5bb5deff..eaa13d05c859 100644
--- a/drivers/acpi/utilities/utstate.c
+++ b/drivers/acpi/utilities/utstate.c
@@ -199,6 +199,13 @@ struct acpi_thread_state *acpi_ut_create_thread_state(void)
199 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD; 199 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
200 state->thread.thread_id = acpi_os_get_thread_id(); 200 state->thread.thread_id = acpi_os_get_thread_id();
201 201
202 /* Check for invalid thread ID - zero is very bad, it will break things */
203
204 if (!state->thread.thread_id) {
205 ACPI_ERROR((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
206 state->thread.thread_id = (acpi_thread_id) 1;
207 }
208
202 return_PTR((struct acpi_thread_state *)state); 209 return_PTR((struct acpi_thread_state *)state);
203} 210}
204 211
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 1930e1a75b22..d0d84c43a9d4 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -262,7 +262,7 @@ acpi_evaluate_integer(acpi_handle handle,
262 if (!data) 262 if (!data)
263 return AE_BAD_PARAMETER; 263 return AE_BAD_PARAMETER;
264 264
265 element = kmalloc(sizeof(union acpi_object), GFP_KERNEL); 265 element = kmalloc(sizeof(union acpi_object), irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
266 if (!element) 266 if (!element)
267 return AE_NO_MEMORY; 267 return AE_NO_MEMORY;
268 268
@@ -332,7 +332,7 @@ acpi_evaluate_string(acpi_handle handle,
332 332
333 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%s]\n", *data)); 333 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%s]\n", *data));
334 334
335 acpi_os_free(buffer.pointer); 335 kfree(buffer.pointer);
336 336
337 return AE_OK; 337 return AE_OK;
338} 338}
@@ -418,7 +418,7 @@ acpi_evaluate_reference(acpi_handle handle,
418 //kfree(list->handles); 418 //kfree(list->handles);
419 } 419 }
420 420
421 acpi_os_free(buffer.pointer); 421 kfree(buffer.pointer);
422 422
423 return status; 423 return status;
424} 424}
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 9feb633087a9..56666a982476 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -117,7 +117,7 @@ struct acpi_video_enumerated_device {
117}; 117};
118 118
119struct acpi_video_bus { 119struct acpi_video_bus {
120 acpi_handle handle; 120 struct acpi_device *device;
121 u8 dos_setting; 121 u8 dos_setting;
122 struct acpi_video_enumerated_device *attached_array; 122 struct acpi_video_enumerated_device *attached_array;
123 u8 attached_count; 123 u8 attached_count;
@@ -155,7 +155,6 @@ struct acpi_video_device_brightness {
155}; 155};
156 156
157struct acpi_video_device { 157struct acpi_video_device {
158 acpi_handle handle;
159 unsigned long device_id; 158 unsigned long device_id;
160 struct acpi_video_device_flags flags; 159 struct acpi_video_device_flags flags;
161 struct acpi_video_device_cap cap; 160 struct acpi_video_device_cap cap;
@@ -272,7 +271,8 @@ static int
272acpi_video_device_query(struct acpi_video_device *device, unsigned long *state) 271acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
273{ 272{
274 int status; 273 int status;
275 status = acpi_evaluate_integer(device->handle, "_DGS", NULL, state); 274
275 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
276 276
277 return status; 277 return status;
278} 278}
@@ -283,8 +283,7 @@ acpi_video_device_get_state(struct acpi_video_device *device,
283{ 283{
284 int status; 284 int status;
285 285
286 286 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
287 status = acpi_evaluate_integer(device->handle, "_DCS", NULL, state);
288 287
289 return status; 288 return status;
290} 289}
@@ -299,7 +298,7 @@ acpi_video_device_set_state(struct acpi_video_device *device, int state)
299 298
300 299
301 arg0.integer.value = state; 300 arg0.integer.value = state;
302 status = acpi_evaluate_integer(device->handle, "_DSS", &args, &ret); 301 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
303 302
304 return status; 303 return status;
305} 304}
@@ -315,7 +314,7 @@ acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
315 314
316 *levels = NULL; 315 *levels = NULL;
317 316
318 status = acpi_evaluate_object(device->handle, "_BCL", NULL, &buffer); 317 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
319 if (!ACPI_SUCCESS(status)) 318 if (!ACPI_SUCCESS(status))
320 return status; 319 return status;
321 obj = (union acpi_object *)buffer.pointer; 320 obj = (union acpi_object *)buffer.pointer;
@@ -344,7 +343,7 @@ acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
344 343
345 344
346 arg0.integer.value = level; 345 arg0.integer.value = level;
347 status = acpi_evaluate_object(device->handle, "_BCM", &args, NULL); 346 status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
348 347
349 printk(KERN_DEBUG "set_level status: %x\n", status); 348 printk(KERN_DEBUG "set_level status: %x\n", status);
350 return status; 349 return status;
@@ -356,7 +355,7 @@ acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
356{ 355{
357 int status; 356 int status;
358 357
359 status = acpi_evaluate_integer(device->handle, "_BQC", NULL, level); 358 status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
360 359
361 return status; 360 return status;
362} 361}
@@ -383,7 +382,7 @@ acpi_video_device_EDID(struct acpi_video_device *device,
383 else 382 else
384 return -EINVAL; 383 return -EINVAL;
385 384
386 status = acpi_evaluate_object(device->handle, "_DDC", &args, &buffer); 385 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
387 if (ACPI_FAILURE(status)) 386 if (ACPI_FAILURE(status))
388 return -ENODEV; 387 return -ENODEV;
389 388
@@ -413,7 +412,7 @@ acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
413 412
414 arg0.integer.value = option; 413 arg0.integer.value = option;
415 414
416 status = acpi_evaluate_integer(video->handle, "_SPD", &args, &tmp); 415 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
417 if (ACPI_SUCCESS(status)) 416 if (ACPI_SUCCESS(status))
418 status = tmp ? (-EINVAL) : (AE_OK); 417 status = tmp ? (-EINVAL) : (AE_OK);
419 418
@@ -425,8 +424,7 @@ acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
425{ 424{
426 int status; 425 int status;
427 426
428 427 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
429 status = acpi_evaluate_integer(video->handle, "_GPD", NULL, id);
430 428
431 return status; 429 return status;
432} 430}
@@ -437,7 +435,7 @@ acpi_video_bus_POST_options(struct acpi_video_bus *video,
437{ 435{
438 int status; 436 int status;
439 437
440 status = acpi_evaluate_integer(video->handle, "_VPO", NULL, options); 438 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
441 *options &= 3; 439 *options &= 3;
442 440
443 return status; 441 return status;
@@ -478,7 +476,7 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
478 } 476 }
479 arg0.integer.value = (lcd_flag << 2) | bios_flag; 477 arg0.integer.value = (lcd_flag << 2) | bios_flag;
480 video->dos_setting = arg0.integer.value; 478 video->dos_setting = arg0.integer.value;
481 acpi_evaluate_object(video->handle, "_DOS", &args, NULL); 479 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
482 480
483 Failed: 481 Failed:
484 return status; 482 return status;
@@ -506,25 +504,25 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
506 504
507 memset(&device->cap, 0, 4); 505 memset(&device->cap, 0, 4);
508 506
509 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ADR", &h_dummy1))) { 507 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
510 device->cap._ADR = 1; 508 device->cap._ADR = 1;
511 } 509 }
512 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCL", &h_dummy1))) { 510 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
513 device->cap._BCL = 1; 511 device->cap._BCL = 1;
514 } 512 }
515 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCM", &h_dummy1))) { 513 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
516 device->cap._BCM = 1; 514 device->cap._BCM = 1;
517 } 515 }
518 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DDC", &h_dummy1))) { 516 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
519 device->cap._DDC = 1; 517 device->cap._DDC = 1;
520 } 518 }
521 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DCS", &h_dummy1))) { 519 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
522 device->cap._DCS = 1; 520 device->cap._DCS = 1;
523 } 521 }
524 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DGS", &h_dummy1))) { 522 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
525 device->cap._DGS = 1; 523 device->cap._DGS = 1;
526 } 524 }
527 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DSS", &h_dummy1))) { 525 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
528 device->cap._DSS = 1; 526 device->cap._DSS = 1;
529 } 527 }
530 528
@@ -588,22 +586,22 @@ static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
588 acpi_handle h_dummy1; 586 acpi_handle h_dummy1;
589 587
590 memset(&video->cap, 0, 4); 588 memset(&video->cap, 0, 4);
591 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOS", &h_dummy1))) { 589 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
592 video->cap._DOS = 1; 590 video->cap._DOS = 1;
593 } 591 }
594 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOD", &h_dummy1))) { 592 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
595 video->cap._DOD = 1; 593 video->cap._DOD = 1;
596 } 594 }
597 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_ROM", &h_dummy1))) { 595 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
598 video->cap._ROM = 1; 596 video->cap._ROM = 1;
599 } 597 }
600 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_GPD", &h_dummy1))) { 598 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
601 video->cap._GPD = 1; 599 video->cap._GPD = 1;
602 } 600 }
603 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_SPD", &h_dummy1))) { 601 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
604 video->cap._SPD = 1; 602 video->cap._SPD = 1;
605 } 603 }
606 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_VPO", &h_dummy1))) { 604 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
607 video->cap._VPO = 1; 605 video->cap._VPO = 1;
608 } 606 }
609} 607}
@@ -1271,7 +1269,6 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1271 1269
1272 memset(data, 0, sizeof(struct acpi_video_device)); 1270 memset(data, 0, sizeof(struct acpi_video_device));
1273 1271
1274 data->handle = device->handle;
1275 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME); 1272 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1276 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); 1273 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1277 acpi_driver_data(device) = data; 1274 acpi_driver_data(device) = data;
@@ -1298,7 +1295,7 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1298 acpi_video_device_bind(video, data); 1295 acpi_video_device_bind(video, data);
1299 acpi_video_device_find_cap(data); 1296 acpi_video_device_find_cap(data);
1300 1297
1301 status = acpi_install_notify_handler(data->handle, 1298 status = acpi_install_notify_handler(device->handle,
1302 ACPI_DEVICE_NOTIFY, 1299 ACPI_DEVICE_NOTIFY,
1303 acpi_video_device_notify, 1300 acpi_video_device_notify,
1304 data); 1301 data);
@@ -1400,8 +1397,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1400 union acpi_object *dod = NULL; 1397 union acpi_object *dod = NULL;
1401 union acpi_object *obj; 1398 union acpi_object *obj;
1402 1399
1403 1400 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1404 status = acpi_evaluate_object(video->handle, "_DOD", NULL, &buffer);
1405 if (!ACPI_SUCCESS(status)) { 1401 if (!ACPI_SUCCESS(status)) {
1406 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD")); 1402 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1407 return status; 1403 return status;
@@ -1450,7 +1446,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1450 video->attached_array = active_device_list; 1446 video->attached_array = active_device_list;
1451 video->attached_count = count; 1447 video->attached_count = count;
1452 out: 1448 out:
1453 acpi_os_free(buffer.pointer); 1449 kfree(buffer.pointer);
1454 return status; 1450 return status;
1455} 1451}
1456 1452
@@ -1569,7 +1565,7 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1569 up(&video->sem); 1565 up(&video->sem);
1570 acpi_video_device_remove_fs(device->dev); 1566 acpi_video_device_remove_fs(device->dev);
1571 1567
1572 status = acpi_remove_notify_handler(device->handle, 1568 status = acpi_remove_notify_handler(device->dev->handle,
1573 ACPI_DEVICE_NOTIFY, 1569 ACPI_DEVICE_NOTIFY,
1574 acpi_video_device_notify); 1570 acpi_video_device_notify);
1575 1571
@@ -1624,8 +1620,7 @@ static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1624 if (!video) 1620 if (!video)
1625 return; 1621 return;
1626 1622
1627 if (acpi_bus_get_device(handle, &device)) 1623 device = video->device;
1628 return;
1629 1624
1630 switch (event) { 1625 switch (event) {
1631 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur, 1626 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur,
@@ -1668,8 +1663,7 @@ static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1668 if (!video_device) 1663 if (!video_device)
1669 return; 1664 return;
1670 1665
1671 if (acpi_bus_get_device(handle, &device)) 1666 device = video_device->dev;
1672 return;
1673 1667
1674 switch (event) { 1668 switch (event) {
1675 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */ 1669 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
@@ -1707,7 +1701,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
1707 return -ENOMEM; 1701 return -ENOMEM;
1708 memset(video, 0, sizeof(struct acpi_video_bus)); 1702 memset(video, 0, sizeof(struct acpi_video_bus));
1709 1703
1710 video->handle = device->handle; 1704 video->device = device;
1711 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME); 1705 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1712 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); 1706 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1713 acpi_driver_data(device) = video; 1707 acpi_driver_data(device) = video;
@@ -1727,7 +1721,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
1727 acpi_video_bus_get_devices(video, device); 1721 acpi_video_bus_get_devices(video, device);
1728 acpi_video_bus_start_devices(video); 1722 acpi_video_bus_start_devices(video);
1729 1723
1730 status = acpi_install_notify_handler(video->handle, 1724 status = acpi_install_notify_handler(device->handle,
1731 ACPI_DEVICE_NOTIFY, 1725 ACPI_DEVICE_NOTIFY,
1732 acpi_video_bus_notify, video); 1726 acpi_video_bus_notify, video);
1733 if (ACPI_FAILURE(status)) { 1727 if (ACPI_FAILURE(status)) {
@@ -1767,7 +1761,7 @@ static int acpi_video_bus_remove(struct acpi_device *device, int type)
1767 1761
1768 acpi_video_bus_stop_devices(video); 1762 acpi_video_bus_stop_devices(video);
1769 1763
1770 status = acpi_remove_notify_handler(video->handle, 1764 status = acpi_remove_notify_handler(video->device->handle,
1771 ACPI_DEVICE_NOTIFY, 1765 ACPI_DEVICE_NOTIFY,
1772 acpi_video_bus_notify); 1766 acpi_video_bus_notify);
1773 1767
diff --git a/drivers/atm/Kconfig b/drivers/atm/Kconfig
index 01a9f1cb7743..cfa5af883e13 100644
--- a/drivers/atm/Kconfig
+++ b/drivers/atm/Kconfig
@@ -398,7 +398,7 @@ config ATM_FORE200E_USE_TASKLET
398 default n 398 default n
399 help 399 help
400 This defers work to be done by the interrupt handler to a 400 This defers work to be done by the interrupt handler to a
401 tasklet instead of hanlding everything at interrupt time. This 401 tasklet instead of handling everything at interrupt time. This
402 may improve the responsive of the host. 402 may improve the responsive of the host.
403 403
404config ATM_FORE200E_TX_RETRY 404config ATM_FORE200E_TX_RETRY
diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
index d3b426313a41..4521a249dd56 100644
--- a/drivers/atm/ambassador.c
+++ b/drivers/atm/ambassador.c
@@ -31,6 +31,7 @@
31#include <linux/atmdev.h> 31#include <linux/atmdev.h>
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/interrupt.h> 33#include <linux/interrupt.h>
34#include <linux/poison.h>
34 35
35#include <asm/atomic.h> 36#include <asm/atomic.h>
36#include <asm/io.h> 37#include <asm/io.h>
@@ -1995,7 +1996,7 @@ static int __devinit ucode_init (loader_block * lb, amb_dev * dev) {
1995 } 1996 }
1996 i += 1; 1997 i += 1;
1997 } 1998 }
1998 if (*pointer == 0xdeadbeef) { 1999 if (*pointer == ATM_POISON) {
1999 return loader_start (lb, dev, ucode_start); 2000 return loader_start (lb, dev, ucode_start);
2000 } else { 2001 } else {
2001 // cast needed as there is no %? for pointer differnces 2002 // cast needed as there is no %? for pointer differnces
diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index 5d1c6c95262c..b0369bb20f08 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -35,6 +35,7 @@ static char const rcsid[] =
35 35
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/pci.h> 37#include <linux/pci.h>
38#include <linux/poison.h>
38#include <linux/skbuff.h> 39#include <linux/skbuff.h>
39#include <linux/kernel.h> 40#include <linux/kernel.h>
40#include <linux/vmalloc.h> 41#include <linux/vmalloc.h>
@@ -3657,7 +3658,7 @@ probe_sram(struct idt77252_dev *card)
3657 writel(SAR_CMD_WRITE_SRAM | (0 << 2), SAR_REG_CMD); 3658 writel(SAR_CMD_WRITE_SRAM | (0 << 2), SAR_REG_CMD);
3658 3659
3659 for (addr = 0x4000; addr < 0x80000; addr += 0x4000) { 3660 for (addr = 0x4000; addr < 0x80000; addr += 0x4000) {
3660 writel(0xdeadbeef, SAR_REG_DR0); 3661 writel(ATM_POISON, SAR_REG_DR0);
3661 writel(SAR_CMD_WRITE_SRAM | (addr << 2), SAR_REG_CMD); 3662 writel(SAR_CMD_WRITE_SRAM | (addr << 2), SAR_REG_CMD);
3662 3663
3663 writel(SAR_CMD_READ_SRAM | (0 << 2), SAR_REG_CMD); 3664 writel(SAR_CMD_READ_SRAM | (0 << 2), SAR_REG_CMD);
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 80502dc6ed66..0b4e22436935 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -20,7 +20,7 @@ config PREVENT_FIRMWARE_BUILD
20 20
21config FW_LOADER 21config FW_LOADER
22 tristate "Userspace firmware loading support" 22 tristate "Userspace firmware loading support"
23 select HOTPLUG 23 depends on HOTPLUG
24 ---help--- 24 ---help---
25 This option is provided for the case where no in-kernel-tree modules 25 This option is provided for the case where no in-kernel-tree modules
26 require userspace firmware loading support, but a module built outside 26 require userspace firmware loading support, but a module built outside
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 83fa8b291a59..2e954d07175a 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -129,7 +129,7 @@ static struct kobj_type ktype_bus = {
129 129
130}; 130};
131 131
132decl_subsys(bus, &ktype_bus, NULL); 132static decl_subsys(bus, &ktype_bus, NULL);
133 133
134 134
135#ifdef CONFIG_HOTPLUG 135#ifdef CONFIG_HOTPLUG
@@ -598,12 +598,13 @@ void put_bus(struct bus_type * bus)
598 * 598 *
599 * Note that kset_find_obj increments bus' reference count. 599 * Note that kset_find_obj increments bus' reference count.
600 */ 600 */
601 601#if 0
602struct bus_type * find_bus(char * name) 602struct bus_type * find_bus(char * name)
603{ 603{
604 struct kobject * k = kset_find_obj(&bus_subsys.kset, name); 604 struct kobject * k = kset_find_obj(&bus_subsys.kset, name);
605 return k ? to_bus(k) : NULL; 605 return k ? to_bus(k) : NULL;
606} 606}
607#endif /* 0 */
607 608
608 609
609/** 610/**
diff --git a/drivers/base/core.c b/drivers/base/core.c
index b21f864c9ce8..be6b5bc0677d 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -559,20 +559,20 @@ static void device_create_release(struct device *dev)
559 559
560/** 560/**
561 * device_create - creates a device and registers it with sysfs 561 * device_create - creates a device and registers it with sysfs
562 * @cs: pointer to the struct class that this device should be registered to. 562 * @class: pointer to the struct class that this device should be registered to
563 * @parent: pointer to the parent struct device of this new device, if any. 563 * @parent: pointer to the parent struct device of this new device, if any
564 * @dev: the dev_t for the char device to be added. 564 * @devt: the dev_t for the char device to be added
565 * @fmt: string for the class device's name 565 * @fmt: string for the device's name
566 *
567 * This function can be used by char device classes. A struct device
568 * will be created in sysfs, registered to the specified class.
566 * 569 *
567 * This function can be used by char device classes. A struct
568 * device will be created in sysfs, registered to the specified
569 * class.
570 * A "dev" file will be created, showing the dev_t for the device, if 570 * A "dev" file will be created, showing the dev_t for the device, if
571 * the dev_t is not 0,0. 571 * the dev_t is not 0,0.
572 * If a pointer to a parent struct device is passed in, the newly 572 * If a pointer to a parent struct device is passed in, the newly created
573 * created struct device will be a child of that device in sysfs. The 573 * struct device will be a child of that device in sysfs.
574 * pointer to the struct device will be returned from the call. Any 574 * The pointer to the struct device will be returned from the call.
575 * further sysfs files that might be required can be created using this 575 * Any further sysfs files that might be required can be created using this
576 * pointer. 576 * pointer.
577 * 577 *
578 * Note: the struct class passed to this function must have previously 578 * Note: the struct class passed to this function must have previously
@@ -620,11 +620,11 @@ EXPORT_SYMBOL_GPL(device_create);
620 620
621/** 621/**
622 * device_destroy - removes a device that was created with device_create() 622 * device_destroy - removes a device that was created with device_create()
623 * @class: the pointer to the struct class that this device was registered * with. 623 * @class: pointer to the struct class that this device was registered with
624 * @dev: the dev_t of the device that was previously registered. 624 * @devt: the dev_t of the device that was previously registered
625 * 625 *
626 * This call unregisters and cleans up a class device that was created with a 626 * This call unregisters and cleans up a device that was created with a
627 * call to class_device_create() 627 * call to device_create().
628 */ 628 */
629void device_destroy(struct class *class, dev_t devt) 629void device_destroy(struct class *class, dev_t devt)
630{ 630{
diff --git a/drivers/base/node.c b/drivers/base/node.c
index d7de1753e094..e9b0957f15d1 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -64,7 +64,7 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
64 "Node %d Mapped: %8lu kB\n" 64 "Node %d Mapped: %8lu kB\n"
65 "Node %d AnonPages: %8lu kB\n" 65 "Node %d AnonPages: %8lu kB\n"
66 "Node %d PageTables: %8lu kB\n" 66 "Node %d PageTables: %8lu kB\n"
67 "Node %d NFS Unstable: %8lu kB\n" 67 "Node %d NFS_Unstable: %8lu kB\n"
68 "Node %d Bounce: %8lu kB\n" 68 "Node %d Bounce: %8lu kB\n"
69 "Node %d Slab: %8lu kB\n", 69 "Node %d Slab: %8lu kB\n",
70 nid, K(i.totalram), 70 nid, K(i.totalram),
diff --git a/drivers/base/topology.c b/drivers/base/topology.c
index c2d621632383..3ef9d514b916 100644
--- a/drivers/base/topology.c
+++ b/drivers/base/topology.c
@@ -139,7 +139,7 @@ static int __cpuinit topology_sysfs_init(void)
139 (void *)(long)i); 139 (void *)(long)i);
140 } 140 }
141 141
142 register_cpu_notifier(&topology_cpu_notifier); 142 register_hotcpu_notifier(&topology_cpu_notifier);
143 143
144 return 0; 144 return 0;
145} 145}
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 93d94749310b..b5382cedf0c0 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -400,6 +400,16 @@ config BLK_DEV_RAM_SIZE
400 what are you doing. If you are using IBM S/390, then set this to 400 what are you doing. If you are using IBM S/390, then set this to
401 8192. 401 8192.
402 402
403config BLK_DEV_RAM_BLOCKSIZE
404 int "Default RAM disk block size (bytes)"
405 depends on BLK_DEV_RAM
406 default "1024"
407 help
408 The default value is 1024 kilobytes. PAGE_SIZE is a much more
409 efficient choice however. The default is kept to ensure initrd
410 setups function - apparently needed by the rd_load_image routine
411 that supposes the filesystem in the image uses a 1024 blocksize.
412
403config BLK_DEV_INITRD 413config BLK_DEV_INITRD
404 bool "Initial RAM filesystem and RAM disk (initramfs/initrd) support" 414 bool "Initial RAM filesystem and RAM disk (initramfs/initrd) support"
405 depends on BROKEN || !FRV 415 depends on BROKEN || !FRV
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 5327f553b4f5..1bc1cf9603f1 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -162,7 +162,7 @@ aoechr_open(struct inode *inode, struct file *filp)
162{ 162{
163 int n, i; 163 int n, i;
164 164
165 n = MINOR(inode->i_rdev); 165 n = iminor(inode);
166 filp->private_data = (void *) (unsigned long) n; 166 filp->private_data = (void *) (unsigned long) n;
167 167
168 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 168 for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 1c4df22dfd2a..2cd3391ff878 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -48,14 +48,14 @@
48#include <linux/completion.h> 48#include <linux/completion.h>
49 49
50#define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin)) 50#define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
51#define DRIVER_NAME "HP CISS Driver (v 2.6.10)" 51#define DRIVER_NAME "HP CISS Driver (v 3.6.10)"
52#define DRIVER_VERSION CCISS_DRIVER_VERSION(2,6,10) 52#define DRIVER_VERSION CCISS_DRIVER_VERSION(3,6,10)
53 53
54/* Embedded module documentation macros - see modules.h */ 54/* Embedded module documentation macros - see modules.h */
55MODULE_AUTHOR("Hewlett-Packard Company"); 55MODULE_AUTHOR("Hewlett-Packard Company");
56MODULE_DESCRIPTION("Driver for HP Controller SA5xxx SA6xxx version 2.6.10"); 56MODULE_DESCRIPTION("Driver for HP Controller SA5xxx SA6xxx version 3.6.10");
57MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400" 57MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400"
58 " SA6i P600 P800 P400 P400i E200 E200i"); 58 " SA6i P600 P800 P400 P400i E200 E200i E500");
59MODULE_LICENSE("GPL"); 59MODULE_LICENSE("GPL");
60 60
61#include "cciss_cmd.h" 61#include "cciss_cmd.h"
@@ -82,6 +82,7 @@ static const struct pci_device_id cciss_pci_device_id[] = {
82 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103C, 0x3213}, 82 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103C, 0x3213},
83 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103C, 0x3214}, 83 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103C, 0x3214},
84 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103C, 0x3215}, 84 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSD, 0x103C, 0x3215},
85 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103C, 0x3233},
85 {0,} 86 {0,}
86}; 87};
87 88
@@ -110,6 +111,7 @@ static struct board_type products[] = {
110 {0x3213103C, "Smart Array E200i", &SA5_access}, 111 {0x3213103C, "Smart Array E200i", &SA5_access},
111 {0x3214103C, "Smart Array E200i", &SA5_access}, 112 {0x3214103C, "Smart Array E200i", &SA5_access},
112 {0x3215103C, "Smart Array E200i", &SA5_access}, 113 {0x3215103C, "Smart Array E200i", &SA5_access},
114 {0x3233103C, "Smart Array E500", &SA5_access},
113}; 115};
114 116
115/* How long to wait (in milliseconds) for board to go into simple mode */ 117/* How long to wait (in milliseconds) for board to go into simple mode */
@@ -1233,6 +1235,50 @@ static inline void complete_buffers(struct bio *bio, int status)
1233 } 1235 }
1234} 1236}
1235 1237
1238static void cciss_check_queues(ctlr_info_t *h)
1239{
1240 int start_queue = h->next_to_run;
1241 int i;
1242
1243 /* check to see if we have maxed out the number of commands that can
1244 * be placed on the queue. If so then exit. We do this check here
1245 * in case the interrupt we serviced was from an ioctl and did not
1246 * free any new commands.
1247 */
1248 if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS)
1249 return;
1250
1251 /* We have room on the queue for more commands. Now we need to queue
1252 * them up. We will also keep track of the next queue to run so
1253 * that every queue gets a chance to be started first.
1254 */
1255 for (i = 0; i < h->highest_lun + 1; i++) {
1256 int curr_queue = (start_queue + i) % (h->highest_lun + 1);
1257 /* make sure the disk has been added and the drive is real
1258 * because this can be called from the middle of init_one.
1259 */
1260 if (!(h->drv[curr_queue].queue) || !(h->drv[curr_queue].heads))
1261 continue;
1262 blk_start_queue(h->gendisk[curr_queue]->queue);
1263
1264 /* check to see if we have maxed out the number of commands
1265 * that can be placed on the queue.
1266 */
1267 if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS) {
1268 if (curr_queue == start_queue) {
1269 h->next_to_run =
1270 (start_queue + 1) % (h->highest_lun + 1);
1271 break;
1272 } else {
1273 h->next_to_run = curr_queue;
1274 break;
1275 }
1276 } else {
1277 curr_queue = (curr_queue + 1) % (h->highest_lun + 1);
1278 }
1279 }
1280}
1281
1236static void cciss_softirq_done(struct request *rq) 1282static void cciss_softirq_done(struct request *rq)
1237{ 1283{
1238 CommandList_struct *cmd = rq->completion_data; 1284 CommandList_struct *cmd = rq->completion_data;
@@ -1264,6 +1310,7 @@ static void cciss_softirq_done(struct request *rq)
1264 spin_lock_irqsave(&h->lock, flags); 1310 spin_lock_irqsave(&h->lock, flags);
1265 end_that_request_last(rq, rq->errors); 1311 end_that_request_last(rq, rq->errors);
1266 cmd_free(h, cmd, 1); 1312 cmd_free(h, cmd, 1);
1313 cciss_check_queues(h);
1267 spin_unlock_irqrestore(&h->lock, flags); 1314 spin_unlock_irqrestore(&h->lock, flags);
1268} 1315}
1269 1316
@@ -2528,8 +2575,6 @@ static irqreturn_t do_cciss_intr(int irq, void *dev_id, struct pt_regs *regs)
2528 CommandList_struct *c; 2575 CommandList_struct *c;
2529 unsigned long flags; 2576 unsigned long flags;
2530 __u32 a, a1, a2; 2577 __u32 a, a1, a2;
2531 int j;
2532 int start_queue = h->next_to_run;
2533 2578
2534 if (interrupt_not_for_us(h)) 2579 if (interrupt_not_for_us(h))
2535 return IRQ_NONE; 2580 return IRQ_NONE;
@@ -2588,45 +2633,6 @@ static irqreturn_t do_cciss_intr(int irq, void *dev_id, struct pt_regs *regs)
2588 } 2633 }
2589 } 2634 }
2590 2635
2591 /* check to see if we have maxed out the number of commands that can
2592 * be placed on the queue. If so then exit. We do this check here
2593 * in case the interrupt we serviced was from an ioctl and did not
2594 * free any new commands.
2595 */
2596 if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS)
2597 goto cleanup;
2598
2599 /* We have room on the queue for more commands. Now we need to queue
2600 * them up. We will also keep track of the next queue to run so
2601 * that every queue gets a chance to be started first.
2602 */
2603 for (j = 0; j < h->highest_lun + 1; j++) {
2604 int curr_queue = (start_queue + j) % (h->highest_lun + 1);
2605 /* make sure the disk has been added and the drive is real
2606 * because this can be called from the middle of init_one.
2607 */
2608 if (!(h->drv[curr_queue].queue) || !(h->drv[curr_queue].heads))
2609 continue;
2610 blk_start_queue(h->gendisk[curr_queue]->queue);
2611
2612 /* check to see if we have maxed out the number of commands
2613 * that can be placed on the queue.
2614 */
2615 if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS) {
2616 if (curr_queue == start_queue) {
2617 h->next_to_run =
2618 (start_queue + 1) % (h->highest_lun + 1);
2619 goto cleanup;
2620 } else {
2621 h->next_to_run = curr_queue;
2622 goto cleanup;
2623 }
2624 } else {
2625 curr_queue = (curr_queue + 1) % (h->highest_lun + 1);
2626 }
2627 }
2628
2629 cleanup:
2630 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 2636 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
2631 return IRQ_HANDLED; 2637 return IRQ_HANDLED;
2632} 2638}
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index 757f42dd8e86..78082edc14b4 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -1739,8 +1739,6 @@ static void getgeometry(int ctlr)
1739 (log_index < id_ctlr_buf->nr_drvs) 1739 (log_index < id_ctlr_buf->nr_drvs)
1740 && (log_unit < NWD); 1740 && (log_unit < NWD);
1741 log_unit++) { 1741 log_unit++) {
1742 struct gendisk *disk = ida_gendisk[ctlr][log_unit];
1743
1744 size = sizeof(sense_log_drv_stat_t); 1742 size = sizeof(sense_log_drv_stat_t);
1745 1743
1746 /* 1744 /*
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 0242cbb86a87..ad1d7065a1b2 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -249,18 +249,6 @@ static int irqdma_allocated;
249#include <linux/cdrom.h> /* for the compatibility eject ioctl */ 249#include <linux/cdrom.h> /* for the compatibility eject ioctl */
250#include <linux/completion.h> 250#include <linux/completion.h>
251 251
252/*
253 * Interrupt freeing also means /proc VFS work - dont do it
254 * from interrupt context. We push this work into keventd:
255 */
256static void fd_free_irq_fn(void *data)
257{
258 fd_free_irq();
259}
260
261static DECLARE_WORK(fd_free_irq_work, fd_free_irq_fn, NULL);
262
263
264static struct request *current_req; 252static struct request *current_req;
265static struct request_queue *floppy_queue; 253static struct request_queue *floppy_queue;
266static void do_fd_request(request_queue_t * q); 254static void do_fd_request(request_queue_t * q);
@@ -826,15 +814,6 @@ static int set_dor(int fdc, char mask, char data)
826 UDRS->select_date = jiffies; 814 UDRS->select_date = jiffies;
827 } 815 }
828 } 816 }
829 /*
830 * We should propagate failures to grab the resources back
831 * nicely from here. Actually we ought to rewrite the fd
832 * driver some day too.
833 */
834 if (newdor & FLOPPY_MOTOR_MASK)
835 floppy_grab_irq_and_dma();
836 if (olddor & FLOPPY_MOTOR_MASK)
837 floppy_release_irq_and_dma();
838 return olddor; 817 return olddor;
839} 818}
840 819
@@ -892,8 +871,6 @@ static int _lock_fdc(int drive, int interruptible, int line)
892 line); 871 line);
893 return -1; 872 return -1;
894 } 873 }
895 if (floppy_grab_irq_and_dma() == -1)
896 return -EBUSY;
897 874
898 if (test_and_set_bit(0, &fdc_busy)) { 875 if (test_and_set_bit(0, &fdc_busy)) {
899 DECLARE_WAITQUEUE(wait, current); 876 DECLARE_WAITQUEUE(wait, current);
@@ -915,6 +892,8 @@ static int _lock_fdc(int drive, int interruptible, int line)
915 892
916 set_current_state(TASK_RUNNING); 893 set_current_state(TASK_RUNNING);
917 remove_wait_queue(&fdc_wait, &wait); 894 remove_wait_queue(&fdc_wait, &wait);
895
896 flush_scheduled_work();
918 } 897 }
919 command_status = FD_COMMAND_NONE; 898 command_status = FD_COMMAND_NONE;
920 899
@@ -948,7 +927,6 @@ static inline void unlock_fdc(void)
948 if (elv_next_request(floppy_queue)) 927 if (elv_next_request(floppy_queue))
949 do_fd_request(floppy_queue); 928 do_fd_request(floppy_queue);
950 spin_unlock_irqrestore(&floppy_lock, flags); 929 spin_unlock_irqrestore(&floppy_lock, flags);
951 floppy_release_irq_and_dma();
952 wake_up(&fdc_wait); 930 wake_up(&fdc_wait);
953} 931}
954 932
@@ -3694,8 +3672,8 @@ static int floppy_release(struct inode *inode, struct file *filp)
3694 } 3672 }
3695 if (!UDRS->fd_ref) 3673 if (!UDRS->fd_ref)
3696 opened_bdev[drive] = NULL; 3674 opened_bdev[drive] = NULL;
3697 floppy_release_irq_and_dma();
3698 mutex_unlock(&open_lock); 3675 mutex_unlock(&open_lock);
3676
3699 return 0; 3677 return 0;
3700} 3678}
3701 3679
@@ -3726,9 +3704,6 @@ static int floppy_open(struct inode *inode, struct file *filp)
3726 if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (filp->f_flags & O_EXCL))) 3704 if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (filp->f_flags & O_EXCL)))
3727 goto out2; 3705 goto out2;
3728 3706
3729 if (floppy_grab_irq_and_dma())
3730 goto out2;
3731
3732 if (filp->f_flags & O_EXCL) 3707 if (filp->f_flags & O_EXCL)
3733 UDRS->fd_ref = -1; 3708 UDRS->fd_ref = -1;
3734 else 3709 else
@@ -3805,7 +3780,6 @@ out:
3805 UDRS->fd_ref--; 3780 UDRS->fd_ref--;
3806 if (!UDRS->fd_ref) 3781 if (!UDRS->fd_ref)
3807 opened_bdev[drive] = NULL; 3782 opened_bdev[drive] = NULL;
3808 floppy_release_irq_and_dma();
3809out2: 3783out2:
3810 mutex_unlock(&open_lock); 3784 mutex_unlock(&open_lock);
3811 return res; 3785 return res;
@@ -3822,14 +3796,9 @@ static int check_floppy_change(struct gendisk *disk)
3822 return 1; 3796 return 1;
3823 3797
3824 if (time_after(jiffies, UDRS->last_checked + UDP->checkfreq)) { 3798 if (time_after(jiffies, UDRS->last_checked + UDP->checkfreq)) {
3825 if (floppy_grab_irq_and_dma()) {
3826 return 1;
3827 }
3828
3829 lock_fdc(drive, 0); 3799 lock_fdc(drive, 0);
3830 poll_drive(0, 0); 3800 poll_drive(0, 0);
3831 process_fd_request(); 3801 process_fd_request();
3832 floppy_release_irq_and_dma();
3833 } 3802 }
3834 3803
3835 if (UTESTF(FD_DISK_CHANGED) || 3804 if (UTESTF(FD_DISK_CHANGED) ||
@@ -4208,6 +4177,11 @@ static int __init floppy_init(void)
4208 int i, unit, drive; 4177 int i, unit, drive;
4209 int err, dr; 4178 int err, dr;
4210 4179
4180#if defined(CONFIG_PPC_MERGE)
4181 if (check_legacy_ioport(FDC1))
4182 return -ENODEV;
4183#endif
4184
4211 raw_cmd = NULL; 4185 raw_cmd = NULL;
4212 4186
4213 for (dr = 0; dr < N_DRIVE; dr++) { 4187 for (dr = 0; dr < N_DRIVE; dr++) {
@@ -4265,13 +4239,6 @@ static int __init floppy_init(void)
4265 } 4239 }
4266 4240
4267 use_virtual_dma = can_use_virtual_dma & 1; 4241 use_virtual_dma = can_use_virtual_dma & 1;
4268#if defined(CONFIG_PPC_MERGE)
4269 if (check_legacy_ioport(FDC1)) {
4270 del_timer(&fd_timeout);
4271 err = -ENODEV;
4272 goto out_unreg_region;
4273 }
4274#endif
4275 fdc_state[0].address = FDC1; 4242 fdc_state[0].address = FDC1;
4276 if (fdc_state[0].address == -1) { 4243 if (fdc_state[0].address == -1) {
4277 del_timer(&fd_timeout); 4244 del_timer(&fd_timeout);
@@ -4346,7 +4313,6 @@ static int __init floppy_init(void)
4346 fdc = 0; 4313 fdc = 0;
4347 del_timer(&fd_timeout); 4314 del_timer(&fd_timeout);
4348 current_drive = 0; 4315 current_drive = 0;
4349 floppy_release_irq_and_dma();
4350 initialising = 0; 4316 initialising = 0;
4351 if (have_no_fdc) { 4317 if (have_no_fdc) {
4352 DPRINT("no floppy controllers found\n"); 4318 DPRINT("no floppy controllers found\n");
@@ -4504,7 +4470,7 @@ static void floppy_release_irq_and_dma(void)
4504 if (irqdma_allocated) { 4470 if (irqdma_allocated) {
4505 fd_disable_dma(); 4471 fd_disable_dma();
4506 fd_free_dma(); 4472 fd_free_dma();
4507 schedule_work(&fd_free_irq_work); 4473 fd_free_irq();
4508 irqdma_allocated = 0; 4474 irqdma_allocated = 0;
4509 } 4475 }
4510 set_dor(0, ~0, 8); 4476 set_dor(0, ~0, 8);
@@ -4600,8 +4566,6 @@ void cleanup_module(void)
4600 /* eject disk, if any */ 4566 /* eject disk, if any */
4601 fd_eject(0); 4567 fd_eject(0);
4602 4568
4603 flush_scheduled_work(); /* fd_free_irq() might be pending */
4604
4605 wait_for_completion(&device_release); 4569 wait_for_completion(&device_release);
4606} 4570}
4607 4571
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 0a1b1ea36ddc..bdbade9a5cf5 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -300,6 +300,15 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
300 lo->disk->disk_name, result); 300 lo->disk->disk_name, result);
301 goto harderror; 301 goto harderror;
302 } 302 }
303
304 if (ntohl(reply.magic) != NBD_REPLY_MAGIC) {
305 printk(KERN_ERR "%s: Wrong magic (0x%lx)\n",
306 lo->disk->disk_name,
307 (unsigned long)ntohl(reply.magic));
308 result = -EPROTO;
309 goto harderror;
310 }
311
303 req = nbd_find_request(lo, reply.handle); 312 req = nbd_find_request(lo, reply.handle);
304 if (unlikely(IS_ERR(req))) { 313 if (unlikely(IS_ERR(req))) {
305 result = PTR_ERR(req); 314 result = PTR_ERR(req);
@@ -312,13 +321,6 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
312 goto harderror; 321 goto harderror;
313 } 322 }
314 323
315 if (ntohl(reply.magic) != NBD_REPLY_MAGIC) {
316 printk(KERN_ERR "%s: Wrong magic (0x%lx)\n",
317 lo->disk->disk_name,
318 (unsigned long)ntohl(reply.magic));
319 result = -EPROTO;
320 goto harderror;
321 }
322 if (ntohl(reply.error)) { 324 if (ntohl(reply.error)) {
323 printk(KERN_ERR "%s: Other side returned error (%d)\n", 325 printk(KERN_ERR "%s: Other side returned error (%d)\n",
324 lo->disk->disk_name, ntohl(reply.error)); 326 lo->disk->disk_name, ntohl(reply.error));
@@ -339,7 +341,8 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
339 printk(KERN_ERR "%s: Receive data failed (result %d)\n", 341 printk(KERN_ERR "%s: Receive data failed (result %d)\n",
340 lo->disk->disk_name, 342 lo->disk->disk_name,
341 result); 343 result);
342 goto harderror; 344 req->errors++;
345 return req;
343 } 346 }
344 dprintk(DBG_RX, "%s: request %p: got %d bytes data\n", 347 dprintk(DBG_RX, "%s: request %p: got %d bytes data\n",
345 lo->disk->disk_name, req, bvec->bv_len); 348 lo->disk->disk_name, req, bvec->bv_len);
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index bde2c64b6346..451b996bba91 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -2577,19 +2577,19 @@ static int pkt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cm
2577 case PKT_CTRL_CMD_SETUP: 2577 case PKT_CTRL_CMD_SETUP:
2578 if (!capable(CAP_SYS_ADMIN)) 2578 if (!capable(CAP_SYS_ADMIN))
2579 return -EPERM; 2579 return -EPERM;
2580 mutex_lock(&ctl_mutex); 2580 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
2581 ret = pkt_setup_dev(&ctrl_cmd); 2581 ret = pkt_setup_dev(&ctrl_cmd);
2582 mutex_unlock(&ctl_mutex); 2582 mutex_unlock(&ctl_mutex);
2583 break; 2583 break;
2584 case PKT_CTRL_CMD_TEARDOWN: 2584 case PKT_CTRL_CMD_TEARDOWN:
2585 if (!capable(CAP_SYS_ADMIN)) 2585 if (!capable(CAP_SYS_ADMIN))
2586 return -EPERM; 2586 return -EPERM;
2587 mutex_lock(&ctl_mutex); 2587 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
2588 ret = pkt_remove_dev(&ctrl_cmd); 2588 ret = pkt_remove_dev(&ctrl_cmd);
2589 mutex_unlock(&ctl_mutex); 2589 mutex_unlock(&ctl_mutex);
2590 break; 2590 break;
2591 case PKT_CTRL_CMD_STATUS: 2591 case PKT_CTRL_CMD_STATUS:
2592 mutex_lock(&ctl_mutex); 2592 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
2593 pkt_get_status(&ctrl_cmd); 2593 pkt_get_status(&ctrl_cmd);
2594 mutex_unlock(&ctl_mutex); 2594 mutex_unlock(&ctl_mutex);
2595 break; 2595 break;
diff --git a/drivers/block/rd.c b/drivers/block/rd.c
index 3cf246abb5ec..a3f64bfe6b58 100644
--- a/drivers/block/rd.c
+++ b/drivers/block/rd.c
@@ -84,7 +84,7 @@ int rd_size = CONFIG_BLK_DEV_RAM_SIZE; /* Size of the RAM disks */
84 * behaviour. The default is still BLOCK_SIZE (needed by rd_load_image that 84 * behaviour. The default is still BLOCK_SIZE (needed by rd_load_image that
85 * supposes the filesystem in the image uses a BLOCK_SIZE blocksize). 85 * supposes the filesystem in the image uses a BLOCK_SIZE blocksize).
86 */ 86 */
87static int rd_blocksize = BLOCK_SIZE; /* blocksize of the RAM disks */ 87static int rd_blocksize = CONFIG_BLK_DEV_RAM_BLOCKSIZE;
88 88
89/* 89/*
90 * Copyright (C) 2000 Linus Torvalds. 90 * Copyright (C) 2000 Linus Torvalds.
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index 3721e12135d9..cc42e762396f 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -250,8 +250,6 @@ static int floppy_open(struct inode *inode, struct file *filp);
250static int floppy_release(struct inode *inode, struct file *filp); 250static int floppy_release(struct inode *inode, struct file *filp);
251static int floppy_check_change(struct gendisk *disk); 251static int floppy_check_change(struct gendisk *disk);
252static int floppy_revalidate(struct gendisk *disk); 252static int floppy_revalidate(struct gendisk *disk);
253static int swim3_add_device(struct device_node *swims);
254int swim3_init(void);
255 253
256#ifndef CONFIG_PMAC_MEDIABAY 254#ifndef CONFIG_PMAC_MEDIABAY
257#define check_media_bay(which, what) 1 255#define check_media_bay(which, what) 1
@@ -1011,114 +1009,63 @@ static struct block_device_operations floppy_fops = {
1011 .revalidate_disk= floppy_revalidate, 1009 .revalidate_disk= floppy_revalidate,
1012}; 1010};
1013 1011
1014int swim3_init(void) 1012static int swim3_add_device(struct macio_dev *mdev, int index)
1015{
1016 struct device_node *swim;
1017 int err = -ENOMEM;
1018 int i;
1019
1020 swim = find_devices("floppy");
1021 while (swim && (floppy_count < MAX_FLOPPIES))
1022 {
1023 swim3_add_device(swim);
1024 swim = swim->next;
1025 }
1026
1027 swim = find_devices("swim3");
1028 while (swim && (floppy_count < MAX_FLOPPIES))
1029 {
1030 swim3_add_device(swim);
1031 swim = swim->next;
1032 }
1033
1034 if (!floppy_count)
1035 return -ENODEV;
1036
1037 for (i = 0; i < floppy_count; i++) {
1038 disks[i] = alloc_disk(1);
1039 if (!disks[i])
1040 goto out;
1041 }
1042
1043 if (register_blkdev(FLOPPY_MAJOR, "fd")) {
1044 err = -EBUSY;
1045 goto out;
1046 }
1047
1048 swim3_queue = blk_init_queue(do_fd_request, &swim3_lock);
1049 if (!swim3_queue) {
1050 err = -ENOMEM;
1051 goto out_queue;
1052 }
1053
1054 for (i = 0; i < floppy_count; i++) {
1055 struct gendisk *disk = disks[i];
1056 disk->major = FLOPPY_MAJOR;
1057 disk->first_minor = i;
1058 disk->fops = &floppy_fops;
1059 disk->private_data = &floppy_states[i];
1060 disk->queue = swim3_queue;
1061 disk->flags |= GENHD_FL_REMOVABLE;
1062 sprintf(disk->disk_name, "fd%d", i);
1063 set_capacity(disk, 2880);
1064 add_disk(disk);
1065 }
1066 return 0;
1067
1068out_queue:
1069 unregister_blkdev(FLOPPY_MAJOR, "fd");
1070out:
1071 while (i--)
1072 put_disk(disks[i]);
1073 /* shouldn't we do something with results of swim_add_device()? */
1074 return err;
1075}
1076
1077static int swim3_add_device(struct device_node *swim)
1078{ 1013{
1014 struct device_node *swim = mdev->ofdev.node;
1079 struct device_node *mediabay; 1015 struct device_node *mediabay;
1080 struct floppy_state *fs = &floppy_states[floppy_count]; 1016 struct floppy_state *fs = &floppy_states[index];
1081 struct resource res_reg, res_dma; 1017 int rc = -EBUSY;
1082 1018
1083 if (of_address_to_resource(swim, 0, &res_reg) || 1019 /* Check & Request resources */
1084 of_address_to_resource(swim, 1, &res_dma)) { 1020 if (macio_resource_count(mdev) < 2) {
1085 printk(KERN_ERR "swim3: Can't get addresses\n"); 1021 printk(KERN_WARNING "ifd%d: no address for %s\n",
1086 return -EINVAL; 1022 index, swim->full_name);
1023 return -ENXIO;
1087 } 1024 }
1088 if (request_mem_region(res_reg.start, res_reg.end - res_reg.start + 1, 1025 if (macio_irq_count(mdev) < 2) {
1089 " (reg)") == NULL) { 1026 printk(KERN_WARNING "fd%d: no intrs for device %s\n",
1090 printk(KERN_ERR "swim3: Can't request register space\n"); 1027 index, swim->full_name);
1091 return -EINVAL;
1092 } 1028 }
1093 if (request_mem_region(res_dma.start, res_dma.end - res_dma.start + 1, 1029 if (macio_request_resource(mdev, 0, "swim3 (mmio)")) {
1094 " (dma)") == NULL) { 1030 printk(KERN_ERR "fd%d: can't request mmio resource for %s\n",
1095 release_mem_region(res_reg.start, 1031 index, swim->full_name);
1096 res_reg.end - res_reg.start + 1); 1032 return -EBUSY;
1097 printk(KERN_ERR "swim3: Can't request DMA space\n");
1098 return -EINVAL;
1099 } 1033 }
1100 1034 if (macio_request_resource(mdev, 1, "swim3 (dma)")) {
1101 if (swim->n_intrs < 2) { 1035 printk(KERN_ERR "fd%d: can't request dma resource for %s\n",
1102 printk(KERN_INFO "swim3: expecting 2 intrs (n_intrs:%d)\n", 1036 index, swim->full_name);
1103 swim->n_intrs); 1037 macio_release_resource(mdev, 0);
1104 release_mem_region(res_reg.start, 1038 return -EBUSY;
1105 res_reg.end - res_reg.start + 1);
1106 release_mem_region(res_dma.start,
1107 res_dma.end - res_dma.start + 1);
1108 return -EINVAL;
1109 } 1039 }
1040 dev_set_drvdata(&mdev->ofdev.dev, fs);
1110 1041
1111 mediabay = (strcasecmp(swim->parent->type, "media-bay") == 0) ? swim->parent : NULL; 1042 mediabay = (strcasecmp(swim->parent->type, "media-bay") == 0) ?
1043 swim->parent : NULL;
1112 if (mediabay == NULL) 1044 if (mediabay == NULL)
1113 pmac_call_feature(PMAC_FTR_SWIM3_ENABLE, swim, 0, 1); 1045 pmac_call_feature(PMAC_FTR_SWIM3_ENABLE, swim, 0, 1);
1114 1046
1115 memset(fs, 0, sizeof(*fs)); 1047 memset(fs, 0, sizeof(*fs));
1116 spin_lock_init(&fs->lock); 1048 spin_lock_init(&fs->lock);
1117 fs->state = idle; 1049 fs->state = idle;
1118 fs->swim3 = (struct swim3 __iomem *)ioremap(res_reg.start, 0x200); 1050 fs->swim3 = (struct swim3 __iomem *)
1119 fs->dma = (struct dbdma_regs __iomem *)ioremap(res_dma.start, 0x200); 1051 ioremap(macio_resource_start(mdev, 0), 0x200);
1120 fs->swim3_intr = swim->intrs[0].line; 1052 if (fs->swim3 == NULL) {
1121 fs->dma_intr = swim->intrs[1].line; 1053 printk("fd%d: couldn't map registers for %s\n",
1054 index, swim->full_name);
1055 rc = -ENOMEM;
1056 goto out_release;
1057 }
1058 fs->dma = (struct dbdma_regs __iomem *)
1059 ioremap(macio_resource_start(mdev, 1), 0x200);
1060 if (fs->dma == NULL) {
1061 printk("fd%d: couldn't map DMA for %s\n",
1062 index, swim->full_name);
1063 iounmap(fs->swim3);
1064 rc = -ENOMEM;
1065 goto out_release;
1066 }
1067 fs->swim3_intr = macio_irq(mdev, 0);
1068 fs->dma_intr = macio_irq(mdev, 1);;
1122 fs->cur_cyl = -1; 1069 fs->cur_cyl = -1;
1123 fs->cur_sector = -1; 1070 fs->cur_sector = -1;
1124 fs->secpercyl = 36; 1071 fs->secpercyl = 36;
@@ -1132,15 +1079,16 @@ static int swim3_add_device(struct device_node *swim)
1132 st_le16(&fs->dma_cmd[1].command, DBDMA_STOP); 1079 st_le16(&fs->dma_cmd[1].command, DBDMA_STOP);
1133 1080
1134 if (request_irq(fs->swim3_intr, swim3_interrupt, 0, "SWIM3", fs)) { 1081 if (request_irq(fs->swim3_intr, swim3_interrupt, 0, "SWIM3", fs)) {
1135 printk(KERN_ERR "Couldn't get irq %d for SWIM3\n", fs->swim3_intr); 1082 printk(KERN_ERR "fd%d: couldn't request irq %d for %s\n",
1083 index, fs->swim3_intr, swim->full_name);
1136 pmac_call_feature(PMAC_FTR_SWIM3_ENABLE, swim, 0, 0); 1084 pmac_call_feature(PMAC_FTR_SWIM3_ENABLE, swim, 0, 0);
1085 goto out_unmap;
1137 return -EBUSY; 1086 return -EBUSY;
1138 } 1087 }
1139/* 1088/*
1140 if (request_irq(fs->dma_intr, fd_dma_interrupt, 0, "SWIM3-dma", fs)) { 1089 if (request_irq(fs->dma_intr, fd_dma_interrupt, 0, "SWIM3-dma", fs)) {
1141 printk(KERN_ERR "Couldn't get irq %d for SWIM3 DMA", 1090 printk(KERN_ERR "Couldn't get irq %d for SWIM3 DMA",
1142 fs->dma_intr); 1091 fs->dma_intr);
1143 pmac_call_feature(PMAC_FTR_SWIM3_ENABLE, swim, 0, 0);
1144 return -EBUSY; 1092 return -EBUSY;
1145 } 1093 }
1146*/ 1094*/
@@ -1150,8 +1098,90 @@ static int swim3_add_device(struct device_node *swim)
1150 printk(KERN_INFO "fd%d: SWIM3 floppy controller %s\n", floppy_count, 1098 printk(KERN_INFO "fd%d: SWIM3 floppy controller %s\n", floppy_count,
1151 mediabay ? "in media bay" : ""); 1099 mediabay ? "in media bay" : "");
1152 1100
1153 floppy_count++; 1101 return 0;
1154 1102
1103 out_unmap:
1104 iounmap(fs->dma);
1105 iounmap(fs->swim3);
1106
1107 out_release:
1108 macio_release_resource(mdev, 0);
1109 macio_release_resource(mdev, 1);
1110
1111 return rc;
1112}
1113
1114static int __devinit swim3_attach(struct macio_dev *mdev, const struct of_device_id *match)
1115{
1116 int i, rc;
1117 struct gendisk *disk;
1118
1119 /* Add the drive */
1120 rc = swim3_add_device(mdev, floppy_count);
1121 if (rc)
1122 return rc;
1123
1124 /* Now create the queue if not there yet */
1125 if (swim3_queue == NULL) {
1126 /* If we failed, there isn't much we can do as the driver is still
1127 * too dumb to remove the device, just bail out
1128 */
1129 if (register_blkdev(FLOPPY_MAJOR, "fd"))
1130 return 0;
1131 swim3_queue = blk_init_queue(do_fd_request, &swim3_lock);
1132 if (swim3_queue == NULL) {
1133 unregister_blkdev(FLOPPY_MAJOR, "fd");
1134 return 0;
1135 }
1136 }
1137
1138 /* Now register that disk. Same comment about failure handling */
1139 i = floppy_count++;
1140 disk = disks[i] = alloc_disk(1);
1141 if (disk == NULL)
1142 return 0;
1143
1144 disk->major = FLOPPY_MAJOR;
1145 disk->first_minor = i;
1146 disk->fops = &floppy_fops;
1147 disk->private_data = &floppy_states[i];
1148 disk->queue = swim3_queue;
1149 disk->flags |= GENHD_FL_REMOVABLE;
1150 sprintf(disk->disk_name, "fd%d", i);
1151 set_capacity(disk, 2880);
1152 add_disk(disk);
1153
1154 return 0;
1155}
1156
1157static struct of_device_id swim3_match[] =
1158{
1159 {
1160 .name = "swim3",
1161 },
1162 {
1163 .compatible = "ohare-swim3"
1164 },
1165 {
1166 .compatible = "swim3"
1167 },
1168};
1169
1170static struct macio_driver swim3_driver =
1171{
1172 .name = "swim3",
1173 .match_table = swim3_match,
1174 .probe = swim3_attach,
1175#if 0
1176 .suspend = swim3_suspend,
1177 .resume = swim3_resume,
1178#endif
1179};
1180
1181
1182int swim3_init(void)
1183{
1184 macio_register_driver(&swim3_driver);
1155 return 0; 1185 return 0;
1156} 1186}
1157 1187
diff --git a/drivers/bluetooth/bcm203x.c b/drivers/bluetooth/bcm203x.c
index 6f67141f4de0..13ba729cdd57 100644
--- a/drivers/bluetooth/bcm203x.c
+++ b/drivers/bluetooth/bcm203x.c
@@ -234,6 +234,7 @@ static int bcm203x_probe(struct usb_interface *intf, const struct usb_device_id
234 data->fw_data = kmalloc(firmware->size, GFP_KERNEL); 234 data->fw_data = kmalloc(firmware->size, GFP_KERNEL);
235 if (!data->fw_data) { 235 if (!data->fw_data) {
236 BT_ERR("Can't allocate memory for firmware image"); 236 BT_ERR("Can't allocate memory for firmware image");
237 release_firmware(firmware);
237 usb_free_urb(data->urb); 238 usb_free_urb(data->urb);
238 kfree(data->buffer); 239 kfree(data->buffer);
239 kfree(data); 240 kfree(data);
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index 2830f58d6f77..8eebf9ca3786 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -739,6 +739,7 @@ static int bluecard_open(bluecard_info_t *info)
739 739
740 hdev->type = HCI_PCCARD; 740 hdev->type = HCI_PCCARD;
741 hdev->driver_data = info; 741 hdev->driver_data = info;
742 SET_HCIDEV_DEV(hdev, &info->p_dev->dev);
742 743
743 hdev->open = bluecard_hci_open; 744 hdev->open = bluecard_hci_open;
744 hdev->close = bluecard_hci_close; 745 hdev->close = bluecard_hci_close;
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index c9dba5565cac..df7bb016df49 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -582,6 +582,7 @@ static int bt3c_open(bt3c_info_t *info)
582 582
583 hdev->type = HCI_PCCARD; 583 hdev->type = HCI_PCCARD;
584 hdev->driver_data = info; 584 hdev->driver_data = info;
585 SET_HCIDEV_DEV(hdev, &info->p_dev->dev);
585 586
586 hdev->open = bt3c_hci_open; 587 hdev->open = bt3c_hci_open;
587 hdev->close = bt3c_hci_close; 588 hdev->close = bt3c_hci_close;
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c
index c889bf8109a1..746ccca97f6f 100644
--- a/drivers/bluetooth/btuart_cs.c
+++ b/drivers/bluetooth/btuart_cs.c
@@ -502,6 +502,7 @@ static int btuart_open(btuart_info_t *info)
502 502
503 hdev->type = HCI_PCCARD; 503 hdev->type = HCI_PCCARD;
504 hdev->driver_data = info; 504 hdev->driver_data = info;
505 SET_HCIDEV_DEV(hdev, &info->p_dev->dev);
505 506
506 hdev->open = btuart_hci_open; 507 hdev->open = btuart_hci_open;
507 hdev->close = btuart_hci_close; 508 hdev->close = btuart_hci_close;
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index be6eed175aa3..0e99def8a1e3 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -484,6 +484,7 @@ static int dtl1_open(dtl1_info_t *info)
484 484
485 hdev->type = HCI_PCCARD; 485 hdev->type = HCI_PCCARD;
486 hdev->driver_data = info; 486 hdev->driver_data = info;
487 SET_HCIDEV_DEV(hdev, &info->p_dev->dev);
487 488
488 hdev->open = dtl1_hci_open; 489 hdev->open = dtl1_hci_open;
489 hdev->close = dtl1_hci_close; 490 hdev->close = dtl1_hci_close;
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 1994270c16e1..93ba25b7ea32 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -191,7 +191,7 @@ static int hci_uart_flush(struct hci_dev *hdev)
191 191
192 /* Flush any pending characters in the driver and discipline. */ 192 /* Flush any pending characters in the driver and discipline. */
193 tty_ldisc_flush(tty); 193 tty_ldisc_flush(tty);
194 if (tty->driver->flush_buffer) 194 if (tty->driver && tty->driver->flush_buffer)
195 tty->driver->flush_buffer(tty); 195 tty->driver->flush_buffer(tty);
196 196
197 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) 197 if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
@@ -290,7 +290,7 @@ static int hci_uart_tty_open(struct tty_struct *tty)
290 if (tty->ldisc.flush_buffer) 290 if (tty->ldisc.flush_buffer)
291 tty->ldisc.flush_buffer(tty); 291 tty->ldisc.flush_buffer(tty);
292 292
293 if (tty->driver->flush_buffer) 293 if (tty->driver && tty->driver->flush_buffer)
294 tty->driver->flush_buffer(tty); 294 tty->driver->flush_buffer(tty);
295 295
296 return 0; 296 return 0;
diff --git a/drivers/bluetooth/hci_usb.c b/drivers/bluetooth/hci_usb.c
index a7d9d7e99e72..e2d4beac7420 100644
--- a/drivers/bluetooth/hci_usb.c
+++ b/drivers/bluetooth/hci_usb.c
@@ -67,6 +67,8 @@ static int ignore = 0;
67static int ignore_dga = 0; 67static int ignore_dga = 0;
68static int ignore_csr = 0; 68static int ignore_csr = 0;
69static int ignore_sniffer = 0; 69static int ignore_sniffer = 0;
70static int disable_scofix = 0;
71static int force_scofix = 0;
70static int reset = 0; 72static int reset = 0;
71 73
72#ifdef CONFIG_BT_HCIUSB_SCO 74#ifdef CONFIG_BT_HCIUSB_SCO
@@ -107,9 +109,12 @@ static struct usb_device_id blacklist_ids[] = {
107 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = HCI_IGNORE }, 109 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = HCI_IGNORE },
108 110
109 /* Broadcom BCM2035 */ 111 /* Broadcom BCM2035 */
110 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = HCI_RESET | HCI_BROKEN_ISOC }, 112 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = HCI_RESET | HCI_WRONG_SCO_MTU },
111 { USB_DEVICE(0x0a5c, 0x2009), .driver_info = HCI_BCM92035 }, 113 { USB_DEVICE(0x0a5c, 0x2009), .driver_info = HCI_BCM92035 },
112 114
115 /* IBM/Lenovo ThinkPad with Broadcom chip */
116 { USB_DEVICE(0x0a5c, 0x201e), .driver_info = HCI_WRONG_SCO_MTU },
117
113 /* Microsoft Wireless Transceiver for Bluetooth 2.0 */ 118 /* Microsoft Wireless Transceiver for Bluetooth 2.0 */
114 { USB_DEVICE(0x045e, 0x009c), .driver_info = HCI_RESET }, 119 { USB_DEVICE(0x045e, 0x009c), .driver_info = HCI_RESET },
115 120
@@ -119,8 +124,13 @@ static struct usb_device_id blacklist_ids[] = {
119 /* ISSC Bluetooth Adapter v3.1 */ 124 /* ISSC Bluetooth Adapter v3.1 */
120 { USB_DEVICE(0x1131, 0x1001), .driver_info = HCI_RESET }, 125 { USB_DEVICE(0x1131, 0x1001), .driver_info = HCI_RESET },
121 126
122 /* RTX Telecom based adapter with buggy SCO support */ 127 /* RTX Telecom based adapters with buggy SCO support */
123 { USB_DEVICE(0x0400, 0x0807), .driver_info = HCI_BROKEN_ISOC }, 128 { USB_DEVICE(0x0400, 0x0807), .driver_info = HCI_BROKEN_ISOC },
129 { USB_DEVICE(0x0400, 0x080a), .driver_info = HCI_BROKEN_ISOC },
130
131 /* Belkin F8T012 and F8T013 devices */
132 { USB_DEVICE(0x050d, 0x0012), .driver_info = HCI_WRONG_SCO_MTU },
133 { USB_DEVICE(0x050d, 0x0013), .driver_info = HCI_WRONG_SCO_MTU },
124 134
125 /* Digianswer devices */ 135 /* Digianswer devices */
126 { USB_DEVICE(0x08fd, 0x0001), .driver_info = HCI_DIGIANSWER }, 136 { USB_DEVICE(0x08fd, 0x0001), .driver_info = HCI_DIGIANSWER },
@@ -129,6 +139,9 @@ static struct usb_device_id blacklist_ids[] = {
129 /* CSR BlueCore Bluetooth Sniffer */ 139 /* CSR BlueCore Bluetooth Sniffer */
130 { USB_DEVICE(0x0a12, 0x0002), .driver_info = HCI_SNIFFER }, 140 { USB_DEVICE(0x0a12, 0x0002), .driver_info = HCI_SNIFFER },
131 141
142 /* Frontline ComProbe Bluetooth Sniffer */
143 { USB_DEVICE(0x16d3, 0x0002), .driver_info = HCI_SNIFFER },
144
132 { } /* Terminating entry */ 145 { } /* Terminating entry */
133}; 146};
134 147
@@ -984,6 +997,11 @@ static int hci_usb_probe(struct usb_interface *intf, const struct usb_device_id
984 if (reset || id->driver_info & HCI_RESET) 997 if (reset || id->driver_info & HCI_RESET)
985 set_bit(HCI_QUIRK_RESET_ON_INIT, &hdev->quirks); 998 set_bit(HCI_QUIRK_RESET_ON_INIT, &hdev->quirks);
986 999
1000 if (force_scofix || id->driver_info & HCI_WRONG_SCO_MTU) {
1001 if (!disable_scofix)
1002 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
1003 }
1004
987 if (id->driver_info & HCI_SNIFFER) { 1005 if (id->driver_info & HCI_SNIFFER) {
988 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997) 1006 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
989 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); 1007 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
@@ -1042,10 +1060,81 @@ static void hci_usb_disconnect(struct usb_interface *intf)
1042 hci_free_dev(hdev); 1060 hci_free_dev(hdev);
1043} 1061}
1044 1062
1063static int hci_usb_suspend(struct usb_interface *intf, pm_message_t message)
1064{
1065 struct hci_usb *husb = usb_get_intfdata(intf);
1066 struct list_head killed;
1067 unsigned long flags;
1068 int i;
1069
1070 if (!husb || intf == husb->isoc_iface)
1071 return 0;
1072
1073 hci_suspend_dev(husb->hdev);
1074
1075 INIT_LIST_HEAD(&killed);
1076
1077 for (i = 0; i < 4; i++) {
1078 struct _urb_queue *q = &husb->pending_q[i];
1079 struct _urb *_urb, *_tmp;
1080
1081 while ((_urb = _urb_dequeue(q))) {
1082 /* reset queue since _urb_dequeue sets it to NULL */
1083 _urb->queue = q;
1084 usb_kill_urb(&_urb->urb);
1085 list_add(&_urb->list, &killed);
1086 }
1087
1088 spin_lock_irqsave(&q->lock, flags);
1089
1090 list_for_each_entry_safe(_urb, _tmp, &killed, list) {
1091 list_move_tail(&_urb->list, &q->head);
1092 }
1093
1094 spin_unlock_irqrestore(&q->lock, flags);
1095 }
1096
1097 return 0;
1098}
1099
1100static int hci_usb_resume(struct usb_interface *intf)
1101{
1102 struct hci_usb *husb = usb_get_intfdata(intf);
1103 unsigned long flags;
1104 int i, err = 0;
1105
1106 if (!husb || intf == husb->isoc_iface)
1107 return 0;
1108
1109 for (i = 0; i < 4; i++) {
1110 struct _urb_queue *q = &husb->pending_q[i];
1111 struct _urb *_urb;
1112
1113 spin_lock_irqsave(&q->lock, flags);
1114
1115 list_for_each_entry(_urb, &q->head, list) {
1116 err = usb_submit_urb(&_urb->urb, GFP_ATOMIC);
1117 if (err)
1118 break;
1119 }
1120
1121 spin_unlock_irqrestore(&q->lock, flags);
1122
1123 if (err)
1124 return -EIO;
1125 }
1126
1127 hci_resume_dev(husb->hdev);
1128
1129 return 0;
1130}
1131
1045static struct usb_driver hci_usb_driver = { 1132static struct usb_driver hci_usb_driver = {
1046 .name = "hci_usb", 1133 .name = "hci_usb",
1047 .probe = hci_usb_probe, 1134 .probe = hci_usb_probe,
1048 .disconnect = hci_usb_disconnect, 1135 .disconnect = hci_usb_disconnect,
1136 .suspend = hci_usb_suspend,
1137 .resume = hci_usb_resume,
1049 .id_table = bluetooth_ids, 1138 .id_table = bluetooth_ids,
1050}; 1139};
1051 1140
@@ -1081,6 +1170,12 @@ MODULE_PARM_DESC(ignore_csr, "Ignore devices with id 0a12:0001");
1081module_param(ignore_sniffer, bool, 0644); 1170module_param(ignore_sniffer, bool, 0644);
1082MODULE_PARM_DESC(ignore_sniffer, "Ignore devices with id 0a12:0002"); 1171MODULE_PARM_DESC(ignore_sniffer, "Ignore devices with id 0a12:0002");
1083 1172
1173module_param(disable_scofix, bool, 0644);
1174MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
1175
1176module_param(force_scofix, bool, 0644);
1177MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
1178
1084module_param(reset, bool, 0644); 1179module_param(reset, bool, 0644);
1085MODULE_PARM_DESC(reset, "Send HCI reset command on initialization"); 1180MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
1086 1181
diff --git a/drivers/bluetooth/hci_usb.h b/drivers/bluetooth/hci_usb.h
index 37100a6ea1a8..963fc55cdc85 100644
--- a/drivers/bluetooth/hci_usb.h
+++ b/drivers/bluetooth/hci_usb.h
@@ -35,6 +35,7 @@
35#define HCI_SNIFFER 0x10 35#define HCI_SNIFFER 0x10
36#define HCI_BCM92035 0x20 36#define HCI_BCM92035 0x20
37#define HCI_BROKEN_ISOC 0x40 37#define HCI_BROKEN_ISOC 0x40
38#define HCI_WRONG_SCO_MTU 0x80
38 39
39#define HCI_MAX_IFACE_NUM 3 40#define HCI_MAX_IFACE_NUM 3
40 41
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index ea589007fa26..aac67a3a6019 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -277,7 +277,6 @@ static int vhci_open(struct inode *inode, struct file *file)
277 277
278 hdev->type = HCI_VHCI; 278 hdev->type = HCI_VHCI;
279 hdev->driver_data = vhci; 279 hdev->driver_data = vhci;
280 SET_HCIDEV_DEV(hdev, vhci_miscdev.dev);
281 280
282 hdev->open = vhci_open_dev; 281 hdev->open = vhci_open_dev;
283 hdev->close = vhci_close_dev; 282 hdev->close = vhci_close_dev;
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index ca27ee89240b..d239cf8b20bd 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -1837,7 +1837,7 @@ static int dvd_read_bca(struct cdrom_device_info *cdi, dvd_struct *s)
1837 init_cdrom_command(&cgc, buf, sizeof(buf), CGC_DATA_READ); 1837 init_cdrom_command(&cgc, buf, sizeof(buf), CGC_DATA_READ);
1838 cgc.cmd[0] = GPCMD_READ_DVD_STRUCTURE; 1838 cgc.cmd[0] = GPCMD_READ_DVD_STRUCTURE;
1839 cgc.cmd[7] = s->type; 1839 cgc.cmd[7] = s->type;
1840 cgc.cmd[9] = cgc.buflen = 0xff; 1840 cgc.cmd[9] = cgc.buflen & 0xff;
1841 1841
1842 if ((ret = cdo->generic_packet(cdi, &cgc))) 1842 if ((ret = cdo->generic_packet(cdi, &cgc)))
1843 return ret; 1843 return ret;
diff --git a/drivers/cdrom/gscd.c b/drivers/cdrom/gscd.c
index b6ee50a2916d..fa7082489765 100644
--- a/drivers/cdrom/gscd.c
+++ b/drivers/cdrom/gscd.c
@@ -266,7 +266,7 @@ repeat:
266 goto out; 266 goto out;
267 267
268 if (req->cmd != READ) { 268 if (req->cmd != READ) {
269 printk("GSCD: bad cmd %lu\n", rq_data_dir(req)); 269 printk("GSCD: bad cmd %u\n", rq_data_dir(req));
270 end_request(req, 0); 270 end_request(req, 0);
271 goto repeat; 271 goto repeat;
272 } 272 }
diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
index ffcf15c30e90..d9c5a9142ad1 100644
--- a/drivers/char/agp/frontend.c
+++ b/drivers/char/agp/frontend.c
@@ -1059,7 +1059,7 @@ ioctl_out:
1059 return ret_val; 1059 return ret_val;
1060} 1060}
1061 1061
1062static struct file_operations agp_fops = 1062static const struct file_operations agp_fops =
1063{ 1063{
1064 .owner = THIS_MODULE, 1064 .owner = THIS_MODULE,
1065 .llseek = no_llseek, 1065 .llseek = no_llseek,
diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
index bcc4668835b5..10a389dafd60 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -112,7 +112,7 @@ static int ac_ioctl(struct inode *, struct file *, unsigned int,
112 unsigned long); 112 unsigned long);
113static irqreturn_t ac_interrupt(int, void *, struct pt_regs *); 113static irqreturn_t ac_interrupt(int, void *, struct pt_regs *);
114 114
115static struct file_operations ac_fops = { 115static const struct file_operations ac_fops = {
116 .owner = THIS_MODULE, 116 .owner = THIS_MODULE,
117 .llseek = no_llseek, 117 .llseek = no_llseek,
118 .read = ac_read, 118 .read = ac_read,
diff --git a/drivers/char/cs5535_gpio.c b/drivers/char/cs5535_gpio.c
index 46d66037b917..8ce3f34cfc22 100644
--- a/drivers/char/cs5535_gpio.c
+++ b/drivers/char/cs5535_gpio.c
@@ -158,7 +158,7 @@ static int cs5535_gpio_open(struct inode *inode, struct file *file)
158 return nonseekable_open(inode, file); 158 return nonseekable_open(inode, file);
159} 159}
160 160
161static struct file_operations cs5535_gpio_fops = { 161static const struct file_operations cs5535_gpio_fops = {
162 .owner = THIS_MODULE, 162 .owner = THIS_MODULE,
163 .write = cs5535_gpio_write, 163 .write = cs5535_gpio_write,
164 .read = cs5535_gpio_read, 164 .read = cs5535_gpio_read,
diff --git a/drivers/char/drm/radeon_state.c b/drivers/char/drm/radeon_state.c
index 5bb2234a9094..39a7f685e3fd 100644
--- a/drivers/char/drm/radeon_state.c
+++ b/drivers/char/drm/radeon_state.c
@@ -175,6 +175,14 @@ static __inline__ int radeon_check_and_fixup_packets(drm_radeon_private_t *
175 } 175 }
176 break; 176 break;
177 177
178 case R200_EMIT_VAP_CTL:{
179 RING_LOCALS;
180 BEGIN_RING(2);
181 OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH, 0);
182 ADVANCE_RING();
183 }
184 break;
185
178 case RADEON_EMIT_RB3D_COLORPITCH: 186 case RADEON_EMIT_RB3D_COLORPITCH:
179 case RADEON_EMIT_RE_LINE_PATTERN: 187 case RADEON_EMIT_RE_LINE_PATTERN:
180 case RADEON_EMIT_SE_LINE_WIDTH: 188 case RADEON_EMIT_SE_LINE_WIDTH:
@@ -202,7 +210,6 @@ static __inline__ int radeon_check_and_fixup_packets(drm_radeon_private_t *
202 case R200_EMIT_TCL_LIGHT_MODEL_CTL_0: 210 case R200_EMIT_TCL_LIGHT_MODEL_CTL_0:
203 case R200_EMIT_TFACTOR_0: 211 case R200_EMIT_TFACTOR_0:
204 case R200_EMIT_VTX_FMT_0: 212 case R200_EMIT_VTX_FMT_0:
205 case R200_EMIT_VAP_CTL:
206 case R200_EMIT_MATRIX_SELECT_0: 213 case R200_EMIT_MATRIX_SELECT_0:
207 case R200_EMIT_TEX_PROC_CTL_2: 214 case R200_EMIT_TEX_PROC_CTL_2:
208 case R200_EMIT_TCL_UCP_VERT_BLEND_CTL: 215 case R200_EMIT_TCL_UCP_VERT_BLEND_CTL:
diff --git a/drivers/char/ds1286.c b/drivers/char/ds1286.c
index d755cac14bc1..21c8229f5443 100644
--- a/drivers/char/ds1286.c
+++ b/drivers/char/ds1286.c
@@ -281,7 +281,7 @@ static unsigned int ds1286_poll(struct file *file, poll_table *wait)
281 * The various file operations we support. 281 * The various file operations we support.
282 */ 282 */
283 283
284static struct file_operations ds1286_fops = { 284static const struct file_operations ds1286_fops = {
285 .llseek = no_llseek, 285 .llseek = no_llseek,
286 .read = ds1286_read, 286 .read = ds1286_read,
287 .poll = ds1286_poll, 287 .poll = ds1286_poll,
diff --git a/drivers/char/ds1302.c b/drivers/char/ds1302.c
index 625e8b517005..bcdb107aa967 100644
--- a/drivers/char/ds1302.c
+++ b/drivers/char/ds1302.c
@@ -282,7 +282,7 @@ get_rtc_status(char *buf)
282 282
283/* The various file operations we support. */ 283/* The various file operations we support. */
284 284
285static struct file_operations rtc_fops = { 285static const struct file_operations rtc_fops = {
286 .owner = THIS_MODULE, 286 .owner = THIS_MODULE,
287 .ioctl = rtc_ioctl, 287 .ioctl = rtc_ioctl,
288}; 288};
diff --git a/drivers/char/ds1620.c b/drivers/char/ds1620.c
index 953e670dcd09..48cb8f0e8ebf 100644
--- a/drivers/char/ds1620.c
+++ b/drivers/char/ds1620.c
@@ -336,7 +336,7 @@ proc_therm_ds1620_read(char *buf, char **start, off_t offset,
336static struct proc_dir_entry *proc_therm_ds1620; 336static struct proc_dir_entry *proc_therm_ds1620;
337#endif 337#endif
338 338
339static struct file_operations ds1620_fops = { 339static const struct file_operations ds1620_fops = {
340 .owner = THIS_MODULE, 340 .owner = THIS_MODULE,
341 .open = nonseekable_open, 341 .open = nonseekable_open,
342 .read = ds1620_read, 342 .read = ds1620_read,
diff --git a/drivers/char/dsp56k.c b/drivers/char/dsp56k.c
index 09b413618b57..9b1bf60ffbe7 100644
--- a/drivers/char/dsp56k.c
+++ b/drivers/char/dsp56k.c
@@ -483,7 +483,7 @@ static int dsp56k_release(struct inode *inode, struct file *file)
483 return 0; 483 return 0;
484} 484}
485 485
486static struct file_operations dsp56k_fops = { 486static const struct file_operations dsp56k_fops = {
487 .owner = THIS_MODULE, 487 .owner = THIS_MODULE,
488 .read = dsp56k_read, 488 .read = dsp56k_read,
489 .write = dsp56k_write, 489 .write = dsp56k_write,
diff --git a/drivers/char/dtlk.c b/drivers/char/dtlk.c
index da2c89f1b8bc..5e82c3bad2e3 100644
--- a/drivers/char/dtlk.c
+++ b/drivers/char/dtlk.c
@@ -94,7 +94,7 @@ static int dtlk_release(struct inode *, struct file *);
94static int dtlk_ioctl(struct inode *inode, struct file *file, 94static int dtlk_ioctl(struct inode *inode, struct file *file,
95 unsigned int cmd, unsigned long arg); 95 unsigned int cmd, unsigned long arg);
96 96
97static struct file_operations dtlk_fops = 97static const struct file_operations dtlk_fops =
98{ 98{
99 .owner = THIS_MODULE, 99 .owner = THIS_MODULE,
100 .read = dtlk_read, 100 .read = dtlk_read,
diff --git a/drivers/char/efirtc.c b/drivers/char/efirtc.c
index 0090e7a4fcd3..004141d535a2 100644
--- a/drivers/char/efirtc.c
+++ b/drivers/char/efirtc.c
@@ -285,7 +285,7 @@ efi_rtc_close(struct inode *inode, struct file *file)
285 * The various file operations we support. 285 * The various file operations we support.
286 */ 286 */
287 287
288static struct file_operations efi_rtc_fops = { 288static const struct file_operations efi_rtc_fops = {
289 .owner = THIS_MODULE, 289 .owner = THIS_MODULE,
290 .ioctl = efi_rtc_ioctl, 290 .ioctl = efi_rtc_ioctl,
291 .open = efi_rtc_open, 291 .open = efi_rtc_open,
diff --git a/drivers/char/ftape/zftape/zftape-init.c b/drivers/char/ftape/zftape/zftape-init.c
index 55272566b740..164a1aa77a2f 100644
--- a/drivers/char/ftape/zftape/zftape-init.c
+++ b/drivers/char/ftape/zftape/zftape-init.c
@@ -86,7 +86,7 @@ static ssize_t zft_read (struct file *fp, char __user *buff,
86static ssize_t zft_write(struct file *fp, const char __user *buff, 86static ssize_t zft_write(struct file *fp, const char __user *buff,
87 size_t req_len, loff_t *ppos); 87 size_t req_len, loff_t *ppos);
88 88
89static struct file_operations zft_cdev = 89static const struct file_operations zft_cdev =
90{ 90{
91 .owner = THIS_MODULE, 91 .owner = THIS_MODULE,
92 .read = zft_read, 92 .read = zft_read,
diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
index bebd7e34f792..817dc409ac20 100644
--- a/drivers/char/genrtc.c
+++ b/drivers/char/genrtc.c
@@ -482,7 +482,7 @@ static inline int gen_rtc_proc_init(void) { return 0; }
482 * The various file operations we support. 482 * The various file operations we support.
483 */ 483 */
484 484
485static struct file_operations gen_rtc_fops = { 485static const struct file_operations gen_rtc_fops = {
486 .owner = THIS_MODULE, 486 .owner = THIS_MODULE,
487#ifdef CONFIG_GEN_RTC_X 487#ifdef CONFIG_GEN_RTC_X
488 .read = gen_rtc_read, 488 .read = gen_rtc_read,
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index e5643f3aa73f..8afba339f05a 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -553,7 +553,7 @@ hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
553 return err; 553 return err;
554} 554}
555 555
556static struct file_operations hpet_fops = { 556static const struct file_operations hpet_fops = {
557 .owner = THIS_MODULE, 557 .owner = THIS_MODULE,
558 .llseek = no_llseek, 558 .llseek = no_llseek,
559 .read = hpet_read, 559 .read = hpet_read,
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index ca2f538e549e..613d67f1c7f0 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -668,6 +668,7 @@ int khvcd(void *unused)
668 do { 668 do {
669 poll_mask = 0; 669 poll_mask = 0;
670 hvc_kicked = 0; 670 hvc_kicked = 0;
671 try_to_freeze();
671 wmb(); 672 wmb();
672 if (cpus_empty(cpus_in_xmon)) { 673 if (cpus_empty(cpus_in_xmon)) {
673 spin_lock(&hvc_structs_lock); 674 spin_lock(&hvc_structs_lock);
diff --git a/drivers/char/hvsi.c b/drivers/char/hvsi.c
index 8dc205b275e3..017f755632a3 100644
--- a/drivers/char/hvsi.c
+++ b/drivers/char/hvsi.c
@@ -311,7 +311,8 @@ static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,
311 /* CD went away; no more connection */ 311 /* CD went away; no more connection */
312 pr_debug("hvsi%i: CD dropped\n", hp->index); 312 pr_debug("hvsi%i: CD dropped\n", hp->index);
313 hp->mctrl &= TIOCM_CD; 313 hp->mctrl &= TIOCM_CD;
314 if (!(hp->tty->flags & CLOCAL)) 314 /* If userland hasn't done an open(2) yet, hp->tty is NULL. */
315 if (hp->tty && !(hp->tty->flags & CLOCAL))
315 *to_hangup = hp->tty; 316 *to_hangup = hp->tty;
316 } 317 }
317 break; 318 break;
@@ -986,10 +987,7 @@ static void hvsi_write_worker(void *arg)
986 start_j = 0; 987 start_j = 0;
987#endif /* DEBUG */ 988#endif /* DEBUG */
988 wake_up_all(&hp->emptyq); 989 wake_up_all(&hp->emptyq);
989 if (test_bit(TTY_DO_WRITE_WAKEUP, &hp->tty->flags) 990 tty_wakeup(hp->tty);
990 && hp->tty->ldisc.write_wakeup)
991 hp->tty->ldisc.write_wakeup(hp->tty);
992 wake_up_interruptible(&hp->tty->write_wait);
993 } 991 }
994 992
995out: 993out:
@@ -1299,13 +1297,12 @@ static int __init hvsi_console_init(void)
1299 hp->inbuf_end = hp->inbuf; 1297 hp->inbuf_end = hp->inbuf;
1300 hp->state = HVSI_CLOSED; 1298 hp->state = HVSI_CLOSED;
1301 hp->vtermno = *vtermno; 1299 hp->vtermno = *vtermno;
1302 hp->virq = virt_irq_create_mapping(irq[0]); 1300 hp->virq = irq_create_mapping(NULL, irq[0]);
1303 if (hp->virq == NO_IRQ) { 1301 if (hp->virq == NO_IRQ) {
1304 printk(KERN_ERR "%s: couldn't create irq mapping for 0x%x\n", 1302 printk(KERN_ERR "%s: couldn't create irq mapping for 0x%x\n",
1305 __FUNCTION__, hp->virq); 1303 __FUNCTION__, irq[0]);
1306 continue; 1304 continue;
1307 } else 1305 }
1308 hp->virq = irq_offset_up(hp->virq);
1309 1306
1310 hvsi_count++; 1307 hvsi_count++;
1311 } 1308 }
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 88b026639f10..154a81d328c1 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -149,7 +149,7 @@ out:
149} 149}
150 150
151 151
152static struct file_operations rng_chrdev_ops = { 152static const struct file_operations rng_chrdev_ops = {
153 .owner = THIS_MODULE, 153 .owner = THIS_MODULE,
154 .open = rng_dev_open, 154 .open = rng_dev_open,
155 .read = rng_dev_read, 155 .read = rng_dev_read,
diff --git a/drivers/char/hw_random/geode-rng.c b/drivers/char/hw_random/geode-rng.c
index be61f22ee7bb..d37ced0d132b 100644
--- a/drivers/char/hw_random/geode-rng.c
+++ b/drivers/char/hw_random/geode-rng.c
@@ -107,10 +107,14 @@ found:
107 if (err) { 107 if (err) {
108 printk(KERN_ERR PFX "RNG registering failed (%d)\n", 108 printk(KERN_ERR PFX "RNG registering failed (%d)\n",
109 err); 109 err);
110 goto out; 110 goto err_unmap;
111 } 111 }
112out: 112out:
113 return err; 113 return err;
114
115err_unmap:
116 iounmap(mem);
117 goto out;
114} 118}
115 119
116static void __exit mod_exit(void) 120static void __exit mod_exit(void)
diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
index 6594bd5645f4..ccd7e7102234 100644
--- a/drivers/char/hw_random/intel-rng.c
+++ b/drivers/char/hw_random/intel-rng.c
@@ -164,7 +164,7 @@ static int __init mod_init(void)
164 if (err) { 164 if (err) {
165 printk(KERN_ERR PFX "RNG registering failed (%d)\n", 165 printk(KERN_ERR PFX "RNG registering failed (%d)\n",
166 err); 166 err);
167 goto out; 167 goto err_unmap;
168 } 168 }
169out: 169out:
170 return err; 170 return err;
diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
index 819516b35a79..a01d796d1eeb 100644
--- a/drivers/char/hw_random/omap-rng.c
+++ b/drivers/char/hw_random/omap-rng.c
@@ -25,12 +25,12 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/random.h> 27#include <linux/random.h>
28#include <linux/clk.h>
28#include <linux/err.h> 29#include <linux/err.h>
29#include <linux/device.h> 30#include <linux/platform_device.h>
30#include <linux/hw_random.h> 31#include <linux/hw_random.h>
31 32
32#include <asm/io.h> 33#include <asm/io.h>
33#include <asm/hardware/clock.h>
34 34
35#define RNG_OUT_REG 0x00 /* Output register */ 35#define RNG_OUT_REG 0x00 /* Output register */
36#define RNG_STAT_REG 0x04 /* Status register 36#define RNG_STAT_REG 0x04 /* Status register
@@ -52,7 +52,7 @@
52 52
53static void __iomem *rng_base; 53static void __iomem *rng_base;
54static struct clk *rng_ick; 54static struct clk *rng_ick;
55static struct device *rng_dev; 55static struct platform_device *rng_dev;
56 56
57static u32 omap_rng_read_reg(int reg) 57static u32 omap_rng_read_reg(int reg)
58{ 58{
@@ -83,9 +83,8 @@ static struct hwrng omap_rng_ops = {
83 .data_read = omap_rng_data_read, 83 .data_read = omap_rng_data_read,
84}; 84};
85 85
86static int __init omap_rng_probe(struct device *dev) 86static int __init omap_rng_probe(struct platform_device *pdev)
87{ 87{
88 struct platform_device *pdev = to_platform_device(dev);
89 struct resource *res, *mem; 88 struct resource *res, *mem;
90 int ret; 89 int ret;
91 90
@@ -95,16 +94,14 @@ static int __init omap_rng_probe(struct device *dev)
95 */ 94 */
96 BUG_ON(rng_dev); 95 BUG_ON(rng_dev);
97 96
98 if (cpu_is_omap24xx()) { 97 if (cpu_is_omap24xx()) {
99 rng_ick = clk_get(NULL, "rng_ick"); 98 rng_ick = clk_get(NULL, "rng_ick");
100 if (IS_ERR(rng_ick)) { 99 if (IS_ERR(rng_ick)) {
101 dev_err(dev, "Could not get rng_ick\n"); 100 dev_err(&pdev->dev, "Could not get rng_ick\n");
102 ret = PTR_ERR(rng_ick); 101 ret = PTR_ERR(rng_ick);
103 return ret; 102 return ret;
104 } 103 } else
105 else { 104 clk_enable(rng_ick);
106 clk_use(rng_ick);
107 }
108 } 105 }
109 106
110 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 107 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -117,7 +114,7 @@ static int __init omap_rng_probe(struct device *dev)
117 if (mem == NULL) 114 if (mem == NULL)
118 return -EBUSY; 115 return -EBUSY;
119 116
120 dev_set_drvdata(dev, mem); 117 dev_set_drvdata(&pdev->dev, mem);
121 rng_base = (u32 __iomem *)io_p2v(res->start); 118 rng_base = (u32 __iomem *)io_p2v(res->start);
122 119
123 ret = hwrng_register(&omap_rng_ops); 120 ret = hwrng_register(&omap_rng_ops);
@@ -127,25 +124,25 @@ static int __init omap_rng_probe(struct device *dev)
127 return ret; 124 return ret;
128 } 125 }
129 126
130 dev_info(dev, "OMAP Random Number Generator ver. %02x\n", 127 dev_info(&pdev->dev, "OMAP Random Number Generator ver. %02x\n",
131 omap_rng_read_reg(RNG_REV_REG)); 128 omap_rng_read_reg(RNG_REV_REG));
132 omap_rng_write_reg(RNG_MASK_REG, 0x1); 129 omap_rng_write_reg(RNG_MASK_REG, 0x1);
133 130
134 rng_dev = dev; 131 rng_dev = pdev;
135 132
136 return 0; 133 return 0;
137} 134}
138 135
139static int __exit omap_rng_remove(struct device *dev) 136static int __exit omap_rng_remove(struct platform_device *pdev)
140{ 137{
141 struct resource *mem = dev_get_drvdata(dev); 138 struct resource *mem = dev_get_drvdata(&pdev->dev);
142 139
143 hwrng_unregister(&omap_rng_ops); 140 hwrng_unregister(&omap_rng_ops);
144 141
145 omap_rng_write_reg(RNG_MASK_REG, 0x0); 142 omap_rng_write_reg(RNG_MASK_REG, 0x0);
146 143
147 if (cpu_is_omap24xx()) { 144 if (cpu_is_omap24xx()) {
148 clk_unuse(rng_ick); 145 clk_disable(rng_ick);
149 clk_put(rng_ick); 146 clk_put(rng_ick);
150 } 147 }
151 148
@@ -157,18 +154,16 @@ static int __exit omap_rng_remove(struct device *dev)
157 154
158#ifdef CONFIG_PM 155#ifdef CONFIG_PM
159 156
160static int omap_rng_suspend(struct device *dev, pm_message_t message, u32 level) 157static int omap_rng_suspend(struct platform_device *pdev, pm_message_t message)
161{ 158{
162 omap_rng_write_reg(RNG_MASK_REG, 0x0); 159 omap_rng_write_reg(RNG_MASK_REG, 0x0);
163
164 return 0; 160 return 0;
165} 161}
166 162
167static int omap_rng_resume(struct device *dev, pm_message_t message, u32 level) 163static int omap_rng_resume(struct platform_device *pdev)
168{ 164{
169 omap_rng_write_reg(RNG_MASK_REG, 0x1); 165 omap_rng_write_reg(RNG_MASK_REG, 0x1);
170 166 return 0;
171 return 1;
172} 167}
173 168
174#else 169#else
@@ -179,9 +174,11 @@ static int omap_rng_resume(struct device *dev, pm_message_t message, u32 level)
179#endif 174#endif
180 175
181 176
182static struct device_driver omap_rng_driver = { 177static struct platform_driver omap_rng_driver = {
183 .name = "omap_rng", 178 .driver = {
184 .bus = &platform_bus_type, 179 .name = "omap_rng",
180 .owner = THIS_MODULE,
181 },
185 .probe = omap_rng_probe, 182 .probe = omap_rng_probe,
186 .remove = __exit_p(omap_rng_remove), 183 .remove = __exit_p(omap_rng_remove),
187 .suspend = omap_rng_suspend, 184 .suspend = omap_rng_suspend,
@@ -193,12 +190,12 @@ static int __init omap_rng_init(void)
193 if (!cpu_is_omap16xx() && !cpu_is_omap24xx()) 190 if (!cpu_is_omap16xx() && !cpu_is_omap24xx())
194 return -ENODEV; 191 return -ENODEV;
195 192
196 return driver_register(&omap_rng_driver); 193 return platform_driver_register(&omap_rng_driver);
197} 194}
198 195
199static void __exit omap_rng_exit(void) 196static void __exit omap_rng_exit(void)
200{ 197{
201 driver_unregister(&omap_rng_driver); 198 platform_driver_unregister(&omap_rng_driver);
202} 199}
203 200
204module_init(omap_rng_init); 201module_init(omap_rng_init);
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index f3c3aaf4560e..353d9f3cf8d7 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -80,7 +80,7 @@ static int i8k_open_fs(struct inode *inode, struct file *file);
80static int i8k_ioctl(struct inode *, struct file *, unsigned int, 80static int i8k_ioctl(struct inode *, struct file *, unsigned int,
81 unsigned long); 81 unsigned long);
82 82
83static struct file_operations i8k_fops = { 83static const struct file_operations i8k_fops = {
84 .open = i8k_open_fs, 84 .open = i8k_open_fs,
85 .read = seq_read, 85 .read = seq_read,
86 .llseek = seq_lseek, 86 .llseek = seq_lseek,
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index a4200a2b0811..7907ae88c2f4 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -233,7 +233,7 @@ static void *DevTableMem[IP2_MAX_BOARDS];
233/* This is the driver descriptor for the ip2ipl device, which is used to 233/* This is the driver descriptor for the ip2ipl device, which is used to
234 * download the loadware to the boards. 234 * download the loadware to the boards.
235 */ 235 */
236static struct file_operations ip2_ipl = { 236static const struct file_operations ip2_ipl = {
237 .owner = THIS_MODULE, 237 .owner = THIS_MODULE,
238 .read = ip2_ipl_read, 238 .read = ip2_ipl_read,
239 .write = ip2_ipl_write, 239 .write = ip2_ipl_write,
@@ -3186,3 +3186,10 @@ ip2trace (unsigned short pn, unsigned char cat, unsigned char label, unsigned lo
3186 3186
3187 3187
3188MODULE_LICENSE("GPL"); 3188MODULE_LICENSE("GPL");
3189
3190static struct pci_device_id ip2main_pci_tbl[] __devinitdata = {
3191 { PCI_DEVICE(PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_IP2EX) },
3192 { }
3193};
3194
3195MODULE_DEVICE_TABLE(pci, ip2main_pci_tbl);
diff --git a/drivers/char/ip27-rtc.c b/drivers/char/ip27-rtc.c
index 3acdac3c967e..a48da02aad2f 100644
--- a/drivers/char/ip27-rtc.c
+++ b/drivers/char/ip27-rtc.c
@@ -196,7 +196,7 @@ static int rtc_release(struct inode *inode, struct file *file)
196 * The various file operations we support. 196 * The various file operations we support.
197 */ 197 */
198 198
199static struct file_operations rtc_fops = { 199static const struct file_operations rtc_fops = {
200 .owner = THIS_MODULE, 200 .owner = THIS_MODULE,
201 .ioctl = rtc_ioctl, 201 .ioctl = rtc_ioctl,
202 .open = rtc_open, 202 .open = rtc_open,
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index 2fc894fef1cb..68d7c61a864e 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -765,7 +765,7 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
765} 765}
766#endif 766#endif
767 767
768static struct file_operations ipmi_fops = { 768static const struct file_operations ipmi_fops = {
769 .owner = THIS_MODULE, 769 .owner = THIS_MODULE,
770 .ioctl = ipmi_ioctl, 770 .ioctl = ipmi_ioctl,
771#ifdef CONFIG_COMPAT 771#ifdef CONFIG_COMPAT
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 0aa5d608fe6f..843d34c8627c 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -3428,6 +3428,7 @@ struct ipmi_recv_msg *ipmi_alloc_recv_msg(void)
3428 3428
3429 rv = kmalloc(sizeof(struct ipmi_recv_msg), GFP_ATOMIC); 3429 rv = kmalloc(sizeof(struct ipmi_recv_msg), GFP_ATOMIC);
3430 if (rv) { 3430 if (rv) {
3431 rv->user = NULL;
3431 rv->done = free_recv_msg; 3432 rv->done = free_recv_msg;
3432 atomic_inc(&recv_msg_inuse_count); 3433 atomic_inc(&recv_msg_inuse_count);
3433 } 3434 }
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index f57eba0bf253..abca98beac14 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -402,10 +402,10 @@ static void handle_flags(struct smi_info *smi_info)
402 smi_info->curr_msg->data, 402 smi_info->curr_msg->data,
403 smi_info->curr_msg->data_size); 403 smi_info->curr_msg->data_size);
404 smi_info->si_state = SI_GETTING_EVENTS; 404 smi_info->si_state = SI_GETTING_EVENTS;
405 } else if (smi_info->msg_flags & OEM_DATA_AVAIL) { 405 } else if (smi_info->msg_flags & OEM_DATA_AVAIL &&
406 if (smi_info->oem_data_avail_handler) 406 smi_info->oem_data_avail_handler) {
407 if (smi_info->oem_data_avail_handler(smi_info)) 407 if (smi_info->oem_data_avail_handler(smi_info))
408 goto retry; 408 goto retry;
409 } else { 409 } else {
410 smi_info->si_state = SI_NORMAL; 410 smi_info->si_state = SI_NORMAL;
411 } 411 }
@@ -2481,6 +2481,7 @@ static __devinit int init_ipmi_si(void)
2481#ifdef CONFIG_PCI 2481#ifdef CONFIG_PCI
2482 pci_unregister_driver(&ipmi_pci_driver); 2482 pci_unregister_driver(&ipmi_pci_driver);
2483#endif 2483#endif
2484 driver_unregister(&ipmi_driver);
2484 printk("ipmi_si: Unable to find any System Interface(s)\n"); 2485 printk("ipmi_si: Unable to find any System Interface(s)\n");
2485 return -ENODEV; 2486 return -ENODEV;
2486 } else { 2487 } else {
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 74a889c58333..accaaf1a6b69 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -807,7 +807,7 @@ static int ipmi_close(struct inode *ino, struct file *filep)
807 return 0; 807 return 0;
808} 808}
809 809
810static struct file_operations ipmi_wdog_fops = { 810static const struct file_operations ipmi_wdog_fops = {
811 .owner = THIS_MODULE, 811 .owner = THIS_MODULE,
812 .read = ipmi_read, 812 .read = ipmi_read,
813 .poll = ipmi_poll, 813 .poll = ipmi_poll,
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index fbce2f0669d6..84dfc4278139 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -748,7 +748,7 @@ static int stli_initpcibrd(int brdtype, struct pci_dev *devp);
748 * will give access to the shared memory on the Stallion intelligent 748 * will give access to the shared memory on the Stallion intelligent
749 * board. This is also a very useful debugging tool. 749 * board. This is also a very useful debugging tool.
750 */ 750 */
751static struct file_operations stli_fsiomem = { 751static const struct file_operations stli_fsiomem = {
752 .owner = THIS_MODULE, 752 .owner = THIS_MODULE,
753 .read = stli_memread, 753 .read = stli_memread,
754 .write = stli_memwrite, 754 .write = stli_memwrite,
diff --git a/drivers/char/ite_gpio.c b/drivers/char/ite_gpio.c
index 747ba45e50e5..cde562d70c4f 100644
--- a/drivers/char/ite_gpio.c
+++ b/drivers/char/ite_gpio.c
@@ -357,7 +357,7 @@ DEB(printk("interrupt 0x%x %d\n",ITE_GPAISR, i));
357 } 357 }
358} 358}
359 359
360static struct file_operations ite_gpio_fops = { 360static const struct file_operations ite_gpio_fops = {
361 .owner = THIS_MODULE, 361 .owner = THIS_MODULE,
362 .ioctl = ite_gpio_ioctl, 362 .ioctl = ite_gpio_ioctl,
363 .open = ite_gpio_open, 363 .open = ite_gpio_open,
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 056ebe84b81d..3e90aac37510 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -107,7 +107,6 @@ const int NR_TYPES = ARRAY_SIZE(max_vals);
107 107
108struct kbd_struct kbd_table[MAX_NR_CONSOLES]; 108struct kbd_struct kbd_table[MAX_NR_CONSOLES];
109static struct kbd_struct *kbd = kbd_table; 109static struct kbd_struct *kbd = kbd_table;
110static struct kbd_struct kbd0;
111 110
112int spawnpid, spawnsig; 111int spawnpid, spawnsig;
113 112
@@ -223,13 +222,13 @@ static void kd_nosound(unsigned long ignored)
223{ 222{
224 struct list_head *node; 223 struct list_head *node;
225 224
226 list_for_each(node,&kbd_handler.h_list) { 225 list_for_each(node, &kbd_handler.h_list) {
227 struct input_handle *handle = to_handle_h(node); 226 struct input_handle *handle = to_handle_h(node);
228 if (test_bit(EV_SND, handle->dev->evbit)) { 227 if (test_bit(EV_SND, handle->dev->evbit)) {
229 if (test_bit(SND_TONE, handle->dev->sndbit)) 228 if (test_bit(SND_TONE, handle->dev->sndbit))
230 input_event(handle->dev, EV_SND, SND_TONE, 0); 229 input_inject_event(handle, EV_SND, SND_TONE, 0);
231 if (test_bit(SND_BELL, handle->dev->sndbit)) 230 if (test_bit(SND_BELL, handle->dev->sndbit))
232 input_event(handle->dev, EV_SND, SND_BELL, 0); 231 input_inject_event(handle, EV_SND, SND_BELL, 0);
233 } 232 }
234 } 233 }
235} 234}
@@ -247,11 +246,11 @@ void kd_mksound(unsigned int hz, unsigned int ticks)
247 struct input_handle *handle = to_handle_h(node); 246 struct input_handle *handle = to_handle_h(node);
248 if (test_bit(EV_SND, handle->dev->evbit)) { 247 if (test_bit(EV_SND, handle->dev->evbit)) {
249 if (test_bit(SND_TONE, handle->dev->sndbit)) { 248 if (test_bit(SND_TONE, handle->dev->sndbit)) {
250 input_event(handle->dev, EV_SND, SND_TONE, hz); 249 input_inject_event(handle, EV_SND, SND_TONE, hz);
251 break; 250 break;
252 } 251 }
253 if (test_bit(SND_BELL, handle->dev->sndbit)) { 252 if (test_bit(SND_BELL, handle->dev->sndbit)) {
254 input_event(handle->dev, EV_SND, SND_BELL, 1); 253 input_inject_event(handle, EV_SND, SND_BELL, 1);
255 break; 254 break;
256 } 255 }
257 } 256 }
@@ -272,15 +271,15 @@ int kbd_rate(struct kbd_repeat *rep)
272 unsigned int d = 0; 271 unsigned int d = 0;
273 unsigned int p = 0; 272 unsigned int p = 0;
274 273
275 list_for_each(node,&kbd_handler.h_list) { 274 list_for_each(node, &kbd_handler.h_list) {
276 struct input_handle *handle = to_handle_h(node); 275 struct input_handle *handle = to_handle_h(node);
277 struct input_dev *dev = handle->dev; 276 struct input_dev *dev = handle->dev;
278 277
279 if (test_bit(EV_REP, dev->evbit)) { 278 if (test_bit(EV_REP, dev->evbit)) {
280 if (rep->delay > 0) 279 if (rep->delay > 0)
281 input_event(dev, EV_REP, REP_DELAY, rep->delay); 280 input_inject_event(handle, EV_REP, REP_DELAY, rep->delay);
282 if (rep->period > 0) 281 if (rep->period > 0)
283 input_event(dev, EV_REP, REP_PERIOD, rep->period); 282 input_inject_event(handle, EV_REP, REP_PERIOD, rep->period);
284 d = dev->rep[REP_DELAY]; 283 d = dev->rep[REP_DELAY];
285 p = dev->rep[REP_PERIOD]; 284 p = dev->rep[REP_PERIOD];
286 } 285 }
@@ -988,7 +987,7 @@ static inline unsigned char getleds(void)
988 * interrupt routines for this thing allows us to easily mask 987 * interrupt routines for this thing allows us to easily mask
989 * this when we don't want any of the above to happen. 988 * this when we don't want any of the above to happen.
990 * This allows for easy and efficient race-condition prevention 989 * This allows for easy and efficient race-condition prevention
991 * for kbd_refresh_leds => input_event(dev, EV_LED, ...) => ... 990 * for kbd_start => input_inject_event(dev, EV_LED, ...) => ...
992 */ 991 */
993 992
994static void kbd_bh(unsigned long dummy) 993static void kbd_bh(unsigned long dummy)
@@ -998,11 +997,11 @@ static void kbd_bh(unsigned long dummy)
998 997
999 if (leds != ledstate) { 998 if (leds != ledstate) {
1000 list_for_each(node, &kbd_handler.h_list) { 999 list_for_each(node, &kbd_handler.h_list) {
1001 struct input_handle * handle = to_handle_h(node); 1000 struct input_handle *handle = to_handle_h(node);
1002 input_event(handle->dev, EV_LED, LED_SCROLLL, !!(leds & 0x01)); 1001 input_inject_event(handle, EV_LED, LED_SCROLLL, !!(leds & 0x01));
1003 input_event(handle->dev, EV_LED, LED_NUML, !!(leds & 0x02)); 1002 input_inject_event(handle, EV_LED, LED_NUML, !!(leds & 0x02));
1004 input_event(handle->dev, EV_LED, LED_CAPSL, !!(leds & 0x04)); 1003 input_inject_event(handle, EV_LED, LED_CAPSL, !!(leds & 0x04));
1005 input_sync(handle->dev); 1004 input_inject_event(handle, EV_SYN, SYN_REPORT, 0);
1006 } 1005 }
1007 } 1006 }
1008 1007
@@ -1011,23 +1010,6 @@ static void kbd_bh(unsigned long dummy)
1011 1010
1012DECLARE_TASKLET_DISABLED(keyboard_tasklet, kbd_bh, 0); 1011DECLARE_TASKLET_DISABLED(keyboard_tasklet, kbd_bh, 0);
1013 1012
1014/*
1015 * This allows a newly plugged keyboard to pick the LED state.
1016 */
1017static void kbd_refresh_leds(struct input_handle *handle)
1018{
1019 unsigned char leds = ledstate;
1020
1021 tasklet_disable(&keyboard_tasklet);
1022 if (leds != 0xff) {
1023 input_event(handle->dev, EV_LED, LED_SCROLLL, !!(leds & 0x01));
1024 input_event(handle->dev, EV_LED, LED_NUML, !!(leds & 0x02));
1025 input_event(handle->dev, EV_LED, LED_CAPSL, !!(leds & 0x04));
1026 input_sync(handle->dev);
1027 }
1028 tasklet_enable(&keyboard_tasklet);
1029}
1030
1031#if defined(CONFIG_X86) || defined(CONFIG_IA64) || defined(CONFIG_ALPHA) ||\ 1013#if defined(CONFIG_X86) || defined(CONFIG_IA64) || defined(CONFIG_ALPHA) ||\
1032 defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) ||\ 1014 defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) ||\
1033 defined(CONFIG_PARISC) || defined(CONFIG_SUPERH) ||\ 1015 defined(CONFIG_PARISC) || defined(CONFIG_SUPERH) ||\
@@ -1043,7 +1025,7 @@ static const unsigned short x86_keycodes[256] =
1043 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 1025 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
1044 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1026 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
1045 80, 81, 82, 83, 84,118, 86, 87, 88,115,120,119,121,112,123, 92, 1027 80, 81, 82, 83, 84,118, 86, 87, 88,115,120,119,121,112,123, 92,
1046 284,285,309,298,312, 91,327,328,329,331,333,335,336,337,338,339, 1028 284,285,309, 0,312, 91,327,328,329,331,333,335,336,337,338,339,
1047 367,288,302,304,350, 89,334,326,267,126,268,269,125,347,348,349, 1029 367,288,302,304,350, 89,334,326,267,126,268,269,125,347,348,349,
1048 360,261,262,263,268,376,100,101,321,316,373,286,289,102,351,355, 1030 360,261,262,263,268,376,100,101,321,316,373,286,289,102,351,355,
1049 103,104,105,275,287,279,306,106,274,107,294,364,358,363,362,361, 1031 103,104,105,275,287,279,306,106,274,107,294,364,358,363,362,361,
@@ -1065,38 +1047,55 @@ extern void sun_do_break(void);
1065static int emulate_raw(struct vc_data *vc, unsigned int keycode, 1047static int emulate_raw(struct vc_data *vc, unsigned int keycode,
1066 unsigned char up_flag) 1048 unsigned char up_flag)
1067{ 1049{
1068 if (keycode > 255 || !x86_keycodes[keycode]) 1050 int code;
1069 return -1;
1070 1051
1071 switch (keycode) { 1052 switch (keycode) {
1072 case KEY_PAUSE: 1053 case KEY_PAUSE:
1073 put_queue(vc, 0xe1); 1054 put_queue(vc, 0xe1);
1074 put_queue(vc, 0x1d | up_flag); 1055 put_queue(vc, 0x1d | up_flag);
1075 put_queue(vc, 0x45 | up_flag); 1056 put_queue(vc, 0x45 | up_flag);
1076 return 0; 1057 break;
1058
1077 case KEY_HANGEUL: 1059 case KEY_HANGEUL:
1078 if (!up_flag) 1060 if (!up_flag)
1079 put_queue(vc, 0xf2); 1061 put_queue(vc, 0xf2);
1080 return 0; 1062 break;
1063
1081 case KEY_HANJA: 1064 case KEY_HANJA:
1082 if (!up_flag) 1065 if (!up_flag)
1083 put_queue(vc, 0xf1); 1066 put_queue(vc, 0xf1);
1084 return 0; 1067 break;
1085 }
1086 1068
1087 if (keycode == KEY_SYSRQ && sysrq_alt) { 1069 case KEY_SYSRQ:
1088 put_queue(vc, 0x54 | up_flag); 1070 /*
1089 return 0; 1071 * Real AT keyboards (that's what we're trying
1090 } 1072 * to emulate here emit 0xe0 0x2a 0xe0 0x37 when
1073 * pressing PrtSc/SysRq alone, but simply 0x54
1074 * when pressing Alt+PrtSc/SysRq.
1075 */
1076 if (sysrq_alt) {
1077 put_queue(vc, 0x54 | up_flag);
1078 } else {
1079 put_queue(vc, 0xe0);
1080 put_queue(vc, 0x2a | up_flag);
1081 put_queue(vc, 0xe0);
1082 put_queue(vc, 0x37 | up_flag);
1083 }
1084 break;
1085
1086 default:
1087 if (keycode > 255)
1088 return -1;
1091 1089
1092 if (x86_keycodes[keycode] & 0x100) 1090 code = x86_keycodes[keycode];
1093 put_queue(vc, 0xe0); 1091 if (!code)
1092 return -1;
1094 1093
1095 put_queue(vc, (x86_keycodes[keycode] & 0x7f) | up_flag); 1094 if (code & 0x100)
1095 put_queue(vc, 0xe0);
1096 put_queue(vc, (code & 0x7f) | up_flag);
1096 1097
1097 if (keycode == KEY_SYSRQ) { 1098 break;
1098 put_queue(vc, 0xe0);
1099 put_queue(vc, 0x37 | up_flag);
1100 } 1099 }
1101 1100
1102 return 0; 1101 return 0;
@@ -1298,16 +1297,15 @@ static struct input_handle *kbd_connect(struct input_handler *handler,
1298 if (i == BTN_MISC && !test_bit(EV_SND, dev->evbit)) 1297 if (i == BTN_MISC && !test_bit(EV_SND, dev->evbit))
1299 return NULL; 1298 return NULL;
1300 1299
1301 if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL))) 1300 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
1301 if (!handle)
1302 return NULL; 1302 return NULL;
1303 memset(handle, 0, sizeof(struct input_handle));
1304 1303
1305 handle->dev = dev; 1304 handle->dev = dev;
1306 handle->handler = handler; 1305 handle->handler = handler;
1307 handle->name = "kbd"; 1306 handle->name = "kbd";
1308 1307
1309 input_open_device(handle); 1308 input_open_device(handle);
1310 kbd_refresh_leds(handle);
1311 1309
1312 return handle; 1310 return handle;
1313} 1311}
@@ -1318,6 +1316,24 @@ static void kbd_disconnect(struct input_handle *handle)
1318 kfree(handle); 1316 kfree(handle);
1319} 1317}
1320 1318
1319/*
1320 * Start keyboard handler on the new keyboard by refreshing LED state to
1321 * match the rest of the system.
1322 */
1323static void kbd_start(struct input_handle *handle)
1324{
1325 unsigned char leds = ledstate;
1326
1327 tasklet_disable(&keyboard_tasklet);
1328 if (leds != 0xff) {
1329 input_inject_event(handle, EV_LED, LED_SCROLLL, !!(leds & 0x01));
1330 input_inject_event(handle, EV_LED, LED_NUML, !!(leds & 0x02));
1331 input_inject_event(handle, EV_LED, LED_CAPSL, !!(leds & 0x04));
1332 input_inject_event(handle, EV_SYN, SYN_REPORT, 0);
1333 }
1334 tasklet_enable(&keyboard_tasklet);
1335}
1336
1321static struct input_device_id kbd_ids[] = { 1337static struct input_device_id kbd_ids[] = {
1322 { 1338 {
1323 .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1339 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
@@ -1338,6 +1354,7 @@ static struct input_handler kbd_handler = {
1338 .event = kbd_event, 1354 .event = kbd_event,
1339 .connect = kbd_connect, 1355 .connect = kbd_connect,
1340 .disconnect = kbd_disconnect, 1356 .disconnect = kbd_disconnect,
1357 .start = kbd_start,
1341 .name = "kbd", 1358 .name = "kbd",
1342 .id_table = kbd_ids, 1359 .id_table = kbd_ids,
1343}; 1360};
@@ -1346,15 +1363,15 @@ int __init kbd_init(void)
1346{ 1363{
1347 int i; 1364 int i;
1348 1365
1349 kbd0.ledflagstate = kbd0.default_ledflagstate = KBD_DEFLEDS; 1366 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1350 kbd0.ledmode = LED_SHOW_FLAGS; 1367 kbd_table[i].ledflagstate = KBD_DEFLEDS;
1351 kbd0.lockstate = KBD_DEFLOCK; 1368 kbd_table[i].default_ledflagstate = KBD_DEFLEDS;
1352 kbd0.slockstate = 0; 1369 kbd_table[i].ledmode = LED_SHOW_FLAGS;
1353 kbd0.modeflags = KBD_DEFMODE; 1370 kbd_table[i].lockstate = KBD_DEFLOCK;
1354 kbd0.kbdmode = VC_XLATE; 1371 kbd_table[i].slockstate = 0;
1355 1372 kbd_table[i].modeflags = KBD_DEFMODE;
1356 for (i = 0 ; i < MAX_NR_CONSOLES ; i++) 1373 kbd_table[i].kbdmode = VC_XLATE;
1357 kbd_table[i] = kbd0; 1374 }
1358 1375
1359 input_register_handler(&kbd_handler); 1376 input_register_handler(&kbd_handler);
1360 1377
diff --git a/drivers/char/lcd.c b/drivers/char/lcd.c
index 7d49b241de56..da601fd6c07a 100644
--- a/drivers/char/lcd.c
+++ b/drivers/char/lcd.c
@@ -598,7 +598,7 @@ static ssize_t lcd_read(struct file *file, char *buf,
598 * The various file operations we support. 598 * The various file operations we support.
599 */ 599 */
600 600
601static struct file_operations lcd_fops = { 601static const struct file_operations lcd_fops = {
602 .read = lcd_read, 602 .read = lcd_read,
603 .ioctl = lcd_ioctl, 603 .ioctl = lcd_ioctl,
604 .open = lcd_open, 604 .open = lcd_open,
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index 582cdbdb0c42..f875fda3b089 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -666,7 +666,7 @@ static int lp_ioctl(struct inode *inode, struct file *file,
666 return retval; 666 return retval;
667} 667}
668 668
669static struct file_operations lp_fops = { 669static const struct file_operations lp_fops = {
670 .owner = THIS_MODULE, 670 .owner = THIS_MODULE,
671 .write = lp_write, 671 .write = lp_write,
672 .ioctl = lp_ioctl, 672 .ioctl = lp_ioctl,
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 70f3954d6dfd..917b20402664 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -95,7 +95,7 @@ static inline int valid_phys_addr_range(unsigned long addr, size_t count)
95 return 1; 95 return 1;
96} 96}
97 97
98static inline int valid_mmap_phys_addr_range(unsigned long addr, size_t size) 98static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t size)
99{ 99{
100 return 1; 100 return 1;
101} 101}
@@ -242,7 +242,7 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma)
242{ 242{
243 size_t size = vma->vm_end - vma->vm_start; 243 size_t size = vma->vm_end - vma->vm_start;
244 244
245 if (!valid_mmap_phys_addr_range(vma->vm_pgoff << PAGE_SHIFT, size)) 245 if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))
246 return -EINVAL; 246 return -EINVAL;
247 247
248 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, 248 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
@@ -776,7 +776,7 @@ static int open_port(struct inode * inode, struct file * filp)
776#define open_kmem open_mem 776#define open_kmem open_mem
777#define open_oldmem open_mem 777#define open_oldmem open_mem
778 778
779static struct file_operations mem_fops = { 779static const struct file_operations mem_fops = {
780 .llseek = memory_lseek, 780 .llseek = memory_lseek,
781 .read = read_mem, 781 .read = read_mem,
782 .write = write_mem, 782 .write = write_mem,
@@ -784,7 +784,7 @@ static struct file_operations mem_fops = {
784 .open = open_mem, 784 .open = open_mem,
785}; 785};
786 786
787static struct file_operations kmem_fops = { 787static const struct file_operations kmem_fops = {
788 .llseek = memory_lseek, 788 .llseek = memory_lseek,
789 .read = read_kmem, 789 .read = read_kmem,
790 .write = write_kmem, 790 .write = write_kmem,
@@ -792,7 +792,7 @@ static struct file_operations kmem_fops = {
792 .open = open_kmem, 792 .open = open_kmem,
793}; 793};
794 794
795static struct file_operations null_fops = { 795static const struct file_operations null_fops = {
796 .llseek = null_lseek, 796 .llseek = null_lseek,
797 .read = read_null, 797 .read = read_null,
798 .write = write_null, 798 .write = write_null,
@@ -800,7 +800,7 @@ static struct file_operations null_fops = {
800}; 800};
801 801
802#if defined(CONFIG_ISA) || !defined(__mc68000__) 802#if defined(CONFIG_ISA) || !defined(__mc68000__)
803static struct file_operations port_fops = { 803static const struct file_operations port_fops = {
804 .llseek = memory_lseek, 804 .llseek = memory_lseek,
805 .read = read_port, 805 .read = read_port,
806 .write = write_port, 806 .write = write_port,
@@ -808,7 +808,7 @@ static struct file_operations port_fops = {
808}; 808};
809#endif 809#endif
810 810
811static struct file_operations zero_fops = { 811static const struct file_operations zero_fops = {
812 .llseek = zero_lseek, 812 .llseek = zero_lseek,
813 .read = read_zero, 813 .read = read_zero,
814 .write = write_zero, 814 .write = write_zero,
@@ -819,14 +819,14 @@ static struct backing_dev_info zero_bdi = {
819 .capabilities = BDI_CAP_MAP_COPY, 819 .capabilities = BDI_CAP_MAP_COPY,
820}; 820};
821 821
822static struct file_operations full_fops = { 822static const struct file_operations full_fops = {
823 .llseek = full_lseek, 823 .llseek = full_lseek,
824 .read = read_full, 824 .read = read_full,
825 .write = write_full, 825 .write = write_full,
826}; 826};
827 827
828#ifdef CONFIG_CRASH_DUMP 828#ifdef CONFIG_CRASH_DUMP
829static struct file_operations oldmem_fops = { 829static const struct file_operations oldmem_fops = {
830 .read = read_oldmem, 830 .read = read_oldmem,
831 .open = open_oldmem, 831 .open = open_oldmem,
832}; 832};
@@ -853,7 +853,7 @@ static ssize_t kmsg_write(struct file * file, const char __user * buf,
853 return ret; 853 return ret;
854} 854}
855 855
856static struct file_operations kmsg_fops = { 856static const struct file_operations kmsg_fops = {
857 .write = kmsg_write, 857 .write = kmsg_write,
858}; 858};
859 859
@@ -903,7 +903,7 @@ static int memory_open(struct inode * inode, struct file * filp)
903 return 0; 903 return 0;
904} 904}
905 905
906static struct file_operations memory_fops = { 906static const struct file_operations memory_fops = {
907 .open = memory_open, /* just a selector for the real open */ 907 .open = memory_open, /* just a selector for the real open */
908}; 908};
909 909
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index d5fa19da330b..62ebe09656e3 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -113,7 +113,7 @@ static int misc_seq_open(struct inode *inode, struct file *file)
113 return seq_open(file, &misc_seq_ops); 113 return seq_open(file, &misc_seq_ops);
114} 114}
115 115
116static struct file_operations misc_proc_fops = { 116static const struct file_operations misc_proc_fops = {
117 .owner = THIS_MODULE, 117 .owner = THIS_MODULE,
118 .open = misc_seq_open, 118 .open = misc_seq_open,
119 .read = seq_read, 119 .read = seq_read,
@@ -176,7 +176,7 @@ fail:
176 */ 176 */
177static struct class *misc_class; 177static struct class *misc_class;
178 178
179static struct file_operations misc_fops = { 179static const struct file_operations misc_fops = {
180 .owner = THIS_MODULE, 180 .owner = THIS_MODULE,
181 .open = misc_open, 181 .open = misc_open,
182}; 182};
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 70b774ff5aa4..1f0f2b6dae26 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -63,7 +63,7 @@ static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma);
63 */ 63 */
64static unsigned long mmtimer_femtoperiod = 0; 64static unsigned long mmtimer_femtoperiod = 0;
65 65
66static struct file_operations mmtimer_fops = { 66static const struct file_operations mmtimer_fops = {
67 .owner = THIS_MODULE, 67 .owner = THIS_MODULE,
68 .mmap = mmtimer_mmap, 68 .mmap = mmtimer_mmap,
69 .ioctl = mmtimer_ioctl, 69 .ioctl = mmtimer_ioctl,
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 4ea7bd5f4f56..a369dd6877d8 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -142,6 +142,7 @@ typedef struct _moxa_board_conf {
142 142
143static moxa_board_conf moxa_boards[MAX_BOARDS]; 143static moxa_board_conf moxa_boards[MAX_BOARDS];
144static void __iomem *moxaBaseAddr[MAX_BOARDS]; 144static void __iomem *moxaBaseAddr[MAX_BOARDS];
145static int loadstat[MAX_BOARDS];
145 146
146struct moxa_str { 147struct moxa_str {
147 int type; 148 int type;
@@ -1688,6 +1689,8 @@ int MoxaDriverPoll(void)
1688 if (moxaCard == 0) 1689 if (moxaCard == 0)
1689 return (-1); 1690 return (-1);
1690 for (card = 0; card < MAX_BOARDS; card++) { 1691 for (card = 0; card < MAX_BOARDS; card++) {
1692 if (loadstat[card] == 0)
1693 continue;
1691 if ((ports = moxa_boards[card].numPorts) == 0) 1694 if ((ports = moxa_boards[card].numPorts) == 0)
1692 continue; 1695 continue;
1693 if (readb(moxaIntPend[card]) == 0xff) { 1696 if (readb(moxaIntPend[card]) == 0xff) {
@@ -2903,6 +2906,7 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
2903 } 2906 }
2904 break; 2907 break;
2905 } 2908 }
2909 loadstat[cardno] = 1;
2906 return (0); 2910 return (0);
2907} 2911}
2908 2912
@@ -2920,7 +2924,7 @@ static int moxaloadc218(int cardno, void __iomem *baseAddr, int len)
2920 len1 = len >> 1; 2924 len1 = len >> 1;
2921 ptr = (ushort *) moxaBuff; 2925 ptr = (ushort *) moxaBuff;
2922 for (i = 0; i < len1; i++) 2926 for (i = 0; i < len1; i++)
2923 usum += *(ptr + i); 2927 usum += le16_to_cpu(*(ptr + i));
2924 retry = 0; 2928 retry = 0;
2925 do { 2929 do {
2926 len1 = len >> 1; 2930 len1 = len >> 1;
@@ -2992,7 +2996,7 @@ static int moxaloadc320(int cardno, void __iomem *baseAddr, int len, int *numPor
2992 wlen = len >> 1; 2996 wlen = len >> 1;
2993 uptr = (ushort *) moxaBuff; 2997 uptr = (ushort *) moxaBuff;
2994 for (i = 0; i < wlen; i++) 2998 for (i = 0; i < wlen; i++)
2995 usum += uptr[i]; 2999 usum += le16_to_cpu(uptr[i]);
2996 retry = 0; 3000 retry = 0;
2997 j = 0; 3001 j = 0;
2998 do { 3002 do {
diff --git a/drivers/char/mwave/mwavedd.c b/drivers/char/mwave/mwavedd.c
index d3ba2f860ef0..39a2e661ff55 100644
--- a/drivers/char/mwave/mwavedd.c
+++ b/drivers/char/mwave/mwavedd.c
@@ -454,7 +454,7 @@ static int register_serial_portandirq(unsigned int port, int irq)
454} 454}
455 455
456 456
457static struct file_operations mwave_fops = { 457static const struct file_operations mwave_fops = {
458 .owner = THIS_MODULE, 458 .owner = THIS_MODULE,
459 .read = mwave_read, 459 .read = mwave_read,
460 .write = mwave_write, 460 .write = mwave_write,
diff --git a/drivers/char/nsc_gpio.c b/drivers/char/nsc_gpio.c
index 5b91e4e25641..7719bd75810b 100644
--- a/drivers/char/nsc_gpio.c
+++ b/drivers/char/nsc_gpio.c
@@ -68,13 +68,11 @@ ssize_t nsc_gpio_write(struct file *file, const char __user *data,
68 amp->gpio_config(m, ~1, 0); 68 amp->gpio_config(m, ~1, 0);
69 break; 69 break;
70 case 'T': 70 case 'T':
71 dev_dbg(dev, "GPIO%d output is push pull\n", 71 dev_dbg(dev, "GPIO%d output is push pull\n", m);
72 m);
73 amp->gpio_config(m, ~2, 2); 72 amp->gpio_config(m, ~2, 2);
74 break; 73 break;
75 case 't': 74 case 't':
76 dev_dbg(dev, "GPIO%d output is open drain\n", 75 dev_dbg(dev, "GPIO%d output is open drain\n", m);
77 m);
78 amp->gpio_config(m, ~2, 0); 76 amp->gpio_config(m, ~2, 0);
79 break; 77 break;
80 case 'P': 78 case 'P':
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index 8c5f102622b6..a39f19c35a6a 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -437,7 +437,7 @@ nvram_read_proc(char *buffer, char **start, off_t offset,
437 437
438#endif /* CONFIG_PROC_FS */ 438#endif /* CONFIG_PROC_FS */
439 439
440static struct file_operations nvram_fops = { 440static const struct file_operations nvram_fops = {
441 .owner = THIS_MODULE, 441 .owner = THIS_MODULE,
442 .llseek = nvram_llseek, 442 .llseek = nvram_llseek,
443 .read = nvram_read, 443 .read = nvram_read,
diff --git a/drivers/char/nwbutton.c b/drivers/char/nwbutton.c
index f240a104d250..7c57ebfa8640 100644
--- a/drivers/char/nwbutton.c
+++ b/drivers/char/nwbutton.c
@@ -183,7 +183,7 @@ static int button_read (struct file *filp, char __user *buffer,
183 * attempts to perform these operations on the device. 183 * attempts to perform these operations on the device.
184 */ 184 */
185 185
186static struct file_operations button_fops = { 186static const struct file_operations button_fops = {
187 .owner = THIS_MODULE, 187 .owner = THIS_MODULE,
188 .read = button_read, 188 .read = button_read,
189}; 189};
diff --git a/drivers/char/nwflash.c b/drivers/char/nwflash.c
index 8865387d3448..206cf6f50695 100644
--- a/drivers/char/nwflash.c
+++ b/drivers/char/nwflash.c
@@ -642,7 +642,7 @@ static void kick_open(void)
642 udelay(25); 642 udelay(25);
643} 643}
644 644
645static struct file_operations flash_fops = 645static const struct file_operations flash_fops =
646{ 646{
647 .owner = THIS_MODULE, 647 .owner = THIS_MODULE,
648 .llseek = flash_llseek, 648 .llseek = flash_llseek,
diff --git a/drivers/char/pc8736x_gpio.c b/drivers/char/pc8736x_gpio.c
index c860de6a6fde..84e5a68635f1 100644
--- a/drivers/char/pc8736x_gpio.c
+++ b/drivers/char/pc8736x_gpio.c
@@ -3,18 +3,18 @@
3 National Semiconductor PC8736x GPIO driver. Allows a user space 3 National Semiconductor PC8736x GPIO driver. Allows a user space
4 process to play with the GPIO pins. 4 process to play with the GPIO pins.
5 5
6 Copyright (c) 2005 Jim Cromie <jim.cromie@gmail.com> 6 Copyright (c) 2005,2006 Jim Cromie <jim.cromie@gmail.com>
7 7
8 adapted from linux/drivers/char/scx200_gpio.c 8 adapted from linux/drivers/char/scx200_gpio.c
9 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>, 9 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>,
10*/ 10*/
11 11
12#include <linux/config.h>
13#include <linux/fs.h> 12#include <linux/fs.h>
14#include <linux/module.h> 13#include <linux/module.h>
15#include <linux/errno.h> 14#include <linux/errno.h>
16#include <linux/kernel.h> 15#include <linux/kernel.h>
17#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/cdev.h>
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/ioport.h> 19#include <linux/ioport.h>
20#include <linux/mutex.h> 20#include <linux/mutex.h>
@@ -25,7 +25,7 @@
25#define DEVNAME "pc8736x_gpio" 25#define DEVNAME "pc8736x_gpio"
26 26
27MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>"); 27MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
28MODULE_DESCRIPTION("NatSemi PC-8736x GPIO Pin Driver"); 28MODULE_DESCRIPTION("NatSemi/Winbond PC-8736x GPIO Pin Driver");
29MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
30 30
31static int major; /* default to dynamic major */ 31static int major; /* default to dynamic major */
@@ -38,14 +38,14 @@ static u8 pc8736x_gpio_shadow[4];
38 38
39#define SIO_BASE1 0x2E /* 1st command-reg to check */ 39#define SIO_BASE1 0x2E /* 1st command-reg to check */
40#define SIO_BASE2 0x4E /* alt command-reg to check */ 40#define SIO_BASE2 0x4E /* alt command-reg to check */
41#define SIO_BASE_OFFSET 0x20
42 41
43#define SIO_SID 0x20 /* SuperI/O ID Register */ 42#define SIO_SID 0x20 /* SuperI/O ID Register */
44#define SIO_SID_VALUE 0xe9 /* Expected value in SuperI/O ID Register */ 43#define SIO_SID_VALUE 0xe9 /* Expected value in SuperI/O ID Register */
45 44
46#define SIO_CF1 0x21 /* chip config, bit0 is chip enable */ 45#define SIO_CF1 0x21 /* chip config, bit0 is chip enable */
47 46
48#define PC8736X_GPIO_SIZE 16 47#define PC8736X_GPIO_RANGE 16 /* ioaddr range */
48#define PC8736X_GPIO_CT 32 /* minors matching 4 8 bit ports */
49 49
50#define SIO_UNIT_SEL 0x7 /* unit select reg */ 50#define SIO_UNIT_SEL 0x7 /* unit select reg */
51#define SIO_UNIT_ACT 0x30 /* unit enable */ 51#define SIO_UNIT_ACT 0x30 /* unit enable */
@@ -212,14 +212,12 @@ static void pc8736x_gpio_change(unsigned index)
212 pc8736x_gpio_set(index, !pc8736x_gpio_current(index)); 212 pc8736x_gpio_set(index, !pc8736x_gpio_current(index));
213} 213}
214 214
215static struct nsc_gpio_ops pc8736x_access = { 215static struct nsc_gpio_ops pc8736x_gpio_ops = {
216 .owner = THIS_MODULE, 216 .owner = THIS_MODULE,
217 .gpio_config = pc8736x_gpio_configure, 217 .gpio_config = pc8736x_gpio_configure,
218 .gpio_dump = nsc_gpio_dump, 218 .gpio_dump = nsc_gpio_dump,
219 .gpio_get = pc8736x_gpio_get, 219 .gpio_get = pc8736x_gpio_get,
220 .gpio_set = pc8736x_gpio_set, 220 .gpio_set = pc8736x_gpio_set,
221 .gpio_set_high = pc8736x_gpio_set_high,
222 .gpio_set_low = pc8736x_gpio_set_low,
223 .gpio_change = pc8736x_gpio_change, 221 .gpio_change = pc8736x_gpio_change,
224 .gpio_current = pc8736x_gpio_current 222 .gpio_current = pc8736x_gpio_current
225}; 223};
@@ -227,16 +225,16 @@ static struct nsc_gpio_ops pc8736x_access = {
227static int pc8736x_gpio_open(struct inode *inode, struct file *file) 225static int pc8736x_gpio_open(struct inode *inode, struct file *file)
228{ 226{
229 unsigned m = iminor(inode); 227 unsigned m = iminor(inode);
230 file->private_data = &pc8736x_access; 228 file->private_data = &pc8736x_gpio_ops;
231 229
232 dev_dbg(&pdev->dev, "open %d\n", m); 230 dev_dbg(&pdev->dev, "open %d\n", m);
233 231
234 if (m > 63) 232 if (m >= PC8736X_GPIO_CT)
235 return -EINVAL; 233 return -EINVAL;
236 return nonseekable_open(inode, file); 234 return nonseekable_open(inode, file);
237} 235}
238 236
239static struct file_operations pc8736x_gpio_fops = { 237static const struct file_operations pc8736x_gpio_fileops = {
240 .owner = THIS_MODULE, 238 .owner = THIS_MODULE,
241 .open = pc8736x_gpio_open, 239 .open = pc8736x_gpio_open,
242 .write = nsc_gpio_write, 240 .write = nsc_gpio_write,
@@ -255,9 +253,12 @@ static void __init pc8736x_init_shadow(void)
255 253
256} 254}
257 255
256static struct cdev pc8736x_gpio_cdev;
257
258static int __init pc8736x_gpio_init(void) 258static int __init pc8736x_gpio_init(void)
259{ 259{
260 int rc = 0; 260 int rc;
261 dev_t devid;
261 262
262 pdev = platform_device_alloc(DEVNAME, 0); 263 pdev = platform_device_alloc(DEVNAME, 0);
263 if (!pdev) 264 if (!pdev)
@@ -275,7 +276,7 @@ static int __init pc8736x_gpio_init(void)
275 dev_err(&pdev->dev, "no device found\n"); 276 dev_err(&pdev->dev, "no device found\n");
276 goto undo_platform_dev_add; 277 goto undo_platform_dev_add;
277 } 278 }
278 pc8736x_access.dev = &pdev->dev; 279 pc8736x_gpio_ops.dev = &pdev->dev;
279 280
280 /* Verify that chip and it's GPIO unit are both enabled. 281 /* Verify that chip and it's GPIO unit are both enabled.
281 My BIOS does this, so I take minimum action here 282 My BIOS does this, so I take minimum action here
@@ -297,7 +298,7 @@ static int __init pc8736x_gpio_init(void)
297 pc8736x_gpio_base = (superio_inb(SIO_BASE_HADDR) << 8 298 pc8736x_gpio_base = (superio_inb(SIO_BASE_HADDR) << 8
298 | superio_inb(SIO_BASE_LADDR)); 299 | superio_inb(SIO_BASE_LADDR));
299 300
300 if (!request_region(pc8736x_gpio_base, 16, DEVNAME)) { 301 if (!request_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE, DEVNAME)) {
301 rc = -ENODEV; 302 rc = -ENODEV;
302 dev_err(&pdev->dev, "GPIO ioport %x busy\n", 303 dev_err(&pdev->dev, "GPIO ioport %x busy\n",
303 pc8736x_gpio_base); 304 pc8736x_gpio_base);
@@ -305,10 +306,17 @@ static int __init pc8736x_gpio_init(void)
305 } 306 }
306 dev_info(&pdev->dev, "GPIO ioport %x reserved\n", pc8736x_gpio_base); 307 dev_info(&pdev->dev, "GPIO ioport %x reserved\n", pc8736x_gpio_base);
307 308
308 rc = register_chrdev(major, DEVNAME, &pc8736x_gpio_fops); 309 if (major) {
310 devid = MKDEV(major, 0);
311 rc = register_chrdev_region(devid, PC8736X_GPIO_CT, DEVNAME);
312 } else {
313 rc = alloc_chrdev_region(&devid, 0, PC8736X_GPIO_CT, DEVNAME);
314 major = MAJOR(devid);
315 }
316
309 if (rc < 0) { 317 if (rc < 0) {
310 dev_err(&pdev->dev, "register-chrdev failed: %d\n", rc); 318 dev_err(&pdev->dev, "register-chrdev failed: %d\n", rc);
311 goto undo_platform_dev_add; 319 goto undo_request_region;
312 } 320 }
313 if (!major) { 321 if (!major) {
314 major = rc; 322 major = rc;
@@ -316,8 +324,15 @@ static int __init pc8736x_gpio_init(void)
316 } 324 }
317 325
318 pc8736x_init_shadow(); 326 pc8736x_init_shadow();
327
328 /* ignore minor errs, and succeed */
329 cdev_init(&pc8736x_gpio_cdev, &pc8736x_gpio_fileops);
330 cdev_add(&pc8736x_gpio_cdev, devid, PC8736X_GPIO_CT);
331
319 return 0; 332 return 0;
320 333
334undo_request_region:
335 release_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE);
321undo_platform_dev_add: 336undo_platform_dev_add:
322 platform_device_del(pdev); 337 platform_device_del(pdev);
323undo_platform_dev_alloc: 338undo_platform_dev_alloc:
@@ -328,14 +343,15 @@ undo_platform_dev_alloc:
328 343
329static void __exit pc8736x_gpio_cleanup(void) 344static void __exit pc8736x_gpio_cleanup(void)
330{ 345{
331 dev_dbg(&pdev->dev, " cleanup\n"); 346 dev_dbg(&pdev->dev, "cleanup\n");
332 347
333 release_region(pc8736x_gpio_base, 16); 348 cdev_del(&pc8736x_gpio_cdev);
349 unregister_chrdev_region(MKDEV(major,0), PC8736X_GPIO_CT);
350 release_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE);
334 351
335 unregister_chrdev(major, DEVNAME); 352 platform_device_del(pdev);
353 platform_device_put(pdev);
336} 354}
337 355
338EXPORT_SYMBOL(pc8736x_access);
339
340module_init(pc8736x_gpio_init); 356module_init(pc8736x_gpio_init);
341module_exit(pc8736x_gpio_cleanup); 357module_exit(pc8736x_gpio_cleanup);
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index 31c8a21f9d87..50d20aafeb18 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -1938,7 +1938,7 @@ static void cm4000_detach(struct pcmcia_device *link)
1938 return; 1938 return;
1939} 1939}
1940 1940
1941static struct file_operations cm4000_fops = { 1941static const struct file_operations cm4000_fops = {
1942 .owner = THIS_MODULE, 1942 .owner = THIS_MODULE,
1943 .read = cmm_read, 1943 .read = cmm_read,
1944 .write = cmm_write, 1944 .write = cmm_write,
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index 47a8465bf95b..55cf4be42976 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -688,7 +688,7 @@ static void reader_detach(struct pcmcia_device *link)
688 return; 688 return;
689} 689}
690 690
691static struct file_operations reader_fops = { 691static const struct file_operations reader_fops = {
692 .owner = THIS_MODULE, 692 .owner = THIS_MODULE,
693 .read = cm4040_read, 693 .read = cm4040_read,
694 .write = cm4040_write, 694 .write = cm4040_write,
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 17bc8abd5df5..00f574cbb0d4 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1174,8 +1174,12 @@ static void dcd_change(MGSLPC_INFO *info)
1174 else 1174 else
1175 info->input_signal_events.dcd_down++; 1175 info->input_signal_events.dcd_down++;
1176#ifdef CONFIG_HDLC 1176#ifdef CONFIG_HDLC
1177 if (info->netcount) 1177 if (info->netcount) {
1178 hdlc_set_carrier(info->serial_signals & SerialSignal_DCD, info->netdev); 1178 if (info->serial_signals & SerialSignal_DCD)
1179 netif_carrier_on(info->netdev);
1180 else
1181 netif_carrier_off(info->netdev);
1182 }
1179#endif 1183#endif
1180 wake_up_interruptible(&info->status_event_wait_q); 1184 wake_up_interruptible(&info->status_event_wait_q);
1181 wake_up_interruptible(&info->event_wait_q); 1185 wake_up_interruptible(&info->event_wait_q);
@@ -4251,8 +4255,10 @@ static int hdlcdev_open(struct net_device *dev)
4251 spin_lock_irqsave(&info->lock, flags); 4255 spin_lock_irqsave(&info->lock, flags);
4252 get_signals(info); 4256 get_signals(info);
4253 spin_unlock_irqrestore(&info->lock, flags); 4257 spin_unlock_irqrestore(&info->lock, flags);
4254 hdlc_set_carrier(info->serial_signals & SerialSignal_DCD, dev); 4258 if (info->serial_signals & SerialSignal_DCD)
4255 4259 netif_carrier_on(dev);
4260 else
4261 netif_carrier_off(dev);
4256 return 0; 4262 return 0;
4257} 4263}
4258 4264
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 24231d9743dc..520d2cf82bc0 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -739,7 +739,7 @@ static unsigned int pp_poll (struct file * file, poll_table * wait)
739 739
740static struct class *ppdev_class; 740static struct class *ppdev_class;
741 741
742static struct file_operations pp_fops = { 742static const struct file_operations pp_fops = {
743 .owner = THIS_MODULE, 743 .owner = THIS_MODULE,
744 .llseek = no_llseek, 744 .llseek = no_llseek,
745 .read = pp_read, 745 .read = pp_read,
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 164bddae047f..4c3a5ca9d8f7 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -416,7 +416,7 @@ static struct entropy_store input_pool = {
416 .poolinfo = &poolinfo_table[0], 416 .poolinfo = &poolinfo_table[0],
417 .name = "input", 417 .name = "input",
418 .limit = 1, 418 .limit = 1,
419 .lock = SPIN_LOCK_UNLOCKED, 419 .lock = __SPIN_LOCK_UNLOCKED(&input_pool.lock),
420 .pool = input_pool_data 420 .pool = input_pool_data
421}; 421};
422 422
@@ -425,7 +425,7 @@ static struct entropy_store blocking_pool = {
425 .name = "blocking", 425 .name = "blocking",
426 .limit = 1, 426 .limit = 1,
427 .pull = &input_pool, 427 .pull = &input_pool,
428 .lock = SPIN_LOCK_UNLOCKED, 428 .lock = __SPIN_LOCK_UNLOCKED(&blocking_pool.lock),
429 .pool = blocking_pool_data 429 .pool = blocking_pool_data
430}; 430};
431 431
@@ -433,7 +433,7 @@ static struct entropy_store nonblocking_pool = {
433 .poolinfo = &poolinfo_table[1], 433 .poolinfo = &poolinfo_table[1],
434 .name = "nonblocking", 434 .name = "nonblocking",
435 .pull = &input_pool, 435 .pull = &input_pool,
436 .lock = SPIN_LOCK_UNLOCKED, 436 .lock = __SPIN_LOCK_UNLOCKED(&nonblocking_pool.lock),
437 .pool = nonblocking_pool_data 437 .pool = nonblocking_pool_data
438}; 438};
439 439
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 9bf97c5e38c0..579868af4a54 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -30,7 +30,7 @@ struct raw_device_data {
30static struct class *raw_class; 30static struct class *raw_class;
31static struct raw_device_data raw_devices[MAX_RAW_MINORS]; 31static struct raw_device_data raw_devices[MAX_RAW_MINORS];
32static DEFINE_MUTEX(raw_mutex); 32static DEFINE_MUTEX(raw_mutex);
33static struct file_operations raw_ctl_fops; /* forward declaration */ 33static const struct file_operations raw_ctl_fops; /* forward declaration */
34 34
35/* 35/*
36 * Open/close code for raw IO. 36 * Open/close code for raw IO.
@@ -261,7 +261,7 @@ static ssize_t raw_file_aio_write(struct kiocb *iocb, const char __user *buf,
261} 261}
262 262
263 263
264static struct file_operations raw_fops = { 264static const struct file_operations raw_fops = {
265 .read = generic_file_read, 265 .read = generic_file_read,
266 .aio_read = generic_file_aio_read, 266 .aio_read = generic_file_aio_read,
267 .write = raw_file_write, 267 .write = raw_file_write,
@@ -274,7 +274,7 @@ static struct file_operations raw_fops = {
274 .owner = THIS_MODULE, 274 .owner = THIS_MODULE,
275}; 275};
276 276
277static struct file_operations raw_ctl_fops = { 277static const struct file_operations raw_ctl_fops = {
278 .ioctl = raw_ctl_ioctl, 278 .ioctl = raw_ctl_ioctl,
279 .open = raw_open, 279 .open = raw_open,
280 .owner = THIS_MODULE, 280 .owner = THIS_MODULE,
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index 3afc6a47ebbc..3fa80aaf4527 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -243,7 +243,7 @@ static struct real_driver rio_real_driver = {
243 * 243 *
244 */ 244 */
245 245
246static struct file_operations rio_fw_fops = { 246static const struct file_operations rio_fw_fops = {
247 .owner = THIS_MODULE, 247 .owner = THIS_MODULE,
248 .ioctl = rio_fw_ioctl, 248 .ioctl = rio_fw_ioctl,
249}; 249};
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index aefac4ac0bf5..6e6a7c7a7eff 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -46,13 +46,12 @@
46 * 1.11a Daniele Bellucci: Audit create_proc_read_entry in rtc_init 46 * 1.11a Daniele Bellucci: Audit create_proc_read_entry in rtc_init
47 * 1.12 Venkatesh Pallipadi: Hooks for emulating rtc on HPET base-timer 47 * 1.12 Venkatesh Pallipadi: Hooks for emulating rtc on HPET base-timer
48 * CONFIG_HPET_EMULATE_RTC 48 * CONFIG_HPET_EMULATE_RTC
49 * 1.12a Maciej W. Rozycki: Handle memory-mapped chips properly.
49 * 1.12ac Alan Cox: Allow read access to the day of week register 50 * 1.12ac Alan Cox: Allow read access to the day of week register
50 */ 51 */
51 52
52#define RTC_VERSION "1.12ac" 53#define RTC_VERSION "1.12ac"
53 54
54#define RTC_IO_EXTENT 0x8
55
56/* 55/*
57 * Note that *all* calls to CMOS_READ and CMOS_WRITE are done with 56 * Note that *all* calls to CMOS_READ and CMOS_WRITE are done with
58 * interrupts disabled. Due to the index-port/data-port (0x70/0x71) 57 * interrupts disabled. Due to the index-port/data-port (0x70/0x71)
@@ -337,7 +336,15 @@ static ssize_t rtc_read(struct file *file, char __user *buf,
337 if (rtc_has_irq == 0) 336 if (rtc_has_irq == 0)
338 return -EIO; 337 return -EIO;
339 338
340 if (count < sizeof(unsigned)) 339 /*
340 * Historically this function used to assume that sizeof(unsigned long)
341 * is the same in userspace and kernelspace. This lead to problems
342 * for configurations with multiple ABIs such a the MIPS o32 and 64
343 * ABIs supported on the same kernel. So now we support read of both
344 * 4 and 8 bytes and assume that's the sizeof(unsigned long) in the
345 * userspace ABI.
346 */
347 if (count != sizeof(unsigned int) && count != sizeof(unsigned long))
341 return -EINVAL; 348 return -EINVAL;
342 349
343 add_wait_queue(&rtc_wait, &wait); 350 add_wait_queue(&rtc_wait, &wait);
@@ -368,10 +375,12 @@ static ssize_t rtc_read(struct file *file, char __user *buf,
368 schedule(); 375 schedule();
369 } while (1); 376 } while (1);
370 377
371 if (count < sizeof(unsigned long)) 378 if (count == sizeof(unsigned int))
372 retval = put_user(data, (unsigned int __user *)buf) ?: sizeof(int); 379 retval = put_user(data, (unsigned int __user *)buf) ?: sizeof(int);
373 else 380 else
374 retval = put_user(data, (unsigned long __user *)buf) ?: sizeof(long); 381 retval = put_user(data, (unsigned long __user *)buf) ?: sizeof(long);
382 if (!retval)
383 retval = count;
375 out: 384 out:
376 current->state = TASK_RUNNING; 385 current->state = TASK_RUNNING;
377 remove_wait_queue(&rtc_wait, &wait); 386 remove_wait_queue(&rtc_wait, &wait);
@@ -877,7 +886,7 @@ int rtc_control(rtc_task_t *task, unsigned int cmd, unsigned long arg)
877 * The various file operations we support. 886 * The various file operations we support.
878 */ 887 */
879 888
880static struct file_operations rtc_fops = { 889static const struct file_operations rtc_fops = {
881 .owner = THIS_MODULE, 890 .owner = THIS_MODULE,
882 .llseek = no_llseek, 891 .llseek = no_llseek,
883 .read = rtc_read, 892 .read = rtc_read,
@@ -896,7 +905,7 @@ static struct miscdevice rtc_dev = {
896 .fops = &rtc_fops, 905 .fops = &rtc_fops,
897}; 906};
898 907
899static struct file_operations rtc_proc_fops = { 908static const struct file_operations rtc_proc_fops = {
900 .owner = THIS_MODULE, 909 .owner = THIS_MODULE,
901 .open = rtc_proc_open, 910 .open = rtc_proc_open,
902 .read = seq_read, 911 .read = seq_read,
@@ -923,6 +932,9 @@ static int __init rtc_init(void)
923 struct sparc_isa_device *isa_dev; 932 struct sparc_isa_device *isa_dev;
924#endif 933#endif
925#endif 934#endif
935#ifndef __sparc__
936 void *r;
937#endif
926 938
927#ifdef __sparc__ 939#ifdef __sparc__
928 for_each_ebus(ebus) { 940 for_each_ebus(ebus) {
@@ -964,8 +976,13 @@ found:
964 } 976 }
965no_irq: 977no_irq:
966#else 978#else
967 if (!request_region(RTC_PORT(0), RTC_IO_EXTENT, "rtc")) { 979 if (RTC_IOMAPPED)
968 printk(KERN_ERR "rtc: I/O port %d is not free.\n", RTC_PORT (0)); 980 r = request_region(RTC_PORT(0), RTC_IO_EXTENT, "rtc");
981 else
982 r = request_mem_region(RTC_PORT(0), RTC_IO_EXTENT, "rtc");
983 if (!r) {
984 printk(KERN_ERR "rtc: I/O resource %lx is not free.\n",
985 (long)(RTC_PORT(0)));
969 return -EIO; 986 return -EIO;
970 } 987 }
971 988
@@ -979,7 +996,10 @@ no_irq:
979 if(request_irq(RTC_IRQ, rtc_int_handler_ptr, IRQF_DISABLED, "rtc", NULL)) { 996 if(request_irq(RTC_IRQ, rtc_int_handler_ptr, IRQF_DISABLED, "rtc", NULL)) {
980 /* Yeah right, seeing as irq 8 doesn't even hit the bus. */ 997 /* Yeah right, seeing as irq 8 doesn't even hit the bus. */
981 printk(KERN_ERR "rtc: IRQ %d is not free.\n", RTC_IRQ); 998 printk(KERN_ERR "rtc: IRQ %d is not free.\n", RTC_IRQ);
982 release_region(RTC_PORT(0), RTC_IO_EXTENT); 999 if (RTC_IOMAPPED)
1000 release_region(RTC_PORT(0), RTC_IO_EXTENT);
1001 else
1002 release_mem_region(RTC_PORT(0), RTC_IO_EXTENT);
983 return -EIO; 1003 return -EIO;
984 } 1004 }
985 hpet_rtc_timer_init(); 1005 hpet_rtc_timer_init();
@@ -1079,7 +1099,10 @@ static void __exit rtc_exit (void)
1079 if (rtc_has_irq) 1099 if (rtc_has_irq)
1080 free_irq (rtc_irq, &rtc_port); 1100 free_irq (rtc_irq, &rtc_port);
1081#else 1101#else
1082 release_region (RTC_PORT (0), RTC_IO_EXTENT); 1102 if (RTC_IOMAPPED)
1103 release_region(RTC_PORT(0), RTC_IO_EXTENT);
1104 else
1105 release_mem_region(RTC_PORT(0), RTC_IO_EXTENT);
1083#ifdef RTC_IRQ 1106#ifdef RTC_IRQ
1084 if (rtc_has_irq) 1107 if (rtc_has_irq)
1085 free_irq (RTC_IRQ, NULL); 1108 free_irq (RTC_IRQ, NULL);
@@ -1222,7 +1245,7 @@ static int rtc_proc_open(struct inode *inode, struct file *file)
1222 1245
1223void rtc_get_rtc_time(struct rtc_time *rtc_tm) 1246void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1224{ 1247{
1225 unsigned long uip_watchdog = jiffies; 1248 unsigned long uip_watchdog = jiffies, flags;
1226 unsigned char ctrl; 1249 unsigned char ctrl;
1227#ifdef CONFIG_MACH_DECSTATION 1250#ifdef CONFIG_MACH_DECSTATION
1228 unsigned int real_year; 1251 unsigned int real_year;
@@ -1249,7 +1272,7 @@ void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1249 * RTC has RTC_DAY_OF_WEEK, we should usually ignore it, as it is 1272 * RTC has RTC_DAY_OF_WEEK, we should usually ignore it, as it is
1250 * only updated by the RTC when initially set to a non-zero value. 1273 * only updated by the RTC when initially set to a non-zero value.
1251 */ 1274 */
1252 spin_lock_irq(&rtc_lock); 1275 spin_lock_irqsave(&rtc_lock, flags);
1253 rtc_tm->tm_sec = CMOS_READ(RTC_SECONDS); 1276 rtc_tm->tm_sec = CMOS_READ(RTC_SECONDS);
1254 rtc_tm->tm_min = CMOS_READ(RTC_MINUTES); 1277 rtc_tm->tm_min = CMOS_READ(RTC_MINUTES);
1255 rtc_tm->tm_hour = CMOS_READ(RTC_HOURS); 1278 rtc_tm->tm_hour = CMOS_READ(RTC_HOURS);
@@ -1263,7 +1286,7 @@ void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1263 real_year = CMOS_READ(RTC_DEC_YEAR); 1286 real_year = CMOS_READ(RTC_DEC_YEAR);
1264#endif 1287#endif
1265 ctrl = CMOS_READ(RTC_CONTROL); 1288 ctrl = CMOS_READ(RTC_CONTROL);
1266 spin_unlock_irq(&rtc_lock); 1289 spin_unlock_irqrestore(&rtc_lock, flags);
1267 1290
1268 if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) 1291 if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
1269 { 1292 {
diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
index 45083e5dd23b..b956c7babd18 100644
--- a/drivers/char/scx200_gpio.c
+++ b/drivers/char/scx200_gpio.c
@@ -5,7 +5,6 @@
5 5
6 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com> */ 6 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com> */
7 7
8#include <linux/config.h>
9#include <linux/device.h> 8#include <linux/device.h>
10#include <linux/fs.h> 9#include <linux/fs.h>
11#include <linux/module.h> 10#include <linux/module.h>
@@ -22,37 +21,37 @@
22#include <linux/scx200_gpio.h> 21#include <linux/scx200_gpio.h>
23#include <linux/nsc_gpio.h> 22#include <linux/nsc_gpio.h>
24 23
25#define NAME "scx200_gpio" 24#define DRVNAME "scx200_gpio"
26#define DEVNAME NAME
27 25
28static struct platform_device *pdev; 26static struct platform_device *pdev;
29 27
30MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>"); 28MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
31MODULE_DESCRIPTION("NatSemi SCx200 GPIO Pin Driver"); 29MODULE_DESCRIPTION("NatSemi/AMD SCx200 GPIO Pin Driver");
32MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
33 31
34static int major = 0; /* default to dynamic major */ 32static int major = 0; /* default to dynamic major */
35module_param(major, int, 0); 33module_param(major, int, 0);
36MODULE_PARM_DESC(major, "Major device number"); 34MODULE_PARM_DESC(major, "Major device number");
37 35
38struct nsc_gpio_ops scx200_access = { 36#define MAX_PINS 32 /* 64 later, when known ok */
37
38struct nsc_gpio_ops scx200_gpio_ops = {
39 .owner = THIS_MODULE, 39 .owner = THIS_MODULE,
40 .gpio_config = scx200_gpio_configure, 40 .gpio_config = scx200_gpio_configure,
41 .gpio_dump = nsc_gpio_dump, 41 .gpio_dump = nsc_gpio_dump,
42 .gpio_get = scx200_gpio_get, 42 .gpio_get = scx200_gpio_get,
43 .gpio_set = scx200_gpio_set, 43 .gpio_set = scx200_gpio_set,
44 .gpio_set_high = scx200_gpio_set_high,
45 .gpio_set_low = scx200_gpio_set_low,
46 .gpio_change = scx200_gpio_change, 44 .gpio_change = scx200_gpio_change,
47 .gpio_current = scx200_gpio_current 45 .gpio_current = scx200_gpio_current
48}; 46};
47EXPORT_SYMBOL(scx200_gpio_ops);
49 48
50static int scx200_gpio_open(struct inode *inode, struct file *file) 49static int scx200_gpio_open(struct inode *inode, struct file *file)
51{ 50{
52 unsigned m = iminor(inode); 51 unsigned m = iminor(inode);
53 file->private_data = &scx200_access; 52 file->private_data = &scx200_gpio_ops;
54 53
55 if (m > 63) 54 if (m >= MAX_PINS)
56 return -EINVAL; 55 return -EINVAL;
57 return nonseekable_open(inode, file); 56 return nonseekable_open(inode, file);
58} 57}
@@ -62,8 +61,7 @@ static int scx200_gpio_release(struct inode *inode, struct file *file)
62 return 0; 61 return 0;
63} 62}
64 63
65 64static const struct file_operations scx200_gpio_fileops = {
66static struct file_operations scx200_gpio_fops = {
67 .owner = THIS_MODULE, 65 .owner = THIS_MODULE,
68 .write = nsc_gpio_write, 66 .write = nsc_gpio_write,
69 .read = nsc_gpio_read, 67 .read = nsc_gpio_read,
@@ -71,21 +69,20 @@ static struct file_operations scx200_gpio_fops = {
71 .release = scx200_gpio_release, 69 .release = scx200_gpio_release,
72}; 70};
73 71
74struct cdev *scx200_devices; 72struct cdev scx200_gpio_cdev; /* use 1 cdev for all pins */
75static int num_pins = 32;
76 73
77static int __init scx200_gpio_init(void) 74static int __init scx200_gpio_init(void)
78{ 75{
79 int rc, i; 76 int rc;
80 dev_t dev = MKDEV(major, 0); 77 dev_t devid;
81 78
82 if (!scx200_gpio_present()) { 79 if (!scx200_gpio_present()) {
83 printk(KERN_ERR NAME ": no SCx200 gpio present\n"); 80 printk(KERN_ERR DRVNAME ": no SCx200 gpio present\n");
84 return -ENODEV; 81 return -ENODEV;
85 } 82 }
86 83
87 /* support dev_dbg() with pdev->dev */ 84 /* support dev_dbg() with pdev->dev */
88 pdev = platform_device_alloc(DEVNAME, 0); 85 pdev = platform_device_alloc(DRVNAME, 0);
89 if (!pdev) 86 if (!pdev)
90 return -ENOMEM; 87 return -ENOMEM;
91 88
@@ -94,37 +91,25 @@ static int __init scx200_gpio_init(void)
94 goto undo_malloc; 91 goto undo_malloc;
95 92
96 /* nsc_gpio uses dev_dbg(), so needs this */ 93 /* nsc_gpio uses dev_dbg(), so needs this */
97 scx200_access.dev = &pdev->dev; 94 scx200_gpio_ops.dev = &pdev->dev;
98 95
99 if (major) 96 if (major) {
100 rc = register_chrdev_region(dev, num_pins, "scx200_gpio"); 97 devid = MKDEV(major, 0);
101 else { 98 rc = register_chrdev_region(devid, MAX_PINS, "scx200_gpio");
102 rc = alloc_chrdev_region(&dev, 0, num_pins, "scx200_gpio"); 99 } else {
103 major = MAJOR(dev); 100 rc = alloc_chrdev_region(&devid, 0, MAX_PINS, "scx200_gpio");
101 major = MAJOR(devid);
104 } 102 }
105 if (rc < 0) { 103 if (rc < 0) {
106 dev_err(&pdev->dev, "SCx200 chrdev_region err: %d\n", rc); 104 dev_err(&pdev->dev, "SCx200 chrdev_region err: %d\n", rc);
107 goto undo_platform_device_add; 105 goto undo_platform_device_add;
108 } 106 }
109 scx200_devices = kzalloc(num_pins * sizeof(struct cdev), GFP_KERNEL); 107
110 if (!scx200_devices) { 108 cdev_init(&scx200_gpio_cdev, &scx200_gpio_fileops);
111 rc = -ENOMEM; 109 cdev_add(&scx200_gpio_cdev, devid, MAX_PINS);
112 goto undo_chrdev_region;
113 }
114 for (i = 0; i < num_pins; i++) {
115 struct cdev *cdev = &scx200_devices[i];
116 cdev_init(cdev, &scx200_gpio_fops);
117 cdev->owner = THIS_MODULE;
118 rc = cdev_add(cdev, MKDEV(major, i), 1);
119 /* tolerate 'minor' errors */
120 if (rc)
121 dev_err(&pdev->dev, "Error %d on minor %d", rc, i);
122 }
123 110
124 return 0; /* succeed */ 111 return 0; /* succeed */
125 112
126undo_chrdev_region:
127 unregister_chrdev_region(dev, num_pins);
128undo_platform_device_add: 113undo_platform_device_add:
129 platform_device_del(pdev); 114 platform_device_del(pdev);
130undo_malloc: 115undo_malloc:
@@ -135,10 +120,11 @@ undo_malloc:
135 120
136static void __exit scx200_gpio_cleanup(void) 121static void __exit scx200_gpio_cleanup(void)
137{ 122{
138 kfree(scx200_devices); 123 cdev_del(&scx200_gpio_cdev);
139 unregister_chrdev_region(MKDEV(major, 0), num_pins); 124 /* cdev_put(&scx200_gpio_cdev); */
125
126 unregister_chrdev_region(MKDEV(major, 0), MAX_PINS);
140 platform_device_unregister(pdev); 127 platform_device_unregister(pdev);
141 /* kfree(pdev); */
142} 128}
143 129
144module_init(scx200_gpio_init); 130module_init(scx200_gpio_init);
diff --git a/drivers/char/snsc.c b/drivers/char/snsc.c
index 203240b6c08f..07e0b75f2338 100644
--- a/drivers/char/snsc.c
+++ b/drivers/char/snsc.c
@@ -347,7 +347,7 @@ scdrv_poll(struct file *file, struct poll_table_struct *wait)
347 return mask; 347 return mask;
348} 348}
349 349
350static struct file_operations scdrv_fops = { 350static const struct file_operations scdrv_fops = {
351 .owner = THIS_MODULE, 351 .owner = THIS_MODULE,
352 .read = scdrv_read, 352 .read = scdrv_read,
353 .write = scdrv_write, 353 .write = scdrv_write,
@@ -374,7 +374,12 @@ scdrv_init(void)
374 struct sysctl_data_s *scd; 374 struct sysctl_data_s *scd;
375 void *salbuf; 375 void *salbuf;
376 dev_t first_dev, dev; 376 dev_t first_dev, dev;
377 nasid_t event_nasid = ia64_sn_get_console_nasid(); 377 nasid_t event_nasid;
378
379 if (!ia64_platform_is("sn2"))
380 return -ENODEV;
381
382 event_nasid = ia64_sn_get_console_nasid();
378 383
379 if (alloc_chrdev_region(&first_dev, 0, num_cnodes, 384 if (alloc_chrdev_region(&first_dev, 0, num_cnodes,
380 SYSCTL_BASENAME) < 0) { 385 SYSCTL_BASENAME) < 0) {
diff --git a/drivers/char/snsc_event.c b/drivers/char/snsc_event.c
index 8b2210b633df..d12d4f629cec 100644
--- a/drivers/char/snsc_event.c
+++ b/drivers/char/snsc_event.c
@@ -220,20 +220,7 @@ scdrv_dispatch_event(char *event, int len)
220 " Sending SIGPWR to init...\n"); 220 " Sending SIGPWR to init...\n");
221 221
222 /* give a SIGPWR signal to init proc */ 222 /* give a SIGPWR signal to init proc */
223 223 kill_proc(1, SIGPWR, 0);
224 /* first find init's task */
225 read_lock(&tasklist_lock);
226 for_each_process(p) {
227 if (p->pid == 1)
228 break;
229 }
230 if (p) {
231 force_sig(SIGPWR, p);
232 } else {
233 printk(KERN_ERR "Failed to signal init!\n");
234 snsc_shutting_down = 0; /* so can try again (?) */
235 }
236 read_unlock(&tasklist_lock);
237 } else { 224 } else {
238 /* print to system log */ 225 /* print to system log */
239 printk("%s|$(0x%x)%s\n", severity, esp_code, desc); 226 printk("%s|$(0x%x)%s\n", severity, esp_code, desc);
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index 45508a039508..d4e434d694b7 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -1106,7 +1106,7 @@ static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
1106 return ret; 1106 return ret;
1107} 1107}
1108 1108
1109static struct file_operations sonypi_misc_fops = { 1109static const struct file_operations sonypi_misc_fops = {
1110 .owner = THIS_MODULE, 1110 .owner = THIS_MODULE,
1111 .read = sonypi_misc_read, 1111 .read = sonypi_misc_read,
1112 .poll = sonypi_misc_poll, 1112 .poll = sonypi_misc_poll,
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index cb2859249d49..a1d303f9a33d 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -2584,6 +2584,12 @@ static void __exit specialix_exit_module(void)
2584 func_exit(); 2584 func_exit();
2585} 2585}
2586 2586
2587static struct pci_device_id specialx_pci_tbl[] __devinitdata = {
2588 { PCI_DEVICE(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_IO8) },
2589 { }
2590};
2591MODULE_DEVICE_TABLE(pci, specialx_pci_tbl);
2592
2587module_init(specialix_init_module); 2593module_init(specialix_init_module);
2588module_exit(specialix_exit_module); 2594module_exit(specialix_exit_module);
2589 2595
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index ed7b8eaf0367..3beb2203d24b 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -707,7 +707,7 @@ static unsigned int sc26198_baudtable[] = {
707 * Define the driver info for a user level control device. Used mainly 707 * Define the driver info for a user level control device. Used mainly
708 * to get at port stats - only not using the port device itself. 708 * to get at port stats - only not using the port device itself.
709 */ 709 */
710static struct file_operations stl_fsiomem = { 710static const struct file_operations stl_fsiomem = {
711 .owner = THIS_MODULE, 711 .owner = THIS_MODULE,
712 .ioctl = stl_memioctl, 712 .ioctl = stl_memioctl,
713}; 713};
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index 45c193aa11db..e1cd2bc4b1e4 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -410,7 +410,7 @@ static struct real_driver sx_real_driver = {
410 * 410 *
411 */ 411 */
412 412
413static struct file_operations sx_fw_fops = { 413static const struct file_operations sx_fw_fops = {
414 .owner = THIS_MODULE, 414 .owner = THIS_MODULE,
415 .ioctl = sx_fw_ioctl, 415 .ioctl = sx_fw_ioctl,
416}; 416};
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index df782dd1098c..78b1b1a2732b 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -1344,8 +1344,12 @@ static void mgsl_isr_io_pin( struct mgsl_struct *info )
1344 } else 1344 } else
1345 info->input_signal_events.dcd_down++; 1345 info->input_signal_events.dcd_down++;
1346#ifdef CONFIG_HDLC 1346#ifdef CONFIG_HDLC
1347 if (info->netcount) 1347 if (info->netcount) {
1348 hdlc_set_carrier(status & MISCSTATUS_DCD, info->netdev); 1348 if (status & MISCSTATUS_DCD)
1349 netif_carrier_on(info->netdev);
1350 else
1351 netif_carrier_off(info->netdev);
1352 }
1349#endif 1353#endif
1350 } 1354 }
1351 if (status & MISCSTATUS_CTS_LATCHED) 1355 if (status & MISCSTATUS_CTS_LATCHED)
@@ -7844,8 +7848,10 @@ static int hdlcdev_open(struct net_device *dev)
7844 spin_lock_irqsave(&info->irq_spinlock, flags); 7848 spin_lock_irqsave(&info->irq_spinlock, flags);
7845 usc_get_serial_signals(info); 7849 usc_get_serial_signals(info);
7846 spin_unlock_irqrestore(&info->irq_spinlock, flags); 7850 spin_unlock_irqrestore(&info->irq_spinlock, flags);
7847 hdlc_set_carrier(info->serial_signals & SerialSignal_DCD, dev); 7851 if (info->serial_signals & SerialSignal_DCD)
7848 7852 netif_carrier_on(dev);
7853 else
7854 netif_carrier_off(dev);
7849 return 0; 7855 return 0;
7850} 7856}
7851 7857
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index e829594195c1..2f07b085536b 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -391,8 +391,8 @@ static MGSL_PARAMS default_params = {
391#define DESC_LIST_SIZE 4096 391#define DESC_LIST_SIZE 4096
392 392
393#define MASK_PARITY BIT1 393#define MASK_PARITY BIT1
394#define MASK_FRAMING BIT2 394#define MASK_FRAMING BIT0
395#define MASK_BREAK BIT3 395#define MASK_BREAK BIT14
396#define MASK_OVERRUN BIT4 396#define MASK_OVERRUN BIT4
397 397
398#define GSR 0x00 /* global status */ 398#define GSR 0x00 /* global status */
@@ -1497,8 +1497,10 @@ static int hdlcdev_open(struct net_device *dev)
1497 spin_lock_irqsave(&info->lock, flags); 1497 spin_lock_irqsave(&info->lock, flags);
1498 get_signals(info); 1498 get_signals(info);
1499 spin_unlock_irqrestore(&info->lock, flags); 1499 spin_unlock_irqrestore(&info->lock, flags);
1500 hdlc_set_carrier(info->signals & SerialSignal_DCD, dev); 1500 if (info->signals & SerialSignal_DCD)
1501 1501 netif_carrier_on(dev);
1502 else
1503 netif_carrier_off(dev);
1502 return 0; 1504 return 0;
1503} 1505}
1504 1506
@@ -1798,17 +1800,17 @@ static void rx_async(struct slgt_info *info)
1798 1800
1799 stat = 0; 1801 stat = 0;
1800 1802
1801 if ((status = *(p+1) & (BIT9 + BIT8))) { 1803 if ((status = *(p+1) & (BIT1 + BIT0))) {
1802 if (status & BIT9) 1804 if (status & BIT1)
1803 icount->parity++; 1805 icount->parity++;
1804 else if (status & BIT8) 1806 else if (status & BIT0)
1805 icount->frame++; 1807 icount->frame++;
1806 /* discard char if tty control flags say so */ 1808 /* discard char if tty control flags say so */
1807 if (status & info->ignore_status_mask) 1809 if (status & info->ignore_status_mask)
1808 continue; 1810 continue;
1809 if (status & BIT9) 1811 if (status & BIT1)
1810 stat = TTY_PARITY; 1812 stat = TTY_PARITY;
1811 else if (status & BIT8) 1813 else if (status & BIT0)
1812 stat = TTY_FRAME; 1814 stat = TTY_FRAME;
1813 } 1815 }
1814 if (tty) { 1816 if (tty) {
@@ -1997,8 +1999,12 @@ static void dcd_change(struct slgt_info *info)
1997 info->input_signal_events.dcd_down++; 1999 info->input_signal_events.dcd_down++;
1998 } 2000 }
1999#ifdef CONFIG_HDLC 2001#ifdef CONFIG_HDLC
2000 if (info->netcount) 2002 if (info->netcount) {
2001 hdlc_set_carrier(info->signals & SerialSignal_DCD, info->netdev); 2003 if (info->signals & SerialSignal_DCD)
2004 netif_carrier_on(info->netdev);
2005 else
2006 netif_carrier_off(info->netdev);
2007 }
2002#endif 2008#endif
2003 wake_up_interruptible(&info->status_event_wait_q); 2009 wake_up_interruptible(&info->status_event_wait_q);
2004 wake_up_interruptible(&info->event_wait_q); 2010 wake_up_interruptible(&info->event_wait_q);
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 1e443a233f51..66f3754fbbdf 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -1752,8 +1752,10 @@ static int hdlcdev_open(struct net_device *dev)
1752 spin_lock_irqsave(&info->lock, flags); 1752 spin_lock_irqsave(&info->lock, flags);
1753 get_signals(info); 1753 get_signals(info);
1754 spin_unlock_irqrestore(&info->lock, flags); 1754 spin_unlock_irqrestore(&info->lock, flags);
1755 hdlc_set_carrier(info->serial_signals & SerialSignal_DCD, dev); 1755 if (info->serial_signals & SerialSignal_DCD)
1756 1756 netif_carrier_on(dev);
1757 else
1758 netif_carrier_off(dev);
1757 return 0; 1759 return 0;
1758} 1760}
1759 1761
@@ -2522,8 +2524,12 @@ void isr_io_pin( SLMP_INFO *info, u16 status )
2522 } else 2524 } else
2523 info->input_signal_events.dcd_down++; 2525 info->input_signal_events.dcd_down++;
2524#ifdef CONFIG_HDLC 2526#ifdef CONFIG_HDLC
2525 if (info->netcount) 2527 if (info->netcount) {
2526 hdlc_set_carrier(status & SerialSignal_DCD, info->netdev); 2528 if (status & SerialSignal_DCD)
2529 netif_carrier_on(info->netdev);
2530 else
2531 netif_carrier_off(info->netdev);
2532 }
2527#endif 2533#endif
2528 } 2534 }
2529 if (status & MISCSTATUS_CTS_LATCHED) 2535 if (status & MISCSTATUS_CTS_LATCHED)
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index a064ee9181c0..ee3ca8f1768e 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -147,12 +147,13 @@ static struct sysrq_key_op sysrq_mountro_op = {
147 .enable_mask = SYSRQ_ENABLE_REMOUNT, 147 .enable_mask = SYSRQ_ENABLE_REMOUNT,
148}; 148};
149 149
150#ifdef CONFIG_DEBUG_MUTEXES 150#ifdef CONFIG_LOCKDEP
151static void sysrq_handle_showlocks(int key, struct pt_regs *pt_regs, 151static void sysrq_handle_showlocks(int key, struct pt_regs *pt_regs,
152 struct tty_struct *tty) 152 struct tty_struct *tty)
153{ 153{
154 mutex_debug_show_all_locks(); 154 debug_show_all_locks();
155} 155}
156
156static struct sysrq_key_op sysrq_showlocks_op = { 157static struct sysrq_key_op sysrq_showlocks_op = {
157 .handler = sysrq_handle_showlocks, 158 .handler = sysrq_handle_showlocks,
158 .help_msg = "show-all-locks(D)", 159 .help_msg = "show-all-locks(D)",
diff --git a/drivers/char/tb0219.c b/drivers/char/tb0219.c
index a80c83210872..bb1bad4c18f9 100644
--- a/drivers/char/tb0219.c
+++ b/drivers/char/tb0219.c
@@ -255,7 +255,7 @@ static int tanbac_tb0219_release(struct inode *inode, struct file *file)
255 return 0; 255 return 0;
256} 256}
257 257
258static struct file_operations tb0219_fops = { 258static const struct file_operations tb0219_fops = {
259 .owner = THIS_MODULE, 259 .owner = THIS_MODULE,
260 .read = tanbac_tb0219_read, 260 .read = tanbac_tb0219_read,
261 .write = tanbac_tb0219_write, 261 .write = tanbac_tb0219_write,
diff --git a/drivers/char/tipar.c b/drivers/char/tipar.c
index e0633a119d29..d30dc09dbbc9 100644
--- a/drivers/char/tipar.c
+++ b/drivers/char/tipar.c
@@ -381,7 +381,7 @@ tipar_ioctl(struct inode *inode, struct file *file,
381 381
382/* ----- kernel module registering ------------------------------------ */ 382/* ----- kernel module registering ------------------------------------ */
383 383
384static struct file_operations tipar_fops = { 384static const struct file_operations tipar_fops = {
385 .owner = THIS_MODULE, 385 .owner = THIS_MODULE,
386 .llseek = no_llseek, 386 .llseek = no_llseek,
387 .read = tipar_read, 387 .read = tipar_read,
diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c
index 952b829e2cb4..d2c5ba4e83b8 100644
--- a/drivers/char/tlclk.c
+++ b/drivers/char/tlclk.c
@@ -247,7 +247,7 @@ static ssize_t tlclk_write(struct file *filp, const char __user *buf, size_t cou
247 return 0; 247 return 0;
248} 248}
249 249
250static struct file_operations tlclk_fops = { 250static const struct file_operations tlclk_fops = {
251 .read = tlclk_read, 251 .read = tlclk_read,
252 .write = tlclk_write, 252 .write = tlclk_write,
253 .open = tlclk_open, 253 .open = tlclk_open,
diff --git a/drivers/char/toshiba.c b/drivers/char/toshiba.c
index e2fb234dee40..dd36fd04a842 100644
--- a/drivers/char/toshiba.c
+++ b/drivers/char/toshiba.c
@@ -92,7 +92,7 @@ static int tosh_ioctl(struct inode *, struct file *, unsigned int,
92 unsigned long); 92 unsigned long);
93 93
94 94
95static struct file_operations tosh_fops = { 95static const struct file_operations tosh_fops = {
96 .owner = THIS_MODULE, 96 .owner = THIS_MODULE,
97 .ioctl = tosh_ioctl, 97 .ioctl = tosh_ioctl,
98}; 98};
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 6889e7db3aff..a082a2e34252 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -1141,6 +1141,7 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
1141 put_device(dev); 1141 put_device(dev);
1142 clear_bit(chip->dev_num, dev_mask); 1142 clear_bit(chip->dev_num, dev_mask);
1143 kfree(chip); 1143 kfree(chip);
1144 kfree(devname);
1144 return NULL; 1145 return NULL;
1145 } 1146 }
1146 1147
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index 58a258cec153..ad8ffe49256f 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -116,7 +116,7 @@ static u8 tpm_atml_status(struct tpm_chip *chip)
116 return ioread8(chip->vendor.iobase + 1); 116 return ioread8(chip->vendor.iobase + 1);
117} 117}
118 118
119static struct file_operations atmel_ops = { 119static const struct file_operations atmel_ops = {
120 .owner = THIS_MODULE, 120 .owner = THIS_MODULE,
121 .llseek = no_llseek, 121 .llseek = no_llseek,
122 .open = tpm_open, 122 .open = tpm_open,
diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c
index adfff21beb21..1353b5a6bae8 100644
--- a/drivers/char/tpm/tpm_infineon.c
+++ b/drivers/char/tpm/tpm_infineon.c
@@ -338,7 +338,7 @@ static struct attribute *inf_attrs[] = {
338 338
339static struct attribute_group inf_attr_grp = {.attrs = inf_attrs }; 339static struct attribute_group inf_attr_grp = {.attrs = inf_attrs };
340 340
341static struct file_operations inf_ops = { 341static const struct file_operations inf_ops = {
342 .owner = THIS_MODULE, 342 .owner = THIS_MODULE,
343 .llseek = no_llseek, 343 .llseek = no_llseek,
344 .open = tpm_open, 344 .open = tpm_open,
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
index 4c8bc06c7d95..26287aace87d 100644
--- a/drivers/char/tpm/tpm_nsc.c
+++ b/drivers/char/tpm/tpm_nsc.c
@@ -226,7 +226,7 @@ static u8 tpm_nsc_status(struct tpm_chip *chip)
226 return inb(chip->vendor.base + NSC_STATUS); 226 return inb(chip->vendor.base + NSC_STATUS);
227} 227}
228 228
229static struct file_operations nsc_ops = { 229static const struct file_operations nsc_ops = {
230 .owner = THIS_MODULE, 230 .owner = THIS_MODULE,
231 .llseek = no_llseek, 231 .llseek = no_llseek,
232 .open = tpm_open, 232 .open = tpm_open,
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index abb0f2aeae66..ee7ac6f43c65 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -330,7 +330,7 @@ out_err:
330 return rc; 330 return rc;
331} 331}
332 332
333static struct file_operations tis_ops = { 333static const struct file_operations tis_ops = {
334 .owner = THIS_MODULE, 334 .owner = THIS_MODULE,
335 .llseek = no_llseek, 335 .llseek = no_llseek,
336 .open = tpm_open, 336 .open = tpm_open,
@@ -424,6 +424,7 @@ static irqreturn_t tis_int_handler(int irq, void *dev_id, struct pt_regs *regs)
424 iowrite32(interrupt, 424 iowrite32(interrupt,
425 chip->vendor.iobase + 425 chip->vendor.iobase +
426 TPM_INT_STATUS(chip->vendor.locality)); 426 TPM_INT_STATUS(chip->vendor.locality));
427 ioread32(chip->vendor.iobase + TPM_INT_STATUS(chip->vendor.locality));
427 return IRQ_HANDLED; 428 return IRQ_HANDLED;
428} 429}
429 430
@@ -431,23 +432,19 @@ static int interrupts = 1;
431module_param(interrupts, bool, 0444); 432module_param(interrupts, bool, 0444);
432MODULE_PARM_DESC(interrupts, "Enable interrupts"); 433MODULE_PARM_DESC(interrupts, "Enable interrupts");
433 434
434static int __devinit tpm_tis_pnp_init(struct pnp_dev *pnp_dev, 435static int tpm_tis_init(struct device *dev, resource_size_t start,
435 const struct pnp_device_id *pnp_id) 436 resource_size_t len)
436{ 437{
437 u32 vendor, intfcaps, intmask; 438 u32 vendor, intfcaps, intmask;
438 int rc, i; 439 int rc, i;
439 unsigned long start, len;
440 struct tpm_chip *chip; 440 struct tpm_chip *chip;
441 441
442 start = pnp_mem_start(pnp_dev, 0);
443 len = pnp_mem_len(pnp_dev, 0);
444
445 if (!start) 442 if (!start)
446 start = TIS_MEM_BASE; 443 start = TIS_MEM_BASE;
447 if (!len) 444 if (!len)
448 len = TIS_MEM_LEN; 445 len = TIS_MEM_LEN;
449 446
450 if (!(chip = tpm_register_hardware(&pnp_dev->dev, &tpm_tis))) 447 if (!(chip = tpm_register_hardware(dev, &tpm_tis)))
451 return -ENODEV; 448 return -ENODEV;
452 449
453 chip->vendor.iobase = ioremap(start, len); 450 chip->vendor.iobase = ioremap(start, len);
@@ -464,7 +461,7 @@ static int __devinit tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
464 chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT); 461 chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
465 chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT); 462 chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
466 463
467 dev_info(&pnp_dev->dev, 464 dev_info(dev,
468 "1.2 TPM (device-id 0x%X, rev-id %d)\n", 465 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
469 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0))); 466 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
470 467
@@ -472,26 +469,26 @@ static int __devinit tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
472 intfcaps = 469 intfcaps =
473 ioread32(chip->vendor.iobase + 470 ioread32(chip->vendor.iobase +
474 TPM_INTF_CAPS(chip->vendor.locality)); 471 TPM_INTF_CAPS(chip->vendor.locality));
475 dev_dbg(&pnp_dev->dev, "TPM interface capabilities (0x%x):\n", 472 dev_dbg(dev, "TPM interface capabilities (0x%x):\n",
476 intfcaps); 473 intfcaps);
477 if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) 474 if (intfcaps & TPM_INTF_BURST_COUNT_STATIC)
478 dev_dbg(&pnp_dev->dev, "\tBurst Count Static\n"); 475 dev_dbg(dev, "\tBurst Count Static\n");
479 if (intfcaps & TPM_INTF_CMD_READY_INT) 476 if (intfcaps & TPM_INTF_CMD_READY_INT)
480 dev_dbg(&pnp_dev->dev, "\tCommand Ready Int Support\n"); 477 dev_dbg(dev, "\tCommand Ready Int Support\n");
481 if (intfcaps & TPM_INTF_INT_EDGE_FALLING) 478 if (intfcaps & TPM_INTF_INT_EDGE_FALLING)
482 dev_dbg(&pnp_dev->dev, "\tInterrupt Edge Falling\n"); 479 dev_dbg(dev, "\tInterrupt Edge Falling\n");
483 if (intfcaps & TPM_INTF_INT_EDGE_RISING) 480 if (intfcaps & TPM_INTF_INT_EDGE_RISING)
484 dev_dbg(&pnp_dev->dev, "\tInterrupt Edge Rising\n"); 481 dev_dbg(dev, "\tInterrupt Edge Rising\n");
485 if (intfcaps & TPM_INTF_INT_LEVEL_LOW) 482 if (intfcaps & TPM_INTF_INT_LEVEL_LOW)
486 dev_dbg(&pnp_dev->dev, "\tInterrupt Level Low\n"); 483 dev_dbg(dev, "\tInterrupt Level Low\n");
487 if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) 484 if (intfcaps & TPM_INTF_INT_LEVEL_HIGH)
488 dev_dbg(&pnp_dev->dev, "\tInterrupt Level High\n"); 485 dev_dbg(dev, "\tInterrupt Level High\n");
489 if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) 486 if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT)
490 dev_dbg(&pnp_dev->dev, "\tLocality Change Int Support\n"); 487 dev_dbg(dev, "\tLocality Change Int Support\n");
491 if (intfcaps & TPM_INTF_STS_VALID_INT) 488 if (intfcaps & TPM_INTF_STS_VALID_INT)
492 dev_dbg(&pnp_dev->dev, "\tSts Valid Int Support\n"); 489 dev_dbg(dev, "\tSts Valid Int Support\n");
493 if (intfcaps & TPM_INTF_DATA_AVAIL_INT) 490 if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
494 dev_dbg(&pnp_dev->dev, "\tData Avail Int Support\n"); 491 dev_dbg(dev, "\tData Avail Int Support\n");
495 492
496 if (request_locality(chip, 0) != 0) { 493 if (request_locality(chip, 0) != 0) {
497 rc = -ENODEV; 494 rc = -ENODEV;
@@ -594,6 +591,16 @@ out_err:
594 return rc; 591 return rc;
595} 592}
596 593
594static int __devinit tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
595 const struct pnp_device_id *pnp_id)
596{
597 resource_size_t start, len;
598 start = pnp_mem_start(pnp_dev, 0);
599 len = pnp_mem_len(pnp_dev, 0);
600
601 return tpm_tis_init(&pnp_dev->dev, start, len);
602}
603
597static int tpm_tis_pnp_suspend(struct pnp_dev *dev, pm_message_t msg) 604static int tpm_tis_pnp_suspend(struct pnp_dev *dev, pm_message_t msg)
598{ 605{
599 return tpm_pm_suspend(&dev->dev, msg); 606 return tpm_pm_suspend(&dev->dev, msg);
@@ -628,8 +635,36 @@ module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
628 sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444); 635 sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
629MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe"); 636MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
630 637
638static struct device_driver tis_drv = {
639 .name = "tpm_tis",
640 .bus = &platform_bus_type,
641 .owner = THIS_MODULE,
642 .suspend = tpm_pm_suspend,
643 .resume = tpm_pm_resume,
644};
645
646static struct platform_device *pdev;
647
648static int force;
649module_param(force, bool, 0444);
650MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry");
631static int __init init_tis(void) 651static int __init init_tis(void)
632{ 652{
653 int rc;
654
655 if (force) {
656 rc = driver_register(&tis_drv);
657 if (rc < 0)
658 return rc;
659 if (IS_ERR(pdev=platform_device_register_simple("tpm_tis", -1, NULL, 0)))
660 return PTR_ERR(pdev);
661 if((rc=tpm_tis_init(&pdev->dev, 0, 0)) != 0) {
662 platform_device_unregister(pdev);
663 driver_unregister(&tis_drv);
664 }
665 return rc;
666 }
667
633 return pnp_register_driver(&tis_pnp_driver); 668 return pnp_register_driver(&tis_pnp_driver);
634} 669}
635 670
@@ -654,7 +689,11 @@ static void __exit cleanup_tis(void)
654 tpm_remove_hardware(chip->dev); 689 tpm_remove_hardware(chip->dev);
655 } 690 }
656 spin_unlock(&tis_lock); 691 spin_unlock(&tis_lock);
657 pnp_unregister_driver(&tis_pnp_driver); 692 if (force) {
693 platform_device_unregister(pdev);
694 driver_unregister(&tis_drv);
695 } else
696 pnp_unregister_driver(&tis_pnp_driver);
658} 697}
659 698
660module_init(init_tis); 699module_init(init_tis);
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 615e934da05f..bb0d9199e994 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -153,6 +153,15 @@ int tty_ioctl(struct inode * inode, struct file * file,
153static int tty_fasync(int fd, struct file * filp, int on); 153static int tty_fasync(int fd, struct file * filp, int on);
154static void release_mem(struct tty_struct *tty, int idx); 154static void release_mem(struct tty_struct *tty, int idx);
155 155
156/**
157 * alloc_tty_struct - allocate a tty object
158 *
159 * Return a new empty tty structure. The data fields have not
160 * been initialized in any way but has been zeroed
161 *
162 * Locking: none
163 * FIXME: use kzalloc
164 */
156 165
157static struct tty_struct *alloc_tty_struct(void) 166static struct tty_struct *alloc_tty_struct(void)
158{ 167{
@@ -166,6 +175,15 @@ static struct tty_struct *alloc_tty_struct(void)
166 175
167static void tty_buffer_free_all(struct tty_struct *); 176static void tty_buffer_free_all(struct tty_struct *);
168 177
178/**
179 * free_tty_struct - free a disused tty
180 * @tty: tty struct to free
181 *
182 * Free the write buffers, tty queue and tty memory itself.
183 *
184 * Locking: none. Must be called after tty is definitely unused
185 */
186
169static inline void free_tty_struct(struct tty_struct *tty) 187static inline void free_tty_struct(struct tty_struct *tty)
170{ 188{
171 kfree(tty->write_buf); 189 kfree(tty->write_buf);
@@ -175,6 +193,17 @@ static inline void free_tty_struct(struct tty_struct *tty)
175 193
176#define TTY_NUMBER(tty) ((tty)->index + (tty)->driver->name_base) 194#define TTY_NUMBER(tty) ((tty)->index + (tty)->driver->name_base)
177 195
196/**
197 * tty_name - return tty naming
198 * @tty: tty structure
199 * @buf: buffer for output
200 *
201 * Convert a tty structure into a name. The name reflects the kernel
202 * naming policy and if udev is in use may not reflect user space
203 *
204 * Locking: none
205 */
206
178char *tty_name(struct tty_struct *tty, char *buf) 207char *tty_name(struct tty_struct *tty, char *buf)
179{ 208{
180 if (!tty) /* Hmm. NULL pointer. That's fun. */ 209 if (!tty) /* Hmm. NULL pointer. That's fun. */
@@ -235,6 +264,28 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)
235 * Tty buffer allocation management 264 * Tty buffer allocation management
236 */ 265 */
237 266
267
268/**
269 * tty_buffer_free_all - free buffers used by a tty
270 * @tty: tty to free from
271 *
272 * Remove all the buffers pending on a tty whether queued with data
273 * or in the free ring. Must be called when the tty is no longer in use
274 *
275 * Locking: none
276 */
277
278
279/**
280 * tty_buffer_free_all - free buffers used by a tty
281 * @tty: tty to free from
282 *
283 * Remove all the buffers pending on a tty whether queued with data
284 * or in the free ring. Must be called when the tty is no longer in use
285 *
286 * Locking: none
287 */
288
238static void tty_buffer_free_all(struct tty_struct *tty) 289static void tty_buffer_free_all(struct tty_struct *tty)
239{ 290{
240 struct tty_buffer *thead; 291 struct tty_buffer *thead;
@@ -247,19 +298,47 @@ static void tty_buffer_free_all(struct tty_struct *tty)
247 kfree(thead); 298 kfree(thead);
248 } 299 }
249 tty->buf.tail = NULL; 300 tty->buf.tail = NULL;
301 tty->buf.memory_used = 0;
250} 302}
251 303
304/**
305 * tty_buffer_init - prepare a tty buffer structure
306 * @tty: tty to initialise
307 *
308 * Set up the initial state of the buffer management for a tty device.
309 * Must be called before the other tty buffer functions are used.
310 *
311 * Locking: none
312 */
313
252static void tty_buffer_init(struct tty_struct *tty) 314static void tty_buffer_init(struct tty_struct *tty)
253{ 315{
254 spin_lock_init(&tty->buf.lock); 316 spin_lock_init(&tty->buf.lock);
255 tty->buf.head = NULL; 317 tty->buf.head = NULL;
256 tty->buf.tail = NULL; 318 tty->buf.tail = NULL;
257 tty->buf.free = NULL; 319 tty->buf.free = NULL;
320 tty->buf.memory_used = 0;
258} 321}
259 322
260static struct tty_buffer *tty_buffer_alloc(size_t size) 323/**
324 * tty_buffer_alloc - allocate a tty buffer
325 * @tty: tty device
326 * @size: desired size (characters)
327 *
328 * Allocate a new tty buffer to hold the desired number of characters.
329 * Return NULL if out of memory or the allocation would exceed the
330 * per device queue
331 *
332 * Locking: Caller must hold tty->buf.lock
333 */
334
335static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
261{ 336{
262 struct tty_buffer *p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC); 337 struct tty_buffer *p;
338
339 if (tty->buf.memory_used + size > 65536)
340 return NULL;
341 p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC);
263 if(p == NULL) 342 if(p == NULL)
264 return NULL; 343 return NULL;
265 p->used = 0; 344 p->used = 0;
@@ -269,17 +348,27 @@ static struct tty_buffer *tty_buffer_alloc(size_t size)
269 p->read = 0; 348 p->read = 0;
270 p->char_buf_ptr = (char *)(p->data); 349 p->char_buf_ptr = (char *)(p->data);
271 p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size; 350 p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size;
272/* printk("Flip create %p\n", p); */ 351 tty->buf.memory_used += size;
273 return p; 352 return p;
274} 353}
275 354
276/* Must be called with the tty_read lock held. This needs to acquire strategy 355/**
277 code to decide if we should kfree or relink a given expired buffer */ 356 * tty_buffer_free - free a tty buffer
357 * @tty: tty owning the buffer
358 * @b: the buffer to free
359 *
360 * Free a tty buffer, or add it to the free list according to our
361 * internal strategy
362 *
363 * Locking: Caller must hold tty->buf.lock
364 */
278 365
279static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b) 366static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
280{ 367{
281 /* Dumb strategy for now - should keep some stats */ 368 /* Dumb strategy for now - should keep some stats */
282/* printk("Flip dispose %p\n", b); */ 369 tty->buf.memory_used -= b->size;
370 WARN_ON(tty->buf.memory_used < 0);
371
283 if(b->size >= 512) 372 if(b->size >= 512)
284 kfree(b); 373 kfree(b);
285 else { 374 else {
@@ -288,6 +377,18 @@ static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
288 } 377 }
289} 378}
290 379
380/**
381 * tty_buffer_find - find a free tty buffer
382 * @tty: tty owning the buffer
383 * @size: characters wanted
384 *
385 * Locate an existing suitable tty buffer or if we are lacking one then
386 * allocate a new one. We round our buffers off in 256 character chunks
387 * to get better allocation behaviour.
388 *
389 * Locking: Caller must hold tty->buf.lock
390 */
391
291static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size) 392static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
292{ 393{
293 struct tty_buffer **tbh = &tty->buf.free; 394 struct tty_buffer **tbh = &tty->buf.free;
@@ -299,20 +400,28 @@ static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
299 t->used = 0; 400 t->used = 0;
300 t->commit = 0; 401 t->commit = 0;
301 t->read = 0; 402 t->read = 0;
302 /* DEBUG ONLY */ 403 tty->buf.memory_used += t->size;
303/* memset(t->data, '*', size); */
304/* printk("Flip recycle %p\n", t); */
305 return t; 404 return t;
306 } 405 }
307 tbh = &((*tbh)->next); 406 tbh = &((*tbh)->next);
308 } 407 }
309 /* Round the buffer size out */ 408 /* Round the buffer size out */
310 size = (size + 0xFF) & ~ 0xFF; 409 size = (size + 0xFF) & ~ 0xFF;
311 return tty_buffer_alloc(size); 410 return tty_buffer_alloc(tty, size);
312 /* Should possibly check if this fails for the largest buffer we 411 /* Should possibly check if this fails for the largest buffer we
313 have queued and recycle that ? */ 412 have queued and recycle that ? */
314} 413}
315 414
415/**
416 * tty_buffer_request_room - grow tty buffer if needed
417 * @tty: tty structure
418 * @size: size desired
419 *
420 * Make at least size bytes of linear space available for the tty
421 * buffer. If we fail return the size we managed to find.
422 *
423 * Locking: Takes tty->buf.lock
424 */
316int tty_buffer_request_room(struct tty_struct *tty, size_t size) 425int tty_buffer_request_room(struct tty_struct *tty, size_t size)
317{ 426{
318 struct tty_buffer *b, *n; 427 struct tty_buffer *b, *n;
@@ -347,6 +456,18 @@ int tty_buffer_request_room(struct tty_struct *tty, size_t size)
347} 456}
348EXPORT_SYMBOL_GPL(tty_buffer_request_room); 457EXPORT_SYMBOL_GPL(tty_buffer_request_room);
349 458
459/**
460 * tty_insert_flip_string - Add characters to the tty buffer
461 * @tty: tty structure
462 * @chars: characters
463 * @size: size
464 *
465 * Queue a series of bytes to the tty buffering. All the characters
466 * passed are marked as without error. Returns the number added.
467 *
468 * Locking: Called functions may take tty->buf.lock
469 */
470
350int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars, 471int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
351 size_t size) 472 size_t size)
352{ 473{
@@ -370,6 +491,20 @@ int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
370} 491}
371EXPORT_SYMBOL(tty_insert_flip_string); 492EXPORT_SYMBOL(tty_insert_flip_string);
372 493
494/**
495 * tty_insert_flip_string_flags - Add characters to the tty buffer
496 * @tty: tty structure
497 * @chars: characters
498 * @flags: flag bytes
499 * @size: size
500 *
501 * Queue a series of bytes to the tty buffering. For each character
502 * the flags array indicates the status of the character. Returns the
503 * number added.
504 *
505 * Locking: Called functions may take tty->buf.lock
506 */
507
373int tty_insert_flip_string_flags(struct tty_struct *tty, 508int tty_insert_flip_string_flags(struct tty_struct *tty,
374 const unsigned char *chars, const char *flags, size_t size) 509 const unsigned char *chars, const char *flags, size_t size)
375{ 510{
@@ -394,6 +529,17 @@ int tty_insert_flip_string_flags(struct tty_struct *tty,
394} 529}
395EXPORT_SYMBOL(tty_insert_flip_string_flags); 530EXPORT_SYMBOL(tty_insert_flip_string_flags);
396 531
532/**
533 * tty_schedule_flip - push characters to ldisc
534 * @tty: tty to push from
535 *
536 * Takes any pending buffers and transfers their ownership to the
537 * ldisc side of the queue. It then schedules those characters for
538 * processing by the line discipline.
539 *
540 * Locking: Takes tty->buf.lock
541 */
542
397void tty_schedule_flip(struct tty_struct *tty) 543void tty_schedule_flip(struct tty_struct *tty)
398{ 544{
399 unsigned long flags; 545 unsigned long flags;
@@ -405,12 +551,19 @@ void tty_schedule_flip(struct tty_struct *tty)
405} 551}
406EXPORT_SYMBOL(tty_schedule_flip); 552EXPORT_SYMBOL(tty_schedule_flip);
407 553
408/* 554/**
555 * tty_prepare_flip_string - make room for characters
556 * @tty: tty
557 * @chars: return pointer for character write area
558 * @size: desired size
559 *
409 * Prepare a block of space in the buffer for data. Returns the length 560 * Prepare a block of space in the buffer for data. Returns the length
410 * available and buffer pointer to the space which is now allocated and 561 * available and buffer pointer to the space which is now allocated and
411 * accounted for as ready for normal characters. This is used for drivers 562 * accounted for as ready for normal characters. This is used for drivers
412 * that need their own block copy routines into the buffer. There is no 563 * that need their own block copy routines into the buffer. There is no
413 * guarantee the buffer is a DMA target! 564 * guarantee the buffer is a DMA target!
565 *
566 * Locking: May call functions taking tty->buf.lock
414 */ 567 */
415 568
416int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, size_t size) 569int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, size_t size)
@@ -427,12 +580,20 @@ int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, size_
427 580
428EXPORT_SYMBOL_GPL(tty_prepare_flip_string); 581EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
429 582
430/* 583/**
584 * tty_prepare_flip_string_flags - make room for characters
585 * @tty: tty
586 * @chars: return pointer for character write area
587 * @flags: return pointer for status flag write area
588 * @size: desired size
589 *
431 * Prepare a block of space in the buffer for data. Returns the length 590 * Prepare a block of space in the buffer for data. Returns the length
432 * available and buffer pointer to the space which is now allocated and 591 * available and buffer pointer to the space which is now allocated and
433 * accounted for as ready for characters. This is used for drivers 592 * accounted for as ready for characters. This is used for drivers
434 * that need their own block copy routines into the buffer. There is no 593 * that need their own block copy routines into the buffer. There is no
435 * guarantee the buffer is a DMA target! 594 * guarantee the buffer is a DMA target!
595 *
596 * Locking: May call functions taking tty->buf.lock
436 */ 597 */
437 598
438int tty_prepare_flip_string_flags(struct tty_struct *tty, unsigned char **chars, char **flags, size_t size) 599int tty_prepare_flip_string_flags(struct tty_struct *tty, unsigned char **chars, char **flags, size_t size)
@@ -451,10 +612,16 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
451 612
452 613
453 614
454/* 615/**
616 * tty_set_termios_ldisc - set ldisc field
617 * @tty: tty structure
618 * @num: line discipline number
619 *
455 * This is probably overkill for real world processors but 620 * This is probably overkill for real world processors but
456 * they are not on hot paths so a little discipline won't do 621 * they are not on hot paths so a little discipline won't do
457 * any harm. 622 * any harm.
623 *
624 * Locking: takes termios_sem
458 */ 625 */
459 626
460static void tty_set_termios_ldisc(struct tty_struct *tty, int num) 627static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
@@ -474,6 +641,19 @@ static DEFINE_SPINLOCK(tty_ldisc_lock);
474static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); 641static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait);
475static struct tty_ldisc tty_ldiscs[NR_LDISCS]; /* line disc dispatch table */ 642static struct tty_ldisc tty_ldiscs[NR_LDISCS]; /* line disc dispatch table */
476 643
644/**
645 * tty_register_ldisc - install a line discipline
646 * @disc: ldisc number
647 * @new_ldisc: pointer to the ldisc object
648 *
649 * Installs a new line discipline into the kernel. The discipline
650 * is set up as unreferenced and then made available to the kernel
651 * from this point onwards.
652 *
653 * Locking:
654 * takes tty_ldisc_lock to guard against ldisc races
655 */
656
477int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc) 657int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc)
478{ 658{
479 unsigned long flags; 659 unsigned long flags;
@@ -493,6 +673,18 @@ int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc)
493} 673}
494EXPORT_SYMBOL(tty_register_ldisc); 674EXPORT_SYMBOL(tty_register_ldisc);
495 675
676/**
677 * tty_unregister_ldisc - unload a line discipline
678 * @disc: ldisc number
679 * @new_ldisc: pointer to the ldisc object
680 *
681 * Remove a line discipline from the kernel providing it is not
682 * currently in use.
683 *
684 * Locking:
685 * takes tty_ldisc_lock to guard against ldisc races
686 */
687
496int tty_unregister_ldisc(int disc) 688int tty_unregister_ldisc(int disc)
497{ 689{
498 unsigned long flags; 690 unsigned long flags;
@@ -512,6 +704,19 @@ int tty_unregister_ldisc(int disc)
512} 704}
513EXPORT_SYMBOL(tty_unregister_ldisc); 705EXPORT_SYMBOL(tty_unregister_ldisc);
514 706
707/**
708 * tty_ldisc_get - take a reference to an ldisc
709 * @disc: ldisc number
710 *
711 * Takes a reference to a line discipline. Deals with refcounts and
712 * module locking counts. Returns NULL if the discipline is not available.
713 * Returns a pointer to the discipline and bumps the ref count if it is
714 * available
715 *
716 * Locking:
717 * takes tty_ldisc_lock to guard against ldisc races
718 */
719
515struct tty_ldisc *tty_ldisc_get(int disc) 720struct tty_ldisc *tty_ldisc_get(int disc)
516{ 721{
517 unsigned long flags; 722 unsigned long flags;
@@ -540,6 +745,17 @@ struct tty_ldisc *tty_ldisc_get(int disc)
540 745
541EXPORT_SYMBOL_GPL(tty_ldisc_get); 746EXPORT_SYMBOL_GPL(tty_ldisc_get);
542 747
748/**
749 * tty_ldisc_put - drop ldisc reference
750 * @disc: ldisc number
751 *
752 * Drop a reference to a line discipline. Manage refcounts and
753 * module usage counts
754 *
755 * Locking:
756 * takes tty_ldisc_lock to guard against ldisc races
757 */
758
543void tty_ldisc_put(int disc) 759void tty_ldisc_put(int disc)
544{ 760{
545 struct tty_ldisc *ld; 761 struct tty_ldisc *ld;
@@ -557,6 +773,19 @@ void tty_ldisc_put(int disc)
557 773
558EXPORT_SYMBOL_GPL(tty_ldisc_put); 774EXPORT_SYMBOL_GPL(tty_ldisc_put);
559 775
776/**
777 * tty_ldisc_assign - set ldisc on a tty
778 * @tty: tty to assign
779 * @ld: line discipline
780 *
781 * Install an instance of a line discipline into a tty structure. The
782 * ldisc must have a reference count above zero to ensure it remains/
783 * The tty instance refcount starts at zero.
784 *
785 * Locking:
786 * Caller must hold references
787 */
788
560static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld) 789static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld)
561{ 790{
562 tty->ldisc = *ld; 791 tty->ldisc = *ld;
@@ -571,6 +800,8 @@ static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld)
571 * the tty ldisc. Return 0 on failure or 1 on success. This is 800 * the tty ldisc. Return 0 on failure or 1 on success. This is
572 * used to implement both the waiting and non waiting versions 801 * used to implement both the waiting and non waiting versions
573 * of tty_ldisc_ref 802 * of tty_ldisc_ref
803 *
804 * Locking: takes tty_ldisc_lock
574 */ 805 */
575 806
576static int tty_ldisc_try(struct tty_struct *tty) 807static int tty_ldisc_try(struct tty_struct *tty)
@@ -602,6 +833,8 @@ static int tty_ldisc_try(struct tty_struct *tty)
602 * must also be careful not to hold other locks that will deadlock 833 * must also be careful not to hold other locks that will deadlock
603 * against a discipline change, such as an existing ldisc reference 834 * against a discipline change, such as an existing ldisc reference
604 * (which we check for) 835 * (which we check for)
836 *
837 * Locking: call functions take tty_ldisc_lock
605 */ 838 */
606 839
607struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) 840struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
@@ -622,6 +855,8 @@ EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
622 * Dereference the line discipline for the terminal and take a 855 * Dereference the line discipline for the terminal and take a
623 * reference to it. If the line discipline is in flux then 856 * reference to it. If the line discipline is in flux then
624 * return NULL. Can be called from IRQ and timer functions. 857 * return NULL. Can be called from IRQ and timer functions.
858 *
859 * Locking: called functions take tty_ldisc_lock
625 */ 860 */
626 861
627struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) 862struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
@@ -639,6 +874,8 @@ EXPORT_SYMBOL_GPL(tty_ldisc_ref);
639 * 874 *
640 * Undoes the effect of tty_ldisc_ref or tty_ldisc_ref_wait. May 875 * Undoes the effect of tty_ldisc_ref or tty_ldisc_ref_wait. May
641 * be called in IRQ context. 876 * be called in IRQ context.
877 *
878 * Locking: takes tty_ldisc_lock
642 */ 879 */
643 880
644void tty_ldisc_deref(struct tty_ldisc *ld) 881void tty_ldisc_deref(struct tty_ldisc *ld)
@@ -683,6 +920,9 @@ static void tty_ldisc_enable(struct tty_struct *tty)
683 * 920 *
684 * Set the discipline of a tty line. Must be called from a process 921 * Set the discipline of a tty line. Must be called from a process
685 * context. 922 * context.
923 *
924 * Locking: takes tty_ldisc_lock.
925 * called functions take termios_sem
686 */ 926 */
687 927
688static int tty_set_ldisc(struct tty_struct *tty, int ldisc) 928static int tty_set_ldisc(struct tty_struct *tty, int ldisc)
@@ -846,9 +1086,17 @@ restart:
846 return retval; 1086 return retval;
847} 1087}
848 1088
849/* 1089/**
850 * This routine returns a tty driver structure, given a device number 1090 * get_tty_driver - find device of a tty
1091 * @dev_t: device identifier
1092 * @index: returns the index of the tty
1093 *
1094 * This routine returns a tty driver structure, given a device number
1095 * and also passes back the index number.
1096 *
1097 * Locking: caller must hold tty_mutex
851 */ 1098 */
1099
852static struct tty_driver *get_tty_driver(dev_t device, int *index) 1100static struct tty_driver *get_tty_driver(dev_t device, int *index)
853{ 1101{
854 struct tty_driver *p; 1102 struct tty_driver *p;
@@ -863,11 +1111,17 @@ static struct tty_driver *get_tty_driver(dev_t device, int *index)
863 return NULL; 1111 return NULL;
864} 1112}
865 1113
866/* 1114/**
867 * If we try to write to, or set the state of, a terminal and we're 1115 * tty_check_change - check for POSIX terminal changes
868 * not in the foreground, send a SIGTTOU. If the signal is blocked or 1116 * @tty: tty to check
869 * ignored, go ahead and perform the operation. (POSIX 7.2) 1117 *
1118 * If we try to write to, or set the state of, a terminal and we're
1119 * not in the foreground, send a SIGTTOU. If the signal is blocked or
1120 * ignored, go ahead and perform the operation. (POSIX 7.2)
1121 *
1122 * Locking: none
870 */ 1123 */
1124
871int tty_check_change(struct tty_struct * tty) 1125int tty_check_change(struct tty_struct * tty)
872{ 1126{
873 if (current->signal->tty != tty) 1127 if (current->signal->tty != tty)
@@ -912,7 +1166,7 @@ static int hung_up_tty_ioctl(struct inode * inode, struct file * file,
912 return cmd == TIOCSPGRP ? -ENOTTY : -EIO; 1166 return cmd == TIOCSPGRP ? -ENOTTY : -EIO;
913} 1167}
914 1168
915static struct file_operations tty_fops = { 1169static const struct file_operations tty_fops = {
916 .llseek = no_llseek, 1170 .llseek = no_llseek,
917 .read = tty_read, 1171 .read = tty_read,
918 .write = tty_write, 1172 .write = tty_write,
@@ -924,7 +1178,7 @@ static struct file_operations tty_fops = {
924}; 1178};
925 1179
926#ifdef CONFIG_UNIX98_PTYS 1180#ifdef CONFIG_UNIX98_PTYS
927static struct file_operations ptmx_fops = { 1181static const struct file_operations ptmx_fops = {
928 .llseek = no_llseek, 1182 .llseek = no_llseek,
929 .read = tty_read, 1183 .read = tty_read,
930 .write = tty_write, 1184 .write = tty_write,
@@ -936,7 +1190,7 @@ static struct file_operations ptmx_fops = {
936}; 1190};
937#endif 1191#endif
938 1192
939static struct file_operations console_fops = { 1193static const struct file_operations console_fops = {
940 .llseek = no_llseek, 1194 .llseek = no_llseek,
941 .read = tty_read, 1195 .read = tty_read,
942 .write = redirected_tty_write, 1196 .write = redirected_tty_write,
@@ -947,7 +1201,7 @@ static struct file_operations console_fops = {
947 .fasync = tty_fasync, 1201 .fasync = tty_fasync,
948}; 1202};
949 1203
950static struct file_operations hung_up_tty_fops = { 1204static const struct file_operations hung_up_tty_fops = {
951 .llseek = no_llseek, 1205 .llseek = no_llseek,
952 .read = hung_up_tty_read, 1206 .read = hung_up_tty_read,
953 .write = hung_up_tty_write, 1207 .write = hung_up_tty_write,
@@ -1005,10 +1259,27 @@ void tty_ldisc_flush(struct tty_struct *tty)
1005 1259
1006EXPORT_SYMBOL_GPL(tty_ldisc_flush); 1260EXPORT_SYMBOL_GPL(tty_ldisc_flush);
1007 1261
1008/* 1262/**
1009 * This can be called by the "eventd" kernel thread. That is process synchronous, 1263 * do_tty_hangup - actual handler for hangup events
1010 * but doesn't hold any locks, so we need to make sure we have the appropriate 1264 * @data: tty device
1011 * locks for what we're doing.. 1265 *
1266 * This can be called by the "eventd" kernel thread. That is process
1267 * synchronous but doesn't hold any locks, so we need to make sure we
1268 * have the appropriate locks for what we're doing.
1269 *
1270 * The hangup event clears any pending redirections onto the hung up
1271 * device. It ensures future writes will error and it does the needed
1272 * line discipline hangup and signal delivery. The tty object itself
1273 * remains intact.
1274 *
1275 * Locking:
1276 * BKL
1277 * redirect lock for undoing redirection
1278 * file list lock for manipulating list of ttys
1279 * tty_ldisc_lock from called functions
1280 * termios_sem resetting termios data
1281 * tasklist_lock to walk task list for hangup event
1282 *
1012 */ 1283 */
1013static void do_tty_hangup(void *data) 1284static void do_tty_hangup(void *data)
1014{ 1285{
@@ -1133,6 +1404,14 @@ static void do_tty_hangup(void *data)
1133 fput(f); 1404 fput(f);
1134} 1405}
1135 1406
1407/**
1408 * tty_hangup - trigger a hangup event
1409 * @tty: tty to hangup
1410 *
1411 * A carrier loss (virtual or otherwise) has occurred on this like
1412 * schedule a hangup sequence to run after this event.
1413 */
1414
1136void tty_hangup(struct tty_struct * tty) 1415void tty_hangup(struct tty_struct * tty)
1137{ 1416{
1138#ifdef TTY_DEBUG_HANGUP 1417#ifdef TTY_DEBUG_HANGUP
@@ -1145,6 +1424,15 @@ void tty_hangup(struct tty_struct * tty)
1145 1424
1146EXPORT_SYMBOL(tty_hangup); 1425EXPORT_SYMBOL(tty_hangup);
1147 1426
1427/**
1428 * tty_vhangup - process vhangup
1429 * @tty: tty to hangup
1430 *
1431 * The user has asked via system call for the terminal to be hung up.
1432 * We do this synchronously so that when the syscall returns the process
1433 * is complete. That guarantee is neccessary for security reasons.
1434 */
1435
1148void tty_vhangup(struct tty_struct * tty) 1436void tty_vhangup(struct tty_struct * tty)
1149{ 1437{
1150#ifdef TTY_DEBUG_HANGUP 1438#ifdef TTY_DEBUG_HANGUP
@@ -1156,6 +1444,14 @@ void tty_vhangup(struct tty_struct * tty)
1156} 1444}
1157EXPORT_SYMBOL(tty_vhangup); 1445EXPORT_SYMBOL(tty_vhangup);
1158 1446
1447/**
1448 * tty_hung_up_p - was tty hung up
1449 * @filp: file pointer of tty
1450 *
1451 * Return true if the tty has been subject to a vhangup or a carrier
1452 * loss
1453 */
1454
1159int tty_hung_up_p(struct file * filp) 1455int tty_hung_up_p(struct file * filp)
1160{ 1456{
1161 return (filp->f_op == &hung_up_tty_fops); 1457 return (filp->f_op == &hung_up_tty_fops);
@@ -1163,19 +1459,28 @@ int tty_hung_up_p(struct file * filp)
1163 1459
1164EXPORT_SYMBOL(tty_hung_up_p); 1460EXPORT_SYMBOL(tty_hung_up_p);
1165 1461
1166/* 1462/**
1167 * This function is typically called only by the session leader, when 1463 * disassociate_ctty - disconnect controlling tty
1168 * it wants to disassociate itself from its controlling tty. 1464 * @on_exit: true if exiting so need to "hang up" the session
1465 *
1466 * This function is typically called only by the session leader, when
1467 * it wants to disassociate itself from its controlling tty.
1169 * 1468 *
1170 * It performs the following functions: 1469 * It performs the following functions:
1171 * (1) Sends a SIGHUP and SIGCONT to the foreground process group 1470 * (1) Sends a SIGHUP and SIGCONT to the foreground process group
1172 * (2) Clears the tty from being controlling the session 1471 * (2) Clears the tty from being controlling the session
1173 * (3) Clears the controlling tty for all processes in the 1472 * (3) Clears the controlling tty for all processes in the
1174 * session group. 1473 * session group.
1175 * 1474 *
1176 * The argument on_exit is set to 1 if called when a process is 1475 * The argument on_exit is set to 1 if called when a process is
1177 * exiting; it is 0 if called by the ioctl TIOCNOTTY. 1476 * exiting; it is 0 if called by the ioctl TIOCNOTTY.
1477 *
1478 * Locking: tty_mutex is taken to protect current->signal->tty
1479 * BKL is taken for hysterical raisins
1480 * Tasklist lock is taken (under tty_mutex) to walk process
1481 * lists for the session.
1178 */ 1482 */
1483
1179void disassociate_ctty(int on_exit) 1484void disassociate_ctty(int on_exit)
1180{ 1485{
1181 struct tty_struct *tty; 1486 struct tty_struct *tty;
@@ -1222,6 +1527,25 @@ void disassociate_ctty(int on_exit)
1222 unlock_kernel(); 1527 unlock_kernel();
1223} 1528}
1224 1529
1530
1531/**
1532 * stop_tty - propogate flow control
1533 * @tty: tty to stop
1534 *
1535 * Perform flow control to the driver. For PTY/TTY pairs we
1536 * must also propogate the TIOCKPKT status. May be called
1537 * on an already stopped device and will not re-call the driver
1538 * method.
1539 *
1540 * This functionality is used by both the line disciplines for
1541 * halting incoming flow and by the driver. It may therefore be
1542 * called from any context, may be under the tty atomic_write_lock
1543 * but not always.
1544 *
1545 * Locking:
1546 * Broken. Relies on BKL which is unsafe here.
1547 */
1548
1225void stop_tty(struct tty_struct *tty) 1549void stop_tty(struct tty_struct *tty)
1226{ 1550{
1227 if (tty->stopped) 1551 if (tty->stopped)
@@ -1238,6 +1562,19 @@ void stop_tty(struct tty_struct *tty)
1238 1562
1239EXPORT_SYMBOL(stop_tty); 1563EXPORT_SYMBOL(stop_tty);
1240 1564
1565/**
1566 * start_tty - propogate flow control
1567 * @tty: tty to start
1568 *
1569 * Start a tty that has been stopped if at all possible. Perform
1570 * any neccessary wakeups and propogate the TIOCPKT status. If this
1571 * is the tty was previous stopped and is being started then the
1572 * driver start method is invoked and the line discipline woken.
1573 *
1574 * Locking:
1575 * Broken. Relies on BKL which is unsafe here.
1576 */
1577
1241void start_tty(struct tty_struct *tty) 1578void start_tty(struct tty_struct *tty)
1242{ 1579{
1243 if (!tty->stopped || tty->flow_stopped) 1580 if (!tty->stopped || tty->flow_stopped)
@@ -1258,6 +1595,23 @@ void start_tty(struct tty_struct *tty)
1258 1595
1259EXPORT_SYMBOL(start_tty); 1596EXPORT_SYMBOL(start_tty);
1260 1597
1598/**
1599 * tty_read - read method for tty device files
1600 * @file: pointer to tty file
1601 * @buf: user buffer
1602 * @count: size of user buffer
1603 * @ppos: unused
1604 *
1605 * Perform the read system call function on this terminal device. Checks
1606 * for hung up devices before calling the line discipline method.
1607 *
1608 * Locking:
1609 * Locks the line discipline internally while needed
1610 * For historical reasons the line discipline read method is
1611 * invoked under the BKL. This will go away in time so do not rely on it
1612 * in new code. Multiple read calls may be outstanding in parallel.
1613 */
1614
1261static ssize_t tty_read(struct file * file, char __user * buf, size_t count, 1615static ssize_t tty_read(struct file * file, char __user * buf, size_t count,
1262 loff_t *ppos) 1616 loff_t *ppos)
1263{ 1617{
@@ -1302,6 +1656,7 @@ static inline ssize_t do_tty_write(
1302 ssize_t ret = 0, written = 0; 1656 ssize_t ret = 0, written = 0;
1303 unsigned int chunk; 1657 unsigned int chunk;
1304 1658
1659 /* FIXME: O_NDELAY ... */
1305 if (mutex_lock_interruptible(&tty->atomic_write_lock)) { 1660 if (mutex_lock_interruptible(&tty->atomic_write_lock)) {
1306 return -ERESTARTSYS; 1661 return -ERESTARTSYS;
1307 } 1662 }
@@ -1318,6 +1673,9 @@ static inline ssize_t do_tty_write(
1318 * layer has problems with bigger chunks. It will 1673 * layer has problems with bigger chunks. It will
1319 * claim to be able to handle more characters than 1674 * claim to be able to handle more characters than
1320 * it actually does. 1675 * it actually does.
1676 *
1677 * FIXME: This can probably go away now except that 64K chunks
1678 * are too likely to fail unless switched to vmalloc...
1321 */ 1679 */
1322 chunk = 2048; 1680 chunk = 2048;
1323 if (test_bit(TTY_NO_WRITE_SPLIT, &tty->flags)) 1681 if (test_bit(TTY_NO_WRITE_SPLIT, &tty->flags))
@@ -1375,6 +1733,24 @@ static inline ssize_t do_tty_write(
1375} 1733}
1376 1734
1377 1735
1736/**
1737 * tty_write - write method for tty device file
1738 * @file: tty file pointer
1739 * @buf: user data to write
1740 * @count: bytes to write
1741 * @ppos: unused
1742 *
1743 * Write data to a tty device via the line discipline.
1744 *
1745 * Locking:
1746 * Locks the line discipline as required
1747 * Writes to the tty driver are serialized by the atomic_write_lock
1748 * and are then processed in chunks to the device. The line discipline
1749 * write method will not be involked in parallel for each device
1750 * The line discipline write method is called under the big
1751 * kernel lock for historical reasons. New code should not rely on this.
1752 */
1753
1378static ssize_t tty_write(struct file * file, const char __user * buf, size_t count, 1754static ssize_t tty_write(struct file * file, const char __user * buf, size_t count,
1379 loff_t *ppos) 1755 loff_t *ppos)
1380{ 1756{
@@ -1422,7 +1798,18 @@ ssize_t redirected_tty_write(struct file * file, const char __user * buf, size_t
1422 1798
1423static char ptychar[] = "pqrstuvwxyzabcde"; 1799static char ptychar[] = "pqrstuvwxyzabcde";
1424 1800
1425static inline void pty_line_name(struct tty_driver *driver, int index, char *p) 1801/**
1802 * pty_line_name - generate name for a pty
1803 * @driver: the tty driver in use
1804 * @index: the minor number
1805 * @p: output buffer of at least 6 bytes
1806 *
1807 * Generate a name from a driver reference and write it to the output
1808 * buffer.
1809 *
1810 * Locking: None
1811 */
1812static void pty_line_name(struct tty_driver *driver, int index, char *p)
1426{ 1813{
1427 int i = index + driver->name_base; 1814 int i = index + driver->name_base;
1428 /* ->name is initialized to "ttyp", but "tty" is expected */ 1815 /* ->name is initialized to "ttyp", but "tty" is expected */
@@ -1431,24 +1818,53 @@ static inline void pty_line_name(struct tty_driver *driver, int index, char *p)
1431 ptychar[i >> 4 & 0xf], i & 0xf); 1818 ptychar[i >> 4 & 0xf], i & 0xf);
1432} 1819}
1433 1820
1434static inline void tty_line_name(struct tty_driver *driver, int index, char *p) 1821/**
1822 * pty_line_name - generate name for a tty
1823 * @driver: the tty driver in use
1824 * @index: the minor number
1825 * @p: output buffer of at least 7 bytes
1826 *
1827 * Generate a name from a driver reference and write it to the output
1828 * buffer.
1829 *
1830 * Locking: None
1831 */
1832static void tty_line_name(struct tty_driver *driver, int index, char *p)
1435{ 1833{
1436 sprintf(p, "%s%d", driver->name, index + driver->name_base); 1834 sprintf(p, "%s%d", driver->name, index + driver->name_base);
1437} 1835}
1438 1836
1439/* 1837/**
1838 * init_dev - initialise a tty device
1839 * @driver: tty driver we are opening a device on
1840 * @idx: device index
1841 * @tty: returned tty structure
1842 *
1843 * Prepare a tty device. This may not be a "new" clean device but
1844 * could also be an active device. The pty drivers require special
1845 * handling because of this.
1846 *
1847 * Locking:
1848 * The function is called under the tty_mutex, which
1849 * protects us from the tty struct or driver itself going away.
1850 *
1851 * On exit the tty device has the line discipline attached and
1852 * a reference count of 1. If a pair was created for pty/tty use
1853 * and the other was a pty master then it too has a reference count of 1.
1854 *
1440 * WSH 06/09/97: Rewritten to remove races and properly clean up after a 1855 * WSH 06/09/97: Rewritten to remove races and properly clean up after a
1441 * failed open. The new code protects the open with a mutex, so it's 1856 * failed open. The new code protects the open with a mutex, so it's
1442 * really quite straightforward. The mutex locking can probably be 1857 * really quite straightforward. The mutex locking can probably be
1443 * relaxed for the (most common) case of reopening a tty. 1858 * relaxed for the (most common) case of reopening a tty.
1444 */ 1859 */
1860
1445static int init_dev(struct tty_driver *driver, int idx, 1861static int init_dev(struct tty_driver *driver, int idx,
1446 struct tty_struct **ret_tty) 1862 struct tty_struct **ret_tty)
1447{ 1863{
1448 struct tty_struct *tty, *o_tty; 1864 struct tty_struct *tty, *o_tty;
1449 struct termios *tp, **tp_loc, *o_tp, **o_tp_loc; 1865 struct termios *tp, **tp_loc, *o_tp, **o_tp_loc;
1450 struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc; 1866 struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
1451 int retval=0; 1867 int retval = 0;
1452 1868
1453 /* check whether we're reopening an existing tty */ 1869 /* check whether we're reopening an existing tty */
1454 if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { 1870 if (driver->flags & TTY_DRIVER_DEVPTS_MEM) {
@@ -1662,10 +2078,20 @@ release_mem_out:
1662 goto end_init; 2078 goto end_init;
1663} 2079}
1664 2080
1665/* 2081/**
1666 * Releases memory associated with a tty structure, and clears out the 2082 * release_mem - release tty structure memory
1667 * driver table slots. 2083 *
2084 * Releases memory associated with a tty structure, and clears out the
2085 * driver table slots. This function is called when a device is no longer
2086 * in use. It also gets called when setup of a device fails.
2087 *
2088 * Locking:
2089 * tty_mutex - sometimes only
2090 * takes the file list lock internally when working on the list
2091 * of ttys that the driver keeps.
2092 * FIXME: should we require tty_mutex is held here ??
1668 */ 2093 */
2094
1669static void release_mem(struct tty_struct *tty, int idx) 2095static void release_mem(struct tty_struct *tty, int idx)
1670{ 2096{
1671 struct tty_struct *o_tty; 2097 struct tty_struct *o_tty;
@@ -2006,18 +2432,27 @@ static void release_dev(struct file * filp)
2006 2432
2007} 2433}
2008 2434
2009/* 2435/**
2010 * tty_open and tty_release keep up the tty count that contains the 2436 * tty_open - open a tty device
2011 * number of opens done on a tty. We cannot use the inode-count, as 2437 * @inode: inode of device file
2012 * different inodes might point to the same tty. 2438 * @filp: file pointer to tty
2439 *
2440 * tty_open and tty_release keep up the tty count that contains the
2441 * number of opens done on a tty. We cannot use the inode-count, as
2442 * different inodes might point to the same tty.
2443 *
2444 * Open-counting is needed for pty masters, as well as for keeping
2445 * track of serial lines: DTR is dropped when the last close happens.
2446 * (This is not done solely through tty->count, now. - Ted 1/27/92)
2013 * 2447 *
2014 * Open-counting is needed for pty masters, as well as for keeping 2448 * The termios state of a pty is reset on first open so that
2015 * track of serial lines: DTR is dropped when the last close happens. 2449 * settings don't persist across reuse.
2016 * (This is not done solely through tty->count, now. - Ted 1/27/92)
2017 * 2450 *
2018 * The termios state of a pty is reset on first open so that 2451 * Locking: tty_mutex protects current->signal->tty, get_tty_driver and
2019 * settings don't persist across reuse. 2452 * init_dev work. tty->count should protect the rest.
2453 * task_lock is held to update task details for sessions
2020 */ 2454 */
2455
2021static int tty_open(struct inode * inode, struct file * filp) 2456static int tty_open(struct inode * inode, struct file * filp)
2022{ 2457{
2023 struct tty_struct *tty; 2458 struct tty_struct *tty;
@@ -2132,6 +2567,18 @@ got_driver:
2132} 2567}
2133 2568
2134#ifdef CONFIG_UNIX98_PTYS 2569#ifdef CONFIG_UNIX98_PTYS
2570/**
2571 * ptmx_open - open a unix 98 pty master
2572 * @inode: inode of device file
2573 * @filp: file pointer to tty
2574 *
2575 * Allocate a unix98 pty master device from the ptmx driver.
2576 *
2577 * Locking: tty_mutex protects theinit_dev work. tty->count should
2578 protect the rest.
2579 * allocated_ptys_lock handles the list of free pty numbers
2580 */
2581
2135static int ptmx_open(struct inode * inode, struct file * filp) 2582static int ptmx_open(struct inode * inode, struct file * filp)
2136{ 2583{
2137 struct tty_struct *tty; 2584 struct tty_struct *tty;
@@ -2191,6 +2638,18 @@ out:
2191} 2638}
2192#endif 2639#endif
2193 2640
2641/**
2642 * tty_release - vfs callback for close
2643 * @inode: inode of tty
2644 * @filp: file pointer for handle to tty
2645 *
2646 * Called the last time each file handle is closed that references
2647 * this tty. There may however be several such references.
2648 *
2649 * Locking:
2650 * Takes bkl. See release_dev
2651 */
2652
2194static int tty_release(struct inode * inode, struct file * filp) 2653static int tty_release(struct inode * inode, struct file * filp)
2195{ 2654{
2196 lock_kernel(); 2655 lock_kernel();
@@ -2199,7 +2658,18 @@ static int tty_release(struct inode * inode, struct file * filp)
2199 return 0; 2658 return 0;
2200} 2659}
2201 2660
2202/* No kernel lock held - fine */ 2661/**
2662 * tty_poll - check tty status
2663 * @filp: file being polled
2664 * @wait: poll wait structures to update
2665 *
2666 * Call the line discipline polling method to obtain the poll
2667 * status of the device.
2668 *
2669 * Locking: locks called line discipline but ldisc poll method
2670 * may be re-entered freely by other callers.
2671 */
2672
2203static unsigned int tty_poll(struct file * filp, poll_table * wait) 2673static unsigned int tty_poll(struct file * filp, poll_table * wait)
2204{ 2674{
2205 struct tty_struct * tty; 2675 struct tty_struct * tty;
@@ -2243,6 +2713,21 @@ static int tty_fasync(int fd, struct file * filp, int on)
2243 return 0; 2713 return 0;
2244} 2714}
2245 2715
2716/**
2717 * tiocsti - fake input character
2718 * @tty: tty to fake input into
2719 * @p: pointer to character
2720 *
2721 * Fake input to a tty device. Does the neccessary locking and
2722 * input management.
2723 *
2724 * FIXME: does not honour flow control ??
2725 *
2726 * Locking:
2727 * Called functions take tty_ldisc_lock
2728 * current->signal->tty check is safe without locks
2729 */
2730
2246static int tiocsti(struct tty_struct *tty, char __user *p) 2731static int tiocsti(struct tty_struct *tty, char __user *p)
2247{ 2732{
2248 char ch, mbz = 0; 2733 char ch, mbz = 0;
@@ -2258,6 +2743,18 @@ static int tiocsti(struct tty_struct *tty, char __user *p)
2258 return 0; 2743 return 0;
2259} 2744}
2260 2745
2746/**
2747 * tiocgwinsz - implement window query ioctl
2748 * @tty; tty
2749 * @arg: user buffer for result
2750 *
2751 * Copies the kernel idea of the window size into the user buffer. No
2752 * locking is done.
2753 *
2754 * FIXME: Returning random values racing a window size set is wrong
2755 * should lock here against that
2756 */
2757
2261static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg) 2758static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg)
2262{ 2759{
2263 if (copy_to_user(arg, &tty->winsize, sizeof(*arg))) 2760 if (copy_to_user(arg, &tty->winsize, sizeof(*arg)))
@@ -2265,6 +2762,24 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg)
2265 return 0; 2762 return 0;
2266} 2763}
2267 2764
2765/**
2766 * tiocswinsz - implement window size set ioctl
2767 * @tty; tty
2768 * @arg: user buffer for result
2769 *
2770 * Copies the user idea of the window size to the kernel. Traditionally
2771 * this is just advisory information but for the Linux console it
2772 * actually has driver level meaning and triggers a VC resize.
2773 *
2774 * Locking:
2775 * The console_sem is used to ensure we do not try and resize
2776 * the console twice at once.
2777 * FIXME: Two racing size sets may leave the console and kernel
2778 * parameters disagreeing. Is this exploitable ?
2779 * FIXME: Random values racing a window size get is wrong
2780 * should lock here against that
2781 */
2782
2268static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty, 2783static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
2269 struct winsize __user * arg) 2784 struct winsize __user * arg)
2270{ 2785{
@@ -2294,6 +2809,15 @@ static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
2294 return 0; 2809 return 0;
2295} 2810}
2296 2811
2812/**
2813 * tioccons - allow admin to move logical console
2814 * @file: the file to become console
2815 *
2816 * Allow the adminstrator to move the redirected console device
2817 *
2818 * Locking: uses redirect_lock to guard the redirect information
2819 */
2820
2297static int tioccons(struct file *file) 2821static int tioccons(struct file *file)
2298{ 2822{
2299 if (!capable(CAP_SYS_ADMIN)) 2823 if (!capable(CAP_SYS_ADMIN))
@@ -2319,6 +2843,17 @@ static int tioccons(struct file *file)
2319 return 0; 2843 return 0;
2320} 2844}
2321 2845
2846/**
2847 * fionbio - non blocking ioctl
2848 * @file: file to set blocking value
2849 * @p: user parameter
2850 *
2851 * Historical tty interfaces had a blocking control ioctl before
2852 * the generic functionality existed. This piece of history is preserved
2853 * in the expected tty API of posix OS's.
2854 *
2855 * Locking: none, the open fle handle ensures it won't go away.
2856 */
2322 2857
2323static int fionbio(struct file *file, int __user *p) 2858static int fionbio(struct file *file, int __user *p)
2324{ 2859{
@@ -2334,9 +2869,26 @@ static int fionbio(struct file *file, int __user *p)
2334 return 0; 2869 return 0;
2335} 2870}
2336 2871
2872/**
2873 * tiocsctty - set controlling tty
2874 * @tty: tty structure
2875 * @arg: user argument
2876 *
2877 * This ioctl is used to manage job control. It permits a session
2878 * leader to set this tty as the controlling tty for the session.
2879 *
2880 * Locking:
2881 * Takes tasklist lock internally to walk sessions
2882 * Takes task_lock() when updating signal->tty
2883 *
2884 * FIXME: tty_mutex is needed to protect signal->tty references.
2885 * FIXME: why task_lock on the signal->tty reference ??
2886 *
2887 */
2888
2337static int tiocsctty(struct tty_struct *tty, int arg) 2889static int tiocsctty(struct tty_struct *tty, int arg)
2338{ 2890{
2339 task_t *p; 2891 struct task_struct *p;
2340 2892
2341 if (current->signal->leader && 2893 if (current->signal->leader &&
2342 (current->signal->session == tty->session)) 2894 (current->signal->session == tty->session))
@@ -2374,6 +2926,18 @@ static int tiocsctty(struct tty_struct *tty, int arg)
2374 return 0; 2926 return 0;
2375} 2927}
2376 2928
2929/**
2930 * tiocgpgrp - get process group
2931 * @tty: tty passed by user
2932 * @real_tty: tty side of the tty pased by the user if a pty else the tty
2933 * @p: returned pid
2934 *
2935 * Obtain the process group of the tty. If there is no process group
2936 * return an error.
2937 *
2938 * Locking: none. Reference to ->signal->tty is safe.
2939 */
2940
2377static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) 2941static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
2378{ 2942{
2379 /* 2943 /*
@@ -2385,6 +2949,20 @@ static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
2385 return put_user(real_tty->pgrp, p); 2949 return put_user(real_tty->pgrp, p);
2386} 2950}
2387 2951
2952/**
2953 * tiocspgrp - attempt to set process group
2954 * @tty: tty passed by user
2955 * @real_tty: tty side device matching tty passed by user
2956 * @p: pid pointer
2957 *
2958 * Set the process group of the tty to the session passed. Only
2959 * permitted where the tty session is our session.
2960 *
2961 * Locking: None
2962 *
2963 * FIXME: current->signal->tty referencing is unsafe.
2964 */
2965
2388static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) 2966static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
2389{ 2967{
2390 pid_t pgrp; 2968 pid_t pgrp;
@@ -2408,6 +2986,18 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
2408 return 0; 2986 return 0;
2409} 2987}
2410 2988
2989/**
2990 * tiocgsid - get session id
2991 * @tty: tty passed by user
2992 * @real_tty: tty side of the tty pased by the user if a pty else the tty
2993 * @p: pointer to returned session id
2994 *
2995 * Obtain the session id of the tty. If there is no session
2996 * return an error.
2997 *
2998 * Locking: none. Reference to ->signal->tty is safe.
2999 */
3000
2411static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) 3001static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
2412{ 3002{
2413 /* 3003 /*
@@ -2421,6 +3011,16 @@ static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t _
2421 return put_user(real_tty->session, p); 3011 return put_user(real_tty->session, p);
2422} 3012}
2423 3013
3014/**
3015 * tiocsetd - set line discipline
3016 * @tty: tty device
3017 * @p: pointer to user data
3018 *
3019 * Set the line discipline according to user request.
3020 *
3021 * Locking: see tty_set_ldisc, this function is just a helper
3022 */
3023
2424static int tiocsetd(struct tty_struct *tty, int __user *p) 3024static int tiocsetd(struct tty_struct *tty, int __user *p)
2425{ 3025{
2426 int ldisc; 3026 int ldisc;
@@ -2430,6 +3030,21 @@ static int tiocsetd(struct tty_struct *tty, int __user *p)
2430 return tty_set_ldisc(tty, ldisc); 3030 return tty_set_ldisc(tty, ldisc);
2431} 3031}
2432 3032
3033/**
3034 * send_break - performed time break
3035 * @tty: device to break on
3036 * @duration: timeout in mS
3037 *
3038 * Perform a timed break on hardware that lacks its own driver level
3039 * timed break functionality.
3040 *
3041 * Locking:
3042 * None
3043 *
3044 * FIXME:
3045 * What if two overlap
3046 */
3047
2433static int send_break(struct tty_struct *tty, unsigned int duration) 3048static int send_break(struct tty_struct *tty, unsigned int duration)
2434{ 3049{
2435 tty->driver->break_ctl(tty, -1); 3050 tty->driver->break_ctl(tty, -1);
@@ -2442,8 +3057,19 @@ static int send_break(struct tty_struct *tty, unsigned int duration)
2442 return 0; 3057 return 0;
2443} 3058}
2444 3059
2445static int 3060/**
2446tty_tiocmget(struct tty_struct *tty, struct file *file, int __user *p) 3061 * tiocmget - get modem status
3062 * @tty: tty device
3063 * @file: user file pointer
3064 * @p: pointer to result
3065 *
3066 * Obtain the modem status bits from the tty driver if the feature
3067 * is supported. Return -EINVAL if it is not available.
3068 *
3069 * Locking: none (up to the driver)
3070 */
3071
3072static int tty_tiocmget(struct tty_struct *tty, struct file *file, int __user *p)
2447{ 3073{
2448 int retval = -EINVAL; 3074 int retval = -EINVAL;
2449 3075
@@ -2456,8 +3082,20 @@ tty_tiocmget(struct tty_struct *tty, struct file *file, int __user *p)
2456 return retval; 3082 return retval;
2457} 3083}
2458 3084
2459static int 3085/**
2460tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int cmd, 3086 * tiocmset - set modem status
3087 * @tty: tty device
3088 * @file: user file pointer
3089 * @cmd: command - clear bits, set bits or set all
3090 * @p: pointer to desired bits
3091 *
3092 * Set the modem status bits from the tty driver if the feature
3093 * is supported. Return -EINVAL if it is not available.
3094 *
3095 * Locking: none (up to the driver)
3096 */
3097
3098static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int cmd,
2461 unsigned __user *p) 3099 unsigned __user *p)
2462{ 3100{
2463 int retval = -EINVAL; 3101 int retval = -EINVAL;
@@ -2573,6 +3211,7 @@ int tty_ioctl(struct inode * inode, struct file * file,
2573 clear_bit(TTY_EXCLUSIVE, &tty->flags); 3211 clear_bit(TTY_EXCLUSIVE, &tty->flags);
2574 return 0; 3212 return 0;
2575 case TIOCNOTTY: 3213 case TIOCNOTTY:
3214 /* FIXME: taks lock or tty_mutex ? */
2576 if (current->signal->tty != tty) 3215 if (current->signal->tty != tty)
2577 return -ENOTTY; 3216 return -ENOTTY;
2578 if (current->signal->leader) 3217 if (current->signal->leader)
@@ -2753,9 +3392,16 @@ void do_SAK(struct tty_struct *tty)
2753 3392
2754EXPORT_SYMBOL(do_SAK); 3393EXPORT_SYMBOL(do_SAK);
2755 3394
2756/* 3395/**
2757 * This routine is called out of the software interrupt to flush data 3396 * flush_to_ldisc
2758 * from the buffer chain to the line discipline. 3397 * @private_: tty structure passed from work queue.
3398 *
3399 * This routine is called out of the software interrupt to flush data
3400 * from the buffer chain to the line discipline.
3401 *
3402 * Locking: holds tty->buf.lock to guard buffer list. Drops the lock
3403 * while invoking the line discipline receive_buf method. The
3404 * receive_buf method is single threaded for each tty instance.
2759 */ 3405 */
2760 3406
2761static void flush_to_ldisc(void *private_) 3407static void flush_to_ldisc(void *private_)
@@ -2831,6 +3477,8 @@ static int n_baud_table = ARRAY_SIZE(baud_table);
2831 * Convert termios baud rate data into a speed. This should be called 3477 * Convert termios baud rate data into a speed. This should be called
2832 * with the termios lock held if this termios is a terminal termios 3478 * with the termios lock held if this termios is a terminal termios
2833 * structure. May change the termios data. 3479 * structure. May change the termios data.
3480 *
3481 * Locking: none
2834 */ 3482 */
2835 3483
2836int tty_termios_baud_rate(struct termios *termios) 3484int tty_termios_baud_rate(struct termios *termios)
@@ -2859,6 +3507,8 @@ EXPORT_SYMBOL(tty_termios_baud_rate);
2859 * Returns the baud rate as an integer for this terminal. The 3507 * Returns the baud rate as an integer for this terminal. The
2860 * termios lock must be held by the caller and the terminal bit 3508 * termios lock must be held by the caller and the terminal bit
2861 * flags may be updated. 3509 * flags may be updated.
3510 *
3511 * Locking: none
2862 */ 3512 */
2863 3513
2864int tty_get_baud_rate(struct tty_struct *tty) 3514int tty_get_baud_rate(struct tty_struct *tty)
@@ -2888,6 +3538,8 @@ EXPORT_SYMBOL(tty_get_baud_rate);
2888 * 3538 *
2889 * In the event of the queue being busy for flipping the work will be 3539 * In the event of the queue being busy for flipping the work will be
2890 * held off and retried later. 3540 * held off and retried later.
3541 *
3542 * Locking: tty buffer lock. Driver locks in low latency mode.
2891 */ 3543 */
2892 3544
2893void tty_flip_buffer_push(struct tty_struct *tty) 3545void tty_flip_buffer_push(struct tty_struct *tty)
@@ -2907,9 +3559,16 @@ void tty_flip_buffer_push(struct tty_struct *tty)
2907EXPORT_SYMBOL(tty_flip_buffer_push); 3559EXPORT_SYMBOL(tty_flip_buffer_push);
2908 3560
2909 3561
2910/* 3562/**
2911 * This subroutine initializes a tty structure. 3563 * initialize_tty_struct
3564 * @tty: tty to initialize
3565 *
3566 * This subroutine initializes a tty structure that has been newly
3567 * allocated.
3568 *
3569 * Locking: none - tty in question must not be exposed at this point
2912 */ 3570 */
3571
2913static void initialize_tty_struct(struct tty_struct *tty) 3572static void initialize_tty_struct(struct tty_struct *tty)
2914{ 3573{
2915 memset(tty, 0, sizeof(struct tty_struct)); 3574 memset(tty, 0, sizeof(struct tty_struct));
@@ -2935,6 +3594,7 @@ static void initialize_tty_struct(struct tty_struct *tty)
2935/* 3594/*
2936 * The default put_char routine if the driver did not define one. 3595 * The default put_char routine if the driver did not define one.
2937 */ 3596 */
3597
2938static void tty_default_put_char(struct tty_struct *tty, unsigned char ch) 3598static void tty_default_put_char(struct tty_struct *tty, unsigned char ch)
2939{ 3599{
2940 tty->driver->write(tty, &ch, 1); 3600 tty->driver->write(tty, &ch, 1);
@@ -2943,19 +3603,23 @@ static void tty_default_put_char(struct tty_struct *tty, unsigned char ch)
2943static struct class *tty_class; 3603static struct class *tty_class;
2944 3604
2945/** 3605/**
2946 * tty_register_device - register a tty device 3606 * tty_register_device - register a tty device
2947 * @driver: the tty driver that describes the tty device 3607 * @driver: the tty driver that describes the tty device
2948 * @index: the index in the tty driver for this tty device 3608 * @index: the index in the tty driver for this tty device
2949 * @device: a struct device that is associated with this tty device. 3609 * @device: a struct device that is associated with this tty device.
2950 * This field is optional, if there is no known struct device for this 3610 * This field is optional, if there is no known struct device
2951 * tty device it can be set to NULL safely. 3611 * for this tty device it can be set to NULL safely.
2952 * 3612 *
2953 * Returns a pointer to the class device (or ERR_PTR(-EFOO) on error). 3613 * Returns a pointer to the class device (or ERR_PTR(-EFOO) on error).
2954 * 3614 *
2955 * This call is required to be made to register an individual tty device if 3615 * This call is required to be made to register an individual tty device
2956 * the tty driver's flags have the TTY_DRIVER_DYNAMIC_DEV bit set. If that 3616 * if the tty driver's flags have the TTY_DRIVER_DYNAMIC_DEV bit set. If
2957 * bit is not set, this function should not be called by a tty driver. 3617 * that bit is not set, this function should not be called by a tty
3618 * driver.
3619 *
3620 * Locking: ??
2958 */ 3621 */
3622
2959struct class_device *tty_register_device(struct tty_driver *driver, 3623struct class_device *tty_register_device(struct tty_driver *driver,
2960 unsigned index, struct device *device) 3624 unsigned index, struct device *device)
2961{ 3625{
@@ -2977,13 +3641,16 @@ struct class_device *tty_register_device(struct tty_driver *driver,
2977} 3641}
2978 3642
2979/** 3643/**
2980 * tty_unregister_device - unregister a tty device 3644 * tty_unregister_device - unregister a tty device
2981 * @driver: the tty driver that describes the tty device 3645 * @driver: the tty driver that describes the tty device
2982 * @index: the index in the tty driver for this tty device 3646 * @index: the index in the tty driver for this tty device
2983 * 3647 *
2984 * If a tty device is registered with a call to tty_register_device() then 3648 * If a tty device is registered with a call to tty_register_device() then
2985 * this function must be made when the tty device is gone. 3649 * this function must be called when the tty device is gone.
3650 *
3651 * Locking: ??
2986 */ 3652 */
3653
2987void tty_unregister_device(struct tty_driver *driver, unsigned index) 3654void tty_unregister_device(struct tty_driver *driver, unsigned index)
2988{ 3655{
2989 class_device_destroy(tty_class, MKDEV(driver->major, driver->minor_start) + index); 3656 class_device_destroy(tty_class, MKDEV(driver->major, driver->minor_start) + index);
@@ -3094,7 +3761,6 @@ int tty_register_driver(struct tty_driver *driver)
3094 driver->cdev.owner = driver->owner; 3761 driver->cdev.owner = driver->owner;
3095 error = cdev_add(&driver->cdev, dev, driver->num); 3762 error = cdev_add(&driver->cdev, dev, driver->num);
3096 if (error) { 3763 if (error) {
3097 cdev_del(&driver->cdev);
3098 unregister_chrdev_region(dev, driver->num); 3764 unregister_chrdev_region(dev, driver->num);
3099 driver->ttys = NULL; 3765 driver->ttys = NULL;
3100 driver->termios = driver->termios_locked = NULL; 3766 driver->termios = driver->termios_locked = NULL;
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index f19cf9d7792d..4ad47d321bd4 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -36,6 +36,18 @@
36#define TERMIOS_WAIT 2 36#define TERMIOS_WAIT 2
37#define TERMIOS_TERMIO 4 37#define TERMIOS_TERMIO 4
38 38
39
40/**
41 * tty_wait_until_sent - wait for I/O to finish
42 * @tty: tty we are waiting for
43 * @timeout: how long we will wait
44 *
45 * Wait for characters pending in a tty driver to hit the wire, or
46 * for a timeout to occur (eg due to flow control)
47 *
48 * Locking: none
49 */
50
39void tty_wait_until_sent(struct tty_struct * tty, long timeout) 51void tty_wait_until_sent(struct tty_struct * tty, long timeout)
40{ 52{
41 DECLARE_WAITQUEUE(wait, current); 53 DECLARE_WAITQUEUE(wait, current);
@@ -94,6 +106,18 @@ static void unset_locked_termios(struct termios *termios,
94 old->c_cc[i] : termios->c_cc[i]; 106 old->c_cc[i] : termios->c_cc[i];
95} 107}
96 108
109/**
110 * change_termios - update termios values
111 * @tty: tty to update
112 * @new_termios: desired new value
113 *
114 * Perform updates to the termios values set on this terminal. There
115 * is a bit of layering violation here with n_tty in terms of the
116 * internal knowledge of this function.
117 *
118 * Locking: termios_sem
119 */
120
97static void change_termios(struct tty_struct * tty, struct termios * new_termios) 121static void change_termios(struct tty_struct * tty, struct termios * new_termios)
98{ 122{
99 int canon_change; 123 int canon_change;
@@ -155,6 +179,19 @@ static void change_termios(struct tty_struct * tty, struct termios * new_termios
155 up(&tty->termios_sem); 179 up(&tty->termios_sem);
156} 180}
157 181
182/**
183 * set_termios - set termios values for a tty
184 * @tty: terminal device
185 * @arg: user data
186 * @opt: option information
187 *
188 * Helper function to prepare termios data and run neccessary other
189 * functions before using change_termios to do the actual changes.
190 *
191 * Locking:
192 * Called functions take ldisc and termios_sem locks
193 */
194
158static int set_termios(struct tty_struct * tty, void __user *arg, int opt) 195static int set_termios(struct tty_struct * tty, void __user *arg, int opt)
159{ 196{
160 struct termios tmp_termios; 197 struct termios tmp_termios;
@@ -284,6 +321,17 @@ static void set_sgflags(struct termios * termios, int flags)
284 } 321 }
285} 322}
286 323
324/**
325 * set_sgttyb - set legacy terminal values
326 * @tty: tty structure
327 * @sgttyb: pointer to old style terminal structure
328 *
329 * Updates a terminal from the legacy BSD style terminal information
330 * structure.
331 *
332 * Locking: termios_sem
333 */
334
287static int set_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb) 335static int set_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
288{ 336{
289 int retval; 337 int retval;
@@ -369,9 +417,16 @@ static int set_ltchars(struct tty_struct * tty, struct ltchars __user * ltchars)
369} 417}
370#endif 418#endif
371 419
372/* 420/**
373 * Send a high priority character to the tty. 421 * send_prio_char - send priority character
422 *
423 * Send a high priority character to the tty even if stopped
424 *
425 * Locking: none
426 *
427 * FIXME: overlapping calls with start/stop tty lose state of tty
374 */ 428 */
429
375static void send_prio_char(struct tty_struct *tty, char ch) 430static void send_prio_char(struct tty_struct *tty, char ch)
376{ 431{
377 int was_stopped = tty->stopped; 432 int was_stopped = tty->stopped;
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index 45e9bd81bc0e..a9247b5213d5 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -465,7 +465,7 @@ vcs_open(struct inode *inode, struct file *filp)
465 return 0; 465 return 0;
466} 466}
467 467
468static struct file_operations vcs_fops = { 468static const struct file_operations vcs_fops = {
469 .llseek = vcs_lseek, 469 .llseek = vcs_lseek,
470 .read = vcs_read, 470 .read = vcs_read,
471 .write = vcs_write, 471 .write = vcs_write,
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index 7d42c8ec8dbc..b72b2049aaae 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -292,7 +292,7 @@ static int proc_viotape_open(struct inode *inode, struct file *file)
292 return single_open(file, proc_viotape_show, NULL); 292 return single_open(file, proc_viotape_show, NULL);
293} 293}
294 294
295static struct file_operations proc_viotape_operations = { 295static const struct file_operations proc_viotape_operations = {
296 .open = proc_viotape_open, 296 .open = proc_viotape_open,
297 .read = seq_read, 297 .read = seq_read,
298 .llseek = seq_lseek, 298 .llseek = seq_lseek,
diff --git a/drivers/char/vr41xx_giu.c b/drivers/char/vr41xx_giu.c
index 073da48c092e..8116a47b80f4 100644
--- a/drivers/char/vr41xx_giu.c
+++ b/drivers/char/vr41xx_giu.c
@@ -33,6 +33,7 @@
33#include <asm/cpu.h> 33#include <asm/cpu.h>
34#include <asm/io.h> 34#include <asm/io.h>
35#include <asm/vr41xx/giu.h> 35#include <asm/vr41xx/giu.h>
36#include <asm/vr41xx/irq.h>
36#include <asm/vr41xx/vr41xx.h> 37#include <asm/vr41xx/vr41xx.h>
37 38
38MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>"); 39MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>");
@@ -605,7 +606,7 @@ static int gpio_release(struct inode *inode, struct file *file)
605 return 0; 606 return 0;
606} 607}
607 608
608static struct file_operations gpio_fops = { 609static const struct file_operations gpio_fops = {
609 .owner = THIS_MODULE, 610 .owner = THIS_MODULE,
610 .read = gpio_read, 611 .read = gpio_read,
611 .write = gpio_write, 612 .write = gpio_write,
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 3ef823d7d255..da7e66a2a38b 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -886,6 +886,7 @@ void vc_disallocate(unsigned int currcons)
886 if (vc_cons_allocated(currcons)) { 886 if (vc_cons_allocated(currcons)) {
887 struct vc_data *vc = vc_cons[currcons].d; 887 struct vc_data *vc = vc_cons[currcons].d;
888 vc->vc_sw->con_deinit(vc); 888 vc->vc_sw->con_deinit(vc);
889 module_put(vc->vc_sw->owner);
889 if (vc->vc_kmalloced) 890 if (vc->vc_kmalloced)
890 kfree(vc->vc_screenbuf); 891 kfree(vc->vc_screenbuf);
891 if (currcons >= MIN_NR_CONSOLES) 892 if (currcons >= MIN_NR_CONSOLES)
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index eccffaf26faa..a5628a8b6620 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -1011,6 +1011,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
1011 return -EPERM; 1011 return -EPERM;
1012 vt_dont_switch = 0; 1012 vt_dont_switch = 0;
1013 return 0; 1013 return 0;
1014 case VT_GETHIFONTMASK:
1015 return put_user(vc->vc_hi_font_mask, (unsigned short __user *)arg);
1014 default: 1016 default:
1015 return -ENOIOCTLCMD; 1017 return -ENOIOCTLCMD;
1016 } 1018 }
diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig
index d53f664a4dd8..fff89c2d88fd 100644
--- a/drivers/char/watchdog/Kconfig
+++ b/drivers/char/watchdog/Kconfig
@@ -45,7 +45,7 @@ config WATCHDOG_NOWAYOUT
45comment "Watchdog Device Drivers" 45comment "Watchdog Device Drivers"
46 depends on WATCHDOG 46 depends on WATCHDOG
47 47
48# Architecture Independant 48# Architecture Independent
49 49
50config SOFT_WATCHDOG 50config SOFT_WATCHDOG
51 tristate "Software watchdog" 51 tristate "Software watchdog"
@@ -127,7 +127,7 @@ config S3C2410_WATCHDOG
127 enabled. 127 enabled.
128 128
129 The driver is limited by the speed of the system's PCLK 129 The driver is limited by the speed of the system's PCLK
130 signal, so with reasonbaly fast systems (PCLK around 50-66MHz) 130 signal, so with reasonably fast systems (PCLK around 50-66MHz)
131 then watchdog intervals of over approximately 20seconds are 131 then watchdog intervals of over approximately 20seconds are
132 unavailable. 132 unavailable.
133 133
@@ -423,7 +423,7 @@ config SBC_EPX_C3_WATCHDOG
423 is no way to know if writing to its IO address will corrupt 423 is no way to know if writing to its IO address will corrupt
424 your system or have any real effect. The only way to be sure 424 your system or have any real effect. The only way to be sure
425 that this driver does what you want is to make sure you 425 that this driver does what you want is to make sure you
426 are runnning it on an EPX-C3 from Winsystems with the watchdog 426 are running it on an EPX-C3 from Winsystems with the watchdog
427 timer at IO address 0x1ee and 0x1ef. It will write to both those 427 timer at IO address 0x1ee and 0x1ef. It will write to both those
428 IO ports. Basically, the assumption is made that if you compile 428 IO ports. Basically, the assumption is made that if you compile
429 this driver into your kernel and/or load it as a module, that you 429 this driver into your kernel and/or load it as a module, that you
@@ -472,7 +472,7 @@ config INDYDOG
472 tristate "Indy/I2 Hardware Watchdog" 472 tristate "Indy/I2 Hardware Watchdog"
473 depends on WATCHDOG && SGI_IP22 473 depends on WATCHDOG && SGI_IP22
474 help 474 help
475 Hardwaredriver for the Indy's/I2's watchdog. This is a 475 Hardware driver for the Indy's/I2's watchdog. This is a
476 watchdog timer that will reboot the machine after a 60 second 476 watchdog timer that will reboot the machine after a 60 second
477 timer expired and no process has written to /dev/watchdog during 477 timer expired and no process has written to /dev/watchdog during
478 that time. 478 that time.
diff --git a/drivers/char/watchdog/acquirewdt.c b/drivers/char/watchdog/acquirewdt.c
index 7289f4af93d0..c77fe3cf2852 100644
--- a/drivers/char/watchdog/acquirewdt.c
+++ b/drivers/char/watchdog/acquirewdt.c
@@ -231,7 +231,7 @@ static int acq_notify_sys(struct notifier_block *this, unsigned long code,
231 * Kernel Interfaces 231 * Kernel Interfaces
232 */ 232 */
233 233
234static struct file_operations acq_fops = { 234static const struct file_operations acq_fops = {
235 .owner = THIS_MODULE, 235 .owner = THIS_MODULE,
236 .llseek = no_llseek, 236 .llseek = no_llseek,
237 .write = acq_write, 237 .write = acq_write,
diff --git a/drivers/char/watchdog/advantechwdt.c b/drivers/char/watchdog/advantechwdt.c
index 194a3fd36b91..8069be445edc 100644
--- a/drivers/char/watchdog/advantechwdt.c
+++ b/drivers/char/watchdog/advantechwdt.c
@@ -227,7 +227,7 @@ advwdt_notify_sys(struct notifier_block *this, unsigned long code,
227 * Kernel Interfaces 227 * Kernel Interfaces
228 */ 228 */
229 229
230static struct file_operations advwdt_fops = { 230static const struct file_operations advwdt_fops = {
231 .owner = THIS_MODULE, 231 .owner = THIS_MODULE,
232 .llseek = no_llseek, 232 .llseek = no_llseek,
233 .write = advwdt_write, 233 .write = advwdt_write,
diff --git a/drivers/char/watchdog/alim1535_wdt.c b/drivers/char/watchdog/alim1535_wdt.c
index 8338ca300e2e..c5c94e4c9495 100644
--- a/drivers/char/watchdog/alim1535_wdt.c
+++ b/drivers/char/watchdog/alim1535_wdt.c
@@ -362,7 +362,7 @@ static int __init ali_find_watchdog(void)
362 * Kernel Interfaces 362 * Kernel Interfaces
363 */ 363 */
364 364
365static struct file_operations ali_fops = { 365static const struct file_operations ali_fops = {
366 .owner = THIS_MODULE, 366 .owner = THIS_MODULE,
367 .llseek = no_llseek, 367 .llseek = no_llseek,
368 .write = ali_write, 368 .write = ali_write,
diff --git a/drivers/char/watchdog/alim7101_wdt.c b/drivers/char/watchdog/alim7101_wdt.c
index c05ac188a4d7..ffd7684f999b 100644
--- a/drivers/char/watchdog/alim7101_wdt.c
+++ b/drivers/char/watchdog/alim7101_wdt.c
@@ -281,7 +281,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
281 } 281 }
282} 282}
283 283
284static struct file_operations wdt_fops = { 284static const struct file_operations wdt_fops = {
285 .owner= THIS_MODULE, 285 .owner= THIS_MODULE,
286 .llseek= no_llseek, 286 .llseek= no_llseek,
287 .write= fop_write, 287 .write= fop_write,
diff --git a/drivers/char/watchdog/at91_wdt.c b/drivers/char/watchdog/at91_wdt.c
index f61dedc3c96c..cc266715ea32 100644
--- a/drivers/char/watchdog/at91_wdt.c
+++ b/drivers/char/watchdog/at91_wdt.c
@@ -183,7 +183,7 @@ static ssize_t at91_wdt_write(struct file *file, const char *data, size_t len, l
183 183
184/* ......................................................................... */ 184/* ......................................................................... */
185 185
186static struct file_operations at91wdt_fops = { 186static const struct file_operations at91wdt_fops = {
187 .owner = THIS_MODULE, 187 .owner = THIS_MODULE,
188 .llseek = no_llseek, 188 .llseek = no_llseek,
189 .ioctl = at91_wdt_ioctl, 189 .ioctl = at91_wdt_ioctl,
diff --git a/drivers/char/watchdog/booke_wdt.c b/drivers/char/watchdog/booke_wdt.c
index 537f5c6729bf..e3cefc538b40 100644
--- a/drivers/char/watchdog/booke_wdt.c
+++ b/drivers/char/watchdog/booke_wdt.c
@@ -145,7 +145,7 @@ static int booke_wdt_open (struct inode *inode, struct file *file)
145 return 0; 145 return 0;
146} 146}
147 147
148static struct file_operations booke_wdt_fops = { 148static const struct file_operations booke_wdt_fops = {
149 .owner = THIS_MODULE, 149 .owner = THIS_MODULE,
150 .llseek = no_llseek, 150 .llseek = no_llseek,
151 .write = booke_wdt_write, 151 .write = booke_wdt_write,
diff --git a/drivers/char/watchdog/cpu5wdt.c b/drivers/char/watchdog/cpu5wdt.c
index 3e8410b5a65e..04c7e49918db 100644
--- a/drivers/char/watchdog/cpu5wdt.c
+++ b/drivers/char/watchdog/cpu5wdt.c
@@ -198,7 +198,7 @@ static ssize_t cpu5wdt_write(struct file *file, const char __user *buf, size_t c
198 return count; 198 return count;
199} 199}
200 200
201static struct file_operations cpu5wdt_fops = { 201static const struct file_operations cpu5wdt_fops = {
202 .owner = THIS_MODULE, 202 .owner = THIS_MODULE,
203 .llseek = no_llseek, 203 .llseek = no_llseek,
204 .ioctl = cpu5wdt_ioctl, 204 .ioctl = cpu5wdt_ioctl,
diff --git a/drivers/char/watchdog/ep93xx_wdt.c b/drivers/char/watchdog/ep93xx_wdt.c
index 9021dbb78299..77c8a955ae9e 100644
--- a/drivers/char/watchdog/ep93xx_wdt.c
+++ b/drivers/char/watchdog/ep93xx_wdt.c
@@ -187,7 +187,7 @@ static int ep93xx_wdt_release(struct inode *inode, struct file *file)
187 return 0; 187 return 0;
188} 188}
189 189
190static struct file_operations ep93xx_wdt_fops = { 190static const struct file_operations ep93xx_wdt_fops = {
191 .owner = THIS_MODULE, 191 .owner = THIS_MODULE,
192 .write = ep93xx_wdt_write, 192 .write = ep93xx_wdt_write,
193 .ioctl = ep93xx_wdt_ioctl, 193 .ioctl = ep93xx_wdt_ioctl,
diff --git a/drivers/char/watchdog/eurotechwdt.c b/drivers/char/watchdog/eurotechwdt.c
index ea670de4fab7..62dbccb2f6df 100644
--- a/drivers/char/watchdog/eurotechwdt.c
+++ b/drivers/char/watchdog/eurotechwdt.c
@@ -356,7 +356,7 @@ static int eurwdt_notify_sys(struct notifier_block *this, unsigned long code,
356 */ 356 */
357 357
358 358
359static struct file_operations eurwdt_fops = { 359static const struct file_operations eurwdt_fops = {
360 .owner = THIS_MODULE, 360 .owner = THIS_MODULE,
361 .llseek = no_llseek, 361 .llseek = no_llseek,
362 .write = eurwdt_write, 362 .write = eurwdt_write,
diff --git a/drivers/char/watchdog/i6300esb.c b/drivers/char/watchdog/i6300esb.c
index 93785f13242e..870539eabbf3 100644
--- a/drivers/char/watchdog/i6300esb.c
+++ b/drivers/char/watchdog/i6300esb.c
@@ -337,7 +337,7 @@ static int esb_notify_sys (struct notifier_block *this, unsigned long code, void
337 * Kernel Interfaces 337 * Kernel Interfaces
338 */ 338 */
339 339
340static struct file_operations esb_fops = { 340static const struct file_operations esb_fops = {
341 .owner = THIS_MODULE, 341 .owner = THIS_MODULE,
342 .llseek = no_llseek, 342 .llseek = no_llseek,
343 .write = esb_write, 343 .write = esb_write,
diff --git a/drivers/char/watchdog/i8xx_tco.c b/drivers/char/watchdog/i8xx_tco.c
index bfbdbbf3c2f2..8385dd36eefe 100644
--- a/drivers/char/watchdog/i8xx_tco.c
+++ b/drivers/char/watchdog/i8xx_tco.c
@@ -378,7 +378,7 @@ static int i8xx_tco_notify_sys (struct notifier_block *this, unsigned long code,
378 * Kernel Interfaces 378 * Kernel Interfaces
379 */ 379 */
380 380
381static struct file_operations i8xx_tco_fops = { 381static const struct file_operations i8xx_tco_fops = {
382 .owner = THIS_MODULE, 382 .owner = THIS_MODULE,
383 .llseek = no_llseek, 383 .llseek = no_llseek,
384 .write = i8xx_tco_write, 384 .write = i8xx_tco_write,
diff --git a/drivers/char/watchdog/ib700wdt.c b/drivers/char/watchdog/ib700wdt.c
index a2e53c715b36..fd95f7327798 100644
--- a/drivers/char/watchdog/ib700wdt.c
+++ b/drivers/char/watchdog/ib700wdt.c
@@ -255,7 +255,7 @@ ibwdt_notify_sys(struct notifier_block *this, unsigned long code,
255 * Kernel Interfaces 255 * Kernel Interfaces
256 */ 256 */
257 257
258static struct file_operations ibwdt_fops = { 258static const struct file_operations ibwdt_fops = {
259 .owner = THIS_MODULE, 259 .owner = THIS_MODULE,
260 .llseek = no_llseek, 260 .llseek = no_llseek,
261 .write = ibwdt_write, 261 .write = ibwdt_write,
diff --git a/drivers/char/watchdog/ibmasr.c b/drivers/char/watchdog/ibmasr.c
index b0741cbdc139..26ceee7a4df0 100644
--- a/drivers/char/watchdog/ibmasr.c
+++ b/drivers/char/watchdog/ibmasr.c
@@ -322,7 +322,7 @@ static int asr_release(struct inode *inode, struct file *file)
322 return 0; 322 return 0;
323} 323}
324 324
325static struct file_operations asr_fops = { 325static const struct file_operations asr_fops = {
326 .owner = THIS_MODULE, 326 .owner = THIS_MODULE,
327 .llseek = no_llseek, 327 .llseek = no_llseek,
328 .write = asr_write, 328 .write = asr_write,
diff --git a/drivers/char/watchdog/indydog.c b/drivers/char/watchdog/indydog.c
index d387979b2434..dacc1c20a310 100644
--- a/drivers/char/watchdog/indydog.c
+++ b/drivers/char/watchdog/indydog.c
@@ -154,7 +154,7 @@ static int indydog_notify_sys(struct notifier_block *this, unsigned long code, v
154 return NOTIFY_DONE; 154 return NOTIFY_DONE;
155} 155}
156 156
157static struct file_operations indydog_fops = { 157static const struct file_operations indydog_fops = {
158 .owner = THIS_MODULE, 158 .owner = THIS_MODULE,
159 .llseek = no_llseek, 159 .llseek = no_llseek,
160 .write = indydog_write, 160 .write = indydog_write,
diff --git a/drivers/char/watchdog/ixp2000_wdt.c b/drivers/char/watchdog/ixp2000_wdt.c
index aa29a7d68759..692908819e26 100644
--- a/drivers/char/watchdog/ixp2000_wdt.c
+++ b/drivers/char/watchdog/ixp2000_wdt.c
@@ -168,7 +168,7 @@ ixp2000_wdt_release(struct inode *inode, struct file *file)
168} 168}
169 169
170 170
171static struct file_operations ixp2000_wdt_fops = 171static const struct file_operations ixp2000_wdt_fops =
172{ 172{
173 .owner = THIS_MODULE, 173 .owner = THIS_MODULE,
174 .llseek = no_llseek, 174 .llseek = no_llseek,
diff --git a/drivers/char/watchdog/ixp4xx_wdt.c b/drivers/char/watchdog/ixp4xx_wdt.c
index e6a3fe83fa01..9db5cf2c38c3 100644
--- a/drivers/char/watchdog/ixp4xx_wdt.c
+++ b/drivers/char/watchdog/ixp4xx_wdt.c
@@ -162,7 +162,7 @@ ixp4xx_wdt_release(struct inode *inode, struct file *file)
162} 162}
163 163
164 164
165static struct file_operations ixp4xx_wdt_fops = 165static const struct file_operations ixp4xx_wdt_fops =
166{ 166{
167 .owner = THIS_MODULE, 167 .owner = THIS_MODULE,
168 .llseek = no_llseek, 168 .llseek = no_llseek,
diff --git a/drivers/char/watchdog/machzwd.c b/drivers/char/watchdog/machzwd.c
index b67b4878ae0f..23734e07fb22 100644
--- a/drivers/char/watchdog/machzwd.c
+++ b/drivers/char/watchdog/machzwd.c
@@ -388,7 +388,7 @@ static int zf_notify_sys(struct notifier_block *this, unsigned long code,
388 388
389 389
390 390
391static struct file_operations zf_fops = { 391static const struct file_operations zf_fops = {
392 .owner = THIS_MODULE, 392 .owner = THIS_MODULE,
393 .llseek = no_llseek, 393 .llseek = no_llseek,
394 .write = zf_write, 394 .write = zf_write,
diff --git a/drivers/char/watchdog/mixcomwd.c b/drivers/char/watchdog/mixcomwd.c
index 433c27f98159..ae943324d251 100644
--- a/drivers/char/watchdog/mixcomwd.c
+++ b/drivers/char/watchdog/mixcomwd.c
@@ -190,7 +190,7 @@ static int mixcomwd_ioctl(struct inode *inode, struct file *file,
190 return 0; 190 return 0;
191} 191}
192 192
193static struct file_operations mixcomwd_fops= 193static const struct file_operations mixcomwd_fops=
194{ 194{
195 .owner = THIS_MODULE, 195 .owner = THIS_MODULE,
196 .llseek = no_llseek, 196 .llseek = no_llseek,
diff --git a/drivers/char/watchdog/mpc83xx_wdt.c b/drivers/char/watchdog/mpc83xx_wdt.c
index dac1381af364..a480903ee1a5 100644
--- a/drivers/char/watchdog/mpc83xx_wdt.c
+++ b/drivers/char/watchdog/mpc83xx_wdt.c
@@ -129,7 +129,7 @@ static int mpc83xx_wdt_ioctl(struct inode *inode, struct file *file,
129 } 129 }
130} 130}
131 131
132static struct file_operations mpc83xx_wdt_fops = { 132static const struct file_operations mpc83xx_wdt_fops = {
133 .owner = THIS_MODULE, 133 .owner = THIS_MODULE,
134 .llseek = no_llseek, 134 .llseek = no_llseek,
135 .write = mpc83xx_wdt_write, 135 .write = mpc83xx_wdt_write,
diff --git a/drivers/char/watchdog/mpc8xx_wdt.c b/drivers/char/watchdog/mpc8xx_wdt.c
index 11f0ccd4c4d4..35dd9e6e1140 100644
--- a/drivers/char/watchdog/mpc8xx_wdt.c
+++ b/drivers/char/watchdog/mpc8xx_wdt.c
@@ -132,7 +132,7 @@ static int mpc8xx_wdt_ioctl(struct inode *inode, struct file *file,
132 return 0; 132 return 0;
133} 133}
134 134
135static struct file_operations mpc8xx_wdt_fops = { 135static const struct file_operations mpc8xx_wdt_fops = {
136 .owner = THIS_MODULE, 136 .owner = THIS_MODULE,
137 .llseek = no_llseek, 137 .llseek = no_llseek,
138 .write = mpc8xx_wdt_write, 138 .write = mpc8xx_wdt_write,
diff --git a/drivers/char/watchdog/mpcore_wdt.c b/drivers/char/watchdog/mpcore_wdt.c
index c2d492c852fc..54b3c56ead0d 100644
--- a/drivers/char/watchdog/mpcore_wdt.c
+++ b/drivers/char/watchdog/mpcore_wdt.c
@@ -297,7 +297,7 @@ static void mpcore_wdt_shutdown(struct platform_device *dev)
297/* 297/*
298 * Kernel Interfaces 298 * Kernel Interfaces
299 */ 299 */
300static struct file_operations mpcore_wdt_fops = { 300static const struct file_operations mpcore_wdt_fops = {
301 .owner = THIS_MODULE, 301 .owner = THIS_MODULE,
302 .llseek = no_llseek, 302 .llseek = no_llseek,
303 .write = mpcore_wdt_write, 303 .write = mpcore_wdt_write,
diff --git a/drivers/char/watchdog/mv64x60_wdt.c b/drivers/char/watchdog/mv64x60_wdt.c
index 20a6cbb0fbb8..5c8fab345b40 100644
--- a/drivers/char/watchdog/mv64x60_wdt.c
+++ b/drivers/char/watchdog/mv64x60_wdt.c
@@ -166,7 +166,7 @@ static int mv64x60_wdt_ioctl(struct inode *inode, struct file *file,
166 return 0; 166 return 0;
167} 167}
168 168
169static struct file_operations mv64x60_wdt_fops = { 169static const struct file_operations mv64x60_wdt_fops = {
170 .owner = THIS_MODULE, 170 .owner = THIS_MODULE,
171 .llseek = no_llseek, 171 .llseek = no_llseek,
172 .write = mv64x60_wdt_write, 172 .write = mv64x60_wdt_write,
diff --git a/drivers/char/watchdog/pcwd.c b/drivers/char/watchdog/pcwd.c
index 6d44ca68312d..cd7d1b6a5d9f 100644
--- a/drivers/char/watchdog/pcwd.c
+++ b/drivers/char/watchdog/pcwd.c
@@ -740,7 +740,7 @@ static int pcwd_notify_sys(struct notifier_block *this, unsigned long code, void
740 * Kernel Interfaces 740 * Kernel Interfaces
741 */ 741 */
742 742
743static struct file_operations pcwd_fops = { 743static const struct file_operations pcwd_fops = {
744 .owner = THIS_MODULE, 744 .owner = THIS_MODULE,
745 .llseek = no_llseek, 745 .llseek = no_llseek,
746 .write = pcwd_write, 746 .write = pcwd_write,
@@ -755,7 +755,7 @@ static struct miscdevice pcwd_miscdev = {
755 .fops = &pcwd_fops, 755 .fops = &pcwd_fops,
756}; 756};
757 757
758static struct file_operations pcwd_temp_fops = { 758static const struct file_operations pcwd_temp_fops = {
759 .owner = THIS_MODULE, 759 .owner = THIS_MODULE,
760 .llseek = no_llseek, 760 .llseek = no_llseek,
761 .read = pcwd_temp_read, 761 .read = pcwd_temp_read,
diff --git a/drivers/char/watchdog/pcwd_pci.c b/drivers/char/watchdog/pcwd_pci.c
index 1f40ecefbf72..c7cfd6dbfe1b 100644
--- a/drivers/char/watchdog/pcwd_pci.c
+++ b/drivers/char/watchdog/pcwd_pci.c
@@ -625,7 +625,7 @@ static int pcipcwd_notify_sys(struct notifier_block *this, unsigned long code, v
625 * Kernel Interfaces 625 * Kernel Interfaces
626 */ 626 */
627 627
628static struct file_operations pcipcwd_fops = { 628static const struct file_operations pcipcwd_fops = {
629 .owner = THIS_MODULE, 629 .owner = THIS_MODULE,
630 .llseek = no_llseek, 630 .llseek = no_llseek,
631 .write = pcipcwd_write, 631 .write = pcipcwd_write,
@@ -640,7 +640,7 @@ static struct miscdevice pcipcwd_miscdev = {
640 .fops = &pcipcwd_fops, 640 .fops = &pcipcwd_fops,
641}; 641};
642 642
643static struct file_operations pcipcwd_temp_fops = { 643static const struct file_operations pcipcwd_temp_fops = {
644 .owner = THIS_MODULE, 644 .owner = THIS_MODULE,
645 .llseek = no_llseek, 645 .llseek = no_llseek,
646 .read = pcipcwd_temp_read, 646 .read = pcipcwd_temp_read,
diff --git a/drivers/char/watchdog/pcwd_usb.c b/drivers/char/watchdog/pcwd_usb.c
index 92bf8c1a0f0d..b7ae73dcdd08 100644
--- a/drivers/char/watchdog/pcwd_usb.c
+++ b/drivers/char/watchdog/pcwd_usb.c
@@ -523,7 +523,7 @@ static int usb_pcwd_notify_sys(struct notifier_block *this, unsigned long code,
523 * Kernel Interfaces 523 * Kernel Interfaces
524 */ 524 */
525 525
526static struct file_operations usb_pcwd_fops = { 526static const struct file_operations usb_pcwd_fops = {
527 .owner = THIS_MODULE, 527 .owner = THIS_MODULE,
528 .llseek = no_llseek, 528 .llseek = no_llseek,
529 .write = usb_pcwd_write, 529 .write = usb_pcwd_write,
@@ -538,7 +538,7 @@ static struct miscdevice usb_pcwd_miscdev = {
538 .fops = &usb_pcwd_fops, 538 .fops = &usb_pcwd_fops,
539}; 539};
540 540
541static struct file_operations usb_pcwd_temperature_fops = { 541static const struct file_operations usb_pcwd_temperature_fops = {
542 .owner = THIS_MODULE, 542 .owner = THIS_MODULE,
543 .llseek = no_llseek, 543 .llseek = no_llseek,
544 .read = usb_pcwd_temperature_read, 544 .read = usb_pcwd_temperature_read,
diff --git a/drivers/char/watchdog/s3c2410_wdt.c b/drivers/char/watchdog/s3c2410_wdt.c
index f267dad26071..be978e8ed754 100644
--- a/drivers/char/watchdog/s3c2410_wdt.c
+++ b/drivers/char/watchdog/s3c2410_wdt.c
@@ -319,7 +319,7 @@ static int s3c2410wdt_ioctl(struct inode *inode, struct file *file,
319 319
320/* kernel interface */ 320/* kernel interface */
321 321
322static struct file_operations s3c2410wdt_fops = { 322static const struct file_operations s3c2410wdt_fops = {
323 .owner = THIS_MODULE, 323 .owner = THIS_MODULE,
324 .llseek = no_llseek, 324 .llseek = no_llseek,
325 .write = s3c2410wdt_write, 325 .write = s3c2410wdt_write,
diff --git a/drivers/char/watchdog/sa1100_wdt.c b/drivers/char/watchdog/sa1100_wdt.c
index b22e95c5470c..1fc16d995788 100644
--- a/drivers/char/watchdog/sa1100_wdt.c
+++ b/drivers/char/watchdog/sa1100_wdt.c
@@ -135,7 +135,7 @@ static int sa1100dog_ioctl(struct inode *inode, struct file *file,
135 return ret; 135 return ret;
136} 136}
137 137
138static struct file_operations sa1100dog_fops = 138static const struct file_operations sa1100dog_fops =
139{ 139{
140 .owner = THIS_MODULE, 140 .owner = THIS_MODULE,
141 .llseek = no_llseek, 141 .llseek = no_llseek,
diff --git a/drivers/char/watchdog/sbc60xxwdt.c b/drivers/char/watchdog/sbc60xxwdt.c
index ed0bd55fbfc1..4663c2fd53cd 100644
--- a/drivers/char/watchdog/sbc60xxwdt.c
+++ b/drivers/char/watchdog/sbc60xxwdt.c
@@ -282,7 +282,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
282 } 282 }
283} 283}
284 284
285static struct file_operations wdt_fops = { 285static const struct file_operations wdt_fops = {
286 .owner = THIS_MODULE, 286 .owner = THIS_MODULE,
287 .llseek = no_llseek, 287 .llseek = no_llseek,
288 .write = fop_write, 288 .write = fop_write,
diff --git a/drivers/char/watchdog/sbc8360.c b/drivers/char/watchdog/sbc8360.c
index 6562aa910ace..41fc6f80c493 100644
--- a/drivers/char/watchdog/sbc8360.c
+++ b/drivers/char/watchdog/sbc8360.c
@@ -200,7 +200,7 @@ static int wd_margin = 0xB;
200static int wd_multiplier = 2; 200static int wd_multiplier = 2;
201static int nowayout = WATCHDOG_NOWAYOUT; 201static int nowayout = WATCHDOG_NOWAYOUT;
202 202
203module_param(timeout, int, 27); 203module_param(timeout, int, 0);
204MODULE_PARM_DESC(timeout, "Index into timeout table (0-63) (default=27 (60s))"); 204MODULE_PARM_DESC(timeout, "Index into timeout table (0-63) (default=27 (60s))");
205module_param(nowayout, int, 0); 205module_param(nowayout, int, 0);
206MODULE_PARM_DESC(nowayout, 206MODULE_PARM_DESC(nowayout,
@@ -305,7 +305,7 @@ static int sbc8360_notify_sys(struct notifier_block *this, unsigned long code,
305 * Kernel Interfaces 305 * Kernel Interfaces
306 */ 306 */
307 307
308static struct file_operations sbc8360_fops = { 308static const struct file_operations sbc8360_fops = {
309 .owner = THIS_MODULE, 309 .owner = THIS_MODULE,
310 .llseek = no_llseek, 310 .llseek = no_llseek,
311 .write = sbc8360_write, 311 .write = sbc8360_write,
@@ -407,7 +407,7 @@ module_exit(sbc8360_exit);
407MODULE_AUTHOR("Ian E. Morgan <imorgan@webcon.ca>"); 407MODULE_AUTHOR("Ian E. Morgan <imorgan@webcon.ca>");
408MODULE_DESCRIPTION("SBC8360 watchdog driver"); 408MODULE_DESCRIPTION("SBC8360 watchdog driver");
409MODULE_LICENSE("GPL"); 409MODULE_LICENSE("GPL");
410MODULE_VERSION("1.0"); 410MODULE_VERSION("1.01");
411MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); 411MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
412 412
413/* end of sbc8360.c */ 413/* end of sbc8360.c */
diff --git a/drivers/char/watchdog/sbc_epx_c3.c b/drivers/char/watchdog/sbc_epx_c3.c
index 09867fadc720..bfc475dabe6d 100644
--- a/drivers/char/watchdog/sbc_epx_c3.c
+++ b/drivers/char/watchdog/sbc_epx_c3.c
@@ -154,7 +154,7 @@ static int epx_c3_notify_sys(struct notifier_block *this, unsigned long code,
154 return NOTIFY_DONE; 154 return NOTIFY_DONE;
155} 155}
156 156
157static struct file_operations epx_c3_fops = { 157static const struct file_operations epx_c3_fops = {
158 .owner = THIS_MODULE, 158 .owner = THIS_MODULE,
159 .llseek = no_llseek, 159 .llseek = no_llseek,
160 .write = epx_c3_write, 160 .write = epx_c3_write,
diff --git a/drivers/char/watchdog/sc1200wdt.c b/drivers/char/watchdog/sc1200wdt.c
index 78ef6333c181..7c3cf293a5af 100644
--- a/drivers/char/watchdog/sc1200wdt.c
+++ b/drivers/char/watchdog/sc1200wdt.c
@@ -292,7 +292,7 @@ static struct notifier_block sc1200wdt_notifier =
292 .notifier_call = sc1200wdt_notify_sys, 292 .notifier_call = sc1200wdt_notify_sys,
293}; 293};
294 294
295static struct file_operations sc1200wdt_fops = 295static const struct file_operations sc1200wdt_fops =
296{ 296{
297 .owner = THIS_MODULE, 297 .owner = THIS_MODULE,
298 .llseek = no_llseek, 298 .llseek = no_llseek,
diff --git a/drivers/char/watchdog/sc520_wdt.c b/drivers/char/watchdog/sc520_wdt.c
index 4ee9974ad8cb..2c7c9db71be8 100644
--- a/drivers/char/watchdog/sc520_wdt.c
+++ b/drivers/char/watchdog/sc520_wdt.c
@@ -336,7 +336,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
336 } 336 }
337} 337}
338 338
339static struct file_operations wdt_fops = { 339static const struct file_operations wdt_fops = {
340 .owner = THIS_MODULE, 340 .owner = THIS_MODULE,
341 .llseek = no_llseek, 341 .llseek = no_llseek,
342 .write = fop_write, 342 .write = fop_write,
diff --git a/drivers/char/watchdog/scx200_wdt.c b/drivers/char/watchdog/scx200_wdt.c
index c0b4754e8de0..c561299a5537 100644
--- a/drivers/char/watchdog/scx200_wdt.c
+++ b/drivers/char/watchdog/scx200_wdt.c
@@ -194,7 +194,7 @@ static int scx200_wdt_ioctl(struct inode *inode, struct file *file,
194 } 194 }
195} 195}
196 196
197static struct file_operations scx200_wdt_fops = { 197static const struct file_operations scx200_wdt_fops = {
198 .owner = THIS_MODULE, 198 .owner = THIS_MODULE,
199 .llseek = no_llseek, 199 .llseek = no_llseek,
200 .write = scx200_wdt_write, 200 .write = scx200_wdt_write,
diff --git a/drivers/char/watchdog/shwdt.c b/drivers/char/watchdog/shwdt.c
index 803701b675c0..1355038f1044 100644
--- a/drivers/char/watchdog/shwdt.c
+++ b/drivers/char/watchdog/shwdt.c
@@ -344,7 +344,7 @@ static int sh_wdt_notify_sys(struct notifier_block *this,
344 return NOTIFY_DONE; 344 return NOTIFY_DONE;
345} 345}
346 346
347static struct file_operations sh_wdt_fops = { 347static const struct file_operations sh_wdt_fops = {
348 .owner = THIS_MODULE, 348 .owner = THIS_MODULE,
349 .llseek = no_llseek, 349 .llseek = no_llseek,
350 .write = sh_wdt_write, 350 .write = sh_wdt_write,
diff --git a/drivers/char/watchdog/softdog.c b/drivers/char/watchdog/softdog.c
index 79ce5c655428..ef8da517545a 100644
--- a/drivers/char/watchdog/softdog.c
+++ b/drivers/char/watchdog/softdog.c
@@ -243,7 +243,7 @@ static int softdog_notify_sys(struct notifier_block *this, unsigned long code,
243 * Kernel Interfaces 243 * Kernel Interfaces
244 */ 244 */
245 245
246static struct file_operations softdog_fops = { 246static const struct file_operations softdog_fops = {
247 .owner = THIS_MODULE, 247 .owner = THIS_MODULE,
248 .llseek = no_llseek, 248 .llseek = no_llseek,
249 .write = softdog_write, 249 .write = softdog_write,
diff --git a/drivers/char/watchdog/w83627hf_wdt.c b/drivers/char/watchdog/w83627hf_wdt.c
index d15ca9a3986f..13f16d41c2fd 100644
--- a/drivers/char/watchdog/w83627hf_wdt.c
+++ b/drivers/char/watchdog/w83627hf_wdt.c
@@ -274,7 +274,7 @@ wdt_notify_sys(struct notifier_block *this, unsigned long code,
274 * Kernel Interfaces 274 * Kernel Interfaces
275 */ 275 */
276 276
277static struct file_operations wdt_fops = { 277static const struct file_operations wdt_fops = {
278 .owner = THIS_MODULE, 278 .owner = THIS_MODULE,
279 .llseek = no_llseek, 279 .llseek = no_llseek,
280 .write = wdt_write, 280 .write = wdt_write,
diff --git a/drivers/char/watchdog/w83877f_wdt.c b/drivers/char/watchdog/w83877f_wdt.c
index 52a8bd0a5988..ccf6c0915945 100644
--- a/drivers/char/watchdog/w83877f_wdt.c
+++ b/drivers/char/watchdog/w83877f_wdt.c
@@ -299,7 +299,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
299 } 299 }
300} 300}
301 301
302static struct file_operations wdt_fops = { 302static const struct file_operations wdt_fops = {
303 .owner = THIS_MODULE, 303 .owner = THIS_MODULE,
304 .llseek = no_llseek, 304 .llseek = no_llseek,
305 .write = fop_write, 305 .write = fop_write,
diff --git a/drivers/char/watchdog/w83977f_wdt.c b/drivers/char/watchdog/w83977f_wdt.c
index c31849e4c5c2..98f4e17db70a 100644
--- a/drivers/char/watchdog/w83977f_wdt.c
+++ b/drivers/char/watchdog/w83977f_wdt.c
@@ -449,7 +449,7 @@ static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
449 return NOTIFY_DONE; 449 return NOTIFY_DONE;
450} 450}
451 451
452static struct file_operations wdt_fops= 452static const struct file_operations wdt_fops=
453{ 453{
454 .owner = THIS_MODULE, 454 .owner = THIS_MODULE,
455 .llseek = no_llseek, 455 .llseek = no_llseek,
diff --git a/drivers/char/watchdog/wafer5823wdt.c b/drivers/char/watchdog/wafer5823wdt.c
index 7cf6c9bbf486..2bb6a9d6ad28 100644
--- a/drivers/char/watchdog/wafer5823wdt.c
+++ b/drivers/char/watchdog/wafer5823wdt.c
@@ -222,7 +222,7 @@ static int wafwdt_notify_sys(struct notifier_block *this, unsigned long code, vo
222 * Kernel Interfaces 222 * Kernel Interfaces
223 */ 223 */
224 224
225static struct file_operations wafwdt_fops = { 225static const struct file_operations wafwdt_fops = {
226 .owner = THIS_MODULE, 226 .owner = THIS_MODULE,
227 .llseek = no_llseek, 227 .llseek = no_llseek,
228 .write = wafwdt_write, 228 .write = wafwdt_write,
diff --git a/drivers/char/watchdog/wdrtas.c b/drivers/char/watchdog/wdrtas.c
index 3a462c34b92a..5c38cdf41731 100644
--- a/drivers/char/watchdog/wdrtas.c
+++ b/drivers/char/watchdog/wdrtas.c
@@ -520,7 +520,7 @@ wdrtas_reboot(struct notifier_block *this, unsigned long code, void *ptr)
520 520
521/*** initialization stuff */ 521/*** initialization stuff */
522 522
523static struct file_operations wdrtas_fops = { 523static const struct file_operations wdrtas_fops = {
524 .owner = THIS_MODULE, 524 .owner = THIS_MODULE,
525 .llseek = no_llseek, 525 .llseek = no_llseek,
526 .write = wdrtas_write, 526 .write = wdrtas_write,
@@ -535,7 +535,7 @@ static struct miscdevice wdrtas_miscdev = {
535 .fops = &wdrtas_fops, 535 .fops = &wdrtas_fops,
536}; 536};
537 537
538static struct file_operations wdrtas_temp_fops = { 538static const struct file_operations wdrtas_temp_fops = {
539 .owner = THIS_MODULE, 539 .owner = THIS_MODULE,
540 .llseek = no_llseek, 540 .llseek = no_llseek,
541 .read = wdrtas_temp_read, 541 .read = wdrtas_temp_read,
diff --git a/drivers/char/watchdog/wdt.c b/drivers/char/watchdog/wdt.c
index a1d972c8f44c..70be81e39a61 100644
--- a/drivers/char/watchdog/wdt.c
+++ b/drivers/char/watchdog/wdt.c
@@ -494,7 +494,7 @@ static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
494 */ 494 */
495 495
496 496
497static struct file_operations wdt_fops = { 497static const struct file_operations wdt_fops = {
498 .owner = THIS_MODULE, 498 .owner = THIS_MODULE,
499 .llseek = no_llseek, 499 .llseek = no_llseek,
500 .write = wdt_write, 500 .write = wdt_write,
@@ -510,7 +510,7 @@ static struct miscdevice wdt_miscdev = {
510}; 510};
511 511
512#ifdef CONFIG_WDT_501 512#ifdef CONFIG_WDT_501
513static struct file_operations wdt_temp_fops = { 513static const struct file_operations wdt_temp_fops = {
514 .owner = THIS_MODULE, 514 .owner = THIS_MODULE,
515 .llseek = no_llseek, 515 .llseek = no_llseek,
516 .read = wdt_temp_read, 516 .read = wdt_temp_read,
diff --git a/drivers/char/watchdog/wdt285.c b/drivers/char/watchdog/wdt285.c
index 52825a1f1779..6555fb844f23 100644
--- a/drivers/char/watchdog/wdt285.c
+++ b/drivers/char/watchdog/wdt285.c
@@ -178,7 +178,7 @@ watchdog_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
178 return ret; 178 return ret;
179} 179}
180 180
181static struct file_operations watchdog_fops = { 181static const struct file_operations watchdog_fops = {
182 .owner = THIS_MODULE, 182 .owner = THIS_MODULE,
183 .llseek = no_llseek, 183 .llseek = no_llseek,
184 .write = watchdog_write, 184 .write = watchdog_write,
diff --git a/drivers/char/watchdog/wdt977.c b/drivers/char/watchdog/wdt977.c
index 3cde2b9bb763..a0935bc775f8 100644
--- a/drivers/char/watchdog/wdt977.c
+++ b/drivers/char/watchdog/wdt977.c
@@ -418,7 +418,7 @@ static int wdt977_notify_sys(struct notifier_block *this, unsigned long code,
418 return NOTIFY_DONE; 418 return NOTIFY_DONE;
419} 419}
420 420
421static struct file_operations wdt977_fops= 421static const struct file_operations wdt977_fops=
422{ 422{
423 .owner = THIS_MODULE, 423 .owner = THIS_MODULE,
424 .llseek = no_llseek, 424 .llseek = no_llseek,
diff --git a/drivers/char/watchdog/wdt_pci.c b/drivers/char/watchdog/wdt_pci.c
index 7529ecdbabae..5918ca2c9c35 100644
--- a/drivers/char/watchdog/wdt_pci.c
+++ b/drivers/char/watchdog/wdt_pci.c
@@ -543,7 +543,7 @@ static int wdtpci_notify_sys(struct notifier_block *this, unsigned long code,
543 */ 543 */
544 544
545 545
546static struct file_operations wdtpci_fops = { 546static const struct file_operations wdtpci_fops = {
547 .owner = THIS_MODULE, 547 .owner = THIS_MODULE,
548 .llseek = no_llseek, 548 .llseek = no_llseek,
549 .write = wdtpci_write, 549 .write = wdtpci_write,
@@ -559,7 +559,7 @@ static struct miscdevice wdtpci_miscdev = {
559}; 559};
560 560
561#ifdef CONFIG_WDT_501_PCI 561#ifdef CONFIG_WDT_501_PCI
562static struct file_operations wdtpci_temp_fops = { 562static const struct file_operations wdtpci_temp_fops = {
563 .owner = THIS_MODULE, 563 .owner = THIS_MODULE,
564 .llseek = no_llseek, 564 .llseek = no_llseek,
565 .read = wdtpci_temp_read, 565 .read = wdtpci_temp_read,
diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
index 498aa37bca22..3ece69231343 100644
--- a/drivers/connector/cn_proc.c
+++ b/drivers/connector/cn_proc.c
@@ -51,6 +51,7 @@ void proc_fork_connector(struct task_struct *task)
51 struct cn_msg *msg; 51 struct cn_msg *msg;
52 struct proc_event *ev; 52 struct proc_event *ev;
53 __u8 buffer[CN_PROC_MSG_SIZE]; 53 __u8 buffer[CN_PROC_MSG_SIZE];
54 struct timespec ts;
54 55
55 if (atomic_read(&proc_event_num_listeners) < 1) 56 if (atomic_read(&proc_event_num_listeners) < 1)
56 return; 57 return;
@@ -58,7 +59,8 @@ void proc_fork_connector(struct task_struct *task)
58 msg = (struct cn_msg*)buffer; 59 msg = (struct cn_msg*)buffer;
59 ev = (struct proc_event*)msg->data; 60 ev = (struct proc_event*)msg->data;
60 get_seq(&msg->seq, &ev->cpu); 61 get_seq(&msg->seq, &ev->cpu);
61 ktime_get_ts(&ev->timestamp); /* get high res monotonic timestamp */ 62 ktime_get_ts(&ts); /* get high res monotonic timestamp */
63 ev->timestamp_ns = timespec_to_ns(&ts);
62 ev->what = PROC_EVENT_FORK; 64 ev->what = PROC_EVENT_FORK;
63 ev->event_data.fork.parent_pid = task->real_parent->pid; 65 ev->event_data.fork.parent_pid = task->real_parent->pid;
64 ev->event_data.fork.parent_tgid = task->real_parent->tgid; 66 ev->event_data.fork.parent_tgid = task->real_parent->tgid;
@@ -76,6 +78,7 @@ void proc_exec_connector(struct task_struct *task)
76{ 78{
77 struct cn_msg *msg; 79 struct cn_msg *msg;
78 struct proc_event *ev; 80 struct proc_event *ev;
81 struct timespec ts;
79 __u8 buffer[CN_PROC_MSG_SIZE]; 82 __u8 buffer[CN_PROC_MSG_SIZE];
80 83
81 if (atomic_read(&proc_event_num_listeners) < 1) 84 if (atomic_read(&proc_event_num_listeners) < 1)
@@ -84,7 +87,8 @@ void proc_exec_connector(struct task_struct *task)
84 msg = (struct cn_msg*)buffer; 87 msg = (struct cn_msg*)buffer;
85 ev = (struct proc_event*)msg->data; 88 ev = (struct proc_event*)msg->data;
86 get_seq(&msg->seq, &ev->cpu); 89 get_seq(&msg->seq, &ev->cpu);
87 ktime_get_ts(&ev->timestamp); 90 ktime_get_ts(&ts); /* get high res monotonic timestamp */
91 ev->timestamp_ns = timespec_to_ns(&ts);
88 ev->what = PROC_EVENT_EXEC; 92 ev->what = PROC_EVENT_EXEC;
89 ev->event_data.exec.process_pid = task->pid; 93 ev->event_data.exec.process_pid = task->pid;
90 ev->event_data.exec.process_tgid = task->tgid; 94 ev->event_data.exec.process_tgid = task->tgid;
@@ -100,6 +104,7 @@ void proc_id_connector(struct task_struct *task, int which_id)
100 struct cn_msg *msg; 104 struct cn_msg *msg;
101 struct proc_event *ev; 105 struct proc_event *ev;
102 __u8 buffer[CN_PROC_MSG_SIZE]; 106 __u8 buffer[CN_PROC_MSG_SIZE];
107 struct timespec ts;
103 108
104 if (atomic_read(&proc_event_num_listeners) < 1) 109 if (atomic_read(&proc_event_num_listeners) < 1)
105 return; 110 return;
@@ -118,7 +123,8 @@ void proc_id_connector(struct task_struct *task, int which_id)
118 } else 123 } else
119 return; 124 return;
120 get_seq(&msg->seq, &ev->cpu); 125 get_seq(&msg->seq, &ev->cpu);
121 ktime_get_ts(&ev->timestamp); 126 ktime_get_ts(&ts); /* get high res monotonic timestamp */
127 ev->timestamp_ns = timespec_to_ns(&ts);
122 128
123 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); 129 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
124 msg->ack = 0; /* not used */ 130 msg->ack = 0; /* not used */
@@ -131,6 +137,7 @@ void proc_exit_connector(struct task_struct *task)
131 struct cn_msg *msg; 137 struct cn_msg *msg;
132 struct proc_event *ev; 138 struct proc_event *ev;
133 __u8 buffer[CN_PROC_MSG_SIZE]; 139 __u8 buffer[CN_PROC_MSG_SIZE];
140 struct timespec ts;
134 141
135 if (atomic_read(&proc_event_num_listeners) < 1) 142 if (atomic_read(&proc_event_num_listeners) < 1)
136 return; 143 return;
@@ -138,7 +145,8 @@ void proc_exit_connector(struct task_struct *task)
138 msg = (struct cn_msg*)buffer; 145 msg = (struct cn_msg*)buffer;
139 ev = (struct proc_event*)msg->data; 146 ev = (struct proc_event*)msg->data;
140 get_seq(&msg->seq, &ev->cpu); 147 get_seq(&msg->seq, &ev->cpu);
141 ktime_get_ts(&ev->timestamp); 148 ktime_get_ts(&ts); /* get high res monotonic timestamp */
149 ev->timestamp_ns = timespec_to_ns(&ts);
142 ev->what = PROC_EVENT_EXIT; 150 ev->what = PROC_EVENT_EXIT;
143 ev->event_data.exit.process_pid = task->pid; 151 ev->event_data.exit.process_pid = task->pid;
144 ev->event_data.exit.process_tgid = task->tgid; 152 ev->event_data.exit.process_tgid = task->tgid;
@@ -164,6 +172,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
164 struct cn_msg *msg; 172 struct cn_msg *msg;
165 struct proc_event *ev; 173 struct proc_event *ev;
166 __u8 buffer[CN_PROC_MSG_SIZE]; 174 __u8 buffer[CN_PROC_MSG_SIZE];
175 struct timespec ts;
167 176
168 if (atomic_read(&proc_event_num_listeners) < 1) 177 if (atomic_read(&proc_event_num_listeners) < 1)
169 return; 178 return;
@@ -171,7 +180,8 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
171 msg = (struct cn_msg*)buffer; 180 msg = (struct cn_msg*)buffer;
172 ev = (struct proc_event*)msg->data; 181 ev = (struct proc_event*)msg->data;
173 msg->seq = rcvd_seq; 182 msg->seq = rcvd_seq;
174 ktime_get_ts(&ev->timestamp); 183 ktime_get_ts(&ts); /* get high res monotonic timestamp */
184 ev->timestamp_ns = timespec_to_ns(&ts);
175 ev->cpu = -1; 185 ev->cpu = -1;
176 ev->what = PROC_EVENT_NONE; 186 ev->what = PROC_EVENT_NONE;
177 ev->event_data.ack.err = err; 187 ev->event_data.ack.err = err;
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 1ba4039777e8..b3df613ae4ec 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -284,39 +284,69 @@ EXPORT_SYMBOL_GPL(cpufreq_notify_transition);
284 * SYSFS INTERFACE * 284 * SYSFS INTERFACE *
285 *********************************************************************/ 285 *********************************************************************/
286 286
287static struct cpufreq_governor *__find_governor(const char *str_governor)
288{
289 struct cpufreq_governor *t;
290
291 list_for_each_entry(t, &cpufreq_governor_list, governor_list)
292 if (!strnicmp(str_governor,t->name,CPUFREQ_NAME_LEN))
293 return t;
294
295 return NULL;
296}
297
287/** 298/**
288 * cpufreq_parse_governor - parse a governor string 299 * cpufreq_parse_governor - parse a governor string
289 */ 300 */
290static int cpufreq_parse_governor (char *str_governor, unsigned int *policy, 301static int cpufreq_parse_governor (char *str_governor, unsigned int *policy,
291 struct cpufreq_governor **governor) 302 struct cpufreq_governor **governor)
292{ 303{
304 int err = -EINVAL;
305
293 if (!cpufreq_driver) 306 if (!cpufreq_driver)
294 return -EINVAL; 307 goto out;
308
295 if (cpufreq_driver->setpolicy) { 309 if (cpufreq_driver->setpolicy) {
296 if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) { 310 if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) {
297 *policy = CPUFREQ_POLICY_PERFORMANCE; 311 *policy = CPUFREQ_POLICY_PERFORMANCE;
298 return 0; 312 err = 0;
299 } else if (!strnicmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) { 313 } else if (!strnicmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) {
300 *policy = CPUFREQ_POLICY_POWERSAVE; 314 *policy = CPUFREQ_POLICY_POWERSAVE;
301 return 0; 315 err = 0;
302 } 316 }
303 return -EINVAL; 317 } else if (cpufreq_driver->target) {
304 } else {
305 struct cpufreq_governor *t; 318 struct cpufreq_governor *t;
319
306 mutex_lock(&cpufreq_governor_mutex); 320 mutex_lock(&cpufreq_governor_mutex);
307 if (!cpufreq_driver || !cpufreq_driver->target) 321
308 goto out; 322 t = __find_governor(str_governor);
309 list_for_each_entry(t, &cpufreq_governor_list, governor_list) { 323
310 if (!strnicmp(str_governor,t->name,CPUFREQ_NAME_LEN)) { 324 if (t == NULL) {
311 *governor = t; 325 char *name = kasprintf(GFP_KERNEL, "cpufreq_%s", str_governor);
326
327 if (name) {
328 int ret;
329
312 mutex_unlock(&cpufreq_governor_mutex); 330 mutex_unlock(&cpufreq_governor_mutex);
313 return 0; 331 ret = request_module(name);
332 mutex_lock(&cpufreq_governor_mutex);
333
334 if (ret == 0)
335 t = __find_governor(str_governor);
314 } 336 }
337
338 kfree(name);
315 } 339 }
316out: 340
341 if (t != NULL) {
342 *governor = t;
343 err = 0;
344 }
345
317 mutex_unlock(&cpufreq_governor_mutex); 346 mutex_unlock(&cpufreq_governor_mutex);
318 } 347 }
319 return -EINVAL; 348 out:
349 return err;
320} 350}
321 351
322 352
@@ -364,10 +394,12 @@ static ssize_t store_##file_name \
364 if (ret != 1) \ 394 if (ret != 1) \
365 return -EINVAL; \ 395 return -EINVAL; \
366 \ 396 \
397 lock_cpu_hotplug(); \
367 mutex_lock(&policy->lock); \ 398 mutex_lock(&policy->lock); \
368 ret = __cpufreq_set_policy(policy, &new_policy); \ 399 ret = __cpufreq_set_policy(policy, &new_policy); \
369 policy->user_policy.object = policy->object; \ 400 policy->user_policy.object = policy->object; \
370 mutex_unlock(&policy->lock); \ 401 mutex_unlock(&policy->lock); \
402 unlock_cpu_hotplug(); \
371 \ 403 \
372 return ret ? ret : count; \ 404 return ret ? ret : count; \
373} 405}
@@ -423,6 +455,8 @@ static ssize_t store_scaling_governor (struct cpufreq_policy * policy,
423 if (cpufreq_parse_governor(str_governor, &new_policy.policy, &new_policy.governor)) 455 if (cpufreq_parse_governor(str_governor, &new_policy.policy, &new_policy.governor))
424 return -EINVAL; 456 return -EINVAL;
425 457
458 lock_cpu_hotplug();
459
426 /* Do not use cpufreq_set_policy here or the user_policy.max 460 /* Do not use cpufreq_set_policy here or the user_policy.max
427 will be wrongly overridden */ 461 will be wrongly overridden */
428 mutex_lock(&policy->lock); 462 mutex_lock(&policy->lock);
@@ -432,6 +466,8 @@ static ssize_t store_scaling_governor (struct cpufreq_policy * policy,
432 policy->user_policy.governor = policy->governor; 466 policy->user_policy.governor = policy->governor;
433 mutex_unlock(&policy->lock); 467 mutex_unlock(&policy->lock);
434 468
469 unlock_cpu_hotplug();
470
435 return ret ? ret : count; 471 return ret ? ret : count;
436} 472}
437 473
@@ -1193,20 +1229,18 @@ EXPORT_SYMBOL(cpufreq_unregister_notifier);
1193 *********************************************************************/ 1229 *********************************************************************/
1194 1230
1195 1231
1232/* Must be called with lock_cpu_hotplug held */
1196int __cpufreq_driver_target(struct cpufreq_policy *policy, 1233int __cpufreq_driver_target(struct cpufreq_policy *policy,
1197 unsigned int target_freq, 1234 unsigned int target_freq,
1198 unsigned int relation) 1235 unsigned int relation)
1199{ 1236{
1200 int retval = -EINVAL; 1237 int retval = -EINVAL;
1201 1238
1202 lock_cpu_hotplug();
1203 dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu, 1239 dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu,
1204 target_freq, relation); 1240 target_freq, relation);
1205 if (cpu_online(policy->cpu) && cpufreq_driver->target) 1241 if (cpu_online(policy->cpu) && cpufreq_driver->target)
1206 retval = cpufreq_driver->target(policy, target_freq, relation); 1242 retval = cpufreq_driver->target(policy, target_freq, relation);
1207 1243
1208 unlock_cpu_hotplug();
1209
1210 return retval; 1244 return retval;
1211} 1245}
1212EXPORT_SYMBOL_GPL(__cpufreq_driver_target); 1246EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
@@ -1221,17 +1255,23 @@ int cpufreq_driver_target(struct cpufreq_policy *policy,
1221 if (!policy) 1255 if (!policy)
1222 return -EINVAL; 1256 return -EINVAL;
1223 1257
1258 lock_cpu_hotplug();
1224 mutex_lock(&policy->lock); 1259 mutex_lock(&policy->lock);
1225 1260
1226 ret = __cpufreq_driver_target(policy, target_freq, relation); 1261 ret = __cpufreq_driver_target(policy, target_freq, relation);
1227 1262
1228 mutex_unlock(&policy->lock); 1263 mutex_unlock(&policy->lock);
1264 unlock_cpu_hotplug();
1229 1265
1230 cpufreq_cpu_put(policy); 1266 cpufreq_cpu_put(policy);
1231 return ret; 1267 return ret;
1232} 1268}
1233EXPORT_SYMBOL_GPL(cpufreq_driver_target); 1269EXPORT_SYMBOL_GPL(cpufreq_driver_target);
1234 1270
1271/*
1272 * Locking: Must be called with the lock_cpu_hotplug() lock held
1273 * when "event" is CPUFREQ_GOV_LIMITS
1274 */
1235 1275
1236static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event) 1276static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
1237{ 1277{
@@ -1253,43 +1293,23 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
1253} 1293}
1254 1294
1255 1295
1256int cpufreq_governor(unsigned int cpu, unsigned int event)
1257{
1258 int ret = 0;
1259 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1260
1261 if (!policy)
1262 return -EINVAL;
1263
1264 mutex_lock(&policy->lock);
1265 ret = __cpufreq_governor(policy, event);
1266 mutex_unlock(&policy->lock);
1267
1268 cpufreq_cpu_put(policy);
1269 return ret;
1270}
1271EXPORT_SYMBOL_GPL(cpufreq_governor);
1272
1273
1274int cpufreq_register_governor(struct cpufreq_governor *governor) 1296int cpufreq_register_governor(struct cpufreq_governor *governor)
1275{ 1297{
1276 struct cpufreq_governor *t; 1298 int err;
1277 1299
1278 if (!governor) 1300 if (!governor)
1279 return -EINVAL; 1301 return -EINVAL;
1280 1302
1281 mutex_lock(&cpufreq_governor_mutex); 1303 mutex_lock(&cpufreq_governor_mutex);
1282 1304
1283 list_for_each_entry(t, &cpufreq_governor_list, governor_list) { 1305 err = -EBUSY;
1284 if (!strnicmp(governor->name,t->name,CPUFREQ_NAME_LEN)) { 1306 if (__find_governor(governor->name) == NULL) {
1285 mutex_unlock(&cpufreq_governor_mutex); 1307 err = 0;
1286 return -EBUSY; 1308 list_add(&governor->governor_list, &cpufreq_governor_list);
1287 }
1288 } 1309 }
1289 list_add(&governor->governor_list, &cpufreq_governor_list);
1290 1310
1291 mutex_unlock(&cpufreq_governor_mutex); 1311 mutex_unlock(&cpufreq_governor_mutex);
1292 return 0; 1312 return err;
1293} 1313}
1294EXPORT_SYMBOL_GPL(cpufreq_register_governor); 1314EXPORT_SYMBOL_GPL(cpufreq_register_governor);
1295 1315
@@ -1338,6 +1358,9 @@ int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
1338EXPORT_SYMBOL(cpufreq_get_policy); 1358EXPORT_SYMBOL(cpufreq_get_policy);
1339 1359
1340 1360
1361/*
1362 * Locking: Must be called with the lock_cpu_hotplug() lock held
1363 */
1341static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_policy *policy) 1364static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_policy *policy)
1342{ 1365{
1343 int ret = 0; 1366 int ret = 0;
@@ -1348,6 +1371,11 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_poli
1348 1371
1349 memcpy(&policy->cpuinfo, &data->cpuinfo, sizeof(struct cpufreq_cpuinfo)); 1372 memcpy(&policy->cpuinfo, &data->cpuinfo, sizeof(struct cpufreq_cpuinfo));
1350 1373
1374 if (policy->min > data->min && policy->min > policy->max) {
1375 ret = -EINVAL;
1376 goto error_out;
1377 }
1378
1351 /* verify the cpu speed can be set within this limit */ 1379 /* verify the cpu speed can be set within this limit */
1352 ret = cpufreq_driver->verify(policy); 1380 ret = cpufreq_driver->verify(policy);
1353 if (ret) 1381 if (ret)
@@ -1432,6 +1460,8 @@ int cpufreq_set_policy(struct cpufreq_policy *policy)
1432 if (!data) 1460 if (!data)
1433 return -EINVAL; 1461 return -EINVAL;
1434 1462
1463 lock_cpu_hotplug();
1464
1435 /* lock this CPU */ 1465 /* lock this CPU */
1436 mutex_lock(&data->lock); 1466 mutex_lock(&data->lock);
1437 1467
@@ -1442,6 +1472,8 @@ int cpufreq_set_policy(struct cpufreq_policy *policy)
1442 data->user_policy.governor = data->governor; 1472 data->user_policy.governor = data->governor;
1443 1473
1444 mutex_unlock(&data->lock); 1474 mutex_unlock(&data->lock);
1475
1476 unlock_cpu_hotplug();
1445 cpufreq_cpu_put(data); 1477 cpufreq_cpu_put(data);
1446 1478
1447 return ret; 1479 return ret;
@@ -1465,6 +1497,7 @@ int cpufreq_update_policy(unsigned int cpu)
1465 if (!data) 1497 if (!data)
1466 return -ENODEV; 1498 return -ENODEV;
1467 1499
1500 lock_cpu_hotplug();
1468 mutex_lock(&data->lock); 1501 mutex_lock(&data->lock);
1469 1502
1470 dprintk("updating policy for CPU %u\n", cpu); 1503 dprintk("updating policy for CPU %u\n", cpu);
@@ -1490,7 +1523,7 @@ int cpufreq_update_policy(unsigned int cpu)
1490 ret = __cpufreq_set_policy(data, &policy); 1523 ret = __cpufreq_set_policy(data, &policy);
1491 1524
1492 mutex_unlock(&data->lock); 1525 mutex_unlock(&data->lock);
1493 1526 unlock_cpu_hotplug();
1494 cpufreq_cpu_put(data); 1527 cpufreq_cpu_put(data);
1495 return ret; 1528 return ret;
1496} 1529}
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index b3ebc8f01975..c4c578defabf 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -525,7 +525,6 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
525 break; 525 break;
526 526
527 case CPUFREQ_GOV_LIMITS: 527 case CPUFREQ_GOV_LIMITS:
528 lock_cpu_hotplug();
529 mutex_lock(&dbs_mutex); 528 mutex_lock(&dbs_mutex);
530 if (policy->max < this_dbs_info->cur_policy->cur) 529 if (policy->max < this_dbs_info->cur_policy->cur)
531 __cpufreq_driver_target( 530 __cpufreq_driver_target(
@@ -536,7 +535,6 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
536 this_dbs_info->cur_policy, 535 this_dbs_info->cur_policy,
537 policy->min, CPUFREQ_RELATION_L); 536 policy->min, CPUFREQ_RELATION_L);
538 mutex_unlock(&dbs_mutex); 537 mutex_unlock(&dbs_mutex);
539 unlock_cpu_hotplug();
540 break; 538 break;
541 } 539 }
542 return 0; 540 return 0;
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index 693e540481b4..52cf1f021825 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -12,22 +12,11 @@
12 12
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/smp.h>
16#include <linux/init.h> 15#include <linux/init.h>
17#include <linux/interrupt.h>
18#include <linux/ctype.h>
19#include <linux/cpufreq.h> 16#include <linux/cpufreq.h>
20#include <linux/sysctl.h>
21#include <linux/types.h>
22#include <linux/fs.h>
23#include <linux/sysfs.h>
24#include <linux/cpu.h> 17#include <linux/cpu.h>
25#include <linux/sched.h>
26#include <linux/kmod.h>
27#include <linux/workqueue.h>
28#include <linux/jiffies.h> 18#include <linux/jiffies.h>
29#include <linux/kernel_stat.h> 19#include <linux/kernel_stat.h>
30#include <linux/percpu.h>
31#include <linux/mutex.h> 20#include <linux/mutex.h>
32 21
33/* 22/*
@@ -56,16 +45,15 @@ static unsigned int def_sampling_rate;
56#define MIN_SAMPLING_RATE (def_sampling_rate / MIN_SAMPLING_RATE_RATIO) 45#define MIN_SAMPLING_RATE (def_sampling_rate / MIN_SAMPLING_RATE_RATIO)
57#define MAX_SAMPLING_RATE (500 * def_sampling_rate) 46#define MAX_SAMPLING_RATE (500 * def_sampling_rate)
58#define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) 47#define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000)
59#define DEF_SAMPLING_DOWN_FACTOR (1)
60#define MAX_SAMPLING_DOWN_FACTOR (10)
61#define TRANSITION_LATENCY_LIMIT (10 * 1000) 48#define TRANSITION_LATENCY_LIMIT (10 * 1000)
62 49
63static void do_dbs_timer(void *data); 50static void do_dbs_timer(void *data);
64 51
65struct cpu_dbs_info_s { 52struct cpu_dbs_info_s {
53 cputime64_t prev_cpu_idle;
54 cputime64_t prev_cpu_wall;
66 struct cpufreq_policy *cur_policy; 55 struct cpufreq_policy *cur_policy;
67 unsigned int prev_cpu_idle_up; 56 struct work_struct work;
68 unsigned int prev_cpu_idle_down;
69 unsigned int enable; 57 unsigned int enable;
70}; 58};
71static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info); 59static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info);
@@ -80,31 +68,32 @@ static unsigned int dbs_enable; /* number of CPUs using this policy */
80 * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock 68 * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock
81 * is recursive for the same process. -Venki 69 * is recursive for the same process. -Venki
82 */ 70 */
83static DEFINE_MUTEX (dbs_mutex); 71static DEFINE_MUTEX(dbs_mutex);
84static DECLARE_WORK (dbs_work, do_dbs_timer, NULL);
85 72
86static struct workqueue_struct *dbs_workq; 73static struct workqueue_struct *kondemand_wq;
87 74
88struct dbs_tuners { 75struct dbs_tuners {
89 unsigned int sampling_rate; 76 unsigned int sampling_rate;
90 unsigned int sampling_down_factor;
91 unsigned int up_threshold; 77 unsigned int up_threshold;
92 unsigned int ignore_nice; 78 unsigned int ignore_nice;
93}; 79};
94 80
95static struct dbs_tuners dbs_tuners_ins = { 81static struct dbs_tuners dbs_tuners_ins = {
96 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, 82 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD,
97 .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
98 .ignore_nice = 0, 83 .ignore_nice = 0,
99}; 84};
100 85
101static inline unsigned int get_cpu_idle_time(unsigned int cpu) 86static inline cputime64_t get_cpu_idle_time(unsigned int cpu)
102{ 87{
103 return kstat_cpu(cpu).cpustat.idle + 88 cputime64_t retval;
104 kstat_cpu(cpu).cpustat.iowait + 89
105 ( dbs_tuners_ins.ignore_nice ? 90 retval = cputime64_add(kstat_cpu(cpu).cpustat.idle,
106 kstat_cpu(cpu).cpustat.nice : 91 kstat_cpu(cpu).cpustat.iowait);
107 0); 92
93 if (dbs_tuners_ins.ignore_nice)
94 retval = cputime64_add(retval, kstat_cpu(cpu).cpustat.nice);
95
96 return retval;
108} 97}
109 98
110/************************** sysfs interface ************************/ 99/************************** sysfs interface ************************/
@@ -133,35 +122,15 @@ static ssize_t show_##file_name \
133 return sprintf(buf, "%u\n", dbs_tuners_ins.object); \ 122 return sprintf(buf, "%u\n", dbs_tuners_ins.object); \
134} 123}
135show_one(sampling_rate, sampling_rate); 124show_one(sampling_rate, sampling_rate);
136show_one(sampling_down_factor, sampling_down_factor);
137show_one(up_threshold, up_threshold); 125show_one(up_threshold, up_threshold);
138show_one(ignore_nice_load, ignore_nice); 126show_one(ignore_nice_load, ignore_nice);
139 127
140static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused,
141 const char *buf, size_t count)
142{
143 unsigned int input;
144 int ret;
145 ret = sscanf (buf, "%u", &input);
146 if (ret != 1 )
147 return -EINVAL;
148
149 if (input > MAX_SAMPLING_DOWN_FACTOR || input < 1)
150 return -EINVAL;
151
152 mutex_lock(&dbs_mutex);
153 dbs_tuners_ins.sampling_down_factor = input;
154 mutex_unlock(&dbs_mutex);
155
156 return count;
157}
158
159static ssize_t store_sampling_rate(struct cpufreq_policy *unused, 128static ssize_t store_sampling_rate(struct cpufreq_policy *unused,
160 const char *buf, size_t count) 129 const char *buf, size_t count)
161{ 130{
162 unsigned int input; 131 unsigned int input;
163 int ret; 132 int ret;
164 ret = sscanf (buf, "%u", &input); 133 ret = sscanf(buf, "%u", &input);
165 134
166 mutex_lock(&dbs_mutex); 135 mutex_lock(&dbs_mutex);
167 if (ret != 1 || input > MAX_SAMPLING_RATE || input < MIN_SAMPLING_RATE) { 136 if (ret != 1 || input > MAX_SAMPLING_RATE || input < MIN_SAMPLING_RATE) {
@@ -180,7 +149,7 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused,
180{ 149{
181 unsigned int input; 150 unsigned int input;
182 int ret; 151 int ret;
183 ret = sscanf (buf, "%u", &input); 152 ret = sscanf(buf, "%u", &input);
184 153
185 mutex_lock(&dbs_mutex); 154 mutex_lock(&dbs_mutex);
186 if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || 155 if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD ||
@@ -203,7 +172,7 @@ static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy,
203 172
204 unsigned int j; 173 unsigned int j;
205 174
206 ret = sscanf (buf, "%u", &input); 175 ret = sscanf(buf, "%u", &input);
207 if ( ret != 1 ) 176 if ( ret != 1 )
208 return -EINVAL; 177 return -EINVAL;
209 178
@@ -217,12 +186,12 @@ static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy,
217 } 186 }
218 dbs_tuners_ins.ignore_nice = input; 187 dbs_tuners_ins.ignore_nice = input;
219 188
220 /* we need to re-evaluate prev_cpu_idle_up and prev_cpu_idle_down */ 189 /* we need to re-evaluate prev_cpu_idle */
221 for_each_online_cpu(j) { 190 for_each_online_cpu(j) {
222 struct cpu_dbs_info_s *j_dbs_info; 191 struct cpu_dbs_info_s *dbs_info;
223 j_dbs_info = &per_cpu(cpu_dbs_info, j); 192 dbs_info = &per_cpu(cpu_dbs_info, j);
224 j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); 193 dbs_info->prev_cpu_idle = get_cpu_idle_time(j);
225 j_dbs_info->prev_cpu_idle_down = j_dbs_info->prev_cpu_idle_up; 194 dbs_info->prev_cpu_wall = get_jiffies_64();
226 } 195 }
227 mutex_unlock(&dbs_mutex); 196 mutex_unlock(&dbs_mutex);
228 197
@@ -234,7 +203,6 @@ static struct freq_attr _name = \
234__ATTR(_name, 0644, show_##_name, store_##_name) 203__ATTR(_name, 0644, show_##_name, store_##_name)
235 204
236define_one_rw(sampling_rate); 205define_one_rw(sampling_rate);
237define_one_rw(sampling_down_factor);
238define_one_rw(up_threshold); 206define_one_rw(up_threshold);
239define_one_rw(ignore_nice_load); 207define_one_rw(ignore_nice_load);
240 208
@@ -242,7 +210,6 @@ static struct attribute * dbs_attributes[] = {
242 &sampling_rate_max.attr, 210 &sampling_rate_max.attr,
243 &sampling_rate_min.attr, 211 &sampling_rate_min.attr,
244 &sampling_rate.attr, 212 &sampling_rate.attr,
245 &sampling_down_factor.attr,
246 &up_threshold.attr, 213 &up_threshold.attr,
247 &ignore_nice_load.attr, 214 &ignore_nice_load.attr,
248 NULL 215 NULL
@@ -255,26 +222,29 @@ static struct attribute_group dbs_attr_group = {
255 222
256/************************** sysfs end ************************/ 223/************************** sysfs end ************************/
257 224
258static void dbs_check_cpu(int cpu) 225static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
259{ 226{
260 unsigned int idle_ticks, up_idle_ticks, total_ticks; 227 unsigned int idle_ticks, total_ticks;
261 unsigned int freq_next; 228 unsigned int load;
262 unsigned int freq_down_sampling_rate; 229 cputime64_t cur_jiffies;
263 static int down_skip[NR_CPUS];
264 struct cpu_dbs_info_s *this_dbs_info;
265 230
266 struct cpufreq_policy *policy; 231 struct cpufreq_policy *policy;
267 unsigned int j; 232 unsigned int j;
268 233
269 this_dbs_info = &per_cpu(cpu_dbs_info, cpu);
270 if (!this_dbs_info->enable) 234 if (!this_dbs_info->enable)
271 return; 235 return;
272 236
273 policy = this_dbs_info->cur_policy; 237 policy = this_dbs_info->cur_policy;
238 cur_jiffies = jiffies64_to_cputime64(get_jiffies_64());
239 total_ticks = (unsigned int) cputime64_sub(cur_jiffies,
240 this_dbs_info->prev_cpu_wall);
241 this_dbs_info->prev_cpu_wall = cur_jiffies;
242 if (!total_ticks)
243 return;
274 /* 244 /*
275 * Every sampling_rate, we check, if current idle time is less 245 * Every sampling_rate, we check, if current idle time is less
276 * than 20% (default), then we try to increase frequency 246 * than 20% (default), then we try to increase frequency
277 * Every sampling_rate*sampling_down_factor, we look for a the lowest 247 * Every sampling_rate, we look for a the lowest
278 * frequency which can sustain the load while keeping idle time over 248 * frequency which can sustain the load while keeping idle time over
279 * 30%. If such a frequency exist, we try to decrease to this frequency. 249 * 30%. If such a frequency exist, we try to decrease to this frequency.
280 * 250 *
@@ -283,36 +253,26 @@ static void dbs_check_cpu(int cpu)
283 * 5% (default) of current frequency 253 * 5% (default) of current frequency
284 */ 254 */
285 255
286 /* Check for frequency increase */ 256 /* Get Idle Time */
287 idle_ticks = UINT_MAX; 257 idle_ticks = UINT_MAX;
288 for_each_cpu_mask(j, policy->cpus) { 258 for_each_cpu_mask(j, policy->cpus) {
289 unsigned int tmp_idle_ticks, total_idle_ticks; 259 cputime64_t total_idle_ticks;
260 unsigned int tmp_idle_ticks;
290 struct cpu_dbs_info_s *j_dbs_info; 261 struct cpu_dbs_info_s *j_dbs_info;
291 262
292 j_dbs_info = &per_cpu(cpu_dbs_info, j); 263 j_dbs_info = &per_cpu(cpu_dbs_info, j);
293 total_idle_ticks = get_cpu_idle_time(j); 264 total_idle_ticks = get_cpu_idle_time(j);
294 tmp_idle_ticks = total_idle_ticks - 265 tmp_idle_ticks = (unsigned int) cputime64_sub(total_idle_ticks,
295 j_dbs_info->prev_cpu_idle_up; 266 j_dbs_info->prev_cpu_idle);
296 j_dbs_info->prev_cpu_idle_up = total_idle_ticks; 267 j_dbs_info->prev_cpu_idle = total_idle_ticks;
297 268
298 if (tmp_idle_ticks < idle_ticks) 269 if (tmp_idle_ticks < idle_ticks)
299 idle_ticks = tmp_idle_ticks; 270 idle_ticks = tmp_idle_ticks;
300 } 271 }
272 load = (100 * (total_ticks - idle_ticks)) / total_ticks;
301 273
302 /* Scale idle ticks by 100 and compare with up and down ticks */ 274 /* Check for frequency increase */
303 idle_ticks *= 100; 275 if (load > dbs_tuners_ins.up_threshold) {
304 up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) *
305 usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
306
307 if (idle_ticks < up_idle_ticks) {
308 down_skip[cpu] = 0;
309 for_each_cpu_mask(j, policy->cpus) {
310 struct cpu_dbs_info_s *j_dbs_info;
311
312 j_dbs_info = &per_cpu(cpu_dbs_info, j);
313 j_dbs_info->prev_cpu_idle_down =
314 j_dbs_info->prev_cpu_idle_up;
315 }
316 /* if we are already at full speed then break out early */ 276 /* if we are already at full speed then break out early */
317 if (policy->cur == policy->max) 277 if (policy->cur == policy->max)
318 return; 278 return;
@@ -323,83 +283,54 @@ static void dbs_check_cpu(int cpu)
323 } 283 }
324 284
325 /* Check for frequency decrease */ 285 /* Check for frequency decrease */
326 down_skip[cpu]++;
327 if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor)
328 return;
329
330 idle_ticks = UINT_MAX;
331 for_each_cpu_mask(j, policy->cpus) {
332 unsigned int tmp_idle_ticks, total_idle_ticks;
333 struct cpu_dbs_info_s *j_dbs_info;
334
335 j_dbs_info = &per_cpu(cpu_dbs_info, j);
336 /* Check for frequency decrease */
337 total_idle_ticks = j_dbs_info->prev_cpu_idle_up;
338 tmp_idle_ticks = total_idle_ticks -
339 j_dbs_info->prev_cpu_idle_down;
340 j_dbs_info->prev_cpu_idle_down = total_idle_ticks;
341
342 if (tmp_idle_ticks < idle_ticks)
343 idle_ticks = tmp_idle_ticks;
344 }
345
346 down_skip[cpu] = 0;
347 /* if we cannot reduce the frequency anymore, break out early */ 286 /* if we cannot reduce the frequency anymore, break out early */
348 if (policy->cur == policy->min) 287 if (policy->cur == policy->min)
349 return; 288 return;
350 289
351 /* Compute how many ticks there are between two measurements */
352 freq_down_sampling_rate = dbs_tuners_ins.sampling_rate *
353 dbs_tuners_ins.sampling_down_factor;
354 total_ticks = usecs_to_jiffies(freq_down_sampling_rate);
355
356 /* 290 /*
357 * The optimal frequency is the frequency that is the lowest that 291 * The optimal frequency is the frequency that is the lowest that
358 * can support the current CPU usage without triggering the up 292 * can support the current CPU usage without triggering the up
359 * policy. To be safe, we focus 10 points under the threshold. 293 * policy. To be safe, we focus 10 points under the threshold.
360 */ 294 */
361 freq_next = ((total_ticks - idle_ticks) * 100) / total_ticks; 295 if (load < (dbs_tuners_ins.up_threshold - 10)) {
362 freq_next = (freq_next * policy->cur) / 296 unsigned int freq_next;
297 freq_next = (policy->cur * load) /
363 (dbs_tuners_ins.up_threshold - 10); 298 (dbs_tuners_ins.up_threshold - 10);
364 299
365 if (freq_next < policy->min)
366 freq_next = policy->min;
367
368 if (freq_next <= ((policy->cur * 95) / 100))
369 __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L); 300 __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L);
301 }
370} 302}
371 303
372static void do_dbs_timer(void *data) 304static void do_dbs_timer(void *data)
373{ 305{
374 int i; 306 unsigned int cpu = smp_processor_id();
307 struct cpu_dbs_info_s *dbs_info = &per_cpu(cpu_dbs_info, cpu);
308
309 if (!dbs_info->enable)
310 return;
311
375 lock_cpu_hotplug(); 312 lock_cpu_hotplug();
376 mutex_lock(&dbs_mutex); 313 dbs_check_cpu(dbs_info);
377 for_each_online_cpu(i)
378 dbs_check_cpu(i);
379 queue_delayed_work(dbs_workq, &dbs_work,
380 usecs_to_jiffies(dbs_tuners_ins.sampling_rate));
381 mutex_unlock(&dbs_mutex);
382 unlock_cpu_hotplug(); 314 unlock_cpu_hotplug();
315 queue_delayed_work_on(cpu, kondemand_wq, &dbs_info->work,
316 usecs_to_jiffies(dbs_tuners_ins.sampling_rate));
383} 317}
384 318
385static inline void dbs_timer_init(void) 319static inline void dbs_timer_init(unsigned int cpu)
386{ 320{
387 INIT_WORK(&dbs_work, do_dbs_timer, NULL); 321 struct cpu_dbs_info_s *dbs_info = &per_cpu(cpu_dbs_info, cpu);
388 if (!dbs_workq) 322
389 dbs_workq = create_singlethread_workqueue("ondemand"); 323 INIT_WORK(&dbs_info->work, do_dbs_timer, 0);
390 if (!dbs_workq) { 324 queue_delayed_work_on(cpu, kondemand_wq, &dbs_info->work,
391 printk(KERN_ERR "ondemand: Cannot initialize kernel thread\n"); 325 usecs_to_jiffies(dbs_tuners_ins.sampling_rate));
392 return;
393 }
394 queue_delayed_work(dbs_workq, &dbs_work,
395 usecs_to_jiffies(dbs_tuners_ins.sampling_rate));
396 return; 326 return;
397} 327}
398 328
399static inline void dbs_timer_exit(void) 329static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info)
400{ 330{
401 if (dbs_workq) 331 dbs_info->enable = 0;
402 cancel_rearming_delayed_workqueue(dbs_workq, &dbs_work); 332 cancel_delayed_work(&dbs_info->work);
333 flush_workqueue(kondemand_wq);
403} 334}
404 335
405static int cpufreq_governor_dbs(struct cpufreq_policy *policy, 336static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
@@ -413,8 +344,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
413 344
414 switch (event) { 345 switch (event) {
415 case CPUFREQ_GOV_START: 346 case CPUFREQ_GOV_START:
416 if ((!cpu_online(cpu)) || 347 if ((!cpu_online(cpu)) || (!policy->cur))
417 (!policy->cur))
418 return -EINVAL; 348 return -EINVAL;
419 349
420 if (policy->cpuinfo.transition_latency > 350 if (policy->cpuinfo.transition_latency >
@@ -427,18 +357,26 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
427 break; 357 break;
428 358
429 mutex_lock(&dbs_mutex); 359 mutex_lock(&dbs_mutex);
360 dbs_enable++;
361 if (dbs_enable == 1) {
362 kondemand_wq = create_workqueue("kondemand");
363 if (!kondemand_wq) {
364 printk(KERN_ERR "Creation of kondemand failed\n");
365 dbs_enable--;
366 mutex_unlock(&dbs_mutex);
367 return -ENOSPC;
368 }
369 }
430 for_each_cpu_mask(j, policy->cpus) { 370 for_each_cpu_mask(j, policy->cpus) {
431 struct cpu_dbs_info_s *j_dbs_info; 371 struct cpu_dbs_info_s *j_dbs_info;
432 j_dbs_info = &per_cpu(cpu_dbs_info, j); 372 j_dbs_info = &per_cpu(cpu_dbs_info, j);
433 j_dbs_info->cur_policy = policy; 373 j_dbs_info->cur_policy = policy;
434 374
435 j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); 375 j_dbs_info->prev_cpu_idle = get_cpu_idle_time(j);
436 j_dbs_info->prev_cpu_idle_down 376 j_dbs_info->prev_cpu_wall = get_jiffies_64();
437 = j_dbs_info->prev_cpu_idle_up;
438 } 377 }
439 this_dbs_info->enable = 1; 378 this_dbs_info->enable = 1;
440 sysfs_create_group(&policy->kobj, &dbs_attr_group); 379 sysfs_create_group(&policy->kobj, &dbs_attr_group);
441 dbs_enable++;
442 /* 380 /*
443 * Start the timerschedule work, when this governor 381 * Start the timerschedule work, when this governor
444 * is used for first time 382 * is used for first time
@@ -457,50 +395,44 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
457 def_sampling_rate = MIN_STAT_SAMPLING_RATE; 395 def_sampling_rate = MIN_STAT_SAMPLING_RATE;
458 396
459 dbs_tuners_ins.sampling_rate = def_sampling_rate; 397 dbs_tuners_ins.sampling_rate = def_sampling_rate;
460 dbs_timer_init();
461 } 398 }
399 dbs_timer_init(policy->cpu);
462 400
463 mutex_unlock(&dbs_mutex); 401 mutex_unlock(&dbs_mutex);
464 break; 402 break;
465 403
466 case CPUFREQ_GOV_STOP: 404 case CPUFREQ_GOV_STOP:
467 mutex_lock(&dbs_mutex); 405 mutex_lock(&dbs_mutex);
468 this_dbs_info->enable = 0; 406 dbs_timer_exit(this_dbs_info);
469 sysfs_remove_group(&policy->kobj, &dbs_attr_group); 407 sysfs_remove_group(&policy->kobj, &dbs_attr_group);
470 dbs_enable--; 408 dbs_enable--;
471 /*
472 * Stop the timerschedule work, when this governor
473 * is used for first time
474 */
475 if (dbs_enable == 0) 409 if (dbs_enable == 0)
476 dbs_timer_exit(); 410 destroy_workqueue(kondemand_wq);
477 411
478 mutex_unlock(&dbs_mutex); 412 mutex_unlock(&dbs_mutex);
479 413
480 break; 414 break;
481 415
482 case CPUFREQ_GOV_LIMITS: 416 case CPUFREQ_GOV_LIMITS:
483 lock_cpu_hotplug();
484 mutex_lock(&dbs_mutex); 417 mutex_lock(&dbs_mutex);
485 if (policy->max < this_dbs_info->cur_policy->cur) 418 if (policy->max < this_dbs_info->cur_policy->cur)
486 __cpufreq_driver_target( 419 __cpufreq_driver_target(this_dbs_info->cur_policy,
487 this_dbs_info->cur_policy, 420 policy->max,
488 policy->max, CPUFREQ_RELATION_H); 421 CPUFREQ_RELATION_H);
489 else if (policy->min > this_dbs_info->cur_policy->cur) 422 else if (policy->min > this_dbs_info->cur_policy->cur)
490 __cpufreq_driver_target( 423 __cpufreq_driver_target(this_dbs_info->cur_policy,
491 this_dbs_info->cur_policy, 424 policy->min,
492 policy->min, CPUFREQ_RELATION_L); 425 CPUFREQ_RELATION_L);
493 mutex_unlock(&dbs_mutex); 426 mutex_unlock(&dbs_mutex);
494 unlock_cpu_hotplug();
495 break; 427 break;
496 } 428 }
497 return 0; 429 return 0;
498} 430}
499 431
500static struct cpufreq_governor cpufreq_gov_dbs = { 432static struct cpufreq_governor cpufreq_gov_dbs = {
501 .name = "ondemand", 433 .name = "ondemand",
502 .governor = cpufreq_governor_dbs, 434 .governor = cpufreq_governor_dbs,
503 .owner = THIS_MODULE, 435 .owner = THIS_MODULE,
504}; 436};
505 437
506static int __init cpufreq_gov_dbs_init(void) 438static int __init cpufreq_gov_dbs_init(void)
@@ -510,21 +442,15 @@ static int __init cpufreq_gov_dbs_init(void)
510 442
511static void __exit cpufreq_gov_dbs_exit(void) 443static void __exit cpufreq_gov_dbs_exit(void)
512{ 444{
513 /* Make sure that the scheduled work is indeed not running.
514 Assumes the timer has been cancelled first. */
515 if (dbs_workq) {
516 flush_workqueue(dbs_workq);
517 destroy_workqueue(dbs_workq);
518 }
519
520 cpufreq_unregister_governor(&cpufreq_gov_dbs); 445 cpufreq_unregister_governor(&cpufreq_gov_dbs);
521} 446}
522 447
523 448
524MODULE_AUTHOR ("Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>"); 449MODULE_AUTHOR("Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>");
525MODULE_DESCRIPTION ("'cpufreq_ondemand' - A dynamic cpufreq governor for " 450MODULE_AUTHOR("Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>");
526 "Low Latency Frequency Transition capable processors"); 451MODULE_DESCRIPTION("'cpufreq_ondemand' - A dynamic cpufreq governor for "
527MODULE_LICENSE ("GPL"); 452 "Low Latency Frequency Transition capable processors");
453MODULE_LICENSE("GPL");
528 454
529module_init(cpufreq_gov_dbs_init); 455module_init(cpufreq_gov_dbs_init);
530module_exit(cpufreq_gov_dbs_exit); 456module_exit(cpufreq_gov_dbs_exit);
diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c
index 44ae5e5b94cf..a06c204589cd 100644
--- a/drivers/cpufreq/cpufreq_userspace.c
+++ b/drivers/cpufreq/cpufreq_userspace.c
@@ -18,6 +18,7 @@
18#include <linux/spinlock.h> 18#include <linux/spinlock.h>
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/cpufreq.h> 20#include <linux/cpufreq.h>
21#include <linux/cpu.h>
21#include <linux/types.h> 22#include <linux/types.h>
22#include <linux/fs.h> 23#include <linux/fs.h>
23#include <linux/sysfs.h> 24#include <linux/sysfs.h>
@@ -70,6 +71,7 @@ static int cpufreq_set(unsigned int freq, struct cpufreq_policy *policy)
70 71
71 dprintk("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq); 72 dprintk("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq);
72 73
74 lock_cpu_hotplug();
73 mutex_lock(&userspace_mutex); 75 mutex_lock(&userspace_mutex);
74 if (!cpu_is_managed[policy->cpu]) 76 if (!cpu_is_managed[policy->cpu])
75 goto err; 77 goto err;
@@ -92,6 +94,7 @@ static int cpufreq_set(unsigned int freq, struct cpufreq_policy *policy)
92 94
93 err: 95 err:
94 mutex_unlock(&userspace_mutex); 96 mutex_unlock(&userspace_mutex);
97 unlock_cpu_hotplug();
95 return ret; 98 return ret;
96} 99}
97 100
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 17ee684144f9..b643d71298a9 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -59,6 +59,9 @@
59#define AES_EXTENDED_KEY_SIZE 64 /* in uint32_t units */ 59#define AES_EXTENDED_KEY_SIZE 64 /* in uint32_t units */
60#define AES_EXTENDED_KEY_SIZE_B (AES_EXTENDED_KEY_SIZE * sizeof(uint32_t)) 60#define AES_EXTENDED_KEY_SIZE_B (AES_EXTENDED_KEY_SIZE * sizeof(uint32_t))
61 61
62/* Whenever making any changes to the following
63 * structure *make sure* you keep E, d_data
64 * and cword aligned on 16 Bytes boundaries!!! */
62struct aes_ctx { 65struct aes_ctx {
63 struct { 66 struct {
64 struct cword encrypt; 67 struct cword encrypt;
@@ -66,8 +69,10 @@ struct aes_ctx {
66 } cword; 69 } cword;
67 u32 *D; 70 u32 *D;
68 int key_length; 71 int key_length;
69 u32 E[AES_EXTENDED_KEY_SIZE]; 72 u32 E[AES_EXTENDED_KEY_SIZE]
70 u32 d_data[AES_EXTENDED_KEY_SIZE]; 73 __attribute__ ((__aligned__(PADLOCK_ALIGNMENT)));
74 u32 d_data[AES_EXTENDED_KEY_SIZE]
75 __attribute__ ((__aligned__(PADLOCK_ALIGNMENT)));
71}; 76};
72 77
73/* ====== Key management routines ====== */ 78/* ====== Key management routines ====== */
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 5829143558e1..15278044295c 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -166,8 +166,8 @@ static struct dma_chan *dma_client_chan_alloc(struct dma_client *client)
166} 166}
167 167
168/** 168/**
169 * dma_client_chan_free - release a DMA channel 169 * dma_chan_cleanup - release a DMA channel's resources
170 * @chan: &dma_chan 170 * @kref: kernel reference structure that contains the DMA channel device
171 */ 171 */
172void dma_chan_cleanup(struct kref *kref) 172void dma_chan_cleanup(struct kref *kref)
173{ 173{
@@ -199,7 +199,7 @@ static void dma_client_chan_free(struct dma_chan *chan)
199 * dma_chans_rebalance - reallocate channels to clients 199 * dma_chans_rebalance - reallocate channels to clients
200 * 200 *
201 * When the number of DMA channel in the system changes, 201 * When the number of DMA channel in the system changes,
202 * channels need to be rebalanced among clients 202 * channels need to be rebalanced among clients.
203 */ 203 */
204static void dma_chans_rebalance(void) 204static void dma_chans_rebalance(void)
205{ 205{
@@ -264,7 +264,7 @@ struct dma_client *dma_async_client_register(dma_event_callback event_callback)
264 264
265/** 265/**
266 * dma_async_client_unregister - unregister a client and free the &dma_client 266 * dma_async_client_unregister - unregister a client and free the &dma_client
267 * @client: 267 * @client: &dma_client to free
268 * 268 *
269 * Force frees any allocated DMA channels, frees the &dma_client memory 269 * Force frees any allocated DMA channels, frees the &dma_client memory
270 */ 270 */
@@ -306,7 +306,7 @@ void dma_async_client_chan_request(struct dma_client *client,
306} 306}
307 307
308/** 308/**
309 * dma_async_device_register - 309 * dma_async_device_register - registers DMA devices found
310 * @device: &dma_device 310 * @device: &dma_device
311 */ 311 */
312int dma_async_device_register(struct dma_device *device) 312int dma_async_device_register(struct dma_device *device)
@@ -348,8 +348,8 @@ int dma_async_device_register(struct dma_device *device)
348} 348}
349 349
350/** 350/**
351 * dma_async_device_unregister - 351 * dma_async_device_cleanup - function called when all references are released
352 * @device: &dma_device 352 * @kref: kernel reference object
353 */ 353 */
354static void dma_async_device_cleanup(struct kref *kref) 354static void dma_async_device_cleanup(struct kref *kref)
355{ 355{
@@ -359,7 +359,11 @@ static void dma_async_device_cleanup(struct kref *kref)
359 complete(&device->done); 359 complete(&device->done);
360} 360}
361 361
362void dma_async_device_unregister(struct dma_device* device) 362/**
363 * dma_async_device_unregister - unregisters DMA devices
364 * @device: &dma_device
365 */
366void dma_async_device_unregister(struct dma_device *device)
363{ 367{
364 struct dma_chan *chan; 368 struct dma_chan *chan;
365 unsigned long flags; 369 unsigned long flags;
diff --git a/drivers/dma/ioatdma.c b/drivers/dma/ioatdma.c
index ecad8f65d2d4..dbd4d6c3698e 100644
--- a/drivers/dma/ioatdma.c
+++ b/drivers/dma/ioatdma.c
@@ -217,7 +217,7 @@ static void ioat_dma_free_chan_resources(struct dma_chan *chan)
217 217
218/** 218/**
219 * do_ioat_dma_memcpy - actual function that initiates a IOAT DMA transaction 219 * do_ioat_dma_memcpy - actual function that initiates a IOAT DMA transaction
220 * @chan: IOAT DMA channel handle 220 * @ioat_chan: IOAT DMA channel handle
221 * @dest: DMA destination address 221 * @dest: DMA destination address
222 * @src: DMA source address 222 * @src: DMA source address
223 * @len: transaction length in bytes 223 * @len: transaction length in bytes
@@ -383,7 +383,7 @@ static dma_cookie_t ioat_dma_memcpy_buf_to_pg(struct dma_chan *chan,
383 * @dest_off: offset into that page 383 * @dest_off: offset into that page
384 * @src_pg: pointer to the page to copy from 384 * @src_pg: pointer to the page to copy from
385 * @src_off: offset into that page 385 * @src_off: offset into that page
386 * @len: transaction length in bytes. This is guaranteed to not make a copy 386 * @len: transaction length in bytes. This is guaranteed not to make a copy
387 * across a page boundary. 387 * across a page boundary.
388 */ 388 */
389 389
@@ -407,7 +407,7 @@ static dma_cookie_t ioat_dma_memcpy_pg_to_pg(struct dma_chan *chan,
407} 407}
408 408
409/** 409/**
410 * ioat_dma_memcpy_issue_pending - push potentially unrecognoized appended descriptors to hw 410 * ioat_dma_memcpy_issue_pending - push potentially unrecognized appended descriptors to hw
411 * @chan: DMA channel handle 411 * @chan: DMA channel handle
412 */ 412 */
413 413
@@ -510,6 +510,8 @@ static void ioat_dma_memcpy_cleanup(struct ioat_dma_chan *chan)
510 * ioat_dma_is_complete - poll the status of a IOAT DMA transaction 510 * ioat_dma_is_complete - poll the status of a IOAT DMA transaction
511 * @chan: IOAT DMA channel handle 511 * @chan: IOAT DMA channel handle
512 * @cookie: DMA transaction identifier 512 * @cookie: DMA transaction identifier
513 * @done: if not %NULL, updated with last completed transaction
514 * @used: if not %NULL, updated with last used transaction
513 */ 515 */
514 516
515static enum dma_status ioat_dma_is_complete(struct dma_chan *chan, 517static enum dma_status ioat_dma_is_complete(struct dma_chan *chan,
@@ -826,7 +828,7 @@ static int __init ioat_init_module(void)
826 /* if forced, worst case is that rmmod hangs */ 828 /* if forced, worst case is that rmmod hangs */
827 __unsafe(THIS_MODULE); 829 __unsafe(THIS_MODULE);
828 830
829 pci_module_init(&ioat_pci_drv); 831 return pci_register_driver(&ioat_pci_drv);
830} 832}
831 833
832module_init(ioat_init_module); 834module_init(ioat_init_module);
diff --git a/drivers/dma/ioatdma_registers.h b/drivers/dma/ioatdma_registers.h
index 41a21ab2b000..a30c7349075a 100644
--- a/drivers/dma/ioatdma_registers.h
+++ b/drivers/dma/ioatdma_registers.h
@@ -76,7 +76,7 @@
76#define IOAT_CHANSTS_OFFSET 0x04 /* 64-bit Channel Status Register */ 76#define IOAT_CHANSTS_OFFSET 0x04 /* 64-bit Channel Status Register */
77#define IOAT_CHANSTS_OFFSET_LOW 0x04 77#define IOAT_CHANSTS_OFFSET_LOW 0x04
78#define IOAT_CHANSTS_OFFSET_HIGH 0x08 78#define IOAT_CHANSTS_OFFSET_HIGH 0x08
79#define IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR 0xFFFFFFFFFFFFFFC0 79#define IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR 0xFFFFFFFFFFFFFFC0UL
80#define IOAT_CHANSTS_SOFT_ERR 0x0000000000000010 80#define IOAT_CHANSTS_SOFT_ERR 0x0000000000000010
81#define IOAT_CHANSTS_DMA_TRANSFER_STATUS 0x0000000000000007 81#define IOAT_CHANSTS_DMA_TRANSFER_STATUS 0x0000000000000007
82#define IOAT_CHANSTS_DMA_TRANSFER_STATUS_ACTIVE 0x0 82#define IOAT_CHANSTS_DMA_TRANSFER_STATUS_ACTIVE 0x0
diff --git a/drivers/dma/iovlock.c b/drivers/dma/iovlock.c
index 5ed327e453a2..d637555a833b 100644
--- a/drivers/dma/iovlock.c
+++ b/drivers/dma/iovlock.c
@@ -31,7 +31,7 @@
31#include <asm/io.h> 31#include <asm/io.h>
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33 33
34int num_pages_spanned(struct iovec *iov) 34static int num_pages_spanned(struct iovec *iov)
35{ 35{
36 return 36 return
37 ((PAGE_ALIGN((unsigned long)iov->iov_base + iov->iov_len) - 37 ((PAGE_ALIGN((unsigned long)iov->iov_base + iov->iov_len) -
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index 3a7cfe88b169..4bde30bb3be7 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * edac_mc kernel module 2 * edac_mc kernel module
3 * (C) 2005 Linux Networx (http://lnxi.com) 3 * (C) 2005, 2006 Linux Networx (http://lnxi.com)
4 * This file may be distributed under the terms of the 4 * This file may be distributed under the terms of the
5 * GNU General Public License. 5 * GNU General Public License.
6 * 6 *
@@ -33,13 +33,8 @@
33#include <asm/edac.h> 33#include <asm/edac.h>
34#include "edac_mc.h" 34#include "edac_mc.h"
35 35
36#define EDAC_MC_VERSION "Ver: 2.0.0 " __DATE__ 36#define EDAC_MC_VERSION "Ver: 2.0.1 " __DATE__
37 37
38/* For now, disable the EDAC sysfs code. The sysfs interface that EDAC
39 * presents to user space needs more thought, and is likely to change
40 * substantially.
41 */
42#define DISABLE_EDAC_SYSFS
43 38
44#ifdef CONFIG_EDAC_DEBUG 39#ifdef CONFIG_EDAC_DEBUG
45/* Values of 0 to 4 will generate output */ 40/* Values of 0 to 4 will generate output */
@@ -64,31 +59,12 @@ static int check_pci_parity = 0; /* default YES check PCI parity */
64static int panic_on_pci_parity; /* default no panic on PCI Parity */ 59static int panic_on_pci_parity; /* default no panic on PCI Parity */
65static atomic_t pci_parity_count = ATOMIC_INIT(0); 60static atomic_t pci_parity_count = ATOMIC_INIT(0);
66 61
67/* Structure of the whitelist and blacklist arrays */
68struct edac_pci_device_list {
69 unsigned int vendor; /* Vendor ID */
70 unsigned int device; /* Deviice ID */
71};
72
73#define MAX_LISTED_PCI_DEVICES 32
74
75/* List of PCI devices (vendor-id:device-id) that should be skipped */
76static struct edac_pci_device_list pci_blacklist[MAX_LISTED_PCI_DEVICES];
77static int pci_blacklist_count;
78
79/* List of PCI devices (vendor-id:device-id) that should be scanned */
80static struct edac_pci_device_list pci_whitelist[MAX_LISTED_PCI_DEVICES];
81static int pci_whitelist_count ;
82
83#ifndef DISABLE_EDAC_SYSFS
84static struct kobject edac_pci_kobj; /* /sys/devices/system/edac/pci */ 62static struct kobject edac_pci_kobj; /* /sys/devices/system/edac/pci */
85static struct completion edac_pci_kobj_complete; 63static struct completion edac_pci_kobj_complete;
86#endif /* DISABLE_EDAC_SYSFS */
87#endif /* CONFIG_PCI */ 64#endif /* CONFIG_PCI */
88 65
89/* START sysfs data and methods */ 66/* START sysfs data and methods */
90 67
91#ifndef DISABLE_EDAC_SYSFS
92 68
93static const char *mem_types[] = { 69static const char *mem_types[] = {
94 [MEM_EMPTY] = "Empty", 70 [MEM_EMPTY] = "Empty",
@@ -147,18 +123,10 @@ static struct completion edac_memctrl_kobj_complete;
147 * /sys/devices/system/edac/mc; 123 * /sys/devices/system/edac/mc;
148 * data structures and methods 124 * data structures and methods
149 */ 125 */
150#if 0
151static ssize_t memctrl_string_show(void *ptr, char *buffer)
152{
153 char *value = (char*) ptr;
154 return sprintf(buffer, "%s\n", value);
155}
156#endif
157
158static ssize_t memctrl_int_show(void *ptr, char *buffer) 126static ssize_t memctrl_int_show(void *ptr, char *buffer)
159{ 127{
160 int *value = (int*) ptr; 128 int *value = (int*) ptr;
161 return sprintf(buffer, "%d\n", *value); 129 return sprintf(buffer, "%u\n", *value);
162} 130}
163 131
164static ssize_t memctrl_int_store(void *ptr, const char *buffer, size_t count) 132static ssize_t memctrl_int_store(void *ptr, const char *buffer, size_t count)
@@ -224,11 +192,6 @@ struct memctrl_dev_attribute attr_##_name = { \
224 .store = _store, \ 192 .store = _store, \
225}; 193};
226 194
227/* cwrow<id> attribute f*/
228#if 0
229MEMCTRL_STRING_ATTR(mc_version,EDAC_MC_VERSION,S_IRUGO,memctrl_string_show,NULL);
230#endif
231
232/* csrow<id> control files */ 195/* csrow<id> control files */
233MEMCTRL_ATTR(panic_on_ue,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store); 196MEMCTRL_ATTR(panic_on_ue,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
234MEMCTRL_ATTR(log_ue,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store); 197MEMCTRL_ATTR(log_ue,S_IRUGO|S_IWUSR,memctrl_int_show,memctrl_int_store);
@@ -257,8 +220,6 @@ static struct kobj_type ktype_memctrl = {
257 .default_attrs = (struct attribute **) memctrl_attr, 220 .default_attrs = (struct attribute **) memctrl_attr,
258}; 221};
259 222
260#endif /* DISABLE_EDAC_SYSFS */
261
262/* Initialize the main sysfs entries for edac: 223/* Initialize the main sysfs entries for edac:
263 * /sys/devices/system/edac 224 * /sys/devices/system/edac
264 * 225 *
@@ -268,11 +229,6 @@ static struct kobj_type ktype_memctrl = {
268 * !0 FAILURE 229 * !0 FAILURE
269 */ 230 */
270static int edac_sysfs_memctrl_setup(void) 231static int edac_sysfs_memctrl_setup(void)
271#ifdef DISABLE_EDAC_SYSFS
272{
273 return 0;
274}
275#else
276{ 232{
277 int err=0; 233 int err=0;
278 234
@@ -304,7 +260,6 @@ static int edac_sysfs_memctrl_setup(void)
304 260
305 return err; 261 return err;
306} 262}
307#endif /* DISABLE_EDAC_SYSFS */
308 263
309/* 264/*
310 * MC teardown: 265 * MC teardown:
@@ -312,7 +267,6 @@ static int edac_sysfs_memctrl_setup(void)
312 */ 267 */
313static void edac_sysfs_memctrl_teardown(void) 268static void edac_sysfs_memctrl_teardown(void)
314{ 269{
315#ifndef DISABLE_EDAC_SYSFS
316 debugf0("MC: " __FILE__ ": %s()\n", __func__); 270 debugf0("MC: " __FILE__ ": %s()\n", __func__);
317 271
318 /* Unregister the MC's kobject and wait for reference count to reach 272 /* Unregister the MC's kobject and wait for reference count to reach
@@ -324,144 +278,9 @@ static void edac_sysfs_memctrl_teardown(void)
324 278
325 /* Unregister the 'edac' object */ 279 /* Unregister the 'edac' object */
326 sysdev_class_unregister(&edac_class); 280 sysdev_class_unregister(&edac_class);
327#endif /* DISABLE_EDAC_SYSFS */
328} 281}
329 282
330#ifdef CONFIG_PCI 283#ifdef CONFIG_PCI
331
332#ifndef DISABLE_EDAC_SYSFS
333
334/*
335 * /sys/devices/system/edac/pci;
336 * data structures and methods
337 */
338
339struct list_control {
340 struct edac_pci_device_list *list;
341 int *count;
342};
343
344#if 0
345/* Output the list as: vendor_id:device:id<,vendor_id:device_id> */
346static ssize_t edac_pci_list_string_show(void *ptr, char *buffer)
347{
348 struct list_control *listctl;
349 struct edac_pci_device_list *list;
350 char *p = buffer;
351 int len=0;
352 int i;
353
354 listctl = ptr;
355 list = listctl->list;
356
357 for (i = 0; i < *(listctl->count); i++, list++ ) {
358 if (len > 0)
359 len += snprintf(p + len, (PAGE_SIZE-len), ",");
360
361 len += snprintf(p + len,
362 (PAGE_SIZE-len),
363 "%x:%x",
364 list->vendor,list->device);
365 }
366
367 len += snprintf(p + len,(PAGE_SIZE-len), "\n");
368 return (ssize_t) len;
369}
370
371/**
372 *
373 * Scan string from **s to **e looking for one 'vendor:device' tuple
374 * where each field is a hex value
375 *
376 * return 0 if an entry is NOT found
377 * return 1 if an entry is found
378 * fill in *vendor_id and *device_id with values found
379 *
380 * In both cases, make sure *s has been moved forward toward *e
381 */
382static int parse_one_device(const char **s,const char **e,
383 unsigned int *vendor_id, unsigned int *device_id)
384{
385 const char *runner, *p;
386
387 /* if null byte, we are done */
388 if (!**s) {
389 (*s)++; /* keep *s moving */
390 return 0;
391 }
392
393 /* skip over newlines & whitespace */
394 if ((**s == '\n') || isspace(**s)) {
395 (*s)++;
396 return 0;
397 }
398
399 if (!isxdigit(**s)) {
400 (*s)++;
401 return 0;
402 }
403
404 /* parse vendor_id */
405 runner = *s;
406
407 while (runner < *e) {
408 /* scan for vendor:device delimiter */
409 if (*runner == ':') {
410 *vendor_id = simple_strtol((char*) *s, (char**) &p, 16);
411 runner = p + 1;
412 break;
413 }
414
415 runner++;
416 }
417
418 if (!isxdigit(*runner)) {
419 *s = ++runner;
420 return 0;
421 }
422
423 /* parse device_id */
424 if (runner < *e) {
425 *device_id = simple_strtol((char*)runner, (char**)&p, 16);
426 runner = p;
427 }
428
429 *s = runner;
430 return 1;
431}
432
433static ssize_t edac_pci_list_string_store(void *ptr, const char *buffer,
434 size_t count)
435{
436 struct list_control *listctl;
437 struct edac_pci_device_list *list;
438 unsigned int vendor_id, device_id;
439 const char *s, *e;
440 int *index;
441
442 s = (char*)buffer;
443 e = s + count;
444 listctl = ptr;
445 list = listctl->list;
446 index = listctl->count;
447 *index = 0;
448
449 while (*index < MAX_LISTED_PCI_DEVICES) {
450 if (parse_one_device(&s,&e,&vendor_id,&device_id)) {
451 list[ *index ].vendor = vendor_id;
452 list[ *index ].device = device_id;
453 (*index)++;
454 }
455
456 /* check for all data consume */
457 if (s >= e)
458 break;
459 }
460
461 return count;
462}
463
464#endif
465static ssize_t edac_pci_int_show(void *ptr, char *buffer) 284static ssize_t edac_pci_int_show(void *ptr, char *buffer)
466{ 285{
467 int *value = ptr; 286 int *value = ptr;
@@ -529,31 +348,6 @@ struct edac_pci_dev_attribute edac_pci_attr_##_name = { \
529 .store = _store, \ 348 .store = _store, \
530}; 349};
531 350
532#if 0
533static struct list_control pci_whitelist_control = {
534 .list = pci_whitelist,
535 .count = &pci_whitelist_count
536};
537
538static struct list_control pci_blacklist_control = {
539 .list = pci_blacklist,
540 .count = &pci_blacklist_count
541};
542
543/* whitelist attribute */
544EDAC_PCI_STRING_ATTR(pci_parity_whitelist,
545 &pci_whitelist_control,
546 S_IRUGO|S_IWUSR,
547 edac_pci_list_string_show,
548 edac_pci_list_string_store);
549
550EDAC_PCI_STRING_ATTR(pci_parity_blacklist,
551 &pci_blacklist_control,
552 S_IRUGO|S_IWUSR,
553 edac_pci_list_string_show,
554 edac_pci_list_string_store);
555#endif
556
557/* PCI Parity control files */ 351/* PCI Parity control files */
558EDAC_PCI_ATTR(check_pci_parity, S_IRUGO|S_IWUSR, edac_pci_int_show, 352EDAC_PCI_ATTR(check_pci_parity, S_IRUGO|S_IWUSR, edac_pci_int_show,
559 edac_pci_int_store); 353 edac_pci_int_store);
@@ -582,18 +376,11 @@ static struct kobj_type ktype_edac_pci = {
582 .default_attrs = (struct attribute **) edac_pci_attr, 376 .default_attrs = (struct attribute **) edac_pci_attr,
583}; 377};
584 378
585#endif /* DISABLE_EDAC_SYSFS */
586
587/** 379/**
588 * edac_sysfs_pci_setup() 380 * edac_sysfs_pci_setup()
589 * 381 *
590 */ 382 */
591static int edac_sysfs_pci_setup(void) 383static int edac_sysfs_pci_setup(void)
592#ifdef DISABLE_EDAC_SYSFS
593{
594 return 0;
595}
596#else
597{ 384{
598 int err; 385 int err;
599 386
@@ -617,16 +404,13 @@ static int edac_sysfs_pci_setup(void)
617 404
618 return err; 405 return err;
619} 406}
620#endif /* DISABLE_EDAC_SYSFS */
621 407
622static void edac_sysfs_pci_teardown(void) 408static void edac_sysfs_pci_teardown(void)
623{ 409{
624#ifndef DISABLE_EDAC_SYSFS
625 debugf0("%s()\n", __func__); 410 debugf0("%s()\n", __func__);
626 init_completion(&edac_pci_kobj_complete); 411 init_completion(&edac_pci_kobj_complete);
627 kobject_unregister(&edac_pci_kobj); 412 kobject_unregister(&edac_pci_kobj);
628 wait_for_completion(&edac_pci_kobj_complete); 413 wait_for_completion(&edac_pci_kobj_complete);
629#endif
630} 414}
631 415
632 416
@@ -756,36 +540,6 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
756} 540}
757 541
758/* 542/*
759 * check_dev_on_list: Scan for a PCI device on a white/black list
760 * @list: an EDAC &edac_pci_device_list white/black list pointer
761 * @free_index: index of next free entry on the list
762 * @pci_dev: PCI Device pointer
763 *
764 * see if list contains the device.
765 *
766 * Returns: 0 not found
767 * 1 found on list
768 */
769static int check_dev_on_list(struct edac_pci_device_list *list,
770 int free_index, struct pci_dev *dev)
771{
772 int i;
773 int rc = 0; /* Assume not found */
774 unsigned short vendor=dev->vendor;
775 unsigned short device=dev->device;
776
777 /* Scan the list, looking for a vendor/device match */
778 for (i = 0; i < free_index; i++, list++ ) {
779 if ((list->vendor == vendor ) && (list->device == device )) {
780 rc = 1;
781 break;
782 }
783 }
784
785 return rc;
786}
787
788/*
789 * pci_dev parity list iterator 543 * pci_dev parity list iterator
790 * Scan the PCI device list for one iteration, looking for SERRORs 544 * Scan the PCI device list for one iteration, looking for SERRORs
791 * Master Parity ERRORS or Parity ERRORs on primary or secondary devices 545 * Master Parity ERRORS or Parity ERRORs on primary or secondary devices
@@ -799,22 +553,7 @@ static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t fn)
799 * bumped until we are done with it 553 * bumped until we are done with it
800 */ 554 */
801 while((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 555 while((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
802 /* if whitelist exists then it has priority, so only scan 556 fn(dev);
803 * those devices on the whitelist
804 */
805 if (pci_whitelist_count > 0 ) {
806 if (check_dev_on_list(pci_whitelist,
807 pci_whitelist_count, dev))
808 fn(dev);
809 } else {
810 /*
811 * if no whitelist, then check if this devices is
812 * blacklisted
813 */
814 if (!check_dev_on_list(pci_blacklist,
815 pci_blacklist_count, dev))
816 fn(dev);
817 }
818 } 557 }
819} 558}
820 559
@@ -855,154 +594,101 @@ static inline void clear_pci_parity_errors(void)
855 594
856#else /* CONFIG_PCI */ 595#else /* CONFIG_PCI */
857 596
858static inline void do_pci_parity_check(void) 597/* pre-process these away */
859{ 598#define do_pci_parity_check()
860 /* no-op */ 599#define clear_pci_parity_errors()
861} 600#define edac_sysfs_pci_teardown()
862 601#define edac_sysfs_pci_setup() (0)
863static inline void clear_pci_parity_errors(void)
864{
865 /* no-op */
866}
867
868static void edac_sysfs_pci_teardown(void)
869{
870}
871 602
872static int edac_sysfs_pci_setup(void)
873{
874 return 0;
875}
876#endif /* CONFIG_PCI */ 603#endif /* CONFIG_PCI */
877 604
878#ifndef DISABLE_EDAC_SYSFS 605/* EDAC sysfs CSROW data structures and methods
879 606 */
880/* EDAC sysfs CSROW data structures and methods */
881
882/* Set of more detailed csrow<id> attribute show/store functions */
883static ssize_t csrow_ch0_dimm_label_show(struct csrow_info *csrow, char *data)
884{
885 ssize_t size = 0;
886
887 if (csrow->nr_channels > 0) {
888 size = snprintf(data, EDAC_MC_LABEL_LEN,"%s\n",
889 csrow->channels[0].label);
890 }
891
892 return size;
893}
894 607
895static ssize_t csrow_ch1_dimm_label_show(struct csrow_info *csrow, char *data) 608/* Set of more default csrow<id> attribute show/store functions */
609static ssize_t csrow_ue_count_show(struct csrow_info *csrow, char *data, int private)
896{ 610{
897 ssize_t size = 0; 611 return sprintf(data,"%u\n", csrow->ue_count);
898
899 if (csrow->nr_channels > 0) {
900 size = snprintf(data, EDAC_MC_LABEL_LEN, "%s\n",
901 csrow->channels[1].label);
902 }
903
904 return size;
905} 612}
906 613
907static ssize_t csrow_ch0_dimm_label_store(struct csrow_info *csrow, 614static ssize_t csrow_ce_count_show(struct csrow_info *csrow, char *data, int private)
908 const char *data, size_t size)
909{ 615{
910 ssize_t max_size = 0; 616 return sprintf(data,"%u\n", csrow->ce_count);
911
912 if (csrow->nr_channels > 0) {
913 max_size = min((ssize_t)size,(ssize_t)EDAC_MC_LABEL_LEN-1);
914 strncpy(csrow->channels[0].label, data, max_size);
915 csrow->channels[0].label[max_size] = '\0';
916 }
917
918 return size;
919} 617}
920 618
921static ssize_t csrow_ch1_dimm_label_store(struct csrow_info *csrow, 619static ssize_t csrow_size_show(struct csrow_info *csrow, char *data, int private)
922 const char *data, size_t size)
923{ 620{
924 ssize_t max_size = 0; 621 return sprintf(data,"%u\n", PAGES_TO_MiB(csrow->nr_pages));
925
926 if (csrow->nr_channels > 1) {
927 max_size = min((ssize_t)size,(ssize_t)EDAC_MC_LABEL_LEN-1);
928 strncpy(csrow->channels[1].label, data, max_size);
929 csrow->channels[1].label[max_size] = '\0';
930 }
931
932 return max_size;
933} 622}
934 623
935static ssize_t csrow_ue_count_show(struct csrow_info *csrow, char *data) 624static ssize_t csrow_mem_type_show(struct csrow_info *csrow, char *data, int private)
936{ 625{
937 return sprintf(data,"%u\n", csrow->ue_count); 626 return sprintf(data,"%s\n", mem_types[csrow->mtype]);
938} 627}
939 628
940static ssize_t csrow_ce_count_show(struct csrow_info *csrow, char *data) 629static ssize_t csrow_dev_type_show(struct csrow_info *csrow, char *data, int private)
941{ 630{
942 return sprintf(data,"%u\n", csrow->ce_count); 631 return sprintf(data,"%s\n", dev_types[csrow->dtype]);
943} 632}
944 633
945static ssize_t csrow_ch0_ce_count_show(struct csrow_info *csrow, char *data) 634static ssize_t csrow_edac_mode_show(struct csrow_info *csrow, char *data, int private)
946{ 635{
947 ssize_t size = 0; 636 return sprintf(data,"%s\n", edac_caps[csrow->edac_mode]);
948
949 if (csrow->nr_channels > 0) {
950 size = sprintf(data,"%u\n", csrow->channels[0].ce_count);
951 }
952
953 return size;
954} 637}
955 638
956static ssize_t csrow_ch1_ce_count_show(struct csrow_info *csrow, char *data) 639/* show/store functions for DIMM Label attributes */
640static ssize_t channel_dimm_label_show(struct csrow_info *csrow,
641 char *data, int channel)
957{ 642{
958 ssize_t size = 0; 643 return snprintf(data, EDAC_MC_LABEL_LEN,"%s",
959 644 csrow->channels[channel].label);
960 if (csrow->nr_channels > 1) {
961 size = sprintf(data,"%u\n", csrow->channels[1].ce_count);
962 }
963
964 return size;
965} 645}
966 646
967static ssize_t csrow_size_show(struct csrow_info *csrow, char *data) 647static ssize_t channel_dimm_label_store(struct csrow_info *csrow,
648 const char *data,
649 size_t count,
650 int channel)
968{ 651{
969 return sprintf(data,"%u\n", PAGES_TO_MiB(csrow->nr_pages)); 652 ssize_t max_size = 0;
970}
971 653
972static ssize_t csrow_mem_type_show(struct csrow_info *csrow, char *data) 654 max_size = min((ssize_t)count,(ssize_t)EDAC_MC_LABEL_LEN-1);
973{ 655 strncpy(csrow->channels[channel].label, data, max_size);
974 return sprintf(data,"%s\n", mem_types[csrow->mtype]); 656 csrow->channels[channel].label[max_size] = '\0';
975}
976 657
977static ssize_t csrow_dev_type_show(struct csrow_info *csrow, char *data) 658 return max_size;
978{
979 return sprintf(data,"%s\n", dev_types[csrow->dtype]);
980} 659}
981 660
982static ssize_t csrow_edac_mode_show(struct csrow_info *csrow, char *data) 661/* show function for dynamic chX_ce_count attribute */
662static ssize_t channel_ce_count_show(struct csrow_info *csrow,
663 char *data,
664 int channel)
983{ 665{
984 return sprintf(data,"%s\n", edac_caps[csrow->edac_mode]); 666 return sprintf(data, "%u\n", csrow->channels[channel].ce_count);
985} 667}
986 668
669/* csrow specific attribute structure */
987struct csrowdev_attribute { 670struct csrowdev_attribute {
988 struct attribute attr; 671 struct attribute attr;
989 ssize_t (*show)(struct csrow_info *,char *); 672 ssize_t (*show)(struct csrow_info *,char *,int);
990 ssize_t (*store)(struct csrow_info *, const char *,size_t); 673 ssize_t (*store)(struct csrow_info *, const char *,size_t,int);
674 int private;
991}; 675};
992 676
993#define to_csrow(k) container_of(k, struct csrow_info, kobj) 677#define to_csrow(k) container_of(k, struct csrow_info, kobj)
994#define to_csrowdev_attr(a) container_of(a, struct csrowdev_attribute, attr) 678#define to_csrowdev_attr(a) container_of(a, struct csrowdev_attribute, attr)
995 679
996/* Set of show/store higher level functions for csrow objects */ 680/* Set of show/store higher level functions for default csrow attributes */
997static ssize_t csrowdev_show(struct kobject *kobj, struct attribute *attr, 681static ssize_t csrowdev_show(struct kobject *kobj,
998 char *buffer) 682 struct attribute *attr,
683 char *buffer)
999{ 684{
1000 struct csrow_info *csrow = to_csrow(kobj); 685 struct csrow_info *csrow = to_csrow(kobj);
1001 struct csrowdev_attribute *csrowdev_attr = to_csrowdev_attr(attr); 686 struct csrowdev_attribute *csrowdev_attr = to_csrowdev_attr(attr);
1002 687
1003 if (csrowdev_attr->show) 688 if (csrowdev_attr->show)
1004 return csrowdev_attr->show(csrow, buffer); 689 return csrowdev_attr->show(csrow,
1005 690 buffer,
691 csrowdev_attr->private);
1006 return -EIO; 692 return -EIO;
1007} 693}
1008 694
@@ -1013,8 +699,10 @@ static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr,
1013 struct csrowdev_attribute * csrowdev_attr = to_csrowdev_attr(attr); 699 struct csrowdev_attribute * csrowdev_attr = to_csrowdev_attr(attr);
1014 700
1015 if (csrowdev_attr->store) 701 if (csrowdev_attr->store)
1016 return csrowdev_attr->store(csrow, buffer, count); 702 return csrowdev_attr->store(csrow,
1017 703 buffer,
704 count,
705 csrowdev_attr->private);
1018 return -EIO; 706 return -EIO;
1019} 707}
1020 708
@@ -1023,69 +711,157 @@ static struct sysfs_ops csrowfs_ops = {
1023 .store = csrowdev_store 711 .store = csrowdev_store
1024}; 712};
1025 713
1026#define CSROWDEV_ATTR(_name,_mode,_show,_store) \ 714#define CSROWDEV_ATTR(_name,_mode,_show,_store,_private) \
1027struct csrowdev_attribute attr_##_name = { \ 715struct csrowdev_attribute attr_##_name = { \
1028 .attr = {.name = __stringify(_name), .mode = _mode }, \ 716 .attr = {.name = __stringify(_name), .mode = _mode }, \
1029 .show = _show, \ 717 .show = _show, \
1030 .store = _store, \ 718 .store = _store, \
719 .private = _private, \
1031}; 720};
1032 721
1033/* cwrow<id>/attribute files */ 722/* default cwrow<id>/attribute files */
1034CSROWDEV_ATTR(size_mb,S_IRUGO,csrow_size_show,NULL); 723CSROWDEV_ATTR(size_mb,S_IRUGO,csrow_size_show,NULL,0);
1035CSROWDEV_ATTR(dev_type,S_IRUGO,csrow_dev_type_show,NULL); 724CSROWDEV_ATTR(dev_type,S_IRUGO,csrow_dev_type_show,NULL,0);
1036CSROWDEV_ATTR(mem_type,S_IRUGO,csrow_mem_type_show,NULL); 725CSROWDEV_ATTR(mem_type,S_IRUGO,csrow_mem_type_show,NULL,0);
1037CSROWDEV_ATTR(edac_mode,S_IRUGO,csrow_edac_mode_show,NULL); 726CSROWDEV_ATTR(edac_mode,S_IRUGO,csrow_edac_mode_show,NULL,0);
1038CSROWDEV_ATTR(ue_count,S_IRUGO,csrow_ue_count_show,NULL); 727CSROWDEV_ATTR(ue_count,S_IRUGO,csrow_ue_count_show,NULL,0);
1039CSROWDEV_ATTR(ce_count,S_IRUGO,csrow_ce_count_show,NULL); 728CSROWDEV_ATTR(ce_count,S_IRUGO,csrow_ce_count_show,NULL,0);
1040CSROWDEV_ATTR(ch0_ce_count,S_IRUGO,csrow_ch0_ce_count_show,NULL);
1041CSROWDEV_ATTR(ch1_ce_count,S_IRUGO,csrow_ch1_ce_count_show,NULL);
1042
1043/* control/attribute files */
1044CSROWDEV_ATTR(ch0_dimm_label,S_IRUGO|S_IWUSR,
1045 csrow_ch0_dimm_label_show,
1046 csrow_ch0_dimm_label_store);
1047CSROWDEV_ATTR(ch1_dimm_label,S_IRUGO|S_IWUSR,
1048 csrow_ch1_dimm_label_show,
1049 csrow_ch1_dimm_label_store);
1050 729
1051/* Attributes of the CSROW<id> object */ 730/* default attributes of the CSROW<id> object */
1052static struct csrowdev_attribute *csrow_attr[] = { 731static struct csrowdev_attribute *default_csrow_attr[] = {
1053 &attr_dev_type, 732 &attr_dev_type,
1054 &attr_mem_type, 733 &attr_mem_type,
1055 &attr_edac_mode, 734 &attr_edac_mode,
1056 &attr_size_mb, 735 &attr_size_mb,
1057 &attr_ue_count, 736 &attr_ue_count,
1058 &attr_ce_count, 737 &attr_ce_count,
1059 &attr_ch0_ce_count,
1060 &attr_ch1_ce_count,
1061 &attr_ch0_dimm_label,
1062 &attr_ch1_dimm_label,
1063 NULL, 738 NULL,
1064}; 739};
1065 740
1066/* No memory to release */ 741
742/* possible dynamic channel DIMM Label attribute files */
743CSROWDEV_ATTR(ch0_dimm_label,S_IRUGO|S_IWUSR,
744 channel_dimm_label_show,
745 channel_dimm_label_store,
746 0 );
747CSROWDEV_ATTR(ch1_dimm_label,S_IRUGO|S_IWUSR,
748 channel_dimm_label_show,
749 channel_dimm_label_store,
750 1 );
751CSROWDEV_ATTR(ch2_dimm_label,S_IRUGO|S_IWUSR,
752 channel_dimm_label_show,
753 channel_dimm_label_store,
754 2 );
755CSROWDEV_ATTR(ch3_dimm_label,S_IRUGO|S_IWUSR,
756 channel_dimm_label_show,
757 channel_dimm_label_store,
758 3 );
759CSROWDEV_ATTR(ch4_dimm_label,S_IRUGO|S_IWUSR,
760 channel_dimm_label_show,
761 channel_dimm_label_store,
762 4 );
763CSROWDEV_ATTR(ch5_dimm_label,S_IRUGO|S_IWUSR,
764 channel_dimm_label_show,
765 channel_dimm_label_store,
766 5 );
767
768/* Total possible dynamic DIMM Label attribute file table */
769static struct csrowdev_attribute *dynamic_csrow_dimm_attr[] = {
770 &attr_ch0_dimm_label,
771 &attr_ch1_dimm_label,
772 &attr_ch2_dimm_label,
773 &attr_ch3_dimm_label,
774 &attr_ch4_dimm_label,
775 &attr_ch5_dimm_label
776};
777
778/* possible dynamic channel ce_count attribute files */
779CSROWDEV_ATTR(ch0_ce_count,S_IRUGO|S_IWUSR,
780 channel_ce_count_show,
781 NULL,
782 0 );
783CSROWDEV_ATTR(ch1_ce_count,S_IRUGO|S_IWUSR,
784 channel_ce_count_show,
785 NULL,
786 1 );
787CSROWDEV_ATTR(ch2_ce_count,S_IRUGO|S_IWUSR,
788 channel_ce_count_show,
789 NULL,
790 2 );
791CSROWDEV_ATTR(ch3_ce_count,S_IRUGO|S_IWUSR,
792 channel_ce_count_show,
793 NULL,
794 3 );
795CSROWDEV_ATTR(ch4_ce_count,S_IRUGO|S_IWUSR,
796 channel_ce_count_show,
797 NULL,
798 4 );
799CSROWDEV_ATTR(ch5_ce_count,S_IRUGO|S_IWUSR,
800 channel_ce_count_show,
801 NULL,
802 5 );
803
804/* Total possible dynamic ce_count attribute file table */
805static struct csrowdev_attribute *dynamic_csrow_ce_count_attr[] = {
806 &attr_ch0_ce_count,
807 &attr_ch1_ce_count,
808 &attr_ch2_ce_count,
809 &attr_ch3_ce_count,
810 &attr_ch4_ce_count,
811 &attr_ch5_ce_count
812};
813
814
815#define EDAC_NR_CHANNELS 6
816
817/* Create dynamic CHANNEL files, indexed by 'chan', under specifed CSROW */
818static int edac_create_channel_files(struct kobject *kobj, int chan)
819{
820 int err=-ENODEV;
821
822 if (chan >= EDAC_NR_CHANNELS)
823 return err;
824
825 /* create the DIMM label attribute file */
826 err = sysfs_create_file(kobj,
827 (struct attribute *) dynamic_csrow_dimm_attr[chan]);
828
829 if (!err) {
830 /* create the CE Count attribute file */
831 err = sysfs_create_file(kobj,
832 (struct attribute *) dynamic_csrow_ce_count_attr[chan]);
833 } else {
834 debugf1("%s() dimm labels and ce_count files created", __func__);
835 }
836
837 return err;
838}
839
840/* No memory to release for this kobj */
1067static void edac_csrow_instance_release(struct kobject *kobj) 841static void edac_csrow_instance_release(struct kobject *kobj)
1068{ 842{
1069 struct csrow_info *cs; 843 struct csrow_info *cs;
1070 844
1071 debugf1("%s()\n", __func__);
1072 cs = container_of(kobj, struct csrow_info, kobj); 845 cs = container_of(kobj, struct csrow_info, kobj);
1073 complete(&cs->kobj_complete); 846 complete(&cs->kobj_complete);
1074} 847}
1075 848
849/* the kobj_type instance for a CSROW */
1076static struct kobj_type ktype_csrow = { 850static struct kobj_type ktype_csrow = {
1077 .release = edac_csrow_instance_release, 851 .release = edac_csrow_instance_release,
1078 .sysfs_ops = &csrowfs_ops, 852 .sysfs_ops = &csrowfs_ops,
1079 .default_attrs = (struct attribute **) csrow_attr, 853 .default_attrs = (struct attribute **) default_csrow_attr,
1080}; 854};
1081 855
1082/* Create a CSROW object under specifed edac_mc_device */ 856/* Create a CSROW object under specifed edac_mc_device */
1083static int edac_create_csrow_object(struct kobject *edac_mci_kobj, 857static int edac_create_csrow_object(
1084 struct csrow_info *csrow, int index) 858 struct kobject *edac_mci_kobj,
859 struct csrow_info *csrow,
860 int index)
1085{ 861{
1086 int err = 0; 862 int err = 0;
863 int chan;
1087 864
1088 debugf0("%s()\n", __func__);
1089 memset(&csrow->kobj, 0, sizeof(csrow->kobj)); 865 memset(&csrow->kobj, 0, sizeof(csrow->kobj));
1090 866
1091 /* generate ..../edac/mc/mc<id>/csrow<index> */ 867 /* generate ..../edac/mc/mc<id>/csrow<index> */
@@ -1095,21 +871,27 @@ static int edac_create_csrow_object(struct kobject *edac_mci_kobj,
1095 871
1096 /* name this instance of csrow<id> */ 872 /* name this instance of csrow<id> */
1097 err = kobject_set_name(&csrow->kobj,"csrow%d",index); 873 err = kobject_set_name(&csrow->kobj,"csrow%d",index);
874 if (err)
875 goto error_exit;
1098 876
877 /* Instanstiate the csrow object */
878 err = kobject_register(&csrow->kobj);
1099 if (!err) { 879 if (!err) {
1100 /* Instanstiate the csrow object */ 880 /* Create the dyanmic attribute files on this csrow,
1101 err = kobject_register(&csrow->kobj); 881 * namely, the DIMM labels and the channel ce_count
1102 882 */
1103 if (err) 883 for (chan = 0; chan < csrow->nr_channels; chan++) {
1104 debugf0("Failed to register CSROW%d\n",index); 884 err = edac_create_channel_files(&csrow->kobj,chan);
1105 else 885 if (err)
1106 debugf0("Registered CSROW%d\n",index); 886 break;
887 }
1107 } 888 }
1108 889
890error_exit:
1109 return err; 891 return err;
1110} 892}
1111 893
1112/* sysfs data structures and methods for the MCI kobjects */ 894/* default sysfs methods and data structures for the main MCI kobject */
1113 895
1114static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci, 896static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci,
1115 const char *data, size_t count) 897 const char *data, size_t count)
@@ -1135,6 +917,7 @@ static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci,
1135 return count; 917 return count;
1136} 918}
1137 919
920/* default attribute files for the MCI object */
1138static ssize_t mci_ue_count_show(struct mem_ctl_info *mci, char *data) 921static ssize_t mci_ue_count_show(struct mem_ctl_info *mci, char *data)
1139{ 922{
1140 return sprintf(data,"%d\n", mci->ue_count); 923 return sprintf(data,"%d\n", mci->ue_count);
@@ -1160,71 +943,11 @@ static ssize_t mci_seconds_show(struct mem_ctl_info *mci, char *data)
1160 return sprintf(data,"%ld\n", (jiffies - mci->start_time) / HZ); 943 return sprintf(data,"%ld\n", (jiffies - mci->start_time) / HZ);
1161} 944}
1162 945
1163static ssize_t mci_mod_name_show(struct mem_ctl_info *mci, char *data)
1164{
1165 return sprintf(data,"%s %s\n", mci->mod_name, mci->mod_ver);
1166}
1167
1168static ssize_t mci_ctl_name_show(struct mem_ctl_info *mci, char *data) 946static ssize_t mci_ctl_name_show(struct mem_ctl_info *mci, char *data)
1169{ 947{
1170 return sprintf(data,"%s\n", mci->ctl_name); 948 return sprintf(data,"%s\n", mci->ctl_name);
1171} 949}
1172 950
1173static int mci_output_edac_cap(char *buf, unsigned long edac_cap)
1174{
1175 char *p = buf;
1176 int bit_idx;
1177
1178 for (bit_idx = 0; bit_idx < 8 * sizeof(edac_cap); bit_idx++) {
1179 if ((edac_cap >> bit_idx) & 0x1)
1180 p += sprintf(p, "%s ", edac_caps[bit_idx]);
1181 }
1182
1183 return p - buf;
1184}
1185
1186static ssize_t mci_edac_capability_show(struct mem_ctl_info *mci, char *data)
1187{
1188 char *p = data;
1189
1190 p += mci_output_edac_cap(p,mci->edac_ctl_cap);
1191 p += sprintf(p, "\n");
1192 return p - data;
1193}
1194
1195static ssize_t mci_edac_current_capability_show(struct mem_ctl_info *mci,
1196 char *data)
1197{
1198 char *p = data;
1199
1200 p += mci_output_edac_cap(p,mci->edac_cap);
1201 p += sprintf(p, "\n");
1202 return p - data;
1203}
1204
1205static int mci_output_mtype_cap(char *buf, unsigned long mtype_cap)
1206{
1207 char *p = buf;
1208 int bit_idx;
1209
1210 for (bit_idx = 0; bit_idx < 8 * sizeof(mtype_cap); bit_idx++) {
1211 if ((mtype_cap >> bit_idx) & 0x1)
1212 p += sprintf(p, "%s ", mem_types[bit_idx]);
1213 }
1214
1215 return p - buf;
1216}
1217
1218static ssize_t mci_supported_mem_type_show(struct mem_ctl_info *mci,
1219 char *data)
1220{
1221 char *p = data;
1222
1223 p += mci_output_mtype_cap(p,mci->mtype_cap);
1224 p += sprintf(p, "\n");
1225 return p - data;
1226}
1227
1228static ssize_t mci_size_mb_show(struct mem_ctl_info *mci, char *data) 951static ssize_t mci_size_mb_show(struct mem_ctl_info *mci, char *data)
1229{ 952{
1230 int total_pages, csrow_idx; 953 int total_pages, csrow_idx;
@@ -1251,6 +974,7 @@ struct mcidev_attribute {
1251#define to_mci(k) container_of(k, struct mem_ctl_info, edac_mci_kobj) 974#define to_mci(k) container_of(k, struct mem_ctl_info, edac_mci_kobj)
1252#define to_mcidev_attr(a) container_of(a, struct mcidev_attribute, attr) 975#define to_mcidev_attr(a) container_of(a, struct mcidev_attribute, attr)
1253 976
977/* MCI show/store functions for top most object */
1254static ssize_t mcidev_show(struct kobject *kobj, struct attribute *attr, 978static ssize_t mcidev_show(struct kobject *kobj, struct attribute *attr,
1255 char *buffer) 979 char *buffer)
1256{ 980{
@@ -1287,31 +1011,21 @@ struct mcidev_attribute mci_attr_##_name = { \
1287 .store = _store, \ 1011 .store = _store, \
1288}; 1012};
1289 1013
1290/* Control file */ 1014/* default Control file */
1291MCIDEV_ATTR(reset_counters,S_IWUSR,NULL,mci_reset_counters_store); 1015MCIDEV_ATTR(reset_counters,S_IWUSR,NULL,mci_reset_counters_store);
1292 1016
1293/* Attribute files */ 1017/* default Attribute files */
1294MCIDEV_ATTR(mc_name,S_IRUGO,mci_ctl_name_show,NULL); 1018MCIDEV_ATTR(mc_name,S_IRUGO,mci_ctl_name_show,NULL);
1295MCIDEV_ATTR(module_name,S_IRUGO,mci_mod_name_show,NULL);
1296MCIDEV_ATTR(edac_capability,S_IRUGO,mci_edac_capability_show,NULL);
1297MCIDEV_ATTR(size_mb,S_IRUGO,mci_size_mb_show,NULL); 1019MCIDEV_ATTR(size_mb,S_IRUGO,mci_size_mb_show,NULL);
1298MCIDEV_ATTR(seconds_since_reset,S_IRUGO,mci_seconds_show,NULL); 1020MCIDEV_ATTR(seconds_since_reset,S_IRUGO,mci_seconds_show,NULL);
1299MCIDEV_ATTR(ue_noinfo_count,S_IRUGO,mci_ue_noinfo_show,NULL); 1021MCIDEV_ATTR(ue_noinfo_count,S_IRUGO,mci_ue_noinfo_show,NULL);
1300MCIDEV_ATTR(ce_noinfo_count,S_IRUGO,mci_ce_noinfo_show,NULL); 1022MCIDEV_ATTR(ce_noinfo_count,S_IRUGO,mci_ce_noinfo_show,NULL);
1301MCIDEV_ATTR(ue_count,S_IRUGO,mci_ue_count_show,NULL); 1023MCIDEV_ATTR(ue_count,S_IRUGO,mci_ue_count_show,NULL);
1302MCIDEV_ATTR(ce_count,S_IRUGO,mci_ce_count_show,NULL); 1024MCIDEV_ATTR(ce_count,S_IRUGO,mci_ce_count_show,NULL);
1303MCIDEV_ATTR(edac_current_capability,S_IRUGO,
1304 mci_edac_current_capability_show,NULL);
1305MCIDEV_ATTR(supported_mem_type,S_IRUGO,
1306 mci_supported_mem_type_show,NULL);
1307 1025
1308static struct mcidev_attribute *mci_attr[] = { 1026static struct mcidev_attribute *mci_attr[] = {
1309 &mci_attr_reset_counters, 1027 &mci_attr_reset_counters,
1310 &mci_attr_module_name,
1311 &mci_attr_mc_name, 1028 &mci_attr_mc_name,
1312 &mci_attr_edac_capability,
1313 &mci_attr_edac_current_capability,
1314 &mci_attr_supported_mem_type,
1315 &mci_attr_size_mb, 1029 &mci_attr_size_mb,
1316 &mci_attr_seconds_since_reset, 1030 &mci_attr_seconds_since_reset,
1317 &mci_attr_ue_noinfo_count, 1031 &mci_attr_ue_noinfo_count,
@@ -1339,7 +1053,6 @@ static struct kobj_type ktype_mci = {
1339 .default_attrs = (struct attribute **) mci_attr, 1053 .default_attrs = (struct attribute **) mci_attr,
1340}; 1054};
1341 1055
1342#endif /* DISABLE_EDAC_SYSFS */
1343 1056
1344#define EDAC_DEVICE_SYMLINK "device" 1057#define EDAC_DEVICE_SYMLINK "device"
1345 1058
@@ -1352,11 +1065,6 @@ static struct kobj_type ktype_mci = {
1352 * !0 Failure 1065 * !0 Failure
1353 */ 1066 */
1354static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) 1067static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
1355#ifdef DISABLE_EDAC_SYSFS
1356{
1357 return 0;
1358}
1359#else
1360{ 1068{
1361 int i; 1069 int i;
1362 int err; 1070 int err;
@@ -1368,7 +1076,6 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
1368 1076
1369 /* set the name of the mc<id> object */ 1077 /* set the name of the mc<id> object */
1370 err = kobject_set_name(edac_mci_kobj,"mc%d",mci->mc_idx); 1078 err = kobject_set_name(edac_mci_kobj,"mc%d",mci->mc_idx);
1371
1372 if (err) 1079 if (err)
1373 return err; 1080 return err;
1374 1081
@@ -1378,14 +1085,12 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
1378 1085
1379 /* register the mc<id> kobject */ 1086 /* register the mc<id> kobject */
1380 err = kobject_register(edac_mci_kobj); 1087 err = kobject_register(edac_mci_kobj);
1381
1382 if (err) 1088 if (err)
1383 return err; 1089 return err;
1384 1090
1385 /* create a symlink for the device */ 1091 /* create a symlink for the device */
1386 err = sysfs_create_link(edac_mci_kobj, &mci->dev->kobj, 1092 err = sysfs_create_link(edac_mci_kobj, &mci->dev->kobj,
1387 EDAC_DEVICE_SYMLINK); 1093 EDAC_DEVICE_SYMLINK);
1388
1389 if (err) 1094 if (err)
1390 goto fail0; 1095 goto fail0;
1391 1096
@@ -1398,7 +1103,6 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
1398 /* Only expose populated CSROWs */ 1103 /* Only expose populated CSROWs */
1399 if (csrow->nr_pages > 0) { 1104 if (csrow->nr_pages > 0) {
1400 err = edac_create_csrow_object(edac_mci_kobj,csrow,i); 1105 err = edac_create_csrow_object(edac_mci_kobj,csrow,i);
1401
1402 if (err) 1106 if (err)
1403 goto fail1; 1107 goto fail1;
1404 } 1108 }
@@ -1422,14 +1126,12 @@ fail0:
1422 wait_for_completion(&mci->kobj_complete); 1126 wait_for_completion(&mci->kobj_complete);
1423 return err; 1127 return err;
1424} 1128}
1425#endif /* DISABLE_EDAC_SYSFS */
1426 1129
1427/* 1130/*
1428 * remove a Memory Controller instance 1131 * remove a Memory Controller instance
1429 */ 1132 */
1430static void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci) 1133static void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
1431{ 1134{
1432#ifndef DISABLE_EDAC_SYSFS
1433 int i; 1135 int i;
1434 1136
1435 debugf0("%s()\n", __func__); 1137 debugf0("%s()\n", __func__);
@@ -1447,7 +1149,6 @@ static void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
1447 init_completion(&mci->kobj_complete); 1149 init_completion(&mci->kobj_complete);
1448 kobject_unregister(&mci->edac_mci_kobj); 1150 kobject_unregister(&mci->edac_mci_kobj);
1449 wait_for_completion(&mci->kobj_complete); 1151 wait_for_completion(&mci->kobj_complete);
1450#endif /* DISABLE_EDAC_SYSFS */
1451} 1152}
1452 1153
1453/* END OF sysfs data and methods */ 1154/* END OF sysfs data and methods */
diff --git a/drivers/edac/edac_mc.h b/drivers/edac/edac_mc.h
index bf6ab8a8d5ed..a1cfd4e3c97d 100644
--- a/drivers/edac/edac_mc.h
+++ b/drivers/edac/edac_mc.h
@@ -29,6 +29,7 @@
29#include <linux/rcupdate.h> 29#include <linux/rcupdate.h>
30#include <linux/completion.h> 30#include <linux/completion.h>
31#include <linux/kobject.h> 31#include <linux/kobject.h>
32#include <linux/platform_device.h>
32 33
33#define EDAC_MC_LABEL_LEN 31 34#define EDAC_MC_LABEL_LEN 31
34#define MC_PROC_NAME_MAX_LEN 7 35#define MC_PROC_NAME_MAX_LEN 7
diff --git a/drivers/fc4/fc.c b/drivers/fc4/fc.c
index 66d03f242d3c..1a159e8843ca 100644
--- a/drivers/fc4/fc.c
+++ b/drivers/fc4/fc.c
@@ -429,7 +429,7 @@ static inline void fcp_scsi_receive(fc_channel *fc, int token, int status, fc_hd
429 429
430 if (fcmd->data) { 430 if (fcmd->data) {
431 if (SCpnt->use_sg) 431 if (SCpnt->use_sg)
432 dma_unmap_sg(fc->dev, (struct scatterlist *)SCpnt->buffer, 432 dma_unmap_sg(fc->dev, (struct scatterlist *)SCpnt->request_buffer,
433 SCpnt->use_sg, 433 SCpnt->use_sg,
434 SCpnt->sc_data_direction); 434 SCpnt->sc_data_direction);
435 else 435 else
@@ -810,7 +810,7 @@ static int fcp_scsi_queue_it(fc_channel *fc, Scsi_Cmnd *SCpnt, fcp_cmnd *fcmd, i
810 SCpnt->request_bufflen, 810 SCpnt->request_bufflen,
811 SCpnt->sc_data_direction); 811 SCpnt->sc_data_direction);
812 } else { 812 } else {
813 struct scatterlist *sg = (struct scatterlist *)SCpnt->buffer; 813 struct scatterlist *sg = (struct scatterlist *)SCpnt->request_buffer;
814 int nents; 814 int nents;
815 815
816 FCD(("XXX: Use_sg %d %d\n", SCpnt->use_sg, sg->length)) 816 FCD(("XXX: Use_sg %d %d\n", SCpnt->use_sg, sg->length))
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c
index 59122cc0a50a..35ad1b032726 100644
--- a/drivers/hwmon/abituguru.c
+++ b/drivers/hwmon/abituguru.c
@@ -26,6 +26,7 @@
26#include <linux/jiffies.h> 26#include <linux/jiffies.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/delay.h>
29#include <linux/platform_device.h> 30#include <linux/platform_device.h>
30#include <linux/hwmon.h> 31#include <linux/hwmon.h>
31#include <linux/hwmon-sysfs.h> 32#include <linux/hwmon-sysfs.h>
@@ -64,17 +65,17 @@
64#define ABIT_UGURU_IN_SENSOR 0 65#define ABIT_UGURU_IN_SENSOR 0
65#define ABIT_UGURU_TEMP_SENSOR 1 66#define ABIT_UGURU_TEMP_SENSOR 1
66#define ABIT_UGURU_NC 2 67#define ABIT_UGURU_NC 2
67/* Timeouts / Retries, if these turn out to need a lot of fiddling we could 68/* In many cases we need to wait for the uGuru to reach a certain status, most
68 convert them to params. */ 69 of the time it will reach this status within 30 - 90 ISA reads, and thus we
69/* 250 was determined by trial and error, 200 works most of the time, but not 70 can best busy wait. This define gives the total amount of reads to try. */
70 always. I assume this is cpu-speed independent, since the ISA-bus and not 71#define ABIT_UGURU_WAIT_TIMEOUT 125
71 the CPU should be the bottleneck. Note that 250 sometimes is still not 72/* However sometimes older versions of the uGuru seem to be distracted and they
72 enough (only reported on AN7 mb) this is handled by a higher layer. */ 73 do not respond for a long time. To handle this we sleep before each of the
73#define ABIT_UGURU_WAIT_TIMEOUT 250 74 last ABIT_UGURU_WAIT_TIMEOUT_SLEEP tries. */
75#define ABIT_UGURU_WAIT_TIMEOUT_SLEEP 5
74/* Normally all expected status in abituguru_ready, are reported after the 76/* Normally all expected status in abituguru_ready, are reported after the
75 first read, but sometimes not and we need to poll, 5 polls was not enough 77 first read, but sometimes not and we need to poll. */
76 50 sofar is. */ 78#define ABIT_UGURU_READY_TIMEOUT 5
77#define ABIT_UGURU_READY_TIMEOUT 50
78/* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */ 79/* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */
79#define ABIT_UGURU_MAX_RETRIES 3 80#define ABIT_UGURU_MAX_RETRIES 3
80#define ABIT_UGURU_RETRY_DELAY (HZ/5) 81#define ABIT_UGURU_RETRY_DELAY (HZ/5)
@@ -142,6 +143,14 @@ static const u8 abituguru_pwm_max[5] = { 0, 255, 255, 75, 75 };
142static int force; 143static int force;
143module_param(force, bool, 0); 144module_param(force, bool, 0);
144MODULE_PARM_DESC(force, "Set to one to force detection."); 145MODULE_PARM_DESC(force, "Set to one to force detection.");
146static int bank1_types[ABIT_UGURU_MAX_BANK1_SENSORS] = { -1, -1, -1, -1, -1,
147 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
148module_param_array(bank1_types, int, NULL, 0);
149MODULE_PARM_DESC(bank1_types, "Bank1 sensortype autodetection override:\n"
150 " -1 autodetect\n"
151 " 0 volt sensor\n"
152 " 1 temp sensor\n"
153 " 2 not connected");
145static int fan_sensors; 154static int fan_sensors;
146module_param(fan_sensors, int, 0); 155module_param(fan_sensors, int, 0);
147MODULE_PARM_DESC(fan_sensors, "Number of fan sensors on the uGuru " 156MODULE_PARM_DESC(fan_sensors, "Number of fan sensors on the uGuru "
@@ -218,6 +227,10 @@ static int abituguru_wait(struct abituguru_data *data, u8 state)
218 timeout--; 227 timeout--;
219 if (timeout == 0) 228 if (timeout == 0)
220 return -EBUSY; 229 return -EBUSY;
230 /* sleep a bit before our last few tries, see the comment on
231 this where ABIT_UGURU_WAIT_TIMEOUT_SLEEP is defined. */
232 if (timeout <= ABIT_UGURU_WAIT_TIMEOUT_SLEEP)
233 msleep(0);
221 } 234 }
222 return 0; 235 return 0;
223} 236}
@@ -248,6 +261,7 @@ static int abituguru_ready(struct abituguru_data *data)
248 "CMD reg does not hold 0xAC after ready command\n"); 261 "CMD reg does not hold 0xAC after ready command\n");
249 return -EIO; 262 return -EIO;
250 } 263 }
264 msleep(0);
251 } 265 }
252 266
253 /* After this the ABIT_UGURU_DATA port should contain 267 /* After this the ABIT_UGURU_DATA port should contain
@@ -260,6 +274,7 @@ static int abituguru_ready(struct abituguru_data *data)
260 "state != more input after ready command\n"); 274 "state != more input after ready command\n");
261 return -EIO; 275 return -EIO;
262 } 276 }
277 msleep(0);
263 } 278 }
264 279
265 data->uguru_ready = 1; 280 data->uguru_ready = 1;
@@ -323,7 +338,8 @@ static int abituguru_read(struct abituguru_data *data,
323 /* And read the data */ 338 /* And read the data */
324 for (i = 0; i < count; i++) { 339 for (i = 0; i < count; i++) {
325 if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { 340 if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) {
326 ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for " 341 ABIT_UGURU_DEBUG(retries ? 1 : 3,
342 "timeout exceeded waiting for "
327 "read state (bank: %d, sensor: %d)\n", 343 "read state (bank: %d, sensor: %d)\n",
328 (int)bank_addr, (int)sensor_addr); 344 (int)bank_addr, (int)sensor_addr);
329 break; 345 break;
@@ -342,7 +358,9 @@ static int abituguru_read(struct abituguru_data *data,
342static int abituguru_write(struct abituguru_data *data, 358static int abituguru_write(struct abituguru_data *data,
343 u8 bank_addr, u8 sensor_addr, u8 *buf, int count) 359 u8 bank_addr, u8 sensor_addr, u8 *buf, int count)
344{ 360{
345 int i; 361 /* We use the ready timeout as we have to wait for 0xAC just like the
362 ready function */
363 int i, timeout = ABIT_UGURU_READY_TIMEOUT;
346 364
347 /* Send the address */ 365 /* Send the address */
348 i = abituguru_send_address(data, bank_addr, sensor_addr, 366 i = abituguru_send_address(data, bank_addr, sensor_addr,
@@ -362,7 +380,8 @@ static int abituguru_write(struct abituguru_data *data,
362 } 380 }
363 381
364 /* Now we need to wait till the chip is ready to be read again, 382 /* Now we need to wait till the chip is ready to be read again,
365 don't ask why */ 383 so that we can read 0xAC as confirmation that our write has
384 succeeded. */
366 if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { 385 if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) {
367 ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state " 386 ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state "
368 "after write (bank: %d, sensor: %d)\n", (int)bank_addr, 387 "after write (bank: %d, sensor: %d)\n", (int)bank_addr,
@@ -371,11 +390,15 @@ static int abituguru_write(struct abituguru_data *data,
371 } 390 }
372 391
373 /* Cmd port MUST be read now and should contain 0xAC */ 392 /* Cmd port MUST be read now and should contain 0xAC */
374 if (inb_p(data->addr + ABIT_UGURU_CMD) != 0xAC) { 393 while (inb_p(data->addr + ABIT_UGURU_CMD) != 0xAC) {
375 ABIT_UGURU_DEBUG(1, "CMD reg does not hold 0xAC after write " 394 timeout--;
376 "(bank: %d, sensor: %d)\n", (int)bank_addr, 395 if (timeout == 0) {
377 (int)sensor_addr); 396 ABIT_UGURU_DEBUG(1, "CMD reg does not hold 0xAC after "
378 return -EIO; 397 "write (bank: %d, sensor: %d)\n",
398 (int)bank_addr, (int)sensor_addr);
399 return -EIO;
400 }
401 msleep(0);
379 } 402 }
380 403
381 /* Last put the chip back in ready state */ 404 /* Last put the chip back in ready state */
@@ -395,7 +418,16 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
395 u8 sensor_addr) 418 u8 sensor_addr)
396{ 419{
397 u8 val, buf[3]; 420 u8 val, buf[3];
398 int ret = ABIT_UGURU_NC; 421 int i, ret = -ENODEV; /* error is the most common used retval :| */
422
423 /* If overriden by the user return the user selected type */
424 if (bank1_types[sensor_addr] >= ABIT_UGURU_IN_SENSOR &&
425 bank1_types[sensor_addr] <= ABIT_UGURU_NC) {
426 ABIT_UGURU_DEBUG(2, "assuming sensor type %d for bank1 sensor "
427 "%d because of \"bank1_types\" module param\n",
428 bank1_types[sensor_addr], (int)sensor_addr);
429 return bank1_types[sensor_addr];
430 }
399 431
400 /* First read the sensor and the current settings */ 432 /* First read the sensor and the current settings */
401 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1, sensor_addr, &val, 433 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1, sensor_addr, &val,
@@ -422,7 +454,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
422 buf[2] = 250; 454 buf[2] = 250;
423 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 455 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
424 buf, 3) != 3) 456 buf, 3) != 3)
425 return -ENODEV; 457 goto abituguru_detect_bank1_sensor_type_exit;
426 /* Now we need 20 ms to give the uguru time to read the sensors 458 /* Now we need 20 ms to give the uguru time to read the sensors
427 and raise a voltage alarm */ 459 and raise a voltage alarm */
428 set_current_state(TASK_UNINTERRUPTIBLE); 460 set_current_state(TASK_UNINTERRUPTIBLE);
@@ -430,21 +462,16 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
430 /* Check for alarm and check the alarm is a volt low alarm. */ 462 /* Check for alarm and check the alarm is a volt low alarm. */
431 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3, 463 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3,
432 ABIT_UGURU_MAX_RETRIES) != 3) 464 ABIT_UGURU_MAX_RETRIES) != 3)
433 return -ENODEV; 465 goto abituguru_detect_bank1_sensor_type_exit;
434 if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) { 466 if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) {
435 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, 467 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1,
436 sensor_addr, buf, 3, 468 sensor_addr, buf, 3,
437 ABIT_UGURU_MAX_RETRIES) != 3) 469 ABIT_UGURU_MAX_RETRIES) != 3)
438 return -ENODEV; 470 goto abituguru_detect_bank1_sensor_type_exit;
439 if (buf[0] & ABIT_UGURU_VOLT_LOW_ALARM_FLAG) { 471 if (buf[0] & ABIT_UGURU_VOLT_LOW_ALARM_FLAG) {
440 /* Restore original settings */
441 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2,
442 sensor_addr,
443 data->bank1_settings[sensor_addr],
444 3) != 3)
445 return -ENODEV;
446 ABIT_UGURU_DEBUG(2, " found volt sensor\n"); 472 ABIT_UGURU_DEBUG(2, " found volt sensor\n");
447 return ABIT_UGURU_IN_SENSOR; 473 ret = ABIT_UGURU_IN_SENSOR;
474 goto abituguru_detect_bank1_sensor_type_exit;
448 } else 475 } else
449 ABIT_UGURU_DEBUG(2, " alarm raised during volt " 476 ABIT_UGURU_DEBUG(2, " alarm raised during volt "
450 "sensor test, but volt low flag not set\n"); 477 "sensor test, but volt low flag not set\n");
@@ -460,7 +487,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
460 buf[2] = 10; 487 buf[2] = 10;
461 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 488 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
462 buf, 3) != 3) 489 buf, 3) != 3)
463 return -ENODEV; 490 goto abituguru_detect_bank1_sensor_type_exit;
464 /* Now we need 50 ms to give the uguru time to read the sensors 491 /* Now we need 50 ms to give the uguru time to read the sensors
465 and raise a temp alarm */ 492 and raise a temp alarm */
466 set_current_state(TASK_UNINTERRUPTIBLE); 493 set_current_state(TASK_UNINTERRUPTIBLE);
@@ -468,15 +495,16 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
468 /* Check for alarm and check the alarm is a temp high alarm. */ 495 /* Check for alarm and check the alarm is a temp high alarm. */
469 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3, 496 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3,
470 ABIT_UGURU_MAX_RETRIES) != 3) 497 ABIT_UGURU_MAX_RETRIES) != 3)
471 return -ENODEV; 498 goto abituguru_detect_bank1_sensor_type_exit;
472 if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) { 499 if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) {
473 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, 500 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1,
474 sensor_addr, buf, 3, 501 sensor_addr, buf, 3,
475 ABIT_UGURU_MAX_RETRIES) != 3) 502 ABIT_UGURU_MAX_RETRIES) != 3)
476 return -ENODEV; 503 goto abituguru_detect_bank1_sensor_type_exit;
477 if (buf[0] & ABIT_UGURU_TEMP_HIGH_ALARM_FLAG) { 504 if (buf[0] & ABIT_UGURU_TEMP_HIGH_ALARM_FLAG) {
478 ret = ABIT_UGURU_TEMP_SENSOR;
479 ABIT_UGURU_DEBUG(2, " found temp sensor\n"); 505 ABIT_UGURU_DEBUG(2, " found temp sensor\n");
506 ret = ABIT_UGURU_TEMP_SENSOR;
507 goto abituguru_detect_bank1_sensor_type_exit;
480 } else 508 } else
481 ABIT_UGURU_DEBUG(2, " alarm raised during temp " 509 ABIT_UGURU_DEBUG(2, " alarm raised during temp "
482 "sensor test, but temp high flag not set\n"); 510 "sensor test, but temp high flag not set\n");
@@ -484,11 +512,23 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
484 ABIT_UGURU_DEBUG(2, " alarm not raised during temp sensor " 512 ABIT_UGURU_DEBUG(2, " alarm not raised during temp sensor "
485 "test\n"); 513 "test\n");
486 514
487 /* Restore original settings */ 515 ret = ABIT_UGURU_NC;
488 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 516abituguru_detect_bank1_sensor_type_exit:
489 data->bank1_settings[sensor_addr], 3) != 3) 517 /* Restore original settings, failing here is really BAD, it has been
518 reported that some BIOS-es hang when entering the uGuru menu with
519 invalid settings present in the uGuru, so we try this 3 times. */
520 for (i = 0; i < 3; i++)
521 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2,
522 sensor_addr, data->bank1_settings[sensor_addr],
523 3) == 3)
524 break;
525 if (i == 3) {
526 printk(KERN_ERR ABIT_UGURU_NAME
527 ": Fatal error could not restore original settings. "
528 "This should never happen please report this to the "
529 "abituguru maintainer (see MAINTAINERS)\n");
490 return -ENODEV; 530 return -ENODEV;
491 531 }
492 return ret; 532 return ret;
493} 533}
494 534
@@ -514,7 +554,7 @@ abituguru_detect_no_bank2_sensors(struct abituguru_data *data)
514{ 554{
515 int i; 555 int i;
516 556
517 if (fan_sensors) { 557 if (fan_sensors > 0 && fan_sensors <= ABIT_UGURU_MAX_BANK2_SENSORS) {
518 data->bank2_sensors = fan_sensors; 558 data->bank2_sensors = fan_sensors;
519 ABIT_UGURU_DEBUG(2, "assuming %d fan sensors because of " 559 ABIT_UGURU_DEBUG(2, "assuming %d fan sensors because of "
520 "\"fan_sensors\" module param\n", 560 "\"fan_sensors\" module param\n",
@@ -568,7 +608,7 @@ abituguru_detect_no_pwms(struct abituguru_data *data)
568{ 608{
569 int i, j; 609 int i, j;
570 610
571 if (pwms) { 611 if (pwms > 0 && pwms <= ABIT_UGURU_MAX_PWMS) {
572 data->pwms = pwms; 612 data->pwms = pwms;
573 ABIT_UGURU_DEBUG(2, "assuming %d PWM outputs because of " 613 ABIT_UGURU_DEBUG(2, "assuming %d PWM outputs because of "
574 "\"pwms\" module param\n", (int)data->pwms); 614 "\"pwms\" module param\n", (int)data->pwms);
@@ -1288,7 +1328,7 @@ static struct abituguru_data *abituguru_update_device(struct device *dev)
1288 data->update_timeouts = 0; 1328 data->update_timeouts = 0;
1289LEAVE_UPDATE: 1329LEAVE_UPDATE:
1290 /* handle timeout condition */ 1330 /* handle timeout condition */
1291 if (err == -EBUSY) { 1331 if (!success && (err == -EBUSY || err >= 0)) {
1292 /* No overflow please */ 1332 /* No overflow please */
1293 if (data->update_timeouts < 255u) 1333 if (data->update_timeouts < 255u)
1294 data->update_timeouts++; 1334 data->update_timeouts++;
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index df05df1a0ef6..ab230c033f99 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -372,7 +372,6 @@ static inline int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
372 372
373 while (count > 0) { 373 while (count > 0) {
374 inval = i2c_inb(i2c_adap); 374 inval = i2c_inb(i2c_adap);
375/*printk("%#02x ",inval); if ( ! (count % 16) ) printk("\n"); */
376 if (inval>=0) { 375 if (inval>=0) {
377 *temp = inval; 376 *temp = inval;
378 rdcount++; 377 rdcount++;
@@ -544,8 +543,7 @@ int i2c_bit_add_bus(struct i2c_adapter *adap)
544 adap->timeout = 100; /* default values, should */ 543 adap->timeout = 100; /* default values, should */
545 adap->retries = 3; /* be replaced by defines */ 544 adap->retries = 3; /* be replaced by defines */
546 545
547 i2c_add_adapter(adap); 546 return i2c_add_adapter(adap);
548 return 0;
549} 547}
550 548
551 549
diff --git a/drivers/i2c/algos/i2c-algo-ite.c b/drivers/i2c/algos/i2c-algo-ite.c
index 2db7bfc85225..70d8eefb5efc 100644
--- a/drivers/i2c/algos/i2c-algo-ite.c
+++ b/drivers/i2c/algos/i2c-algo-ite.c
@@ -742,10 +742,8 @@ int i2c_iic_add_bus(struct i2c_adapter *adap)
742 adap->retries = 3; /* be replaced by defines */ 742 adap->retries = 3; /* be replaced by defines */
743 adap->flags = 0; 743 adap->flags = 0;
744 744
745 i2c_add_adapter(adap);
746 iic_init(iic_adap); 745 iic_init(iic_adap);
747 746 return i2c_add_adapter(adap);
748 return 0;
749} 747}
750 748
751 749
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index 82946acab4c7..b88a6fcf7bd0 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -374,10 +374,10 @@ int i2c_pca_add_bus(struct i2c_adapter *adap)
374 adap->timeout = 100; /* default values, should */ 374 adap->timeout = 100; /* default values, should */
375 adap->retries = 3; /* be replaced by defines */ 375 adap->retries = 3; /* be replaced by defines */
376 376
377 rval = pca_init(pca_adap); 377 if ((rval = pca_init(pca_adap)))
378 return rval;
378 379
379 if (!rval) 380 rval = i2c_add_adapter(adap);
380 i2c_add_adapter(adap);
381 381
382 return rval; 382 return rval;
383} 383}
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index 6e498df1f717..5b24930adb5a 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -479,9 +479,11 @@ int i2c_pcf_add_bus(struct i2c_adapter *adap)
479 adap->timeout = 100; /* default values, should */ 479 adap->timeout = 100; /* default values, should */
480 adap->retries = 3; /* be replaced by defines */ 480 adap->retries = 3; /* be replaced by defines */
481 481
482 rval = pcf_init_8584(pcf_adap); 482 if ((rval = pcf_init_8584(pcf_adap)))
483 if (!rval) 483 return rval;
484 i2c_add_adapter(adap); 484
485 rval = i2c_add_adapter(adap);
486
485 return rval; 487 return rval;
486} 488}
487 489
diff --git a/drivers/i2c/algos/i2c-algo-sibyte.c b/drivers/i2c/algos/i2c-algo-sibyte.c
index 3df3f09995c2..32d41c6fac0f 100644
--- a/drivers/i2c/algos/i2c-algo-sibyte.c
+++ b/drivers/i2c/algos/i2c-algo-sibyte.c
@@ -173,9 +173,7 @@ int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
173 printk("\n"); 173 printk("\n");
174 } 174 }
175 175
176 i2c_add_adapter(i2c_adap); 176 return i2c_add_adapter(i2c_adap);
177
178 return 0;
179} 177}
180 178
181 179
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index aca7e1668605..48c56939c861 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -21,6 +21,9 @@
21 * - Make it work with IXP46x chips 21 * - Make it work with IXP46x chips
22 * - Cleanup function names, coding style, etc 22 * - Cleanup function names, coding style, etc
23 * 23 *
24 * - writing to slave address causes latchup on iop331.
25 * fix: driver refuses to address self.
26 *
24 * This program is free software; you can redistribute it and/or modify 27 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by 28 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, version 2. 29 * the Free Software Foundation, version 2.
@@ -73,12 +76,6 @@ iop3xx_i2c_reset(struct i2c_algo_iop3xx_data *iop3xx_adap)
73} 76}
74 77
75static void 78static void
76iop3xx_i2c_set_slave_addr(struct i2c_algo_iop3xx_data *iop3xx_adap)
77{
78 __raw_writel(MYSAR, iop3xx_adap->ioaddr + SAR_OFFSET);
79}
80
81static void
82iop3xx_i2c_enable(struct i2c_algo_iop3xx_data *iop3xx_adap) 79iop3xx_i2c_enable(struct i2c_algo_iop3xx_data *iop3xx_adap)
83{ 80{
84 u32 cr = IOP3XX_ICR_GCD | IOP3XX_ICR_SCLEN | IOP3XX_ICR_UE; 81 u32 cr = IOP3XX_ICR_GCD | IOP3XX_ICR_SCLEN | IOP3XX_ICR_UE;
@@ -248,6 +245,13 @@ iop3xx_i2c_send_target_addr(struct i2c_algo_iop3xx_data *iop3xx_adap,
248 int status; 245 int status;
249 int rc; 246 int rc;
250 247
248 /* avoid writing to my slave address (hangs on 80331),
249 * forbidden in Intel developer manual
250 */
251 if (msg->addr == MYSAR) {
252 return -EBUSY;
253 }
254
251 __raw_writel(iic_cook_addr(msg), iop3xx_adap->ioaddr + DBR_OFFSET); 255 __raw_writel(iic_cook_addr(msg), iop3xx_adap->ioaddr + DBR_OFFSET);
252 256
253 cr &= ~(IOP3XX_ICR_MSTOP | IOP3XX_ICR_NACK); 257 cr &= ~(IOP3XX_ICR_MSTOP | IOP3XX_ICR_NACK);
@@ -498,7 +502,6 @@ iop3xx_i2c_probe(struct platform_device *pdev)
498 spin_lock_init(&adapter_data->lock); 502 spin_lock_init(&adapter_data->lock);
499 503
500 iop3xx_i2c_reset(adapter_data); 504 iop3xx_i2c_reset(adapter_data);
501 iop3xx_i2c_set_slave_addr(adapter_data);
502 iop3xx_i2c_enable(adapter_data); 505 iop3xx_i2c_enable(adapter_data);
503 506
504 platform_set_drvdata(pdev, new_adapter); 507 platform_set_drvdata(pdev, new_adapter);
diff --git a/drivers/i2c/busses/i2c-iop3xx.h b/drivers/i2c/busses/i2c-iop3xx.h
index e46ebaea7b1e..8485861f6a36 100644
--- a/drivers/i2c/busses/i2c-iop3xx.h
+++ b/drivers/i2c/busses/i2c-iop3xx.h
@@ -80,7 +80,7 @@
80#define IOP3XX_GPOD_I2C0 0x00c0 /* clear these bits to enable ch0 */ 80#define IOP3XX_GPOD_I2C0 0x00c0 /* clear these bits to enable ch0 */
81#define IOP3XX_GPOD_I2C1 0x0030 /* clear these bits to enable ch1 */ 81#define IOP3XX_GPOD_I2C1 0x0030 /* clear these bits to enable ch1 */
82 82
83#define MYSAR 0x02 /* SWAG a suitable slave address */ 83#define MYSAR 0 /* default slave address */
84 84
85#define I2C_ERR 321 85#define I2C_ERR 321
86#define I2C_ERR_BERR (I2C_ERR+0) 86#define I2C_ERR_BERR (I2C_ERR+0)
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 2a0b3be7cdd0..53bb43593863 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -148,8 +148,6 @@ static int i2c_powermac_master_xfer( struct i2c_adapter *adap,
148 int read; 148 int read;
149 int addrdir; 149 int addrdir;
150 150
151 if (num != 1)
152 return -EINVAL;
153 if (msgs->flags & I2C_M_TEN) 151 if (msgs->flags & I2C_M_TEN)
154 return -EINVAL; 152 return -EINVAL;
155 read = (msgs->flags & I2C_M_RD) != 0; 153 read = (msgs->flags & I2C_M_RD) != 0;
@@ -166,7 +164,7 @@ static int i2c_powermac_master_xfer( struct i2c_adapter *adap,
166 rc = pmac_i2c_xfer(bus, addrdir, 0, 0, msgs->buf, msgs->len); 164 rc = pmac_i2c_xfer(bus, addrdir, 0, 0, msgs->buf, msgs->len);
167 bail: 165 bail:
168 pmac_i2c_close(bus); 166 pmac_i2c_close(bus);
169 return rc < 0 ? rc : msgs->len; 167 return rc < 0 ? rc : 1;
170} 168}
171 169
172static u32 i2c_powermac_func(struct i2c_adapter * adapter) 170static u32 i2c_powermac_func(struct i2c_adapter * adapter)
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 22a3eda04166..eae9e81be375 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -184,21 +184,21 @@ static void scx200_acb_machine(struct scx200_acb_iface *iface, u8 status)
184 break; 184 break;
185 185
186 case state_read: 186 case state_read:
187 /* Set ACK if receiving the last byte */ 187 /* Set ACK if _next_ byte will be the last one */
188 if (iface->len == 1) 188 if (iface->len == 2)
189 outb(inb(ACBCTL1) | ACBCTL1_ACK, ACBCTL1); 189 outb(inb(ACBCTL1) | ACBCTL1_ACK, ACBCTL1);
190 else 190 else
191 outb(inb(ACBCTL1) & ~ACBCTL1_ACK, ACBCTL1); 191 outb(inb(ACBCTL1) & ~ACBCTL1_ACK, ACBCTL1);
192 192
193 *iface->ptr++ = inb(ACBSDA); 193 if (iface->len == 1) {
194 --iface->len;
195
196 if (iface->len == 0) {
197 iface->result = 0; 194 iface->result = 0;
198 iface->state = state_idle; 195 iface->state = state_idle;
199 outb(inb(ACBCTL1) | ACBCTL1_STOP, ACBCTL1); 196 outb(inb(ACBCTL1) | ACBCTL1_STOP, ACBCTL1);
200 } 197 }
201 198
199 *iface->ptr++ = inb(ACBSDA);
200 --iface->len;
201
202 break; 202 break;
203 203
204 case state_write: 204 case state_write:
@@ -232,7 +232,7 @@ static void scx200_acb_poll(struct scx200_acb_iface *iface)
232 unsigned long timeout; 232 unsigned long timeout;
233 233
234 timeout = jiffies + POLL_TIMEOUT; 234 timeout = jiffies + POLL_TIMEOUT;
235 while (time_before(jiffies, timeout)) { 235 while (1) {
236 status = inb(ACBST); 236 status = inb(ACBST);
237 237
238 /* Reset the status register to avoid the hang */ 238 /* Reset the status register to avoid the hang */
@@ -242,7 +242,10 @@ static void scx200_acb_poll(struct scx200_acb_iface *iface)
242 scx200_acb_machine(iface, status); 242 scx200_acb_machine(iface, status);
243 return; 243 return;
244 } 244 }
245 yield(); 245 if (time_after(jiffies, timeout))
246 break;
247 cpu_relax();
248 cond_resched();
246 } 249 }
247 250
248 dev_err(&iface->adapter.dev, "timeout in state %s\n", 251 dev_err(&iface->adapter.dev, "timeout in state %s\n",
@@ -307,8 +310,12 @@ static s32 scx200_acb_smbus_xfer(struct i2c_adapter *adapter,
307 buffer = (u8 *)&cur_word; 310 buffer = (u8 *)&cur_word;
308 break; 311 break;
309 312
310 case I2C_SMBUS_BLOCK_DATA: 313 case I2C_SMBUS_I2C_BLOCK_DATA:
314 if (rw == I2C_SMBUS_READ)
315 data->block[0] = I2C_SMBUS_BLOCK_MAX; /* For now */
311 len = data->block[0]; 316 len = data->block[0];
317 if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
318 return -EINVAL;
312 buffer = &data->block[1]; 319 buffer = &data->block[1];
313 break; 320 break;
314 321
@@ -372,7 +379,7 @@ static u32 scx200_acb_func(struct i2c_adapter *adapter)
372{ 379{
373 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 380 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
374 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 381 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
375 I2C_FUNC_SMBUS_BLOCK_DATA; 382 I2C_FUNC_SMBUS_I2C_BLOCK;
376} 383}
377 384
378/* For now, we only handle combined mode (smbus) */ 385/* For now, we only handle combined mode (smbus) */
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c
index 54b6e6a4beed..cb22280cdd27 100644
--- a/drivers/i2c/chips/pca9539.c
+++ b/drivers/i2c/chips/pca9539.c
@@ -134,11 +134,13 @@ static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
134 new_client->driver = &pca9539_driver; 134 new_client->driver = &pca9539_driver;
135 new_client->flags = 0; 135 new_client->flags = 0;
136 136
137 /* Detection: the pca9539 only has 8 registers (0-7). 137 if (kind < 0) {
138 A read of 7 should succeed, but a read of 8 should fail. */ 138 /* Detection: the pca9539 only has 8 registers (0-7).
139 if ((i2c_smbus_read_byte_data(new_client, 7) < 0) || 139 A read of 7 should succeed, but a read of 8 should fail. */
140 (i2c_smbus_read_byte_data(new_client, 8) >= 0)) 140 if ((i2c_smbus_read_byte_data(new_client, 7) < 0) ||
141 goto exit_kfree; 141 (i2c_smbus_read_byte_data(new_client, 8) >= 0))
142 goto exit_kfree;
143 }
142 144
143 strlcpy(new_client->name, "pca9539", I2C_NAME_SIZE); 145 strlcpy(new_client->name, "pca9539", I2C_NAME_SIZE);
144 146
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index e7e27049fbfa..0be6fd6a267d 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -43,13 +43,12 @@
43/*-------------------------------------------------------------------------*/ 43/*-------------------------------------------------------------------------*/
44 44
45#define DRIVER_VERSION "2 May 2005" 45#define DRIVER_VERSION "2 May 2005"
46#define DRIVER_NAME (tps65010_driver.name) 46#define DRIVER_NAME (tps65010_driver.driver.name)
47 47
48MODULE_DESCRIPTION("TPS6501x Power Management Driver"); 48MODULE_DESCRIPTION("TPS6501x Power Management Driver");
49MODULE_LICENSE("GPL"); 49MODULE_LICENSE("GPL");
50 50
51static unsigned short normal_i2c[] = { 0x48, /* 0x49, */ I2C_CLIENT_END }; 51static unsigned short normal_i2c[] = { 0x48, /* 0x49, */ I2C_CLIENT_END };
52static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
53 52
54I2C_CLIENT_INSMOD; 53I2C_CLIENT_INSMOD;
55 54
@@ -100,7 +99,7 @@ struct tps65010 {
100 /* not currently tracking GPIO state */ 99 /* not currently tracking GPIO state */
101}; 100};
102 101
103#define POWER_POLL_DELAY msecs_to_jiffies(800) 102#define POWER_POLL_DELAY msecs_to_jiffies(5000)
104 103
105/*-------------------------------------------------------------------------*/ 104/*-------------------------------------------------------------------------*/
106 105
@@ -520,8 +519,11 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind)
520 goto fail1; 519 goto fail1;
521 } 520 }
522 521
522 /* the IRQ is active low, but many gpio lines can't support that
523 * so this driver can use falling-edge triggers instead.
524 */
525 irqflags = IRQF_SAMPLE_RANDOM;
523#ifdef CONFIG_ARM 526#ifdef CONFIG_ARM
524 irqflags = IRQF_SAMPLE_RANDOM | IRQF_TRIGGER_LOW;
525 if (machine_is_omap_h2()) { 527 if (machine_is_omap_h2()) {
526 tps->model = TPS65010; 528 tps->model = TPS65010;
527 omap_cfg_reg(W4_GPIO58); 529 omap_cfg_reg(W4_GPIO58);
@@ -543,8 +545,6 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind)
543 545
544 // FIXME set up this board's IRQ ... 546 // FIXME set up this board's IRQ ...
545 } 547 }
546#else
547 irqflags = IRQF_SAMPLE_RANDOM;
548#endif 548#endif
549 549
550 if (tps->irq > 0) { 550 if (tps->irq > 0) {
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index a45155f799d4..9cb277d6aa48 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -756,9 +756,9 @@ int i2c_probe(struct i2c_adapter *adapter,
756 "parameter for adapter %d, " 756 "parameter for adapter %d, "
757 "addr 0x%02x\n", adap_id, 757 "addr 0x%02x\n", adap_id,
758 address_data->ignore[j + 1]); 758 address_data->ignore[j + 1]);
759 ignore = 1;
760 break;
759 } 761 }
760 ignore = 1;
761 break;
762 } 762 }
763 if (ignore) 763 if (ignore)
764 continue; 764 continue;
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index d1266fe2d1ab..b6fb167e20f6 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -682,6 +682,7 @@ config BLK_DEV_SVWKS
682config BLK_DEV_SGIIOC4 682config BLK_DEV_SGIIOC4
683 tristate "Silicon Graphics IOC4 chipset ATA/ATAPI support" 683 tristate "Silicon Graphics IOC4 chipset ATA/ATAPI support"
684 depends on (IA64_SGI_SN2 || IA64_GENERIC) && SGI_IOC4 684 depends on (IA64_SGI_SN2 || IA64_GENERIC) && SGI_IOC4
685 select IDEPCI_SHARE_IRQ
685 help 686 help
686 This driver adds PIO & MultiMode DMA-2 support for the SGI IOC4 687 This driver adds PIO & MultiMode DMA-2 support for the SGI IOC4
687 chipset, which has one channel and can support two devices. 688 chipset, which has one channel and can support two devices.
@@ -773,20 +774,6 @@ config BLK_DEV_IDEDMA_PMAC
773 to transfer data to and from memory. Saying Y is safe and improves 774 to transfer data to and from memory. Saying Y is safe and improves
774 performance. 775 performance.
775 776
776config BLK_DEV_IDE_PMAC_BLINK
777 bool "Blink laptop LED on drive activity (DEPRECATED)"
778 depends on BLK_DEV_IDE_PMAC && ADB_PMU
779 select ADB_PMU_LED
780 select LEDS_TRIGGERS
781 select LEDS_TRIGGER_IDE_DISK
782 help
783 This option enables the use of the sleep LED as a hard drive
784 activity LED.
785 This option is deprecated, it only selects ADB_PMU_LED and
786 LEDS_TRIGGER_IDE_DISK and changes the code in the new led class
787 device to default to the ide-disk trigger (which should be set
788 from userspace via sysfs).
789
790config BLK_DEV_IDE_SWARM 777config BLK_DEV_IDE_SWARM
791 tristate "IDE for Sibyte evaluation boards" 778 tristate "IDE for Sibyte evaluation boards"
792 depends on SIBYTE_SB1xxx_SOC 779 depends on SIBYTE_SB1xxx_SOC
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index f712e4cfd9dc..7cf3eb023521 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -776,7 +776,7 @@ static void update_ordered(ide_drive_t *drive)
776 * not available so we don't need to recheck that. 776 * not available so we don't need to recheck that.
777 */ 777 */
778 capacity = idedisk_capacity(drive); 778 capacity = idedisk_capacity(drive);
779 barrier = ide_id_has_flush_cache(id) && 779 barrier = ide_id_has_flush_cache(id) && !drive->noflush &&
780 (drive->addressing == 0 || capacity <= (1ULL << 28) || 780 (drive->addressing == 0 || capacity <= (1ULL << 28) ||
781 ide_id_has_flush_cache_ext(id)); 781 ide_id_has_flush_cache_ext(id));
782 782
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 98918fb6b2ce..7c3a13e1cf64 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -750,7 +750,7 @@ void ide_dma_verbose(ide_drive_t *drive)
750 goto bug_dma_off; 750 goto bug_dma_off;
751 printk(", DMA"); 751 printk(", DMA");
752 } else if (id->field_valid & 1) { 752 } else if (id->field_valid & 1) {
753 printk(", BUG"); 753 goto bug_dma_off;
754 } 754 }
755 return; 755 return;
756bug_dma_off: 756bug_dma_off:
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 6ca3476d02c7..adbe9f76a505 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -838,7 +838,7 @@ static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
838 "transferred\n", pc->actually_transferred); 838 "transferred\n", pc->actually_transferred);
839 clear_bit(PC_DMA_IN_PROGRESS, &pc->flags); 839 clear_bit(PC_DMA_IN_PROGRESS, &pc->flags);
840 840
841 local_irq_enable(); 841 local_irq_enable_in_hardirq();
842 842
843 if (status.b.check || test_bit(PC_DMA_ERROR, &pc->flags)) { 843 if (status.b.check || test_bit(PC_DMA_ERROR, &pc->flags)) {
844 /* Error detected */ 844 /* Error detected */
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 7dba9992ad30..fb6795236e76 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -693,7 +693,7 @@ static ide_startstop_t drive_cmd_intr (ide_drive_t *drive)
693 u8 stat = hwif->INB(IDE_STATUS_REG); 693 u8 stat = hwif->INB(IDE_STATUS_REG);
694 int retries = 10; 694 int retries = 10;
695 695
696 local_irq_enable(); 696 local_irq_enable_in_hardirq();
697 if ((stat & DRQ_STAT) && args && args[3]) { 697 if ((stat & DRQ_STAT) && args && args[3]) {
698 u8 io_32bit = drive->io_32bit; 698 u8 io_32bit = drive->io_32bit;
699 drive->io_32bit = 0; 699 drive->io_32bit = 0;
@@ -1286,7 +1286,7 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
1286 if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq) 1286 if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq)
1287 disable_irq_nosync(hwif->irq); 1287 disable_irq_nosync(hwif->irq);
1288 spin_unlock(&ide_lock); 1288 spin_unlock(&ide_lock);
1289 local_irq_enable(); 1289 local_irq_enable_in_hardirq();
1290 /* allow other IRQs while we start this request */ 1290 /* allow other IRQs while we start this request */
1291 startstop = start_request(drive, rq); 1291 startstop = start_request(drive, rq);
1292 spin_lock_irq(&ide_lock); 1292 spin_lock_irq(&ide_lock);
@@ -1631,7 +1631,7 @@ irqreturn_t ide_intr (int irq, void *dev_id, struct pt_regs *regs)
1631 spin_unlock(&ide_lock); 1631 spin_unlock(&ide_lock);
1632 1632
1633 if (drive->unmask) 1633 if (drive->unmask)
1634 local_irq_enable(); 1634 local_irq_enable_in_hardirq();
1635 /* service this interrupt, may set handler for next interrupt */ 1635 /* service this interrupt, may set handler for next interrupt */
1636 startstop = handler(drive); 1636 startstop = handler(drive);
1637 spin_lock_irq(&ide_lock); 1637 spin_lock_irq(&ide_lock);
@@ -1705,7 +1705,7 @@ int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t actio
1705{ 1705{
1706 unsigned long flags; 1706 unsigned long flags;
1707 ide_hwgroup_t *hwgroup = HWGROUP(drive); 1707 ide_hwgroup_t *hwgroup = HWGROUP(drive);
1708 DECLARE_COMPLETION(wait); 1708 DECLARE_COMPLETION_ONSTACK(wait);
1709 int where = ELEVATOR_INSERT_BACK, err; 1709 int where = ELEVATOR_INSERT_BACK, err;
1710 int must_wait = (action == ide_wait || action == ide_head_wait); 1710 int must_wait = (action == ide_wait || action == ide_head_wait);
1711 1711
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 657165297dc7..77703acaec17 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -23,6 +23,7 @@
23#include <linux/hdreg.h> 23#include <linux/hdreg.h>
24#include <linux/ide.h> 24#include <linux/ide.h>
25#include <linux/bitops.h> 25#include <linux/bitops.h>
26#include <linux/nmi.h>
26 27
27#include <asm/byteorder.h> 28#include <asm/byteorder.h>
28#include <asm/irq.h> 29#include <asm/irq.h>
@@ -1243,6 +1244,7 @@ int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout)
1243 if (stat == 0xff) 1244 if (stat == 0xff)
1244 return -ENODEV; 1245 return -ENODEV;
1245 touch_softlockup_watchdog(); 1246 touch_softlockup_watchdog();
1247 touch_nmi_watchdog();
1246 } 1248 }
1247 return -EBUSY; 1249 return -EBUSY;
1248} 1250}
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index c12f1b71e934..41b74b13a00c 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -376,6 +376,8 @@ static int proc_ide_read_media
376 break; 376 break;
377 case ide_floppy:media = "floppy\n"; 377 case ide_floppy:media = "floppy\n";
378 break; 378 break;
379 case ide_optical:media = "optical\n";
380 break;
379 default: media = "UNKNOWN\n"; 381 default: media = "UNKNOWN\n";
380 break; 382 break;
381 } 383 }
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 04547eb0833f..97a9244312fc 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -222,7 +222,7 @@ ide_startstop_t task_no_data_intr (ide_drive_t *drive)
222 ide_hwif_t *hwif = HWIF(drive); 222 ide_hwif_t *hwif = HWIF(drive);
223 u8 stat; 223 u8 stat;
224 224
225 local_irq_enable(); 225 local_irq_enable_in_hardirq();
226 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) { 226 if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) {
227 return ide_error(drive, "task_no_data_intr", stat); 227 return ide_error(drive, "task_no_data_intr", stat);
228 /* calls ide_end_drive_cmd */ 228 /* calls ide_end_drive_cmd */
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 05fbd9298db7..defd4b4bd374 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -1539,7 +1539,7 @@ static int __init ide_setup(char *s)
1539 const char *hd_words[] = { 1539 const char *hd_words[] = {
1540 "none", "noprobe", "nowerr", "cdrom", "serialize", 1540 "none", "noprobe", "nowerr", "cdrom", "serialize",
1541 "autotune", "noautotune", "minus8", "swapdata", "bswap", 1541 "autotune", "noautotune", "minus8", "swapdata", "bswap",
1542 "minus11", "remap", "remap63", "scsi", NULL }; 1542 "noflush", "remap", "remap63", "scsi", NULL };
1543 unit = s[2] - 'a'; 1543 unit = s[2] - 'a';
1544 hw = unit / MAX_DRIVES; 1544 hw = unit / MAX_DRIVES;
1545 unit = unit % MAX_DRIVES; 1545 unit = unit % MAX_DRIVES;
@@ -1578,6 +1578,9 @@ static int __init ide_setup(char *s)
1578 case -10: /* "bswap" */ 1578 case -10: /* "bswap" */
1579 drive->bswap = 1; 1579 drive->bswap = 1;
1580 goto done; 1580 goto done;
1581 case -11: /* noflush */
1582 drive->noflush = 1;
1583 goto done;
1581 case -12: /* "remap" */ 1584 case -12: /* "remap" */
1582 drive->remap_0_to_1 = 1; 1585 drive->remap_0_to_1 = 1;
1583 goto done; 1586 goto done;
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index b7e459e4f284..602797a44208 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -146,16 +146,7 @@ static void ide_detach(struct pcmcia_device *link)
146 kfree(link->priv); 146 kfree(link->priv);
147} /* ide_detach */ 147} /* ide_detach */
148 148
149static void idecs_mmio_fixup(ide_hwif_t *hwif) 149static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq, struct pcmcia_device *handle)
150{
151 default_hwif_mmiops(hwif);
152 hwif->mmio = 2;
153
154 ide_undecoded_slave(hwif);
155}
156
157static int idecs_register(unsigned long io, unsigned long ctl,
158 unsigned long irq, struct pcmcia_device *handle, int is_mmio)
159{ 150{
160 hw_regs_t hw; 151 hw_regs_t hw;
161 memset(&hw, 0, sizeof(hw)); 152 memset(&hw, 0, sizeof(hw));
@@ -163,19 +154,7 @@ static int idecs_register(unsigned long io, unsigned long ctl,
163 hw.irq = irq; 154 hw.irq = irq;
164 hw.chipset = ide_pci; 155 hw.chipset = ide_pci;
165 hw.dev = &handle->dev; 156 hw.dev = &handle->dev;
166 157 return ide_register_hw_with_fixup(&hw, NULL, ide_undecoded_slave);
167 if(is_mmio)
168 return ide_register_hw_with_fixup(&hw, NULL, idecs_mmio_fixup);
169 else
170 return ide_register_hw_with_fixup(&hw, NULL, ide_undecoded_slave);
171}
172
173void outb_io(unsigned char value, unsigned long port) {
174 outb(value, port);
175}
176
177void outb_mem(unsigned char value, unsigned long port) {
178 writeb(value, (void __iomem *) port);
179} 158}
180 159
181/*====================================================================== 160/*======================================================================
@@ -201,8 +180,7 @@ static int ide_config(struct pcmcia_device *link)
201 } *stk = NULL; 180 } *stk = NULL;
202 cistpl_cftable_entry_t *cfg; 181 cistpl_cftable_entry_t *cfg;
203 int i, pass, last_ret = 0, last_fn = 0, hd, is_kme = 0; 182 int i, pass, last_ret = 0, last_fn = 0, hd, is_kme = 0;
204 unsigned long io_base, ctl_base, is_mmio, try_slave; 183 unsigned long io_base, ctl_base;
205 void (*my_outb)(unsigned char, unsigned long);
206 184
207 DEBUG(0, "ide_config(0x%p)\n", link); 185 DEBUG(0, "ide_config(0x%p)\n", link);
208 186
@@ -232,7 +210,7 @@ static int ide_config(struct pcmcia_device *link)
232 /* Not sure if this is right... look up the current Vcc */ 210 /* Not sure if this is right... look up the current Vcc */
233 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &stk->conf)); 211 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &stk->conf));
234 212
235 pass = io_base = ctl_base = is_mmio = try_slave = 0; 213 pass = io_base = ctl_base = 0;
236 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 214 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
237 tuple.Attributes = 0; 215 tuple.Attributes = 0;
238 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); 216 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
@@ -280,45 +258,11 @@ static int ide_config(struct pcmcia_device *link)
280 goto next_entry; 258 goto next_entry;
281 io_base = link->io.BasePort1; 259 io_base = link->io.BasePort1;
282 ctl_base = link->io.BasePort1 + 0x0e; 260 ctl_base = link->io.BasePort1 + 0x0e;
283
284 if (io->win[0].len >= 0x20)
285 try_slave = 1;
286
287 } else goto next_entry; 261 } else goto next_entry;
288 /* If we've got this far, we're done */ 262 /* If we've got this far, we're done */
289 break; 263 break;
290 } 264 }
291 265
292 if ((cfg->mem.nwin > 0) || (stk->dflt.mem.nwin > 0)) {
293 win_req_t req;
294 memreq_t map;
295 cistpl_mem_t *mem = (cfg->mem.nwin) ? &cfg->mem : &stk->dflt.mem;
296
297 if (mem->win[0].len < 16)
298 goto next_entry;
299
300 req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
301 req.Attributes |= WIN_ENABLE;
302 req.Base = mem->win[0].host_addr;
303 req.Size = 0;
304
305 req.AccessSpeed = 0;
306 if (pcmcia_request_window(&link, &req, &link->win) != 0)
307 goto next_entry;
308 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
309 if (pcmcia_map_mem_page(link->win, &map) != 0)
310 goto next_entry;
311
312 io_base = (unsigned long) ioremap(req.Base, req.Size);
313 ctl_base = io_base + 0x0e;
314 is_mmio = 1;
315
316 if (mem->win[0].len >= 0x20)
317 try_slave = 1;
318
319 break;
320 }
321
322 next_entry: 266 next_entry:
323 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 267 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
324 memcpy(&stk->dflt, cfg, sizeof(stk->dflt)); 268 memcpy(&stk->dflt, cfg, sizeof(stk->dflt));
@@ -334,26 +278,21 @@ static int ide_config(struct pcmcia_device *link)
334 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 278 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
335 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 279 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
336 280
337 if(is_mmio)
338 my_outb = outb_mem;
339 else
340 my_outb = outb_io;
341
342 /* disable drive interrupts during IDE probe */ 281 /* disable drive interrupts during IDE probe */
343 my_outb(0x02, ctl_base); 282 outb(0x02, ctl_base);
344 283
345 /* special setup for KXLC005 card */ 284 /* special setup for KXLC005 card */
346 if (is_kme) 285 if (is_kme)
347 my_outb(0x81, ctl_base+1); 286 outb(0x81, ctl_base+1);
348 287
349 /* retry registration in case device is still spinning up */ 288 /* retry registration in case device is still spinning up */
350 for (hd = -1, i = 0; i < 10; i++) { 289 for (hd = -1, i = 0; i < 10; i++) {
351 hd = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, link, is_mmio); 290 hd = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, link);
352 if (hd >= 0) break; 291 if (hd >= 0) break;
353 if (try_slave) { 292 if (link->io.NumPorts1 == 0x20) {
354 my_outb(0x02, ctl_base + 0x10); 293 outb(0x02, ctl_base + 0x10);
355 hd = idecs_register(io_base + 0x10, ctl_base + 0x10, 294 hd = idecs_register(io_base + 0x10, ctl_base + 0x10,
356 link->irq.AssignedIRQ, link, is_mmio); 295 link->irq.AssignedIRQ, link);
357 if (hd >= 0) { 296 if (hd >= 0) {
358 io_base += 0x10; 297 io_base += 0x10;
359 ctl_base += 0x10; 298 ctl_base += 0x10;
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index a7c725f8bf64..f286079d233f 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -425,12 +425,12 @@ static int __devinit aec62xx_init_one(struct pci_dev *dev, const struct pci_devi
425 return d->init_setup(dev, d); 425 return d->init_setup(dev, d);
426} 426}
427 427
428static const struct pci_device_id aec62xx_pci_tbl[] = { 428static struct pci_device_id aec62xx_pci_tbl[] = {
429 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP850UF), 0 }, 429 { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP850UF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
430 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP860), 1 }, 430 { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP860, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
431 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP860R), 2 }, 431 { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP860R, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
432 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP865), 3 }, 432 { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP865, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
433 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP865R), 4 }, 433 { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP865R, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
434 { 0, }, 434 { 0, },
435}; 435};
436MODULE_DEVICE_TABLE(pci, aec62xx_pci_tbl); 436MODULE_DEVICE_TABLE(pci, aec62xx_pci_tbl);
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 351dab2fcacf..d419e4bb54f4 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -730,7 +730,7 @@ static unsigned int __devinit ata66_ali15x3 (ide_hwif_t *hwif)
730 730
731 if(m5229_revision <= 0x20) 731 if(m5229_revision <= 0x20)
732 tmpbyte = (tmpbyte & (~0x02)) | 0x01; 732 tmpbyte = (tmpbyte & (~0x02)) | 0x01;
733 else if (m5229_revision == 0xc7) 733 else if (m5229_revision == 0xc7 || m5229_revision == 0xc8)
734 tmpbyte |= 0x03; 734 tmpbyte |= 0x03;
735 else 735 else
736 tmpbyte |= 0x01; 736 tmpbyte |= 0x01;
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index f82e82109728..78810ba982e9 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -180,6 +180,36 @@ static ide_pci_device_t generic_chipsets[] __devinitdata = {
180 .channels = 2, 180 .channels = 2,
181 .autodma = AUTODMA, 181 .autodma = AUTODMA,
182 .bootable = OFF_BOARD, 182 .bootable = OFF_BOARD,
183 },{ /* 15 */
184 .name = "JMB361",
185 .init_hwif = init_hwif_generic,
186 .channels = 2,
187 .autodma = AUTODMA,
188 .bootable = OFF_BOARD,
189 },{ /* 16 */
190 .name = "JMB363",
191 .init_hwif = init_hwif_generic,
192 .channels = 2,
193 .autodma = AUTODMA,
194 .bootable = OFF_BOARD,
195 },{ /* 17 */
196 .name = "JMB365",
197 .init_hwif = init_hwif_generic,
198 .channels = 2,
199 .autodma = AUTODMA,
200 .bootable = OFF_BOARD,
201 },{ /* 18 */
202 .name = "JMB366",
203 .init_hwif = init_hwif_generic,
204 .channels = 2,
205 .autodma = AUTODMA,
206 .bootable = OFF_BOARD,
207 },{ /* 19 */
208 .name = "JMB368",
209 .init_hwif = init_hwif_generic,
210 .channels = 2,
211 .autodma = AUTODMA,
212 .bootable = OFF_BOARD,
183 } 213 }
184}; 214};
185 215
@@ -212,6 +242,9 @@ static int __devinit generic_init_one(struct pci_dev *dev, const struct pci_devi
212 (!(PCI_FUNC(dev->devfn) & 1))) 242 (!(PCI_FUNC(dev->devfn) & 1)))
213 goto out; 243 goto out;
214 244
245 if (dev->vendor == PCI_VENDOR_ID_JMICRON && PCI_FUNC(dev->devfn) != 1)
246 goto out;
247
215 pci_read_config_word(dev, PCI_COMMAND, &command); 248 pci_read_config_word(dev, PCI_COMMAND, &command);
216 if (!(command & PCI_COMMAND_IO)) { 249 if (!(command & PCI_COMMAND_IO)) {
217 printk(KERN_INFO "Skipping disabled %s IDE controller.\n", d->name); 250 printk(KERN_INFO "Skipping disabled %s IDE controller.\n", d->name);
@@ -239,6 +272,11 @@ static struct pci_device_id generic_pci_tbl[] = {
239 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12}, 272 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12},
240 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13}, 273 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13},
241 { PCI_VENDOR_ID_NETCELL,PCI_DEVICE_ID_REVOLUTION, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14}, 274 { PCI_VENDOR_ID_NETCELL,PCI_DEVICE_ID_REVOLUTION, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14},
275 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 15},
276 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 16},
277 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 17},
278 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 18},
279 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 19},
242 /* Must come last. If you add entries adjust this table appropriately and the init_one code */ 280 /* Must come last. If you add entries adjust this table appropriately and the init_one code */
243 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 0}, 281 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 0},
244 { 0, }, 282 { 0, },
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index 3cb04424d351..e9bad185968a 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -498,9 +498,14 @@ static int config_chipset_for_dma (ide_drive_t *drive)
498{ 498{
499 u8 speed = ide_dma_speed(drive, it821x_ratemask(drive)); 499 u8 speed = ide_dma_speed(drive, it821x_ratemask(drive));
500 500
501 config_it821x_chipset_for_pio(drive, !speed); 501 if (speed) {
502 it821x_tune_chipset(drive, speed); 502 config_it821x_chipset_for_pio(drive, 0);
503 return ide_dma_enable(drive); 503 it821x_tune_chipset(drive, speed);
504
505 return ide_dma_enable(drive);
506 }
507
508 return 0;
504} 509}
505 510
506/** 511/**
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index 03677bff0d72..f063d954236c 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -649,11 +649,11 @@ static int __devinit svwks_init_one(struct pci_dev *dev, const struct pci_device
649} 649}
650 650
651static struct pci_device_id svwks_pci_tbl[] = { 651static struct pci_device_id svwks_pci_tbl[] = {
652 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE), 0}, 652 { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
653 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE), 1}, 653 { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
654 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE), 2}, 654 { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
655 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2), 3}, 655 { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
656 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000IDE), 4}, 656 { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
657 { 0, }, 657 { 0, },
658}; 658};
659MODULE_DEVICE_TABLE(pci, svwks_pci_tbl); 659MODULE_DEVICE_TABLE(pci, svwks_pci_tbl);
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index e125032bb403..d8a0d87df734 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -367,12 +367,13 @@ sgiioc4_INB(unsigned long port)
367static void __devinit 367static void __devinit
368ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base) 368ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base)
369{ 369{
370 void __iomem *virt_dma_base;
370 int num_ports = sizeof (ioc4_dma_regs_t); 371 int num_ports = sizeof (ioc4_dma_regs_t);
371 372
372 printk(KERN_INFO "%s: BM-DMA at 0x%04lx-0x%04lx\n", hwif->name, 373 printk(KERN_INFO "%s: BM-DMA at 0x%04lx-0x%04lx\n", hwif->name,
373 dma_base, dma_base + num_ports - 1); 374 dma_base, dma_base + num_ports - 1);
374 375
375 if (!request_region(dma_base, num_ports, hwif->name)) { 376 if (!request_mem_region(dma_base, num_ports, hwif->name)) {
376 printk(KERN_ERR 377 printk(KERN_ERR
377 "%s(%s) -- ERROR, Addresses 0x%p to 0x%p " 378 "%s(%s) -- ERROR, Addresses 0x%p to 0x%p "
378 "ALREADY in use\n", 379 "ALREADY in use\n",
@@ -381,13 +382,21 @@ ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base)
381 goto dma_alloc_failure; 382 goto dma_alloc_failure;
382 } 383 }
383 384
384 hwif->dma_base = dma_base; 385 virt_dma_base = ioremap(dma_base, num_ports);
386 if (virt_dma_base == NULL) {
387 printk(KERN_ERR
388 "%s(%s) -- ERROR, Unable to map addresses 0x%lx to 0x%lx\n",
389 __FUNCTION__, hwif->name, dma_base, dma_base + num_ports - 1);
390 goto dma_remap_failure;
391 }
392 hwif->dma_base = (unsigned long) virt_dma_base;
393
385 hwif->dmatable_cpu = pci_alloc_consistent(hwif->pci_dev, 394 hwif->dmatable_cpu = pci_alloc_consistent(hwif->pci_dev,
386 IOC4_PRD_ENTRIES * IOC4_PRD_BYTES, 395 IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
387 &hwif->dmatable_dma); 396 &hwif->dmatable_dma);
388 397
389 if (!hwif->dmatable_cpu) 398 if (!hwif->dmatable_cpu)
390 goto dma_alloc_failure; 399 goto dma_pci_alloc_failure;
391 400
392 hwif->sg_max_nents = IOC4_PRD_ENTRIES; 401 hwif->sg_max_nents = IOC4_PRD_ENTRIES;
393 402
@@ -411,6 +420,12 @@ dma_base2alloc_failure:
411 printk(KERN_INFO 420 printk(KERN_INFO
412 "Changing from DMA to PIO mode for Drive %s\n", hwif->name); 421 "Changing from DMA to PIO mode for Drive %s\n", hwif->name);
413 422
423dma_pci_alloc_failure:
424 iounmap(virt_dma_base);
425
426dma_remap_failure:
427 release_mem_region(dma_base, num_ports);
428
414dma_alloc_failure: 429dma_alloc_failure:
415 /* Disable DMA because we couldnot allocate any DMA maps */ 430 /* Disable DMA because we couldnot allocate any DMA maps */
416 hwif->autodma = 0; 431 hwif->autodma = 0;
@@ -607,18 +622,15 @@ ide_init_sgiioc4(ide_hwif_t * hwif)
607 hwif->ide_dma_lostirq = &sgiioc4_ide_dma_lostirq; 622 hwif->ide_dma_lostirq = &sgiioc4_ide_dma_lostirq;
608 hwif->ide_dma_timeout = &__ide_dma_timeout; 623 hwif->ide_dma_timeout = &__ide_dma_timeout;
609 624
610 /*
611 * The IOC4 uses MMIO rather than Port IO.
612 * It also needs special workarounds for INB.
613 */
614 default_hwif_mmiops(hwif);
615 hwif->INB = &sgiioc4_INB; 625 hwif->INB = &sgiioc4_INB;
616} 626}
617 627
618static int __devinit 628static int __devinit
619sgiioc4_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t * d) 629sgiioc4_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t * d)
620{ 630{
621 unsigned long base, ctl, dma_base, irqport; 631 unsigned long cmd_base, dma_base, irqport;
632 unsigned long bar0, cmd_phys_base, ctl;
633 void __iomem *virt_base;
622 ide_hwif_t *hwif; 634 ide_hwif_t *hwif;
623 int h; 635 int h;
624 636
@@ -636,23 +648,32 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t * d)
636 } 648 }
637 649
638 /* Get the CmdBlk and CtrlBlk Base Registers */ 650 /* Get the CmdBlk and CtrlBlk Base Registers */
639 base = pci_resource_start(dev, 0) + IOC4_CMD_OFFSET; 651 bar0 = pci_resource_start(dev, 0);
640 ctl = pci_resource_start(dev, 0) + IOC4_CTRL_OFFSET; 652 virt_base = ioremap(bar0, pci_resource_len(dev, 0));
641 irqport = pci_resource_start(dev, 0) + IOC4_INTR_OFFSET; 653 if (virt_base == NULL) {
654 printk(KERN_ERR "%s: Unable to remap BAR 0 address: 0x%lx\n",
655 d->name, bar0);
656 return -ENOMEM;
657 }
658 cmd_base = (unsigned long) virt_base + IOC4_CMD_OFFSET;
659 ctl = (unsigned long) virt_base + IOC4_CTRL_OFFSET;
660 irqport = (unsigned long) virt_base + IOC4_INTR_OFFSET;
642 dma_base = pci_resource_start(dev, 0) + IOC4_DMA_OFFSET; 661 dma_base = pci_resource_start(dev, 0) + IOC4_DMA_OFFSET;
643 662
644 if (!request_region(base, IOC4_CMD_CTL_BLK_SIZE, hwif->name)) { 663 cmd_phys_base = bar0 + IOC4_CMD_OFFSET;
664 if (!request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE,
665 hwif->name)) {
645 printk(KERN_ERR 666 printk(KERN_ERR
646 "%s : %s -- ERROR, Port Addresses " 667 "%s : %s -- ERROR, Addresses "
647 "0x%p to 0x%p ALREADY in use\n", 668 "0x%p to 0x%p ALREADY in use\n",
648 __FUNCTION__, hwif->name, (void *) base, 669 __FUNCTION__, hwif->name, (void *) cmd_phys_base,
649 (void *) base + IOC4_CMD_CTL_BLK_SIZE); 670 (void *) cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE);
650 return -ENOMEM; 671 return -ENOMEM;
651 } 672 }
652 673
653 if (hwif->io_ports[IDE_DATA_OFFSET] != base) { 674 if (hwif->io_ports[IDE_DATA_OFFSET] != cmd_base) {
654 /* Initialize the IO registers */ 675 /* Initialize the IO registers */
655 sgiioc4_init_hwif_ports(&hwif->hw, base, ctl, irqport); 676 sgiioc4_init_hwif_ports(&hwif->hw, cmd_base, ctl, irqport);
656 memcpy(hwif->io_ports, hwif->hw.io_ports, 677 memcpy(hwif->io_ports, hwif->hw.io_ports,
657 sizeof (hwif->io_ports)); 678 sizeof (hwif->io_ports));
658 hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET]; 679 hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
@@ -665,6 +686,9 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t * d)
665 hwif->cds = (struct ide_pci_device_s *) d; 686 hwif->cds = (struct ide_pci_device_s *) d;
666 hwif->gendev.parent = &dev->dev;/* setup proper ancestral information */ 687 hwif->gendev.parent = &dev->dev;/* setup proper ancestral information */
667 688
689 /* The IOC4 uses MMIO rather than Port IO. */
690 default_hwif_mmiops(hwif);
691
668 /* Initializing chipset IRQ Registers */ 692 /* Initializing chipset IRQ Registers */
669 hwif->OUTL(0x03, irqport + IOC4_INTR_SET * 4); 693 hwif->OUTL(0x03, irqport + IOC4_INTR_SET * 4);
670 694
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 25ceb4a39ed2..20b392948f36 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -1082,10 +1082,10 @@ static int __devinit siimage_init_one(struct pci_dev *dev, const struct pci_devi
1082} 1082}
1083 1083
1084static struct pci_device_id siimage_pci_tbl[] = { 1084static struct pci_device_id siimage_pci_tbl[] = {
1085 { PCI_DEVICE(PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_SII_680), 0}, 1085 { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_SII_680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1086#ifdef CONFIG_BLK_DEV_IDE_SATA 1086#ifdef CONFIG_BLK_DEV_IDE_SATA
1087 { PCI_DEVICE(PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_SII_3112), 1}, 1087 { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_SII_3112, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
1088 { PCI_DEVICE(PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_SII_1210SA), 2}, 1088 { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_SII_1210SA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
1089#endif 1089#endif
1090 { 0, }, 1090 { 0, },
1091}; 1091};
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 8a6c23ac8cc1..f03196c5db37 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -86,6 +86,8 @@ static const struct {
86 u8 chipset_family; 86 u8 chipset_family;
87 u8 flags; 87 u8 flags;
88} SiSHostChipInfo[] = { 88} SiSHostChipInfo[] = {
89 { "SiS968", PCI_DEVICE_ID_SI_968, ATA_133 },
90 { "SiS966", PCI_DEVICE_ID_SI_966, ATA_133 },
89 { "SiS965", PCI_DEVICE_ID_SI_965, ATA_133 }, 91 { "SiS965", PCI_DEVICE_ID_SI_965, ATA_133 },
90 { "SiS745", PCI_DEVICE_ID_SI_745, ATA_100 }, 92 { "SiS745", PCI_DEVICE_ID_SI_745, ATA_100 },
91 { "SiS735", PCI_DEVICE_ID_SI_735, ATA_100 }, 93 { "SiS735", PCI_DEVICE_ID_SI_735, ATA_100 },
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index afdaee3c15c9..9b7589e8e93e 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -6,7 +6,7 @@
6 * 6 *
7 * vt82c576, vt82c586, vt82c586a, vt82c586b, vt82c596a, vt82c596b, 7 * vt82c576, vt82c586, vt82c586a, vt82c586b, vt82c596a, vt82c596b,
8 * vt82c686, vt82c686a, vt82c686b, vt8231, vt8233, vt8233c, vt8233a, 8 * vt82c686, vt82c686a, vt82c686b, vt8231, vt8233, vt8233c, vt8233a,
9 * vt8235, vt8237 9 * vt8235, vt8237, vt8237a
10 * 10 *
11 * Copyright (c) 2000-2002 Vojtech Pavlik 11 * Copyright (c) 2000-2002 Vojtech Pavlik
12 * 12 *
@@ -81,6 +81,7 @@ static struct via_isa_bridge {
81 { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 81 { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
82 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 82 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
83 { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 83 { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
84 { "vt8237a", PCI_DEVICE_ID_VIA_8237A, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
84 { "vt8235", PCI_DEVICE_ID_VIA_8235, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 85 { "vt8235", PCI_DEVICE_ID_VIA_8235, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
85 { "vt8233a", PCI_DEVICE_ID_VIA_8233A, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 86 { "vt8233a", PCI_DEVICE_ID_VIA_8233A, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
86 { "vt8233c", PCI_DEVICE_ID_VIA_8233C_0, 0x00, 0x2f, VIA_UDMA_100 }, 87 { "vt8233c", PCI_DEVICE_ID_VIA_8233C_0, 0x00, 0x2f, VIA_UDMA_100 },
diff --git a/drivers/ieee1394/hosts.c b/drivers/ieee1394/hosts.c
index 3ed56be8706c..59e6f49545bf 100644
--- a/drivers/ieee1394/hosts.c
+++ b/drivers/ieee1394/hosts.c
@@ -90,6 +90,14 @@ static int alloc_hostnum_cb(struct hpsb_host *host, void *__data)
90 return 0; 90 return 0;
91} 91}
92 92
93/*
94 * The pending_packet_queue is special in that it's processed
95 * from hardirq context too (such as hpsb_bus_reset()). Hence
96 * split the lock class from the usual networking skb-head
97 * lock class by using a separate key for it:
98 */
99static struct lock_class_key pending_packet_queue_key;
100
93static DEFINE_MUTEX(host_num_alloc); 101static DEFINE_MUTEX(host_num_alloc);
94 102
95/** 103/**
@@ -128,6 +136,8 @@ struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
128 h->driver = drv; 136 h->driver = drv;
129 137
130 skb_queue_head_init(&h->pending_packet_queue); 138 skb_queue_head_init(&h->pending_packet_queue);
139 lockdep_set_class(&h->pending_packet_queue.lock,
140 &pending_packet_queue_key);
131 INIT_LIST_HEAD(&h->addr_space); 141 INIT_LIST_HEAD(&h->addr_space);
132 142
133 for (i = 2; i < 16; i++) 143 for (i = 2; i < 16; i++)
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
index 2283005e3035..baa090d08d20 100644
--- a/drivers/ieee1394/ohci1394.c
+++ b/drivers/ieee1394/ohci1394.c
@@ -3553,6 +3553,8 @@ static int ohci1394_pci_resume (struct pci_dev *pdev)
3553 3553
3554static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) 3554static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state)
3555{ 3555{
3556 pci_save_state(pdev);
3557
3556#ifdef CONFIG_PPC_PMAC 3558#ifdef CONFIG_PPC_PMAC
3557 if (machine_is(powermac)) { 3559 if (machine_is(powermac)) {
3558 struct device_node *of_node; 3560 struct device_node *of_node;
@@ -3564,8 +3566,6 @@ static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state)
3564 } 3566 }
3565#endif 3567#endif
3566 3568
3567 pci_save_state(pdev);
3568
3569 return 0; 3569 return 0;
3570} 3570}
3571 3571
diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index d294bbc42f09..1205e8027829 100644
--- a/drivers/infiniband/core/addr.c
+++ b/drivers/infiniband/core/addr.c
@@ -35,6 +35,7 @@
35#include <net/arp.h> 35#include <net/arp.h>
36#include <net/neighbour.h> 36#include <net/neighbour.h>
37#include <net/route.h> 37#include <net/route.h>
38#include <net/netevent.h>
38#include <rdma/ib_addr.h> 39#include <rdma/ib_addr.h>
39 40
40MODULE_AUTHOR("Sean Hefty"); 41MODULE_AUTHOR("Sean Hefty");
@@ -326,25 +327,22 @@ void rdma_addr_cancel(struct rdma_dev_addr *addr)
326} 327}
327EXPORT_SYMBOL(rdma_addr_cancel); 328EXPORT_SYMBOL(rdma_addr_cancel);
328 329
329static int addr_arp_recv(struct sk_buff *skb, struct net_device *dev, 330static int netevent_callback(struct notifier_block *self, unsigned long event,
330 struct packet_type *pkt, struct net_device *orig_dev) 331 void *ctx)
331{ 332{
332 struct arphdr *arp_hdr; 333 if (event == NETEVENT_NEIGH_UPDATE) {
334 struct neighbour *neigh = ctx;
333 335
334 arp_hdr = (struct arphdr *) skb->nh.raw; 336 if (neigh->dev->type == ARPHRD_INFINIBAND &&
335 337 (neigh->nud_state & NUD_VALID)) {
336 if (arp_hdr->ar_op == htons(ARPOP_REQUEST) || 338 set_timeout(jiffies);
337 arp_hdr->ar_op == htons(ARPOP_REPLY)) 339 }
338 set_timeout(jiffies); 340 }
339
340 kfree_skb(skb);
341 return 0; 341 return 0;
342} 342}
343 343
344static struct packet_type addr_arp = { 344static struct notifier_block nb = {
345 .type = __constant_htons(ETH_P_ARP), 345 .notifier_call = netevent_callback
346 .func = addr_arp_recv,
347 .af_packet_priv = (void*) 1,
348}; 346};
349 347
350static int addr_init(void) 348static int addr_init(void)
@@ -353,13 +351,13 @@ static int addr_init(void)
353 if (!addr_wq) 351 if (!addr_wq)
354 return -ENOMEM; 352 return -ENOMEM;
355 353
356 dev_add_pack(&addr_arp); 354 register_netevent_notifier(&nb);
357 return 0; 355 return 0;
358} 356}
359 357
360static void addr_cleanup(void) 358static void addr_cleanup(void)
361{ 359{
362 dev_remove_pack(&addr_arp); 360 unregister_netevent_notifier(&nb);
363 destroy_workqueue(addr_wq); 361 destroy_workqueue(addr_wq);
364} 362}
365 363
diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c
index e05ca2cdc73f..75313ade2e0d 100644
--- a/drivers/infiniband/core/cache.c
+++ b/drivers/infiniband/core/cache.c
@@ -301,7 +301,8 @@ static void ib_cache_event(struct ib_event_handler *handler,
301 event->event == IB_EVENT_PORT_ACTIVE || 301 event->event == IB_EVENT_PORT_ACTIVE ||
302 event->event == IB_EVENT_LID_CHANGE || 302 event->event == IB_EVENT_LID_CHANGE ||
303 event->event == IB_EVENT_PKEY_CHANGE || 303 event->event == IB_EVENT_PKEY_CHANGE ||
304 event->event == IB_EVENT_SM_CHANGE) { 304 event->event == IB_EVENT_SM_CHANGE ||
305 event->event == IB_EVENT_CLIENT_REREGISTER) {
305 work = kmalloc(sizeof *work, GFP_ATOMIC); 306 work = kmalloc(sizeof *work, GFP_ATOMIC);
306 if (work) { 307 if (work) {
307 INIT_WORK(&work->work, ib_cache_task, work); 308 INIT_WORK(&work->work, ib_cache_task, work);
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 3f6705f3083a..0de335b7bfc2 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -701,7 +701,7 @@ static void cm_reset_to_idle(struct cm_id_private *cm_id_priv)
701 } 701 }
702} 702}
703 703
704void ib_destroy_cm_id(struct ib_cm_id *cm_id) 704static void cm_destroy_id(struct ib_cm_id *cm_id, int err)
705{ 705{
706 struct cm_id_private *cm_id_priv; 706 struct cm_id_private *cm_id_priv;
707 struct cm_work *work; 707 struct cm_work *work;
@@ -735,12 +735,22 @@ retest:
735 sizeof cm_id_priv->av.port->cm_dev->ca_guid, 735 sizeof cm_id_priv->av.port->cm_dev->ca_guid,
736 NULL, 0); 736 NULL, 0);
737 break; 737 break;
738 case IB_CM_REQ_RCVD:
739 if (err == -ENOMEM) {
740 /* Do not reject to allow future retries. */
741 cm_reset_to_idle(cm_id_priv);
742 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
743 } else {
744 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
745 ib_send_cm_rej(cm_id, IB_CM_REJ_CONSUMER_DEFINED,
746 NULL, 0, NULL, 0);
747 }
748 break;
738 case IB_CM_MRA_REQ_RCVD: 749 case IB_CM_MRA_REQ_RCVD:
739 case IB_CM_REP_SENT: 750 case IB_CM_REP_SENT:
740 case IB_CM_MRA_REP_RCVD: 751 case IB_CM_MRA_REP_RCVD:
741 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 752 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
742 /* Fall through */ 753 /* Fall through */
743 case IB_CM_REQ_RCVD:
744 case IB_CM_MRA_REQ_SENT: 754 case IB_CM_MRA_REQ_SENT:
745 case IB_CM_REP_RCVD: 755 case IB_CM_REP_RCVD:
746 case IB_CM_MRA_REP_SENT: 756 case IB_CM_MRA_REP_SENT:
@@ -775,6 +785,11 @@ retest:
775 kfree(cm_id_priv->private_data); 785 kfree(cm_id_priv->private_data);
776 kfree(cm_id_priv); 786 kfree(cm_id_priv);
777} 787}
788
789void ib_destroy_cm_id(struct ib_cm_id *cm_id)
790{
791 cm_destroy_id(cm_id, 0);
792}
778EXPORT_SYMBOL(ib_destroy_cm_id); 793EXPORT_SYMBOL(ib_destroy_cm_id);
779 794
780int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id, __be64 service_mask, 795int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id, __be64 service_mask,
@@ -960,8 +975,10 @@ int ib_send_cm_req(struct ib_cm_id *cm_id,
960 975
961 cm_id_priv->timewait_info = cm_create_timewait_info(cm_id_priv-> 976 cm_id_priv->timewait_info = cm_create_timewait_info(cm_id_priv->
962 id.local_id); 977 id.local_id);
963 if (IS_ERR(cm_id_priv->timewait_info)) 978 if (IS_ERR(cm_id_priv->timewait_info)) {
979 ret = PTR_ERR(cm_id_priv->timewait_info);
964 goto out; 980 goto out;
981 }
965 982
966 ret = cm_init_av_by_path(param->primary_path, &cm_id_priv->av); 983 ret = cm_init_av_by_path(param->primary_path, &cm_id_priv->av);
967 if (ret) 984 if (ret)
@@ -1163,7 +1180,7 @@ static void cm_process_work(struct cm_id_private *cm_id_priv,
1163 } 1180 }
1164 cm_deref_id(cm_id_priv); 1181 cm_deref_id(cm_id_priv);
1165 if (ret) 1182 if (ret)
1166 ib_destroy_cm_id(&cm_id_priv->id); 1183 cm_destroy_id(&cm_id_priv->id, ret);
1167} 1184}
1168 1185
1169static void cm_format_mra(struct cm_mra_msg *mra_msg, 1186static void cm_format_mra(struct cm_mra_msg *mra_msg,
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 863f64befc7c..5d625a81193f 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -49,7 +49,7 @@ MODULE_DESCRIPTION("Generic RDMA CM Agent");
49MODULE_LICENSE("Dual BSD/GPL"); 49MODULE_LICENSE("Dual BSD/GPL");
50 50
51#define CMA_CM_RESPONSE_TIMEOUT 20 51#define CMA_CM_RESPONSE_TIMEOUT 20
52#define CMA_MAX_CM_RETRIES 3 52#define CMA_MAX_CM_RETRIES 15
53 53
54static void cma_add_one(struct ib_device *device); 54static void cma_add_one(struct ib_device *device);
55static void cma_remove_one(struct ib_device *device); 55static void cma_remove_one(struct ib_device *device);
@@ -262,14 +262,14 @@ static void cma_detach_from_dev(struct rdma_id_private *id_priv)
262static int cma_acquire_ib_dev(struct rdma_id_private *id_priv) 262static int cma_acquire_ib_dev(struct rdma_id_private *id_priv)
263{ 263{
264 struct cma_device *cma_dev; 264 struct cma_device *cma_dev;
265 union ib_gid *gid; 265 union ib_gid gid;
266 int ret = -ENODEV; 266 int ret = -ENODEV;
267 267
268 gid = ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr); 268 ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid),
269 269
270 mutex_lock(&lock); 270 mutex_lock(&lock);
271 list_for_each_entry(cma_dev, &dev_list, list) { 271 list_for_each_entry(cma_dev, &dev_list, list) {
272 ret = ib_find_cached_gid(cma_dev->device, gid, 272 ret = ib_find_cached_gid(cma_dev->device, &gid,
273 &id_priv->id.port_num, NULL); 273 &id_priv->id.port_num, NULL);
274 if (!ret) { 274 if (!ret) {
275 cma_attach_to_dev(id_priv, cma_dev); 275 cma_attach_to_dev(id_priv, cma_dev);
@@ -812,6 +812,7 @@ static int cma_ib_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
812 cma_modify_qp_err(&id_priv->id); 812 cma_modify_qp_err(&id_priv->id);
813 status = ib_event->param.rej_rcvd.reason; 813 status = ib_event->param.rej_rcvd.reason;
814 event = RDMA_CM_EVENT_REJECTED; 814 event = RDMA_CM_EVENT_REJECTED;
815 private_data_len = IB_CM_REJ_PRIVATE_DATA_SIZE;
815 break; 816 break;
816 default: 817 default:
817 printk(KERN_ERR "RDMA CMA: unexpected IB CM event: %d", 818 printk(KERN_ERR "RDMA CMA: unexpected IB CM event: %d",
@@ -1134,8 +1135,8 @@ static int cma_query_ib_route(struct rdma_id_private *id_priv, int timeout_ms,
1134 struct ib_sa_path_rec path_rec; 1135 struct ib_sa_path_rec path_rec;
1135 1136
1136 memset(&path_rec, 0, sizeof path_rec); 1137 memset(&path_rec, 0, sizeof path_rec);
1137 path_rec.sgid = *ib_addr_get_sgid(addr); 1138 ib_addr_get_sgid(addr, &path_rec.sgid);
1138 path_rec.dgid = *ib_addr_get_dgid(addr); 1139 ib_addr_get_dgid(addr, &path_rec.dgid);
1139 path_rec.pkey = cpu_to_be16(ib_addr_get_pkey(addr)); 1140 path_rec.pkey = cpu_to_be16(ib_addr_get_pkey(addr));
1140 path_rec.numb_path = 1; 1141 path_rec.numb_path = 1;
1141 1142
@@ -1263,7 +1264,7 @@ static int cma_bind_loopback(struct rdma_id_private *id_priv)
1263{ 1264{
1264 struct cma_device *cma_dev; 1265 struct cma_device *cma_dev;
1265 struct ib_port_attr port_attr; 1266 struct ib_port_attr port_attr;
1266 union ib_gid *gid; 1267 union ib_gid gid;
1267 u16 pkey; 1268 u16 pkey;
1268 int ret; 1269 int ret;
1269 u8 p; 1270 u8 p;
@@ -1284,8 +1285,7 @@ static int cma_bind_loopback(struct rdma_id_private *id_priv)
1284 } 1285 }
1285 1286
1286port_found: 1287port_found:
1287 gid = ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr); 1288 ret = ib_get_cached_gid(cma_dev->device, p, 0, &gid);
1288 ret = ib_get_cached_gid(cma_dev->device, p, 0, gid);
1289 if (ret) 1289 if (ret)
1290 goto out; 1290 goto out;
1291 1291
@@ -1293,6 +1293,7 @@ port_found:
1293 if (ret) 1293 if (ret)
1294 goto out; 1294 goto out;
1295 1295
1296 ib_addr_set_sgid(&id_priv->id.route.addr.dev_addr, &gid);
1296 ib_addr_set_pkey(&id_priv->id.route.addr.dev_addr, pkey); 1297 ib_addr_set_pkey(&id_priv->id.route.addr.dev_addr, pkey);
1297 id_priv->id.port_num = p; 1298 id_priv->id.port_num = p;
1298 cma_attach_to_dev(id_priv, cma_dev); 1299 cma_attach_to_dev(id_priv, cma_dev);
@@ -1339,6 +1340,7 @@ static int cma_resolve_loopback(struct rdma_id_private *id_priv)
1339{ 1340{
1340 struct cma_work *work; 1341 struct cma_work *work;
1341 struct sockaddr_in *src_in, *dst_in; 1342 struct sockaddr_in *src_in, *dst_in;
1343 union ib_gid gid;
1342 int ret; 1344 int ret;
1343 1345
1344 work = kzalloc(sizeof *work, GFP_KERNEL); 1346 work = kzalloc(sizeof *work, GFP_KERNEL);
@@ -1351,8 +1353,8 @@ static int cma_resolve_loopback(struct rdma_id_private *id_priv)
1351 goto err; 1353 goto err;
1352 } 1354 }
1353 1355
1354 ib_addr_set_dgid(&id_priv->id.route.addr.dev_addr, 1356 ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid);
1355 ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr)); 1357 ib_addr_set_dgid(&id_priv->id.route.addr.dev_addr, &gid);
1356 1358
1357 if (cma_zero_addr(&id_priv->id.route.addr.src_addr)) { 1359 if (cma_zero_addr(&id_priv->id.route.addr.src_addr)) {
1358 src_in = (struct sockaddr_in *)&id_priv->id.route.addr.src_addr; 1360 src_in = (struct sockaddr_in *)&id_priv->id.route.addr.src_addr;
diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
index 615fe9cc6c56..86a3b2d401db 100644
--- a/drivers/infiniband/core/fmr_pool.c
+++ b/drivers/infiniband/core/fmr_pool.c
@@ -426,7 +426,7 @@ EXPORT_SYMBOL(ib_flush_fmr_pool);
426struct ib_pool_fmr *ib_fmr_pool_map_phys(struct ib_fmr_pool *pool_handle, 426struct ib_pool_fmr *ib_fmr_pool_map_phys(struct ib_fmr_pool *pool_handle,
427 u64 *page_list, 427 u64 *page_list,
428 int list_len, 428 int list_len,
429 u64 *io_virtual_address) 429 u64 io_virtual_address)
430{ 430{
431 struct ib_fmr_pool *pool = pool_handle; 431 struct ib_fmr_pool *pool = pool_handle;
432 struct ib_pool_fmr *fmr; 432 struct ib_pool_fmr *fmr;
@@ -440,7 +440,7 @@ struct ib_pool_fmr *ib_fmr_pool_map_phys(struct ib_fmr_pool *pool_handle,
440 fmr = ib_fmr_cache_lookup(pool, 440 fmr = ib_fmr_cache_lookup(pool,
441 page_list, 441 page_list,
442 list_len, 442 list_len,
443 *io_virtual_address); 443 io_virtual_address);
444 if (fmr) { 444 if (fmr) {
445 /* found in cache */ 445 /* found in cache */
446 ++fmr->ref_count; 446 ++fmr->ref_count;
@@ -464,7 +464,7 @@ struct ib_pool_fmr *ib_fmr_pool_map_phys(struct ib_fmr_pool *pool_handle,
464 spin_unlock_irqrestore(&pool->pool_lock, flags); 464 spin_unlock_irqrestore(&pool->pool_lock, flags);
465 465
466 result = ib_map_phys_fmr(fmr->fmr, page_list, list_len, 466 result = ib_map_phys_fmr(fmr->fmr, page_list, list_len,
467 *io_virtual_address); 467 io_virtual_address);
468 468
469 if (result) { 469 if (result) {
470 spin_lock_irqsave(&pool->pool_lock, flags); 470 spin_lock_irqsave(&pool->pool_lock, flags);
@@ -481,7 +481,7 @@ struct ib_pool_fmr *ib_fmr_pool_map_phys(struct ib_fmr_pool *pool_handle,
481 fmr->ref_count = 1; 481 fmr->ref_count = 1;
482 482
483 if (pool->cache_bucket) { 483 if (pool->cache_bucket) {
484 fmr->io_virtual_address = *io_virtual_address; 484 fmr->io_virtual_address = io_virtual_address;
485 fmr->page_list_len = list_len; 485 fmr->page_list_len = list_len;
486 memcpy(fmr->page_list, page_list, list_len * sizeof(*page_list)); 486 memcpy(fmr->page_list, page_list, list_len * sizeof(*page_list));
487 487
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index 5ed4dab52a6f..1c3cfbbe6a97 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -167,6 +167,15 @@ static int is_vendor_method_in_use(
167 return 0; 167 return 0;
168} 168}
169 169
170int ib_response_mad(struct ib_mad *mad)
171{
172 return ((mad->mad_hdr.method & IB_MGMT_METHOD_RESP) ||
173 (mad->mad_hdr.method == IB_MGMT_METHOD_TRAP_REPRESS) ||
174 ((mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_BM) &&
175 (mad->mad_hdr.attr_mod & IB_BM_ATTR_MOD_RESP)));
176}
177EXPORT_SYMBOL(ib_response_mad);
178
170/* 179/*
171 * ib_register_mad_agent - Register to send/receive MADs 180 * ib_register_mad_agent - Register to send/receive MADs
172 */ 181 */
@@ -570,13 +579,6 @@ int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent)
570} 579}
571EXPORT_SYMBOL(ib_unregister_mad_agent); 580EXPORT_SYMBOL(ib_unregister_mad_agent);
572 581
573static inline int response_mad(struct ib_mad *mad)
574{
575 /* Trap represses are responses although response bit is reset */
576 return ((mad->mad_hdr.method == IB_MGMT_METHOD_TRAP_REPRESS) ||
577 (mad->mad_hdr.method & IB_MGMT_METHOD_RESP));
578}
579
580static void dequeue_mad(struct ib_mad_list_head *mad_list) 582static void dequeue_mad(struct ib_mad_list_head *mad_list)
581{ 583{
582 struct ib_mad_queue *mad_queue; 584 struct ib_mad_queue *mad_queue;
@@ -723,7 +725,7 @@ static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv,
723 switch (ret) 725 switch (ret)
724 { 726 {
725 case IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY: 727 case IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY:
726 if (response_mad(&mad_priv->mad.mad) && 728 if (ib_response_mad(&mad_priv->mad.mad) &&
727 mad_agent_priv->agent.recv_handler) { 729 mad_agent_priv->agent.recv_handler) {
728 local->mad_priv = mad_priv; 730 local->mad_priv = mad_priv;
729 local->recv_mad_agent = mad_agent_priv; 731 local->recv_mad_agent = mad_agent_priv;
@@ -1551,7 +1553,7 @@ find_mad_agent(struct ib_mad_port_private *port_priv,
1551 unsigned long flags; 1553 unsigned long flags;
1552 1554
1553 spin_lock_irqsave(&port_priv->reg_lock, flags); 1555 spin_lock_irqsave(&port_priv->reg_lock, flags);
1554 if (response_mad(mad)) { 1556 if (ib_response_mad(mad)) {
1555 u32 hi_tid; 1557 u32 hi_tid;
1556 struct ib_mad_agent_private *entry; 1558 struct ib_mad_agent_private *entry;
1557 1559
@@ -1799,7 +1801,7 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,
1799 } 1801 }
1800 1802
1801 /* Complete corresponding request */ 1803 /* Complete corresponding request */
1802 if (response_mad(mad_recv_wc->recv_buf.mad)) { 1804 if (ib_response_mad(mad_recv_wc->recv_buf.mad)) {
1803 spin_lock_irqsave(&mad_agent_priv->lock, flags); 1805 spin_lock_irqsave(&mad_agent_priv->lock, flags);
1804 mad_send_wr = ib_find_send_mad(mad_agent_priv, mad_recv_wc); 1806 mad_send_wr = ib_find_send_mad(mad_agent_priv, mad_recv_wc);
1805 if (!mad_send_wr) { 1807 if (!mad_send_wr) {
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index e911c99ff843..d6b84226bba7 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -405,7 +405,8 @@ static void ib_sa_event(struct ib_event_handler *handler, struct ib_event *event
405 event->event == IB_EVENT_PORT_ACTIVE || 405 event->event == IB_EVENT_PORT_ACTIVE ||
406 event->event == IB_EVENT_LID_CHANGE || 406 event->event == IB_EVENT_LID_CHANGE ||
407 event->event == IB_EVENT_PKEY_CHANGE || 407 event->event == IB_EVENT_PKEY_CHANGE ||
408 event->event == IB_EVENT_SM_CHANGE) { 408 event->event == IB_EVENT_SM_CHANGE ||
409 event->event == IB_EVENT_CLIENT_REREGISTER) {
409 struct ib_sa_device *sa_dev; 410 struct ib_sa_device *sa_dev;
410 sa_dev = container_of(handler, typeof(*sa_dev), event_handler); 411 sa_dev = container_of(handler, typeof(*sa_dev), event_handler);
411 412
@@ -488,13 +489,13 @@ static void init_mad(struct ib_sa_mad *mad, struct ib_mad_agent *agent)
488 spin_unlock_irqrestore(&tid_lock, flags); 489 spin_unlock_irqrestore(&tid_lock, flags);
489} 490}
490 491
491static int send_mad(struct ib_sa_query *query, int timeout_ms) 492static int send_mad(struct ib_sa_query *query, int timeout_ms, gfp_t gfp_mask)
492{ 493{
493 unsigned long flags; 494 unsigned long flags;
494 int ret, id; 495 int ret, id;
495 496
496retry: 497retry:
497 if (!idr_pre_get(&query_idr, GFP_ATOMIC)) 498 if (!idr_pre_get(&query_idr, gfp_mask))
498 return -ENOMEM; 499 return -ENOMEM;
499 spin_lock_irqsave(&idr_lock, flags); 500 spin_lock_irqsave(&idr_lock, flags);
500 ret = idr_get_new(&query_idr, query, &id); 501 ret = idr_get_new(&query_idr, query, &id);
@@ -630,7 +631,7 @@ int ib_sa_path_rec_get(struct ib_device *device, u8 port_num,
630 631
631 *sa_query = &query->sa_query; 632 *sa_query = &query->sa_query;
632 633
633 ret = send_mad(&query->sa_query, timeout_ms); 634 ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
634 if (ret < 0) 635 if (ret < 0)
635 goto err2; 636 goto err2;
636 637
@@ -752,7 +753,7 @@ int ib_sa_service_rec_query(struct ib_device *device, u8 port_num, u8 method,
752 753
753 *sa_query = &query->sa_query; 754 *sa_query = &query->sa_query;
754 755
755 ret = send_mad(&query->sa_query, timeout_ms); 756 ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
756 if (ret < 0) 757 if (ret < 0)
757 goto err2; 758 goto err2;
758 759
@@ -844,7 +845,7 @@ int ib_sa_mcmember_rec_query(struct ib_device *device, u8 port_num,
844 845
845 *sa_query = &query->sa_query; 846 *sa_query = &query->sa_query;
846 847
847 ret = send_mad(&query->sa_query, timeout_ms); 848 ret = send_mad(&query->sa_query, timeout_ms, gfp_mask);
848 if (ret < 0) 849 if (ret < 0)
849 goto err2; 850 goto err2;
850 851
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index afe70a549c2f..1273f8807e84 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -112,8 +112,10 @@ struct ib_umad_device {
112struct ib_umad_file { 112struct ib_umad_file {
113 struct ib_umad_port *port; 113 struct ib_umad_port *port;
114 struct list_head recv_list; 114 struct list_head recv_list;
115 struct list_head send_list;
115 struct list_head port_list; 116 struct list_head port_list;
116 spinlock_t recv_lock; 117 spinlock_t recv_lock;
118 spinlock_t send_lock;
117 wait_queue_head_t recv_wait; 119 wait_queue_head_t recv_wait;
118 struct ib_mad_agent *agent[IB_UMAD_MAX_AGENTS]; 120 struct ib_mad_agent *agent[IB_UMAD_MAX_AGENTS];
119 int agents_dead; 121 int agents_dead;
@@ -177,12 +179,21 @@ static int queue_packet(struct ib_umad_file *file,
177 return ret; 179 return ret;
178} 180}
179 181
182static void dequeue_send(struct ib_umad_file *file,
183 struct ib_umad_packet *packet)
184 {
185 spin_lock_irq(&file->send_lock);
186 list_del(&packet->list);
187 spin_unlock_irq(&file->send_lock);
188 }
189
180static void send_handler(struct ib_mad_agent *agent, 190static void send_handler(struct ib_mad_agent *agent,
181 struct ib_mad_send_wc *send_wc) 191 struct ib_mad_send_wc *send_wc)
182{ 192{
183 struct ib_umad_file *file = agent->context; 193 struct ib_umad_file *file = agent->context;
184 struct ib_umad_packet *packet = send_wc->send_buf->context[0]; 194 struct ib_umad_packet *packet = send_wc->send_buf->context[0];
185 195
196 dequeue_send(file, packet);
186 ib_destroy_ah(packet->msg->ah); 197 ib_destroy_ah(packet->msg->ah);
187 ib_free_send_mad(packet->msg); 198 ib_free_send_mad(packet->msg);
188 199
@@ -370,6 +381,51 @@ static int copy_rmpp_mad(struct ib_mad_send_buf *msg, const char __user *buf)
370 return 0; 381 return 0;
371} 382}
372 383
384static int same_destination(struct ib_user_mad_hdr *hdr1,
385 struct ib_user_mad_hdr *hdr2)
386{
387 if (!hdr1->grh_present && !hdr2->grh_present)
388 return (hdr1->lid == hdr2->lid);
389
390 if (hdr1->grh_present && hdr2->grh_present)
391 return !memcmp(hdr1->gid, hdr2->gid, 16);
392
393 return 0;
394}
395
396static int is_duplicate(struct ib_umad_file *file,
397 struct ib_umad_packet *packet)
398{
399 struct ib_umad_packet *sent_packet;
400 struct ib_mad_hdr *sent_hdr, *hdr;
401
402 hdr = (struct ib_mad_hdr *) packet->mad.data;
403 list_for_each_entry(sent_packet, &file->send_list, list) {
404 sent_hdr = (struct ib_mad_hdr *) sent_packet->mad.data;
405
406 if ((hdr->tid != sent_hdr->tid) ||
407 (hdr->mgmt_class != sent_hdr->mgmt_class))
408 continue;
409
410 /*
411 * No need to be overly clever here. If two new operations have
412 * the same TID, reject the second as a duplicate. This is more
413 * restrictive than required by the spec.
414 */
415 if (!ib_response_mad((struct ib_mad *) hdr)) {
416 if (!ib_response_mad((struct ib_mad *) sent_hdr))
417 return 1;
418 continue;
419 } else if (!ib_response_mad((struct ib_mad *) sent_hdr))
420 continue;
421
422 if (same_destination(&packet->mad.hdr, &sent_packet->mad.hdr))
423 return 1;
424 }
425
426 return 0;
427}
428
373static ssize_t ib_umad_write(struct file *filp, const char __user *buf, 429static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
374 size_t count, loff_t *pos) 430 size_t count, loff_t *pos)
375{ 431{
@@ -379,7 +435,6 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
379 struct ib_ah_attr ah_attr; 435 struct ib_ah_attr ah_attr;
380 struct ib_ah *ah; 436 struct ib_ah *ah;
381 struct ib_rmpp_mad *rmpp_mad; 437 struct ib_rmpp_mad *rmpp_mad;
382 u8 method;
383 __be64 *tid; 438 __be64 *tid;
384 int ret, data_len, hdr_len, copy_offset, rmpp_active; 439 int ret, data_len, hdr_len, copy_offset, rmpp_active;
385 440
@@ -473,28 +528,36 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
473 } 528 }
474 529
475 /* 530 /*
476 * If userspace is generating a request that will generate a 531 * Set the high-order part of the transaction ID to make MADs from
477 * response, we need to make sure the high-order part of the 532 * different agents unique, and allow routing responses back to the
478 * transaction ID matches the agent being used to send the 533 * original requestor.
479 * MAD.
480 */ 534 */
481 method = ((struct ib_mad_hdr *) packet->msg->mad)->method; 535 if (!ib_response_mad(packet->msg->mad)) {
482
483 if (!(method & IB_MGMT_METHOD_RESP) &&
484 method != IB_MGMT_METHOD_TRAP_REPRESS &&
485 method != IB_MGMT_METHOD_SEND) {
486 tid = &((struct ib_mad_hdr *) packet->msg->mad)->tid; 536 tid = &((struct ib_mad_hdr *) packet->msg->mad)->tid;
487 *tid = cpu_to_be64(((u64) agent->hi_tid) << 32 | 537 *tid = cpu_to_be64(((u64) agent->hi_tid) << 32 |
488 (be64_to_cpup(tid) & 0xffffffff)); 538 (be64_to_cpup(tid) & 0xffffffff));
539 rmpp_mad->mad_hdr.tid = *tid;
540 }
541
542 spin_lock_irq(&file->send_lock);
543 ret = is_duplicate(file, packet);
544 if (!ret)
545 list_add_tail(&packet->list, &file->send_list);
546 spin_unlock_irq(&file->send_lock);
547 if (ret) {
548 ret = -EINVAL;
549 goto err_msg;
489 } 550 }
490 551
491 ret = ib_post_send_mad(packet->msg, NULL); 552 ret = ib_post_send_mad(packet->msg, NULL);
492 if (ret) 553 if (ret)
493 goto err_msg; 554 goto err_send;
494 555
495 up_read(&file->port->mutex); 556 up_read(&file->port->mutex);
496 return count; 557 return count;
497 558
559err_send:
560 dequeue_send(file, packet);
498err_msg: 561err_msg:
499 ib_free_send_mad(packet->msg); 562 ib_free_send_mad(packet->msg);
500err_ah: 563err_ah:
@@ -657,7 +720,9 @@ static int ib_umad_open(struct inode *inode, struct file *filp)
657 } 720 }
658 721
659 spin_lock_init(&file->recv_lock); 722 spin_lock_init(&file->recv_lock);
723 spin_lock_init(&file->send_lock);
660 INIT_LIST_HEAD(&file->recv_list); 724 INIT_LIST_HEAD(&file->recv_list);
725 INIT_LIST_HEAD(&file->send_list);
661 init_waitqueue_head(&file->recv_wait); 726 init_waitqueue_head(&file->recv_wait);
662 727
663 file->port = port; 728 file->port = port;
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
index bb9bee56a824..102a59c033ff 100644
--- a/drivers/infiniband/core/uverbs.h
+++ b/drivers/infiniband/core/uverbs.h
@@ -42,6 +42,7 @@
42#include <linux/kref.h> 42#include <linux/kref.h>
43#include <linux/idr.h> 43#include <linux/idr.h>
44#include <linux/mutex.h> 44#include <linux/mutex.h>
45#include <linux/completion.h>
45 46
46#include <rdma/ib_verbs.h> 47#include <rdma/ib_verbs.h>
47#include <rdma/ib_user_verbs.h> 48#include <rdma/ib_user_verbs.h>
@@ -69,6 +70,7 @@
69 70
70struct ib_uverbs_device { 71struct ib_uverbs_device {
71 struct kref ref; 72 struct kref ref;
73 struct completion comp;
72 int devnum; 74 int devnum;
73 struct cdev *dev; 75 struct cdev *dev;
74 struct class_device *class_dev; 76 struct class_device *class_dev;
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index bdf5d5098190..30923eb68ec7 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -42,6 +42,13 @@
42 42
43#include "uverbs.h" 43#include "uverbs.h"
44 44
45static struct lock_class_key pd_lock_key;
46static struct lock_class_key mr_lock_key;
47static struct lock_class_key cq_lock_key;
48static struct lock_class_key qp_lock_key;
49static struct lock_class_key ah_lock_key;
50static struct lock_class_key srq_lock_key;
51
45#define INIT_UDATA(udata, ibuf, obuf, ilen, olen) \ 52#define INIT_UDATA(udata, ibuf, obuf, ilen, olen) \
46 do { \ 53 do { \
47 (udata)->inbuf = (void __user *) (ibuf); \ 54 (udata)->inbuf = (void __user *) (ibuf); \
@@ -76,12 +83,13 @@
76 */ 83 */
77 84
78static void init_uobj(struct ib_uobject *uobj, u64 user_handle, 85static void init_uobj(struct ib_uobject *uobj, u64 user_handle,
79 struct ib_ucontext *context) 86 struct ib_ucontext *context, struct lock_class_key *key)
80{ 87{
81 uobj->user_handle = user_handle; 88 uobj->user_handle = user_handle;
82 uobj->context = context; 89 uobj->context = context;
83 kref_init(&uobj->ref); 90 kref_init(&uobj->ref);
84 init_rwsem(&uobj->mutex); 91 init_rwsem(&uobj->mutex);
92 lockdep_set_class(&uobj->mutex, key);
85 uobj->live = 0; 93 uobj->live = 0;
86} 94}
87 95
@@ -470,7 +478,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
470 if (!uobj) 478 if (!uobj)
471 return -ENOMEM; 479 return -ENOMEM;
472 480
473 init_uobj(uobj, 0, file->ucontext); 481 init_uobj(uobj, 0, file->ucontext, &pd_lock_key);
474 down_write(&uobj->mutex); 482 down_write(&uobj->mutex);
475 483
476 pd = file->device->ib_dev->alloc_pd(file->device->ib_dev, 484 pd = file->device->ib_dev->alloc_pd(file->device->ib_dev,
@@ -591,7 +599,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
591 if (!obj) 599 if (!obj)
592 return -ENOMEM; 600 return -ENOMEM;
593 601
594 init_uobj(&obj->uobject, 0, file->ucontext); 602 init_uobj(&obj->uobject, 0, file->ucontext, &mr_lock_key);
595 down_write(&obj->uobject.mutex); 603 down_write(&obj->uobject.mutex);
596 604
597 /* 605 /*
@@ -770,7 +778,7 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
770 if (!obj) 778 if (!obj)
771 return -ENOMEM; 779 return -ENOMEM;
772 780
773 init_uobj(&obj->uobject, cmd.user_handle, file->ucontext); 781 init_uobj(&obj->uobject, cmd.user_handle, file->ucontext, &cq_lock_key);
774 down_write(&obj->uobject.mutex); 782 down_write(&obj->uobject.mutex);
775 783
776 if (cmd.comp_channel >= 0) { 784 if (cmd.comp_channel >= 0) {
@@ -1051,13 +1059,14 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
1051 if (!obj) 1059 if (!obj)
1052 return -ENOMEM; 1060 return -ENOMEM;
1053 1061
1054 init_uobj(&obj->uevent.uobject, cmd.user_handle, file->ucontext); 1062 init_uobj(&obj->uevent.uobject, cmd.user_handle, file->ucontext, &qp_lock_key);
1055 down_write(&obj->uevent.uobject.mutex); 1063 down_write(&obj->uevent.uobject.mutex);
1056 1064
1065 srq = cmd.is_srq ? idr_read_srq(cmd.srq_handle, file->ucontext) : NULL;
1057 pd = idr_read_pd(cmd.pd_handle, file->ucontext); 1066 pd = idr_read_pd(cmd.pd_handle, file->ucontext);
1058 scq = idr_read_cq(cmd.send_cq_handle, file->ucontext); 1067 scq = idr_read_cq(cmd.send_cq_handle, file->ucontext);
1059 rcq = idr_read_cq(cmd.recv_cq_handle, file->ucontext); 1068 rcq = cmd.recv_cq_handle == cmd.send_cq_handle ?
1060 srq = cmd.is_srq ? idr_read_srq(cmd.srq_handle, file->ucontext) : NULL; 1069 scq : idr_read_cq(cmd.recv_cq_handle, file->ucontext);
1061 1070
1062 if (!pd || !scq || !rcq || (cmd.is_srq && !srq)) { 1071 if (!pd || !scq || !rcq || (cmd.is_srq && !srq)) {
1063 ret = -EINVAL; 1072 ret = -EINVAL;
@@ -1125,7 +1134,8 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
1125 1134
1126 put_pd_read(pd); 1135 put_pd_read(pd);
1127 put_cq_read(scq); 1136 put_cq_read(scq);
1128 put_cq_read(rcq); 1137 if (rcq != scq)
1138 put_cq_read(rcq);
1129 if (srq) 1139 if (srq)
1130 put_srq_read(srq); 1140 put_srq_read(srq);
1131 1141
@@ -1150,7 +1160,7 @@ err_put:
1150 put_pd_read(pd); 1160 put_pd_read(pd);
1151 if (scq) 1161 if (scq)
1152 put_cq_read(scq); 1162 put_cq_read(scq);
1153 if (rcq) 1163 if (rcq && rcq != scq)
1154 put_cq_read(rcq); 1164 put_cq_read(rcq);
1155 if (srq) 1165 if (srq)
1156 put_srq_read(srq); 1166 put_srq_read(srq);
@@ -1751,7 +1761,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
1751 if (!uobj) 1761 if (!uobj)
1752 return -ENOMEM; 1762 return -ENOMEM;
1753 1763
1754 init_uobj(uobj, cmd.user_handle, file->ucontext); 1764 init_uobj(uobj, cmd.user_handle, file->ucontext, &ah_lock_key);
1755 down_write(&uobj->mutex); 1765 down_write(&uobj->mutex);
1756 1766
1757 pd = idr_read_pd(cmd.pd_handle, file->ucontext); 1767 pd = idr_read_pd(cmd.pd_handle, file->ucontext);
@@ -1775,7 +1785,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
1775 ah = ib_create_ah(pd, &attr); 1785 ah = ib_create_ah(pd, &attr);
1776 if (IS_ERR(ah)) { 1786 if (IS_ERR(ah)) {
1777 ret = PTR_ERR(ah); 1787 ret = PTR_ERR(ah);
1778 goto err; 1788 goto err_put;
1779 } 1789 }
1780 1790
1781 ah->uobject = uobj; 1791 ah->uobject = uobj;
@@ -1811,6 +1821,9 @@ err_copy:
1811err_destroy: 1821err_destroy:
1812 ib_destroy_ah(ah); 1822 ib_destroy_ah(ah);
1813 1823
1824err_put:
1825 put_pd_read(pd);
1826
1814err: 1827err:
1815 put_uobj_write(uobj); 1828 put_uobj_write(uobj);
1816 return ret; 1829 return ret;
@@ -1963,7 +1976,7 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
1963 if (!obj) 1976 if (!obj)
1964 return -ENOMEM; 1977 return -ENOMEM;
1965 1978
1966 init_uobj(&obj->uobject, cmd.user_handle, file->ucontext); 1979 init_uobj(&obj->uobject, cmd.user_handle, file->ucontext, &srq_lock_key);
1967 down_write(&obj->uobject.mutex); 1980 down_write(&obj->uobject.mutex);
1968 1981
1969 pd = idr_read_pd(cmd.pd_handle, file->ucontext); 1982 pd = idr_read_pd(cmd.pd_handle, file->ucontext);
@@ -1984,7 +1997,7 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
1984 srq = pd->device->create_srq(pd, &attr, &udata); 1997 srq = pd->device->create_srq(pd, &attr, &udata);
1985 if (IS_ERR(srq)) { 1998 if (IS_ERR(srq)) {
1986 ret = PTR_ERR(srq); 1999 ret = PTR_ERR(srq);
1987 goto err; 2000 goto err_put;
1988 } 2001 }
1989 2002
1990 srq->device = pd->device; 2003 srq->device = pd->device;
@@ -2029,6 +2042,9 @@ err_copy:
2029err_destroy: 2042err_destroy:
2030 ib_destroy_srq(srq); 2043 ib_destroy_srq(srq);
2031 2044
2045err_put:
2046 put_pd_read(pd);
2047
2032err: 2048err:
2033 put_uobj_write(&obj->uobject); 2049 put_uobj_write(&obj->uobject);
2034 return ret; 2050 return ret;
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index e725cccc7cde..4e16314e8e6d 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -122,7 +122,7 @@ static void ib_uverbs_release_dev(struct kref *ref)
122 struct ib_uverbs_device *dev = 122 struct ib_uverbs_device *dev =
123 container_of(ref, struct ib_uverbs_device, ref); 123 container_of(ref, struct ib_uverbs_device, ref);
124 124
125 kfree(dev); 125 complete(&dev->comp);
126} 126}
127 127
128void ib_uverbs_release_ucq(struct ib_uverbs_file *file, 128void ib_uverbs_release_ucq(struct ib_uverbs_file *file,
@@ -740,6 +740,7 @@ static void ib_uverbs_add_one(struct ib_device *device)
740 return; 740 return;
741 741
742 kref_init(&uverbs_dev->ref); 742 kref_init(&uverbs_dev->ref);
743 init_completion(&uverbs_dev->comp);
743 744
744 spin_lock(&map_lock); 745 spin_lock(&map_lock);
745 uverbs_dev->devnum = find_first_zero_bit(dev_map, IB_UVERBS_MAX_DEVICES); 746 uverbs_dev->devnum = find_first_zero_bit(dev_map, IB_UVERBS_MAX_DEVICES);
@@ -793,6 +794,8 @@ err_cdev:
793 794
794err: 795err:
795 kref_put(&uverbs_dev->ref, ib_uverbs_release_dev); 796 kref_put(&uverbs_dev->ref, ib_uverbs_release_dev);
797 wait_for_completion(&uverbs_dev->comp);
798 kfree(uverbs_dev);
796 return; 799 return;
797} 800}
798 801
@@ -812,7 +815,10 @@ static void ib_uverbs_remove_one(struct ib_device *device)
812 spin_unlock(&map_lock); 815 spin_unlock(&map_lock);
813 816
814 clear_bit(uverbs_dev->devnum, dev_map); 817 clear_bit(uverbs_dev->devnum, dev_map);
818
815 kref_put(&uverbs_dev->ref, ib_uverbs_release_dev); 819 kref_put(&uverbs_dev->ref, ib_uverbs_release_dev);
820 wait_for_completion(&uverbs_dev->comp);
821 kfree(uverbs_dev);
816} 822}
817 823
818static int uverbs_event_get_sb(struct file_system_type *fs_type, int flags, 824static int uverbs_event_get_sb(struct file_system_type *fs_type, int flags,
diff --git a/drivers/infiniband/hw/ipath/ipath_driver.c b/drivers/infiniband/hw/ipath/ipath_driver.c
index 823131d58b34..f98518d912b5 100644
--- a/drivers/infiniband/hw/ipath/ipath_driver.c
+++ b/drivers/infiniband/hw/ipath/ipath_driver.c
@@ -859,6 +859,38 @@ static void ipath_rcv_layer(struct ipath_devdata *dd, u32 etail,
859 __ipath_layer_rcv_lid(dd, hdr); 859 __ipath_layer_rcv_lid(dd, hdr);
860} 860}
861 861
862static void ipath_rcv_hdrerr(struct ipath_devdata *dd,
863 u32 eflags,
864 u32 l,
865 u32 etail,
866 u64 *rc)
867{
868 char emsg[128];
869 struct ipath_message_header *hdr;
870
871 get_rhf_errstring(eflags, emsg, sizeof emsg);
872 hdr = (struct ipath_message_header *)&rc[1];
873 ipath_cdbg(PKT, "RHFerrs %x hdrqtail=%x typ=%u "
874 "tlen=%x opcode=%x egridx=%x: %s\n",
875 eflags, l,
876 ipath_hdrget_rcv_type((__le32 *) rc),
877 ipath_hdrget_length_in_bytes((__le32 *) rc),
878 be32_to_cpu(hdr->bth[0]) >> 24,
879 etail, emsg);
880
881 /* Count local link integrity errors. */
882 if (eflags & (INFINIPATH_RHF_H_ICRCERR | INFINIPATH_RHF_H_VCRCERR)) {
883 u8 n = (dd->ipath_ibcctrl >>
884 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
885 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
886
887 if (++dd->ipath_lli_counter > n) {
888 dd->ipath_lli_counter = 0;
889 dd->ipath_lli_errors++;
890 }
891 }
892}
893
862/* 894/*
863 * ipath_kreceive - receive a packet 895 * ipath_kreceive - receive a packet
864 * @dd: the infinipath device 896 * @dd: the infinipath device
@@ -875,7 +907,6 @@ void ipath_kreceive(struct ipath_devdata *dd)
875 struct ipath_message_header *hdr; 907 struct ipath_message_header *hdr;
876 u32 eflags, i, etype, tlen, pkttot = 0, updegr=0, reloop=0; 908 u32 eflags, i, etype, tlen, pkttot = 0, updegr=0, reloop=0;
877 static u64 totcalls; /* stats, may eventually remove */ 909 static u64 totcalls; /* stats, may eventually remove */
878 char emsg[128];
879 910
880 if (!dd->ipath_hdrqtailptr) { 911 if (!dd->ipath_hdrqtailptr) {
881 ipath_dev_err(dd, 912 ipath_dev_err(dd,
@@ -938,26 +969,9 @@ reloop:
938 "%x\n", etype); 969 "%x\n", etype);
939 } 970 }
940 971
941 if (eflags & ~(INFINIPATH_RHF_H_TIDERR | 972 if (unlikely(eflags))
942 INFINIPATH_RHF_H_IHDRERR)) { 973 ipath_rcv_hdrerr(dd, eflags, l, etail, rc);
943 get_rhf_errstring(eflags, emsg, sizeof emsg); 974 else if (etype == RCVHQ_RCV_TYPE_NON_KD) {
944 ipath_cdbg(PKT, "RHFerrs %x hdrqtail=%x typ=%u "
945 "tlen=%x opcode=%x egridx=%x: %s\n",
946 eflags, l, etype, tlen, bthbytes[0],
947 ipath_hdrget_index((__le32 *) rc), emsg);
948 /* Count local link integrity errors. */
949 if (eflags & (INFINIPATH_RHF_H_ICRCERR |
950 INFINIPATH_RHF_H_VCRCERR)) {
951 u8 n = (dd->ipath_ibcctrl >>
952 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
953 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
954
955 if (++dd->ipath_lli_counter > n) {
956 dd->ipath_lli_counter = 0;
957 dd->ipath_lli_errors++;
958 }
959 }
960 } else if (etype == RCVHQ_RCV_TYPE_NON_KD) {
961 int ret = __ipath_verbs_rcv(dd, rc + 1, 975 int ret = __ipath_verbs_rcv(dd, rc + 1,
962 ebuf, tlen); 976 ebuf, tlen);
963 if (ret == -ENODEV) 977 if (ret == -ENODEV)
@@ -981,25 +995,7 @@ reloop:
981 else if (etype == RCVHQ_RCV_TYPE_EXPECTED) 995 else if (etype == RCVHQ_RCV_TYPE_EXPECTED)
982 ipath_dbg("Bug: Expected TID, opcode %x; ignored\n", 996 ipath_dbg("Bug: Expected TID, opcode %x; ignored\n",
983 be32_to_cpu(hdr->bth[0]) & 0xff); 997 be32_to_cpu(hdr->bth[0]) & 0xff);
984 else if (eflags & (INFINIPATH_RHF_H_TIDERR | 998 else {
985 INFINIPATH_RHF_H_IHDRERR)) {
986 /*
987 * This is a type 3 packet, only the LRH is in the
988 * rcvhdrq, the rest of the header is in the eager
989 * buffer.
990 */
991 u8 opcode;
992 if (ebuf) {
993 bthbytes = (u8 *) ebuf;
994 opcode = *bthbytes;
995 }
996 else
997 opcode = 0;
998 get_rhf_errstring(eflags, emsg, sizeof emsg);
999 ipath_dbg("Err %x (%s), opcode %x, egrbuf %x, "
1000 "len %x\n", eflags, emsg, opcode, etail,
1001 tlen);
1002 } else {
1003 /* 999 /*
1004 * error packet, type of error unknown. 1000 * error packet, type of error unknown.
1005 * Probably type 3, but we don't know, so don't 1001 * Probably type 3, but we don't know, so don't
diff --git a/drivers/infiniband/hw/ipath/ipath_keys.c b/drivers/infiniband/hw/ipath/ipath_keys.c
index 46773c673a1a..a5ca279370aa 100644
--- a/drivers/infiniband/hw/ipath/ipath_keys.c
+++ b/drivers/infiniband/hw/ipath/ipath_keys.c
@@ -197,6 +197,21 @@ int ipath_rkey_ok(struct ipath_ibdev *dev, struct ipath_sge_state *ss,
197 size_t off; 197 size_t off;
198 int ret; 198 int ret;
199 199
200 /*
201 * We use RKEY == zero for physical addresses
202 * (see ipath_get_dma_mr).
203 */
204 if (rkey == 0) {
205 sge->mr = NULL;
206 sge->vaddr = phys_to_virt(vaddr);
207 sge->length = len;
208 sge->sge_length = len;
209 ss->sg_list = NULL;
210 ss->num_sge = 1;
211 ret = 1;
212 goto bail;
213 }
214
200 mr = rkt->table[(rkey >> (32 - ib_ipath_lkey_table_size))]; 215 mr = rkt->table[(rkey >> (32 - ib_ipath_lkey_table_size))];
201 if (unlikely(mr == NULL || mr->lkey != rkey)) { 216 if (unlikely(mr == NULL || mr->lkey != rkey)) {
202 ret = 0; 217 ret = 0;
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.c b/drivers/infiniband/hw/ipath/ipath_verbs.c
index 56ac336dd1ec..d70a9b6b5239 100644
--- a/drivers/infiniband/hw/ipath/ipath_verbs.c
+++ b/drivers/infiniband/hw/ipath/ipath_verbs.c
@@ -191,10 +191,6 @@ void ipath_skip_sge(struct ipath_sge_state *ss, u32 length)
191{ 191{
192 struct ipath_sge *sge = &ss->sge; 192 struct ipath_sge *sge = &ss->sge;
193 193
194 while (length > sge->sge_length) {
195 length -= sge->sge_length;
196 ss->sge = *ss->sg_list++;
197 }
198 while (length) { 194 while (length) {
199 u32 len = sge->length; 195 u32 len = sge->length;
200 196
@@ -627,6 +623,7 @@ static int ipath_query_device(struct ib_device *ibdev,
627 props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR | 623 props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
628 IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT | 624 IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
629 IB_DEVICE_SYS_IMAGE_GUID; 625 IB_DEVICE_SYS_IMAGE_GUID;
626 props->page_size_cap = PAGE_SIZE;
630 props->vendor_id = ipath_layer_get_vendorid(dev->dd); 627 props->vendor_id = ipath_layer_get_vendorid(dev->dd);
631 props->vendor_part_id = ipath_layer_get_deviceid(dev->dd); 628 props->vendor_part_id = ipath_layer_get_deviceid(dev->dd);
632 props->hw_ver = ipath_layer_get_pcirev(dev->dd); 629 props->hw_ver = ipath_layer_get_pcirev(dev->dd);
diff --git a/drivers/infiniband/hw/mthca/mthca_allocator.c b/drivers/infiniband/hw/mthca/mthca_allocator.c
index 9ba3211cef7c..f930e55b58fc 100644
--- a/drivers/infiniband/hw/mthca/mthca_allocator.c
+++ b/drivers/infiniband/hw/mthca/mthca_allocator.c
@@ -41,9 +41,11 @@
41/* Trivial bitmap-based allocator */ 41/* Trivial bitmap-based allocator */
42u32 mthca_alloc(struct mthca_alloc *alloc) 42u32 mthca_alloc(struct mthca_alloc *alloc)
43{ 43{
44 unsigned long flags;
44 u32 obj; 45 u32 obj;
45 46
46 spin_lock(&alloc->lock); 47 spin_lock_irqsave(&alloc->lock, flags);
48
47 obj = find_next_zero_bit(alloc->table, alloc->max, alloc->last); 49 obj = find_next_zero_bit(alloc->table, alloc->max, alloc->last);
48 if (obj >= alloc->max) { 50 if (obj >= alloc->max) {
49 alloc->top = (alloc->top + alloc->max) & alloc->mask; 51 alloc->top = (alloc->top + alloc->max) & alloc->mask;
@@ -56,19 +58,24 @@ u32 mthca_alloc(struct mthca_alloc *alloc)
56 } else 58 } else
57 obj = -1; 59 obj = -1;
58 60
59 spin_unlock(&alloc->lock); 61 spin_unlock_irqrestore(&alloc->lock, flags);
60 62
61 return obj; 63 return obj;
62} 64}
63 65
64void mthca_free(struct mthca_alloc *alloc, u32 obj) 66void mthca_free(struct mthca_alloc *alloc, u32 obj)
65{ 67{
68 unsigned long flags;
69
66 obj &= alloc->max - 1; 70 obj &= alloc->max - 1;
67 spin_lock(&alloc->lock); 71
72 spin_lock_irqsave(&alloc->lock, flags);
73
68 clear_bit(obj, alloc->table); 74 clear_bit(obj, alloc->table);
69 alloc->last = min(alloc->last, obj); 75 alloc->last = min(alloc->last, obj);
70 alloc->top = (alloc->top + alloc->max) & alloc->mask; 76 alloc->top = (alloc->top + alloc->max) & alloc->mask;
71 spin_unlock(&alloc->lock); 77
78 spin_unlock_irqrestore(&alloc->lock, flags);
72} 79}
73 80
74int mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask, 81int mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask,
@@ -108,14 +115,15 @@ void mthca_alloc_cleanup(struct mthca_alloc *alloc)
108 * serialize access to the array. 115 * serialize access to the array.
109 */ 116 */
110 117
118#define MTHCA_ARRAY_MASK (PAGE_SIZE / sizeof (void *) - 1)
119
111void *mthca_array_get(struct mthca_array *array, int index) 120void *mthca_array_get(struct mthca_array *array, int index)
112{ 121{
113 int p = (index * sizeof (void *)) >> PAGE_SHIFT; 122 int p = (index * sizeof (void *)) >> PAGE_SHIFT;
114 123
115 if (array->page_list[p].page) { 124 if (array->page_list[p].page)
116 int i = index & (PAGE_SIZE / sizeof (void *) - 1); 125 return array->page_list[p].page[index & MTHCA_ARRAY_MASK];
117 return array->page_list[p].page[i]; 126 else
118 } else
119 return NULL; 127 return NULL;
120} 128}
121 129
@@ -130,8 +138,7 @@ int mthca_array_set(struct mthca_array *array, int index, void *value)
130 if (!array->page_list[p].page) 138 if (!array->page_list[p].page)
131 return -ENOMEM; 139 return -ENOMEM;
132 140
133 array->page_list[p].page[index & (PAGE_SIZE / sizeof (void *) - 1)] = 141 array->page_list[p].page[index & MTHCA_ARRAY_MASK] = value;
134 value;
135 ++array->page_list[p].used; 142 ++array->page_list[p].used;
136 143
137 return 0; 144 return 0;
@@ -144,7 +151,8 @@ void mthca_array_clear(struct mthca_array *array, int index)
144 if (--array->page_list[p].used == 0) { 151 if (--array->page_list[p].used == 0) {
145 free_page((unsigned long) array->page_list[p].page); 152 free_page((unsigned long) array->page_list[p].page);
146 array->page_list[p].page = NULL; 153 array->page_list[p].page = NULL;
147 } 154 } else
155 array->page_list[p].page[index & MTHCA_ARRAY_MASK] = NULL;
148 156
149 if (array->page_list[p].used < 0) 157 if (array->page_list[p].used < 0)
150 pr_debug("Array %p index %d page %d with ref count %d < 0\n", 158 pr_debug("Array %p index %d page %d with ref count %d < 0\n",
diff --git a/drivers/infiniband/hw/mthca/mthca_av.c b/drivers/infiniband/hw/mthca/mthca_av.c
index b12aa03be251..e215041b2db9 100644
--- a/drivers/infiniband/hw/mthca/mthca_av.c
+++ b/drivers/infiniband/hw/mthca/mthca_av.c
@@ -303,9 +303,10 @@ int mthca_ah_query(struct ib_ah *ibah, struct ib_ah_attr *attr)
303 memset(attr, 0, sizeof *attr); 303 memset(attr, 0, sizeof *attr);
304 attr->dlid = be16_to_cpu(ah->av->dlid); 304 attr->dlid = be16_to_cpu(ah->av->dlid);
305 attr->sl = be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 28; 305 attr->sl = be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 28;
306 attr->static_rate = ah->av->msg_sr & 0x7;
307 attr->src_path_bits = ah->av->g_slid & 0x7F;
308 attr->port_num = be32_to_cpu(ah->av->port_pd) >> 24; 306 attr->port_num = be32_to_cpu(ah->av->port_pd) >> 24;
307 attr->static_rate = mthca_rate_to_ib(dev, ah->av->msg_sr & 0x7,
308 attr->port_num);
309 attr->src_path_bits = ah->av->g_slid & 0x7F;
309 attr->ah_flags = mthca_ah_grh_present(ah) ? IB_AH_GRH : 0; 310 attr->ah_flags = mthca_ah_grh_present(ah) ? IB_AH_GRH : 0;
310 311
311 if (attr->ah_flags) { 312 if (attr->ah_flags) {
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
index d0f7731802c9..deabc14b4ea4 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
@@ -778,11 +778,12 @@ int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
778 ((dev->fw_ver & 0xffff0000ull) >> 16) | 778 ((dev->fw_ver & 0xffff0000ull) >> 16) |
779 ((dev->fw_ver & 0x0000ffffull) << 16); 779 ((dev->fw_ver & 0x0000ffffull) << 16);
780 780
781 MTHCA_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET);
782 dev->cmd.max_cmds = 1 << lg;
783
781 mthca_dbg(dev, "FW version %012llx, max commands %d\n", 784 mthca_dbg(dev, "FW version %012llx, max commands %d\n",
782 (unsigned long long) dev->fw_ver, dev->cmd.max_cmds); 785 (unsigned long long) dev->fw_ver, dev->cmd.max_cmds);
783 786
784 MTHCA_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET);
785 dev->cmd.max_cmds = 1 << lg;
786 MTHCA_GET(dev->catas_err.addr, outbox, QUERY_FW_ERR_START_OFFSET); 787 MTHCA_GET(dev->catas_err.addr, outbox, QUERY_FW_ERR_START_OFFSET);
787 MTHCA_GET(dev->catas_err.size, outbox, QUERY_FW_ERR_SIZE_OFFSET); 788 MTHCA_GET(dev->catas_err.size, outbox, QUERY_FW_ERR_SIZE_OFFSET);
788 789
diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
index 557cde3a4563..7b82c1907f04 100644
--- a/drivers/infiniband/hw/mthca/mthca_main.c
+++ b/drivers/infiniband/hw/mthca/mthca_main.c
@@ -967,12 +967,12 @@ static struct {
967} mthca_hca_table[] = { 967} mthca_hca_table[] = {
968 [TAVOR] = { .latest_fw = MTHCA_FW_VER(3, 4, 0), 968 [TAVOR] = { .latest_fw = MTHCA_FW_VER(3, 4, 0),
969 .flags = 0 }, 969 .flags = 0 },
970 [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 7, 400), 970 [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 7, 600),
971 .flags = MTHCA_FLAG_PCIE }, 971 .flags = MTHCA_FLAG_PCIE },
972 [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 1, 0), 972 [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 1, 400),
973 .flags = MTHCA_FLAG_MEMFREE | 973 .flags = MTHCA_FLAG_MEMFREE |
974 MTHCA_FLAG_PCIE }, 974 MTHCA_FLAG_PCIE },
975 [SINAI] = { .latest_fw = MTHCA_FW_VER(1, 0, 800), 975 [SINAI] = { .latest_fw = MTHCA_FW_VER(1, 1, 0),
976 .flags = MTHCA_FLAG_MEMFREE | 976 .flags = MTHCA_FLAG_MEMFREE |
977 MTHCA_FLAG_PCIE | 977 MTHCA_FLAG_PCIE |
978 MTHCA_FLAG_SINAI_OPT } 978 MTHCA_FLAG_SINAI_OPT }
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index 230ae21db8fd..265b1d1c4a62 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -1287,11 +1287,7 @@ int mthca_register_device(struct mthca_dev *dev)
1287 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | 1287 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
1288 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | 1288 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
1289 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | 1289 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
1290 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | 1290 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST);
1291 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
1292 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
1293 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
1294 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
1295 dev->ib_dev.node_type = IB_NODE_CA; 1291 dev->ib_dev.node_type = IB_NODE_CA;
1296 dev->ib_dev.phys_port_cnt = dev->limits.num_ports; 1292 dev->ib_dev.phys_port_cnt = dev->limits.num_ports;
1297 dev->ib_dev.dma_device = &dev->pdev->dev; 1293 dev->ib_dev.dma_device = &dev->pdev->dev;
@@ -1316,6 +1312,11 @@ int mthca_register_device(struct mthca_dev *dev)
1316 dev->ib_dev.modify_srq = mthca_modify_srq; 1312 dev->ib_dev.modify_srq = mthca_modify_srq;
1317 dev->ib_dev.query_srq = mthca_query_srq; 1313 dev->ib_dev.query_srq = mthca_query_srq;
1318 dev->ib_dev.destroy_srq = mthca_destroy_srq; 1314 dev->ib_dev.destroy_srq = mthca_destroy_srq;
1315 dev->ib_dev.uverbs_cmd_mask |=
1316 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
1317 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
1318 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
1319 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
1319 1320
1320 if (mthca_is_memfree(dev)) 1321 if (mthca_is_memfree(dev))
1321 dev->ib_dev.post_srq_recv = mthca_arbel_post_srq_recv; 1322 dev->ib_dev.post_srq_recv = mthca_arbel_post_srq_recv;
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.h b/drivers/infiniband/hw/mthca/mthca_provider.h
index 8de2887ba15c..9a5bece3fa5c 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.h
+++ b/drivers/infiniband/hw/mthca/mthca_provider.h
@@ -136,8 +136,8 @@ struct mthca_ah {
136 * We have one global lock that protects dev->cq/qp_table. Each 136 * We have one global lock that protects dev->cq/qp_table. Each
137 * struct mthca_cq/qp also has its own lock. An individual qp lock 137 * struct mthca_cq/qp also has its own lock. An individual qp lock
138 * may be taken inside of an individual cq lock. Both cqs attached to 138 * may be taken inside of an individual cq lock. Both cqs attached to
139 * a qp may be locked, with the send cq locked first. No other 139 * a qp may be locked, with the cq with the lower cqn locked first.
140 * nesting should be done. 140 * No other nesting should be done.
141 * 141 *
142 * Each struct mthca_cq/qp also has an ref count, protected by the 142 * Each struct mthca_cq/qp also has an ref count, protected by the
143 * corresponding table lock. The pointer from the cq/qp_table to the 143 * corresponding table lock. The pointer from the cq/qp_table to the
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index 16c387d8170c..2e8f6f36e0a5 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -99,6 +99,10 @@ enum {
99 MTHCA_QP_BIT_RSC = 1 << 3 99 MTHCA_QP_BIT_RSC = 1 << 3
100}; 100};
101 101
102enum {
103 MTHCA_SEND_DOORBELL_FENCE = 1 << 5
104};
105
102struct mthca_qp_path { 106struct mthca_qp_path {
103 __be32 port_pkey; 107 __be32 port_pkey;
104 u8 rnr_retry; 108 u8 rnr_retry;
@@ -222,9 +226,8 @@ static void *get_send_wqe(struct mthca_qp *qp, int n)
222 (PAGE_SIZE - 1)); 226 (PAGE_SIZE - 1));
223} 227}
224 228
225static void mthca_wq_init(struct mthca_wq *wq) 229static void mthca_wq_reset(struct mthca_wq *wq)
226{ 230{
227 spin_lock_init(&wq->lock);
228 wq->next_ind = 0; 231 wq->next_ind = 0;
229 wq->last_comp = wq->max - 1; 232 wq->last_comp = wq->max - 1;
230 wq->head = 0; 233 wq->head = 0;
@@ -845,10 +848,10 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
845 mthca_cq_clean(dev, to_mcq(qp->ibqp.recv_cq), qp->qpn, 848 mthca_cq_clean(dev, to_mcq(qp->ibqp.recv_cq), qp->qpn,
846 qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL); 849 qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL);
847 850
848 mthca_wq_init(&qp->sq); 851 mthca_wq_reset(&qp->sq);
849 qp->sq.last = get_send_wqe(qp, qp->sq.max - 1); 852 qp->sq.last = get_send_wqe(qp, qp->sq.max - 1);
850 853
851 mthca_wq_init(&qp->rq); 854 mthca_wq_reset(&qp->rq);
852 qp->rq.last = get_recv_wqe(qp, qp->rq.max - 1); 855 qp->rq.last = get_recv_wqe(qp, qp->rq.max - 1);
853 856
854 if (mthca_is_memfree(dev)) { 857 if (mthca_is_memfree(dev)) {
@@ -1112,8 +1115,11 @@ static int mthca_alloc_qp_common(struct mthca_dev *dev,
1112 qp->atomic_rd_en = 0; 1115 qp->atomic_rd_en = 0;
1113 qp->resp_depth = 0; 1116 qp->resp_depth = 0;
1114 qp->sq_policy = send_policy; 1117 qp->sq_policy = send_policy;
1115 mthca_wq_init(&qp->sq); 1118 mthca_wq_reset(&qp->sq);
1116 mthca_wq_init(&qp->rq); 1119 mthca_wq_reset(&qp->rq);
1120
1121 spin_lock_init(&qp->sq.lock);
1122 spin_lock_init(&qp->rq.lock);
1117 1123
1118 ret = mthca_map_memfree(dev, qp); 1124 ret = mthca_map_memfree(dev, qp);
1119 if (ret) 1125 if (ret)
@@ -1257,6 +1263,32 @@ int mthca_alloc_qp(struct mthca_dev *dev,
1257 return 0; 1263 return 0;
1258} 1264}
1259 1265
1266static void mthca_lock_cqs(struct mthca_cq *send_cq, struct mthca_cq *recv_cq)
1267{
1268 if (send_cq == recv_cq)
1269 spin_lock_irq(&send_cq->lock);
1270 else if (send_cq->cqn < recv_cq->cqn) {
1271 spin_lock_irq(&send_cq->lock);
1272 spin_lock_nested(&recv_cq->lock, SINGLE_DEPTH_NESTING);
1273 } else {
1274 spin_lock_irq(&recv_cq->lock);
1275 spin_lock_nested(&send_cq->lock, SINGLE_DEPTH_NESTING);
1276 }
1277}
1278
1279static void mthca_unlock_cqs(struct mthca_cq *send_cq, struct mthca_cq *recv_cq)
1280{
1281 if (send_cq == recv_cq)
1282 spin_unlock_irq(&send_cq->lock);
1283 else if (send_cq->cqn < recv_cq->cqn) {
1284 spin_unlock(&recv_cq->lock);
1285 spin_unlock_irq(&send_cq->lock);
1286 } else {
1287 spin_unlock(&send_cq->lock);
1288 spin_unlock_irq(&recv_cq->lock);
1289 }
1290}
1291
1260int mthca_alloc_sqp(struct mthca_dev *dev, 1292int mthca_alloc_sqp(struct mthca_dev *dev,
1261 struct mthca_pd *pd, 1293 struct mthca_pd *pd,
1262 struct mthca_cq *send_cq, 1294 struct mthca_cq *send_cq,
@@ -1309,17 +1341,13 @@ int mthca_alloc_sqp(struct mthca_dev *dev,
1309 * Lock CQs here, so that CQ polling code can do QP lookup 1341 * Lock CQs here, so that CQ polling code can do QP lookup
1310 * without taking a lock. 1342 * without taking a lock.
1311 */ 1343 */
1312 spin_lock_irq(&send_cq->lock); 1344 mthca_lock_cqs(send_cq, recv_cq);
1313 if (send_cq != recv_cq)
1314 spin_lock(&recv_cq->lock);
1315 1345
1316 spin_lock(&dev->qp_table.lock); 1346 spin_lock(&dev->qp_table.lock);
1317 mthca_array_clear(&dev->qp_table.qp, mqpn); 1347 mthca_array_clear(&dev->qp_table.qp, mqpn);
1318 spin_unlock(&dev->qp_table.lock); 1348 spin_unlock(&dev->qp_table.lock);
1319 1349
1320 if (send_cq != recv_cq) 1350 mthca_unlock_cqs(send_cq, recv_cq);
1321 spin_unlock(&recv_cq->lock);
1322 spin_unlock_irq(&send_cq->lock);
1323 1351
1324 err_out: 1352 err_out:
1325 dma_free_coherent(&dev->pdev->dev, sqp->header_buf_size, 1353 dma_free_coherent(&dev->pdev->dev, sqp->header_buf_size,
@@ -1353,9 +1381,7 @@ void mthca_free_qp(struct mthca_dev *dev,
1353 * Lock CQs here, so that CQ polling code can do QP lookup 1381 * Lock CQs here, so that CQ polling code can do QP lookup
1354 * without taking a lock. 1382 * without taking a lock.
1355 */ 1383 */
1356 spin_lock_irq(&send_cq->lock); 1384 mthca_lock_cqs(send_cq, recv_cq);
1357 if (send_cq != recv_cq)
1358 spin_lock(&recv_cq->lock);
1359 1385
1360 spin_lock(&dev->qp_table.lock); 1386 spin_lock(&dev->qp_table.lock);
1361 mthca_array_clear(&dev->qp_table.qp, 1387 mthca_array_clear(&dev->qp_table.qp,
@@ -1363,9 +1389,7 @@ void mthca_free_qp(struct mthca_dev *dev,
1363 --qp->refcount; 1389 --qp->refcount;
1364 spin_unlock(&dev->qp_table.lock); 1390 spin_unlock(&dev->qp_table.lock);
1365 1391
1366 if (send_cq != recv_cq) 1392 mthca_unlock_cqs(send_cq, recv_cq);
1367 spin_unlock(&recv_cq->lock);
1368 spin_unlock_irq(&send_cq->lock);
1369 1393
1370 wait_event(qp->wait, !get_qp_refcount(dev, qp)); 1394 wait_event(qp->wait, !get_qp_refcount(dev, qp));
1371 1395
@@ -1500,7 +1524,7 @@ int mthca_tavor_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1500 int i; 1524 int i;
1501 int size; 1525 int size;
1502 int size0 = 0; 1526 int size0 = 0;
1503 u32 f0 = 0; 1527 u32 f0;
1504 int ind; 1528 int ind;
1505 u8 op0 = 0; 1529 u8 op0 = 0;
1506 1530
@@ -1684,6 +1708,8 @@ int mthca_tavor_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1684 if (!size0) { 1708 if (!size0) {
1685 size0 = size; 1709 size0 = size;
1686 op0 = mthca_opcode[wr->opcode]; 1710 op0 = mthca_opcode[wr->opcode];
1711 f0 = wr->send_flags & IB_SEND_FENCE ?
1712 MTHCA_SEND_DOORBELL_FENCE : 0;
1687 } 1713 }
1688 1714
1689 ++ind; 1715 ++ind;
@@ -1841,7 +1867,7 @@ int mthca_arbel_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1841 int i; 1867 int i;
1842 int size; 1868 int size;
1843 int size0 = 0; 1869 int size0 = 0;
1844 u32 f0 = 0; 1870 u32 f0;
1845 int ind; 1871 int ind;
1846 u8 op0 = 0; 1872 u8 op0 = 0;
1847 1873
@@ -2049,6 +2075,8 @@ int mthca_arbel_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
2049 if (!size0) { 2075 if (!size0) {
2050 size0 = size; 2076 size0 = size;
2051 op0 = mthca_opcode[wr->opcode]; 2077 op0 = mthca_opcode[wr->opcode];
2078 f0 = wr->send_flags & IB_SEND_FENCE ?
2079 MTHCA_SEND_DOORBELL_FENCE : 0;
2052 } 2080 }
2053 2081
2054 ++ind; 2082 ++ind;
diff --git a/drivers/infiniband/hw/mthca/mthca_srq.c b/drivers/infiniband/hw/mthca/mthca_srq.c
index fab417c5cf43..b60a9d79ae54 100644
--- a/drivers/infiniband/hw/mthca/mthca_srq.c
+++ b/drivers/infiniband/hw/mthca/mthca_srq.c
@@ -370,7 +370,8 @@ int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
370 return -EINVAL; 370 return -EINVAL;
371 371
372 if (attr_mask & IB_SRQ_LIMIT) { 372 if (attr_mask & IB_SRQ_LIMIT) {
373 if (attr->srq_limit > srq->max) 373 u32 max_wr = mthca_is_memfree(dev) ? srq->max - 1 : srq->max;
374 if (attr->srq_limit > max_wr)
374 return -EINVAL; 375 return -EINVAL;
375 376
376 mutex_lock(&srq->mutex); 377 mutex_lock(&srq->mutex);
diff --git a/drivers/infiniband/ulp/ipoib/Kconfig b/drivers/infiniband/ulp/ipoib/Kconfig
index 13d6d01c72c0..d74653d7de1c 100644
--- a/drivers/infiniband/ulp/ipoib/Kconfig
+++ b/drivers/infiniband/ulp/ipoib/Kconfig
@@ -6,8 +6,7 @@ config INFINIBAND_IPOIB
6 transports IP packets over InfiniBand so you can use your IB 6 transports IP packets over InfiniBand so you can use your IB
7 device as a fancy NIC. 7 device as a fancy NIC.
8 8
9 The IPoIB protocol is defined by the IETF ipoib working 9 See Documentation/infiniband/ipoib.txt for more information
10 group: <http://www.ietf.org/html.charters/ipoib-charter.html>.
11 10
12config INFINIBAND_IPOIB_DEBUG 11config INFINIBAND_IPOIB_DEBUG
13 bool "IP-over-InfiniBand debugging" if EMBEDDED 12 bool "IP-over-InfiniBand debugging" if EMBEDDED
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index 3f89f5e19036..474aa214ab57 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -212,6 +212,7 @@ struct ipoib_path {
212 212
213struct ipoib_neigh { 213struct ipoib_neigh {
214 struct ipoib_ah *ah; 214 struct ipoib_ah *ah;
215 union ib_gid dgid;
215 struct sk_buff_head queue; 216 struct sk_buff_head queue;
216 217
217 struct neighbour *neighbour; 218 struct neighbour *neighbour;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 1c6ea1c682a5..cf71d2a5515c 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -404,6 +404,8 @@ static void path_rec_completion(int status,
404 list_for_each_entry(neigh, &path->neigh_list, list) { 404 list_for_each_entry(neigh, &path->neigh_list, list) {
405 kref_get(&path->ah->ref); 405 kref_get(&path->ah->ref);
406 neigh->ah = path->ah; 406 neigh->ah = path->ah;
407 memcpy(&neigh->dgid.raw, &path->pathrec.dgid.raw,
408 sizeof(union ib_gid));
407 409
408 while ((skb = __skb_dequeue(&neigh->queue))) 410 while ((skb = __skb_dequeue(&neigh->queue)))
409 __skb_queue_tail(&skqueue, skb); 411 __skb_queue_tail(&skqueue, skb);
@@ -510,6 +512,8 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
510 if (path->ah) { 512 if (path->ah) {
511 kref_get(&path->ah->ref); 513 kref_get(&path->ah->ref);
512 neigh->ah = path->ah; 514 neigh->ah = path->ah;
515 memcpy(&neigh->dgid.raw, &path->pathrec.dgid.raw,
516 sizeof(union ib_gid));
513 517
514 ipoib_send(dev, skb, path->ah, 518 ipoib_send(dev, skb, path->ah,
515 be32_to_cpup((__be32 *) skb->dst->neighbour->ha)); 519 be32_to_cpup((__be32 *) skb->dst->neighbour->ha));
@@ -633,6 +637,25 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
633 neigh = *to_ipoib_neigh(skb->dst->neighbour); 637 neigh = *to_ipoib_neigh(skb->dst->neighbour);
634 638
635 if (likely(neigh->ah)) { 639 if (likely(neigh->ah)) {
640 if (unlikely(memcmp(&neigh->dgid.raw,
641 skb->dst->neighbour->ha + 4,
642 sizeof(union ib_gid)))) {
643 spin_lock(&priv->lock);
644 /*
645 * It's safe to call ipoib_put_ah() inside
646 * priv->lock here, because we know that
647 * path->ah will always hold one more reference,
648 * so ipoib_put_ah() will never do more than
649 * decrement the ref count.
650 */
651 ipoib_put_ah(neigh->ah);
652 list_del(&neigh->list);
653 ipoib_neigh_free(neigh);
654 spin_unlock(&priv->lock);
655 ipoib_path_lookup(skb, dev);
656 goto out;
657 }
658
636 ipoib_send(dev, skb, neigh->ah, 659 ipoib_send(dev, skb, neigh->ah,
637 be32_to_cpup((__be32 *) skb->dst->neighbour->ha)); 660 be32_to_cpup((__be32 *) skb->dst->neighbour->ha));
638 goto out; 661 goto out;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index ab40488182b3..ec356ce7cdcd 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -264,6 +264,10 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
264 if (!ah) { 264 if (!ah) {
265 ipoib_warn(priv, "ib_address_create failed\n"); 265 ipoib_warn(priv, "ib_address_create failed\n");
266 } else { 266 } else {
267 spin_lock_irq(&priv->lock);
268 mcast->ah = ah;
269 spin_unlock_irq(&priv->lock);
270
267 ipoib_dbg_mcast(priv, "MGID " IPOIB_GID_FMT 271 ipoib_dbg_mcast(priv, "MGID " IPOIB_GID_FMT
268 " AV %p, LID 0x%04x, SL %d\n", 272 " AV %p, LID 0x%04x, SL %d\n",
269 IPOIB_GID_ARG(mcast->mcmember.mgid), 273 IPOIB_GID_ARG(mcast->mcmember.mgid),
@@ -271,10 +275,6 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
271 be16_to_cpu(mcast->mcmember.mlid), 275 be16_to_cpu(mcast->mcmember.mlid),
272 mcast->mcmember.sl); 276 mcast->mcmember.sl);
273 } 277 }
274
275 spin_lock_irq(&priv->lock);
276 mcast->ah = ah;
277 spin_unlock_irq(&priv->lock);
278 } 278 }
279 279
280 /* actually send any queued packets */ 280 /* actually send any queued packets */
@@ -326,6 +326,7 @@ ipoib_mcast_sendonly_join_complete(int status,
326 326
327 /* Clear the busy flag so we try again */ 327 /* Clear the busy flag so we try again */
328 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); 328 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
329 mcast->query = NULL;
329 } 330 }
330 331
331 complete(&mcast->done); 332 complete(&mcast->done);
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c
index b2c033edb03c..1437d7ee3b19 100644
--- a/drivers/infiniband/ulp/iser/iscsi_iser.c
+++ b/drivers/infiniband/ulp/iser/iscsi_iser.c
@@ -378,21 +378,6 @@ iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn)
378 return iser_conn_set_full_featured_mode(conn); 378 return iser_conn_set_full_featured_mode(conn);
379} 379}
380 380
381static void
382iscsi_iser_conn_terminate(struct iscsi_conn *conn)
383{
384 struct iscsi_iser_conn *iser_conn = conn->dd_data;
385 struct iser_conn *ib_conn = iser_conn->ib_conn;
386
387 BUG_ON(!ib_conn);
388 /* starts conn teardown process, waits until all previously *
389 * posted buffers get flushed, deallocates all conn resources */
390 iser_conn_terminate(ib_conn);
391 iser_conn->ib_conn = NULL;
392 conn->recv_lock = NULL;
393}
394
395
396static struct iscsi_transport iscsi_iser_transport; 381static struct iscsi_transport iscsi_iser_transport;
397 382
398static struct iscsi_cls_session * 383static struct iscsi_cls_session *
@@ -437,159 +422,50 @@ iscsi_iser_session_create(struct iscsi_transport *iscsit,
437} 422}
438 423
439static int 424static int
440iscsi_iser_conn_set_param(struct iscsi_cls_conn *cls_conn, 425iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn,
441 enum iscsi_param param, uint32_t value) 426 enum iscsi_param param, char *buf, int buflen)
442{ 427{
443 struct iscsi_conn *conn = cls_conn->dd_data; 428 int value;
444 struct iscsi_session *session = conn->session;
445
446 spin_lock_bh(&session->lock);
447 if (conn->c_stage != ISCSI_CONN_INITIAL_STAGE &&
448 conn->stop_stage != STOP_CONN_RECOVER) {
449 printk(KERN_ERR "iscsi_iser: can not change parameter [%d]\n",
450 param);
451 spin_unlock_bh(&session->lock);
452 return 0;
453 }
454 spin_unlock_bh(&session->lock);
455 429
456 switch (param) { 430 switch (param) {
457 case ISCSI_PARAM_MAX_RECV_DLENGTH: 431 case ISCSI_PARAM_MAX_RECV_DLENGTH:
458 /* TBD */ 432 /* TBD */
459 break; 433 break;
460 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
461 conn->max_xmit_dlength = value;
462 break;
463 case ISCSI_PARAM_HDRDGST_EN: 434 case ISCSI_PARAM_HDRDGST_EN:
435 sscanf(buf, "%d", &value);
464 if (value) { 436 if (value) {
465 printk(KERN_ERR "DataDigest wasn't negotiated to None"); 437 printk(KERN_ERR "DataDigest wasn't negotiated to None");
466 return -EPROTO; 438 return -EPROTO;
467 } 439 }
468 break; 440 break;
469 case ISCSI_PARAM_DATADGST_EN: 441 case ISCSI_PARAM_DATADGST_EN:
442 sscanf(buf, "%d", &value);
470 if (value) { 443 if (value) {
471 printk(KERN_ERR "DataDigest wasn't negotiated to None"); 444 printk(KERN_ERR "DataDigest wasn't negotiated to None");
472 return -EPROTO; 445 return -EPROTO;
473 } 446 }
474 break; 447 break;
475 case ISCSI_PARAM_INITIAL_R2T_EN:
476 session->initial_r2t_en = value;
477 break;
478 case ISCSI_PARAM_IMM_DATA_EN:
479 session->imm_data_en = value;
480 break;
481 case ISCSI_PARAM_FIRST_BURST:
482 session->first_burst = value;
483 break;
484 case ISCSI_PARAM_MAX_BURST:
485 session->max_burst = value;
486 break;
487 case ISCSI_PARAM_PDU_INORDER_EN:
488 session->pdu_inorder_en = value;
489 break;
490 case ISCSI_PARAM_DATASEQ_INORDER_EN:
491 session->dataseq_inorder_en = value;
492 break;
493 case ISCSI_PARAM_ERL:
494 session->erl = value;
495 break;
496 case ISCSI_PARAM_IFMARKER_EN: 448 case ISCSI_PARAM_IFMARKER_EN:
449 sscanf(buf, "%d", &value);
497 if (value) { 450 if (value) {
498 printk(KERN_ERR "IFMarker wasn't negotiated to No"); 451 printk(KERN_ERR "IFMarker wasn't negotiated to No");
499 return -EPROTO; 452 return -EPROTO;
500 } 453 }
501 break; 454 break;
502 case ISCSI_PARAM_OFMARKER_EN: 455 case ISCSI_PARAM_OFMARKER_EN:
456 sscanf(buf, "%d", &value);
503 if (value) { 457 if (value) {
504 printk(KERN_ERR "OFMarker wasn't negotiated to No"); 458 printk(KERN_ERR "OFMarker wasn't negotiated to No");
505 return -EPROTO; 459 return -EPROTO;
506 } 460 }
507 break; 461 break;
508 default: 462 default:
509 break; 463 return iscsi_set_param(cls_conn, param, buf, buflen);
510 } 464 }
511 465
512 return 0; 466 return 0;
513} 467}
514 468
515static int
516iscsi_iser_session_get_param(struct iscsi_cls_session *cls_session,
517 enum iscsi_param param, uint32_t *value)
518{
519 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
520 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
521
522 switch (param) {
523 case ISCSI_PARAM_INITIAL_R2T_EN:
524 *value = session->initial_r2t_en;
525 break;
526 case ISCSI_PARAM_MAX_R2T:
527 *value = session->max_r2t;
528 break;
529 case ISCSI_PARAM_IMM_DATA_EN:
530 *value = session->imm_data_en;
531 break;
532 case ISCSI_PARAM_FIRST_BURST:
533 *value = session->first_burst;
534 break;
535 case ISCSI_PARAM_MAX_BURST:
536 *value = session->max_burst;
537 break;
538 case ISCSI_PARAM_PDU_INORDER_EN:
539 *value = session->pdu_inorder_en;
540 break;
541 case ISCSI_PARAM_DATASEQ_INORDER_EN:
542 *value = session->dataseq_inorder_en;
543 break;
544 case ISCSI_PARAM_ERL:
545 *value = session->erl;
546 break;
547 case ISCSI_PARAM_IFMARKER_EN:
548 *value = 0;
549 break;
550 case ISCSI_PARAM_OFMARKER_EN:
551 *value = 0;
552 break;
553 default:
554 return ISCSI_ERR_PARAM_NOT_FOUND;
555 }
556
557 return 0;
558}
559
560static int
561iscsi_iser_conn_get_param(struct iscsi_cls_conn *cls_conn,
562 enum iscsi_param param, uint32_t *value)
563{
564 struct iscsi_conn *conn = cls_conn->dd_data;
565
566 switch(param) {
567 case ISCSI_PARAM_MAX_RECV_DLENGTH:
568 *value = conn->max_recv_dlength;
569 break;
570 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
571 *value = conn->max_xmit_dlength;
572 break;
573 case ISCSI_PARAM_HDRDGST_EN:
574 *value = 0;
575 break;
576 case ISCSI_PARAM_DATADGST_EN:
577 *value = 0;
578 break;
579 /*case ISCSI_PARAM_TARGET_RECV_DLENGTH:
580 *value = conn->target_recv_dlength;
581 break;
582 case ISCSI_PARAM_INITIATOR_RECV_DLENGTH:
583 *value = conn->initiator_recv_dlength;
584 break;*/
585 default:
586 return ISCSI_ERR_PARAM_NOT_FOUND;
587 }
588
589 return 0;
590}
591
592
593static void 469static void
594iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats) 470iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
595{ 471{
@@ -664,13 +540,13 @@ iscsi_iser_ep_poll(__u64 ep_handle, int timeout_ms)
664static void 540static void
665iscsi_iser_ep_disconnect(__u64 ep_handle) 541iscsi_iser_ep_disconnect(__u64 ep_handle)
666{ 542{
667 struct iser_conn *ib_conn = iscsi_iser_ib_conn_lookup(ep_handle); 543 struct iser_conn *ib_conn;
668 544
545 ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
669 if (!ib_conn) 546 if (!ib_conn)
670 return; 547 return;
671 548
672 iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state); 549 iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state);
673
674 iser_conn_terminate(ib_conn); 550 iser_conn_terminate(ib_conn);
675} 551}
676 552
@@ -701,7 +577,12 @@ static struct iscsi_transport iscsi_iser_transport = {
701 ISCSI_FIRST_BURST | 577 ISCSI_FIRST_BURST |
702 ISCSI_MAX_BURST | 578 ISCSI_MAX_BURST |
703 ISCSI_PDU_INORDER_EN | 579 ISCSI_PDU_INORDER_EN |
704 ISCSI_DATASEQ_INORDER_EN, 580 ISCSI_DATASEQ_INORDER_EN |
581 ISCSI_EXP_STATSN |
582 ISCSI_PERSISTENT_PORT |
583 ISCSI_PERSISTENT_ADDRESS |
584 ISCSI_TARGET_NAME |
585 ISCSI_TPGT,
705 .host_template = &iscsi_iser_sht, 586 .host_template = &iscsi_iser_sht,
706 .conndata_size = sizeof(struct iscsi_conn), 587 .conndata_size = sizeof(struct iscsi_conn),
707 .max_lun = ISCSI_ISER_MAX_LUN, 588 .max_lun = ISCSI_ISER_MAX_LUN,
@@ -713,14 +594,11 @@ static struct iscsi_transport iscsi_iser_transport = {
713 .create_conn = iscsi_iser_conn_create, 594 .create_conn = iscsi_iser_conn_create,
714 .bind_conn = iscsi_iser_conn_bind, 595 .bind_conn = iscsi_iser_conn_bind,
715 .destroy_conn = iscsi_iser_conn_destroy, 596 .destroy_conn = iscsi_iser_conn_destroy,
716 .set_param = iscsi_iser_conn_set_param, 597 .set_param = iscsi_iser_set_param,
717 .get_conn_param = iscsi_iser_conn_get_param, 598 .get_conn_param = iscsi_conn_get_param,
718 .get_session_param = iscsi_iser_session_get_param, 599 .get_session_param = iscsi_session_get_param,
719 .start_conn = iscsi_iser_conn_start, 600 .start_conn = iscsi_iser_conn_start,
720 .stop_conn = iscsi_conn_stop, 601 .stop_conn = iscsi_conn_stop,
721 /* these are called as part of conn recovery */
722 .suspend_conn_recv = NULL, /* FIXME is/how this relvant to iser? */
723 .terminate_conn = iscsi_iser_conn_terminate,
724 /* IO */ 602 /* IO */
725 .send_pdu = iscsi_conn_send_pdu, 603 .send_pdu = iscsi_conn_send_pdu,
726 .get_stats = iscsi_iser_conn_get_stats, 604 .get_stats = iscsi_iser_conn_get_stats,
diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c
index ff117bbf81b4..72febf1f8ff8 100644
--- a/drivers/infiniband/ulp/iser/iser_verbs.c
+++ b/drivers/infiniband/ulp/iser/iser_verbs.c
@@ -594,7 +594,7 @@ int iser_reg_page_vec(struct iser_conn *ib_conn,
594 mem = ib_fmr_pool_map_phys(ib_conn->fmr_pool, 594 mem = ib_fmr_pool_map_phys(ib_conn->fmr_pool,
595 page_list, 595 page_list,
596 page_vec->length, 596 page_vec->length,
597 &io_addr); 597 io_addr);
598 598
599 if (IS_ERR(mem)) { 599 if (IS_ERR(mem)) {
600 status = (int)PTR_ERR(mem); 600 status = (int)PTR_ERR(mem);
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 4e22afef7206..fd8344cdc0db 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -77,6 +77,14 @@ MODULE_PARM_DESC(topspin_workarounds,
77 77
78static const u8 topspin_oui[3] = { 0x00, 0x05, 0xad }; 78static const u8 topspin_oui[3] = { 0x00, 0x05, 0xad };
79 79
80static int mellanox_workarounds = 1;
81
82module_param(mellanox_workarounds, int, 0444);
83MODULE_PARM_DESC(mellanox_workarounds,
84 "Enable workarounds for Mellanox SRP target bugs if != 0");
85
86static const u8 mellanox_oui[3] = { 0x00, 0x02, 0xc9 };
87
80static void srp_add_one(struct ib_device *device); 88static void srp_add_one(struct ib_device *device);
81static void srp_remove_one(struct ib_device *device); 89static void srp_remove_one(struct ib_device *device);
82static void srp_completion(struct ib_cq *cq, void *target_ptr); 90static void srp_completion(struct ib_cq *cq, void *target_ptr);
@@ -526,8 +534,10 @@ static int srp_reconnect_target(struct srp_target_port *target)
526 while (ib_poll_cq(target->cq, 1, &wc) > 0) 534 while (ib_poll_cq(target->cq, 1, &wc) > 0)
527 ; /* nothing */ 535 ; /* nothing */
528 536
537 spin_lock_irq(target->scsi_host->host_lock);
529 list_for_each_entry_safe(req, tmp, &target->req_queue, list) 538 list_for_each_entry_safe(req, tmp, &target->req_queue, list)
530 srp_reset_req(target, req); 539 srp_reset_req(target, req);
540 spin_unlock_irq(target->scsi_host->host_lock);
531 541
532 target->rx_head = 0; 542 target->rx_head = 0;
533 target->tx_head = 0; 543 target->tx_head = 0;
@@ -567,7 +577,7 @@ err:
567 return ret; 577 return ret;
568} 578}
569 579
570static int srp_map_fmr(struct srp_device *dev, struct scatterlist *scat, 580static int srp_map_fmr(struct srp_target_port *target, struct scatterlist *scat,
571 int sg_cnt, struct srp_request *req, 581 int sg_cnt, struct srp_request *req,
572 struct srp_direct_buf *buf) 582 struct srp_direct_buf *buf)
573{ 583{
@@ -577,10 +587,15 @@ static int srp_map_fmr(struct srp_device *dev, struct scatterlist *scat,
577 int page_cnt; 587 int page_cnt;
578 int i, j; 588 int i, j;
579 int ret; 589 int ret;
590 struct srp_device *dev = target->srp_host->dev;
580 591
581 if (!dev->fmr_pool) 592 if (!dev->fmr_pool)
582 return -ENODEV; 593 return -ENODEV;
583 594
595 if ((sg_dma_address(&scat[0]) & ~dev->fmr_page_mask) &&
596 mellanox_workarounds && !memcmp(&target->ioc_guid, mellanox_oui, 3))
597 return -EINVAL;
598
584 len = page_cnt = 0; 599 len = page_cnt = 0;
585 for (i = 0; i < sg_cnt; ++i) { 600 for (i = 0; i < sg_cnt; ++i) {
586 if (sg_dma_address(&scat[i]) & ~dev->fmr_page_mask) { 601 if (sg_dma_address(&scat[i]) & ~dev->fmr_page_mask) {
@@ -615,9 +630,10 @@ static int srp_map_fmr(struct srp_device *dev, struct scatterlist *scat,
615 (sg_dma_address(&scat[i]) & dev->fmr_page_mask) + j; 630 (sg_dma_address(&scat[i]) & dev->fmr_page_mask) + j;
616 631
617 req->fmr = ib_fmr_pool_map_phys(dev->fmr_pool, 632 req->fmr = ib_fmr_pool_map_phys(dev->fmr_pool,
618 dma_pages, page_cnt, &io_addr); 633 dma_pages, page_cnt, io_addr);
619 if (IS_ERR(req->fmr)) { 634 if (IS_ERR(req->fmr)) {
620 ret = PTR_ERR(req->fmr); 635 ret = PTR_ERR(req->fmr);
636 req->fmr = NULL;
621 goto out; 637 goto out;
622 } 638 }
623 639
@@ -682,7 +698,7 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_target_port *target,
682 buf->va = cpu_to_be64(sg_dma_address(scat)); 698 buf->va = cpu_to_be64(sg_dma_address(scat));
683 buf->key = cpu_to_be32(target->srp_host->dev->mr->rkey); 699 buf->key = cpu_to_be32(target->srp_host->dev->mr->rkey);
684 buf->len = cpu_to_be32(sg_dma_len(scat)); 700 buf->len = cpu_to_be32(sg_dma_len(scat));
685 } else if (srp_map_fmr(target->srp_host->dev, scat, count, req, 701 } else if (srp_map_fmr(target, scat, count, req,
686 (void *) cmd->add_data)) { 702 (void *) cmd->add_data)) {
687 /* 703 /*
688 * FMR mapping failed, and the scatterlist has more 704 * FMR mapping failed, and the scatterlist has more
@@ -783,13 +799,6 @@ static void srp_process_rsp(struct srp_target_port *target, struct srp_rsp *rsp)
783 spin_unlock_irqrestore(target->scsi_host->host_lock, flags); 799 spin_unlock_irqrestore(target->scsi_host->host_lock, flags);
784} 800}
785 801
786static void srp_reconnect_work(void *target_ptr)
787{
788 struct srp_target_port *target = target_ptr;
789
790 srp_reconnect_target(target);
791}
792
793static void srp_handle_recv(struct srp_target_port *target, struct ib_wc *wc) 802static void srp_handle_recv(struct srp_target_port *target, struct ib_wc *wc)
794{ 803{
795 struct srp_iu *iu; 804 struct srp_iu *iu;
@@ -842,7 +851,6 @@ static void srp_completion(struct ib_cq *cq, void *target_ptr)
842{ 851{
843 struct srp_target_port *target = target_ptr; 852 struct srp_target_port *target = target_ptr;
844 struct ib_wc wc; 853 struct ib_wc wc;
845 unsigned long flags;
846 854
847 ib_req_notify_cq(cq, IB_CQ_NEXT_COMP); 855 ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);
848 while (ib_poll_cq(cq, 1, &wc) > 0) { 856 while (ib_poll_cq(cq, 1, &wc) > 0) {
@@ -850,10 +858,6 @@ static void srp_completion(struct ib_cq *cq, void *target_ptr)
850 printk(KERN_ERR PFX "failed %s status %d\n", 858 printk(KERN_ERR PFX "failed %s status %d\n",
851 wc.wr_id & SRP_OP_RECV ? "receive" : "send", 859 wc.wr_id & SRP_OP_RECV ? "receive" : "send",
852 wc.status); 860 wc.status);
853 spin_lock_irqsave(target->scsi_host->host_lock, flags);
854 if (target->state == SRP_TARGET_LIVE)
855 schedule_work(&target->work);
856 spin_unlock_irqrestore(target->scsi_host->host_lock, flags);
857 break; 861 break;
858 } 862 }
859 863
@@ -1689,8 +1693,6 @@ static ssize_t srp_create_target(struct class_device *class_dev,
1689 target->scsi_host = target_host; 1693 target->scsi_host = target_host;
1690 target->srp_host = host; 1694 target->srp_host = host;
1691 1695
1692 INIT_WORK(&target->work, srp_reconnect_work, target);
1693
1694 INIT_LIST_HEAD(&target->free_reqs); 1696 INIT_LIST_HEAD(&target->free_reqs);
1695 INIT_LIST_HEAD(&target->req_queue); 1697 INIT_LIST_HEAD(&target->req_queue);
1696 for (i = 0; i < SRP_SQ_SIZE; ++i) { 1698 for (i = 0; i < SRP_SQ_SIZE; ++i) {
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index a29d5ceb00cf..4bf48188cc91 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -127,14 +127,10 @@ static int evdev_open(struct inode * inode, struct file * file)
127{ 127{
128 struct evdev_list *list; 128 struct evdev_list *list;
129 int i = iminor(inode) - EVDEV_MINOR_BASE; 129 int i = iminor(inode) - EVDEV_MINOR_BASE;
130 int accept_err;
131 130
132 if (i >= EVDEV_MINORS || !evdev_table[i] || !evdev_table[i]->exist) 131 if (i >= EVDEV_MINORS || !evdev_table[i] || !evdev_table[i]->exist)
133 return -ENODEV; 132 return -ENODEV;
134 133
135 if ((accept_err = input_accept_process(&(evdev_table[i]->handle), file)))
136 return accept_err;
137
138 if (!(list = kzalloc(sizeof(struct evdev_list), GFP_KERNEL))) 134 if (!(list = kzalloc(sizeof(struct evdev_list), GFP_KERNEL)))
139 return -ENOMEM; 135 return -ENOMEM;
140 136
@@ -260,7 +256,7 @@ static ssize_t evdev_write(struct file * file, const char __user * buffer, size_
260 256
261 if (evdev_event_from_user(buffer + retval, &event)) 257 if (evdev_event_from_user(buffer + retval, &event))
262 return -EFAULT; 258 return -EFAULT;
263 input_event(list->evdev->handle.dev, event.type, event.code, event.value); 259 input_inject_event(&list->evdev->handle, event.type, event.code, event.value);
264 retval += evdev_event_size(); 260 retval += evdev_event_size();
265 } 261 }
266 262
@@ -428,8 +424,8 @@ static long evdev_ioctl_handler(struct file *file, unsigned int cmd,
428 if (get_user(v, ip + 1)) 424 if (get_user(v, ip + 1))
429 return -EFAULT; 425 return -EFAULT;
430 426
431 input_event(dev, EV_REP, REP_DELAY, u); 427 input_inject_event(&evdev->handle, EV_REP, REP_DELAY, u);
432 input_event(dev, EV_REP, REP_PERIOD, v); 428 input_inject_event(&evdev->handle, EV_REP, REP_PERIOD, v);
433 429
434 return 0; 430 return 0;
435 431
diff --git a/drivers/input/gameport/fm801-gp.c b/drivers/input/gameport/fm801-gp.c
index 47e93daa0fa7..90de5afe03c2 100644
--- a/drivers/input/gameport/fm801-gp.c
+++ b/drivers/input/gameport/fm801-gp.c
@@ -106,10 +106,10 @@ static int __devinit fm801_gp_probe(struct pci_dev *pci, const struct pci_device
106 gp->gameport = port; 106 gp->gameport = port;
107 gp->res_port = request_region(port->io, 0x10, "FM801 GP"); 107 gp->res_port = request_region(port->io, 0x10, "FM801 GP");
108 if (!gp->res_port) { 108 if (!gp->res_port) {
109 kfree(gp);
110 gameport_free_port(port);
111 printk(KERN_DEBUG "fm801-gp: unable to grab region 0x%x-0x%x\n", 109 printk(KERN_DEBUG "fm801-gp: unable to grab region 0x%x-0x%x\n",
112 port->io, port->io + 0x0f); 110 port->io, port->io + 0x0f);
111 gameport_free_port(port);
112 kfree(gp);
113 return -EBUSY; 113 return -EBUSY;
114 } 114 }
115 115
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
index 36644bff379d..3f47ae55c6f3 100644
--- a/drivers/input/gameport/gameport.c
+++ b/drivers/input/gameport/gameport.c
@@ -53,6 +53,7 @@ static LIST_HEAD(gameport_list);
53 53
54static struct bus_type gameport_bus; 54static struct bus_type gameport_bus;
55 55
56static void gameport_add_driver(struct gameport_driver *drv);
56static void gameport_add_port(struct gameport *gameport); 57static void gameport_add_port(struct gameport *gameport);
57static void gameport_destroy_port(struct gameport *gameport); 58static void gameport_destroy_port(struct gameport *gameport);
58static void gameport_reconnect_port(struct gameport *gameport); 59static void gameport_reconnect_port(struct gameport *gameport);
@@ -211,8 +212,14 @@ static void gameport_release_driver(struct gameport *gameport)
211 212
212static void gameport_find_driver(struct gameport *gameport) 213static void gameport_find_driver(struct gameport *gameport)
213{ 214{
215 int error;
216
214 down_write(&gameport_bus.subsys.rwsem); 217 down_write(&gameport_bus.subsys.rwsem);
215 device_attach(&gameport->dev); 218 error = device_attach(&gameport->dev);
219 if (error < 0)
220 printk(KERN_WARNING
221 "gameport: device_attach() failed for %s (%s), error: %d\n",
222 gameport->phys, gameport->name, error);
216 up_write(&gameport_bus.subsys.rwsem); 223 up_write(&gameport_bus.subsys.rwsem);
217} 224}
218 225
@@ -316,7 +323,6 @@ static void gameport_remove_duplicate_events(struct gameport_event *event)
316 spin_unlock_irqrestore(&gameport_event_lock, flags); 323 spin_unlock_irqrestore(&gameport_event_lock, flags);
317} 324}
318 325
319
320static struct gameport_event *gameport_get_event(void) 326static struct gameport_event *gameport_get_event(void)
321{ 327{
322 struct gameport_event *event; 328 struct gameport_event *event;
@@ -342,7 +348,6 @@ static struct gameport_event *gameport_get_event(void)
342static void gameport_handle_event(void) 348static void gameport_handle_event(void)
343{ 349{
344 struct gameport_event *event; 350 struct gameport_event *event;
345 struct gameport_driver *gameport_drv;
346 351
347 mutex_lock(&gameport_mutex); 352 mutex_lock(&gameport_mutex);
348 353
@@ -369,8 +374,7 @@ static void gameport_handle_event(void)
369 break; 374 break;
370 375
371 case GAMEPORT_REGISTER_DRIVER: 376 case GAMEPORT_REGISTER_DRIVER:
372 gameport_drv = event->object; 377 gameport_add_driver(event->object);
373 driver_register(&gameport_drv->driver);
374 break; 378 break;
375 379
376 default: 380 default:
@@ -532,6 +536,7 @@ static void gameport_init_port(struct gameport *gameport)
532 if (gameport->parent) 536 if (gameport->parent)
533 gameport->dev.parent = &gameport->parent->dev; 537 gameport->dev.parent = &gameport->parent->dev;
534 538
539 INIT_LIST_HEAD(&gameport->node);
535 spin_lock_init(&gameport->timer_lock); 540 spin_lock_init(&gameport->timer_lock);
536 init_timer(&gameport->poll_timer); 541 init_timer(&gameport->poll_timer);
537 gameport->poll_timer.function = gameport_run_poll_handler; 542 gameport->poll_timer.function = gameport_run_poll_handler;
@@ -544,6 +549,8 @@ static void gameport_init_port(struct gameport *gameport)
544 */ 549 */
545static void gameport_add_port(struct gameport *gameport) 550static void gameport_add_port(struct gameport *gameport)
546{ 551{
552 int error;
553
547 if (gameport->parent) 554 if (gameport->parent)
548 gameport->parent->child = gameport; 555 gameport->parent->child = gameport;
549 556
@@ -558,8 +565,13 @@ static void gameport_add_port(struct gameport *gameport)
558 printk(KERN_INFO "gameport: %s is %s, speed %dkHz\n", 565 printk(KERN_INFO "gameport: %s is %s, speed %dkHz\n",
559 gameport->name, gameport->phys, gameport->speed); 566 gameport->name, gameport->phys, gameport->speed);
560 567
561 device_add(&gameport->dev); 568 error = device_add(&gameport->dev);
562 gameport->registered = 1; 569 if (error)
570 printk(KERN_ERR
571 "gameport: device_add() failed for %s (%s), error: %d\n",
572 gameport->phys, gameport->name, error);
573 else
574 gameport->registered = 1;
563} 575}
564 576
565/* 577/*
@@ -583,10 +595,11 @@ static void gameport_destroy_port(struct gameport *gameport)
583 595
584 if (gameport->registered) { 596 if (gameport->registered) {
585 device_del(&gameport->dev); 597 device_del(&gameport->dev);
586 list_del_init(&gameport->node);
587 gameport->registered = 0; 598 gameport->registered = 0;
588 } 599 }
589 600
601 list_del_init(&gameport->node);
602
590 gameport_remove_pending_events(gameport); 603 gameport_remove_pending_events(gameport);
591 put_device(&gameport->dev); 604 put_device(&gameport->dev);
592} 605}
@@ -704,11 +717,22 @@ static int gameport_driver_remove(struct device *dev)
704} 717}
705 718
706static struct bus_type gameport_bus = { 719static struct bus_type gameport_bus = {
707 .name = "gameport", 720 .name = "gameport",
708 .probe = gameport_driver_probe, 721 .probe = gameport_driver_probe,
709 .remove = gameport_driver_remove, 722 .remove = gameport_driver_remove,
710}; 723};
711 724
725static void gameport_add_driver(struct gameport_driver *drv)
726{
727 int error;
728
729 error = driver_register(&drv->driver);
730 if (error)
731 printk(KERN_ERR
732 "gameport: driver_register() failed for %s, error: %d\n",
733 drv->driver.name, error);
734}
735
712void __gameport_register_driver(struct gameport_driver *drv, struct module *owner) 736void __gameport_register_driver(struct gameport_driver *drv, struct module *owner)
713{ 737{
714 drv->driver.bus = &gameport_bus; 738 drv->driver.bus = &gameport_bus;
@@ -778,16 +802,24 @@ void gameport_close(struct gameport *gameport)
778 802
779static int __init gameport_init(void) 803static int __init gameport_init(void)
780{ 804{
781 gameport_task = kthread_run(gameport_thread, NULL, "kgameportd"); 805 int error;
782 if (IS_ERR(gameport_task)) {
783 printk(KERN_ERR "gameport: Failed to start kgameportd\n");
784 return PTR_ERR(gameport_task);
785 }
786 806
787 gameport_bus.dev_attrs = gameport_device_attrs; 807 gameport_bus.dev_attrs = gameport_device_attrs;
788 gameport_bus.drv_attrs = gameport_driver_attrs; 808 gameport_bus.drv_attrs = gameport_driver_attrs;
789 gameport_bus.match = gameport_bus_match; 809 gameport_bus.match = gameport_bus_match;
790 bus_register(&gameport_bus); 810 error = bus_register(&gameport_bus);
811 if (error) {
812 printk(KERN_ERR "gameport: failed to register gameport bus, error: %d\n", error);
813 return error;
814 }
815
816 gameport_task = kthread_run(gameport_thread, NULL, "kgameportd");
817 if (IS_ERR(gameport_task)) {
818 bus_unregister(&gameport_bus);
819 error = PTR_ERR(gameport_task);
820 printk(KERN_ERR "gameport: Failed to start kgameportd, error: %d\n", error);
821 return error;
822 }
791 823
792 return 0; 824 return 0;
793} 825}
diff --git a/drivers/input/input.c b/drivers/input/input.c
index a90486f5e491..9cb4b9a54f01 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -35,6 +35,16 @@ static LIST_HEAD(input_handler_list);
35 35
36static struct input_handler *input_table[8]; 36static struct input_handler *input_table[8];
37 37
38/**
39 * input_event() - report new input event
40 * @handle: device that generated the event
41 * @type: type of the event
42 * @code: event code
43 * @value: value of the event
44 *
45 * This function should be used by drivers implementing various input devices
46 * See also input_inject_event()
47 */
38void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 48void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
39{ 49{
40 struct input_handle *handle; 50 struct input_handle *handle;
@@ -183,6 +193,23 @@ void input_event(struct input_dev *dev, unsigned int type, unsigned int code, in
183} 193}
184EXPORT_SYMBOL(input_event); 194EXPORT_SYMBOL(input_event);
185 195
196/**
197 * input_inject_event() - send input event from input handler
198 * @handle: input handle to send event through
199 * @type: type of the event
200 * @code: event code
201 * @value: value of the event
202 *
203 * Similar to input_event() but will ignore event if device is "grabbed" and handle
204 * injecting event is not the one that owns the device.
205 */
206void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
207{
208 if (!handle->dev->grab || handle->dev->grab == handle)
209 input_event(handle->dev, type, code, value);
210}
211EXPORT_SYMBOL(input_inject_event);
212
186static void input_repeat_key(unsigned long data) 213static void input_repeat_key(unsigned long data)
187{ 214{
188 struct input_dev *dev = (void *) data; 215 struct input_dev *dev = (void *) data;
@@ -197,15 +224,6 @@ static void input_repeat_key(unsigned long data)
197 mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_PERIOD])); 224 mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_PERIOD]));
198} 225}
199 226
200int input_accept_process(struct input_handle *handle, struct file *file)
201{
202 if (handle->dev->accept)
203 return handle->dev->accept(handle->dev, file);
204
205 return 0;
206}
207EXPORT_SYMBOL(input_accept_process);
208
209int input_grab_device(struct input_handle *handle) 227int input_grab_device(struct input_handle *handle)
210{ 228{
211 if (handle->dev->grab) 229 if (handle->dev->grab)
@@ -218,8 +236,15 @@ EXPORT_SYMBOL(input_grab_device);
218 236
219void input_release_device(struct input_handle *handle) 237void input_release_device(struct input_handle *handle)
220{ 238{
221 if (handle->dev->grab == handle) 239 struct input_dev *dev = handle->dev;
222 handle->dev->grab = NULL; 240
241 if (dev->grab == handle) {
242 dev->grab = NULL;
243
244 list_for_each_entry(handle, &dev->h_list, d_node)
245 if (handle->handler->start)
246 handle->handler->start(handle);
247 }
223} 248}
224EXPORT_SYMBOL(input_release_device); 249EXPORT_SYMBOL(input_release_device);
225 250
@@ -963,8 +988,11 @@ int input_register_device(struct input_dev *dev)
963 list_for_each_entry(handler, &input_handler_list, node) 988 list_for_each_entry(handler, &input_handler_list, node)
964 if (!handler->blacklist || !input_match_device(handler->blacklist, dev)) 989 if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
965 if ((id = input_match_device(handler->id_table, dev))) 990 if ((id = input_match_device(handler->id_table, dev)))
966 if ((handle = handler->connect(handler, dev, id))) 991 if ((handle = handler->connect(handler, dev, id))) {
967 input_link_handle(handle); 992 input_link_handle(handle);
993 if (handler->start)
994 handler->start(handle);
995 }
968 996
969 input_wakeup_procfs_readers(); 997 input_wakeup_procfs_readers();
970 998
@@ -1028,8 +1056,11 @@ void input_register_handler(struct input_handler *handler)
1028 list_for_each_entry(dev, &input_dev_list, node) 1056 list_for_each_entry(dev, &input_dev_list, node)
1029 if (!handler->blacklist || !input_match_device(handler->blacklist, dev)) 1057 if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
1030 if ((id = input_match_device(handler->id_table, dev))) 1058 if ((id = input_match_device(handler->id_table, dev)))
1031 if ((handle = handler->connect(handler, dev, id))) 1059 if ((handle = handler->connect(handler, dev, id))) {
1032 input_link_handle(handle); 1060 input_link_handle(handle);
1061 if (handler->start)
1062 handler->start(handle);
1063 }
1033 1064
1034 input_wakeup_procfs_readers(); 1065 input_wakeup_procfs_readers();
1035} 1066}
diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c
index 6d99e3c37884..b4914e7231f8 100644
--- a/drivers/input/joystick/iforce/iforce-main.c
+++ b/drivers/input/joystick/iforce/iforce-main.c
@@ -79,6 +79,7 @@ static struct iforce_device iforce_device[] = {
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 { 0x06f8, 0x0004, "Gullemot Jet Leader 3D", btn_joystick, abs_joystick, ff_iforce }, //?
82 { 0x06d6, 0x29bc, "Trust Force Feedback Race Master", btn_wheel, abs_wheel, ff_iforce },
82 { 0x0000, 0x0000, "Unknown I-Force Device [%04x:%04x]", btn_joystick, abs_joystick, ff_iforce } 83 { 0x0000, 0x0000, "Unknown I-Force Device [%04x:%04x]", btn_joystick, abs_joystick, ff_iforce }
83}; 84};
84 85
@@ -222,22 +223,22 @@ static int iforce_erase_effect(struct input_dev *dev, int effect_id)
222 int err = 0; 223 int err = 0;
223 struct iforce_core_effect* core_effect; 224 struct iforce_core_effect* core_effect;
224 225
225 /* Check who is trying to erase this effect */
226 if (iforce->core_effects[effect_id].owner != current->pid) {
227 printk(KERN_WARNING "iforce-main.c: %d tried to erase an effect belonging to %d\n", current->pid, iforce->core_effects[effect_id].owner);
228 return -EACCES;
229 }
230
231 if (effect_id < 0 || effect_id >= FF_EFFECTS_MAX) 226 if (effect_id < 0 || effect_id >= FF_EFFECTS_MAX)
232 return -EINVAL; 227 return -EINVAL;
233 228
234 core_effect = iforce->core_effects + effect_id; 229 core_effect = &iforce->core_effects[effect_id];
230
231 /* Check who is trying to erase this effect */
232 if (core_effect->owner != current->pid) {
233 printk(KERN_WARNING "iforce-main.c: %d tried to erase an effect belonging to %d\n", current->pid, core_effect->owner);
234 return -EACCES;
235 }
235 236
236 if (test_bit(FF_MOD1_IS_USED, core_effect->flags)) 237 if (test_bit(FF_MOD1_IS_USED, core_effect->flags))
237 err = release_resource(&(iforce->core_effects[effect_id].mod1_chunk)); 238 err = release_resource(&core_effect->mod1_chunk);
238 239
239 if (!err && test_bit(FF_MOD2_IS_USED, core_effect->flags)) 240 if (!err && test_bit(FF_MOD2_IS_USED, core_effect->flags))
240 err = release_resource(&(iforce->core_effects[effect_id].mod2_chunk)); 241 err = release_resource(&core_effect->mod2_chunk);
241 242
242 /*TODO: remember to change that if more FF_MOD* bits are added */ 243 /*TODO: remember to change that if more FF_MOD* bits are added */
243 core_effect->flags[0] = 0; 244 core_effect->flags[0] = 0;
diff --git a/drivers/input/joystick/spaceball.c b/drivers/input/joystick/spaceball.c
index 75eb5ca59992..7a19ee052972 100644
--- a/drivers/input/joystick/spaceball.c
+++ b/drivers/input/joystick/spaceball.c
@@ -50,7 +50,7 @@ MODULE_LICENSE("GPL");
50 */ 50 */
51 51
52#define SPACEBALL_MAX_LENGTH 128 52#define SPACEBALL_MAX_LENGTH 128
53#define SPACEBALL_MAX_ID 8 53#define SPACEBALL_MAX_ID 9
54 54
55#define SPACEBALL_1003 1 55#define SPACEBALL_1003 1
56#define SPACEBALL_2003B 3 56#define SPACEBALL_2003B 3
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index ce1f10e8984b..a86afd0a5ef1 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -482,13 +482,7 @@ out:
482 return IRQ_HANDLED; 482 return IRQ_HANDLED;
483} 483}
484 484
485/* 485static int atkbd_set_repeat_rate(struct atkbd *atkbd)
486 * atkbd_event_work() is used to complete processing of events that
487 * can not be processed by input_event() which is often called from
488 * interrupt context.
489 */
490
491static void atkbd_event_work(void *data)
492{ 486{
493 const short period[32] = 487 const short period[32] =
494 { 33, 37, 42, 46, 50, 54, 58, 63, 67, 75, 83, 92, 100, 109, 116, 125, 488 { 33, 37, 42, 46, 50, 54, 58, 63, 67, 75, 83, 92, 100, 109, 116, 125,
@@ -496,41 +490,64 @@ static void atkbd_event_work(void *data)
496 const short delay[4] = 490 const short delay[4] =
497 { 250, 500, 750, 1000 }; 491 { 250, 500, 750, 1000 };
498 492
499 struct atkbd *atkbd = data; 493 struct input_dev *dev = atkbd->dev;
494 unsigned char param;
495 int i = 0, j = 0;
496
497 while (i < ARRAY_SIZE(period) - 1 && period[i] < dev->rep[REP_PERIOD])
498 i++;
499 dev->rep[REP_PERIOD] = period[i];
500
501 while (j < ARRAY_SIZE(delay) - 1 && delay[j] < dev->rep[REP_DELAY])
502 j++;
503 dev->rep[REP_DELAY] = delay[j];
504
505 param = i | (j << 5);
506 return ps2_command(&atkbd->ps2dev, &param, ATKBD_CMD_SETREP);
507}
508
509static int atkbd_set_leds(struct atkbd *atkbd)
510{
500 struct input_dev *dev = atkbd->dev; 511 struct input_dev *dev = atkbd->dev;
501 unsigned char param[2]; 512 unsigned char param[2];
502 int i, j;
503 513
504 mutex_lock(&atkbd->event_mutex); 514 param[0] = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0)
515 | (test_bit(LED_NUML, dev->led) ? 2 : 0)
516 | (test_bit(LED_CAPSL, dev->led) ? 4 : 0);
517 if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS))
518 return -1;
505 519
506 if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask)) { 520 if (atkbd->extra) {
507 param[0] = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0) 521 param[0] = 0;
508 | (test_bit(LED_NUML, dev->led) ? 2 : 0) 522 param[1] = (test_bit(LED_COMPOSE, dev->led) ? 0x01 : 0)
509 | (test_bit(LED_CAPSL, dev->led) ? 4 : 0); 523 | (test_bit(LED_SLEEP, dev->led) ? 0x02 : 0)
510 ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS); 524 | (test_bit(LED_SUSPEND, dev->led) ? 0x04 : 0)
511 525 | (test_bit(LED_MISC, dev->led) ? 0x10 : 0)
512 if (atkbd->extra) { 526 | (test_bit(LED_MUTE, dev->led) ? 0x20 : 0);
513 param[0] = 0; 527 if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_EX_SETLEDS))
514 param[1] = (test_bit(LED_COMPOSE, dev->led) ? 0x01 : 0) 528 return -1;
515 | (test_bit(LED_SLEEP, dev->led) ? 0x02 : 0)
516 | (test_bit(LED_SUSPEND, dev->led) ? 0x04 : 0)
517 | (test_bit(LED_MISC, dev->led) ? 0x10 : 0)
518 | (test_bit(LED_MUTE, dev->led) ? 0x20 : 0);
519 ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_EX_SETLEDS);
520 }
521 } 529 }
522 530
523 if (test_and_clear_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask)) { 531 return 0;
524 i = j = 0; 532}
525 while (i < 31 && period[i] < dev->rep[REP_PERIOD]) 533
526 i++; 534/*
527 while (j < 3 && delay[j] < dev->rep[REP_DELAY]) 535 * atkbd_event_work() is used to complete processing of events that
528 j++; 536 * can not be processed by input_event() which is often called from
529 dev->rep[REP_PERIOD] = period[i]; 537 * interrupt context.
530 dev->rep[REP_DELAY] = delay[j]; 538 */
531 param[0] = i | (j << 5); 539
532 ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETREP); 540static void atkbd_event_work(void *data)
533 } 541{
542 struct atkbd *atkbd = data;
543
544 mutex_lock(&atkbd->event_mutex);
545
546 if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask))
547 atkbd_set_leds(atkbd);
548
549 if (test_and_clear_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask))
550 atkbd_set_repeat_rate(atkbd);
534 551
535 mutex_unlock(&atkbd->event_mutex); 552 mutex_unlock(&atkbd->event_mutex);
536} 553}
@@ -975,7 +992,6 @@ static int atkbd_reconnect(struct serio *serio)
975{ 992{
976 struct atkbd *atkbd = serio_get_drvdata(serio); 993 struct atkbd *atkbd = serio_get_drvdata(serio);
977 struct serio_driver *drv = serio->drv; 994 struct serio_driver *drv = serio->drv;
978 unsigned char param[1];
979 995
980 if (!atkbd || !drv) { 996 if (!atkbd || !drv) {
981 printk(KERN_DEBUG "atkbd: reconnect request, but serio is disconnected, ignoring...\n"); 997 printk(KERN_DEBUG "atkbd: reconnect request, but serio is disconnected, ignoring...\n");
@@ -985,10 +1001,6 @@ static int atkbd_reconnect(struct serio *serio)
985 atkbd_disable(atkbd); 1001 atkbd_disable(atkbd);
986 1002
987 if (atkbd->write) { 1003 if (atkbd->write) {
988 param[0] = (test_bit(LED_SCROLLL, atkbd->dev->led) ? 1 : 0)
989 | (test_bit(LED_NUML, atkbd->dev->led) ? 2 : 0)
990 | (test_bit(LED_CAPSL, atkbd->dev->led) ? 4 : 0);
991
992 if (atkbd_probe(atkbd)) 1004 if (atkbd_probe(atkbd))
993 return -1; 1005 return -1;
994 if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra)) 1006 if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra))
@@ -996,8 +1008,13 @@ static int atkbd_reconnect(struct serio *serio)
996 1008
997 atkbd_activate(atkbd); 1009 atkbd_activate(atkbd);
998 1010
999 if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS)) 1011/*
1000 return -1; 1012 * Restore repeat rate and LEDs (that were reset by atkbd_activate)
1013 * to pre-resume state
1014 */
1015 if (!atkbd->softrepeat)
1016 atkbd_set_repeat_rate(atkbd);
1017 atkbd_set_leds(atkbd);
1001 } 1018 }
1002 1019
1003 atkbd_enable(atkbd); 1020 atkbd_enable(atkbd);
diff --git a/drivers/input/misc/wistron_btns.c b/drivers/input/misc/wistron_btns.c
index ccf0faeee5c1..de0f46dd9692 100644
--- a/drivers/input/misc/wistron_btns.c
+++ b/drivers/input/misc/wistron_btns.c
@@ -94,7 +94,7 @@ static void call_bios(struct regs *regs)
94 94
95static ssize_t __init locate_wistron_bios(void __iomem *base) 95static ssize_t __init locate_wistron_bios(void __iomem *base)
96{ 96{
97 static const unsigned char __initdata signature[] = 97 static unsigned char __initdata signature[] =
98 { 0x42, 0x21, 0x55, 0x30 }; 98 { 0x42, 0x21, 0x55, 0x30 };
99 ssize_t offset; 99 ssize_t offset;
100 100
@@ -343,7 +343,7 @@ static struct key_entry keymap_aopen_1559as[] = {
343 * a list of buttons and their key codes (reported when loading this module 343 * a list of buttons and their key codes (reported when loading this module
344 * with force=1) and the output of dmidecode to $MODULE_AUTHOR. 344 * with force=1) and the output of dmidecode to $MODULE_AUTHOR.
345 */ 345 */
346static struct dmi_system_id dmi_ids[] = { 346static struct dmi_system_id dmi_ids[] __initdata = {
347 { 347 {
348 .callback = dmi_matched, 348 .callback = dmi_matched,
349 .ident = "Fujitsu-Siemens Amilo Pro V2000", 349 .ident = "Fujitsu-Siemens Amilo Pro V2000",
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index 2f0d28840810..54b696cfe1e3 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -238,8 +238,7 @@ static struct ps2pp_info *get_model_info(unsigned char model)
238 { 100, PS2PP_KIND_MX, /* MX510 */ 238 { 100, PS2PP_KIND_MX, /* MX510 */
239 PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN | 239 PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN |
240 PS2PP_EXTRA_BTN | PS2PP_NAV_BTN }, 240 PS2PP_EXTRA_BTN | PS2PP_NAV_BTN },
241 { 111, PS2PP_KIND_MX, /* MX300 */ 241 { 111, PS2PP_KIND_MX, PS2PP_WHEEL | PS2PP_SIDE_BTN }, /* MX300 reports task button as side */
242 PS2PP_WHEEL | PS2PP_EXTRA_BTN | PS2PP_TASK_BTN },
243 { 112, PS2PP_KIND_MX, /* MX500 */ 242 { 112, PS2PP_KIND_MX, /* MX500 */
244 PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN | 243 PS2PP_WHEEL | PS2PP_SIDE_BTN | PS2PP_TASK_BTN |
245 PS2PP_EXTRA_BTN | PS2PP_NAV_BTN }, 244 PS2PP_EXTRA_BTN | PS2PP_NAV_BTN },
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 8bc9f51ae6c2..343afa38f4c2 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -485,13 +485,6 @@ static int im_explorer_detect(struct psmouse *psmouse, int set_properties)
485 param[0] = 40; 485 param[0] = 40;
486 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); 486 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
487 487
488 param[0] = 200;
489 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
490 param[0] = 200;
491 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
492 param[0] = 60;
493 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
494
495 if (set_properties) { 488 if (set_properties) {
496 set_bit(BTN_MIDDLE, psmouse->dev->keybit); 489 set_bit(BTN_MIDDLE, psmouse->dev->keybit);
497 set_bit(REL_WHEEL, psmouse->dev->relbit); 490 set_bit(REL_WHEEL, psmouse->dev->relbit);
diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c
index 6d9ec9ab1b90..ae5871a0e060 100644
--- a/drivers/input/mouse/trackpoint.c
+++ b/drivers/input/mouse/trackpoint.c
@@ -183,21 +183,26 @@ static struct attribute_group trackpoint_attr_group = {
183 .attrs = trackpoint_attrs, 183 .attrs = trackpoint_attrs,
184}; 184};
185 185
186static void trackpoint_disconnect(struct psmouse *psmouse) 186static int trackpoint_start_protocol(struct psmouse *psmouse, unsigned char *firmware_id)
187{ 187{
188 sysfs_remove_group(&psmouse->ps2dev.serio->dev.kobj, &trackpoint_attr_group); 188 unsigned char param[2] = { 0 };
189 189
190 kfree(psmouse->private); 190 if (ps2_command(&psmouse->ps2dev, param, MAKE_PS2_CMD(0, 2, TP_READ_ID)))
191 psmouse->private = NULL; 191 return -1;
192
193 if (param[0] != TP_MAGIC_IDENT)
194 return -1;
195
196 if (firmware_id)
197 *firmware_id = param[1];
198
199 return 0;
192} 200}
193 201
194static int trackpoint_sync(struct psmouse *psmouse) 202static int trackpoint_sync(struct psmouse *psmouse)
195{ 203{
196 unsigned char toggle;
197 struct trackpoint_data *tp = psmouse->private; 204 struct trackpoint_data *tp = psmouse->private;
198 205 unsigned char toggle;
199 if (!tp)
200 return -1;
201 206
202 /* Disable features that may make device unusable with this driver */ 207 /* Disable features that may make device unusable with this driver */
203 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, &toggle); 208 trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, &toggle);
@@ -263,27 +268,38 @@ static void trackpoint_defaults(struct trackpoint_data *tp)
263 tp->ext_dev = TP_DEF_EXT_DEV; 268 tp->ext_dev = TP_DEF_EXT_DEV;
264} 269}
265 270
271static void trackpoint_disconnect(struct psmouse *psmouse)
272{
273 sysfs_remove_group(&psmouse->ps2dev.serio->dev.kobj, &trackpoint_attr_group);
274
275 kfree(psmouse->private);
276 psmouse->private = NULL;
277}
278
279static int trackpoint_reconnect(struct psmouse *psmouse)
280{
281 if (trackpoint_start_protocol(psmouse, NULL))
282 return -1;
283
284 if (trackpoint_sync(psmouse))
285 return -1;
286
287 return 0;
288}
289
266int trackpoint_detect(struct psmouse *psmouse, int set_properties) 290int trackpoint_detect(struct psmouse *psmouse, int set_properties)
267{ 291{
268 struct trackpoint_data *priv; 292 struct trackpoint_data *priv;
269 struct ps2dev *ps2dev = &psmouse->ps2dev; 293 struct ps2dev *ps2dev = &psmouse->ps2dev;
270 unsigned char firmware_id; 294 unsigned char firmware_id;
271 unsigned char button_info; 295 unsigned char button_info;
272 unsigned char param[2];
273
274 param[0] = param[1] = 0;
275 296
276 if (ps2_command(ps2dev, param, MAKE_PS2_CMD(0, 2, TP_READ_ID))) 297 if (trackpoint_start_protocol(psmouse, &firmware_id))
277 return -1;
278
279 if (param[0] != TP_MAGIC_IDENT)
280 return -1; 298 return -1;
281 299
282 if (!set_properties) 300 if (!set_properties)
283 return 0; 301 return 0;
284 302
285 firmware_id = param[1];
286
287 if (trackpoint_read(&psmouse->ps2dev, TP_EXT_BTN, &button_info)) { 303 if (trackpoint_read(&psmouse->ps2dev, TP_EXT_BTN, &button_info)) {
288 printk(KERN_WARNING "trackpoint.c: failed to get extended button data\n"); 304 printk(KERN_WARNING "trackpoint.c: failed to get extended button data\n");
289 button_info = 0; 305 button_info = 0;
@@ -296,7 +312,7 @@ int trackpoint_detect(struct psmouse *psmouse, int set_properties)
296 psmouse->vendor = "IBM"; 312 psmouse->vendor = "IBM";
297 psmouse->name = "TrackPoint"; 313 psmouse->name = "TrackPoint";
298 314
299 psmouse->reconnect = trackpoint_sync; 315 psmouse->reconnect = trackpoint_reconnect;
300 psmouse->disconnect = trackpoint_disconnect; 316 psmouse->disconnect = trackpoint_disconnect;
301 317
302 trackpoint_defaults(priv); 318 trackpoint_defaults(priv);
diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
index 7d9fafea9615..54adba2d8ed5 100644
--- a/drivers/input/serio/i8042-sparcio.h
+++ b/drivers/input/serio/i8042-sparcio.h
@@ -88,7 +88,7 @@ static struct of_device_id sparc_i8042_match[] = {
88 }, 88 },
89 {}, 89 {},
90}; 90};
91MODULE_DEVICE_TABLE(of, i8042_match); 91MODULE_DEVICE_TABLE(of, sparc_i8042_match);
92 92
93static struct of_platform_driver sparc_i8042_driver = { 93static struct of_platform_driver sparc_i8042_driver = {
94 .name = "i8042", 94 .name = "i8042",
diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c
index 79c97f94bcbd..ed202f2f251a 100644
--- a/drivers/input/serio/libps2.c
+++ b/drivers/input/serio/libps2.c
@@ -177,7 +177,12 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
177 return -1; 177 return -1;
178 } 178 }
179 179
180 mutex_lock(&ps2dev->cmd_mutex); 180 if (send && !param) {
181 WARN_ON(1);
182 return -1;
183 }
184
185 mutex_lock_nested(&ps2dev->cmd_mutex, SINGLE_DEPTH_NESTING);
181 186
182 serio_pause_rx(ps2dev->serio); 187 serio_pause_rx(ps2dev->serio);
183 ps2dev->flags = command == PS2_CMD_GETID ? PS2_FLAG_WAITID : 0; 188 ps2dev->flags = command == PS2_CMD_GETID ? PS2_FLAG_WAITID : 0;
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index 6521034bc933..3e76ad71c9a0 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -62,6 +62,7 @@ static LIST_HEAD(serio_list);
62 62
63static struct bus_type serio_bus; 63static struct bus_type serio_bus;
64 64
65static void serio_add_driver(struct serio_driver *drv);
65static void serio_add_port(struct serio *serio); 66static void serio_add_port(struct serio *serio);
66static void serio_destroy_port(struct serio *serio); 67static void serio_destroy_port(struct serio *serio);
67static void serio_reconnect_port(struct serio *serio); 68static void serio_reconnect_port(struct serio *serio);
@@ -140,8 +141,14 @@ static void serio_release_driver(struct serio *serio)
140 141
141static void serio_find_driver(struct serio *serio) 142static void serio_find_driver(struct serio *serio)
142{ 143{
144 int error;
145
143 down_write(&serio_bus.subsys.rwsem); 146 down_write(&serio_bus.subsys.rwsem);
144 device_attach(&serio->dev); 147 error = device_attach(&serio->dev);
148 if (error < 0)
149 printk(KERN_WARNING
150 "serio: device_attach() failed for %s (%s), error: %d\n",
151 serio->phys, serio->name, error);
145 up_write(&serio_bus.subsys.rwsem); 152 up_write(&serio_bus.subsys.rwsem);
146} 153}
147 154
@@ -272,7 +279,6 @@ static struct serio_event *serio_get_event(void)
272static void serio_handle_event(void) 279static void serio_handle_event(void)
273{ 280{
274 struct serio_event *event; 281 struct serio_event *event;
275 struct serio_driver *serio_drv;
276 282
277 mutex_lock(&serio_mutex); 283 mutex_lock(&serio_mutex);
278 284
@@ -304,8 +310,7 @@ static void serio_handle_event(void)
304 break; 310 break;
305 311
306 case SERIO_REGISTER_DRIVER: 312 case SERIO_REGISTER_DRIVER:
307 serio_drv = event->object; 313 serio_add_driver(event->object);
308 driver_register(&serio_drv->driver);
309 break; 314 break;
310 315
311 default: 316 default:
@@ -525,6 +530,7 @@ static void serio_init_port(struct serio *serio)
525 530
526 __module_get(THIS_MODULE); 531 __module_get(THIS_MODULE);
527 532
533 INIT_LIST_HEAD(&serio->node);
528 spin_lock_init(&serio->lock); 534 spin_lock_init(&serio->lock);
529 mutex_init(&serio->drv_mutex); 535 mutex_init(&serio->drv_mutex);
530 device_initialize(&serio->dev); 536 device_initialize(&serio->dev);
@@ -542,6 +548,8 @@ static void serio_init_port(struct serio *serio)
542 */ 548 */
543static void serio_add_port(struct serio *serio) 549static void serio_add_port(struct serio *serio)
544{ 550{
551 int error;
552
545 if (serio->parent) { 553 if (serio->parent) {
546 serio_pause_rx(serio->parent); 554 serio_pause_rx(serio->parent);
547 serio->parent->child = serio; 555 serio->parent->child = serio;
@@ -551,9 +559,19 @@ static void serio_add_port(struct serio *serio)
551 list_add_tail(&serio->node, &serio_list); 559 list_add_tail(&serio->node, &serio_list);
552 if (serio->start) 560 if (serio->start)
553 serio->start(serio); 561 serio->start(serio);
554 device_add(&serio->dev); 562 error = device_add(&serio->dev);
555 sysfs_create_group(&serio->dev.kobj, &serio_id_attr_group); 563 if (error)
556 serio->registered = 1; 564 printk(KERN_ERR
565 "serio: device_add() failed for %s (%s), error: %d\n",
566 serio->phys, serio->name, error);
567 else {
568 serio->registered = 1;
569 error = sysfs_create_group(&serio->dev.kobj, &serio_id_attr_group);
570 if (error)
571 printk(KERN_ERR
572 "serio: sysfs_create_group() failed for %s (%s), error: %d\n",
573 serio->phys, serio->name, error);
574 }
557} 575}
558 576
559/* 577/*
@@ -583,10 +601,10 @@ static void serio_destroy_port(struct serio *serio)
583 if (serio->registered) { 601 if (serio->registered) {
584 sysfs_remove_group(&serio->dev.kobj, &serio_id_attr_group); 602 sysfs_remove_group(&serio->dev.kobj, &serio_id_attr_group);
585 device_del(&serio->dev); 603 device_del(&serio->dev);
586 list_del_init(&serio->node);
587 serio->registered = 0; 604 serio->registered = 0;
588 } 605 }
589 606
607 list_del_init(&serio->node);
590 serio_remove_pending_events(serio); 608 serio_remove_pending_events(serio);
591 put_device(&serio->dev); 609 put_device(&serio->dev);
592} 610}
@@ -756,6 +774,17 @@ static struct bus_type serio_bus = {
756 .remove = serio_driver_remove, 774 .remove = serio_driver_remove,
757}; 775};
758 776
777static void serio_add_driver(struct serio_driver *drv)
778{
779 int error;
780
781 error = driver_register(&drv->driver);
782 if (error)
783 printk(KERN_ERR
784 "serio: driver_register() failed for %s, error: %d\n",
785 drv->driver.name, error);
786}
787
759void __serio_register_driver(struct serio_driver *drv, struct module *owner) 788void __serio_register_driver(struct serio_driver *drv, struct module *owner)
760{ 789{
761 drv->driver.bus = &serio_bus; 790 drv->driver.bus = &serio_bus;
@@ -903,18 +932,26 @@ irqreturn_t serio_interrupt(struct serio *serio,
903 932
904static int __init serio_init(void) 933static int __init serio_init(void)
905{ 934{
906 serio_task = kthread_run(serio_thread, NULL, "kseriod"); 935 int error;
907 if (IS_ERR(serio_task)) {
908 printk(KERN_ERR "serio: Failed to start kseriod\n");
909 return PTR_ERR(serio_task);
910 }
911 936
912 serio_bus.dev_attrs = serio_device_attrs; 937 serio_bus.dev_attrs = serio_device_attrs;
913 serio_bus.drv_attrs = serio_driver_attrs; 938 serio_bus.drv_attrs = serio_driver_attrs;
914 serio_bus.match = serio_bus_match; 939 serio_bus.match = serio_bus_match;
915 serio_bus.uevent = serio_uevent; 940 serio_bus.uevent = serio_uevent;
916 serio_bus.resume = serio_resume; 941 serio_bus.resume = serio_resume;
917 bus_register(&serio_bus); 942 error = bus_register(&serio_bus);
943 if (error) {
944 printk(KERN_ERR "serio: failed to register serio bus, error: %d\n", error);
945 return error;
946 }
947
948 serio_task = kthread_run(serio_thread, NULL, "kseriod");
949 if (IS_ERR(serio_task)) {
950 bus_unregister(&serio_bus);
951 error = PTR_ERR(serio_task);
952 printk(KERN_ERR "serio: Failed to start kseriod, error: %d\n", error);
953 return error;
954 }
918 955
919 return 0; 956 return 0;
920} 957}
diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
index 0a5be7f969f2..af3eb9e795b5 100644
--- a/drivers/isdn/hardware/eicon/divasync.h
+++ b/drivers/isdn/hardware/eicon/divasync.h
@@ -256,7 +256,6 @@ typedef struct
256#define NO_ORDER_CHECK_MASK 0x00000010 256#define NO_ORDER_CHECK_MASK 0x00000010
257#define LOW_CHANNEL_MASK 0x00000020 257#define LOW_CHANNEL_MASK 0x00000020
258#define NO_HSCX30_MASK 0x00000040 258#define NO_HSCX30_MASK 0x00000040
259#define MODE_MASK 0x00000080
260#define SET_BOARD 0x00001000 259#define SET_BOARD 0x00001000
261#define SET_CRC4 0x00030000 260#define SET_CRC4 0x00030000
262#define SET_L1_TRISTATE 0x00040000 261#define SET_L1_TRISTATE 0x00040000
diff --git a/drivers/isdn/hisax/asuscom.c b/drivers/isdn/hisax/asuscom.c
index a98c5e38bbbc..93ff941c48f1 100644
--- a/drivers/isdn/hisax/asuscom.c
+++ b/drivers/isdn/hisax/asuscom.c
@@ -297,7 +297,7 @@ Asus_card_msg(struct IsdnCardState *cs, int mt, void *arg)
297} 297}
298 298
299#ifdef __ISAPNP__ 299#ifdef __ISAPNP__
300static struct isapnp_device_id asus_ids[] __initdata = { 300static struct isapnp_device_id asus_ids[] __devinitdata = {
301 { ISAPNP_VENDOR('A', 'S', 'U'), ISAPNP_FUNCTION(0x1688), 301 { ISAPNP_VENDOR('A', 'S', 'U'), ISAPNP_FUNCTION(0x1688),
302 ISAPNP_VENDOR('A', 'S', 'U'), ISAPNP_FUNCTION(0x1688), 302 ISAPNP_VENDOR('A', 'S', 'U'), ISAPNP_FUNCTION(0x1688),
303 (unsigned long) "Asus1688 PnP" }, 303 (unsigned long) "Asus1688 PnP" },
@@ -313,11 +313,11 @@ static struct isapnp_device_id asus_ids[] __initdata = {
313 { 0, } 313 { 0, }
314}; 314};
315 315
316static struct isapnp_device_id *ipid __initdata = &asus_ids[0]; 316static struct isapnp_device_id *ipid __devinitdata = &asus_ids[0];
317static struct pnp_card *pnp_c __devinitdata = NULL; 317static struct pnp_card *pnp_c __devinitdata = NULL;
318#endif 318#endif
319 319
320int __init 320int __devinit
321setup_asuscom(struct IsdnCard *card) 321setup_asuscom(struct IsdnCard *card)
322{ 322{
323 int bytecnt; 323 int bytecnt;
diff --git a/drivers/isdn/hisax/avm_a1.c b/drivers/isdn/hisax/avm_a1.c
index 9a8b02557ff9..729e906bdc61 100644
--- a/drivers/isdn/hisax/avm_a1.c
+++ b/drivers/isdn/hisax/avm_a1.c
@@ -178,7 +178,7 @@ AVM_card_msg(struct IsdnCardState *cs, int mt, void *arg)
178 return(0); 178 return(0);
179} 179}
180 180
181int __init 181int __devinit
182setup_avm_a1(struct IsdnCard *card) 182setup_avm_a1(struct IsdnCard *card)
183{ 183{
184 u_char val; 184 u_char val;
diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
index 04f5917bf5a1..369afd3a3a4b 100644
--- a/drivers/isdn/hisax/avm_pci.c
+++ b/drivers/isdn/hisax/avm_pci.c
@@ -639,7 +639,7 @@ clear_pending_hdlc_ints(struct IsdnCardState *cs)
639} 639}
640#endif /* 0 */ 640#endif /* 0 */
641 641
642static void __init 642static void
643inithdlc(struct IsdnCardState *cs) 643inithdlc(struct IsdnCardState *cs)
644{ 644{
645 cs->bcs[0].BC_SetStack = setstack_hdlc; 645 cs->bcs[0].BC_SetStack = setstack_hdlc;
@@ -727,13 +727,13 @@ AVM_card_msg(struct IsdnCardState *cs, int mt, void *arg)
727} 727}
728 728
729#ifdef CONFIG_PCI 729#ifdef CONFIG_PCI
730static struct pci_dev *dev_avm __initdata = NULL; 730static struct pci_dev *dev_avm __devinitdata = NULL;
731#endif 731#endif
732#ifdef __ISAPNP__ 732#ifdef __ISAPNP__
733static struct pnp_card *pnp_avm_c __initdata = NULL; 733static struct pnp_card *pnp_avm_c __devinitdata = NULL;
734#endif 734#endif
735 735
736int __init 736int __devinit
737setup_avm_pcipnp(struct IsdnCard *card) 737setup_avm_pcipnp(struct IsdnCard *card)
738{ 738{
739 u_int val, ver; 739 u_int val, ver;
diff --git a/drivers/isdn/hisax/bkm_a4t.c b/drivers/isdn/hisax/bkm_a4t.c
index 3cf1f2421789..87a630128a6c 100644
--- a/drivers/isdn/hisax/bkm_a4t.c
+++ b/drivers/isdn/hisax/bkm_a4t.c
@@ -255,9 +255,9 @@ BKM_card_msg(struct IsdnCardState *cs, int mt, void *arg)
255 return (0); 255 return (0);
256} 256}
257 257
258static struct pci_dev *dev_a4t __initdata = NULL; 258static struct pci_dev *dev_a4t __devinitdata = NULL;
259 259
260int __init 260int __devinit
261setup_bkm_a4t(struct IsdnCard *card) 261setup_bkm_a4t(struct IsdnCard *card)
262{ 262{
263 struct IsdnCardState *cs = card->cs; 263 struct IsdnCardState *cs = card->cs;
diff --git a/drivers/isdn/hisax/bkm_a8.c b/drivers/isdn/hisax/bkm_a8.c
index 15681f3e73b8..dae090a9a489 100644
--- a/drivers/isdn/hisax/bkm_a8.c
+++ b/drivers/isdn/hisax/bkm_a8.c
@@ -260,7 +260,7 @@ BKM_card_msg(struct IsdnCardState *cs, int mt, void *arg)
260 return (0); 260 return (0);
261} 261}
262 262
263static int __init 263static int __devinit
264sct_alloc_io(u_int adr, u_int len) 264sct_alloc_io(u_int adr, u_int len)
265{ 265{
266 if (!request_region(adr, len, "scitel")) { 266 if (!request_region(adr, len, "scitel")) {
@@ -272,16 +272,16 @@ sct_alloc_io(u_int adr, u_int len)
272 return(0); 272 return(0);
273} 273}
274 274
275static struct pci_dev *dev_a8 __initdata = NULL; 275static struct pci_dev *dev_a8 __devinitdata = NULL;
276static u16 sub_vendor_id __initdata = 0; 276static u16 sub_vendor_id __devinitdata = 0;
277static u16 sub_sys_id __initdata = 0; 277static u16 sub_sys_id __devinitdata = 0;
278static u_char pci_bus __initdata = 0; 278static u_char pci_bus __devinitdata = 0;
279static u_char pci_device_fn __initdata = 0; 279static u_char pci_device_fn __devinitdata = 0;
280static u_char pci_irq __initdata = 0; 280static u_char pci_irq __devinitdata = 0;
281 281
282#endif /* CONFIG_PCI */ 282#endif /* CONFIG_PCI */
283 283
284int __init 284int __devinit
285setup_sct_quadro(struct IsdnCard *card) 285setup_sct_quadro(struct IsdnCard *card)
286{ 286{
287#ifdef CONFIG_PCI 287#ifdef CONFIG_PCI
diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
index 5333be5d2c47..e10350360f2f 100644
--- a/drivers/isdn/hisax/config.c
+++ b/drivers/isdn/hisax/config.c
@@ -1875,7 +1875,7 @@ static void EChannel_proc_rcv(struct hisax_d_if *d_if)
1875#ifdef CONFIG_PCI 1875#ifdef CONFIG_PCI
1876#include <linux/pci.h> 1876#include <linux/pci.h>
1877 1877
1878static struct pci_device_id hisax_pci_tbl[] __initdata = { 1878static struct pci_device_id hisax_pci_tbl[] __devinitdata = {
1879#ifdef CONFIG_HISAX_FRITZPCI 1879#ifdef CONFIG_HISAX_FRITZPCI
1880 {PCI_VENDOR_ID_AVM, PCI_DEVICE_ID_AVM_A1, PCI_ANY_ID, PCI_ANY_ID}, 1880 {PCI_VENDOR_ID_AVM, PCI_DEVICE_ID_AVM_A1, PCI_ANY_ID, PCI_ANY_ID},
1881#endif 1881#endif
diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
index 323a02ef3844..e294fa3918f3 100644
--- a/drivers/isdn/hisax/diva.c
+++ b/drivers/isdn/hisax/diva.c
@@ -887,13 +887,13 @@ Diva_card_msg(struct IsdnCardState *cs, int mt, void *arg)
887 return(0); 887 return(0);
888} 888}
889 889
890static struct pci_dev *dev_diva __initdata = NULL; 890static struct pci_dev *dev_diva __devinitdata = NULL;
891static struct pci_dev *dev_diva_u __initdata = NULL; 891static struct pci_dev *dev_diva_u __devinitdata = NULL;
892static struct pci_dev *dev_diva201 __initdata = NULL; 892static struct pci_dev *dev_diva201 __devinitdata = NULL;
893static struct pci_dev *dev_diva202 __initdata = NULL; 893static struct pci_dev *dev_diva202 __devinitdata = NULL;
894 894
895#ifdef __ISAPNP__ 895#ifdef __ISAPNP__
896static struct isapnp_device_id diva_ids[] __initdata = { 896static struct isapnp_device_id diva_ids[] __devinitdata = {
897 { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51), 897 { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51),
898 ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51), 898 ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51),
899 (unsigned long) "Diva picola" }, 899 (unsigned long) "Diva picola" },
@@ -915,12 +915,12 @@ static struct isapnp_device_id diva_ids[] __initdata = {
915 { 0, } 915 { 0, }
916}; 916};
917 917
918static struct isapnp_device_id *ipid __initdata = &diva_ids[0]; 918static struct isapnp_device_id *ipid __devinitdata = &diva_ids[0];
919static struct pnp_card *pnp_c __devinitdata = NULL; 919static struct pnp_card *pnp_c __devinitdata = NULL;
920#endif 920#endif
921 921
922 922
923int __init 923int __devinit
924setup_diva(struct IsdnCard *card) 924setup_diva(struct IsdnCard *card)
925{ 925{
926 int bytecnt = 8; 926 int bytecnt = 8;
diff --git a/drivers/isdn/hisax/enternow_pci.c b/drivers/isdn/hisax/enternow_pci.c
index 8fcbe2e7d765..76c7d29d1b2f 100644
--- a/drivers/isdn/hisax/enternow_pci.c
+++ b/drivers/isdn/hisax/enternow_pci.c
@@ -301,10 +301,10 @@ enpci_interrupt(int intno, void *dev_id, struct pt_regs *regs)
301} 301}
302 302
303 303
304static struct pci_dev *dev_netjet __initdata = NULL; 304static struct pci_dev *dev_netjet __devinitdata = NULL;
305 305
306/* called by config.c */ 306/* called by config.c */
307int __init 307int __devinit
308setup_enternow_pci(struct IsdnCard *card) 308setup_enternow_pci(struct IsdnCard *card)
309{ 309{
310 int bytecnt; 310 int bytecnt;
diff --git a/drivers/isdn/hisax/gazel.c b/drivers/isdn/hisax/gazel.c
index 3e7d92303582..fe2937267777 100644
--- a/drivers/isdn/hisax/gazel.c
+++ b/drivers/isdn/hisax/gazel.c
@@ -484,7 +484,7 @@ reserve_regions(struct IsdnCard *card, struct IsdnCardState *cs)
484 return 1; 484 return 1;
485} 485}
486 486
487static int __init 487static int __devinit
488setup_gazelisa(struct IsdnCard *card, struct IsdnCardState *cs) 488setup_gazelisa(struct IsdnCard *card, struct IsdnCardState *cs)
489{ 489{
490 printk(KERN_INFO "Gazel: ISA PnP card automatic recognition\n"); 490 printk(KERN_INFO "Gazel: ISA PnP card automatic recognition\n");
@@ -532,9 +532,9 @@ setup_gazelisa(struct IsdnCard *card, struct IsdnCardState *cs)
532 return (0); 532 return (0);
533} 533}
534 534
535static struct pci_dev *dev_tel __initdata = NULL; 535static struct pci_dev *dev_tel __devinitdata = NULL;
536 536
537static int __init 537static int __devinit
538setup_gazelpci(struct IsdnCardState *cs) 538setup_gazelpci(struct IsdnCardState *cs)
539{ 539{
540 u_int pci_ioaddr0 = 0, pci_ioaddr1 = 0; 540 u_int pci_ioaddr0 = 0, pci_ioaddr1 = 0;
@@ -621,7 +621,7 @@ setup_gazelpci(struct IsdnCardState *cs)
621 return (0); 621 return (0);
622} 622}
623 623
624int __init 624int __devinit
625setup_gazel(struct IsdnCard *card) 625setup_gazel(struct IsdnCard *card)
626{ 626{
627 struct IsdnCardState *cs = card->cs; 627 struct IsdnCardState *cs = card->cs;
diff --git a/drivers/isdn/hisax/hfc4s8s_l1.c b/drivers/isdn/hisax/hfc4s8s_l1.c
index 0f967b3df79d..3a5ca8a68fc4 100644
--- a/drivers/isdn/hisax/hfc4s8s_l1.c
+++ b/drivers/isdn/hisax/hfc4s8s_l1.c
@@ -1703,7 +1703,7 @@ hfc4s8s_module_init(void)
1703/* driver module exit : */ 1703/* driver module exit : */
1704/* release the HFC-4s/8s hardware */ 1704/* release the HFC-4s/8s hardware */
1705/*************************************/ 1705/*************************************/
1706static void 1706static void __exit
1707hfc4s8s_module_exit(void) 1707hfc4s8s_module_exit(void)
1708{ 1708{
1709 pci_unregister_driver(&hfc4s8s_driver); 1709 pci_unregister_driver(&hfc4s8s_driver);
diff --git a/drivers/isdn/hisax/hfc_2bds0.c b/drivers/isdn/hisax/hfc_2bds0.c
index 637a261c9312..6360e8214720 100644
--- a/drivers/isdn/hisax/hfc_2bds0.c
+++ b/drivers/isdn/hisax/hfc_2bds0.c
@@ -1015,7 +1015,7 @@ hfc_dbusy_timer(struct IsdnCardState *cs)
1015{ 1015{
1016} 1016}
1017 1017
1018static unsigned int __init 1018static unsigned int
1019*init_send_hfcd(int cnt) 1019*init_send_hfcd(int cnt)
1020{ 1020{
1021 int i, *send; 1021 int i, *send;
@@ -1030,7 +1030,7 @@ static unsigned int __init
1030 return(send); 1030 return(send);
1031} 1031}
1032 1032
1033void __init 1033void
1034init2bds0(struct IsdnCardState *cs) 1034init2bds0(struct IsdnCardState *cs)
1035{ 1035{
1036 cs->setstack_d = setstack_hfcd; 1036 cs->setstack_d = setstack_hfcd;
diff --git a/drivers/isdn/hisax/hfc_2bs0.c b/drivers/isdn/hisax/hfc_2bs0.c
index c964539cc43e..d0520ad30677 100644
--- a/drivers/isdn/hisax/hfc_2bs0.c
+++ b/drivers/isdn/hisax/hfc_2bs0.c
@@ -551,7 +551,7 @@ setstack_hfc(struct PStack *st, struct BCState *bcs)
551 return (0); 551 return (0);
552} 552}
553 553
554static void __init 554static void
555init_send(struct BCState *bcs) 555init_send(struct BCState *bcs)
556{ 556{
557 int i; 557 int i;
@@ -565,7 +565,7 @@ init_send(struct BCState *bcs)
565 bcs->hw.hfc.send[i] = 0x1fff; 565 bcs->hw.hfc.send[i] = 0x1fff;
566} 566}
567 567
568void __init 568void
569inithfc(struct IsdnCardState *cs) 569inithfc(struct IsdnCardState *cs)
570{ 570{
571 init_send(&cs->bcs[0]); 571 init_send(&cs->bcs[0]);
diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
index 7241e73879ba..1df60ca9481f 100644
--- a/drivers/isdn/hisax/hfc_pci.c
+++ b/drivers/isdn/hisax/hfc_pci.c
@@ -1581,7 +1581,7 @@ hfcpci_bh(struct IsdnCardState *cs)
1581/********************************/ 1581/********************************/
1582/* called for card init message */ 1582/* called for card init message */
1583/********************************/ 1583/********************************/
1584static void __init 1584static void
1585inithfcpci(struct IsdnCardState *cs) 1585inithfcpci(struct IsdnCardState *cs)
1586{ 1586{
1587 cs->bcs[0].BC_SetStack = setstack_2b; 1587 cs->bcs[0].BC_SetStack = setstack_2b;
@@ -1638,11 +1638,11 @@ hfcpci_card_msg(struct IsdnCardState *cs, int mt, void *arg)
1638 1638
1639 1639
1640/* this variable is used as card index when more than one cards are present */ 1640/* this variable is used as card index when more than one cards are present */
1641static struct pci_dev *dev_hfcpci __initdata = NULL; 1641static struct pci_dev *dev_hfcpci __devinitdata = NULL;
1642 1642
1643#endif /* CONFIG_PCI */ 1643#endif /* CONFIG_PCI */
1644 1644
1645int __init 1645int __devinit
1646setup_hfcpci(struct IsdnCard *card) 1646setup_hfcpci(struct IsdnCard *card)
1647{ 1647{
1648 u_long flags; 1648 u_long flags;
diff --git a/drivers/isdn/hisax/hfcscard.c b/drivers/isdn/hisax/hfcscard.c
index 86ab1c13f6b1..4e7f472877e9 100644
--- a/drivers/isdn/hisax/hfcscard.c
+++ b/drivers/isdn/hisax/hfcscard.c
@@ -139,7 +139,7 @@ hfcs_card_msg(struct IsdnCardState *cs, int mt, void *arg)
139} 139}
140 140
141#ifdef __ISAPNP__ 141#ifdef __ISAPNP__
142static struct isapnp_device_id hfc_ids[] __initdata = { 142static struct isapnp_device_id hfc_ids[] __devinitdata = {
143 { ISAPNP_VENDOR('A', 'N', 'X'), ISAPNP_FUNCTION(0x1114), 143 { ISAPNP_VENDOR('A', 'N', 'X'), ISAPNP_FUNCTION(0x1114),
144 ISAPNP_VENDOR('A', 'N', 'X'), ISAPNP_FUNCTION(0x1114), 144 ISAPNP_VENDOR('A', 'N', 'X'), ISAPNP_FUNCTION(0x1114),
145 (unsigned long) "Acer P10" }, 145 (unsigned long) "Acer P10" },
@@ -164,11 +164,11 @@ static struct isapnp_device_id hfc_ids[] __initdata = {
164 { 0, } 164 { 0, }
165}; 165};
166 166
167static struct isapnp_device_id *ipid __initdata = &hfc_ids[0]; 167static struct isapnp_device_id *ipid __devinitdata = &hfc_ids[0];
168static struct pnp_card *pnp_c __devinitdata = NULL; 168static struct pnp_card *pnp_c __devinitdata = NULL;
169#endif 169#endif
170 170
171int __init 171int __devinit
172setup_hfcs(struct IsdnCard *card) 172setup_hfcs(struct IsdnCard *card)
173{ 173{
174 struct IsdnCardState *cs = card->cs; 174 struct IsdnCardState *cs = card->cs;
diff --git a/drivers/isdn/hisax/icc.c b/drivers/isdn/hisax/icc.c
index c615752b96aa..2cf7b665609e 100644
--- a/drivers/isdn/hisax/icc.c
+++ b/drivers/isdn/hisax/icc.c
@@ -24,10 +24,10 @@
24#define DBUSY_TIMER_VALUE 80 24#define DBUSY_TIMER_VALUE 80
25#define ARCOFI_USE 0 25#define ARCOFI_USE 0
26 26
27static char *ICCVer[] __initdata = 27static char *ICCVer[] =
28{"2070 A1/A3", "2070 B1", "2070 B2/B3", "2070 V2.4"}; 28{"2070 A1/A3", "2070 B1", "2070 B2/B3", "2070 V2.4"};
29 29
30void __init 30void
31ICCVersion(struct IsdnCardState *cs, char *s) 31ICCVersion(struct IsdnCardState *cs, char *s)
32{ 32{
33 int val; 33 int val;
@@ -613,7 +613,7 @@ dbusy_timer_handler(struct IsdnCardState *cs)
613 } 613 }
614} 614}
615 615
616void __init 616void
617initicc(struct IsdnCardState *cs) 617initicc(struct IsdnCardState *cs)
618{ 618{
619 cs->setstack_d = setstack_icc; 619 cs->setstack_d = setstack_icc;
@@ -646,7 +646,7 @@ initicc(struct IsdnCardState *cs)
646 ph_command(cs, ICC_CMD_DI); 646 ph_command(cs, ICC_CMD_DI);
647} 647}
648 648
649void __init 649void
650clear_pending_icc_ints(struct IsdnCardState *cs) 650clear_pending_icc_ints(struct IsdnCardState *cs)
651{ 651{
652 int val, eval; 652 int val, eval;
diff --git a/drivers/isdn/hisax/icc.h b/drivers/isdn/hisax/icc.h
index b3bb3d5de532..e7f593967e43 100644
--- a/drivers/isdn/hisax/icc.h
+++ b/drivers/isdn/hisax/icc.h
@@ -65,7 +65,7 @@
65#define ICC_IND_AIL 0xE 65#define ICC_IND_AIL 0xE
66#define ICC_IND_DC 0xF 66#define ICC_IND_DC 0xF
67 67
68extern void __init ICCVersion(struct IsdnCardState *cs, char *s); 68extern void ICCVersion(struct IsdnCardState *cs, char *s);
69extern void initicc(struct IsdnCardState *cs); 69extern void initicc(struct IsdnCardState *cs);
70extern void icc_interrupt(struct IsdnCardState *cs, u_char val); 70extern void icc_interrupt(struct IsdnCardState *cs, u_char val);
71extern void clear_pending_icc_ints(struct IsdnCardState *cs); 71extern void clear_pending_icc_ints(struct IsdnCardState *cs);
diff --git a/drivers/isdn/hisax/ipacx.c b/drivers/isdn/hisax/ipacx.c
index df5fc92a89b2..00afd5538909 100644
--- a/drivers/isdn/hisax/ipacx.c
+++ b/drivers/isdn/hisax/ipacx.c
@@ -38,8 +38,8 @@ static void dbusy_timer_handler(struct IsdnCardState *cs);
38static void dch_empty_fifo(struct IsdnCardState *cs, int count); 38static void dch_empty_fifo(struct IsdnCardState *cs, int count);
39static void dch_fill_fifo(struct IsdnCardState *cs); 39static void dch_fill_fifo(struct IsdnCardState *cs);
40static inline void dch_int(struct IsdnCardState *cs); 40static inline void dch_int(struct IsdnCardState *cs);
41static void __devinit dch_setstack(struct PStack *st, struct IsdnCardState *cs); 41static void dch_setstack(struct PStack *st, struct IsdnCardState *cs);
42static void __devinit dch_init(struct IsdnCardState *cs); 42static void dch_init(struct IsdnCardState *cs);
43static void bch_l2l1(struct PStack *st, int pr, void *arg); 43static void bch_l2l1(struct PStack *st, int pr, void *arg);
44static void bch_empty_fifo(struct BCState *bcs, int count); 44static void bch_empty_fifo(struct BCState *bcs, int count);
45static void bch_fill_fifo(struct BCState *bcs); 45static void bch_fill_fifo(struct BCState *bcs);
@@ -48,8 +48,8 @@ static void bch_mode(struct BCState *bcs, int mode, int bc);
48static void bch_close_state(struct BCState *bcs); 48static void bch_close_state(struct BCState *bcs);
49static int bch_open_state(struct IsdnCardState *cs, struct BCState *bcs); 49static int bch_open_state(struct IsdnCardState *cs, struct BCState *bcs);
50static int bch_setstack(struct PStack *st, struct BCState *bcs); 50static int bch_setstack(struct PStack *st, struct BCState *bcs);
51static void __devinit bch_init(struct IsdnCardState *cs, int hscx); 51static void bch_init(struct IsdnCardState *cs, int hscx);
52static void __init clear_pending_ints(struct IsdnCardState *cs); 52static void clear_pending_ints(struct IsdnCardState *cs);
53 53
54//---------------------------------------------------------- 54//----------------------------------------------------------
55// Issue Layer 1 command to chip 55// Issue Layer 1 command to chip
@@ -408,7 +408,7 @@ dch_int(struct IsdnCardState *cs)
408 408
409//---------------------------------------------------------- 409//----------------------------------------------------------
410//---------------------------------------------------------- 410//----------------------------------------------------------
411static void __devinit 411static void
412dch_setstack(struct PStack *st, struct IsdnCardState *cs) 412dch_setstack(struct PStack *st, struct IsdnCardState *cs)
413{ 413{
414 st->l1.l1hw = dch_l2l1; 414 st->l1.l1hw = dch_l2l1;
@@ -416,7 +416,7 @@ dch_setstack(struct PStack *st, struct IsdnCardState *cs)
416 416
417//---------------------------------------------------------- 417//----------------------------------------------------------
418//---------------------------------------------------------- 418//----------------------------------------------------------
419static void __devinit 419static void
420dch_init(struct IsdnCardState *cs) 420dch_init(struct IsdnCardState *cs)
421{ 421{
422 printk(KERN_INFO "HiSax: IPACX ISDN driver v0.1.0\n"); 422 printk(KERN_INFO "HiSax: IPACX ISDN driver v0.1.0\n");
@@ -823,7 +823,7 @@ bch_setstack(struct PStack *st, struct BCState *bcs)
823 823
824//---------------------------------------------------------- 824//----------------------------------------------------------
825//---------------------------------------------------------- 825//----------------------------------------------------------
826static void __devinit 826static void
827bch_init(struct IsdnCardState *cs, int hscx) 827bch_init(struct IsdnCardState *cs, int hscx)
828{ 828{
829 cs->bcs[hscx].BC_SetStack = bch_setstack; 829 cs->bcs[hscx].BC_SetStack = bch_setstack;
@@ -861,7 +861,7 @@ interrupt_ipacx(struct IsdnCardState *cs)
861//---------------------------------------------------------- 861//----------------------------------------------------------
862// Clears chip interrupt status 862// Clears chip interrupt status
863//---------------------------------------------------------- 863//----------------------------------------------------------
864static void __init 864static void
865clear_pending_ints(struct IsdnCardState *cs) 865clear_pending_ints(struct IsdnCardState *cs)
866{ 866{
867 int ista; 867 int ista;
@@ -883,7 +883,7 @@ clear_pending_ints(struct IsdnCardState *cs)
883// Does chip configuration work 883// Does chip configuration work
884// Work to do depends on bit mask in part 884// Work to do depends on bit mask in part
885//---------------------------------------------------------- 885//----------------------------------------------------------
886void __init 886void
887init_ipacx(struct IsdnCardState *cs, int part) 887init_ipacx(struct IsdnCardState *cs, int part)
888{ 888{
889 if (part &1) { // initialise chip 889 if (part &1) { // initialise chip
diff --git a/drivers/isdn/hisax/isurf.c b/drivers/isdn/hisax/isurf.c
index 33747afc984d..715a1a8cd694 100644
--- a/drivers/isdn/hisax/isurf.c
+++ b/drivers/isdn/hisax/isurf.c
@@ -196,10 +196,10 @@ isurf_auxcmd(struct IsdnCardState *cs, isdn_ctrl *ic) {
196} 196}
197 197
198#ifdef __ISAPNP__ 198#ifdef __ISAPNP__
199static struct pnp_card *pnp_c __initdata = NULL; 199static struct pnp_card *pnp_c __devinitdata = NULL;
200#endif 200#endif
201 201
202int __init 202int __devinit
203setup_isurf(struct IsdnCard *card) 203setup_isurf(struct IsdnCard *card)
204{ 204{
205 int ver; 205 int ver;
diff --git a/drivers/isdn/hisax/ix1_micro.c b/drivers/isdn/hisax/ix1_micro.c
index 908a7e144421..39717506c678 100644
--- a/drivers/isdn/hisax/ix1_micro.c
+++ b/drivers/isdn/hisax/ix1_micro.c
@@ -210,7 +210,7 @@ ix1_card_msg(struct IsdnCardState *cs, int mt, void *arg)
210} 210}
211 211
212#ifdef __ISAPNP__ 212#ifdef __ISAPNP__
213static struct isapnp_device_id itk_ids[] __initdata = { 213static struct isapnp_device_id itk_ids[] __devinitdata = {
214 { ISAPNP_VENDOR('I', 'T', 'K'), ISAPNP_FUNCTION(0x25), 214 { ISAPNP_VENDOR('I', 'T', 'K'), ISAPNP_FUNCTION(0x25),
215 ISAPNP_VENDOR('I', 'T', 'K'), ISAPNP_FUNCTION(0x25), 215 ISAPNP_VENDOR('I', 'T', 'K'), ISAPNP_FUNCTION(0x25),
216 (unsigned long) "ITK micro 2" }, 216 (unsigned long) "ITK micro 2" },
@@ -220,12 +220,12 @@ static struct isapnp_device_id itk_ids[] __initdata = {
220 { 0, } 220 { 0, }
221}; 221};
222 222
223static struct isapnp_device_id *ipid __initdata = &itk_ids[0]; 223static struct isapnp_device_id *ipid __devinitdata = &itk_ids[0];
224static struct pnp_card *pnp_c __devinitdata = NULL; 224static struct pnp_card *pnp_c __devinitdata = NULL;
225#endif 225#endif
226 226
227 227
228int __init 228int __devinit
229setup_ix1micro(struct IsdnCard *card) 229setup_ix1micro(struct IsdnCard *card)
230{ 230{
231 struct IsdnCardState *cs = card->cs; 231 struct IsdnCardState *cs = card->cs;
diff --git a/drivers/isdn/hisax/jade.c b/drivers/isdn/hisax/jade.c
index 2659fecc2674..43d61d1bc5b6 100644
--- a/drivers/isdn/hisax/jade.c
+++ b/drivers/isdn/hisax/jade.c
@@ -19,7 +19,7 @@
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20 20
21 21
22int __init 22int
23JadeVersion(struct IsdnCardState *cs, char *s) 23JadeVersion(struct IsdnCardState *cs, char *s)
24{ 24{
25 int ver,i; 25 int ver,i;
@@ -253,7 +253,7 @@ setstack_jade(struct PStack *st, struct BCState *bcs)
253 return (0); 253 return (0);
254} 254}
255 255
256void __init 256void
257clear_pending_jade_ints(struct IsdnCardState *cs) 257clear_pending_jade_ints(struct IsdnCardState *cs)
258{ 258{
259 int val; 259 int val;
@@ -279,7 +279,7 @@ clear_pending_jade_ints(struct IsdnCardState *cs)
279 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0xF8); 279 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0xF8);
280} 280}
281 281
282void __init 282void
283initjade(struct IsdnCardState *cs) 283initjade(struct IsdnCardState *cs)
284{ 284{
285 cs->bcs[0].BC_SetStack = setstack_jade; 285 cs->bcs[0].BC_SetStack = setstack_jade;
diff --git a/drivers/isdn/hisax/mic.c b/drivers/isdn/hisax/mic.c
index fe11f226b285..8c82519593a8 100644
--- a/drivers/isdn/hisax/mic.c
+++ b/drivers/isdn/hisax/mic.c
@@ -189,7 +189,7 @@ mic_card_msg(struct IsdnCardState *cs, int mt, void *arg)
189 return(0); 189 return(0);
190} 190}
191 191
192int __init 192int __devinit
193setup_mic(struct IsdnCard *card) 193setup_mic(struct IsdnCard *card)
194{ 194{
195 int bytecnt; 195 int bytecnt;
diff --git a/drivers/isdn/hisax/netjet.c b/drivers/isdn/hisax/netjet.c
index 47a47ef0968b..38f648f9b0ed 100644
--- a/drivers/isdn/hisax/netjet.c
+++ b/drivers/isdn/hisax/netjet.c
@@ -909,7 +909,7 @@ setstack_tiger(struct PStack *st, struct BCState *bcs)
909} 909}
910 910
911 911
912void __init 912void
913inittiger(struct IsdnCardState *cs) 913inittiger(struct IsdnCardState *cs)
914{ 914{
915 if (!(cs->bcs[0].hw.tiger.send = kmalloc(NETJET_DMA_TXSIZE * sizeof(unsigned int), 915 if (!(cs->bcs[0].hw.tiger.send = kmalloc(NETJET_DMA_TXSIZE * sizeof(unsigned int),
diff --git a/drivers/isdn/hisax/niccy.c b/drivers/isdn/hisax/niccy.c
index 79a97b1c3812..489022bdef7b 100644
--- a/drivers/isdn/hisax/niccy.c
+++ b/drivers/isdn/hisax/niccy.c
@@ -232,12 +232,12 @@ niccy_card_msg(struct IsdnCardState *cs, int mt, void *arg)
232 return(0); 232 return(0);
233} 233}
234 234
235static struct pci_dev *niccy_dev __initdata = NULL; 235static struct pci_dev *niccy_dev __devinitdata = NULL;
236#ifdef __ISAPNP__ 236#ifdef __ISAPNP__
237static struct pnp_card *pnp_c __devinitdata = NULL; 237static struct pnp_card *pnp_c __devinitdata = NULL;
238#endif 238#endif
239 239
240int __init 240int __devinit
241setup_niccy(struct IsdnCard *card) 241setup_niccy(struct IsdnCard *card)
242{ 242{
243 struct IsdnCardState *cs = card->cs; 243 struct IsdnCardState *cs = card->cs;
diff --git a/drivers/isdn/hisax/nj_s.c b/drivers/isdn/hisax/nj_s.c
index e5b900a6fa0b..80025fd890f4 100644
--- a/drivers/isdn/hisax/nj_s.c
+++ b/drivers/isdn/hisax/nj_s.c
@@ -148,9 +148,9 @@ NETjet_S_card_msg(struct IsdnCardState *cs, int mt, void *arg)
148 return(0); 148 return(0);
149} 149}
150 150
151static struct pci_dev *dev_netjet __initdata = NULL; 151static struct pci_dev *dev_netjet __devinitdata = NULL;
152 152
153int __init 153int __devinit
154setup_netjet_s(struct IsdnCard *card) 154setup_netjet_s(struct IsdnCard *card)
155{ 155{
156 int bytecnt,cfg; 156 int bytecnt,cfg;
diff --git a/drivers/isdn/hisax/nj_u.c b/drivers/isdn/hisax/nj_u.c
index 7002b09936d4..37497162d539 100644
--- a/drivers/isdn/hisax/nj_u.c
+++ b/drivers/isdn/hisax/nj_u.c
@@ -128,9 +128,9 @@ NETjet_U_card_msg(struct IsdnCardState *cs, int mt, void *arg)
128 return(0); 128 return(0);
129} 129}
130 130
131static struct pci_dev *dev_netjet __initdata = NULL; 131static struct pci_dev *dev_netjet __devinitdata = NULL;
132 132
133int __init 133int __devinit
134setup_netjet_u(struct IsdnCard *card) 134setup_netjet_u(struct IsdnCard *card)
135{ 135{
136 int bytecnt; 136 int bytecnt;
diff --git a/drivers/isdn/hisax/s0box.c b/drivers/isdn/hisax/s0box.c
index 7b63085ea6e5..e76042d323ea 100644
--- a/drivers/isdn/hisax/s0box.c
+++ b/drivers/isdn/hisax/s0box.c
@@ -211,7 +211,7 @@ S0Box_card_msg(struct IsdnCardState *cs, int mt, void *arg)
211 return(0); 211 return(0);
212} 212}
213 213
214int __init 214int __devinit
215setup_s0box(struct IsdnCard *card) 215setup_s0box(struct IsdnCard *card)
216{ 216{
217 struct IsdnCardState *cs = card->cs; 217 struct IsdnCardState *cs = card->cs;
diff --git a/drivers/isdn/hisax/saphir.c b/drivers/isdn/hisax/saphir.c
index 821776e1561a..d943d365890b 100644
--- a/drivers/isdn/hisax/saphir.c
+++ b/drivers/isdn/hisax/saphir.c
@@ -241,7 +241,7 @@ saphir_card_msg(struct IsdnCardState *cs, int mt, void *arg)
241} 241}
242 242
243 243
244int __init 244int __devinit
245setup_saphir(struct IsdnCard *card) 245setup_saphir(struct IsdnCard *card)
246{ 246{
247 struct IsdnCardState *cs = card->cs; 247 struct IsdnCardState *cs = card->cs;
diff --git a/drivers/isdn/hisax/sportster.c b/drivers/isdn/hisax/sportster.c
index cdf35dc564c4..a49b694eb730 100644
--- a/drivers/isdn/hisax/sportster.c
+++ b/drivers/isdn/hisax/sportster.c
@@ -184,7 +184,7 @@ Sportster_card_msg(struct IsdnCardState *cs, int mt, void *arg)
184 return(0); 184 return(0);
185} 185}
186 186
187static int __init 187static int __devinit
188get_io_range(struct IsdnCardState *cs) 188get_io_range(struct IsdnCardState *cs)
189{ 189{
190 int i, j, adr; 190 int i, j, adr;
@@ -209,7 +209,7 @@ get_io_range(struct IsdnCardState *cs)
209 } 209 }
210} 210}
211 211
212int __init 212int __devinit
213setup_sportster(struct IsdnCard *card) 213setup_sportster(struct IsdnCard *card)
214{ 214{
215 struct IsdnCardState *cs = card->cs; 215 struct IsdnCardState *cs = card->cs;
diff --git a/drivers/isdn/hisax/teleint.c b/drivers/isdn/hisax/teleint.c
index a2b1816af37a..e94dc6f5bd62 100644
--- a/drivers/isdn/hisax/teleint.c
+++ b/drivers/isdn/hisax/teleint.c
@@ -261,7 +261,7 @@ TeleInt_card_msg(struct IsdnCardState *cs, int mt, void *arg)
261 return(0); 261 return(0);
262} 262}
263 263
264int __init 264int __devinit
265setup_TeleInt(struct IsdnCard *card) 265setup_TeleInt(struct IsdnCard *card)
266{ 266{
267 struct IsdnCardState *cs = card->cs; 267 struct IsdnCardState *cs = card->cs;
diff --git a/drivers/isdn/hisax/teles0.c b/drivers/isdn/hisax/teles0.c
index 2b7df8f98233..f94af0930a17 100644
--- a/drivers/isdn/hisax/teles0.c
+++ b/drivers/isdn/hisax/teles0.c
@@ -265,7 +265,7 @@ Teles_card_msg(struct IsdnCardState *cs, int mt, void *arg)
265 return(0); 265 return(0);
266} 266}
267 267
268int __init 268int __devinit
269setup_teles0(struct IsdnCard *card) 269setup_teles0(struct IsdnCard *card)
270{ 270{
271 u_char val; 271 u_char val;
diff --git a/drivers/isdn/hisax/telespci.c b/drivers/isdn/hisax/telespci.c
index 9382cdf04d8d..dca446865f24 100644
--- a/drivers/isdn/hisax/telespci.c
+++ b/drivers/isdn/hisax/telespci.c
@@ -284,9 +284,9 @@ TelesPCI_card_msg(struct IsdnCardState *cs, int mt, void *arg)
284 return(0); 284 return(0);
285} 285}
286 286
287static struct pci_dev *dev_tel __initdata = NULL; 287static struct pci_dev *dev_tel __devinitdata = NULL;
288 288
289int __init 289int __devinit
290setup_telespci(struct IsdnCard *card) 290setup_telespci(struct IsdnCard *card)
291{ 291{
292 struct IsdnCardState *cs = card->cs; 292 struct IsdnCardState *cs = card->cs;
diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
index 6c68419c05ff..0595293b8659 100644
--- a/drivers/isdn/hisax/w6692.c
+++ b/drivers/isdn/hisax/w6692.c
@@ -44,11 +44,11 @@ static const char *w6692_revision = "$Revision: 1.18.2.4 $";
44 44
45#define DBUSY_TIMER_VALUE 80 45#define DBUSY_TIMER_VALUE 80
46 46
47static char *W6692Ver[] __initdata = 47static char *W6692Ver[] =
48{"W6692 V00", "W6692 V01", "W6692 V10", 48{"W6692 V00", "W6692 V01", "W6692 V10",
49 "W6692 V11"}; 49 "W6692 V11"};
50 50
51static void __init 51static void
52W6692Version(struct IsdnCardState *cs, char *s) 52W6692Version(struct IsdnCardState *cs, char *s)
53{ 53{
54 int val; 54 int val;
@@ -897,7 +897,7 @@ static void resetW6692(struct IsdnCardState *cs)
897 } 897 }
898} 898}
899 899
900static void __init initW6692(struct IsdnCardState *cs, int part) 900static void initW6692(struct IsdnCardState *cs, int part)
901{ 901{
902 if (part & 1) { 902 if (part & 1) {
903 cs->setstack_d = setstack_W6692; 903 cs->setstack_d = setstack_W6692;
@@ -992,9 +992,9 @@ w6692_card_msg(struct IsdnCardState *cs, int mt, void *arg)
992 992
993static int id_idx ; 993static int id_idx ;
994 994
995static struct pci_dev *dev_w6692 __initdata = NULL; 995static struct pci_dev *dev_w6692 __devinitdata = NULL;
996 996
997int __init 997int __devinit
998setup_w6692(struct IsdnCard *card) 998setup_w6692(struct IsdnCard *card)
999{ 999{
1000 struct IsdnCardState *cs = card->cs; 1000 struct IsdnCardState *cs = card->cs;
diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
index 9f6c6375ff75..c3d79eef9e32 100644
--- a/drivers/isdn/i4l/isdn_common.c
+++ b/drivers/isdn/i4l/isdn_common.c
@@ -1059,7 +1059,7 @@ isdn_info_update(void)
1059static ssize_t 1059static ssize_t
1060isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off) 1060isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off)
1061{ 1061{
1062 uint minor = MINOR(file->f_dentry->d_inode->i_rdev); 1062 uint minor = iminor(file->f_dentry->d_inode);
1063 int len = 0; 1063 int len = 0;
1064 int drvidx; 1064 int drvidx;
1065 int chidx; 1065 int chidx;
@@ -1163,7 +1163,7 @@ isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off)
1163static ssize_t 1163static ssize_t
1164isdn_write(struct file *file, const char __user *buf, size_t count, loff_t * off) 1164isdn_write(struct file *file, const char __user *buf, size_t count, loff_t * off)
1165{ 1165{
1166 uint minor = MINOR(file->f_dentry->d_inode->i_rdev); 1166 uint minor = iminor(file->f_dentry->d_inode);
1167 int drvidx; 1167 int drvidx;
1168 int chidx; 1168 int chidx;
1169 int retval; 1169 int retval;
@@ -1225,7 +1225,7 @@ static unsigned int
1225isdn_poll(struct file *file, poll_table * wait) 1225isdn_poll(struct file *file, poll_table * wait)
1226{ 1226{
1227 unsigned int mask = 0; 1227 unsigned int mask = 0;
1228 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev); 1228 unsigned int minor = iminor(file->f_dentry->d_inode);
1229 int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL); 1229 int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1230 1230
1231 lock_kernel(); 1231 lock_kernel();
@@ -1266,7 +1266,7 @@ isdn_poll(struct file *file, poll_table * wait)
1266static int 1266static int
1267isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg) 1267isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1268{ 1268{
1269 uint minor = MINOR(inode->i_rdev); 1269 uint minor = iminor(inode);
1270 isdn_ctrl c; 1270 isdn_ctrl c;
1271 int drvidx; 1271 int drvidx;
1272 int chidx; 1272 int chidx;
@@ -1717,7 +1717,7 @@ isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1717static int 1717static int
1718isdn_open(struct inode *ino, struct file *filep) 1718isdn_open(struct inode *ino, struct file *filep)
1719{ 1719{
1720 uint minor = MINOR(ino->i_rdev); 1720 uint minor = iminor(ino);
1721 int drvidx; 1721 int drvidx;
1722 int chidx; 1722 int chidx;
1723 int retval = -ENODEV; 1723 int retval = -ENODEV;
@@ -1779,7 +1779,7 @@ isdn_open(struct inode *ino, struct file *filep)
1779static int 1779static int
1780isdn_close(struct inode *ino, struct file *filep) 1780isdn_close(struct inode *ino, struct file *filep)
1781{ 1781{
1782 uint minor = MINOR(ino->i_rdev); 1782 uint minor = iminor(ino);
1783 1783
1784 lock_kernel(); 1784 lock_kernel();
1785 if (minor == ISDN_MINOR_STATUS) { 1785 if (minor == ISDN_MINOR_STATUS) {
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index 29e7667ec962..119412d6bd15 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -667,7 +667,7 @@ isdn_ppp_poll(struct file *file, poll_table * wait)
667 667
668 if (is->debug & 0x2) 668 if (is->debug & 0x2)
669 printk(KERN_DEBUG "isdn_ppp_poll: minor: %d\n", 669 printk(KERN_DEBUG "isdn_ppp_poll: minor: %d\n",
670 MINOR(file->f_dentry->d_inode->i_rdev)); 670 iminor(file->f_dentry->d_inode));
671 671
672 /* just registers wait_queue hook. This doesn't really wait. */ 672 /* just registers wait_queue hook. This doesn't really wait. */
673 poll_wait(file, &is->wq, wait); 673 poll_wait(file, &is->wq, wait);
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 96509989e921..9c39b98d5a5b 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -69,6 +69,13 @@ config LEDS_AMS_DELTA
69 help 69 help
70 This option enables support for the LEDs on Amstrad Delta (E3). 70 This option enables support for the LEDs on Amstrad Delta (E3).
71 71
72config LEDS_NET48XX
73 tristate "LED Support for Soekris net48xx series Error LED"
74 depends on LEDS_CLASS && SCx200_GPIO
75 help
76 This option enables support for the Soekris net4801 and net4826 error
77 LED.
78
72comment "LED Triggers" 79comment "LED Triggers"
73 80
74config LEDS_TRIGGERS 81config LEDS_TRIGGERS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 88d3b6eaa6a2..6aa2aed7539d 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_LEDS_IXP4XX) += leds-ixp4xx-gpio.o
12obj-$(CONFIG_LEDS_TOSA) += leds-tosa.o 12obj-$(CONFIG_LEDS_TOSA) += leds-tosa.o
13obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o 13obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o
14obj-$(CONFIG_LEDS_AMS_DELTA) += leds-ams-delta.o 14obj-$(CONFIG_LEDS_AMS_DELTA) += leds-ams-delta.o
15obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o
15 16
16# LED Triggers 17# LED Triggers
17obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o 18obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
diff --git a/drivers/leds/leds-net48xx.c b/drivers/leds/leds-net48xx.c
new file mode 100644
index 000000000000..713c4a8aa77d
--- /dev/null
+++ b/drivers/leds/leds-net48xx.c
@@ -0,0 +1,116 @@
1/*
2 * LEDs driver for Soekris net48xx
3 *
4 * Copyright (C) 2006 Chris Boot <bootc@bootc.net>
5 *
6 * Based on leds-ams-delta.c
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 version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/platform_device.h>
16#include <linux/leds.h>
17#include <linux/err.h>
18#include <asm/io.h>
19#include <linux/scx200_gpio.h>
20
21#define DRVNAME "net48xx-led"
22#define NET48XX_ERROR_LED_GPIO 20
23
24static struct platform_device *pdev;
25
26static void net48xx_error_led_set(struct led_classdev *led_cdev,
27 enum led_brightness value)
28{
29 if (value)
30 scx200_gpio_set_high(NET48XX_ERROR_LED_GPIO);
31 else
32 scx200_gpio_set_low(NET48XX_ERROR_LED_GPIO);
33}
34
35static struct led_classdev net48xx_error_led = {
36 .name = "net48xx:error",
37 .brightness_set = net48xx_error_led_set,
38};
39
40#ifdef CONFIG_PM
41static int net48xx_led_suspend(struct platform_device *dev,
42 pm_message_t state)
43{
44 led_classdev_suspend(&net48xx_error_led);
45 return 0;
46}
47
48static int net48xx_led_resume(struct platform_device *dev)
49{
50 led_classdev_resume(&net48xx_error_led);
51 return 0;
52}
53#else
54#define net48xx_led_suspend NULL
55#define net48xx_led_resume NULL
56#endif
57
58static int net48xx_led_probe(struct platform_device *pdev)
59{
60 return led_classdev_register(&pdev->dev, &net48xx_error_led);
61}
62
63static int net48xx_led_remove(struct platform_device *pdev)
64{
65 led_classdev_unregister(&net48xx_error_led);
66 return 0;
67}
68
69static struct platform_driver net48xx_led_driver = {
70 .probe = net48xx_led_probe,
71 .remove = net48xx_led_remove,
72 .suspend = net48xx_led_suspend,
73 .resume = net48xx_led_resume,
74 .driver = {
75 .name = DRVNAME,
76 .owner = THIS_MODULE,
77 },
78};
79
80static int __init net48xx_led_init(void)
81{
82 int ret;
83
84 if (!scx200_gpio_present()) {
85 ret = -ENODEV;
86 goto out;
87 }
88
89 ret = platform_driver_register(&net48xx_led_driver);
90 if (ret < 0)
91 goto out;
92
93 pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
94 if (IS_ERR(pdev)) {
95 ret = PTR_ERR(pdev);
96 platform_driver_unregister(&net48xx_led_driver);
97 goto out;
98 }
99
100out:
101 return ret;
102}
103
104static void __exit net48xx_led_exit(void)
105{
106 platform_device_unregister(pdev);
107 platform_driver_unregister(&net48xx_led_driver);
108}
109
110module_init(net48xx_led_init);
111module_exit(net48xx_led_exit);
112
113MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
114MODULE_DESCRIPTION("Soekris net48xx LED driver");
115MODULE_LICENSE("GPL");
116
diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig
index 54f3f6b94efc..d5d649f5ccdb 100644
--- a/drivers/macintosh/Kconfig
+++ b/drivers/macintosh/Kconfig
@@ -90,6 +90,15 @@ config ADB_PMU_LED
90 and the ide-disk LED trigger and configure appropriately through 90 and the ide-disk LED trigger and configure appropriately through
91 sysfs. 91 sysfs.
92 92
93config ADB_PMU_LED_IDE
94 bool "Use front LED as IDE LED by default"
95 depends on ADB_PMU_LED
96 select LEDS_TRIGGERS
97 select LEDS_TRIGGER_IDE_DISK
98 help
99 This option makes the front LED default to the IDE trigger
100 so that it blinks on IDE activity.
101
93config PMAC_SMU 102config PMAC_SMU
94 bool "Support for SMU based PowerMacs" 103 bool "Support for SMU based PowerMacs"
95 depends on PPC_PMAC64 104 depends on PPC_PMAC64
@@ -100,7 +109,7 @@ config PMAC_SMU
100 109
101config PMAC_APM_EMU 110config PMAC_APM_EMU
102 tristate "APM emulation" 111 tristate "APM emulation"
103 depends on PPC_PMAC && PPC32 && PM 112 depends on PPC_PMAC && PPC32 && PM && ADB_PMU
104 113
105config PMAC_MEDIABAY 114config PMAC_MEDIABAY
106 bool "Support PowerBook hotswap media bay" 115 bool "Support PowerBook hotswap media bay"
@@ -113,7 +122,8 @@ config PMAC_MEDIABAY
113 122
114config PMAC_BACKLIGHT 123config PMAC_BACKLIGHT
115 bool "Backlight control for LCD screens" 124 bool "Backlight control for LCD screens"
116 depends on ADB_PMU && (BROKEN || !PPC64) 125 depends on ADB_PMU && FB = y && (BROKEN || !PPC64)
126 select FB_BACKLIGHT
117 help 127 help
118 Say Y here to enable Macintosh specific extensions of the generic 128 Say Y here to enable Macintosh specific extensions of the generic
119 backlight code. With this enabled, the brightness keys on older 129 backlight code. With this enabled, the brightness keys on older
diff --git a/drivers/macintosh/adbhid.c b/drivers/macintosh/adbhid.c
index 545be1ed6927..c69d23bb255e 100644
--- a/drivers/macintosh/adbhid.c
+++ b/drivers/macintosh/adbhid.c
@@ -45,14 +45,11 @@
45#include <linux/pmu.h> 45#include <linux/pmu.h>
46 46
47#include <asm/machdep.h> 47#include <asm/machdep.h>
48#include <asm/backlight.h>
48#ifdef CONFIG_PPC_PMAC 49#ifdef CONFIG_PPC_PMAC
49#include <asm/pmac_feature.h> 50#include <asm/pmac_feature.h>
50#endif 51#endif
51 52
52#ifdef CONFIG_PMAC_BACKLIGHT
53#include <asm/backlight.h>
54#endif
55
56MODULE_AUTHOR("Franz Sirl <Franz.Sirl-kernel@lauterbach.com>"); 53MODULE_AUTHOR("Franz Sirl <Franz.Sirl-kernel@lauterbach.com>");
57 54
58#define KEYB_KEYREG 0 /* register # for key up/down data */ 55#define KEYB_KEYREG 0 /* register # for key up/down data */
@@ -237,11 +234,6 @@ static struct adb_ids keyboard_ids;
237static struct adb_ids mouse_ids; 234static struct adb_ids mouse_ids;
238static struct adb_ids buttons_ids; 235static struct adb_ids buttons_ids;
239 236
240#ifdef CONFIG_PMAC_BACKLIGHT
241/* Exported to via-pmu.c */
242int disable_kernel_backlight = 0;
243#endif /* CONFIG_PMAC_BACKLIGHT */
244
245/* Kind of keyboard, see Apple technote 1152 */ 237/* Kind of keyboard, see Apple technote 1152 */
246#define ADB_KEYBOARD_UNKNOWN 0 238#define ADB_KEYBOARD_UNKNOWN 0
247#define ADB_KEYBOARD_ANSI 0x0100 239#define ADB_KEYBOARD_ANSI 0x0100
@@ -527,7 +519,7 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
527 519
528 case 0xa: /* brightness decrease */ 520 case 0xa: /* brightness decrease */
529#ifdef CONFIG_PMAC_BACKLIGHT 521#ifdef CONFIG_PMAC_BACKLIGHT
530 if (!disable_kernel_backlight && down) 522 if (down)
531 pmac_backlight_key_down(); 523 pmac_backlight_key_down();
532#endif 524#endif
533 input_report_key(adbhid[id]->input, KEY_BRIGHTNESSDOWN, down); 525 input_report_key(adbhid[id]->input, KEY_BRIGHTNESSDOWN, down);
@@ -535,7 +527,7 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
535 527
536 case 0x9: /* brightness increase */ 528 case 0x9: /* brightness increase */
537#ifdef CONFIG_PMAC_BACKLIGHT 529#ifdef CONFIG_PMAC_BACKLIGHT
538 if (!disable_kernel_backlight && down) 530 if (down)
539 pmac_backlight_key_up(); 531 pmac_backlight_key_up();
540#endif 532#endif
541 input_report_key(adbhid[id]->input, KEY_BRIGHTNESSUP, down); 533 input_report_key(adbhid[id]->input, KEY_BRIGHTNESSUP, down);
diff --git a/drivers/macintosh/macio-adb.c b/drivers/macintosh/macio-adb.c
index 314fc0830d90..4b08852c35ee 100644
--- a/drivers/macintosh/macio-adb.c
+++ b/drivers/macintosh/macio-adb.c
@@ -90,22 +90,12 @@ int macio_init(void)
90{ 90{
91 struct device_node *adbs; 91 struct device_node *adbs;
92 struct resource r; 92 struct resource r;
93 unsigned int irq;
93 94
94 adbs = find_compatible_devices("adb", "chrp,adb0"); 95 adbs = find_compatible_devices("adb", "chrp,adb0");
95 if (adbs == 0) 96 if (adbs == 0)
96 return -ENXIO; 97 return -ENXIO;
97 98
98#if 0
99 { int i = 0;
100
101 printk("macio_adb_init: node = %p, addrs =", adbs->node);
102 while(!of_address_to_resource(adbs, i, &r))
103 printk(" %x(%x)", r.start, r.end - r.start);
104 printk(", intrs =");
105 for (i = 0; i < adbs->n_intrs; ++i)
106 printk(" %x", adbs->intrs[i].line);
107 printk("\n"); }
108#endif
109 if (of_address_to_resource(adbs, 0, &r)) 99 if (of_address_to_resource(adbs, 0, &r))
110 return -ENXIO; 100 return -ENXIO;
111 adb = ioremap(r.start, sizeof(struct adb_regs)); 101 adb = ioremap(r.start, sizeof(struct adb_regs));
@@ -117,10 +107,9 @@ int macio_init(void)
117 out_8(&adb->active_lo.r, 0xff); 107 out_8(&adb->active_lo.r, 0xff);
118 out_8(&adb->autopoll.r, APE); 108 out_8(&adb->autopoll.r, APE);
119 109
120 if (request_irq(adbs->intrs[0].line, macio_adb_interrupt, 110 irq = irq_of_parse_and_map(adbs, 0);
121 0, "ADB", (void *)0)) { 111 if (request_irq(irq, macio_adb_interrupt, 0, "ADB", (void *)0)) {
122 printk(KERN_ERR "ADB: can't get irq %d\n", 112 printk(KERN_ERR "ADB: can't get irq %d\n", irq);
123 adbs->intrs[0].line);
124 return -EAGAIN; 113 return -EAGAIN;
125 } 114 }
126 out_8(&adb->intr_enb.r, DFB | TAG); 115 out_8(&adb->intr_enb.r, DFB | TAG);
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index 40ae7b6a939d..82657bc86d19 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -280,75 +280,128 @@ static void macio_release_dev(struct device *dev)
280static int macio_resource_quirks(struct device_node *np, struct resource *res, 280static int macio_resource_quirks(struct device_node *np, struct resource *res,
281 int index) 281 int index)
282{ 282{
283 if (res->flags & IORESOURCE_MEM) { 283 /* Only quirks for memory resources for now */
284 /* Grand Central has too large resource 0 on some machines */ 284 if ((res->flags & IORESOURCE_MEM) == 0)
285 if (index == 0 && !strcmp(np->name, "gc")) 285 return 0;
286 res->end = res->start + 0x1ffff; 286
287 /* Grand Central has too large resource 0 on some machines */
288 if (index == 0 && !strcmp(np->name, "gc"))
289 res->end = res->start + 0x1ffff;
287 290
288 /* Airport has bogus resource 2 */ 291 /* Airport has bogus resource 2 */
289 if (index >= 2 && !strcmp(np->name, "radio")) 292 if (index >= 2 && !strcmp(np->name, "radio"))
290 return 1; 293 return 1;
291 294
292#ifndef CONFIG_PPC64 295#ifndef CONFIG_PPC64
293 /* DBDMAs may have bogus sizes */ 296 /* DBDMAs may have bogus sizes */
294 if ((res->start & 0x0001f000) == 0x00008000) 297 if ((res->start & 0x0001f000) == 0x00008000)
295 res->end = res->start + 0xff; 298 res->end = res->start + 0xff;
296#endif /* CONFIG_PPC64 */ 299#endif /* CONFIG_PPC64 */
297 300
298 /* ESCC parent eats child resources. We could have added a 301 /* ESCC parent eats child resources. We could have added a
299 * level of hierarchy, but I don't really feel the need 302 * level of hierarchy, but I don't really feel the need
300 * for it 303 * for it
301 */ 304 */
302 if (!strcmp(np->name, "escc")) 305 if (!strcmp(np->name, "escc"))
303 return 1; 306 return 1;
304 307
305 /* ESCC has bogus resources >= 3 */ 308 /* ESCC has bogus resources >= 3 */
306 if (index >= 3 && !(strcmp(np->name, "ch-a") && 309 if (index >= 3 && !(strcmp(np->name, "ch-a") &&
307 strcmp(np->name, "ch-b"))) 310 strcmp(np->name, "ch-b")))
308 return 1; 311 return 1;
309 312
310 /* Media bay has too many resources, keep only first one */ 313 /* Media bay has too many resources, keep only first one */
311 if (index > 0 && !strcmp(np->name, "media-bay")) 314 if (index > 0 && !strcmp(np->name, "media-bay"))
312 return 1; 315 return 1;
313 316
314 /* Some older IDE resources have bogus sizes */ 317 /* Some older IDE resources have bogus sizes */
315 if (!(strcmp(np->name, "IDE") && strcmp(np->name, "ATA") && 318 if (!(strcmp(np->name, "IDE") && strcmp(np->name, "ATA") &&
316 strcmp(np->type, "ide") && strcmp(np->type, "ata"))) { 319 strcmp(np->type, "ide") && strcmp(np->type, "ata"))) {
317 if (index == 0 && (res->end - res->start) > 0xfff) 320 if (index == 0 && (res->end - res->start) > 0xfff)
318 res->end = res->start + 0xfff; 321 res->end = res->start + 0xfff;
319 if (index == 1 && (res->end - res->start) > 0xff) 322 if (index == 1 && (res->end - res->start) > 0xff)
320 res->end = res->start + 0xff; 323 res->end = res->start + 0xff;
321 }
322 } 324 }
323 return 0; 325 return 0;
324} 326}
325 327
328static void macio_create_fixup_irq(struct macio_dev *dev, int index,
329 unsigned int line)
330{
331 unsigned int irq;
326 332
327static void macio_setup_interrupts(struct macio_dev *dev) 333 irq = irq_create_mapping(NULL, line);
334 if (irq != NO_IRQ) {
335 dev->interrupt[index].start = irq;
336 dev->interrupt[index].flags = IORESOURCE_IRQ;
337 dev->interrupt[index].name = dev->ofdev.dev.bus_id;
338 }
339 if (dev->n_interrupts <= index)
340 dev->n_interrupts = index + 1;
341}
342
343static void macio_add_missing_resources(struct macio_dev *dev)
328{ 344{
329 struct device_node *np = dev->ofdev.node; 345 struct device_node *np = dev->ofdev.node;
330 int i,j; 346 unsigned int irq_base;
347
348 /* Gatwick has some missing interrupts on child nodes */
349 if (dev->bus->chip->type != macio_gatwick)
350 return;
331 351
332 /* For now, we use pre-parsed entries in the device-tree for 352 /* irq_base is always 64 on gatwick. I have no cleaner way to get
333 * interrupt routing and addresses, but we should change that 353 * that value from here at this point
334 * to dynamically parsed entries and so get rid of most of the
335 * clutter in struct device_node
336 */ 354 */
337 for (i = j = 0; i < np->n_intrs; i++) { 355 irq_base = 64;
356
357 /* Fix SCC */
358 if (strcmp(np->name, "ch-a") == 0) {
359 macio_create_fixup_irq(dev, 0, 15 + irq_base);
360 macio_create_fixup_irq(dev, 1, 4 + irq_base);
361 macio_create_fixup_irq(dev, 2, 5 + irq_base);
362 printk(KERN_INFO "macio: fixed SCC irqs on gatwick\n");
363 }
364
365 /* Fix media-bay */
366 if (strcmp(np->name, "media-bay") == 0) {
367 macio_create_fixup_irq(dev, 0, 29 + irq_base);
368 printk(KERN_INFO "macio: fixed media-bay irq on gatwick\n");
369 }
370
371 /* Fix left media bay childs */
372 if (dev->media_bay != NULL && strcmp(np->name, "floppy") == 0) {
373 macio_create_fixup_irq(dev, 0, 19 + irq_base);
374 macio_create_fixup_irq(dev, 1, 1 + irq_base);
375 printk(KERN_INFO "macio: fixed left floppy irqs\n");
376 }
377 if (dev->media_bay != NULL && strcasecmp(np->name, "ata4") == 0) {
378 macio_create_fixup_irq(dev, 0, 14 + irq_base);
379 macio_create_fixup_irq(dev, 0, 3 + irq_base);
380 printk(KERN_INFO "macio: fixed left ide irqs\n");
381 }
382}
383
384static void macio_setup_interrupts(struct macio_dev *dev)
385{
386 struct device_node *np = dev->ofdev.node;
387 unsigned int irq;
388 int i = 0, j = 0;
389
390 for (;;) {
338 struct resource *res = &dev->interrupt[j]; 391 struct resource *res = &dev->interrupt[j];
339 392
340 if (j >= MACIO_DEV_COUNT_IRQS) 393 if (j >= MACIO_DEV_COUNT_IRQS)
341 break; 394 break;
342 res->start = np->intrs[i].line; 395 irq = irq_of_parse_and_map(np, i++);
343 res->flags = IORESOURCE_IO; 396 if (irq == NO_IRQ)
344 if (np->intrs[j].sense) 397 break;
345 res->flags |= IORESOURCE_IRQ_LOWLEVEL; 398 res->start = irq;
346 else 399 res->flags = IORESOURCE_IRQ;
347 res->flags |= IORESOURCE_IRQ_HIGHEDGE;
348 res->name = dev->ofdev.dev.bus_id; 400 res->name = dev->ofdev.dev.bus_id;
349 if (macio_resource_quirks(np, res, i)) 401 if (macio_resource_quirks(np, res, i - 1)) {
350 memset(res, 0, sizeof(struct resource)); 402 memset(res, 0, sizeof(struct resource));
351 else 403 continue;
404 } else
352 j++; 405 j++;
353 } 406 }
354 dev->n_interrupts = j; 407 dev->n_interrupts = j;
@@ -445,6 +498,7 @@ static struct macio_dev * macio_add_one_device(struct macio_chip *chip,
445 /* Setup interrupts & resources */ 498 /* Setup interrupts & resources */
446 macio_setup_interrupts(dev); 499 macio_setup_interrupts(dev);
447 macio_setup_resources(dev, parent_res); 500 macio_setup_resources(dev, parent_res);
501 macio_add_missing_resources(dev);
448 502
449 /* Register with core */ 503 /* Register with core */
450 if (of_device_register(&dev->ofdev) != 0) { 504 if (of_device_register(&dev->ofdev) != 0) {
diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index ff6d9bfdc3d2..00ef46898147 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -75,9 +75,11 @@ struct smu_device {
75 struct of_device *of_dev; 75 struct of_device *of_dev;
76 int doorbell; /* doorbell gpio */ 76 int doorbell; /* doorbell gpio */
77 u32 __iomem *db_buf; /* doorbell buffer */ 77 u32 __iomem *db_buf; /* doorbell buffer */
78 int db_irq; 78 struct device_node *db_node;
79 unsigned int db_irq;
79 int msg; 80 int msg;
80 int msg_irq; 81 struct device_node *msg_node;
82 unsigned int msg_irq;
81 struct smu_cmd_buf *cmd_buf; /* command buffer virtual */ 83 struct smu_cmd_buf *cmd_buf; /* command buffer virtual */
82 u32 cmd_buf_abs; /* command buffer absolute */ 84 u32 cmd_buf_abs; /* command buffer absolute */
83 struct list_head cmd_list; 85 struct list_head cmd_list;
@@ -93,6 +95,7 @@ struct smu_device {
93 */ 95 */
94static struct smu_device *smu; 96static struct smu_device *smu;
95static DEFINE_MUTEX(smu_part_access); 97static DEFINE_MUTEX(smu_part_access);
98static int smu_irq_inited;
96 99
97static void smu_i2c_retry(unsigned long data); 100static void smu_i2c_retry(unsigned long data);
98 101
@@ -257,6 +260,10 @@ int smu_queue_cmd(struct smu_cmd *cmd)
257 smu_start_cmd(); 260 smu_start_cmd();
258 spin_unlock_irqrestore(&smu->lock, flags); 261 spin_unlock_irqrestore(&smu->lock, flags);
259 262
263 /* Workaround for early calls when irq isn't available */
264 if (!smu_irq_inited || smu->db_irq == NO_IRQ)
265 smu_spinwait_cmd(cmd);
266
260 return 0; 267 return 0;
261} 268}
262EXPORT_SYMBOL(smu_queue_cmd); 269EXPORT_SYMBOL(smu_queue_cmd);
@@ -478,14 +485,15 @@ int __init smu_init (void)
478 smu->cmd_buf_abs = (u32)smu_cmdbuf_abs; 485 smu->cmd_buf_abs = (u32)smu_cmdbuf_abs;
479 smu->cmd_buf = (struct smu_cmd_buf *)abs_to_virt(smu_cmdbuf_abs); 486 smu->cmd_buf = (struct smu_cmd_buf *)abs_to_virt(smu_cmdbuf_abs);
480 487
481 np = of_find_node_by_name(NULL, "smu-doorbell"); 488 smu->db_node = of_find_node_by_name(NULL, "smu-doorbell");
482 if (np == NULL) { 489 if (smu->db_node == NULL) {
483 printk(KERN_ERR "SMU: Can't find doorbell GPIO !\n"); 490 printk(KERN_ERR "SMU: Can't find doorbell GPIO !\n");
484 goto fail; 491 goto fail;
485 } 492 }
486 data = (u32 *)get_property(np, "reg", NULL); 493 data = (u32 *)get_property(smu->db_node, "reg", NULL);
487 if (data == NULL) { 494 if (data == NULL) {
488 of_node_put(np); 495 of_node_put(smu->db_node);
496 smu->db_node = NULL;
489 printk(KERN_ERR "SMU: Can't find doorbell GPIO address !\n"); 497 printk(KERN_ERR "SMU: Can't find doorbell GPIO address !\n");
490 goto fail; 498 goto fail;
491 } 499 }
@@ -497,27 +505,21 @@ int __init smu_init (void)
497 smu->doorbell = *data; 505 smu->doorbell = *data;
498 if (smu->doorbell < 0x50) 506 if (smu->doorbell < 0x50)
499 smu->doorbell += 0x50; 507 smu->doorbell += 0x50;
500 if (np->n_intrs > 0)
501 smu->db_irq = np->intrs[0].line;
502
503 of_node_put(np);
504 508
505 /* Now look for the smu-interrupt GPIO */ 509 /* Now look for the smu-interrupt GPIO */
506 do { 510 do {
507 np = of_find_node_by_name(NULL, "smu-interrupt"); 511 smu->msg_node = of_find_node_by_name(NULL, "smu-interrupt");
508 if (np == NULL) 512 if (smu->msg_node == NULL)
509 break; 513 break;
510 data = (u32 *)get_property(np, "reg", NULL); 514 data = (u32 *)get_property(smu->msg_node, "reg", NULL);
511 if (data == NULL) { 515 if (data == NULL) {
512 of_node_put(np); 516 of_node_put(smu->msg_node);
517 smu->msg_node = NULL;
513 break; 518 break;
514 } 519 }
515 smu->msg = *data; 520 smu->msg = *data;
516 if (smu->msg < 0x50) 521 if (smu->msg < 0x50)
517 smu->msg += 0x50; 522 smu->msg += 0x50;
518 if (np->n_intrs > 0)
519 smu->msg_irq = np->intrs[0].line;
520 of_node_put(np);
521 } while(0); 523 } while(0);
522 524
523 /* Doorbell buffer is currently hard-coded, I didn't find a proper 525 /* Doorbell buffer is currently hard-coded, I didn't find a proper
@@ -549,6 +551,19 @@ static int smu_late_init(void)
549 smu->i2c_timer.function = smu_i2c_retry; 551 smu->i2c_timer.function = smu_i2c_retry;
550 smu->i2c_timer.data = (unsigned long)smu; 552 smu->i2c_timer.data = (unsigned long)smu;
551 553
554 if (smu->db_node) {
555 smu->db_irq = irq_of_parse_and_map(smu->db_node, 0);
556 if (smu->db_irq == NO_IRQ)
557 printk(KERN_ERR "smu: failed to map irq for node %s\n",
558 smu->db_node->full_name);
559 }
560 if (smu->msg_node) {
561 smu->msg_irq = irq_of_parse_and_map(smu->msg_node, 0);
562 if (smu->msg_irq == NO_IRQ)
563 printk(KERN_ERR "smu: failed to map irq for node %s\n",
564 smu->msg_node->full_name);
565 }
566
552 /* 567 /*
553 * Try to request the interrupts 568 * Try to request the interrupts
554 */ 569 */
@@ -573,6 +588,7 @@ static int smu_late_init(void)
573 } 588 }
574 } 589 }
575 590
591 smu_irq_inited = 1;
576 return 0; 592 return 0;
577} 593}
578/* This has to be before arch_initcall as the low i2c stuff relies on the 594/* This has to be before arch_initcall as the low i2c stuff relies on the
@@ -744,6 +760,11 @@ static void smu_i2c_low_completion(struct smu_cmd *scmd, void *misc)
744 if (fail && --cmd->retries > 0) { 760 if (fail && --cmd->retries > 0) {
745 DPRINTK("SMU: i2c failure, starting timer...\n"); 761 DPRINTK("SMU: i2c failure, starting timer...\n");
746 BUG_ON(cmd != smu->cmd_i2c_cur); 762 BUG_ON(cmd != smu->cmd_i2c_cur);
763 if (!smu_irq_inited) {
764 mdelay(5);
765 smu_i2c_retry(0);
766 return;
767 }
747 mod_timer(&smu->i2c_timer, jiffies + msecs_to_jiffies(5)); 768 mod_timer(&smu->i2c_timer, jiffies + msecs_to_jiffies(5));
748 return; 769 return;
749 } 770 }
diff --git a/drivers/macintosh/therm_pm72.c b/drivers/macintosh/therm_pm72.c
index c1fe0b368f76..20bf67244e2c 100644
--- a/drivers/macintosh/therm_pm72.c
+++ b/drivers/macintosh/therm_pm72.c
@@ -95,6 +95,17 @@
95 * - Use min/max macros here or there 95 * - Use min/max macros here or there
96 * - Latest darwin updated U3H min fan speed to 20% PWM 96 * - Latest darwin updated U3H min fan speed to 20% PWM
97 * 97 *
98 * July. 06, 2006 : 1.3
99 * - Fix setting of RPM fans on Xserve G5 (they were going too fast)
100 * - Add missing slots fan control loop for Xserve G5
101 * - Lower fixed slots fan speed from 50% to 40% on desktop G5s. We
102 * still can't properly implement the control loop for these, so let's
103 * reduce the noise a little bit, it appears that 40% still gives us
104 * a pretty good air flow
105 * - Add code to "tickle" the FCU regulary so it doesn't think that
106 * we are gone while in fact, the machine just didn't need any fan
107 * speed change lately
108 *
98 */ 109 */
99 110
100#include <linux/types.h> 111#include <linux/types.h>
@@ -121,7 +132,7 @@
121 132
122#include "therm_pm72.h" 133#include "therm_pm72.h"
123 134
124#define VERSION "1.2b2" 135#define VERSION "1.3"
125 136
126#undef DEBUG 137#undef DEBUG
127 138
@@ -146,6 +157,7 @@ static struct basckside_pid_params backside_params;
146static struct backside_pid_state backside_state; 157static struct backside_pid_state backside_state;
147static struct drives_pid_state drives_state; 158static struct drives_pid_state drives_state;
148static struct dimm_pid_state dimms_state; 159static struct dimm_pid_state dimms_state;
160static struct slots_pid_state slots_state;
149static int state; 161static int state;
150static int cpu_count; 162static int cpu_count;
151static int cpu_pid_type; 163static int cpu_pid_type;
@@ -154,7 +166,8 @@ static struct completion ctrl_complete;
154static int critical_state; 166static int critical_state;
155static int rackmac; 167static int rackmac;
156static s32 dimm_output_clamp; 168static s32 dimm_output_clamp;
157 169static int fcu_rpm_shift;
170static int fcu_tickle_ticks;
158static DECLARE_MUTEX(driver_lock); 171static DECLARE_MUTEX(driver_lock);
159 172
160/* 173/*
@@ -495,13 +508,20 @@ static int start_fcu(void)
495 rc = fan_write_reg(0x2e, &buf, 1); 508 rc = fan_write_reg(0x2e, &buf, 1);
496 if (rc < 0) 509 if (rc < 0)
497 return -EIO; 510 return -EIO;
511 rc = fan_read_reg(0, &buf, 1);
512 if (rc < 0)
513 return -EIO;
514 fcu_rpm_shift = (buf == 1) ? 2 : 3;
515 printk(KERN_DEBUG "FCU Initialized, RPM fan shift is %d\n",
516 fcu_rpm_shift);
517
498 return 0; 518 return 0;
499} 519}
500 520
501static int set_rpm_fan(int fan_index, int rpm) 521static int set_rpm_fan(int fan_index, int rpm)
502{ 522{
503 unsigned char buf[2]; 523 unsigned char buf[2];
504 int rc, id; 524 int rc, id, min, max;
505 525
506 if (fcu_fans[fan_index].type != FCU_FAN_RPM) 526 if (fcu_fans[fan_index].type != FCU_FAN_RPM)
507 return -EINVAL; 527 return -EINVAL;
@@ -509,12 +529,15 @@ static int set_rpm_fan(int fan_index, int rpm)
509 if (id == FCU_FAN_ABSENT_ID) 529 if (id == FCU_FAN_ABSENT_ID)
510 return -EINVAL; 530 return -EINVAL;
511 531
512 if (rpm < 300) 532 min = 2400 >> fcu_rpm_shift;
513 rpm = 300; 533 max = 56000 >> fcu_rpm_shift;
514 else if (rpm > 8191) 534
515 rpm = 8191; 535 if (rpm < min)
516 buf[0] = rpm >> 5; 536 rpm = min;
517 buf[1] = rpm << 3; 537 else if (rpm > max)
538 rpm = max;
539 buf[0] = rpm >> (8 - fcu_rpm_shift);
540 buf[1] = rpm << fcu_rpm_shift;
518 rc = fan_write_reg(0x10 + (id * 2), buf, 2); 541 rc = fan_write_reg(0x10 + (id * 2), buf, 2);
519 if (rc < 0) 542 if (rc < 0)
520 return -EIO; 543 return -EIO;
@@ -551,7 +574,7 @@ static int get_rpm_fan(int fan_index, int programmed)
551 if (rc != 2) 574 if (rc != 2)
552 return -EIO; 575 return -EIO;
553 576
554 return (buf[0] << 5) | buf[1] >> 3; 577 return (buf[0] << (8 - fcu_rpm_shift)) | buf[1] >> fcu_rpm_shift;
555} 578}
556 579
557static int set_pwm_fan(int fan_index, int pwm) 580static int set_pwm_fan(int fan_index, int pwm)
@@ -609,6 +632,26 @@ static int get_pwm_fan(int fan_index)
609 return (buf[0] * 1000) / 2559; 632 return (buf[0] * 1000) / 2559;
610} 633}
611 634
635static void tickle_fcu(void)
636{
637 int pwm;
638
639 pwm = get_pwm_fan(SLOTS_FAN_PWM_INDEX);
640
641 DBG("FCU Tickle, slots fan is: %d\n", pwm);
642 if (pwm < 0)
643 pwm = 100;
644
645 if (!rackmac) {
646 pwm = SLOTS_FAN_DEFAULT_PWM;
647 } else if (pwm < SLOTS_PID_OUTPUT_MIN)
648 pwm = SLOTS_PID_OUTPUT_MIN;
649
650 /* That is hopefully enough to make the FCU happy */
651 set_pwm_fan(SLOTS_FAN_PWM_INDEX, pwm);
652}
653
654
612/* 655/*
613 * Utility routine to read the CPU calibration EEPROM data 656 * Utility routine to read the CPU calibration EEPROM data
614 * from the device-tree 657 * from the device-tree
@@ -715,6 +758,9 @@ BUILD_SHOW_FUNC_INT(backside_fan_pwm, backside_state.pwm)
715BUILD_SHOW_FUNC_FIX(drives_temperature, drives_state.last_temp) 758BUILD_SHOW_FUNC_FIX(drives_temperature, drives_state.last_temp)
716BUILD_SHOW_FUNC_INT(drives_fan_rpm, drives_state.rpm) 759BUILD_SHOW_FUNC_INT(drives_fan_rpm, drives_state.rpm)
717 760
761BUILD_SHOW_FUNC_FIX(slots_temperature, slots_state.last_temp)
762BUILD_SHOW_FUNC_INT(slots_fan_pwm, slots_state.pwm)
763
718BUILD_SHOW_FUNC_FIX(dimms_temperature, dimms_state.last_temp) 764BUILD_SHOW_FUNC_FIX(dimms_temperature, dimms_state.last_temp)
719 765
720static DEVICE_ATTR(cpu0_temperature,S_IRUGO,show_cpu0_temperature,NULL); 766static DEVICE_ATTR(cpu0_temperature,S_IRUGO,show_cpu0_temperature,NULL);
@@ -735,6 +781,9 @@ static DEVICE_ATTR(backside_fan_pwm,S_IRUGO,show_backside_fan_pwm,NULL);
735static DEVICE_ATTR(drives_temperature,S_IRUGO,show_drives_temperature,NULL); 781static DEVICE_ATTR(drives_temperature,S_IRUGO,show_drives_temperature,NULL);
736static DEVICE_ATTR(drives_fan_rpm,S_IRUGO,show_drives_fan_rpm,NULL); 782static DEVICE_ATTR(drives_fan_rpm,S_IRUGO,show_drives_fan_rpm,NULL);
737 783
784static DEVICE_ATTR(slots_temperature,S_IRUGO,show_slots_temperature,NULL);
785static DEVICE_ATTR(slots_fan_pwm,S_IRUGO,show_slots_fan_pwm,NULL);
786
738static DEVICE_ATTR(dimms_temperature,S_IRUGO,show_dimms_temperature,NULL); 787static DEVICE_ATTR(dimms_temperature,S_IRUGO,show_dimms_temperature,NULL);
739 788
740/* 789/*
@@ -1076,6 +1125,9 @@ static void do_monitor_cpu_rack(struct cpu_pid_state *state)
1076 fan_min = dimm_output_clamp; 1125 fan_min = dimm_output_clamp;
1077 fan_min = max(fan_min, (int)state->mpu.rminn_intake_fan); 1126 fan_min = max(fan_min, (int)state->mpu.rminn_intake_fan);
1078 1127
1128 DBG(" CPU min mpu = %d, min dimm = %d\n",
1129 state->mpu.rminn_intake_fan, dimm_output_clamp);
1130
1079 state->rpm = max(state->rpm, (int)fan_min); 1131 state->rpm = max(state->rpm, (int)fan_min);
1080 state->rpm = min(state->rpm, (int)state->mpu.rmaxn_intake_fan); 1132 state->rpm = min(state->rpm, (int)state->mpu.rmaxn_intake_fan);
1081 state->intake_rpm = state->rpm; 1133 state->intake_rpm = state->rpm;
@@ -1374,7 +1426,8 @@ static void do_monitor_drives(struct drives_pid_state *state)
1374 DBG(" current rpm: %d\n", state->rpm); 1426 DBG(" current rpm: %d\n", state->rpm);
1375 1427
1376 /* Get some sensor readings */ 1428 /* Get some sensor readings */
1377 temp = le16_to_cpu(i2c_smbus_read_word_data(state->monitor, DS1775_TEMP)) << 8; 1429 temp = le16_to_cpu(i2c_smbus_read_word_data(state->monitor,
1430 DS1775_TEMP)) << 8;
1378 state->last_temp = temp; 1431 state->last_temp = temp;
1379 DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp), 1432 DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp),
1380 FIX32TOPRINT(DRIVES_PID_INPUT_TARGET)); 1433 FIX32TOPRINT(DRIVES_PID_INPUT_TARGET));
@@ -1575,7 +1628,7 @@ static int init_dimms_state(struct dimm_pid_state *state)
1575} 1628}
1576 1629
1577/* 1630/*
1578 * Dispose of the state data for the drives control loop 1631 * Dispose of the state data for the DIMM control loop
1579 */ 1632 */
1580static void dispose_dimms_state(struct dimm_pid_state *state) 1633static void dispose_dimms_state(struct dimm_pid_state *state)
1581{ 1634{
@@ -1588,6 +1641,127 @@ static void dispose_dimms_state(struct dimm_pid_state *state)
1588 state->monitor = NULL; 1641 state->monitor = NULL;
1589} 1642}
1590 1643
1644/*
1645 * Slots fan control loop
1646 */
1647static void do_monitor_slots(struct slots_pid_state *state)
1648{
1649 s32 temp, integral, derivative;
1650 s64 integ_p, deriv_p, prop_p, sum;
1651 int i, rc;
1652
1653 if (--state->ticks != 0)
1654 return;
1655 state->ticks = SLOTS_PID_INTERVAL;
1656
1657 DBG("slots:\n");
1658
1659 /* Check fan status */
1660 rc = get_pwm_fan(SLOTS_FAN_PWM_INDEX);
1661 if (rc < 0) {
1662 printk(KERN_WARNING "Error %d reading slots fan !\n", rc);
1663 /* XXX What do we do now ? */
1664 } else
1665 state->pwm = rc;
1666 DBG(" current pwm: %d\n", state->pwm);
1667
1668 /* Get some sensor readings */
1669 temp = le16_to_cpu(i2c_smbus_read_word_data(state->monitor,
1670 DS1775_TEMP)) << 8;
1671 state->last_temp = temp;
1672 DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp),
1673 FIX32TOPRINT(SLOTS_PID_INPUT_TARGET));
1674
1675 /* Store temperature and error in history array */
1676 state->cur_sample = (state->cur_sample + 1) % SLOTS_PID_HISTORY_SIZE;
1677 state->sample_history[state->cur_sample] = temp;
1678 state->error_history[state->cur_sample] = temp - SLOTS_PID_INPUT_TARGET;
1679
1680 /* If first loop, fill the history table */
1681 if (state->first) {
1682 for (i = 0; i < (SLOTS_PID_HISTORY_SIZE - 1); i++) {
1683 state->cur_sample = (state->cur_sample + 1) %
1684 SLOTS_PID_HISTORY_SIZE;
1685 state->sample_history[state->cur_sample] = temp;
1686 state->error_history[state->cur_sample] =
1687 temp - SLOTS_PID_INPUT_TARGET;
1688 }
1689 state->first = 0;
1690 }
1691
1692 /* Calculate the integral term */
1693 sum = 0;
1694 integral = 0;
1695 for (i = 0; i < SLOTS_PID_HISTORY_SIZE; i++)
1696 integral += state->error_history[i];
1697 integral *= SLOTS_PID_INTERVAL;
1698 DBG(" integral: %08x\n", integral);
1699 integ_p = ((s64)SLOTS_PID_G_r) * (s64)integral;
1700 DBG(" integ_p: %d\n", (int)(integ_p >> 36));
1701 sum += integ_p;
1702
1703 /* Calculate the derivative term */
1704 derivative = state->error_history[state->cur_sample] -
1705 state->error_history[(state->cur_sample + SLOTS_PID_HISTORY_SIZE - 1)
1706 % SLOTS_PID_HISTORY_SIZE];
1707 derivative /= SLOTS_PID_INTERVAL;
1708 deriv_p = ((s64)SLOTS_PID_G_d) * (s64)derivative;
1709 DBG(" deriv_p: %d\n", (int)(deriv_p >> 36));
1710 sum += deriv_p;
1711
1712 /* Calculate the proportional term */
1713 prop_p = ((s64)SLOTS_PID_G_p) * (s64)(state->error_history[state->cur_sample]);
1714 DBG(" prop_p: %d\n", (int)(prop_p >> 36));
1715 sum += prop_p;
1716
1717 /* Scale sum */
1718 sum >>= 36;
1719
1720 DBG(" sum: %d\n", (int)sum);
1721 state->pwm = (s32)sum;
1722
1723 state->pwm = max(state->pwm, SLOTS_PID_OUTPUT_MIN);
1724 state->pwm = min(state->pwm, SLOTS_PID_OUTPUT_MAX);
1725
1726 DBG("** DRIVES PWM: %d\n", (int)state->pwm);
1727 set_pwm_fan(SLOTS_FAN_PWM_INDEX, state->pwm);
1728}
1729
1730/*
1731 * Initialize the state structure for the slots bay fan control loop
1732 */
1733static int init_slots_state(struct slots_pid_state *state)
1734{
1735 state->ticks = 1;
1736 state->first = 1;
1737 state->pwm = 50;
1738
1739 state->monitor = attach_i2c_chip(XSERVE_SLOTS_LM75, "slots_temp");
1740 if (state->monitor == NULL)
1741 return -ENODEV;
1742
1743 device_create_file(&of_dev->dev, &dev_attr_slots_temperature);
1744 device_create_file(&of_dev->dev, &dev_attr_slots_fan_pwm);
1745
1746 return 0;
1747}
1748
1749/*
1750 * Dispose of the state data for the slots control loop
1751 */
1752static void dispose_slots_state(struct slots_pid_state *state)
1753{
1754 if (state->monitor == NULL)
1755 return;
1756
1757 device_remove_file(&of_dev->dev, &dev_attr_slots_temperature);
1758 device_remove_file(&of_dev->dev, &dev_attr_slots_fan_pwm);
1759
1760 detach_i2c_chip(state->monitor);
1761 state->monitor = NULL;
1762}
1763
1764
1591static int call_critical_overtemp(void) 1765static int call_critical_overtemp(void)
1592{ 1766{
1593 char *argv[] = { critical_overtemp_path, NULL }; 1767 char *argv[] = { critical_overtemp_path, NULL };
@@ -1617,14 +1791,17 @@ static int main_control_loop(void *x)
1617 goto out; 1791 goto out;
1618 } 1792 }
1619 1793
1620 /* Set the PCI fan once for now */ 1794 /* Set the PCI fan once for now on non-RackMac */
1621 set_pwm_fan(SLOTS_FAN_PWM_INDEX, SLOTS_FAN_DEFAULT_PWM); 1795 if (!rackmac)
1796 set_pwm_fan(SLOTS_FAN_PWM_INDEX, SLOTS_FAN_DEFAULT_PWM);
1622 1797
1623 /* Initialize ADCs */ 1798 /* Initialize ADCs */
1624 initialize_adc(&cpu_state[0]); 1799 initialize_adc(&cpu_state[0]);
1625 if (cpu_state[1].monitor != NULL) 1800 if (cpu_state[1].monitor != NULL)
1626 initialize_adc(&cpu_state[1]); 1801 initialize_adc(&cpu_state[1]);
1627 1802
1803 fcu_tickle_ticks = FCU_TICKLE_TICKS;
1804
1628 up(&driver_lock); 1805 up(&driver_lock);
1629 1806
1630 while (state == state_attached) { 1807 while (state == state_attached) {
@@ -1634,6 +1811,12 @@ static int main_control_loop(void *x)
1634 1811
1635 down(&driver_lock); 1812 down(&driver_lock);
1636 1813
1814 /* Tickle the FCU just in case */
1815 if (--fcu_tickle_ticks < 0) {
1816 fcu_tickle_ticks = FCU_TICKLE_TICKS;
1817 tickle_fcu();
1818 }
1819
1637 /* First, we always calculate the new DIMMs state on an Xserve */ 1820 /* First, we always calculate the new DIMMs state on an Xserve */
1638 if (rackmac) 1821 if (rackmac)
1639 do_monitor_dimms(&dimms_state); 1822 do_monitor_dimms(&dimms_state);
@@ -1654,7 +1837,9 @@ static int main_control_loop(void *x)
1654 } 1837 }
1655 /* Then, the rest */ 1838 /* Then, the rest */
1656 do_monitor_backside(&backside_state); 1839 do_monitor_backside(&backside_state);
1657 if (!rackmac) 1840 if (rackmac)
1841 do_monitor_slots(&slots_state);
1842 else
1658 do_monitor_drives(&drives_state); 1843 do_monitor_drives(&drives_state);
1659 up(&driver_lock); 1844 up(&driver_lock);
1660 1845
@@ -1696,6 +1881,7 @@ static void dispose_control_loops(void)
1696 dispose_cpu_state(&cpu_state[1]); 1881 dispose_cpu_state(&cpu_state[1]);
1697 dispose_backside_state(&backside_state); 1882 dispose_backside_state(&backside_state);
1698 dispose_drives_state(&drives_state); 1883 dispose_drives_state(&drives_state);
1884 dispose_slots_state(&slots_state);
1699 dispose_dimms_state(&dimms_state); 1885 dispose_dimms_state(&dimms_state);
1700} 1886}
1701 1887
@@ -1745,6 +1931,8 @@ static int create_control_loops(void)
1745 goto fail; 1931 goto fail;
1746 if (rackmac && init_dimms_state(&dimms_state)) 1932 if (rackmac && init_dimms_state(&dimms_state))
1747 goto fail; 1933 goto fail;
1934 if (rackmac && init_slots_state(&slots_state))
1935 goto fail;
1748 if (!rackmac && init_drives_state(&drives_state)) 1936 if (!rackmac && init_drives_state(&drives_state))
1749 goto fail; 1937 goto fail;
1750 1938
diff --git a/drivers/macintosh/therm_pm72.h b/drivers/macintosh/therm_pm72.h
index fc7e9b7ecaf2..393cc9df94e1 100644
--- a/drivers/macintosh/therm_pm72.h
+++ b/drivers/macintosh/therm_pm72.h
@@ -105,6 +105,7 @@ static char * critical_overtemp_path = "/sbin/critical_overtemp";
105#define DRIVES_DALLAS_ID 0x94 105#define DRIVES_DALLAS_ID 0x94
106#define BACKSIDE_MAX_ID 0x98 106#define BACKSIDE_MAX_ID 0x98
107#define XSERVE_DIMMS_LM87 0x25a 107#define XSERVE_DIMMS_LM87 0x25a
108#define XSERVE_SLOTS_LM75 0x290
108 109
109/* 110/*
110 * Some MAX6690, DS1775, LM87 register definitions 111 * Some MAX6690, DS1775, LM87 register definitions
@@ -198,7 +199,7 @@ struct drives_pid_state
198 199
199#define SLOTS_FAN_PWM_DEFAULT_ID 2 200#define SLOTS_FAN_PWM_DEFAULT_ID 2
200#define SLOTS_FAN_PWM_INDEX 2 201#define SLOTS_FAN_PWM_INDEX 2
201#define SLOTS_FAN_DEFAULT_PWM 50 /* Do better here ! */ 202#define SLOTS_FAN_DEFAULT_PWM 40 /* Do better here ! */
202 203
203 204
204/* 205/*
@@ -206,7 +207,7 @@ struct drives_pid_state
206 */ 207 */
207#define DIMM_PID_G_d 0 208#define DIMM_PID_G_d 0
208#define DIMM_PID_G_p 0 209#define DIMM_PID_G_p 0
209#define DIMM_PID_G_r 0x6553600 210#define DIMM_PID_G_r 0x06553600
210#define DIMM_PID_INPUT_TARGET 3276800 211#define DIMM_PID_INPUT_TARGET 3276800
211#define DIMM_PID_INTERVAL 1 212#define DIMM_PID_INTERVAL 1
212#define DIMM_PID_OUTPUT_MAX 14000 213#define DIMM_PID_OUTPUT_MAX 14000
@@ -226,6 +227,31 @@ struct dimm_pid_state
226}; 227};
227 228
228 229
230/*
231 * PID factors for the Xserve Slots control loop
232 */
233#define SLOTS_PID_G_d 0
234#define SLOTS_PID_G_p 0
235#define SLOTS_PID_G_r 0x00100000
236#define SLOTS_PID_INPUT_TARGET 3200000
237#define SLOTS_PID_INTERVAL 1
238#define SLOTS_PID_OUTPUT_MAX 100
239#define SLOTS_PID_OUTPUT_MIN 20
240#define SLOTS_PID_HISTORY_SIZE 20
241
242struct slots_pid_state
243{
244 int ticks;
245 struct i2c_client * monitor;
246 s32 sample_history[SLOTS_PID_HISTORY_SIZE];
247 s32 error_history[SLOTS_PID_HISTORY_SIZE];
248 int cur_sample;
249 s32 last_temp;
250 int first;
251 int pwm;
252};
253
254
229 255
230/* Desktops */ 256/* Desktops */
231 257
@@ -283,6 +309,9 @@ struct cpu_pid_state
283 s32 pump_max; 309 s32 pump_max;
284}; 310};
285 311
312/* Tickle FCU every 10 seconds */
313#define FCU_TICKLE_TICKS 10
314
286/* 315/*
287 * Driver state 316 * Driver state
288 */ 317 */
diff --git a/drivers/macintosh/via-cuda.c b/drivers/macintosh/via-cuda.c
index 6501db50fb83..69d5452fd22f 100644
--- a/drivers/macintosh/via-cuda.c
+++ b/drivers/macintosh/via-cuda.c
@@ -34,13 +34,6 @@
34static volatile unsigned char __iomem *via; 34static volatile unsigned char __iomem *via;
35static DEFINE_SPINLOCK(cuda_lock); 35static DEFINE_SPINLOCK(cuda_lock);
36 36
37#ifdef CONFIG_MAC
38#define CUDA_IRQ IRQ_MAC_ADB
39#define eieio()
40#else
41#define CUDA_IRQ vias->intrs[0].line
42#endif
43
44/* VIA registers - spaced 0x200 bytes apart */ 37/* VIA registers - spaced 0x200 bytes apart */
45#define RS 0x200 /* skip between registers */ 38#define RS 0x200 /* skip between registers */
46#define B 0 /* B-side data */ 39#define B 0 /* B-side data */
@@ -189,11 +182,24 @@ int __init find_via_cuda(void)
189 182
190static int __init via_cuda_start(void) 183static int __init via_cuda_start(void)
191{ 184{
185 unsigned int irq;
186
192 if (via == NULL) 187 if (via == NULL)
193 return -ENODEV; 188 return -ENODEV;
194 189
195 if (request_irq(CUDA_IRQ, cuda_interrupt, 0, "ADB", cuda_interrupt)) { 190#ifdef CONFIG_MAC
196 printk(KERN_ERR "cuda_init: can't get irq %d\n", CUDA_IRQ); 191 irq = IRQ_MAC_ADB;
192#else /* CONFIG_MAC */
193 irq = irq_of_parse_and_map(vias, 0);
194 if (irq == NO_IRQ) {
195 printk(KERN_ERR "via-cuda: can't map interrupts for %s\n",
196 vias->full_name);
197 return -ENODEV;
198 }
199#endif /* CONFIG_MAP */
200
201 if (request_irq(irq, cuda_interrupt, 0, "ADB", cuda_interrupt)) {
202 printk(KERN_ERR "via-cuda: can't request irq %d\n", irq);
197 return -EAGAIN; 203 return -EAGAIN;
198 } 204 }
199 205
diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c
index b42d05f2aaff..a82f313d9dc9 100644
--- a/drivers/macintosh/via-pmu-backlight.c
+++ b/drivers/macintosh/via-pmu-backlight.c
@@ -15,19 +15,51 @@
15 15
16#define MAX_PMU_LEVEL 0xFF 16#define MAX_PMU_LEVEL 0xFF
17 17
18static struct device_node *vias;
19static struct backlight_properties pmu_backlight_data; 18static struct backlight_properties pmu_backlight_data;
19static spinlock_t pmu_backlight_lock;
20static int sleeping;
21static u8 bl_curve[FB_BACKLIGHT_LEVELS];
20 22
21static int pmu_backlight_get_level_brightness(struct fb_info *info, 23static void pmu_backlight_init_curve(u8 off, u8 min, u8 max)
22 int level) 24{
25 unsigned int i, flat, count, range = (max - min);
26
27 bl_curve[0] = off;
28
29 for (flat = 1; flat < (FB_BACKLIGHT_LEVELS / 16); ++flat)
30 bl_curve[flat] = min;
31
32 count = FB_BACKLIGHT_LEVELS * 15 / 16;
33 for (i = 0; i < count; ++i)
34 bl_curve[flat + i] = min + (range * (i + 1) / count);
35}
36
37static int pmu_backlight_curve_lookup(int value)
38{
39 int level = (FB_BACKLIGHT_LEVELS - 1);
40 int i, max = 0;
41
42 /* Look for biggest value */
43 for (i = 0; i < FB_BACKLIGHT_LEVELS; i++)
44 max = max((int)bl_curve[i], max);
45
46 /* Look for nearest value */
47 for (i = 0; i < FB_BACKLIGHT_LEVELS; i++) {
48 int diff = abs(bl_curve[i] - value);
49 if (diff < max) {
50 max = diff;
51 level = i;
52 }
53 }
54 return level;
55}
56
57static int pmu_backlight_get_level_brightness(int level)
23{ 58{
24 int pmulevel; 59 int pmulevel;
25 60
26 /* Get and convert the value */ 61 /* Get and convert the value */
27 mutex_lock(&info->bl_mutex); 62 pmulevel = bl_curve[level] * FB_BACKLIGHT_MAX / MAX_PMU_LEVEL;
28 pmulevel = info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_PMU_LEVEL;
29 mutex_unlock(&info->bl_mutex);
30
31 if (pmulevel < 0) 63 if (pmulevel < 0)
32 pmulevel = 0; 64 pmulevel = 0;
33 else if (pmulevel > MAX_PMU_LEVEL) 65 else if (pmulevel > MAX_PMU_LEVEL)
@@ -38,25 +70,37 @@ static int pmu_backlight_get_level_brightness(struct fb_info *info,
38 70
39static int pmu_backlight_update_status(struct backlight_device *bd) 71static int pmu_backlight_update_status(struct backlight_device *bd)
40{ 72{
41 struct fb_info *info = class_get_devdata(&bd->class_dev);
42 struct adb_request req; 73 struct adb_request req;
43 int pmulevel, level = bd->props->brightness; 74 unsigned long flags;
75 int level = bd->props->brightness;
76
77 spin_lock_irqsave(&pmu_backlight_lock, flags);
44 78
45 if (vias == NULL) 79 /* Don't update brightness when sleeping */
46 return -ENODEV; 80 if (sleeping)
81 goto out;
47 82
48 if (bd->props->power != FB_BLANK_UNBLANK || 83 if (bd->props->power != FB_BLANK_UNBLANK ||
49 bd->props->fb_blank != FB_BLANK_UNBLANK) 84 bd->props->fb_blank != FB_BLANK_UNBLANK)
50 level = 0; 85 level = 0;
51 86
52 pmulevel = pmu_backlight_get_level_brightness(info, level); 87 if (level > 0) {
88 int pmulevel = pmu_backlight_get_level_brightness(level);
53 89
54 pmu_request(&req, NULL, 2, PMU_BACKLIGHT_BRIGHT, pmulevel); 90 pmu_request(&req, NULL, 2, PMU_BACKLIGHT_BRIGHT, pmulevel);
55 pmu_wait_complete(&req); 91 pmu_wait_complete(&req);
92
93 pmu_request(&req, NULL, 2, PMU_POWER_CTRL,
94 PMU_POW_BACKLIGHT | PMU_POW_ON);
95 pmu_wait_complete(&req);
96 } else {
97 pmu_request(&req, NULL, 2, PMU_POWER_CTRL,
98 PMU_POW_BACKLIGHT | PMU_POW_OFF);
99 pmu_wait_complete(&req);
100 }
56 101
57 pmu_request(&req, NULL, 2, PMU_POWER_CTRL, 102out:
58 PMU_POW_BACKLIGHT | (level > 0 ? PMU_POW_ON : PMU_POW_OFF)); 103 spin_unlock_irqrestore(&pmu_backlight_lock, flags);
59 pmu_wait_complete(&req);
60 104
61 return 0; 105 return 0;
62} 106}
@@ -73,15 +117,23 @@ static struct backlight_properties pmu_backlight_data = {
73 .max_brightness = (FB_BACKLIGHT_LEVELS - 1), 117 .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
74}; 118};
75 119
76void __init pmu_backlight_init(struct device_node *in_vias) 120#ifdef CONFIG_PM
121void pmu_backlight_set_sleep(int sleep)
122{
123 unsigned long flags;
124
125 spin_lock_irqsave(&pmu_backlight_lock, flags);
126 sleeping = sleep;
127 spin_unlock_irqrestore(&pmu_backlight_lock, flags);
128}
129#endif /* CONFIG_PM */
130
131void __init pmu_backlight_init()
77{ 132{
78 struct backlight_device *bd; 133 struct backlight_device *bd;
79 struct fb_info *info;
80 char name[10]; 134 char name[10];
81 int level, autosave; 135 int level, autosave;
82 136
83 vias = in_vias;
84
85 /* Special case for the old PowerBook since I can't test on it */ 137 /* Special case for the old PowerBook since I can't test on it */
86 autosave = 138 autosave =
87 machine_is_compatible("AAPL,3400/2400") || 139 machine_is_compatible("AAPL,3400/2400") ||
@@ -93,27 +145,14 @@ void __init pmu_backlight_init(struct device_node *in_vias)
93 !machine_is_compatible("PowerBook1,1")) 145 !machine_is_compatible("PowerBook1,1"))
94 return; 146 return;
95 147
96 /* Actually, this is a hack, but I don't know of a better way 148 snprintf(name, sizeof(name), "pmubl");
97 * to get the first framebuffer device.
98 */
99 info = registered_fb[0];
100 if (!info) {
101 printk("pmubl: No framebuffer found\n");
102 goto error;
103 }
104
105 snprintf(name, sizeof(name), "pmubl%d", info->node);
106 149
107 bd = backlight_device_register(name, info, &pmu_backlight_data); 150 bd = backlight_device_register(name, NULL, &pmu_backlight_data);
108 if (IS_ERR(bd)) { 151 if (IS_ERR(bd)) {
109 printk("pmubl: Backlight registration failed\n"); 152 printk("pmubl: Backlight registration failed\n");
110 goto error; 153 goto error;
111 } 154 }
112 155 pmu_backlight_init_curve(0x7F, 0x46, 0x0E);
113 mutex_lock(&info->bl_mutex);
114 info->bl_dev = bd;
115 fb_bl_default_curve(info, 0x7F, 0x46, 0x0E);
116 mutex_unlock(&info->bl_mutex);
117 156
118 level = pmu_backlight_data.max_brightness; 157 level = pmu_backlight_data.max_brightness;
119 158
@@ -123,18 +162,16 @@ void __init pmu_backlight_init(struct device_node *in_vias)
123 pmu_request(&req, NULL, 2, 0xd9, 0); 162 pmu_request(&req, NULL, 2, 0xd9, 0);
124 pmu_wait_complete(&req); 163 pmu_wait_complete(&req);
125 164
126 mutex_lock(&info->bl_mutex); 165 level = pmu_backlight_curve_lookup(
127 level = pmac_backlight_curve_lookup(info,
128 (req.reply[0] >> 4) * 166 (req.reply[0] >> 4) *
129 pmu_backlight_data.max_brightness / 15); 167 pmu_backlight_data.max_brightness / 15);
130 mutex_unlock(&info->bl_mutex);
131 } 168 }
132 169
133 up(&bd->sem); 170 down(&bd->sem);
134 bd->props->brightness = level; 171 bd->props->brightness = level;
135 bd->props->power = FB_BLANK_UNBLANK; 172 bd->props->power = FB_BLANK_UNBLANK;
136 bd->props->update_status(bd); 173 bd->props->update_status(bd);
137 down(&bd->sem); 174 up(&bd->sem);
138 175
139 mutex_lock(&pmac_backlight_mutex); 176 mutex_lock(&pmac_backlight_mutex);
140 if (!pmac_backlight) 177 if (!pmac_backlight)
diff --git a/drivers/macintosh/via-pmu-led.c b/drivers/macintosh/via-pmu-led.c
index af8375ed0f5e..5189d5454b1f 100644
--- a/drivers/macintosh/via-pmu-led.c
+++ b/drivers/macintosh/via-pmu-led.c
@@ -74,7 +74,7 @@ static void pmu_led_set(struct led_classdev *led_cdev,
74 74
75static struct led_classdev pmu_led = { 75static struct led_classdev pmu_led = {
76 .name = "pmu-front-led", 76 .name = "pmu-front-led",
77#ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK 77#ifdef CONFIG_ADB_PMU_LED_IDE
78 .default_trigger = "ide-disk", 78 .default_trigger = "ide-disk",
79#endif 79#endif
80 .brightness_set = pmu_led_set, 80 .brightness_set = pmu_led_set,
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index c1193d34ec9e..14610a63f580 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -16,7 +16,6 @@
16 * a sleep or a freq. switch 16 * a sleep or a freq. switch
17 * - Move sleep code out of here to pmac_pm, merge into new 17 * - Move sleep code out of here to pmac_pm, merge into new
18 * common PM infrastructure 18 * common PM infrastructure
19 * - Move backlight code out as well
20 * - Save/Restore PCI space properly 19 * - Save/Restore PCI space properly
21 * 20 *
22 */ 21 */
@@ -60,13 +59,7 @@
60#include <asm/mmu_context.h> 59#include <asm/mmu_context.h>
61#include <asm/cputable.h> 60#include <asm/cputable.h>
62#include <asm/time.h> 61#include <asm/time.h>
63#ifdef CONFIG_PMAC_BACKLIGHT
64#include <asm/backlight.h> 62#include <asm/backlight.h>
65#endif
66
67#ifdef CONFIG_PPC32
68#include <asm/open_pic.h>
69#endif
70 63
71#include "via-pmu-event.h" 64#include "via-pmu-event.h"
72 65
@@ -151,7 +144,7 @@ static int pmu_fully_inited = 0;
151static int pmu_has_adb; 144static int pmu_has_adb;
152static struct device_node *gpio_node; 145static struct device_node *gpio_node;
153static unsigned char __iomem *gpio_reg = NULL; 146static unsigned char __iomem *gpio_reg = NULL;
154static int gpio_irq = -1; 147static int gpio_irq = NO_IRQ;
155static int gpio_irq_enabled = -1; 148static int gpio_irq_enabled = -1;
156static volatile int pmu_suspended = 0; 149static volatile int pmu_suspended = 0;
157static spinlock_t pmu_lock; 150static spinlock_t pmu_lock;
@@ -181,10 +174,6 @@ static int query_batt_timer = BATTERY_POLLING_COUNT;
181static struct adb_request batt_req; 174static struct adb_request batt_req;
182static struct proc_dir_entry *proc_pmu_batt[PMU_MAX_BATTERIES]; 175static struct proc_dir_entry *proc_pmu_batt[PMU_MAX_BATTERIES];
183 176
184#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
185extern int disable_kernel_backlight;
186#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */
187
188int __fake_sleep; 177int __fake_sleep;
189int asleep; 178int asleep;
190BLOCKING_NOTIFIER_HEAD(sleep_notifier_list); 179BLOCKING_NOTIFIER_HEAD(sleep_notifier_list);
@@ -403,22 +392,21 @@ static int __init pmu_init(void)
403 */ 392 */
404static int __init via_pmu_start(void) 393static int __init via_pmu_start(void)
405{ 394{
395 unsigned int irq;
396
406 if (vias == NULL) 397 if (vias == NULL)
407 return -ENODEV; 398 return -ENODEV;
408 399
409 batt_req.complete = 1; 400 batt_req.complete = 1;
410 401
411#ifndef CONFIG_PPC_MERGE 402 irq = irq_of_parse_and_map(vias, 0);
412 if (pmu_kind == PMU_KEYLARGO_BASED) 403 if (irq == NO_IRQ) {
413 openpic_set_irq_priority(vias->intrs[0].line, 404 printk(KERN_ERR "via-pmu: can't map interruptn");
414 OPENPIC_PRIORITY_DEFAULT + 1); 405 return -ENODEV;
415#endif 406 }
416 407 if (request_irq(irq, via_pmu_interrupt, 0, "VIA-PMU", (void *)0)) {
417 if (request_irq(vias->intrs[0].line, via_pmu_interrupt, 0, "VIA-PMU", 408 printk(KERN_ERR "via-pmu: can't request irq %d\n", irq);
418 (void *)0)) { 409 return -ENODEV;
419 printk(KERN_ERR "VIA-PMU: can't get irq %d\n",
420 vias->intrs[0].line);
421 return -EAGAIN;
422 } 410 }
423 411
424 if (pmu_kind == PMU_KEYLARGO_BASED) { 412 if (pmu_kind == PMU_KEYLARGO_BASED) {
@@ -426,10 +414,10 @@ static int __init via_pmu_start(void)
426 if (gpio_node == NULL) 414 if (gpio_node == NULL)
427 gpio_node = of_find_node_by_name(NULL, 415 gpio_node = of_find_node_by_name(NULL,
428 "pmu-interrupt"); 416 "pmu-interrupt");
429 if (gpio_node && gpio_node->n_intrs > 0) 417 if (gpio_node)
430 gpio_irq = gpio_node->intrs[0].line; 418 gpio_irq = irq_of_parse_and_map(gpio_node, 0);
431 419
432 if (gpio_irq != -1) { 420 if (gpio_irq != NO_IRQ) {
433 if (request_irq(gpio_irq, gpio1_interrupt, 0, 421 if (request_irq(gpio_irq, gpio1_interrupt, 0,
434 "GPIO1 ADB", (void *)0)) 422 "GPIO1 ADB", (void *)0))
435 printk(KERN_ERR "pmu: can't get irq %d" 423 printk(KERN_ERR "pmu: can't get irq %d"
@@ -471,7 +459,7 @@ static int __init via_pmu_dev_init(void)
471 459
472#ifdef CONFIG_PMAC_BACKLIGHT 460#ifdef CONFIG_PMAC_BACKLIGHT
473 /* Initialize backlight */ 461 /* Initialize backlight */
474 pmu_backlight_init(vias); 462 pmu_backlight_init();
475#endif 463#endif
476 464
477#ifdef CONFIG_PPC32 465#ifdef CONFIG_PPC32
@@ -1408,11 +1396,8 @@ next:
1408 else if ((1 << pirq) & PMU_INT_SNDBRT) { 1396 else if ((1 << pirq) & PMU_INT_SNDBRT) {
1409#ifdef CONFIG_PMAC_BACKLIGHT 1397#ifdef CONFIG_PMAC_BACKLIGHT
1410 if (len == 3) 1398 if (len == 3)
1411#ifdef CONFIG_INPUT_ADBHID 1399 pmac_backlight_set_legacy_brightness_pmu(data[1] >> 4);
1412 if (!disable_kernel_backlight) 1400#endif
1413#endif /* CONFIG_INPUT_ADBHID */
1414 pmac_backlight_set_legacy_brightness(data[1] >> 4);
1415#endif /* CONFIG_PMAC_BACKLIGHT */
1416 } 1401 }
1417 /* Tick interrupt */ 1402 /* Tick interrupt */
1418 else if ((1 << pirq) & PMU_INT_TICK) { 1403 else if ((1 << pirq) & PMU_INT_TICK) {
@@ -2010,6 +1995,8 @@ restore_via_state(void)
2010 out_8(&via[IER], IER_SET | SR_INT | CB1_INT); 1995 out_8(&via[IER], IER_SET | SR_INT | CB1_INT);
2011} 1996}
2012 1997
1998extern void pmu_backlight_set_sleep(int sleep);
1999
2013static int 2000static int
2014pmac_suspend_devices(void) 2001pmac_suspend_devices(void)
2015{ 2002{
@@ -2047,6 +2034,11 @@ pmac_suspend_devices(void)
2047 return -EBUSY; 2034 return -EBUSY;
2048 } 2035 }
2049 2036
2037#ifdef CONFIG_PMAC_BACKLIGHT
2038 /* Tell backlight code not to muck around with the chip anymore */
2039 pmu_backlight_set_sleep(1);
2040#endif
2041
2050 /* Call platform functions marked "on sleep" */ 2042 /* Call platform functions marked "on sleep" */
2051 pmac_pfunc_i2c_suspend(); 2043 pmac_pfunc_i2c_suspend();
2052 pmac_pfunc_base_suspend(); 2044 pmac_pfunc_base_suspend();
@@ -2105,6 +2097,11 @@ pmac_wakeup_devices(void)
2105{ 2097{
2106 mdelay(100); 2098 mdelay(100);
2107 2099
2100#ifdef CONFIG_PMAC_BACKLIGHT
2101 /* Tell backlight code it can use the chip again */
2102 pmu_backlight_set_sleep(0);
2103#endif
2104
2108 /* Power back up system devices (including the PIC) */ 2105 /* Power back up system devices (including the PIC) */
2109 device_power_up(); 2106 device_power_up();
2110 2107
@@ -2419,7 +2416,7 @@ struct pmu_private {
2419 spinlock_t lock; 2416 spinlock_t lock;
2420#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) 2417#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
2421 int backlight_locker; 2418 int backlight_locker;
2422#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */ 2419#endif
2423}; 2420};
2424 2421
2425static LIST_HEAD(all_pmu_pvt); 2422static LIST_HEAD(all_pmu_pvt);
@@ -2469,7 +2466,7 @@ pmu_open(struct inode *inode, struct file *file)
2469 spin_lock_irqsave(&all_pvt_lock, flags); 2466 spin_lock_irqsave(&all_pvt_lock, flags);
2470#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) 2467#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
2471 pp->backlight_locker = 0; 2468 pp->backlight_locker = 0;
2472#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */ 2469#endif
2473 list_add(&pp->list, &all_pmu_pvt); 2470 list_add(&pp->list, &all_pmu_pvt);
2474 spin_unlock_irqrestore(&all_pvt_lock, flags); 2471 spin_unlock_irqrestore(&all_pvt_lock, flags);
2475 file->private_data = pp; 2472 file->private_data = pp;
@@ -2564,13 +2561,12 @@ pmu_release(struct inode *inode, struct file *file)
2564 spin_lock_irqsave(&all_pvt_lock, flags); 2561 spin_lock_irqsave(&all_pvt_lock, flags);
2565 list_del(&pp->list); 2562 list_del(&pp->list);
2566 spin_unlock_irqrestore(&all_pvt_lock, flags); 2563 spin_unlock_irqrestore(&all_pvt_lock, flags);
2564
2567#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) 2565#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
2568 if (pp->backlight_locker) { 2566 if (pp->backlight_locker)
2569 spin_lock_irqsave(&pmu_lock, flags); 2567 pmac_backlight_enable();
2570 disable_kernel_backlight--; 2568#endif
2571 spin_unlock_irqrestore(&pmu_lock, flags); 2569
2572 }
2573#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */
2574 kfree(pp); 2570 kfree(pp);
2575 } 2571 }
2576 unlock_kernel(); 2572 unlock_kernel();
@@ -2647,18 +2643,18 @@ pmu_ioctl(struct inode * inode, struct file *filp,
2647#ifdef CONFIG_INPUT_ADBHID 2643#ifdef CONFIG_INPUT_ADBHID
2648 case PMU_IOC_GRAB_BACKLIGHT: { 2644 case PMU_IOC_GRAB_BACKLIGHT: {
2649 struct pmu_private *pp = filp->private_data; 2645 struct pmu_private *pp = filp->private_data;
2650 unsigned long flags;
2651 2646
2652 if (pp->backlight_locker) 2647 if (pp->backlight_locker)
2653 return 0; 2648 return 0;
2649
2654 pp->backlight_locker = 1; 2650 pp->backlight_locker = 1;
2655 spin_lock_irqsave(&pmu_lock, flags); 2651 pmac_backlight_disable();
2656 disable_kernel_backlight++; 2652
2657 spin_unlock_irqrestore(&pmu_lock, flags);
2658 return 0; 2653 return 0;
2659 } 2654 }
2660#endif /* CONFIG_INPUT_ADBHID */ 2655#endif /* CONFIG_INPUT_ADBHID */
2661#endif /* CONFIG_PMAC_BACKLIGHT_LEGACY */ 2656#endif /* CONFIG_PMAC_BACKLIGHT_LEGACY */
2657
2662 case PMU_IOC_GET_MODEL: 2658 case PMU_IOC_GET_MODEL:
2663 return put_user(pmu_kind, argp); 2659 return put_user(pmu_kind, argp);
2664 case PMU_IOC_HAS_ADB: 2660 case PMU_IOC_HAS_ADB:
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 217615b33223..93f701ea87bc 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -710,6 +710,8 @@ static int multipath_ctr(struct dm_target *ti, unsigned int argc,
710 return -EINVAL; 710 return -EINVAL;
711 } 711 }
712 712
713 m->ti = ti;
714
713 r = parse_features(&as, m, ti); 715 r = parse_features(&as, m, ti);
714 if (r) 716 if (r)
715 goto bad; 717 goto bad;
@@ -751,7 +753,6 @@ static int multipath_ctr(struct dm_target *ti, unsigned int argc,
751 } 753 }
752 754
753 ti->private = m; 755 ti->private = m;
754 m->ti = ti;
755 756
756 return 0; 757 return 0;
757 758
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index be48cedf986b..c54de989eb00 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -255,7 +255,9 @@ static struct region *__rh_alloc(struct region_hash *rh, region_t region)
255 struct region *reg, *nreg; 255 struct region *reg, *nreg;
256 256
257 read_unlock(&rh->hash_lock); 257 read_unlock(&rh->hash_lock);
258 nreg = mempool_alloc(rh->region_pool, GFP_NOIO); 258 nreg = mempool_alloc(rh->region_pool, GFP_ATOMIC);
259 if (unlikely(!nreg))
260 nreg = kmalloc(sizeof(struct region), GFP_NOIO);
259 nreg->state = rh->log->type->in_sync(rh->log, region, 1) ? 261 nreg->state = rh->log->type->in_sync(rh->log, region, 1) ?
260 RH_CLEAN : RH_NOSYNC; 262 RH_CLEAN : RH_NOSYNC;
261 nreg->rh = rh; 263 nreg->rh = rh;
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index ff83c9b5979e..b99c19c7eb22 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -162,7 +162,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
162 goto out; 162 goto out;
163 } 163 }
164 164
165 min_spacing = mddev->array_size; 165 min_spacing = conf->array_size;
166 sector_div(min_spacing, PAGE_SIZE/sizeof(struct dev_info *)); 166 sector_div(min_spacing, PAGE_SIZE/sizeof(struct dev_info *));
167 167
168 /* min_spacing is the minimum spacing that will fit the hash 168 /* min_spacing is the minimum spacing that will fit the hash
@@ -171,7 +171,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
171 * that is larger than min_spacing as use the size of that as 171 * that is larger than min_spacing as use the size of that as
172 * the actual spacing 172 * the actual spacing
173 */ 173 */
174 conf->hash_spacing = mddev->array_size; 174 conf->hash_spacing = conf->array_size;
175 for (i=0; i < cnt-1 ; i++) { 175 for (i=0; i < cnt-1 ; i++) {
176 sector_t sz = 0; 176 sector_t sz = 0;
177 int j; 177 int j;
@@ -228,7 +228,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
228 curr_offset = 0; 228 curr_offset = 0;
229 i = 0; 229 i = 0;
230 for (curr_offset = 0; 230 for (curr_offset = 0;
231 curr_offset < mddev->array_size; 231 curr_offset < conf->array_size;
232 curr_offset += conf->hash_spacing) { 232 curr_offset += conf->hash_spacing) {
233 233
234 while (i < mddev->raid_disks-1 && 234 while (i < mddev->raid_disks-1 &&
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 2fe32c261922..8dbab2ef3885 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -110,7 +110,7 @@ static ctl_table raid_table[] = {
110 .procname = "speed_limit_min", 110 .procname = "speed_limit_min",
111 .data = &sysctl_speed_limit_min, 111 .data = &sysctl_speed_limit_min,
112 .maxlen = sizeof(int), 112 .maxlen = sizeof(int),
113 .mode = 0644, 113 .mode = S_IRUGO|S_IWUSR,
114 .proc_handler = &proc_dointvec, 114 .proc_handler = &proc_dointvec,
115 }, 115 },
116 { 116 {
@@ -118,7 +118,7 @@ static ctl_table raid_table[] = {
118 .procname = "speed_limit_max", 118 .procname = "speed_limit_max",
119 .data = &sysctl_speed_limit_max, 119 .data = &sysctl_speed_limit_max,
120 .maxlen = sizeof(int), 120 .maxlen = sizeof(int),
121 .mode = 0644, 121 .mode = S_IRUGO|S_IWUSR,
122 .proc_handler = &proc_dointvec, 122 .proc_handler = &proc_dointvec,
123 }, 123 },
124 { .ctl_name = 0 } 124 { .ctl_name = 0 }
@@ -129,7 +129,7 @@ static ctl_table raid_dir_table[] = {
129 .ctl_name = DEV_RAID, 129 .ctl_name = DEV_RAID,
130 .procname = "raid", 130 .procname = "raid",
131 .maxlen = 0, 131 .maxlen = 0,
132 .mode = 0555, 132 .mode = S_IRUGO|S_IXUGO,
133 .child = raid_table, 133 .child = raid_table,
134 }, 134 },
135 { .ctl_name = 0 } 135 { .ctl_name = 0 }
@@ -1062,6 +1062,11 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1062 if (rdev->sb_size & bmask) 1062 if (rdev->sb_size & bmask)
1063 rdev-> sb_size = (rdev->sb_size | bmask)+1; 1063 rdev-> sb_size = (rdev->sb_size | bmask)+1;
1064 1064
1065 if (sb->level == cpu_to_le32(LEVEL_MULTIPATH))
1066 rdev->desc_nr = -1;
1067 else
1068 rdev->desc_nr = le32_to_cpu(sb->dev_number);
1069
1065 if (refdev == 0) 1070 if (refdev == 0)
1066 ret = 1; 1071 ret = 1;
1067 else { 1072 else {
@@ -1171,7 +1176,6 @@ static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev)
1171 } 1176 }
1172 if (mddev->level != LEVEL_MULTIPATH) { 1177 if (mddev->level != LEVEL_MULTIPATH) {
1173 int role; 1178 int role;
1174 rdev->desc_nr = le32_to_cpu(sb->dev_number);
1175 role = le16_to_cpu(sb->dev_roles[rdev->desc_nr]); 1179 role = le16_to_cpu(sb->dev_roles[rdev->desc_nr]);
1176 switch(role) { 1180 switch(role) {
1177 case 0xffff: /* spare */ 1181 case 0xffff: /* spare */
@@ -1404,7 +1408,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev)
1404 struct block_device *bdev; 1408 struct block_device *bdev;
1405 char b[BDEVNAME_SIZE]; 1409 char b[BDEVNAME_SIZE];
1406 1410
1407 bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); 1411 bdev = open_partition_by_devnum(dev, FMODE_READ|FMODE_WRITE);
1408 if (IS_ERR(bdev)) { 1412 if (IS_ERR(bdev)) {
1409 printk(KERN_ERR "md: could not open %s.\n", 1413 printk(KERN_ERR "md: could not open %s.\n",
1410 __bdevname(dev, b)); 1414 __bdevname(dev, b));
@@ -1414,7 +1418,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev)
1414 if (err) { 1418 if (err) {
1415 printk(KERN_ERR "md: could not bd_claim %s.\n", 1419 printk(KERN_ERR "md: could not bd_claim %s.\n",
1416 bdevname(bdev, b)); 1420 bdevname(bdev, b));
1417 blkdev_put(bdev); 1421 blkdev_put_partition(bdev);
1418 return err; 1422 return err;
1419 } 1423 }
1420 rdev->bdev = bdev; 1424 rdev->bdev = bdev;
@@ -1428,7 +1432,7 @@ static void unlock_rdev(mdk_rdev_t *rdev)
1428 if (!bdev) 1432 if (!bdev)
1429 MD_BUG(); 1433 MD_BUG();
1430 bd_release(bdev); 1434 bd_release(bdev);
1431 blkdev_put(bdev); 1435 blkdev_put_partition(bdev);
1432} 1436}
1433 1437
1434void md_autodetect_dev(dev_t dev); 1438void md_autodetect_dev(dev_t dev);
@@ -1593,6 +1597,19 @@ void md_update_sb(mddev_t * mddev)
1593 1597
1594repeat: 1598repeat:
1595 spin_lock_irq(&mddev->write_lock); 1599 spin_lock_irq(&mddev->write_lock);
1600
1601 if (mddev->degraded && mddev->sb_dirty == 3)
1602 /* If the array is degraded, then skipping spares is both
1603 * dangerous and fairly pointless.
1604 * Dangerous because a device that was removed from the array
1605 * might have a event_count that still looks up-to-date,
1606 * so it can be re-added without a resync.
1607 * Pointless because if there are any spares to skip,
1608 * then a recovery will happen and soon that array won't
1609 * be degraded any more and the spare can go back to sleep then.
1610 */
1611 mddev->sb_dirty = 1;
1612
1596 sync_req = mddev->in_sync; 1613 sync_req = mddev->in_sync;
1597 mddev->utime = get_seconds(); 1614 mddev->utime = get_seconds();
1598 if (mddev->sb_dirty == 3) 1615 if (mddev->sb_dirty == 3)
@@ -1779,8 +1796,8 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1779 } 1796 }
1780 return err ? err : len; 1797 return err ? err : len;
1781} 1798}
1782static struct rdev_sysfs_entry 1799static struct rdev_sysfs_entry rdev_state =
1783rdev_state = __ATTR(state, 0644, state_show, state_store); 1800__ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
1784 1801
1785static ssize_t 1802static ssize_t
1786super_show(mdk_rdev_t *rdev, char *page) 1803super_show(mdk_rdev_t *rdev, char *page)
@@ -1811,7 +1828,7 @@ errors_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1811 return -EINVAL; 1828 return -EINVAL;
1812} 1829}
1813static struct rdev_sysfs_entry rdev_errors = 1830static struct rdev_sysfs_entry rdev_errors =
1814__ATTR(errors, 0644, errors_show, errors_store); 1831__ATTR(errors, S_IRUGO|S_IWUSR, errors_show, errors_store);
1815 1832
1816static ssize_t 1833static ssize_t
1817slot_show(mdk_rdev_t *rdev, char *page) 1834slot_show(mdk_rdev_t *rdev, char *page)
@@ -1845,7 +1862,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1845 1862
1846 1863
1847static struct rdev_sysfs_entry rdev_slot = 1864static struct rdev_sysfs_entry rdev_slot =
1848__ATTR(slot, 0644, slot_show, slot_store); 1865__ATTR(slot, S_IRUGO|S_IWUSR, slot_show, slot_store);
1849 1866
1850static ssize_t 1867static ssize_t
1851offset_show(mdk_rdev_t *rdev, char *page) 1868offset_show(mdk_rdev_t *rdev, char *page)
@@ -1867,7 +1884,7 @@ offset_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1867} 1884}
1868 1885
1869static struct rdev_sysfs_entry rdev_offset = 1886static struct rdev_sysfs_entry rdev_offset =
1870__ATTR(offset, 0644, offset_show, offset_store); 1887__ATTR(offset, S_IRUGO|S_IWUSR, offset_show, offset_store);
1871 1888
1872static ssize_t 1889static ssize_t
1873rdev_size_show(mdk_rdev_t *rdev, char *page) 1890rdev_size_show(mdk_rdev_t *rdev, char *page)
@@ -1891,7 +1908,7 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1891} 1908}
1892 1909
1893static struct rdev_sysfs_entry rdev_size = 1910static struct rdev_sysfs_entry rdev_size =
1894__ATTR(size, 0644, rdev_size_show, rdev_size_store); 1911__ATTR(size, S_IRUGO|S_IWUSR, rdev_size_show, rdev_size_store);
1895 1912
1896static struct attribute *rdev_default_attrs[] = { 1913static struct attribute *rdev_default_attrs[] = {
1897 &rdev_state.attr, 1914 &rdev_state.attr,
@@ -1922,6 +1939,8 @@ rdev_attr_store(struct kobject *kobj, struct attribute *attr,
1922 1939
1923 if (!entry->store) 1940 if (!entry->store)
1924 return -EIO; 1941 return -EIO;
1942 if (!capable(CAP_SYS_ADMIN))
1943 return -EACCES;
1925 return entry->store(rdev, page, length); 1944 return entry->store(rdev, page, length);
1926} 1945}
1927 1946
@@ -2128,7 +2147,7 @@ safe_delay_store(mddev_t *mddev, const char *cbuf, size_t len)
2128 return len; 2147 return len;
2129} 2148}
2130static struct md_sysfs_entry md_safe_delay = 2149static struct md_sysfs_entry md_safe_delay =
2131__ATTR(safe_mode_delay, 0644,safe_delay_show, safe_delay_store); 2150__ATTR(safe_mode_delay, S_IRUGO|S_IWUSR,safe_delay_show, safe_delay_store);
2132 2151
2133static ssize_t 2152static ssize_t
2134level_show(mddev_t *mddev, char *page) 2153level_show(mddev_t *mddev, char *page)
@@ -2163,7 +2182,7 @@ level_store(mddev_t *mddev, const char *buf, size_t len)
2163} 2182}
2164 2183
2165static struct md_sysfs_entry md_level = 2184static struct md_sysfs_entry md_level =
2166__ATTR(level, 0644, level_show, level_store); 2185__ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store);
2167 2186
2168 2187
2169static ssize_t 2188static ssize_t
@@ -2188,7 +2207,7 @@ layout_store(mddev_t *mddev, const char *buf, size_t len)
2188 return len; 2207 return len;
2189} 2208}
2190static struct md_sysfs_entry md_layout = 2209static struct md_sysfs_entry md_layout =
2191__ATTR(layout, 0655, layout_show, layout_store); 2210__ATTR(layout, S_IRUGO|S_IWUSR, layout_show, layout_store);
2192 2211
2193 2212
2194static ssize_t 2213static ssize_t
@@ -2219,7 +2238,7 @@ raid_disks_store(mddev_t *mddev, const char *buf, size_t len)
2219 return rv ? rv : len; 2238 return rv ? rv : len;
2220} 2239}
2221static struct md_sysfs_entry md_raid_disks = 2240static struct md_sysfs_entry md_raid_disks =
2222__ATTR(raid_disks, 0644, raid_disks_show, raid_disks_store); 2241__ATTR(raid_disks, S_IRUGO|S_IWUSR, raid_disks_show, raid_disks_store);
2223 2242
2224static ssize_t 2243static ssize_t
2225chunk_size_show(mddev_t *mddev, char *page) 2244chunk_size_show(mddev_t *mddev, char *page)
@@ -2243,7 +2262,7 @@ chunk_size_store(mddev_t *mddev, const char *buf, size_t len)
2243 return len; 2262 return len;
2244} 2263}
2245static struct md_sysfs_entry md_chunk_size = 2264static struct md_sysfs_entry md_chunk_size =
2246__ATTR(chunk_size, 0644, chunk_size_show, chunk_size_store); 2265__ATTR(chunk_size, S_IRUGO|S_IWUSR, chunk_size_show, chunk_size_store);
2247 2266
2248static ssize_t 2267static ssize_t
2249resync_start_show(mddev_t *mddev, char *page) 2268resync_start_show(mddev_t *mddev, char *page)
@@ -2267,7 +2286,7 @@ resync_start_store(mddev_t *mddev, const char *buf, size_t len)
2267 return len; 2286 return len;
2268} 2287}
2269static struct md_sysfs_entry md_resync_start = 2288static struct md_sysfs_entry md_resync_start =
2270__ATTR(resync_start, 0644, resync_start_show, resync_start_store); 2289__ATTR(resync_start, S_IRUGO|S_IWUSR, resync_start_show, resync_start_store);
2271 2290
2272/* 2291/*
2273 * The array state can be: 2292 * The array state can be:
@@ -2437,7 +2456,8 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
2437 else 2456 else
2438 return len; 2457 return len;
2439} 2458}
2440static struct md_sysfs_entry md_array_state = __ATTR(array_state, 0644, array_state_show, array_state_store); 2459static struct md_sysfs_entry md_array_state =
2460__ATTR(array_state, S_IRUGO|S_IWUSR, array_state_show, array_state_store);
2441 2461
2442static ssize_t 2462static ssize_t
2443null_show(mddev_t *mddev, char *page) 2463null_show(mddev_t *mddev, char *page)
@@ -2497,7 +2517,7 @@ new_dev_store(mddev_t *mddev, const char *buf, size_t len)
2497} 2517}
2498 2518
2499static struct md_sysfs_entry md_new_device = 2519static struct md_sysfs_entry md_new_device =
2500__ATTR(new_dev, 0200, null_show, new_dev_store); 2520__ATTR(new_dev, S_IWUSR, null_show, new_dev_store);
2501 2521
2502static ssize_t 2522static ssize_t
2503size_show(mddev_t *mddev, char *page) 2523size_show(mddev_t *mddev, char *page)
@@ -2535,7 +2555,7 @@ size_store(mddev_t *mddev, const char *buf, size_t len)
2535} 2555}
2536 2556
2537static struct md_sysfs_entry md_size = 2557static struct md_sysfs_entry md_size =
2538__ATTR(component_size, 0644, size_show, size_store); 2558__ATTR(component_size, S_IRUGO|S_IWUSR, size_show, size_store);
2539 2559
2540 2560
2541/* Metdata version. 2561/* Metdata version.
@@ -2583,7 +2603,7 @@ metadata_store(mddev_t *mddev, const char *buf, size_t len)
2583} 2603}
2584 2604
2585static struct md_sysfs_entry md_metadata = 2605static struct md_sysfs_entry md_metadata =
2586__ATTR(metadata_version, 0644, metadata_show, metadata_store); 2606__ATTR(metadata_version, S_IRUGO|S_IWUSR, metadata_show, metadata_store);
2587 2607
2588static ssize_t 2608static ssize_t
2589action_show(mddev_t *mddev, char *page) 2609action_show(mddev_t *mddev, char *page)
@@ -2651,12 +2671,11 @@ mismatch_cnt_show(mddev_t *mddev, char *page)
2651 (unsigned long long) mddev->resync_mismatches); 2671 (unsigned long long) mddev->resync_mismatches);
2652} 2672}
2653 2673
2654static struct md_sysfs_entry 2674static struct md_sysfs_entry md_scan_mode =
2655md_scan_mode = __ATTR(sync_action, S_IRUGO|S_IWUSR, action_show, action_store); 2675__ATTR(sync_action, S_IRUGO|S_IWUSR, action_show, action_store);
2656 2676
2657 2677
2658static struct md_sysfs_entry 2678static struct md_sysfs_entry md_mismatches = __ATTR_RO(mismatch_cnt);
2659md_mismatches = __ATTR_RO(mismatch_cnt);
2660 2679
2661static ssize_t 2680static ssize_t
2662sync_min_show(mddev_t *mddev, char *page) 2681sync_min_show(mddev_t *mddev, char *page)
@@ -2715,15 +2734,14 @@ static ssize_t
2715sync_speed_show(mddev_t *mddev, char *page) 2734sync_speed_show(mddev_t *mddev, char *page)
2716{ 2735{
2717 unsigned long resync, dt, db; 2736 unsigned long resync, dt, db;
2718 resync = (mddev->curr_resync - atomic_read(&mddev->recovery_active)); 2737 resync = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active));
2719 dt = ((jiffies - mddev->resync_mark) / HZ); 2738 dt = ((jiffies - mddev->resync_mark) / HZ);
2720 if (!dt) dt++; 2739 if (!dt) dt++;
2721 db = resync - (mddev->resync_mark_cnt); 2740 db = resync - (mddev->resync_mark_cnt);
2722 return sprintf(page, "%ld\n", db/dt/2); /* K/sec */ 2741 return sprintf(page, "%ld\n", db/dt/2); /* K/sec */
2723} 2742}
2724 2743
2725static struct md_sysfs_entry 2744static struct md_sysfs_entry md_sync_speed = __ATTR_RO(sync_speed);
2726md_sync_speed = __ATTR_RO(sync_speed);
2727 2745
2728static ssize_t 2746static ssize_t
2729sync_completed_show(mddev_t *mddev, char *page) 2747sync_completed_show(mddev_t *mddev, char *page)
@@ -2739,8 +2757,7 @@ sync_completed_show(mddev_t *mddev, char *page)
2739 return sprintf(page, "%lu / %lu\n", resync, max_blocks); 2757 return sprintf(page, "%lu / %lu\n", resync, max_blocks);
2740} 2758}
2741 2759
2742static struct md_sysfs_entry 2760static struct md_sysfs_entry md_sync_completed = __ATTR_RO(sync_completed);
2743md_sync_completed = __ATTR_RO(sync_completed);
2744 2761
2745static ssize_t 2762static ssize_t
2746suspend_lo_show(mddev_t *mddev, char *page) 2763suspend_lo_show(mddev_t *mddev, char *page)
@@ -2857,6 +2874,8 @@ md_attr_store(struct kobject *kobj, struct attribute *attr,
2857 2874
2858 if (!entry->store) 2875 if (!entry->store)
2859 return -EIO; 2876 return -EIO;
2877 if (!capable(CAP_SYS_ADMIN))
2878 return -EACCES;
2860 rv = mddev_lock(mddev); 2879 rv = mddev_lock(mddev);
2861 if (!rv) { 2880 if (!rv) {
2862 rv = entry->store(mddev, page, length); 2881 rv = entry->store(mddev, page, length);
@@ -3091,7 +3110,6 @@ static int do_md_run(mddev_t * mddev)
3091 } 3110 }
3092 3111
3093 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 3112 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
3094 md_wakeup_thread(mddev->thread);
3095 3113
3096 if (mddev->sb_dirty) 3114 if (mddev->sb_dirty)
3097 md_update_sb(mddev); 3115 md_update_sb(mddev);
@@ -3112,7 +3130,7 @@ static int do_md_run(mddev_t * mddev)
3112 * start recovery here. If we leave it to md_check_recovery, 3130 * start recovery here. If we leave it to md_check_recovery,
3113 * it will remove the drives and not do the right thing 3131 * it will remove the drives and not do the right thing
3114 */ 3132 */
3115 if (mddev->degraded) { 3133 if (mddev->degraded && !mddev->sync_thread) {
3116 struct list_head *rtmp; 3134 struct list_head *rtmp;
3117 int spares = 0; 3135 int spares = 0;
3118 ITERATE_RDEV(mddev,rdev,rtmp) 3136 ITERATE_RDEV(mddev,rdev,rtmp)
@@ -3133,10 +3151,11 @@ static int do_md_run(mddev_t * mddev)
3133 mdname(mddev)); 3151 mdname(mddev));
3134 /* leave the spares where they are, it shouldn't hurt */ 3152 /* leave the spares where they are, it shouldn't hurt */
3135 mddev->recovery = 0; 3153 mddev->recovery = 0;
3136 } else 3154 }
3137 md_wakeup_thread(mddev->sync_thread);
3138 } 3155 }
3139 } 3156 }
3157 md_wakeup_thread(mddev->thread);
3158 md_wakeup_thread(mddev->sync_thread); /* possibly kick off a reshape */
3140 3159
3141 mddev->changed = 1; 3160 mddev->changed = 1;
3142 md_new_event(mddev); 3161 md_new_event(mddev);
@@ -4586,6 +4605,8 @@ void md_error(mddev_t *mddev, mdk_rdev_t *rdev)
4586 __builtin_return_address(0),__builtin_return_address(1), 4605 __builtin_return_address(0),__builtin_return_address(1),
4587 __builtin_return_address(2),__builtin_return_address(3)); 4606 __builtin_return_address(2),__builtin_return_address(3));
4588*/ 4607*/
4608 if (!mddev->pers)
4609 return;
4589 if (!mddev->pers->error_handler) 4610 if (!mddev->pers->error_handler)
4590 return; 4611 return;
4591 mddev->pers->error_handler(mddev,rdev); 4612 mddev->pers->error_handler(mddev,rdev);
@@ -4683,12 +4704,13 @@ static void status_resync(struct seq_file *seq, mddev_t * mddev)
4683 */ 4704 */
4684 dt = ((jiffies - mddev->resync_mark) / HZ); 4705 dt = ((jiffies - mddev->resync_mark) / HZ);
4685 if (!dt) dt++; 4706 if (!dt) dt++;
4686 db = resync - (mddev->resync_mark_cnt/2); 4707 db = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active))
4687 rt = (dt * ((unsigned long)(max_blocks-resync) / (db/100+1)))/100; 4708 - mddev->resync_mark_cnt;
4709 rt = (dt * ((unsigned long)(max_blocks-resync) / (db/2/100+1)))/100;
4688 4710
4689 seq_printf(seq, " finish=%lu.%lumin", rt / 60, (rt % 60)/6); 4711 seq_printf(seq, " finish=%lu.%lumin", rt / 60, (rt % 60)/6);
4690 4712
4691 seq_printf(seq, " speed=%ldK/sec", db/dt); 4713 seq_printf(seq, " speed=%ldK/sec", db/2/dt);
4692} 4714}
4693 4715
4694static void *md_seq_start(struct seq_file *seq, loff_t *pos) 4716static void *md_seq_start(struct seq_file *seq, loff_t *pos)
@@ -5199,6 +5221,7 @@ void md_do_sync(mddev_t *mddev)
5199 5221
5200 j += sectors; 5222 j += sectors;
5201 if (j>1) mddev->curr_resync = j; 5223 if (j>1) mddev->curr_resync = j;
5224 mddev->curr_mark_cnt = io_sectors;
5202 if (last_check == 0) 5225 if (last_check == 0)
5203 /* this is the earliers that rebuilt will be 5226 /* this is the earliers that rebuilt will be
5204 * visible in /proc/mdstat 5227 * visible in /proc/mdstat
@@ -5645,8 +5668,8 @@ static int set_ro(const char *val, struct kernel_param *kp)
5645 return -EINVAL; 5668 return -EINVAL;
5646} 5669}
5647 5670
5648module_param_call(start_ro, set_ro, get_ro, NULL, 0600); 5671module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR);
5649module_param(start_dirty_degraded, int, 0644); 5672module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR);
5650 5673
5651 5674
5652EXPORT_SYMBOL(register_md_personality); 5675EXPORT_SYMBOL(register_md_personality);
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index cead918578a7..3b4d69c05623 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -930,10 +930,13 @@ static void status(struct seq_file *seq, mddev_t *mddev)
930 930
931 seq_printf(seq, " [%d/%d] [", conf->raid_disks, 931 seq_printf(seq, " [%d/%d] [", conf->raid_disks,
932 conf->working_disks); 932 conf->working_disks);
933 for (i = 0; i < conf->raid_disks; i++) 933 rcu_read_lock();
934 for (i = 0; i < conf->raid_disks; i++) {
935 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
934 seq_printf(seq, "%s", 936 seq_printf(seq, "%s",
935 conf->mirrors[i].rdev && 937 rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_");
936 test_bit(In_sync, &conf->mirrors[i].rdev->flags) ? "U" : "_"); 938 }
939 rcu_read_unlock();
937 seq_printf(seq, "]"); 940 seq_printf(seq, "]");
938} 941}
939 942
@@ -975,7 +978,6 @@ static void error(mddev_t *mddev, mdk_rdev_t *rdev)
975static void print_conf(conf_t *conf) 978static void print_conf(conf_t *conf)
976{ 979{
977 int i; 980 int i;
978 mirror_info_t *tmp;
979 981
980 printk("RAID1 conf printout:\n"); 982 printk("RAID1 conf printout:\n");
981 if (!conf) { 983 if (!conf) {
@@ -985,14 +987,17 @@ static void print_conf(conf_t *conf)
985 printk(" --- wd:%d rd:%d\n", conf->working_disks, 987 printk(" --- wd:%d rd:%d\n", conf->working_disks,
986 conf->raid_disks); 988 conf->raid_disks);
987 989
990 rcu_read_lock();
988 for (i = 0; i < conf->raid_disks; i++) { 991 for (i = 0; i < conf->raid_disks; i++) {
989 char b[BDEVNAME_SIZE]; 992 char b[BDEVNAME_SIZE];
990 tmp = conf->mirrors + i; 993 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
991 if (tmp->rdev) 994 if (rdev)
992 printk(" disk %d, wo:%d, o:%d, dev:%s\n", 995 printk(" disk %d, wo:%d, o:%d, dev:%s\n",
993 i, !test_bit(In_sync, &tmp->rdev->flags), !test_bit(Faulty, &tmp->rdev->flags), 996 i, !test_bit(In_sync, &rdev->flags),
994 bdevname(tmp->rdev->bdev,b)); 997 !test_bit(Faulty, &rdev->flags),
998 bdevname(rdev->bdev,b));
995 } 999 }
1000 rcu_read_unlock();
996} 1001}
997 1002
998static void close_sync(conf_t *conf) 1003static void close_sync(conf_t *conf)
@@ -1008,20 +1013,20 @@ static int raid1_spare_active(mddev_t *mddev)
1008{ 1013{
1009 int i; 1014 int i;
1010 conf_t *conf = mddev->private; 1015 conf_t *conf = mddev->private;
1011 mirror_info_t *tmp;
1012 1016
1013 /* 1017 /*
1014 * Find all failed disks within the RAID1 configuration 1018 * Find all failed disks within the RAID1 configuration
1015 * and mark them readable 1019 * and mark them readable.
1020 * Called under mddev lock, so rcu protection not needed.
1016 */ 1021 */
1017 for (i = 0; i < conf->raid_disks; i++) { 1022 for (i = 0; i < conf->raid_disks; i++) {
1018 tmp = conf->mirrors + i; 1023 mdk_rdev_t *rdev = conf->mirrors[i].rdev;
1019 if (tmp->rdev 1024 if (rdev
1020 && !test_bit(Faulty, &tmp->rdev->flags) 1025 && !test_bit(Faulty, &rdev->flags)
1021 && !test_bit(In_sync, &tmp->rdev->flags)) { 1026 && !test_bit(In_sync, &rdev->flags)) {
1022 conf->working_disks++; 1027 conf->working_disks++;
1023 mddev->degraded--; 1028 mddev->degraded--;
1024 set_bit(In_sync, &tmp->rdev->flags); 1029 set_bit(In_sync, &rdev->flags);
1025 } 1030 }
1026 } 1031 }
1027 1032
@@ -1145,7 +1150,7 @@ static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error)
1145 long sectors_to_go = r1_bio->sectors; 1150 long sectors_to_go = r1_bio->sectors;
1146 /* make sure these bits doesn't get cleared. */ 1151 /* make sure these bits doesn't get cleared. */
1147 do { 1152 do {
1148 bitmap_end_sync(mddev->bitmap, r1_bio->sector, 1153 bitmap_end_sync(mddev->bitmap, s,
1149 &sync_blocks, 1); 1154 &sync_blocks, 1);
1150 s += sync_blocks; 1155 s += sync_blocks;
1151 sectors_to_go -= sync_blocks; 1156 sectors_to_go -= sync_blocks;
@@ -1237,7 +1242,7 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
1237 /* ouch - failed to read all of that. 1242 /* ouch - failed to read all of that.
1238 * Try some synchronous reads of other devices to get 1243 * Try some synchronous reads of other devices to get
1239 * good data, much like with normal read errors. Only 1244 * good data, much like with normal read errors. Only
1240 * read into the pages we already have so they we don't 1245 * read into the pages we already have so we don't
1241 * need to re-issue the read request. 1246 * need to re-issue the read request.
1242 * We don't need to freeze the array, because being in an 1247 * We don't need to freeze the array, because being in an
1243 * active sync request, there is no normal IO, and 1248 * active sync request, there is no normal IO, and
@@ -1257,6 +1262,10 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
1257 s = PAGE_SIZE >> 9; 1262 s = PAGE_SIZE >> 9;
1258 do { 1263 do {
1259 if (r1_bio->bios[d]->bi_end_io == end_sync_read) { 1264 if (r1_bio->bios[d]->bi_end_io == end_sync_read) {
1265 /* No rcu protection needed here devices
1266 * can only be removed when no resync is
1267 * active, and resync is currently active
1268 */
1260 rdev = conf->mirrors[d].rdev; 1269 rdev = conf->mirrors[d].rdev;
1261 if (sync_page_io(rdev->bdev, 1270 if (sync_page_io(rdev->bdev,
1262 sect + rdev->data_offset, 1271 sect + rdev->data_offset,
@@ -1463,6 +1472,11 @@ static void raid1d(mddev_t *mddev)
1463 s = PAGE_SIZE >> 9; 1472 s = PAGE_SIZE >> 9;
1464 1473
1465 do { 1474 do {
1475 /* Note: no rcu protection needed here
1476 * as this is synchronous in the raid1d thread
1477 * which is the thread that might remove
1478 * a device. If raid1d ever becomes multi-threaded....
1479 */
1466 rdev = conf->mirrors[d].rdev; 1480 rdev = conf->mirrors[d].rdev;
1467 if (rdev && 1481 if (rdev &&
1468 test_bit(In_sync, &rdev->flags) && 1482 test_bit(In_sync, &rdev->flags) &&
@@ -1486,7 +1500,6 @@ static void raid1d(mddev_t *mddev)
1486 d = conf->raid_disks; 1500 d = conf->raid_disks;
1487 d--; 1501 d--;
1488 rdev = conf->mirrors[d].rdev; 1502 rdev = conf->mirrors[d].rdev;
1489 atomic_add(s, &rdev->corrected_errors);
1490 if (rdev && 1503 if (rdev &&
1491 test_bit(In_sync, &rdev->flags)) { 1504 test_bit(In_sync, &rdev->flags)) {
1492 if (sync_page_io(rdev->bdev, 1505 if (sync_page_io(rdev->bdev,
@@ -1509,6 +1522,11 @@ static void raid1d(mddev_t *mddev)
1509 s<<9, conf->tmppage, READ) == 0) 1522 s<<9, conf->tmppage, READ) == 0)
1510 /* Well, this device is dead */ 1523 /* Well, this device is dead */
1511 md_error(mddev, rdev); 1524 md_error(mddev, rdev);
1525 else {
1526 atomic_add(s, &rdev->corrected_errors);
1527 printk(KERN_INFO "raid1:%s: read error corrected (%d sectors at %llu on %s)\n",
1528 mdname(mddev), s, (unsigned long long)(sect + rdev->data_offset), bdevname(rdev->bdev, b));
1529 }
1512 } 1530 }
1513 } 1531 }
1514 } else { 1532 } else {
@@ -1622,15 +1640,16 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1622 return 0; 1640 return 0;
1623 } 1641 }
1624 1642
1625 /* before building a request, check if we can skip these blocks..
1626 * This call the bitmap_start_sync doesn't actually record anything
1627 */
1628 if (mddev->bitmap == NULL && 1643 if (mddev->bitmap == NULL &&
1629 mddev->recovery_cp == MaxSector && 1644 mddev->recovery_cp == MaxSector &&
1645 !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) &&
1630 conf->fullsync == 0) { 1646 conf->fullsync == 0) {
1631 *skipped = 1; 1647 *skipped = 1;
1632 return max_sector - sector_nr; 1648 return max_sector - sector_nr;
1633 } 1649 }
1650 /* before building a request, check if we can skip these blocks..
1651 * This call the bitmap_start_sync doesn't actually record anything
1652 */
1634 if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) && 1653 if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
1635 !conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { 1654 !conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
1636 /* We can skip this block, and probably several more */ 1655 /* We can skip this block, and probably several more */
@@ -1783,19 +1802,17 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1783 for (i=0; i<conf->raid_disks; i++) { 1802 for (i=0; i<conf->raid_disks; i++) {
1784 bio = r1_bio->bios[i]; 1803 bio = r1_bio->bios[i];
1785 if (bio->bi_end_io == end_sync_read) { 1804 if (bio->bi_end_io == end_sync_read) {
1786 md_sync_acct(conf->mirrors[i].rdev->bdev, nr_sectors); 1805 md_sync_acct(bio->bi_bdev, nr_sectors);
1787 generic_make_request(bio); 1806 generic_make_request(bio);
1788 } 1807 }
1789 } 1808 }
1790 } else { 1809 } else {
1791 atomic_set(&r1_bio->remaining, 1); 1810 atomic_set(&r1_bio->remaining, 1);
1792 bio = r1_bio->bios[r1_bio->read_disk]; 1811 bio = r1_bio->bios[r1_bio->read_disk];
1793 md_sync_acct(conf->mirrors[r1_bio->read_disk].rdev->bdev, 1812 md_sync_acct(bio->bi_bdev, nr_sectors);
1794 nr_sectors);
1795 generic_make_request(bio); 1813 generic_make_request(bio);
1796 1814
1797 } 1815 }
1798
1799 return nr_sectors; 1816 return nr_sectors;
1800} 1817}
1801 1818
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 7f636283a1ba..016ddb831c9b 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1492,6 +1492,10 @@ static void raid10d(mddev_t *mddev)
1492 s<<9, conf->tmppage, READ) == 0) 1492 s<<9, conf->tmppage, READ) == 0)
1493 /* Well, this device is dead */ 1493 /* Well, this device is dead */
1494 md_error(mddev, rdev); 1494 md_error(mddev, rdev);
1495 else
1496 printk(KERN_INFO "raid10:%s: read error corrected (%d sectors at %llu on %s)\n",
1497 mdname(mddev), s, (unsigned long long)(sect+rdev->data_offset), bdevname(rdev->bdev, b));
1498
1495 rdev_dec_pending(rdev, mddev); 1499 rdev_dec_pending(rdev, mddev);
1496 rcu_read_lock(); 1500 rcu_read_lock();
1497 } 1501 }
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 7433871f4b3a..450066007160 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -18,6 +18,30 @@
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 19 */
20 20
21/*
22 * BITMAP UNPLUGGING:
23 *
24 * The sequencing for updating the bitmap reliably is a little
25 * subtle (and I got it wrong the first time) so it deserves some
26 * explanation.
27 *
28 * We group bitmap updates into batches. Each batch has a number.
29 * We may write out several batches at once, but that isn't very important.
30 * conf->bm_write is the number of the last batch successfully written.
31 * conf->bm_flush is the number of the last batch that was closed to
32 * new additions.
33 * When we discover that we will need to write to any block in a stripe
34 * (in add_stripe_bio) we update the in-memory bitmap and record in sh->bm_seq
35 * the number of the batch it will be in. This is bm_flush+1.
36 * When we are ready to do a write, if that batch hasn't been written yet,
37 * we plug the array and queue the stripe for later.
38 * When an unplug happens, we increment bm_flush, thus closing the current
39 * batch.
40 * When we notice that bm_flush > bm_write, we write out all pending updates
41 * to the bitmap, and advance bm_write to where bm_flush was.
42 * This may occasionally write a bit out twice, but is sure never to
43 * miss any bits.
44 */
21 45
22#include <linux/module.h> 46#include <linux/module.h>
23#include <linux/slab.h> 47#include <linux/slab.h>
@@ -88,12 +112,14 @@ static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
88 BUG_ON(!list_empty(&sh->lru)); 112 BUG_ON(!list_empty(&sh->lru));
89 BUG_ON(atomic_read(&conf->active_stripes)==0); 113 BUG_ON(atomic_read(&conf->active_stripes)==0);
90 if (test_bit(STRIPE_HANDLE, &sh->state)) { 114 if (test_bit(STRIPE_HANDLE, &sh->state)) {
91 if (test_bit(STRIPE_DELAYED, &sh->state)) 115 if (test_bit(STRIPE_DELAYED, &sh->state)) {
92 list_add_tail(&sh->lru, &conf->delayed_list); 116 list_add_tail(&sh->lru, &conf->delayed_list);
93 else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && 117 blk_plug_device(conf->mddev->queue);
94 conf->seq_write == sh->bm_seq) 118 } else if (test_bit(STRIPE_BIT_DELAY, &sh->state) &&
119 sh->bm_seq - conf->seq_write > 0) {
95 list_add_tail(&sh->lru, &conf->bitmap_list); 120 list_add_tail(&sh->lru, &conf->bitmap_list);
96 else { 121 blk_plug_device(conf->mddev->queue);
122 } else {
97 clear_bit(STRIPE_BIT_DELAY, &sh->state); 123 clear_bit(STRIPE_BIT_DELAY, &sh->state);
98 list_add_tail(&sh->lru, &conf->handle_list); 124 list_add_tail(&sh->lru, &conf->handle_list);
99 } 125 }
@@ -270,7 +296,7 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
270 < (conf->max_nr_stripes *3/4) 296 < (conf->max_nr_stripes *3/4)
271 || !conf->inactive_blocked), 297 || !conf->inactive_blocked),
272 conf->device_lock, 298 conf->device_lock,
273 unplug_slaves(conf->mddev) 299 raid5_unplug_device(conf->mddev->queue)
274 ); 300 );
275 conf->inactive_blocked = 0; 301 conf->inactive_blocked = 0;
276 } else 302 } else
@@ -281,7 +307,8 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
281 } else { 307 } else {
282 if (!test_bit(STRIPE_HANDLE, &sh->state)) 308 if (!test_bit(STRIPE_HANDLE, &sh->state))
283 atomic_inc(&conf->active_stripes); 309 atomic_inc(&conf->active_stripes);
284 if (list_empty(&sh->lru)) 310 if (list_empty(&sh->lru) &&
311 !test_bit(STRIPE_EXPANDING, &sh->state))
285 BUG(); 312 BUG();
286 list_del_init(&sh->lru); 313 list_del_init(&sh->lru);
287 } 314 }
@@ -496,6 +523,8 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
496 raid5_conf_t *conf = sh->raid_conf; 523 raid5_conf_t *conf = sh->raid_conf;
497 int disks = sh->disks, i; 524 int disks = sh->disks, i;
498 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); 525 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags);
526 char b[BDEVNAME_SIZE];
527 mdk_rdev_t *rdev;
499 528
500 if (bi->bi_size) 529 if (bi->bi_size)
501 return 1; 530 return 1;
@@ -543,25 +572,39 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
543 set_bit(R5_UPTODATE, &sh->dev[i].flags); 572 set_bit(R5_UPTODATE, &sh->dev[i].flags);
544#endif 573#endif
545 if (test_bit(R5_ReadError, &sh->dev[i].flags)) { 574 if (test_bit(R5_ReadError, &sh->dev[i].flags)) {
546 printk(KERN_INFO "raid5: read error corrected!!\n"); 575 rdev = conf->disks[i].rdev;
576 printk(KERN_INFO "raid5:%s: read error corrected (%lu sectors at %llu on %s)\n",
577 mdname(conf->mddev), STRIPE_SECTORS,
578 (unsigned long long)sh->sector + rdev->data_offset,
579 bdevname(rdev->bdev, b));
547 clear_bit(R5_ReadError, &sh->dev[i].flags); 580 clear_bit(R5_ReadError, &sh->dev[i].flags);
548 clear_bit(R5_ReWrite, &sh->dev[i].flags); 581 clear_bit(R5_ReWrite, &sh->dev[i].flags);
549 } 582 }
550 if (atomic_read(&conf->disks[i].rdev->read_errors)) 583 if (atomic_read(&conf->disks[i].rdev->read_errors))
551 atomic_set(&conf->disks[i].rdev->read_errors, 0); 584 atomic_set(&conf->disks[i].rdev->read_errors, 0);
552 } else { 585 } else {
586 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
553 int retry = 0; 587 int retry = 0;
588 rdev = conf->disks[i].rdev;
589
554 clear_bit(R5_UPTODATE, &sh->dev[i].flags); 590 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
555 atomic_inc(&conf->disks[i].rdev->read_errors); 591 atomic_inc(&rdev->read_errors);
556 if (conf->mddev->degraded) 592 if (conf->mddev->degraded)
557 printk(KERN_WARNING "raid5: read error not correctable.\n"); 593 printk(KERN_WARNING "raid5:%s: read error not correctable (sector %llu on %s).\n",
594 mdname(conf->mddev),
595 (unsigned long long)sh->sector + rdev->data_offset,
596 bdn);
558 else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) 597 else if (test_bit(R5_ReWrite, &sh->dev[i].flags))
559 /* Oh, no!!! */ 598 /* Oh, no!!! */
560 printk(KERN_WARNING "raid5: read error NOT corrected!!\n"); 599 printk(KERN_WARNING "raid5:%s: read error NOT corrected!! (sector %llu on %s).\n",
561 else if (atomic_read(&conf->disks[i].rdev->read_errors) 600 mdname(conf->mddev),
601 (unsigned long long)sh->sector + rdev->data_offset,
602 bdn);
603 else if (atomic_read(&rdev->read_errors)
562 > conf->max_nr_stripes) 604 > conf->max_nr_stripes)
563 printk(KERN_WARNING 605 printk(KERN_WARNING
564 "raid5: Too many read errors, failing device.\n"); 606 "raid5:%s: Too many read errors, failing device %s.\n",
607 mdname(conf->mddev), bdn);
565 else 608 else
566 retry = 1; 609 retry = 1;
567 if (retry) 610 if (retry)
@@ -569,7 +612,7 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
569 else { 612 else {
570 clear_bit(R5_ReadError, &sh->dev[i].flags); 613 clear_bit(R5_ReadError, &sh->dev[i].flags);
571 clear_bit(R5_ReWrite, &sh->dev[i].flags); 614 clear_bit(R5_ReWrite, &sh->dev[i].flags);
572 md_error(conf->mddev, conf->disks[i].rdev); 615 md_error(conf->mddev, rdev);
573 } 616 }
574 } 617 }
575 rdev_dec_pending(conf->disks[i].rdev, conf->mddev); 618 rdev_dec_pending(conf->disks[i].rdev, conf->mddev);
@@ -1270,9 +1313,9 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
1270 (unsigned long long)sh->sector, dd_idx); 1313 (unsigned long long)sh->sector, dd_idx);
1271 1314
1272 if (conf->mddev->bitmap && firstwrite) { 1315 if (conf->mddev->bitmap && firstwrite) {
1273 sh->bm_seq = conf->seq_write;
1274 bitmap_startwrite(conf->mddev->bitmap, sh->sector, 1316 bitmap_startwrite(conf->mddev->bitmap, sh->sector,
1275 STRIPE_SECTORS, 0); 1317 STRIPE_SECTORS, 0);
1318 sh->bm_seq = conf->seq_flush+1;
1276 set_bit(STRIPE_BIT_DELAY, &sh->state); 1319 set_bit(STRIPE_BIT_DELAY, &sh->state);
1277 } 1320 }
1278 1321
@@ -2554,13 +2597,6 @@ static int raid5_issue_flush(request_queue_t *q, struct gendisk *disk,
2554 return ret; 2597 return ret;
2555} 2598}
2556 2599
2557static inline void raid5_plug_device(raid5_conf_t *conf)
2558{
2559 spin_lock_irq(&conf->device_lock);
2560 blk_plug_device(conf->mddev->queue);
2561 spin_unlock_irq(&conf->device_lock);
2562}
2563
2564static int make_request(request_queue_t *q, struct bio * bi) 2600static int make_request(request_queue_t *q, struct bio * bi)
2565{ 2601{
2566 mddev_t *mddev = q->queuedata; 2602 mddev_t *mddev = q->queuedata;
@@ -2670,7 +2706,6 @@ static int make_request(request_queue_t *q, struct bio * bi)
2670 goto retry; 2706 goto retry;
2671 } 2707 }
2672 finish_wait(&conf->wait_for_overlap, &w); 2708 finish_wait(&conf->wait_for_overlap, &w);
2673 raid5_plug_device(conf);
2674 handle_stripe(sh, NULL); 2709 handle_stripe(sh, NULL);
2675 release_stripe(sh); 2710 release_stripe(sh);
2676 } else { 2711 } else {
@@ -2923,7 +2958,7 @@ static void raid5d (mddev_t *mddev)
2923 while (1) { 2958 while (1) {
2924 struct list_head *first; 2959 struct list_head *first;
2925 2960
2926 if (conf->seq_flush - conf->seq_write > 0) { 2961 if (conf->seq_flush != conf->seq_write) {
2927 int seq = conf->seq_flush; 2962 int seq = conf->seq_flush;
2928 spin_unlock_irq(&conf->device_lock); 2963 spin_unlock_irq(&conf->device_lock);
2929 bitmap_unplug(mddev->bitmap); 2964 bitmap_unplug(mddev->bitmap);
@@ -3246,9 +3281,6 @@ static int run(mddev_t *mddev)
3246 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); 3281 set_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
3247 mddev->sync_thread = md_register_thread(md_do_sync, mddev, 3282 mddev->sync_thread = md_register_thread(md_do_sync, mddev,
3248 "%s_reshape"); 3283 "%s_reshape");
3249 /* FIXME if md_register_thread fails?? */
3250 md_wakeup_thread(mddev->sync_thread);
3251
3252 } 3284 }
3253 3285
3254 /* read-ahead size must cover two whole stripes, which is 3286 /* read-ahead size must cover two whole stripes, which is
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index ef52e6da01ed..ed4aa4e7912c 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -53,7 +53,7 @@ config VIDEO_V4L1_COMPAT
53 If you are unsure as to whether this is required, answer Y. 53 If you are unsure as to whether this is required, answer Y.
54 54
55config VIDEO_V4L2 55config VIDEO_V4L2
56 tristate 56 bool
57 default y 57 default y
58 58
59source "drivers/media/video/Kconfig" 59source "drivers/media/video/Kconfig"
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index 8393d472d3b8..7e0cedc557df 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -1190,6 +1190,7 @@ int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int
1190 } 1190 }
1191 return err; 1191 return err;
1192 } 1192 }
1193#ifdef CONFIG_VIDEO_V4L1_COMPAT
1193 case VIDIOCGMBUF: 1194 case VIDIOCGMBUF:
1194 { 1195 {
1195 struct video_mbuf *mbuf = arg; 1196 struct video_mbuf *mbuf = arg;
@@ -1218,6 +1219,7 @@ int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int
1218 mutex_unlock(&q->lock); 1219 mutex_unlock(&q->lock);
1219 return 0; 1220 return 0;
1220 } 1221 }
1222#endif
1221 default: 1223 default:
1222 return v4l_compat_translate_ioctl(inode,file,cmd,arg, 1224 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
1223 saa7146_video_do_ioctl); 1225 saa7146_video_do_ioctl);
diff --git a/drivers/media/dvb/b2c2/Kconfig b/drivers/media/dvb/b2c2/Kconfig
index d7f1fd5b7b02..49a06fc54c51 100644
--- a/drivers/media/dvb/b2c2/Kconfig
+++ b/drivers/media/dvb/b2c2/Kconfig
@@ -1,6 +1,7 @@
1config DVB_B2C2_FLEXCOP 1config DVB_B2C2_FLEXCOP
2 tristate "Technisat/B2C2 FlexCopII(b) and FlexCopIII adapters" 2 tristate "Technisat/B2C2 FlexCopII(b) and FlexCopIII adapters"
3 depends on DVB_CORE && I2C 3 depends on DVB_CORE && I2C
4 select DVB_PLL
4 select DVB_STV0299 5 select DVB_STV0299
5 select DVB_MT352 6 select DVB_MT352
6 select DVB_MT312 7 select DVB_MT312
diff --git a/drivers/media/dvb/bt8xx/Kconfig b/drivers/media/dvb/bt8xx/Kconfig
index f394002118f8..7d0ee1ab2903 100644
--- a/drivers/media/dvb/bt8xx/Kconfig
+++ b/drivers/media/dvb/bt8xx/Kconfig
@@ -1,6 +1,7 @@
1config DVB_BT8XX 1config DVB_BT8XX
2 tristate "BT8xx based PCI cards" 2 tristate "BT8xx based PCI cards"
3 depends on DVB_CORE && PCI && I2C && VIDEO_BT848 3 depends on DVB_CORE && PCI && I2C && VIDEO_BT848
4 select DVB_PLL
4 select DVB_MT352 5 select DVB_MT352
5 select DVB_SP887X 6 select DVB_SP887X
6 select DVB_NXT6000 7 select DVB_NXT6000
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index d687a14ec0a7..06ac899a9a26 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -393,7 +393,7 @@ static int dst_set_bandwidth(struct dst_state *state, fe_bandwidth_t bandwidth)
393 state->bandwidth = bandwidth; 393 state->bandwidth = bandwidth;
394 394
395 if (state->dst_type != DST_TYPE_IS_TERR) 395 if (state->dst_type != DST_TYPE_IS_TERR)
396 return 0; 396 return -EOPNOTSUPP;
397 397
398 switch (bandwidth) { 398 switch (bandwidth) {
399 case BANDWIDTH_6_MHZ: 399 case BANDWIDTH_6_MHZ:
@@ -462,7 +462,7 @@ static int dst_set_symbolrate(struct dst_state *state, u32 srate)
462 462
463 state->symbol_rate = srate; 463 state->symbol_rate = srate;
464 if (state->dst_type == DST_TYPE_IS_TERR) { 464 if (state->dst_type == DST_TYPE_IS_TERR) {
465 return 0; 465 return -EOPNOTSUPP;
466 } 466 }
467 dprintk(verbose, DST_INFO, 1, "set symrate %u", srate); 467 dprintk(verbose, DST_INFO, 1, "set symrate %u", srate);
468 srate /= 1000; 468 srate /= 1000;
@@ -504,7 +504,7 @@ static int dst_set_symbolrate(struct dst_state *state, u32 srate)
504static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation) 504static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation)
505{ 505{
506 if (state->dst_type != DST_TYPE_IS_CABLE) 506 if (state->dst_type != DST_TYPE_IS_CABLE)
507 return 0; 507 return -EOPNOTSUPP;
508 508
509 state->modulation = modulation; 509 state->modulation = modulation;
510 switch (modulation) { 510 switch (modulation) {
@@ -1234,7 +1234,7 @@ int dst_command(struct dst_state *state, u8 *data, u8 len)
1234 goto error; 1234 goto error;
1235 } 1235 }
1236 if (write_dst(state, data, len)) { 1236 if (write_dst(state, data, len)) {
1237 dprintk(verbose, DST_INFO, 1, "Tring to recover.. "); 1237 dprintk(verbose, DST_INFO, 1, "Trying to recover.. ");
1238 if ((dst_error_recovery(state)) < 0) { 1238 if ((dst_error_recovery(state)) < 0) {
1239 dprintk(verbose, DST_ERROR, 1, "Recovery Failed."); 1239 dprintk(verbose, DST_ERROR, 1, "Recovery Failed.");
1240 goto error; 1240 goto error;
@@ -1328,15 +1328,13 @@ static int dst_tone_power_cmd(struct dst_state *state)
1328{ 1328{
1329 u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 }; 1329 u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
1330 1330
1331 if (state->dst_type == DST_TYPE_IS_TERR) 1331 if (state->dst_type != DST_TYPE_IS_SAT)
1332 return 0; 1332 return -EOPNOTSUPP;
1333 paket[4] = state->tx_tuna[4]; 1333 paket[4] = state->tx_tuna[4];
1334 paket[2] = state->tx_tuna[2]; 1334 paket[2] = state->tx_tuna[2];
1335 paket[3] = state->tx_tuna[3]; 1335 paket[3] = state->tx_tuna[3];
1336 paket[7] = dst_check_sum (paket, 7); 1336 paket[7] = dst_check_sum (paket, 7);
1337 dst_command(state, paket, 8); 1337 return dst_command(state, paket, 8);
1338
1339 return 0;
1340} 1338}
1341 1339
1342static int dst_get_tuna(struct dst_state *state) 1340static int dst_get_tuna(struct dst_state *state)
@@ -1465,7 +1463,7 @@ static int dst_set_diseqc(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd
1465 u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec }; 1463 u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
1466 1464
1467 if (state->dst_type != DST_TYPE_IS_SAT) 1465 if (state->dst_type != DST_TYPE_IS_SAT)
1468 return 0; 1466 return -EOPNOTSUPP;
1469 if (cmd->msg_len > 0 && cmd->msg_len < 5) 1467 if (cmd->msg_len > 0 && cmd->msg_len < 5)
1470 memcpy(&paket[3], cmd->msg, cmd->msg_len); 1468 memcpy(&paket[3], cmd->msg, cmd->msg_len);
1471 else if (cmd->msg_len == 5 && state->dst_hw_cap & DST_TYPE_HAS_DISEQC5) 1469 else if (cmd->msg_len == 5 && state->dst_hw_cap & DST_TYPE_HAS_DISEQC5)
@@ -1473,18 +1471,17 @@ static int dst_set_diseqc(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd
1473 else 1471 else
1474 return -EINVAL; 1472 return -EINVAL;
1475 paket[7] = dst_check_sum(&paket[0], 7); 1473 paket[7] = dst_check_sum(&paket[0], 7);
1476 dst_command(state, paket, 8); 1474 return dst_command(state, paket, 8);
1477 return 0;
1478} 1475}
1479 1476
1480static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 1477static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
1481{ 1478{
1482 int need_cmd; 1479 int need_cmd, retval = 0;
1483 struct dst_state *state = fe->demodulator_priv; 1480 struct dst_state *state = fe->demodulator_priv;
1484 1481
1485 state->voltage = voltage; 1482 state->voltage = voltage;
1486 if (state->dst_type != DST_TYPE_IS_SAT) 1483 if (state->dst_type != DST_TYPE_IS_SAT)
1487 return 0; 1484 return -EOPNOTSUPP;
1488 1485
1489 need_cmd = 0; 1486 need_cmd = 0;
1490 1487
@@ -1506,9 +1503,9 @@ static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
1506 } 1503 }
1507 1504
1508 if (need_cmd) 1505 if (need_cmd)
1509 dst_tone_power_cmd(state); 1506 retval = dst_tone_power_cmd(state);
1510 1507
1511 return 0; 1508 return retval;
1512} 1509}
1513 1510
1514static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 1511static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
@@ -1517,7 +1514,7 @@ static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
1517 1514
1518 state->tone = tone; 1515 state->tone = tone;
1519 if (state->dst_type != DST_TYPE_IS_SAT) 1516 if (state->dst_type != DST_TYPE_IS_SAT)
1520 return 0; 1517 return -EOPNOTSUPP;
1521 1518
1522 switch (tone) { 1519 switch (tone) {
1523 case SEC_TONE_OFF: 1520 case SEC_TONE_OFF:
@@ -1533,9 +1530,7 @@ static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
1533 default: 1530 default:
1534 return -EINVAL; 1531 return -EINVAL;
1535 } 1532 }
1536 dst_tone_power_cmd(state); 1533 return dst_tone_power_cmd(state);
1537
1538 return 0;
1539} 1534}
1540 1535
1541static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd) 1536static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
@@ -1543,7 +1538,7 @@ static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
1543 struct dst_state *state = fe->demodulator_priv; 1538 struct dst_state *state = fe->demodulator_priv;
1544 1539
1545 if (state->dst_type != DST_TYPE_IS_SAT) 1540 if (state->dst_type != DST_TYPE_IS_SAT)
1546 return 0; 1541 return -EOPNOTSUPP;
1547 state->minicmd = minicmd; 1542 state->minicmd = minicmd;
1548 switch (minicmd) { 1543 switch (minicmd) {
1549 case SEC_MINI_A: 1544 case SEC_MINI_A:
@@ -1553,9 +1548,7 @@ static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
1553 state->tx_tuna[3] = 0xff; 1548 state->tx_tuna[3] = 0xff;
1554 break; 1549 break;
1555 } 1550 }
1556 dst_tone_power_cmd(state); 1551 return dst_tone_power_cmd(state);
1557
1558 return 0;
1559} 1552}
1560 1553
1561 1554
@@ -1608,28 +1601,31 @@ static int dst_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
1608{ 1601{
1609 struct dst_state *state = fe->demodulator_priv; 1602 struct dst_state *state = fe->demodulator_priv;
1610 1603
1611 dst_get_signal(state); 1604 int retval = dst_get_signal(state);
1612 *strength = state->decode_strength; 1605 *strength = state->decode_strength;
1613 1606
1614 return 0; 1607 return retval;
1615} 1608}
1616 1609
1617static int dst_read_snr(struct dvb_frontend *fe, u16 *snr) 1610static int dst_read_snr(struct dvb_frontend *fe, u16 *snr)
1618{ 1611{
1619 struct dst_state *state = fe->demodulator_priv; 1612 struct dst_state *state = fe->demodulator_priv;
1620 1613
1621 dst_get_signal(state); 1614 int retval = dst_get_signal(state);
1622 *snr = state->decode_snr; 1615 *snr = state->decode_snr;
1623 1616
1624 return 0; 1617 return retval;
1625} 1618}
1626 1619
1627static int dst_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p) 1620static int dst_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
1628{ 1621{
1622 int retval = -EINVAL;
1629 struct dst_state *state = fe->demodulator_priv; 1623 struct dst_state *state = fe->demodulator_priv;
1630 1624
1631 if (p != NULL) { 1625 if (p != NULL) {
1632 dst_set_freq(state, p->frequency); 1626 retval = dst_set_freq(state, p->frequency);
1627 if(retval != 0)
1628 return retval;
1633 dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency); 1629 dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);
1634 1630
1635 if (state->dst_type == DST_TYPE_IS_SAT) { 1631 if (state->dst_type == DST_TYPE_IS_SAT) {
@@ -1647,10 +1643,10 @@ static int dst_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_paramet
1647 dst_set_symbolrate(state, p->u.qam.symbol_rate); 1643 dst_set_symbolrate(state, p->u.qam.symbol_rate);
1648 dst_set_modulation(state, p->u.qam.modulation); 1644 dst_set_modulation(state, p->u.qam.modulation);
1649 } 1645 }
1650 dst_write_tuna(fe); 1646 retval = dst_write_tuna(fe);
1651 } 1647 }
1652 1648
1653 return 0; 1649 return retval;
1654} 1650}
1655 1651
1656static int dst_tune_frontend(struct dvb_frontend* fe, 1652static int dst_tune_frontend(struct dvb_frontend* fe,
diff --git a/drivers/media/dvb/dvb-core/Makefile b/drivers/media/dvb/dvb-core/Makefile
index 11054657fdb5..0b5182835cc8 100644
--- a/drivers/media/dvb/dvb-core/Makefile
+++ b/drivers/media/dvb/dvb-core/Makefile
@@ -2,8 +2,8 @@
2# Makefile for the kernel DVB device drivers. 2# Makefile for the kernel DVB device drivers.
3# 3#
4 4
5dvb-core-objs = dvbdev.o dmxdev.o dvb_demux.o dvb_filter.o \ 5dvb-core-objs := dvbdev.o dmxdev.o dvb_demux.o dvb_filter.o \
6 dvb_ca_en50221.o dvb_frontend.o \ 6 dvb_ca_en50221.o dvb_frontend.o \
7 dvb_net.o dvb_ringbuffer.o dvb_math.o 7 dvb_net.o dvb_ringbuffer.o dvb_math.o
8 8
9obj-$(CONFIG_DVB_CORE) += dvb-core.o 9obj-$(CONFIG_DVB_CORE) += dvb-core.o
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 59ac35ddd51e..57b34cda99f5 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -526,7 +526,9 @@ static int dvb_frontend_thread(void *data)
526 fepriv->delay = 3*HZ; 526 fepriv->delay = 3*HZ;
527 fepriv->status = 0; 527 fepriv->status = 0;
528 fepriv->wakeup = 0; 528 fepriv->wakeup = 0;
529 fepriv->reinitialise = 1; 529 fepriv->reinitialise = 0;
530
531 dvb_frontend_init(fe);
530 532
531 while (1) { 533 while (1) {
532 up(&fepriv->sem); /* is locked when we enter the thread... */ 534 up(&fepriv->sem); /* is locked when we enter the thread... */
@@ -1013,17 +1015,18 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
1013 return ret; 1015 return ret;
1014 1016
1015 if ((file->f_flags & O_ACCMODE) != O_RDONLY) { 1017 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
1018
1019 /* normal tune mode when opened R/W */
1020 fepriv->tune_mode_flags &= ~FE_TUNE_MODE_ONESHOT;
1021 fepriv->tone = -1;
1022 fepriv->voltage = -1;
1023
1016 ret = dvb_frontend_start (fe); 1024 ret = dvb_frontend_start (fe);
1017 if (ret) 1025 if (ret)
1018 dvb_generic_release (inode, file); 1026 dvb_generic_release (inode, file);
1019 1027
1020 /* empty event queue */ 1028 /* empty event queue */
1021 fepriv->events.eventr = fepriv->events.eventw = 0; 1029 fepriv->events.eventr = fepriv->events.eventw = 0;
1022
1023 /* normal tune mode when opened R/W */
1024 fepriv->tune_mode_flags &= ~FE_TUNE_MODE_ONESHOT;
1025 fepriv->tone = -1;
1026 fepriv->voltage = -1;
1027 } 1030 }
1028 1031
1029 return ret; 1032 return ret;
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index 3bc6722a6443..75824b77198a 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -2,6 +2,7 @@ config DVB_USB
2 tristate "Support for various USB DVB devices" 2 tristate "Support for various USB DVB devices"
3 depends on DVB_CORE && USB && I2C 3 depends on DVB_CORE && USB && I2C
4 select FW_LOADER 4 select FW_LOADER
5 select DVB_PLL
5 help 6 help
6 By enabling this you will be able to choose the various supported 7 By enabling this you will be able to choose the various supported
7 USB1.1 and USB2.0 DVB devices. 8 USB1.1 and USB2.0 DVB devices.
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index 0ef361f0309b..db978555b1eb 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -6,43 +6,43 @@ comment "DVB-S (satellite) frontends"
6 6
7config DVB_STV0299 7config DVB_STV0299
8 tristate "ST STV0299 based" 8 tristate "ST STV0299 based"
9 depends on DVB_CORE 9 depends on DVB_CORE && I2C
10 help 10 help
11 A DVB-S tuner module. Say Y when you want to support this frontend. 11 A DVB-S tuner module. Say Y when you want to support this frontend.
12 12
13config DVB_CX24110 13config DVB_CX24110
14 tristate "Conexant CX24110 based" 14 tristate "Conexant CX24110 based"
15 depends on DVB_CORE 15 depends on DVB_CORE && I2C
16 help 16 help
17 A DVB-S tuner module. Say Y when you want to support this frontend. 17 A DVB-S tuner module. Say Y when you want to support this frontend.
18 18
19config DVB_CX24123 19config DVB_CX24123
20 tristate "Conexant CX24123 based" 20 tristate "Conexant CX24123 based"
21 depends on DVB_CORE 21 depends on DVB_CORE && I2C
22 help 22 help
23 A DVB-S tuner module. Say Y when you want to support this frontend. 23 A DVB-S tuner module. Say Y when you want to support this frontend.
24 24
25config DVB_TDA8083 25config DVB_TDA8083
26 tristate "Philips TDA8083 based" 26 tristate "Philips TDA8083 based"
27 depends on DVB_CORE 27 depends on DVB_CORE && I2C
28 help 28 help
29 A DVB-S tuner module. Say Y when you want to support this frontend. 29 A DVB-S tuner module. Say Y when you want to support this frontend.
30 30
31config DVB_MT312 31config DVB_MT312
32 tristate "Zarlink VP310/MT312 based" 32 tristate "Zarlink VP310/MT312 based"
33 depends on DVB_CORE 33 depends on DVB_CORE && I2C
34 help 34 help
35 A DVB-S tuner module. Say Y when you want to support this frontend. 35 A DVB-S tuner module. Say Y when you want to support this frontend.
36 36
37config DVB_VES1X93 37config DVB_VES1X93
38 tristate "VLSI VES1893 or VES1993 based" 38 tristate "VLSI VES1893 or VES1993 based"
39 depends on DVB_CORE 39 depends on DVB_CORE && I2C
40 help 40 help
41 A DVB-S tuner module. Say Y when you want to support this frontend. 41 A DVB-S tuner module. Say Y when you want to support this frontend.
42 42
43config DVB_S5H1420 43config DVB_S5H1420
44 tristate "Samsung S5H1420 based" 44 tristate "Samsung S5H1420 based"
45 depends on DVB_CORE 45 depends on DVB_CORE && I2C
46 help 46 help
47 A DVB-S tuner module. Say Y when you want to support this frontend. 47 A DVB-S tuner module. Say Y when you want to support this frontend.
48 48
@@ -51,7 +51,7 @@ comment "DVB-T (terrestrial) frontends"
51 51
52config DVB_SP8870 52config DVB_SP8870
53 tristate "Spase sp8870 based" 53 tristate "Spase sp8870 based"
54 depends on DVB_CORE 54 depends on DVB_CORE && I2C
55 select FW_LOADER 55 select FW_LOADER
56 help 56 help
57 A DVB-T tuner module. Say Y when you want to support this frontend. 57 A DVB-T tuner module. Say Y when you want to support this frontend.
@@ -63,7 +63,7 @@ config DVB_SP8870
63 63
64config DVB_SP887X 64config DVB_SP887X
65 tristate "Spase sp887x based" 65 tristate "Spase sp887x based"
66 depends on DVB_CORE 66 depends on DVB_CORE && I2C
67 select FW_LOADER 67 select FW_LOADER
68 help 68 help
69 A DVB-T tuner module. Say Y when you want to support this frontend. 69 A DVB-T tuner module. Say Y when you want to support this frontend.
@@ -75,25 +75,25 @@ config DVB_SP887X
75 75
76config DVB_CX22700 76config DVB_CX22700
77 tristate "Conexant CX22700 based" 77 tristate "Conexant CX22700 based"
78 depends on DVB_CORE 78 depends on DVB_CORE && I2C
79 help 79 help
80 A DVB-T tuner module. Say Y when you want to support this frontend. 80 A DVB-T tuner module. Say Y when you want to support this frontend.
81 81
82config DVB_CX22702 82config DVB_CX22702
83 tristate "Conexant cx22702 demodulator (OFDM)" 83 tristate "Conexant cx22702 demodulator (OFDM)"
84 depends on DVB_CORE 84 depends on DVB_CORE && I2C
85 help 85 help
86 A DVB-T tuner module. Say Y when you want to support this frontend. 86 A DVB-T tuner module. Say Y when you want to support this frontend.
87 87
88config DVB_L64781 88config DVB_L64781
89 tristate "LSI L64781" 89 tristate "LSI L64781"
90 depends on DVB_CORE 90 depends on DVB_CORE && I2C
91 help 91 help
92 A DVB-T tuner module. Say Y when you want to support this frontend. 92 A DVB-T tuner module. Say Y when you want to support this frontend.
93 93
94config DVB_TDA1004X 94config DVB_TDA1004X
95 tristate "Philips TDA10045H/TDA10046H based" 95 tristate "Philips TDA10045H/TDA10046H based"
96 depends on DVB_CORE 96 depends on DVB_CORE && I2C
97 select FW_LOADER 97 select FW_LOADER
98 help 98 help
99 A DVB-T tuner module. Say Y when you want to support this frontend. 99 A DVB-T tuner module. Say Y when you want to support this frontend.
@@ -106,32 +106,32 @@ config DVB_TDA1004X
106 106
107config DVB_NXT6000 107config DVB_NXT6000
108 tristate "NxtWave Communications NXT6000 based" 108 tristate "NxtWave Communications NXT6000 based"
109 depends on DVB_CORE 109 depends on DVB_CORE && I2C
110 help 110 help
111 A DVB-T tuner module. Say Y when you want to support this frontend. 111 A DVB-T tuner module. Say Y when you want to support this frontend.
112 112
113config DVB_MT352 113config DVB_MT352
114 tristate "Zarlink MT352 based" 114 tristate "Zarlink MT352 based"
115 depends on DVB_CORE 115 depends on DVB_CORE && I2C
116 help 116 help
117 A DVB-T tuner module. Say Y when you want to support this frontend. 117 A DVB-T tuner module. Say Y when you want to support this frontend.
118 118
119config DVB_ZL10353 119config DVB_ZL10353
120 tristate "Zarlink ZL10353 based" 120 tristate "Zarlink ZL10353 based"
121 depends on DVB_CORE 121 depends on DVB_CORE && I2C
122 help 122 help
123 A DVB-T tuner module. Say Y when you want to support this frontend. 123 A DVB-T tuner module. Say Y when you want to support this frontend.
124 124
125config DVB_DIB3000MB 125config DVB_DIB3000MB
126 tristate "DiBcom 3000M-B" 126 tristate "DiBcom 3000M-B"
127 depends on DVB_CORE 127 depends on DVB_CORE && I2C
128 help 128 help
129 A DVB-T tuner module. Designed for mobile usage. Say Y when you want 129 A DVB-T tuner module. Designed for mobile usage. Say Y when you want
130 to support this frontend. 130 to support this frontend.
131 131
132config DVB_DIB3000MC 132config DVB_DIB3000MC
133 tristate "DiBcom 3000P/M-C" 133 tristate "DiBcom 3000P/M-C"
134 depends on DVB_CORE 134 depends on DVB_CORE && I2C
135 help 135 help
136 A DVB-T tuner module. Designed for mobile usage. Say Y when you want 136 A DVB-T tuner module. Designed for mobile usage. Say Y when you want
137 to support this frontend. 137 to support this frontend.
@@ -141,19 +141,19 @@ comment "DVB-C (cable) frontends"
141 141
142config DVB_VES1820 142config DVB_VES1820
143 tristate "VLSI VES1820 based" 143 tristate "VLSI VES1820 based"
144 depends on DVB_CORE 144 depends on DVB_CORE && I2C
145 help 145 help
146 A DVB-C tuner module. Say Y when you want to support this frontend. 146 A DVB-C tuner module. Say Y when you want to support this frontend.
147 147
148config DVB_TDA10021 148config DVB_TDA10021
149 tristate "Philips TDA10021 based" 149 tristate "Philips TDA10021 based"
150 depends on DVB_CORE 150 depends on DVB_CORE && I2C
151 help 151 help
152 A DVB-C tuner module. Say Y when you want to support this frontend. 152 A DVB-C tuner module. Say Y when you want to support this frontend.
153 153
154config DVB_STV0297 154config DVB_STV0297
155 tristate "ST STV0297 based" 155 tristate "ST STV0297 based"
156 depends on DVB_CORE 156 depends on DVB_CORE && I2C
157 help 157 help
158 A DVB-C tuner module. Say Y when you want to support this frontend. 158 A DVB-C tuner module. Say Y when you want to support this frontend.
159 159
@@ -162,7 +162,7 @@ comment "ATSC (North American/Korean Terrestrial/Cable DTV) frontends"
162 162
163config DVB_NXT200X 163config DVB_NXT200X
164 tristate "NxtWave Communications NXT2002/NXT2004 based" 164 tristate "NxtWave Communications NXT2002/NXT2004 based"
165 depends on DVB_CORE 165 depends on DVB_CORE && I2C
166 select FW_LOADER 166 select FW_LOADER
167 help 167 help
168 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 168 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
@@ -176,7 +176,7 @@ config DVB_NXT200X
176 176
177config DVB_OR51211 177config DVB_OR51211
178 tristate "Oren OR51211 based" 178 tristate "Oren OR51211 based"
179 depends on DVB_CORE 179 depends on DVB_CORE && I2C
180 select FW_LOADER 180 select FW_LOADER
181 help 181 help
182 An ATSC 8VSB tuner module. Say Y when you want to support this frontend. 182 An ATSC 8VSB tuner module. Say Y when you want to support this frontend.
@@ -188,7 +188,7 @@ config DVB_OR51211
188 188
189config DVB_OR51132 189config DVB_OR51132
190 tristate "Oren OR51132 based" 190 tristate "Oren OR51132 based"
191 depends on DVB_CORE 191 depends on DVB_CORE && I2C
192 select FW_LOADER 192 select FW_LOADER
193 help 193 help
194 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 194 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
@@ -203,7 +203,7 @@ config DVB_OR51132
203 203
204config DVB_BCM3510 204config DVB_BCM3510
205 tristate "Broadcom BCM3510" 205 tristate "Broadcom BCM3510"
206 depends on DVB_CORE 206 depends on DVB_CORE && I2C
207 select FW_LOADER 207 select FW_LOADER
208 help 208 help
209 An ATSC 8VSB/16VSB and QAM64/256 tuner module. Say Y when you want to 209 An ATSC 8VSB/16VSB and QAM64/256 tuner module. Say Y when you want to
@@ -211,7 +211,7 @@ config DVB_BCM3510
211 211
212config DVB_LGDT330X 212config DVB_LGDT330X
213 tristate "LG Electronics LGDT3302/LGDT3303 based" 213 tristate "LG Electronics LGDT3302/LGDT3303 based"
214 depends on DVB_CORE 214 depends on DVB_CORE && I2C
215 help 215 help
216 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 216 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
217 to support this frontend. 217 to support this frontend.
@@ -220,15 +220,19 @@ config DVB_LGDT330X
220comment "Miscellaneous devices" 220comment "Miscellaneous devices"
221 depends on DVB_CORE 221 depends on DVB_CORE
222 222
223config DVB_PLL
224 tristate
225 depends on DVB_CORE && I2C
226
223config DVB_LNBP21 227config DVB_LNBP21
224 tristate "LNBP21 SEC controller" 228 tristate "LNBP21 SEC controller"
225 depends on DVB_CORE 229 depends on DVB_CORE && I2C
226 help 230 help
227 An SEC control chip. 231 An SEC control chip.
228 232
229config DVB_ISL6421 233config DVB_ISL6421
230 tristate "ISL6421 SEC controller" 234 tristate "ISL6421 SEC controller"
231 depends on DVB_CORE 235 depends on DVB_CORE && I2C
232 help 236 help
233 An SEC control chip. 237 An SEC control chip.
234 238
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 5222245c7f59..0e4880b6db14 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -4,7 +4,7 @@
4 4
5EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ 5EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/
6 6
7obj-$(CONFIG_DVB_CORE) += dvb-pll.o 7obj-$(CONFIG_DVB_PLL) += dvb-pll.o
8obj-$(CONFIG_DVB_STV0299) += stv0299.o 8obj-$(CONFIG_DVB_STV0299) += stv0299.o
9obj-$(CONFIG_DVB_SP8870) += sp8870.o 9obj-$(CONFIG_DVB_SP8870) += sp8870.o
10obj-$(CONFIG_DVB_CX22700) += cx22700.o 10obj-$(CONFIG_DVB_CX22700) += cx22700.o
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c
index a189683454b7..2be33f27c69f 100644
--- a/drivers/media/dvb/frontends/dvb-pll.c
+++ b/drivers/media/dvb/frontends/dvb-pll.c
@@ -194,11 +194,11 @@ struct dvb_pll_desc dvb_pll_tda665x = {
194 { 253834000, 36249333, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ }, 194 { 253834000, 36249333, 166667, 0xca, 0x62 /* 011 0 0 0 10 */ },
195 { 383834000, 36249333, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ }, 195 { 383834000, 36249333, 166667, 0xca, 0xa2 /* 101 0 0 0 10 */ },
196 { 443834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ }, 196 { 443834000, 36249333, 166667, 0xca, 0xc2 /* 110 0 0 0 10 */ },
197 { 444000000, 36249333, 166667, 0xca, 0xc3 /* 110 0 0 0 11 */ }, 197 { 444000000, 36249333, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
198 { 583834000, 36249333, 166667, 0xca, 0x63 /* 011 0 0 0 11 */ }, 198 { 583834000, 36249333, 166667, 0xca, 0x64 /* 011 0 0 1 00 */ },
199 { 793834000, 36249333, 166667, 0xca, 0xa3 /* 101 0 0 0 11 */ }, 199 { 793834000, 36249333, 166667, 0xca, 0xa4 /* 101 0 0 1 00 */ },
200 { 444834000, 36249333, 166667, 0xca, 0xc3 /* 110 0 0 0 11 */ }, 200 { 444834000, 36249333, 166667, 0xca, 0xc4 /* 110 0 0 1 00 */ },
201 { 861000000, 36249333, 166667, 0xca, 0xe3 /* 111 0 0 0 11 */ }, 201 { 861000000, 36249333, 166667, 0xca, 0xe4 /* 111 0 0 1 00 */ },
202 } 202 }
203}; 203};
204EXPORT_SYMBOL(dvb_pll_tda665x); 204EXPORT_SYMBOL(dvb_pll_tda665x);
@@ -613,7 +613,21 @@ static struct dvb_tuner_ops dvb_pll_tuner_ops = {
613 613
614int dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2c, struct dvb_pll_desc *desc) 614int dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2c, struct dvb_pll_desc *desc)
615{ 615{
616 u8 b1 [] = { 0 };
617 struct i2c_msg msg = { .addr = pll_addr, .flags = I2C_M_RD, .buf = b1, .len = 1 };
616 struct dvb_pll_priv *priv = NULL; 618 struct dvb_pll_priv *priv = NULL;
619 int ret;
620
621 if (i2c != NULL) {
622 if (fe->ops.i2c_gate_ctrl)
623 fe->ops.i2c_gate_ctrl(fe, 1);
624
625 ret = i2c_transfer (i2c, &msg, 1);
626 if (ret != 1)
627 return -1;
628 if (fe->ops.i2c_gate_ctrl)
629 fe->ops.i2c_gate_ctrl(fe, 0);
630 }
617 631
618 priv = kzalloc(sizeof(struct dvb_pll_priv), GFP_KERNEL); 632 priv = kzalloc(sizeof(struct dvb_pll_priv), GFP_KERNEL);
619 if (priv == NULL) 633 if (priv == NULL)
diff --git a/drivers/media/dvb/frontends/nxt200x.c b/drivers/media/dvb/frontends/nxt200x.c
index 55671cb5255e..87c286ee6a00 100644
--- a/drivers/media/dvb/frontends/nxt200x.c
+++ b/drivers/media/dvb/frontends/nxt200x.c
@@ -896,9 +896,9 @@ static int nxt2002_init(struct dvb_frontend* fe)
896 } 896 }
897 897
898 ret = nxt2002_load_firmware(fe, fw); 898 ret = nxt2002_load_firmware(fe, fw);
899 release_firmware(fw);
899 if (ret) { 900 if (ret) {
900 printk("nxt2002: Writing firmware to device failed\n"); 901 printk("nxt2002: Writing firmware to device failed\n");
901 release_firmware(fw);
902 return ret; 902 return ret;
903 } 903 }
904 printk("nxt2002: Firmware upload complete\n"); 904 printk("nxt2002: Firmware upload complete\n");
@@ -960,9 +960,9 @@ static int nxt2004_init(struct dvb_frontend* fe)
960 } 960 }
961 961
962 ret = nxt2004_load_firmware(fe, fw); 962 ret = nxt2004_load_firmware(fe, fw);
963 release_firmware(fw);
963 if (ret) { 964 if (ret) {
964 printk("nxt2004: Writing firmware to device failed\n"); 965 printk("nxt2004: Writing firmware to device failed\n");
965 release_firmware(fw);
966 return ret; 966 return ret;
967 } 967 }
968 printk("nxt2004: Firmware upload complete\n"); 968 printk("nxt2004: Firmware upload complete\n");
diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
index 26bed616fabe..2bf124b53689 100644
--- a/drivers/media/dvb/frontends/or51211.c
+++ b/drivers/media/dvb/frontends/or51211.c
@@ -437,10 +437,10 @@ static int or51211_init(struct dvb_frontend* fe)
437 } 437 }
438 438
439 ret = or51211_load_firmware(fe, fw); 439 ret = or51211_load_firmware(fe, fw);
440 release_firmware(fw);
440 if (ret) { 441 if (ret) {
441 printk(KERN_WARNING "or51211: Writing firmware to " 442 printk(KERN_WARNING "or51211: Writing firmware to "
442 "device failed!\n"); 443 "device failed!\n");
443 release_firmware(fw);
444 return ret; 444 return ret;
445 } 445 }
446 printk(KERN_INFO "or51211: Firmware upload complete.\n"); 446 printk(KERN_INFO "or51211: Firmware upload complete.\n");
diff --git a/drivers/media/dvb/frontends/sp8870.c b/drivers/media/dvb/frontends/sp8870.c
index 44ec5b9a4695..d98fd5c2e13e 100644
--- a/drivers/media/dvb/frontends/sp8870.c
+++ b/drivers/media/dvb/frontends/sp8870.c
@@ -318,7 +318,6 @@ static int sp8870_init (struct dvb_frontend* fe)
318 printk("sp8870: waiting for firmware upload (%s)...\n", SP8870_DEFAULT_FIRMWARE); 318 printk("sp8870: waiting for firmware upload (%s)...\n", SP8870_DEFAULT_FIRMWARE);
319 if (state->config->request_firmware(fe, &fw, SP8870_DEFAULT_FIRMWARE)) { 319 if (state->config->request_firmware(fe, &fw, SP8870_DEFAULT_FIRMWARE)) {
320 printk("sp8870: no firmware upload (timeout or file not found?)\n"); 320 printk("sp8870: no firmware upload (timeout or file not found?)\n");
321 release_firmware(fw);
322 return -EIO; 321 return -EIO;
323 } 322 }
324 323
@@ -327,6 +326,7 @@ static int sp8870_init (struct dvb_frontend* fe)
327 release_firmware(fw); 326 release_firmware(fw);
328 return -EIO; 327 return -EIO;
329 } 328 }
329 release_firmware(fw);
330 printk("sp8870: firmware upload complete\n"); 330 printk("sp8870: firmware upload complete\n");
331 331
332 /* enable TS output and interface pins */ 332 /* enable TS output and interface pins */
diff --git a/drivers/media/dvb/frontends/sp887x.c b/drivers/media/dvb/frontends/sp887x.c
index b0a2b02f6608..5c2f8f4e0ae5 100644
--- a/drivers/media/dvb/frontends/sp887x.c
+++ b/drivers/media/dvb/frontends/sp887x.c
@@ -520,9 +520,9 @@ static int sp887x_init(struct dvb_frontend* fe)
520 } 520 }
521 521
522 ret = sp887x_initial_setup(fe, fw); 522 ret = sp887x_initial_setup(fe, fw);
523 release_firmware(fw);
523 if (ret) { 524 if (ret) {
524 printk("sp887x: writing firmware to device failed\n"); 525 printk("sp887x: writing firmware to device failed\n");
525 release_firmware(fw);
526 return ret; 526 return ret;
527 } 527 }
528 printk("sp887x: firmware upload complete\n"); 528 printk("sp887x: firmware upload complete\n");
diff --git a/drivers/media/dvb/pluto2/Kconfig b/drivers/media/dvb/pluto2/Kconfig
index 7d8e6e87bdbb..9b84b1bdc313 100644
--- a/drivers/media/dvb/pluto2/Kconfig
+++ b/drivers/media/dvb/pluto2/Kconfig
@@ -2,6 +2,7 @@ config DVB_PLUTO2
2 tristate "Pluto2 cards" 2 tristate "Pluto2 cards"
3 depends on DVB_CORE && PCI && I2C 3 depends on DVB_CORE && PCI && I2C
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select DVB_PLL
5 select DVB_TDA1004X 6 select DVB_TDA1004X
6 help 7 help
7 Support for PCI cards based on the Pluto2 FPGA like the Satelco 8 Support for PCI cards based on the Pluto2 FPGA like the Satelco
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
index 987881fa988c..5fb097595cfb 100644
--- a/drivers/media/dvb/ttpci/Kconfig
+++ b/drivers/media/dvb/ttpci/Kconfig
@@ -3,6 +3,7 @@ config DVB_AV7110
3 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1 3 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1
4 select FW_LOADER 4 select FW_LOADER
5 select VIDEO_SAA7146_VV 5 select VIDEO_SAA7146_VV
6 select DVB_PLL
6 select DVB_VES1820 7 select DVB_VES1820
7 select DVB_VES1X93 8 select DVB_VES1X93
8 select DVB_STV0299 9 select DVB_STV0299
@@ -61,6 +62,7 @@ config DVB_BUDGET
61 tristate "Budget cards" 62 tristate "Budget cards"
62 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1 63 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1
63 select VIDEO_SAA7146 64 select VIDEO_SAA7146
65 select DVB_PLL
64 select DVB_STV0299 66 select DVB_STV0299
65 select DVB_VES1X93 67 select DVB_VES1X93
66 select DVB_VES1820 68 select DVB_VES1820
@@ -83,6 +85,7 @@ config DVB_BUDGET_CI
83 tristate "Budget cards with onboard CI connector" 85 tristate "Budget cards with onboard CI connector"
84 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1 86 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1
85 select VIDEO_SAA7146 87 select VIDEO_SAA7146
88 select DVB_PLL
86 select DVB_STV0297 89 select DVB_STV0297
87 select DVB_STV0299 90 select DVB_STV0299
88 select DVB_TDA1004X 91 select DVB_TDA1004X
@@ -104,6 +107,7 @@ config DVB_BUDGET_AV
104 tristate "Budget cards with analog video inputs" 107 tristate "Budget cards with analog video inputs"
105 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1 108 depends on DVB_CORE && PCI && I2C && VIDEO_V4L1
106 select VIDEO_SAA7146_VV 109 select VIDEO_SAA7146_VV
110 select DVB_PLL
107 select DVB_STV0299 111 select DVB_STV0299
108 select DVB_TDA1004X 112 select DVB_TDA1004X
109 select DVB_TDA10021 113 select DVB_TDA10021
@@ -122,6 +126,7 @@ config DVB_BUDGET_PATCH
122 tristate "AV7110 cards with Budget Patch" 126 tristate "AV7110 cards with Budget Patch"
123 depends on DVB_CORE && DVB_BUDGET && VIDEO_V4L1 127 depends on DVB_CORE && DVB_BUDGET && VIDEO_V4L1
124 select DVB_AV7110 128 select DVB_AV7110
129 select DVB_PLL
125 select DVB_STV0299 130 select DVB_STV0299
126 select DVB_VES1X93 131 select DVB_VES1X93
127 select DVB_TDA8083 132 select DVB_TDA8083
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 500f15c10aaf..4506165c5de2 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -2203,8 +2203,8 @@ static int frontend_init(struct av7110 *av7110)
2203 av7110->fe->ops.tuner_ops.set_params = nexusca_stv0297_tuner_set_params; 2203 av7110->fe->ops.tuner_ops.set_params = nexusca_stv0297_tuner_set_params;
2204 2204
2205 /* set TDA9819 into DVB mode */ 2205 /* set TDA9819 into DVB mode */
2206 saa7146_setgpio(av7110->dev, 1, SAA7146_GPIO_OUTLO); // TDA9198 pin9(STD) 2206 saa7146_setgpio(av7110->dev, 1, SAA7146_GPIO_OUTLO); // TDA9819 pin9(STD)
2207 saa7146_setgpio(av7110->dev, 3, SAA7146_GPIO_OUTLO); // TDA9198 pin30(VIF) 2207 saa7146_setgpio(av7110->dev, 3, SAA7146_GPIO_OUTLO); // TDA9819 pin30(VIF)
2208 2208
2209 /* tuner on this needs a slower i2c bus speed */ 2209 /* tuner on this needs a slower i2c bus speed */
2210 av7110->dev->i2c_bitrate = SAA7146_I2C_BUS_BIT_RATE_240; 2210 av7110->dev->i2c_bitrate = SAA7146_I2C_BUS_BIT_RATE_240;
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index 64055461559d..6ffe53fdcf57 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -272,8 +272,8 @@ static int av7110_dvb_c_switch(struct saa7146_fh *fh)
272 if (ves1820_writereg(dev, 0x09, 0x0f, 0x60)) 272 if (ves1820_writereg(dev, 0x09, 0x0f, 0x60))
273 dprintk(1, "setting band in demodulator failed.\n"); 273 dprintk(1, "setting band in demodulator failed.\n");
274 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) { 274 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
275 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // TDA9198 pin9(STD) 275 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // TDA9819 pin9(STD)
276 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI); // TDA9198 pin30(VIF) 276 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI); // TDA9819 pin30(VIF)
277 } 277 }
278 if (i2c_writereg(av7110, 0x48, 0x02, 0xd0) != 1) 278 if (i2c_writereg(av7110, 0x48, 0x02, 0xd0) != 1)
279 dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num); 279 dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
@@ -308,8 +308,8 @@ static int av7110_dvb_c_switch(struct saa7146_fh *fh)
308 if (ves1820_writereg(dev, 0x09, 0x0f, 0x20)) 308 if (ves1820_writereg(dev, 0x09, 0x0f, 0x20))
309 dprintk(1, "setting band in demodulator failed.\n"); 309 dprintk(1, "setting band in demodulator failed.\n");
310 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) { 310 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
311 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO); // TDA9198 pin9(STD) 311 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO); // TDA9819 pin9(STD)
312 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); // TDA9198 pin30(VIF) 312 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); // TDA9819 pin30(VIF)
313 } 313 }
314 } 314 }
315 315
@@ -750,8 +750,8 @@ int av7110_init_analog_module(struct av7110 *av7110)
750 if (ves1820_writereg(av7110->dev, 0x09, 0x0f, 0x20)) 750 if (ves1820_writereg(av7110->dev, 0x09, 0x0f, 0x20))
751 dprintk(1, "setting band in demodulator failed.\n"); 751 dprintk(1, "setting band in demodulator failed.\n");
752 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) { 752 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
753 saa7146_setgpio(av7110->dev, 1, SAA7146_GPIO_OUTLO); // TDA9198 pin9(STD) 753 saa7146_setgpio(av7110->dev, 1, SAA7146_GPIO_OUTLO); // TDA9819 pin9(STD)
754 saa7146_setgpio(av7110->dev, 3, SAA7146_GPIO_OUTLO); // TDA9198 pin30(VIF) 754 saa7146_setgpio(av7110->dev, 3, SAA7146_GPIO_OUTLO); // TDA9819 pin30(VIF)
755 } 755 }
756 756
757 /* init the saa7113 */ 757 /* init the saa7113 */
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 5f111d407730..2d21fec23b4d 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -1303,6 +1303,9 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
1303 budget_av->budget.dvb_adapter.priv = budget_av; 1303 budget_av->budget.dvb_adapter.priv = budget_av;
1304 frontend_init(budget_av); 1304 frontend_init(budget_av);
1305 ciintf_init(budget_av); 1305 ciintf_init(budget_av);
1306
1307 ttpci_budget_init_hooks(&budget_av->budget);
1308
1306 return 0; 1309 return 0;
1307} 1310}
1308 1311
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index 4b966eea3834..ffbbb3e34be4 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -1101,6 +1101,8 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
1101 budget_ci->budget.dvb_adapter.priv = budget_ci; 1101 budget_ci->budget.dvb_adapter.priv = budget_ci;
1102 frontend_init(budget_ci); 1102 frontend_init(budget_ci);
1103 1103
1104 ttpci_budget_init_hooks(&budget_ci->budget);
1105
1104 return 0; 1106 return 0;
1105} 1107}
1106 1108
diff --git a/drivers/media/dvb/ttpci/budget-core.c b/drivers/media/dvb/ttpci/budget-core.c
index e4cf7775e07f..e15562f81664 100644
--- a/drivers/media/dvb/ttpci/budget-core.c
+++ b/drivers/media/dvb/ttpci/budget-core.c
@@ -63,9 +63,6 @@ static int stop_ts_capture(struct budget *budget)
63{ 63{
64 dprintk(2, "budget: %p\n", budget); 64 dprintk(2, "budget: %p\n", budget);
65 65
66 if (--budget->feeding)
67 return budget->feeding;
68
69 saa7146_write(budget->dev, MC1, MASK_20); // DMA3 off 66 saa7146_write(budget->dev, MC1, MASK_20); // DMA3 off
70 SAA7146_IER_DISABLE(budget->dev, MASK_10); 67 SAA7146_IER_DISABLE(budget->dev, MASK_10);
71 return 0; 68 return 0;
@@ -77,8 +74,8 @@ static int start_ts_capture(struct budget *budget)
77 74
78 dprintk(2, "budget: %p\n", budget); 75 dprintk(2, "budget: %p\n", budget);
79 76
80 if (budget->feeding) 77 if (!budget->feeding || !budget->fe_synced)
81 return ++budget->feeding; 78 return 0;
82 79
83 saa7146_write(dev, MC1, MASK_20); // DMA3 off 80 saa7146_write(dev, MC1, MASK_20); // DMA3 off
84 81
@@ -139,7 +136,33 @@ static int start_ts_capture(struct budget *budget)
139 SAA7146_IER_ENABLE(budget->dev, MASK_10); /* VPE */ 136 SAA7146_IER_ENABLE(budget->dev, MASK_10); /* VPE */
140 saa7146_write(dev, MC1, (MASK_04 | MASK_20)); /* DMA3 on */ 137 saa7146_write(dev, MC1, (MASK_04 | MASK_20)); /* DMA3 on */
141 138
142 return ++budget->feeding; 139 return 0;
140}
141
142static int budget_read_fe_status(struct dvb_frontend *fe, fe_status_t *status)
143{
144 struct budget *budget = (struct budget *) fe->dvb->priv;
145 int synced;
146 int ret;
147
148 if (budget->read_fe_status)
149 ret = budget->read_fe_status(fe, status);
150 else
151 ret = -EINVAL;
152
153 if (!ret) {
154 synced = (*status & FE_HAS_LOCK);
155 if (synced != budget->fe_synced) {
156 budget->fe_synced = synced;
157 spin_lock(&budget->feedlock);
158 if (synced)
159 start_ts_capture(budget);
160 else
161 stop_ts_capture(budget);
162 spin_unlock(&budget->feedlock);
163 }
164 }
165 return ret;
143} 166}
144 167
145static void vpeirq(unsigned long data) 168static void vpeirq(unsigned long data)
@@ -267,7 +290,7 @@ static int budget_start_feed(struct dvb_demux_feed *feed)
267{ 290{
268 struct dvb_demux *demux = feed->demux; 291 struct dvb_demux *demux = feed->demux;
269 struct budget *budget = (struct budget *) demux->priv; 292 struct budget *budget = (struct budget *) demux->priv;
270 int status; 293 int status = 0;
271 294
272 dprintk(2, "budget: %p\n", budget); 295 dprintk(2, "budget: %p\n", budget);
273 296
@@ -276,7 +299,8 @@ static int budget_start_feed(struct dvb_demux_feed *feed)
276 299
277 spin_lock(&budget->feedlock); 300 spin_lock(&budget->feedlock);
278 feed->pusi_seen = 0; /* have a clean section start */ 301 feed->pusi_seen = 0; /* have a clean section start */
279 status = start_ts_capture(budget); 302 if (budget->feeding++ == 0)
303 status = start_ts_capture(budget);
280 spin_unlock(&budget->feedlock); 304 spin_unlock(&budget->feedlock);
281 return status; 305 return status;
282} 306}
@@ -285,12 +309,13 @@ static int budget_stop_feed(struct dvb_demux_feed *feed)
285{ 309{
286 struct dvb_demux *demux = feed->demux; 310 struct dvb_demux *demux = feed->demux;
287 struct budget *budget = (struct budget *) demux->priv; 311 struct budget *budget = (struct budget *) demux->priv;
288 int status; 312 int status = 0;
289 313
290 dprintk(2, "budget: %p\n", budget); 314 dprintk(2, "budget: %p\n", budget);
291 315
292 spin_lock(&budget->feedlock); 316 spin_lock(&budget->feedlock);
293 status = stop_ts_capture(budget); 317 if (--budget->feeding == 0)
318 status = stop_ts_capture(budget);
294 spin_unlock(&budget->feedlock); 319 spin_unlock(&budget->feedlock);
295 return status; 320 return status;
296} 321}
@@ -470,6 +495,14 @@ err:
470 return ret; 495 return ret;
471} 496}
472 497
498void ttpci_budget_init_hooks(struct budget *budget)
499{
500 if (budget->dvb_frontend && !budget->read_fe_status) {
501 budget->read_fe_status = budget->dvb_frontend->ops.read_status;
502 budget->dvb_frontend->ops.read_status = budget_read_fe_status;
503 }
504}
505
473int ttpci_budget_deinit(struct budget *budget) 506int ttpci_budget_deinit(struct budget *budget)
474{ 507{
475 struct saa7146_dev *dev = budget->dev; 508 struct saa7146_dev *dev = budget->dev;
@@ -508,11 +541,8 @@ void ttpci_budget_set_video_port(struct saa7146_dev *dev, int video_port)
508 spin_lock(&budget->feedlock); 541 spin_lock(&budget->feedlock);
509 budget->video_port = video_port; 542 budget->video_port = video_port;
510 if (budget->feeding) { 543 if (budget->feeding) {
511 int oldfeeding = budget->feeding;
512 budget->feeding = 1;
513 stop_ts_capture(budget); 544 stop_ts_capture(budget);
514 start_ts_capture(budget); 545 start_ts_capture(budget);
515 budget->feeding = oldfeeding;
516 } 546 }
517 spin_unlock(&budget->feedlock); 547 spin_unlock(&budget->feedlock);
518} 548}
@@ -520,6 +550,7 @@ void ttpci_budget_set_video_port(struct saa7146_dev *dev, int video_port)
520EXPORT_SYMBOL_GPL(ttpci_budget_debiread); 550EXPORT_SYMBOL_GPL(ttpci_budget_debiread);
521EXPORT_SYMBOL_GPL(ttpci_budget_debiwrite); 551EXPORT_SYMBOL_GPL(ttpci_budget_debiwrite);
522EXPORT_SYMBOL_GPL(ttpci_budget_init); 552EXPORT_SYMBOL_GPL(ttpci_budget_init);
553EXPORT_SYMBOL_GPL(ttpci_budget_init_hooks);
523EXPORT_SYMBOL_GPL(ttpci_budget_deinit); 554EXPORT_SYMBOL_GPL(ttpci_budget_deinit);
524EXPORT_SYMBOL_GPL(ttpci_budget_irq10_handler); 555EXPORT_SYMBOL_GPL(ttpci_budget_irq10_handler);
525EXPORT_SYMBOL_GPL(ttpci_budget_set_video_port); 556EXPORT_SYMBOL_GPL(ttpci_budget_set_video_port);
diff --git a/drivers/media/dvb/ttpci/budget-patch.c b/drivers/media/dvb/ttpci/budget-patch.c
index ee60ce90a400..57227441891e 100644
--- a/drivers/media/dvb/ttpci/budget-patch.c
+++ b/drivers/media/dvb/ttpci/budget-patch.c
@@ -617,6 +617,8 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
617 budget->dvb_adapter.priv = budget; 617 budget->dvb_adapter.priv = budget;
618 frontend_init(budget); 618 frontend_init(budget);
619 619
620 ttpci_budget_init_hooks(budget);
621
620 return 0; 622 return 0;
621} 623}
622 624
diff --git a/drivers/media/dvb/ttpci/budget.c b/drivers/media/dvb/ttpci/budget.c
index 35761f13c12b..863dffb4ed8e 100644
--- a/drivers/media/dvb/ttpci/budget.c
+++ b/drivers/media/dvb/ttpci/budget.c
@@ -375,9 +375,6 @@ static void frontend_init(struct budget *budget)
375 if (budget->dvb_frontend) { 375 if (budget->dvb_frontend) {
376 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params; 376 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
377 budget->dvb_frontend->tuner_priv = &budget->i2c_adap; 377 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
378 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
379 budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
380 budget->dvb_frontend->ops.set_tone = budget_set_tone;
381 break; 378 break;
382 } 379 }
383 break; 380 break;
@@ -474,6 +471,8 @@ static int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_
474 budget->dvb_adapter.priv = budget; 471 budget->dvb_adapter.priv = budget;
475 frontend_init(budget); 472 frontend_init(budget);
476 473
474 ttpci_budget_init_hooks(budget);
475
477 return 0; 476 return 0;
478} 477}
479 478
diff --git a/drivers/media/dvb/ttpci/budget.h b/drivers/media/dvb/ttpci/budget.h
index ecea3a13030e..e8a5c79178e1 100644
--- a/drivers/media/dvb/ttpci/budget.h
+++ b/drivers/media/dvb/ttpci/budget.h
@@ -52,9 +52,6 @@ struct budget {
52 struct dmx_frontend hw_frontend; 52 struct dmx_frontend hw_frontend;
53 struct dmx_frontend mem_frontend; 53 struct dmx_frontend mem_frontend;
54 54
55 int fe_synced;
56 struct mutex pid_mutex;
57
58 int ci_present; 55 int ci_present;
59 int video_port; 56 int video_port;
60 57
@@ -74,6 +71,9 @@ struct budget {
74 71
75 struct dvb_adapter dvb_adapter; 72 struct dvb_adapter dvb_adapter;
76 struct dvb_frontend *dvb_frontend; 73 struct dvb_frontend *dvb_frontend;
74 int (*read_fe_status)(struct dvb_frontend *fe, fe_status_t *status);
75 int fe_synced;
76
77 void *priv; 77 void *priv;
78}; 78};
79 79
@@ -106,6 +106,7 @@ static struct saa7146_pci_extension_data x_var = { \
106extern int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev, 106extern int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
107 struct saa7146_pci_extension_data *info, 107 struct saa7146_pci_extension_data *info,
108 struct module *owner); 108 struct module *owner);
109extern void ttpci_budget_init_hooks(struct budget *budget);
109extern int ttpci_budget_deinit(struct budget *budget); 110extern int ttpci_budget_deinit(struct budget *budget);
110extern void ttpci_budget_irq10_handler(struct saa7146_dev *dev, u32 * isr); 111extern void ttpci_budget_irq10_handler(struct saa7146_dev *dev, u32 * isr);
111extern void ttpci_budget_set_video_port(struct saa7146_dev *dev, int video_port); 112extern void ttpci_budget_set_video_port(struct saa7146_dev *dev, int video_port);
diff --git a/drivers/media/dvb/ttusb-budget/Kconfig b/drivers/media/dvb/ttusb-budget/Kconfig
index 92c7cdcf8981..46a6a60d2ab9 100644
--- a/drivers/media/dvb/ttusb-budget/Kconfig
+++ b/drivers/media/dvb/ttusb-budget/Kconfig
@@ -1,6 +1,7 @@
1config DVB_TTUSB_BUDGET 1config DVB_TTUSB_BUDGET
2 tristate "Technotrend/Hauppauge Nova-USB devices" 2 tristate "Technotrend/Hauppauge Nova-USB devices"
3 depends on DVB_CORE && USB 3 depends on DVB_CORE && USB && I2C
4 select DVB_PLL
4 select DVB_CX22700 5 select DVB_CX22700
5 select DVB_TDA1004X 6 select DVB_TDA1004X
6 select DVB_VES1820 7 select DVB_VES1820
diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index de3128a31de8..220076b1b956 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -350,5 +350,15 @@ config RADIO_ZOLTRIX_PORT
350 help 350 help
351 Enter the I/O port of your Zoltrix radio card. 351 Enter the I/O port of your Zoltrix radio card.
352 352
353endmenu 353config USB_DSBR
354 tristate "D-Link USB FM radio support (EXPERIMENTAL)"
355 depends on USB && VIDEO_V4L1 && EXPERIMENTAL
356 ---help---
357 Say Y here if you want to connect this type of radio to your
358 computer's USB port. Note that the audio is not digital, and
359 you must connect the line out connector to a sound card or a
360 set of speakers.
354 361
362 To compile this driver as a module, choose M here: the
363 module will be called dsbr100.
364endmenu
diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
index e95b6805e002..cf55a18e3ddf 100644
--- a/drivers/media/radio/Makefile
+++ b/drivers/media/radio/Makefile
@@ -20,5 +20,6 @@ obj-$(CONFIG_RADIO_GEMTEK) += radio-gemtek.o
20obj-$(CONFIG_RADIO_GEMTEK_PCI) += radio-gemtek-pci.o 20obj-$(CONFIG_RADIO_GEMTEK_PCI) += radio-gemtek-pci.o
21obj-$(CONFIG_RADIO_TRUST) += radio-trust.o 21obj-$(CONFIG_RADIO_TRUST) += radio-trust.o
22obj-$(CONFIG_RADIO_MAESTRO) += radio-maestro.o 22obj-$(CONFIG_RADIO_MAESTRO) += radio-maestro.o
23obj-$(CONFIG_USB_DSBR) += dsbr100.o
23 24
24EXTRA_CFLAGS += -Isound 25EXTRA_CFLAGS += -Isound
diff --git a/drivers/media/video/dsbr100.c b/drivers/media/radio/dsbr100.c
index f7e33f9ee8e9..f7e33f9ee8e9 100644
--- a/drivers/media/video/dsbr100.c
+++ b/drivers/media/radio/dsbr100.c
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 6d532f170ce5..94d078b77bab 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -145,7 +145,7 @@ config VIDEO_SAA5246A
145 145
146config VIDEO_SAA5249 146config VIDEO_SAA5249
147 tristate "SAA5249 Teletext processor" 147 tristate "SAA5249 Teletext processor"
148 depends on VIDEO_DEV && I2C 148 depends on VIDEO_DEV && I2C && VIDEO_V4L1
149 help 149 help
150 Support for I2C bus based teletext using the SAA5249 chip. At the 150 Support for I2C bus based teletext using the SAA5249 chip. At the
151 moment this is only useful on some European WinTV cards. 151 moment this is only useful on some European WinTV cards.
@@ -155,7 +155,7 @@ config VIDEO_SAA5249
155 155
156config TUNER_3036 156config TUNER_3036
157 tristate "SAB3036 tuner" 157 tristate "SAB3036 tuner"
158 depends on VIDEO_DEV && I2C 158 depends on VIDEO_DEV && I2C && VIDEO_V4L1
159 help 159 help
160 Say Y here to include support for Philips SAB3036 compatible tuners. 160 Say Y here to include support for Philips SAB3036 compatible tuners.
161 If in doubt, say N. 161 If in doubt, say N.
@@ -260,7 +260,7 @@ source "drivers/media/video/saa7134/Kconfig"
260 260
261config VIDEO_MXB 261config VIDEO_MXB
262 tristate "Siemens-Nixdorf 'Multimedia eXtension Board'" 262 tristate "Siemens-Nixdorf 'Multimedia eXtension Board'"
263 depends on PCI && VIDEO_V4L1 263 depends on PCI && VIDEO_V4L1 && I2C
264 select VIDEO_SAA7146_VV 264 select VIDEO_SAA7146_VV
265 select VIDEO_TUNER 265 select VIDEO_TUNER
266 ---help--- 266 ---help---
@@ -272,7 +272,7 @@ config VIDEO_MXB
272 272
273config VIDEO_DPC 273config VIDEO_DPC
274 tristate "Philips-Semiconductors 'dpc7146 demonstration board'" 274 tristate "Philips-Semiconductors 'dpc7146 demonstration board'"
275 depends on PCI && VIDEO_V4L1 275 depends on PCI && VIDEO_V4L1 && I2C
276 select VIDEO_SAA7146_VV 276 select VIDEO_SAA7146_VV
277 select VIDEO_V4L2 277 select VIDEO_V4L2
278 ---help--- 278 ---help---
@@ -287,7 +287,7 @@ config VIDEO_DPC
287 287
288config VIDEO_HEXIUM_ORION 288config VIDEO_HEXIUM_ORION
289 tristate "Hexium HV-PCI6 and Orion frame grabber" 289 tristate "Hexium HV-PCI6 and Orion frame grabber"
290 depends on PCI && VIDEO_V4L1 290 depends on PCI && VIDEO_V4L1 && I2C
291 select VIDEO_SAA7146_VV 291 select VIDEO_SAA7146_VV
292 select VIDEO_V4L2 292 select VIDEO_V4L2
293 ---help--- 293 ---help---
@@ -299,7 +299,7 @@ config VIDEO_HEXIUM_ORION
299 299
300config VIDEO_HEXIUM_GEMINI 300config VIDEO_HEXIUM_GEMINI
301 tristate "Hexium Gemini frame grabber" 301 tristate "Hexium Gemini frame grabber"
302 depends on PCI && VIDEO_V4L1 302 depends on PCI && VIDEO_V4L1 && I2C
303 select VIDEO_SAA7146_VV 303 select VIDEO_SAA7146_VV
304 select VIDEO_V4L2 304 select VIDEO_V4L2
305 ---help--- 305 ---help---
@@ -449,18 +449,6 @@ source "drivers/media/video/pvrusb2/Kconfig"
449 449
450source "drivers/media/video/em28xx/Kconfig" 450source "drivers/media/video/em28xx/Kconfig"
451 451
452config USB_DSBR
453 tristate "D-Link USB FM radio support (EXPERIMENTAL)"
454 depends on USB && VIDEO_V4L1 && EXPERIMENTAL
455 ---help---
456 Say Y here if you want to connect this type of radio to your
457 computer's USB port. Note that the audio is not digital, and
458 you must connect the line out connector to a sound card or a
459 set of speakers.
460
461 To compile this driver as a module, choose M here: the
462 module will be called dsbr100.
463
464source "drivers/media/video/usbvideo/Kconfig" 452source "drivers/media/video/usbvideo/Kconfig"
465 453
466source "drivers/media/video/et61x251/Kconfig" 454source "drivers/media/video/et61x251/Kconfig"
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 353d61cfac1b..e82e511f2a72 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -77,7 +77,6 @@ obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o
77obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o 77obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o
78 78
79obj-$(CONFIG_USB_DABUSB) += dabusb.o 79obj-$(CONFIG_USB_DABUSB) += dabusb.o
80obj-$(CONFIG_USB_DSBR) += dsbr100.o
81obj-$(CONFIG_USB_OV511) += ov511.o 80obj-$(CONFIG_USB_OV511) += ov511.o
82obj-$(CONFIG_USB_SE401) += se401.o 81obj-$(CONFIG_USB_SE401) += se401.o
83obj-$(CONFIG_USB_STV680) += stv680.o 82obj-$(CONFIG_USB_STV680) += stv680.o
@@ -91,6 +90,7 @@ obj-$(CONFIG_USB_ZC0301) += zc0301/
91obj-$(CONFIG_USB_IBMCAM) += usbvideo/ 90obj-$(CONFIG_USB_IBMCAM) += usbvideo/
92obj-$(CONFIG_USB_KONICAWC) += usbvideo/ 91obj-$(CONFIG_USB_KONICAWC) += usbvideo/
93obj-$(CONFIG_USB_VICAM) += usbvideo/ 92obj-$(CONFIG_USB_VICAM) += usbvideo/
93obj-$(CONFIG_USB_QUICKCAM_MESSENGER) += usbvideo/
94 94
95obj-$(CONFIG_VIDEO_VIVI) += vivi.o 95obj-$(CONFIG_VIDEO_VIVI) += vivi.o
96 96
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
index 153f6a4a96c9..cdcf55650714 100644
--- a/drivers/media/video/bt8xx/Kconfig
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_BT848 1config VIDEO_BT848
2 tristate "BT848 Video For Linux" 2 tristate "BT848 Video For Linux"
3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L2 3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L1
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select FW_LOADER 5 select FW_LOADER
6 select VIDEO_BTCX 6 select VIDEO_BTCX
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 5764a89d3562..20dff7c316eb 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -3923,7 +3923,12 @@ static int __devinit bttv_register_video(struct bttv *btv)
3923 goto err; 3923 goto err;
3924 printk(KERN_INFO "bttv%d: registered device video%d\n", 3924 printk(KERN_INFO "bttv%d: registered device video%d\n",
3925 btv->c.nr,btv->video_dev->minor & 0x1f); 3925 btv->c.nr,btv->video_dev->minor & 0x1f);
3926 video_device_create_file(btv->video_dev, &class_device_attr_card); 3926 if (class_device_create_file(&btv->video_dev->class_dev,
3927 &class_device_attr_card)<0) {
3928 printk(KERN_ERR "bttv%d: class_device_create_file 'card' "
3929 "failed\n", btv->c.nr);
3930 goto err;
3931 }
3927 3932
3928 /* vbi */ 3933 /* vbi */
3929 btv->vbi_dev = vdev_init(btv, &bttv_vbi_template, "vbi"); 3934 btv->vbi_dev = vdev_init(btv, &bttv_vbi_template, "vbi");
@@ -4287,6 +4292,8 @@ static struct pci_driver bttv_pci_driver = {
4287 4292
4288static int bttv_init_module(void) 4293static int bttv_init_module(void)
4289{ 4294{
4295 int ret;
4296
4290 bttv_num = 0; 4297 bttv_num = 0;
4291 4298
4292 printk(KERN_INFO "bttv: driver version %d.%d.%d loaded\n", 4299 printk(KERN_INFO "bttv: driver version %d.%d.%d loaded\n",
@@ -4308,7 +4315,11 @@ static int bttv_init_module(void)
4308 4315
4309 bttv_check_chipset(); 4316 bttv_check_chipset();
4310 4317
4311 bus_register(&bttv_sub_bus_type); 4318 ret = bus_register(&bttv_sub_bus_type);
4319 if (ret < 0) {
4320 printk(KERN_WARNING "bttv: bus_register error: %d\n", ret);
4321 return ret;
4322 }
4312 return pci_register_driver(&bttv_pci_driver); 4323 return pci_register_driver(&bttv_pci_driver);
4313} 4324}
4314 4325
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index b41f81d2372c..933d6db09acb 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -303,6 +303,7 @@ int bttv_input_init(struct bttv *btv)
303 ir->mask_keyup = 0x010000; 303 ir->mask_keyup = 0x010000;
304 ir->polling = 50; // ms 304 ir->polling = 50; // ms
305 break; 305 break;
306 case BTTV_BOARD_PV_M4900:
306 case BTTV_BOARD_PV_BT878P_9B: 307 case BTTV_BOARD_PV_BT878P_9B:
307 case BTTV_BOARD_PV_BT878P_PLUS: 308 case BTTV_BOARD_PV_BT878P_PLUS:
308 ir_codes = ir_codes_pixelview; 309 ir_codes = ir_codes_pixelview;
diff --git a/drivers/media/video/bt8xx/bttv-vbi.c b/drivers/media/video/bt8xx/bttv-vbi.c
index 8c9f0f7cf467..63676e7bd635 100644
--- a/drivers/media/video/bt8xx/bttv-vbi.c
+++ b/drivers/media/video/bt8xx/bttv-vbi.c
@@ -31,11 +31,16 @@
31#include <asm/io.h> 31#include <asm/io.h>
32#include "bttvp.h" 32#include "bttvp.h"
33 33
34/* Offset from line sync pulse leading edge (0H) in 1 / sampling_rate: 34/* Offset from line sync pulse leading edge (0H) to start of VBI capture,
35 bt8x8 /HRESET pulse starts at 0H and has length 64 / fCLKx1 (E|O_VTC 35 in fCLKx2 pixels. According to the datasheet, VBI capture starts
36 HSFMT = 0). VBI_HDELAY (always 0) is an offset from the trailing edge 36 VBI_HDELAY fCLKx1 pixels from the tailing edgeof /HRESET, and /HRESET
37 of /HRESET in 1 / fCLKx1, and the sampling_rate tvnorm->Fsc is fCLKx2. */ 37 is 64 fCLKx1 pixels wide. VBI_HDELAY is set to 0, so this should be
38#define VBI_OFFSET ((64 + 0) * 2) 38 (64 + 0) * 2 = 128 fCLKx2 pixels. But it's not! The datasheet is
39 Just Plain Wrong. The real value appears to be different for
40 different revisions of the bt8x8 chips, and to be affected by the
41 horizontal scaling factor. Experimentally, the value is measured
42 to be about 244. */
43#define VBI_OFFSET 244
39 44
40#define VBI_DEFLINES 16 45#define VBI_DEFLINES 16
41#define VBI_MAXLINES 32 46#define VBI_MAXLINES 32
diff --git a/drivers/media/video/compat_ioctl32.c b/drivers/media/video/compat_ioctl32.c
index 353d02b67c33..b69ee1194815 100644
--- a/drivers/media/video/compat_ioctl32.c
+++ b/drivers/media/video/compat_ioctl32.c
@@ -21,7 +21,7 @@
21 21
22#ifdef CONFIG_COMPAT 22#ifdef CONFIG_COMPAT
23 23
24 24#ifdef CONFIG_VIDEO_V4L1_COMPAT
25struct video_tuner32 { 25struct video_tuner32 {
26 compat_int_t tuner; 26 compat_int_t tuner;
27 char name[32]; 27 char name[32];
@@ -107,6 +107,7 @@ struct video_window32 {
107 compat_caddr_t clips; 107 compat_caddr_t clips;
108 compat_int_t clipcount; 108 compat_int_t clipcount;
109}; 109};
110#endif
110 111
111static int native_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 112static int native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
112{ 113{
@@ -124,6 +125,7 @@ static int native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
124} 125}
125 126
126 127
128#ifdef CONFIG_VIDEO_V4L1_COMPAT
127/* You get back everything except the clips... */ 129/* You get back everything except the clips... */
128static int put_video_window32(struct video_window *kp, struct video_window32 __user *up) 130static int put_video_window32(struct video_window *kp, struct video_window32 __user *up)
129{ 131{
@@ -138,6 +140,7 @@ static int put_video_window32(struct video_window *kp, struct video_window32 __u
138 return -EFAULT; 140 return -EFAULT;
139 return 0; 141 return 0;
140} 142}
143#endif
141 144
142struct v4l2_clip32 145struct v4l2_clip32
143{ 146{
@@ -490,6 +493,24 @@ static inline int put_v4l2_input(struct v4l2_input *kp, struct v4l2_input __user
490 return 0; 493 return 0;
491} 494}
492 495
496#ifdef CONFIG_VIDEO_V4L1_COMPAT
497struct video_code32
498{
499 char loadwhat[16]; /* name or tag of file being passed */
500 compat_int_t datasize;
501 unsigned char *data;
502};
503
504static inline int microcode32(struct video_code *kp, struct video_code32 __user *up)
505{
506 if(!access_ok(VERIFY_READ, up, sizeof(struct video_code32)) ||
507 copy_from_user(kp->loadwhat, up->loadwhat, sizeof (up->loadwhat)) ||
508 get_user(kp->datasize, &up->datasize) ||
509 copy_from_user(kp->data, up->data, up->datasize))
510 return -EFAULT;
511 return 0;
512}
513
493#define VIDIOCGTUNER32 _IOWR('v',4, struct video_tuner32) 514#define VIDIOCGTUNER32 _IOWR('v',4, struct video_tuner32)
494#define VIDIOCSTUNER32 _IOW('v',5, struct video_tuner32) 515#define VIDIOCSTUNER32 _IOW('v',5, struct video_tuner32)
495#define VIDIOCGWIN32 _IOR('v',9, struct video_window32) 516#define VIDIOCGWIN32 _IOR('v',9, struct video_window32)
@@ -498,6 +519,9 @@ static inline int put_v4l2_input(struct v4l2_input *kp, struct v4l2_input __user
498#define VIDIOCSFBUF32 _IOW('v',12, struct video_buffer32) 519#define VIDIOCSFBUF32 _IOW('v',12, struct video_buffer32)
499#define VIDIOCGFREQ32 _IOR('v',14, u32) 520#define VIDIOCGFREQ32 _IOR('v',14, u32)
500#define VIDIOCSFREQ32 _IOW('v',15, u32) 521#define VIDIOCSFREQ32 _IOW('v',15, u32)
522#define VIDIOCSMICROCODE32 _IOW('v',27, struct video_code32)
523
524#endif
501 525
502/* VIDIOC_ENUMINPUT32 is VIDIOC_ENUMINPUT minus 4 bytes of padding alignement */ 526/* VIDIOC_ENUMINPUT32 is VIDIOC_ENUMINPUT minus 4 bytes of padding alignement */
503#define VIDIOC_ENUMINPUT32 VIDIOC_ENUMINPUT - _IOC(0, 0, 0, 4) 527#define VIDIOC_ENUMINPUT32 VIDIOC_ENUMINPUT - _IOC(0, 0, 0, 4)
@@ -519,6 +543,7 @@ static inline int put_v4l2_input(struct v4l2_input *kp, struct v4l2_input __user
519#define VIDIOC_S_INPUT32 _IOWR ('V', 39, compat_int_t) 543#define VIDIOC_S_INPUT32 _IOWR ('V', 39, compat_int_t)
520#define VIDIOC_TRY_FMT32 _IOWR ('V', 64, struct v4l2_format32) 544#define VIDIOC_TRY_FMT32 _IOWR ('V', 64, struct v4l2_format32)
521 545
546#ifdef CONFIG_VIDEO_V4L1_COMPAT
522enum { 547enum {
523 MaxClips = (~0U-sizeof(struct video_window))/sizeof(struct video_clip) 548 MaxClips = (~0U-sizeof(struct video_window))/sizeof(struct video_clip)
524}; 549};
@@ -583,13 +608,17 @@ static int do_set_window(struct file *file, unsigned int cmd, unsigned long arg)
583 608
584 return native_ioctl(file, VIDIOCSWIN, (unsigned long)vw); 609 return native_ioctl(file, VIDIOCSWIN, (unsigned long)vw);
585} 610}
611#endif
586 612
587static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 613static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
588{ 614{
589 union { 615 union {
616#ifdef CONFIG_VIDEO_V4L1_COMPAT
590 struct video_tuner vt; 617 struct video_tuner vt;
591 struct video_buffer vb; 618 struct video_buffer vb;
592 struct video_window vw; 619 struct video_window vw;
620 struct video_code vc;
621#endif
593 struct v4l2_format v2f; 622 struct v4l2_format v2f;
594 struct v4l2_buffer v2b; 623 struct v4l2_buffer v2b;
595 struct v4l2_framebuffer v2fb; 624 struct v4l2_framebuffer v2fb;
@@ -605,6 +634,7 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
605 634
606 /* First, convert the command. */ 635 /* First, convert the command. */
607 switch(cmd) { 636 switch(cmd) {
637#ifdef CONFIG_VIDEO_V4L1_COMPAT
608 case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break; 638 case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break;
609 case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break; 639 case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break;
610 case VIDIOCGWIN32: cmd = VIDIOCGWIN; break; 640 case VIDIOCGWIN32: cmd = VIDIOCGWIN; break;
@@ -612,6 +642,8 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
612 case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break; 642 case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break;
613 case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break; 643 case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break;
614 case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break; 644 case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break;
645 case VIDIOCSMICROCODE32: cmd = VIDIOCSMICROCODE; break;
646#endif
615 case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break; 647 case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break;
616 case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break; 648 case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break;
617 case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break; 649 case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break;
@@ -631,6 +663,7 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
631 }; 663 };
632 664
633 switch(cmd) { 665 switch(cmd) {
666#ifdef CONFIG_VIDEO_V4L1_COMPAT
634 case VIDIOCSTUNER: 667 case VIDIOCSTUNER:
635 case VIDIOCGTUNER: 668 case VIDIOCGTUNER:
636 err = get_video_tuner32(&karg.vt, up); 669 err = get_video_tuner32(&karg.vt, up);
@@ -644,6 +677,7 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
644 break; 677 break;
645 678
646 case VIDIOCSFREQ: 679 case VIDIOCSFREQ:
680#endif
647 case VIDIOC_S_INPUT: 681 case VIDIOC_S_INPUT:
648 case VIDIOC_OVERLAY: 682 case VIDIOC_OVERLAY:
649 case VIDIOC_STREAMON: 683 case VIDIOC_STREAMON:
@@ -697,14 +731,21 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
697 compatible_arg = 0; 731 compatible_arg = 0;
698 break; 732 break;
699 733
734#ifdef CONFIG_VIDEO_V4L1_COMPAT
700 case VIDIOCGWIN: 735 case VIDIOCGWIN:
701 case VIDIOCGFBUF: 736 case VIDIOCGFBUF:
702 case VIDIOCGFREQ: 737 case VIDIOCGFREQ:
738#endif
703 case VIDIOC_G_FBUF: 739 case VIDIOC_G_FBUF:
704 case VIDIOC_G_INPUT: 740 case VIDIOC_G_INPUT:
705 compatible_arg = 0; 741 compatible_arg = 0;
742#ifdef CONFIG_VIDEO_V4L1_COMPAT
743 case VIDIOCSMICROCODE:
744 err = microcode32(&karg.vc, up);
745 compatible_arg = 0;
746 break;
747#endif
706 }; 748 };
707
708 if(err) 749 if(err)
709 goto out; 750 goto out;
710 751
@@ -719,6 +760,7 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
719 } 760 }
720 if(err == 0) { 761 if(err == 0) {
721 switch(cmd) { 762 switch(cmd) {
763#ifdef CONFIG_VIDEO_V4L1_COMPAT
722 case VIDIOCGTUNER: 764 case VIDIOCGTUNER:
723 err = put_video_tuner32(&karg.vt, up); 765 err = put_video_tuner32(&karg.vt, up);
724 break; 766 break;
@@ -730,7 +772,7 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
730 case VIDIOCGFBUF: 772 case VIDIOCGFBUF:
731 err = put_video_buffer32(&karg.vb, up); 773 err = put_video_buffer32(&karg.vb, up);
732 break; 774 break;
733 775#endif
734 case VIDIOC_G_FBUF: 776 case VIDIOC_G_FBUF:
735 err = put_v4l2_framebuffer32(&karg.v2fb, up); 777 err = put_v4l2_framebuffer32(&karg.v2fb, up);
736 break; 778 break;
@@ -768,7 +810,9 @@ static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg
768 err = put_v4l2_input32(&karg.v2i, up); 810 err = put_v4l2_input32(&karg.v2i, up);
769 break; 811 break;
770 812
813#ifdef CONFIG_VIDEO_V4L1_COMPAT
771 case VIDIOCGFREQ: 814 case VIDIOCGFREQ:
815#endif
772 case VIDIOC_G_INPUT: 816 case VIDIOC_G_INPUT:
773 err = put_user(((u32)karg.vx), (u32 __user *)up); 817 err = put_user(((u32)karg.vx), (u32 __user *)up);
774 break; 818 break;
@@ -786,6 +830,7 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
786 return ret; 830 return ret;
787 831
788 switch (cmd) { 832 switch (cmd) {
833#ifdef CONFIG_VIDEO_V4L1_COMPAT
789 case VIDIOCSWIN32: 834 case VIDIOCSWIN32:
790 ret = do_set_window(file, cmd, arg); 835 ret = do_set_window(file, cmd, arg);
791 break; 836 break;
@@ -796,6 +841,7 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
796 case VIDIOCSFBUF32: 841 case VIDIOCSFBUF32:
797 case VIDIOCGFREQ32: 842 case VIDIOCGFREQ32:
798 case VIDIOCSFREQ32: 843 case VIDIOCSFREQ32:
844#endif
799 case VIDIOC_QUERYCAP: 845 case VIDIOC_QUERYCAP:
800 case VIDIOC_ENUM_FMT: 846 case VIDIOC_ENUM_FMT:
801 case VIDIOC_G_FMT32: 847 case VIDIOC_G_FMT32:
@@ -827,6 +873,7 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
827 ret = do_video_ioctl(file, cmd, arg); 873 ret = do_video_ioctl(file, cmd, arg);
828 break; 874 break;
829 875
876#ifdef CONFIG_VIDEO_V4L1_COMPAT
830 /* Little v, the video4linux ioctls (conflict?) */ 877 /* Little v, the video4linux ioctls (conflict?) */
831 case VIDIOCGCAP: 878 case VIDIOCGCAP:
832 case VIDIOCGCHAN: 879 case VIDIOCGCHAN:
@@ -855,6 +902,7 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
855 case _IOR('v' , BASE_VIDIOCPRIVATE+7, int): 902 case _IOR('v' , BASE_VIDIOCPRIVATE+7, int):
856 ret = native_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); 903 ret = native_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
857 break; 904 break;
905#endif
858 default: 906 default:
859 v4l_print_ioctl("compat_ioctl32", cmd); 907 v4l_print_ioctl("compat_ioctl32", cmd);
860 } 908 }
diff --git a/drivers/media/video/cpia2/Kconfig b/drivers/media/video/cpia2/Kconfig
index 513cc0927389..e39a96152004 100644
--- a/drivers/media/video/cpia2/Kconfig
+++ b/drivers/media/video/cpia2/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_CPIA2 1config VIDEO_CPIA2
2 tristate "CPiA2 Video For Linux" 2 tristate "CPiA2 Video For Linux"
3 depends on VIDEO_DEV && USB 3 depends on VIDEO_DEV && USB && VIDEO_V4L1
4 ---help--- 4 ---help---
5 This is the video4linux driver for cameras based on Vision's CPiA2 5 This is the video4linux driver for cameras based on Vision's CPiA2
6 (Colour Processor Interface ASIC), such as the Digital Blue QX5 6 (Colour Processor Interface ASIC), such as the Digital Blue QX5
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 5c2036b40ea1..7bb7589a07c3 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -104,8 +104,8 @@ u32 cx25840_read4(struct i2c_client * client, u16 addr)
104 if (i2c_master_recv(client, buffer, 4) < 4) 104 if (i2c_master_recv(client, buffer, 4) < 4)
105 return 0; 105 return 0;
106 106
107 return (buffer[0] << 24) | (buffer[1] << 16) | 107 return (buffer[3] << 24) | (buffer[2] << 16) |
108 (buffer[2] << 8) | buffer[3]; 108 (buffer[1] << 8) | buffer[0];
109} 109}
110 110
111int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned and_mask, 111int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned and_mask,
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index 80e23ee9801c..7a94e6a11927 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -51,6 +51,7 @@ config VIDEO_CX88_DVB
51 tristate "DVB/ATSC Support for cx2388x based TV cards" 51 tristate "DVB/ATSC Support for cx2388x based TV cards"
52 depends on VIDEO_CX88 && DVB_CORE 52 depends on VIDEO_CX88 && DVB_CORE
53 select VIDEO_BUF_DVB 53 select VIDEO_BUF_DVB
54 select DVB_PLL
54 ---help--- 55 ---help---
55 This adds support for DVB/ATSC cards based on the 56 This adds support for DVB/ATSC cards based on the
56 Conexant 2388x chip. 57 Conexant 2388x chip.
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index 349632b48e93..b60177f173c3 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -453,11 +453,13 @@ static int blackbird_load_firmware(struct cx8802_dev *dev)
453 if (firmware->size != BLACKBIRD_FIRM_IMAGE_SIZE) { 453 if (firmware->size != BLACKBIRD_FIRM_IMAGE_SIZE) {
454 dprintk(0, "ERROR: Firmware size mismatch (have %zd, expected %d)\n", 454 dprintk(0, "ERROR: Firmware size mismatch (have %zd, expected %d)\n",
455 firmware->size, BLACKBIRD_FIRM_IMAGE_SIZE); 455 firmware->size, BLACKBIRD_FIRM_IMAGE_SIZE);
456 release_firmware(firmware);
456 return -1; 457 return -1;
457 } 458 }
458 459
459 if (0 != memcmp(firmware->data, magic, 8)) { 460 if (0 != memcmp(firmware->data, magic, 8)) {
460 dprintk(0, "ERROR: Firmware magic mismatch, wrong file?\n"); 461 dprintk(0, "ERROR: Firmware magic mismatch, wrong file?\n");
462 release_firmware(firmware);
461 return -1; 463 return -1;
462 } 464 }
463 465
@@ -478,6 +480,7 @@ static int blackbird_load_firmware(struct cx8802_dev *dev)
478 } 480 }
479 if (checksum) { 481 if (checksum) {
480 dprintk(0, "ERROR: Firmware load failed (checksum mismatch).\n"); 482 dprintk(0, "ERROR: Firmware load failed (checksum mismatch).\n");
483 release_firmware(firmware);
481 return -1; 484 return -1;
482 } 485 }
483 release_firmware(firmware); 486 release_firmware(firmware);
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index 72b630a91f41..c25564648993 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -89,7 +89,7 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
89 89
90 auxgpio = cx_read(MO_GP1_IO); 90 auxgpio = cx_read(MO_GP1_IO);
91 /* Take out the parity part */ 91 /* Take out the parity part */
92 gpio+=(gpio & 0x7fd) + (auxgpio & 0xef); 92 gpio=(gpio & 0x7fd) + (auxgpio & 0xef);
93 } else 93 } else
94 auxgpio = gpio; 94 auxgpio = gpio;
95 95
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 2225d4b94140..94c92bacc342 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -1180,7 +1180,6 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1180 V4L2_CAP_READWRITE | 1180 V4L2_CAP_READWRITE |
1181 V4L2_CAP_STREAMING | 1181 V4L2_CAP_STREAMING |
1182 V4L2_CAP_VBI_CAPTURE | 1182 V4L2_CAP_VBI_CAPTURE |
1183 V4L2_CAP_VIDEO_OVERLAY |
1184 0; 1183 0;
1185 if (UNSET != core->tuner_type) 1184 if (UNSET != core->tuner_type)
1186 cap->capabilities |= V4L2_CAP_TUNER; 1185 cap->capabilities |= V4L2_CAP_TUNER;
@@ -1226,7 +1225,7 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1226 struct v4l2_format *f = arg; 1225 struct v4l2_format *f = arg;
1227 return cx8800_try_fmt(dev,fh,f); 1226 return cx8800_try_fmt(dev,fh,f);
1228 } 1227 }
1229#ifdef HAVE_V4L1 1228#ifdef CONFIG_VIDEO_V4L1_COMPAT
1230 /* --- streaming capture ------------------------------------- */ 1229 /* --- streaming capture ------------------------------------- */
1231 case VIDIOCGMBUF: 1230 case VIDIOCGMBUF:
1232 { 1231 {
@@ -1585,7 +1584,7 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
1585 *id = 0; 1584 *id = 0;
1586 return 0; 1585 return 0;
1587 } 1586 }
1588#ifdef HAVE_V4L1 1587#ifdef CONFIG_VIDEO_V4L1_COMPAT
1589 case VIDIOCSTUNER: 1588 case VIDIOCSTUNER:
1590 { 1589 {
1591 struct video_tuner *v = arg; 1590 struct video_tuner *v = arg;
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index dbb75a7db199..56246b8578f3 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -362,7 +362,7 @@ int msp_sleep(struct msp_state *state, int timeout)
362} 362}
363 363
364/* ------------------------------------------------------------------------ */ 364/* ------------------------------------------------------------------------ */
365 365#ifdef CONFIG_VIDEO_V4L1
366static int msp_mode_v4l2_to_v4l1(int rxsubchans, int audmode) 366static int msp_mode_v4l2_to_v4l1(int rxsubchans, int audmode)
367{ 367{
368 if (rxsubchans == V4L2_TUNER_SUB_MONO) 368 if (rxsubchans == V4L2_TUNER_SUB_MONO)
@@ -384,6 +384,7 @@ static int msp_mode_v4l1_to_v4l2(int mode)
384 return V4L2_TUNER_MODE_LANG1; 384 return V4L2_TUNER_MODE_LANG1;
385 return V4L2_TUNER_MODE_MONO; 385 return V4L2_TUNER_MODE_MONO;
386} 386}
387#endif
387 388
388static int msp_get_ctrl(struct i2c_client *client, struct v4l2_control *ctrl) 389static int msp_get_ctrl(struct i2c_client *client, struct v4l2_control *ctrl)
389{ 390{
@@ -509,6 +510,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
509 /* --- v4l ioctls --- */ 510 /* --- v4l ioctls --- */
510 /* take care: bttv does userspace copying, we'll get a 511 /* take care: bttv does userspace copying, we'll get a
511 kernel pointer here... */ 512 kernel pointer here... */
513#ifdef CONFIG_VIDEO_V4L1
512 case VIDIOCGAUDIO: 514 case VIDIOCGAUDIO:
513 { 515 {
514 struct video_audio *va = arg; 516 struct video_audio *va = arg;
@@ -577,6 +579,12 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
577 } 579 }
578 580
579 case VIDIOCSFREQ: 581 case VIDIOCSFREQ:
582 {
583 /* new channel -- kick audio carrier scan */
584 msp_wake_thread(client);
585 break;
586 }
587#endif
580 case VIDIOC_S_FREQUENCY: 588 case VIDIOC_S_FREQUENCY:
581 { 589 {
582 /* new channel -- kick audio carrier scan */ 590 /* new channel -- kick audio carrier scan */
diff --git a/drivers/media/video/msp3400-kthreads.c b/drivers/media/video/msp3400-kthreads.c
index f2fd9195b3ac..ed02ff811388 100644
--- a/drivers/media/video/msp3400-kthreads.c
+++ b/drivers/media/video/msp3400-kthreads.c
@@ -961,10 +961,10 @@ int msp34xxg_thread(void *data)
961 /* setup the chip*/ 961 /* setup the chip*/
962 msp34xxg_reset(client); 962 msp34xxg_reset(client);
963 state->std = state->radio ? 0x40 : msp_standard; 963 state->std = state->radio ? 0x40 : msp_standard;
964 if (state->std != 1)
965 goto unmute;
966 /* start autodetect */ 964 /* start autodetect */
967 msp_write_dem(client, 0x20, state->std); 965 msp_write_dem(client, 0x20, state->std);
966 if (state->std != 1)
967 goto unmute;
968 968
969 /* watch autodetect */ 969 /* watch autodetect */
970 v4l_dbg(1, msp_debug, client, "started autodetect, waiting for result\n"); 970 v4l_dbg(1, msp_debug, client, "started autodetect, waiting for result\n");
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index 9b48abcf6089..be1e5cc78081 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -852,7 +852,6 @@ unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *hdw)
852 return hdw->serial_number; 852 return hdw->serial_number;
853} 853}
854 854
855
856int pvr2_hdw_get_unit_number(struct pvr2_hdw *hdw) 855int pvr2_hdw_get_unit_number(struct pvr2_hdw *hdw)
857{ 856{
858 return hdw->unit_number; 857 return hdw->unit_number;
@@ -2318,7 +2317,6 @@ void pvr2_hdw_poll_trigger_unlocked(struct pvr2_hdw *hdw)
2318 } 2317 }
2319} 2318}
2320 2319
2321
2322/* Return name for this driver instance */ 2320/* Return name for this driver instance */
2323const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *hdw) 2321const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *hdw)
2324{ 2322{
@@ -2542,6 +2540,10 @@ static void pvr2_ctl_timeout(unsigned long data)
2542} 2540}
2543 2541
2544 2542
2543/* Issue a command and get a response from the device. This extended
2544 version includes a probe flag (which if set means that device errors
2545 should not be logged or treated as fatal) and a timeout in jiffies.
2546 This can be used to non-lethally probe the health of endpoint 1. */
2545static int pvr2_send_request_ex(struct pvr2_hdw *hdw, 2547static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
2546 unsigned int timeout,int probe_fl, 2548 unsigned int timeout,int probe_fl,
2547 void *write_data,unsigned int write_len, 2549 void *write_data,unsigned int write_len,
@@ -2970,6 +2972,7 @@ int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *hdw)
2970} 2972}
2971 2973
2972 2974
2975/* Stop / start video stream transport */
2973static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl) 2976static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl)
2974{ 2977{
2975 int status; 2978 int status;
@@ -3068,6 +3071,7 @@ int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val)
3068} 3071}
3069 3072
3070 3073
3074/* Find I2C address of eeprom */
3071static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw) 3075static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw)
3072{ 3076{
3073 int result; 3077 int result;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-io.c b/drivers/media/video/pvrusb2/pvrusb2-io.c
index 681f79c8064e..1e393762546c 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-io.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-io.c
@@ -26,6 +26,8 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28 28
29static const char *pvr2_buffer_state_decode(enum pvr2_buffer_state);
30
29#define BUFFER_SIG 0x47653271 31#define BUFFER_SIG 0x47653271
30 32
31// #define SANITY_CHECK_BUFFERS 33// #define SANITY_CHECK_BUFFERS
@@ -515,6 +517,10 @@ void pvr2_stream_set_callback(struct pvr2_stream *sp,
515} 517}
516 518
517/* Query / set the nominal buffer count */ 519/* Query / set the nominal buffer count */
520int pvr2_stream_get_buffer_count(struct pvr2_stream *sp)
521{
522 return sp->buffer_target_count;
523}
518 524
519int pvr2_stream_set_buffer_count(struct pvr2_stream *sp,unsigned int cnt) 525int pvr2_stream_set_buffer_count(struct pvr2_stream *sp,unsigned int cnt)
520{ 526{
@@ -553,7 +559,6 @@ int pvr2_stream_get_ready_count(struct pvr2_stream *sp)
553 return sp->r_count; 559 return sp->r_count;
554} 560}
555 561
556
557void pvr2_stream_kill(struct pvr2_stream *sp) 562void pvr2_stream_kill(struct pvr2_stream *sp)
558{ 563{
559 struct pvr2_buffer *bp; 564 struct pvr2_buffer *bp;
@@ -607,7 +612,6 @@ int pvr2_buffer_queue(struct pvr2_buffer *bp)
607 return ret; 612 return ret;
608} 613}
609 614
610
611int pvr2_buffer_set_buffer(struct pvr2_buffer *bp,void *ptr,unsigned int cnt) 615int pvr2_buffer_set_buffer(struct pvr2_buffer *bp,void *ptr,unsigned int cnt)
612{ 616{
613 int ret = 0; 617 int ret = 0;
@@ -646,7 +650,6 @@ int pvr2_buffer_get_status(struct pvr2_buffer *bp)
646 return bp->status; 650 return bp->status;
647} 651}
648 652
649
650int pvr2_buffer_get_id(struct pvr2_buffer *bp) 653int pvr2_buffer_get_id(struct pvr2_buffer *bp)
651{ 654{
652 return bp->id; 655 return bp->id;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-io.h b/drivers/media/video/pvrusb2/pvrusb2-io.h
index 96285ad234a6..93279cc2a35e 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-io.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-io.h
@@ -47,6 +47,7 @@ void pvr2_stream_set_callback(struct pvr2_stream *,
47 void *data); 47 void *data);
48 48
49/* Query / set the nominal buffer count */ 49/* Query / set the nominal buffer count */
50int pvr2_stream_get_buffer_count(struct pvr2_stream *);
50int pvr2_stream_set_buffer_count(struct pvr2_stream *,unsigned int); 51int pvr2_stream_set_buffer_count(struct pvr2_stream *,unsigned int);
51 52
52/* Get a pointer to a buffer that is either idle, ready, or is specified 53/* Get a pointer to a buffer that is either idle, ready, or is specified
@@ -58,6 +59,7 @@ struct pvr2_buffer *pvr2_stream_get_buffer(struct pvr2_stream *sp,int id);
58/* Find out how many buffers are idle or ready */ 59/* Find out how many buffers are idle or ready */
59int pvr2_stream_get_ready_count(struct pvr2_stream *); 60int pvr2_stream_get_ready_count(struct pvr2_stream *);
60 61
62
61/* Kill all pending buffers and throw away any ready buffers as well */ 63/* Kill all pending buffers and throw away any ready buffers as well */
62void pvr2_stream_kill(struct pvr2_stream *); 64void pvr2_stream_kill(struct pvr2_stream *);
63 65
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ioread.c b/drivers/media/video/pvrusb2/pvrusb2-ioread.c
index f7a2e225a002..b71f9a961f8a 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ioread.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ioread.c
@@ -213,7 +213,9 @@ int pvr2_ioread_setup(struct pvr2_ioread *cp,struct pvr2_stream *sp)
213 " pvr2_ioread_setup (tear-down) id=%p",cp); 213 " pvr2_ioread_setup (tear-down) id=%p",cp);
214 pvr2_ioread_stop(cp); 214 pvr2_ioread_stop(cp);
215 pvr2_stream_kill(cp->stream); 215 pvr2_stream_kill(cp->stream);
216 pvr2_stream_set_buffer_count(cp->stream,0); 216 if (pvr2_stream_get_buffer_count(cp->stream)) {
217 pvr2_stream_set_buffer_count(cp->stream,0);
218 }
217 cp->stream = NULL; 219 cp->stream = NULL;
218 } 220 }
219 if (sp) { 221 if (sp) {
@@ -251,7 +253,6 @@ int pvr2_ioread_set_enabled(struct pvr2_ioread *cp,int fl)
251 return ret; 253 return ret;
252} 254}
253 255
254
255static int pvr2_ioread_get_buffer(struct pvr2_ioread *cp) 256static int pvr2_ioread_get_buffer(struct pvr2_ioread *cp)
256{ 257{
257 int stat; 258 int stat;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index 6af55a8b6f05..d1dda5caf406 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -44,12 +44,16 @@ struct pvr2_sysfs {
44 struct kobj_type ktype; 44 struct kobj_type ktype;
45 struct class_device_attribute attr_v4l_minor_number; 45 struct class_device_attribute attr_v4l_minor_number;
46 struct class_device_attribute attr_unit_number; 46 struct class_device_attribute attr_unit_number;
47 int v4l_minor_number_created_ok;
48 int unit_number_created_ok;
47}; 49};
48 50
49#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC 51#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
50struct pvr2_sysfs_debugifc { 52struct pvr2_sysfs_debugifc {
51 struct class_device_attribute attr_debugcmd; 53 struct class_device_attribute attr_debugcmd;
52 struct class_device_attribute attr_debuginfo; 54 struct class_device_attribute attr_debuginfo;
55 int debugcmd_created_ok;
56 int debuginfo_created_ok;
53}; 57};
54#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ 58#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
55 59
@@ -67,6 +71,7 @@ struct pvr2_sysfs_ctl_item {
67 struct pvr2_sysfs_ctl_item *item_next; 71 struct pvr2_sysfs_ctl_item *item_next;
68 struct attribute *attr_gen[7]; 72 struct attribute *attr_gen[7];
69 struct attribute_group grp; 73 struct attribute_group grp;
74 int created_ok;
70 char name[80]; 75 char name[80];
71}; 76};
72 77
@@ -487,6 +492,7 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
487 struct pvr2_sysfs_func_set *fp; 492 struct pvr2_sysfs_func_set *fp;
488 struct pvr2_ctrl *cptr; 493 struct pvr2_ctrl *cptr;
489 unsigned int cnt,acnt; 494 unsigned int cnt,acnt;
495 int ret;
490 496
491 if ((ctl_id < 0) || (ctl_id >= (sizeof(funcs)/sizeof(funcs[0])))) { 497 if ((ctl_id < 0) || (ctl_id >= (sizeof(funcs)/sizeof(funcs[0])))) {
492 return; 498 return;
@@ -589,7 +595,13 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
589 cip->grp.name = cip->name; 595 cip->grp.name = cip->name;
590 cip->grp.attrs = cip->attr_gen; 596 cip->grp.attrs = cip->attr_gen;
591 597
592 sysfs_create_group(&sfp->class_dev->kobj,&cip->grp); 598 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
599 if (ret) {
600 printk(KERN_WARNING "%s: sysfs_create_group error: %d\n",
601 __FUNCTION__, ret);
602 return;
603 }
604 cip->created_ok = !0;
593} 605}
594 606
595#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC 607#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
@@ -600,6 +612,8 @@ static ssize_t debugcmd_store(struct class_device *,const char *,size_t count);
600static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp) 612static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
601{ 613{
602 struct pvr2_sysfs_debugifc *dip; 614 struct pvr2_sysfs_debugifc *dip;
615 int ret;
616
603 dip = kmalloc(sizeof(*dip),GFP_KERNEL); 617 dip = kmalloc(sizeof(*dip),GFP_KERNEL);
604 if (!dip) return; 618 if (!dip) return;
605 memset(dip,0,sizeof(*dip)); 619 memset(dip,0,sizeof(*dip));
@@ -613,17 +627,34 @@ static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
613 dip->attr_debuginfo.attr.mode = S_IRUGO; 627 dip->attr_debuginfo.attr.mode = S_IRUGO;
614 dip->attr_debuginfo.show = debuginfo_show; 628 dip->attr_debuginfo.show = debuginfo_show;
615 sfp->debugifc = dip; 629 sfp->debugifc = dip;
616 class_device_create_file(sfp->class_dev,&dip->attr_debugcmd); 630 ret = class_device_create_file(sfp->class_dev,&dip->attr_debugcmd);
617 class_device_create_file(sfp->class_dev,&dip->attr_debuginfo); 631 if (ret < 0) {
632 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
633 __FUNCTION__, ret);
634 } else {
635 dip->debugcmd_created_ok = !0;
636 }
637 ret = class_device_create_file(sfp->class_dev,&dip->attr_debuginfo);
638 if (ret < 0) {
639 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
640 __FUNCTION__, ret);
641 } else {
642 dip->debuginfo_created_ok = !0;
643 }
618} 644}
619 645
620 646
621static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp) 647static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
622{ 648{
623 if (!sfp->debugifc) return; 649 if (!sfp->debugifc) return;
624 class_device_remove_file(sfp->class_dev, 650 if (sfp->debugifc->debuginfo_created_ok) {
625 &sfp->debugifc->attr_debuginfo); 651 class_device_remove_file(sfp->class_dev,
626 class_device_remove_file(sfp->class_dev,&sfp->debugifc->attr_debugcmd); 652 &sfp->debugifc->attr_debuginfo);
653 }
654 if (sfp->debugifc->debugcmd_created_ok) {
655 class_device_remove_file(sfp->class_dev,
656 &sfp->debugifc->attr_debugcmd);
657 }
627 kfree(sfp->debugifc); 658 kfree(sfp->debugifc);
628 sfp->debugifc = NULL; 659 sfp->debugifc = NULL;
629} 660}
@@ -645,7 +676,9 @@ static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
645 struct pvr2_sysfs_ctl_item *cip1,*cip2; 676 struct pvr2_sysfs_ctl_item *cip1,*cip2;
646 for (cip1 = sfp->item_first; cip1; cip1 = cip2) { 677 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
647 cip2 = cip1->item_next; 678 cip2 = cip1->item_next;
648 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp); 679 if (cip1->created_ok) {
680 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
681 }
649 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1); 682 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
650 kfree(cip1); 683 kfree(cip1);
651 } 684 }
@@ -675,8 +708,14 @@ static void class_dev_destroy(struct pvr2_sysfs *sfp)
675 pvr2_sysfs_tear_down_debugifc(sfp); 708 pvr2_sysfs_tear_down_debugifc(sfp);
676#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ 709#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
677 pvr2_sysfs_tear_down_controls(sfp); 710 pvr2_sysfs_tear_down_controls(sfp);
678 class_device_remove_file(sfp->class_dev,&sfp->attr_v4l_minor_number); 711 if (sfp->v4l_minor_number_created_ok) {
679 class_device_remove_file(sfp->class_dev,&sfp->attr_unit_number); 712 class_device_remove_file(sfp->class_dev,
713 &sfp->attr_v4l_minor_number);
714 }
715 if (sfp->unit_number_created_ok) {
716 class_device_remove_file(sfp->class_dev,
717 &sfp->attr_unit_number);
718 }
680 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev); 719 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
681 sfp->class_dev->class_data = NULL; 720 sfp->class_dev->class_data = NULL;
682 class_device_unregister(sfp->class_dev); 721 class_device_unregister(sfp->class_dev);
@@ -709,6 +748,8 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
709{ 748{
710 struct usb_device *usb_dev; 749 struct usb_device *usb_dev;
711 struct class_device *class_dev; 750 struct class_device *class_dev;
751 int ret;
752
712 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw); 753 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
713 if (!usb_dev) return; 754 if (!usb_dev) return;
714 class_dev = kmalloc(sizeof(*class_dev),GFP_KERNEL); 755 class_dev = kmalloc(sizeof(*class_dev),GFP_KERNEL);
@@ -733,20 +774,40 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
733 774
734 sfp->class_dev = class_dev; 775 sfp->class_dev = class_dev;
735 class_dev->class_data = sfp; 776 class_dev->class_data = sfp;
736 class_device_register(class_dev); 777 ret = class_device_register(class_dev);
778 if (ret) {
779 printk(KERN_ERR "%s: class_device_register failed\n",
780 __FUNCTION__);
781 kfree(class_dev);
782 return;
783 }
737 784
738 sfp->attr_v4l_minor_number.attr.owner = THIS_MODULE; 785 sfp->attr_v4l_minor_number.attr.owner = THIS_MODULE;
739 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number"; 786 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
740 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO; 787 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
741 sfp->attr_v4l_minor_number.show = v4l_minor_number_show; 788 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
742 sfp->attr_v4l_minor_number.store = NULL; 789 sfp->attr_v4l_minor_number.store = NULL;
743 class_device_create_file(sfp->class_dev,&sfp->attr_v4l_minor_number); 790 ret = class_device_create_file(sfp->class_dev,
791 &sfp->attr_v4l_minor_number);
792 if (ret < 0) {
793 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
794 __FUNCTION__, ret);
795 } else {
796 sfp->v4l_minor_number_created_ok = !0;
797 }
798
744 sfp->attr_unit_number.attr.owner = THIS_MODULE; 799 sfp->attr_unit_number.attr.owner = THIS_MODULE;
745 sfp->attr_unit_number.attr.name = "unit_number"; 800 sfp->attr_unit_number.attr.name = "unit_number";
746 sfp->attr_unit_number.attr.mode = S_IRUGO; 801 sfp->attr_unit_number.attr.mode = S_IRUGO;
747 sfp->attr_unit_number.show = unit_number_show; 802 sfp->attr_unit_number.show = unit_number_show;
748 sfp->attr_unit_number.store = NULL; 803 sfp->attr_unit_number.store = NULL;
749 class_device_create_file(sfp->class_dev,&sfp->attr_unit_number); 804 ret = class_device_create_file(sfp->class_dev,&sfp->attr_unit_number);
805 if (ret < 0) {
806 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
807 __FUNCTION__, ret);
808 } else {
809 sfp->unit_number_created_ok = !0;
810 }
750 811
751 pvr2_sysfs_add_controls(sfp); 812 pvr2_sysfs_add_controls(sfp);
752#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC 813#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
diff --git a/drivers/media/video/pwc/Kconfig b/drivers/media/video/pwc/Kconfig
index 697145e0bf15..8fdf7101d3bf 100644
--- a/drivers/media/video/pwc/Kconfig
+++ b/drivers/media/video/pwc/Kconfig
@@ -30,7 +30,7 @@ config USB_PWC
30 30
31config USB_PWC_DEBUG 31config USB_PWC_DEBUG
32 bool "USB Philips Cameras verbose debug" 32 bool "USB Philips Cameras verbose debug"
33 depends USB_PWC 33 depends on USB_PWC
34 help 34 help
35 Say Y here in order to have the pwc driver generate verbose debugging 35 Say Y here in order to have the pwc driver generate verbose debugging
36 messages. 36 messages.
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index 47d0d83a0264..d4703944df9c 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -160,6 +160,7 @@ static struct file_operations pwc_fops = {
160 .poll = pwc_video_poll, 160 .poll = pwc_video_poll,
161 .mmap = pwc_video_mmap, 161 .mmap = pwc_video_mmap,
162 .ioctl = pwc_video_ioctl, 162 .ioctl = pwc_video_ioctl,
163 .compat_ioctl = v4l_compat_ioctl32,
163 .llseek = no_llseek, 164 .llseek = no_llseek,
164}; 165};
165static struct video_device pwc_template = { 166static struct video_device pwc_template = {
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index e1c1805df1fb..f5543166d193 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -40,6 +40,7 @@ config VIDEO_SAA7134_DVB
40 depends on VIDEO_SAA7134 && DVB_CORE 40 depends on VIDEO_SAA7134 && DVB_CORE
41 select VIDEO_BUF_DVB 41 select VIDEO_BUF_DVB
42 select FW_LOADER 42 select FW_LOADER
43 select DVB_PLL
43 ---help--- 44 ---help---
44 This adds support for DVB cards based on the 45 This adds support for DVB cards based on the
45 Philips saa7134 chip. 46 Philips saa7134 chip.
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index f1fd69e7f119..d73cff1970ae 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -997,9 +997,9 @@ static int saa7134_alsa_init(void)
997 struct saa7134_dev *dev = NULL; 997 struct saa7134_dev *dev = NULL;
998 struct list_head *list; 998 struct list_head *list;
999 999
1000 if (!dmasound_init && !dmasound_exit) { 1000 if (!saa7134_dmasound_init && !saa7134_dmasound_exit) {
1001 dmasound_init = alsa_device_init; 1001 saa7134_dmasound_init = alsa_device_init;
1002 dmasound_exit = alsa_device_exit; 1002 saa7134_dmasound_exit = alsa_device_exit;
1003 } else { 1003 } else {
1004 printk(KERN_WARNING "saa7134 ALSA: can't load, DMA sound handler already assigned (probably to OSS)\n"); 1004 printk(KERN_WARNING "saa7134 ALSA: can't load, DMA sound handler already assigned (probably to OSS)\n");
1005 return -EBUSY; 1005 return -EBUSY;
@@ -1036,8 +1036,8 @@ static void saa7134_alsa_exit(void)
1036 snd_card_free(snd_saa7134_cards[idx]); 1036 snd_card_free(snd_saa7134_cards[idx]);
1037 } 1037 }
1038 1038
1039 dmasound_init = NULL; 1039 saa7134_dmasound_init = NULL;
1040 dmasound_exit = NULL; 1040 saa7134_dmasound_exit = NULL;
1041 printk(KERN_INFO "saa7134 ALSA driver for DMA sound unloaded\n"); 1041 printk(KERN_INFO "saa7134 ALSA driver for DMA sound unloaded\n");
1042 1042
1043 return; 1043 return;
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 6e97cc84ba89..be3a81fc90a2 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -95,8 +95,8 @@ LIST_HEAD(saa7134_devlist);
95static LIST_HEAD(mops_list); 95static LIST_HEAD(mops_list);
96static unsigned int saa7134_devcount; 96static unsigned int saa7134_devcount;
97 97
98int (*dmasound_init)(struct saa7134_dev *dev); 98int (*saa7134_dmasound_init)(struct saa7134_dev *dev);
99int (*dmasound_exit)(struct saa7134_dev *dev); 99int (*saa7134_dmasound_exit)(struct saa7134_dev *dev);
100 100
101#define dprintk(fmt, arg...) if (core_debug) \ 101#define dprintk(fmt, arg...) if (core_debug) \
102 printk(KERN_DEBUG "%s/core: " fmt, dev->name , ## arg) 102 printk(KERN_DEBUG "%s/core: " fmt, dev->name , ## arg)
@@ -1008,8 +1008,8 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1008 /* check for signal */ 1008 /* check for signal */
1009 saa7134_irq_video_intl(dev); 1009 saa7134_irq_video_intl(dev);
1010 1010
1011 if (dmasound_init && !dev->dmasound.priv_data) { 1011 if (saa7134_dmasound_init && !dev->dmasound.priv_data) {
1012 dmasound_init(dev); 1012 saa7134_dmasound_init(dev);
1013 } 1013 }
1014 1014
1015 return 0; 1015 return 0;
@@ -1036,8 +1036,8 @@ static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1036 struct saa7134_mpeg_ops *mops; 1036 struct saa7134_mpeg_ops *mops;
1037 1037
1038 /* Release DMA sound modules if present */ 1038 /* Release DMA sound modules if present */
1039 if (dmasound_exit && dev->dmasound.priv_data) { 1039 if (saa7134_dmasound_exit && dev->dmasound.priv_data) {
1040 dmasound_exit(dev); 1040 saa7134_dmasound_exit(dev);
1041 } 1041 }
1042 1042
1043 /* debugging ... */ 1043 /* debugging ... */
@@ -1169,8 +1169,8 @@ EXPORT_SYMBOL(saa7134_boards);
1169 1169
1170/* ----------------- for the DMA sound modules --------------- */ 1170/* ----------------- for the DMA sound modules --------------- */
1171 1171
1172EXPORT_SYMBOL(dmasound_init); 1172EXPORT_SYMBOL(saa7134_dmasound_init);
1173EXPORT_SYMBOL(dmasound_exit); 1173EXPORT_SYMBOL(saa7134_dmasound_exit);
1174EXPORT_SYMBOL(saa7134_pgtable_free); 1174EXPORT_SYMBOL(saa7134_pgtable_free);
1175EXPORT_SYMBOL(saa7134_pgtable_build); 1175EXPORT_SYMBOL(saa7134_pgtable_build);
1176EXPORT_SYMBOL(saa7134_pgtable_alloc); 1176EXPORT_SYMBOL(saa7134_pgtable_alloc);
diff --git a/drivers/media/video/saa7134/saa7134-oss.c b/drivers/media/video/saa7134/saa7134-oss.c
index 3895d05804ae..2e3ba5f31453 100644
--- a/drivers/media/video/saa7134/saa7134-oss.c
+++ b/drivers/media/video/saa7134/saa7134-oss.c
@@ -993,9 +993,9 @@ static int saa7134_oss_init(void)
993 struct saa7134_dev *dev = NULL; 993 struct saa7134_dev *dev = NULL;
994 struct list_head *list; 994 struct list_head *list;
995 995
996 if (!dmasound_init && !dmasound_exit) { 996 if (!saa7134_dmasound_init && !saa7134_dmasound_exit) {
997 dmasound_init = oss_device_init; 997 saa7134_dmasound_init = oss_device_init;
998 dmasound_exit = oss_device_exit; 998 saa7134_dmasound_exit = oss_device_exit;
999 } else { 999 } else {
1000 printk(KERN_WARNING "saa7134 OSS: can't load, DMA sound handler already assigned (probably to ALSA)\n"); 1000 printk(KERN_WARNING "saa7134 OSS: can't load, DMA sound handler already assigned (probably to ALSA)\n");
1001 return -EBUSY; 1001 return -EBUSY;
@@ -1037,8 +1037,8 @@ static void saa7134_oss_exit(void)
1037 1037
1038 } 1038 }
1039 1039
1040 dmasound_init = NULL; 1040 saa7134_dmasound_init = NULL;
1041 dmasound_exit = NULL; 1041 saa7134_dmasound_exit = NULL;
1042 1042
1043 printk(KERN_INFO "saa7134 OSS driver for DMA sound unloaded\n"); 1043 printk(KERN_INFO "saa7134 OSS driver for DMA sound unloaded\n");
1044 1044
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index e4156ec9c6d7..2c171af9a9f2 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -40,7 +40,7 @@
40 40
41static unsigned int video_debug = 0; 41static unsigned int video_debug = 0;
42static unsigned int gbuffers = 8; 42static unsigned int gbuffers = 8;
43static unsigned int noninterlaced = 0; 43static unsigned int noninterlaced = 1;
44static unsigned int gbufsize = 720*576*4; 44static unsigned int gbufsize = 720*576*4;
45static unsigned int gbufsize_max = 720*576*4; 45static unsigned int gbufsize_max = 720*576*4;
46module_param(video_debug, int, 0644); 46module_param(video_debug, int, 0644);
@@ -48,7 +48,7 @@ MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
48module_param(gbuffers, int, 0444); 48module_param(gbuffers, int, 0444);
49MODULE_PARM_DESC(gbuffers,"number of capture buffers, range 2-32"); 49MODULE_PARM_DESC(gbuffers,"number of capture buffers, range 2-32");
50module_param(noninterlaced, int, 0644); 50module_param(noninterlaced, int, 0644);
51MODULE_PARM_DESC(noninterlaced,"video input is noninterlaced"); 51MODULE_PARM_DESC(noninterlaced,"capture non interlaced video");
52 52
53#define dprintk(fmt, arg...) if (video_debug) \ 53#define dprintk(fmt, arg...) if (video_debug) \
54 printk(KERN_DEBUG "%s/video: " fmt, dev->name , ## arg) 54 printk(KERN_DEBUG "%s/video: " fmt, dev->name , ## arg)
@@ -2087,7 +2087,7 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
2087 struct v4l2_format *f = arg; 2087 struct v4l2_format *f = arg;
2088 return saa7134_try_fmt(dev,fh,f); 2088 return saa7134_try_fmt(dev,fh,f);
2089 } 2089 }
2090#ifdef HAVE_V4L1 2090#ifdef CONFIG_VIDEO_V4L1_COMPAT
2091 case VIDIOCGMBUF: 2091 case VIDIOCGMBUF:
2092 { 2092 {
2093 struct video_mbuf *mbuf = arg; 2093 struct video_mbuf *mbuf = arg;
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index d5ee99c574cc..c04ce6152fd5 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -586,8 +586,8 @@ void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf);
586 586
587int saa7134_set_dmabits(struct saa7134_dev *dev); 587int saa7134_set_dmabits(struct saa7134_dev *dev);
588 588
589extern int (*dmasound_init)(struct saa7134_dev *dev); 589extern int (*saa7134_dmasound_init)(struct saa7134_dev *dev);
590extern int (*dmasound_exit)(struct saa7134_dev *dev); 590extern int (*saa7134_dmasound_exit)(struct saa7134_dev *dev);
591 591
592 592
593/* ----------------------------------------------------------- */ 593/* ----------------------------------------------------------- */
diff --git a/drivers/media/video/stradis.c b/drivers/media/video/stradis.c
index b36ba9fa3a28..5686547ba76a 100644
--- a/drivers/media/video/stradis.c
+++ b/drivers/media/video/stradis.c
@@ -2181,7 +2181,6 @@ static struct pci_device_id stradis_pci_tbl[] = {
2181 { 0 } 2181 { 0 }
2182}; 2182};
2183 2183
2184MODULE_DEVICE_TABLE(pci, stradis_pci_tbl);
2185 2184
2186static struct pci_driver stradis_driver = { 2185static struct pci_driver stradis_driver = {
2187 .name = "stradis", 2186 .name = "stradis",
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index f7eb402d5f2b..40590bae5ff7 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -196,14 +196,6 @@ static void set_type(struct i2c_client *c, unsigned int type,
196 i2c_master_send(c, buffer, 4); 196 i2c_master_send(c, buffer, 4);
197 default_tuner_init(c); 197 default_tuner_init(c);
198 break; 198 break;
199 case TUNER_LG_TDVS_H06XF:
200 /* Set the Auxiliary Byte. */
201 buffer[2] &= ~0x20;
202 buffer[2] |= 0x18;
203 buffer[3] = 0x20;
204 i2c_master_send(c, buffer, 4);
205 default_tuner_init(c);
206 break;
207 case TUNER_PHILIPS_TD1316: 199 case TUNER_PHILIPS_TD1316:
208 buffer[0] = 0x0b; 200 buffer[0] = 0x0b;
209 buffer[1] = 0xdc; 201 buffer[1] = 0xdc;
@@ -598,6 +590,7 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
598 if (t->standby) 590 if (t->standby)
599 t->standby (client); 591 t->standby (client);
600 break; 592 break;
593#ifdef CONFIG_VIDEO_V4L1
601 case VIDIOCSAUDIO: 594 case VIDIOCSAUDIO:
602 if (check_mode(t, "VIDIOCSAUDIO") == EINVAL) 595 if (check_mode(t, "VIDIOCSAUDIO") == EINVAL)
603 return 0; 596 return 0;
@@ -607,17 +600,6 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
607 /* Should be implemented, since bttv calls it */ 600 /* Should be implemented, since bttv calls it */
608 tuner_dbg("VIDIOCSAUDIO not implemented.\n"); 601 tuner_dbg("VIDIOCSAUDIO not implemented.\n");
609 break; 602 break;
610 case TDA9887_SET_CONFIG:
611 if (t->type == TUNER_TDA9887) {
612 int *i = arg;
613
614 t->tda9887_config = *i;
615 set_freq(client, t->tv_freq);
616 }
617 break;
618 /* --- v4l ioctls --- */
619 /* take care: bttv does userspace copying, we'll get a
620 kernel pointer here... */
621 case VIDIOCSCHAN: 603 case VIDIOCSCHAN:
622 { 604 {
623 static const v4l2_std_id map[] = { 605 static const v4l2_std_id map[] = {
@@ -701,7 +683,18 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
701 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO; 683 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
702 return 0; 684 return 0;
703 } 685 }
686#endif
687 case TDA9887_SET_CONFIG:
688 if (t->type == TUNER_TDA9887) {
689 int *i = arg;
704 690
691 t->tda9887_config = *i;
692 set_freq(client, t->tv_freq);
693 }
694 break;
695 /* --- v4l ioctls --- */
696 /* take care: bttv does userspace copying, we'll get a
697 kernel pointer here... */
705 case VIDIOC_S_STD: 698 case VIDIOC_S_STD:
706 { 699 {
707 v4l2_std_id *id = arg; 700 v4l2_std_id *id = arg;
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index d071c5cbf013..abe37cf632c6 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -339,7 +339,20 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
339 if (4 != (rc = i2c_master_send(c,buffer,4))) 339 if (4 != (rc = i2c_master_send(c,buffer,4)))
340 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); 340 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
341 341
342 if (t->type == TUNER_MICROTUNE_4042FI5) { 342 switch (t->type) {
343 case TUNER_LG_TDVS_H06XF:
344 /* Set the Auxiliary Byte. */
345 buffer[0] = buffer[2];
346 buffer[0] &= ~0x20;
347 buffer[0] |= 0x18;
348 buffer[1] = 0x20;
349 tuner_dbg("tv 0x%02x 0x%02x\n",buffer[0],buffer[1]);
350
351 if (2 != (rc = i2c_master_send(c,buffer,2)))
352 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc);
353 break;
354 case TUNER_MICROTUNE_4042FI5:
355 {
343 // FIXME - this may also work for other tuners 356 // FIXME - this may also work for other tuners
344 unsigned long timeout = jiffies + msecs_to_jiffies(1); 357 unsigned long timeout = jiffies + msecs_to_jiffies(1);
345 u8 status_byte = 0; 358 u8 status_byte = 0;
@@ -364,10 +377,12 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
364 buffer[2] = config; 377 buffer[2] = config;
365 buffer[3] = cb; 378 buffer[3] = cb;
366 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", 379 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
367 buffer[0],buffer[1],buffer[2],buffer[3]); 380 buffer[0],buffer[1],buffer[2],buffer[3]);
368 381
369 if (4 != (rc = i2c_master_send(c,buffer,4))) 382 if (4 != (rc = i2c_master_send(c,buffer,4)))
370 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); 383 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
384 break;
385 }
371 } 386 }
372} 387}
373 388
diff --git a/drivers/media/video/tuner-types.c b/drivers/media/video/tuner-types.c
index a167e17c6dcd..8b542599ed47 100644
--- a/drivers/media/video/tuner-types.c
+++ b/drivers/media/video/tuner-types.c
@@ -926,11 +926,17 @@ static struct tuner_params tuner_lg_tdvs_h06xf_params[] = {
926 926
927/* ------------ TUNER_YMEC_TVF66T5_B_DFF - Philips PAL ------------ */ 927/* ------------ TUNER_YMEC_TVF66T5_B_DFF - Philips PAL ------------ */
928 928
929static struct tuner_range tuner_ymec_tvf66t5_b_dff_pal_ranges[] = {
930 { 16 * 160.25 /*MHz*/, 0x8e, 0x01, },
931 { 16 * 464.25 /*MHz*/, 0x8e, 0x02, },
932 { 16 * 999.99 , 0x8e, 0x08, },
933};
934
929static struct tuner_params tuner_ymec_tvf66t5_b_dff_params[] = { 935static struct tuner_params tuner_ymec_tvf66t5_b_dff_params[] = {
930 { 936 {
931 .type = TUNER_PARAM_TYPE_PAL, 937 .type = TUNER_PARAM_TYPE_PAL,
932 .ranges = tuner_tena_9533_di_pal_ranges, 938 .ranges = tuner_ymec_tvf66t5_b_dff_pal_ranges,
933 .count = ARRAY_SIZE(tuner_tena_9533_di_pal_ranges), 939 .count = ARRAY_SIZE(tuner_ymec_tvf66t5_b_dff_pal_ranges),
934 }, 940 },
935}; 941};
936 942
@@ -1027,10 +1033,11 @@ static struct tuner_params tuner_tnf_5335mf_params[] = {
1027/* 70-79 */ 1033/* 70-79 */
1028/* ------------ TUNER_SAMSUNG_TCPN_2121P30A - Samsung NTSC ------------ */ 1034/* ------------ TUNER_SAMSUNG_TCPN_2121P30A - Samsung NTSC ------------ */
1029 1035
1036/* '+ 4' turns on the Low Noise Amplifier */
1030static struct tuner_range tuner_samsung_tcpn_2121p30a_ntsc_ranges[] = { 1037static struct tuner_range tuner_samsung_tcpn_2121p30a_ntsc_ranges[] = {
1031 { 16 * 130.00 /*MHz*/, 0xce, 0x01, }, 1038 { 16 * 130.00 /*MHz*/, 0xce, 0x01 + 4, },
1032 { 16 * 364.50 /*MHz*/, 0xce, 0x02, }, 1039 { 16 * 364.50 /*MHz*/, 0xce, 0x02 + 4, },
1033 { 16 * 999.99 , 0xce, 0x08, }, 1040 { 16 * 999.99 , 0xce, 0x08 + 4, },
1034}; 1041};
1035 1042
1036static struct tuner_params tuner_samsung_tcpn_2121p30a_params[] = { 1043static struct tuner_params tuner_samsung_tcpn_2121p30a_params[] = {
@@ -1060,10 +1067,11 @@ static struct tuner_params tuner_thomson_fe6600_params[] = {
1060 1067
1061/* ------------ TUNER_SAMSUNG_TCPG_6121P30A - Samsung PAL ------------ */ 1068/* ------------ TUNER_SAMSUNG_TCPG_6121P30A - Samsung PAL ------------ */
1062 1069
1070/* '+ 4' turns on the Low Noise Amplifier */
1063static struct tuner_range tuner_samsung_tcpg_6121p30a_pal_ranges[] = { 1071static struct tuner_range tuner_samsung_tcpg_6121p30a_pal_ranges[] = {
1064 { 16 * 146.25 /*MHz*/, 0xce, 0x01, }, 1072 { 16 * 146.25 /*MHz*/, 0xce, 0x01 + 4, },
1065 { 16 * 428.50 /*MHz*/, 0xce, 0x02, }, 1073 { 16 * 428.50 /*MHz*/, 0xce, 0x02 + 4, },
1066 { 16 * 999.99 , 0xce, 0x08, }, 1074 { 16 * 999.99 , 0xce, 0x08 + 4, },
1067}; 1075};
1068 1076
1069static struct tuner_params tuner_samsung_tcpg_6121p30a_params[] = { 1077static struct tuner_params tuner_samsung_tcpg_6121p30a_params[] = {
diff --git a/drivers/media/video/usbvideo/Kconfig b/drivers/media/video/usbvideo/Kconfig
index 59fb899f31f3..a0fd82b924f2 100644
--- a/drivers/media/video/usbvideo/Kconfig
+++ b/drivers/media/video/usbvideo/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_USBVIDEO
3 3
4config USB_VICAM 4config USB_VICAM
5 tristate "USB 3com HomeConnect (aka vicam) support (EXPERIMENTAL)" 5 tristate "USB 3com HomeConnect (aka vicam) support (EXPERIMENTAL)"
6 depends on USB && VIDEO_V4L1 && EXPERIMENTAL 6 depends on USB && VIDEO_DEV && VIDEO_V4L1 && EXPERIMENTAL
7 select VIDEO_USBVIDEO 7 select VIDEO_USBVIDEO
8 ---help--- 8 ---help---
9 Say Y here if you have 3com homeconnect camera (vicam). 9 Say Y here if you have 3com homeconnect camera (vicam).
@@ -13,7 +13,7 @@ config USB_VICAM
13 13
14config USB_IBMCAM 14config USB_IBMCAM
15 tristate "USB IBM (Xirlink) C-it Camera support" 15 tristate "USB IBM (Xirlink) C-it Camera support"
16 depends on USB && VIDEO_V4L1 16 depends on USB && VIDEO_DEV && VIDEO_V4L1
17 select VIDEO_USBVIDEO 17 select VIDEO_USBVIDEO
18 ---help--- 18 ---help---
19 Say Y here if you want to connect a IBM "C-It" camera, also known as 19 Say Y here if you want to connect a IBM "C-It" camera, also known as
@@ -28,7 +28,7 @@ config USB_IBMCAM
28 28
29config USB_KONICAWC 29config USB_KONICAWC
30 tristate "USB Konica Webcam support" 30 tristate "USB Konica Webcam support"
31 depends on USB && VIDEO_V4L1 31 depends on USB && VIDEO_DEV && VIDEO_V4L1
32 select VIDEO_USBVIDEO 32 select VIDEO_USBVIDEO
33 ---help--- 33 ---help---
34 Say Y here if you want support for webcams based on a Konica 34 Say Y here if you want support for webcams based on a Konica
@@ -39,7 +39,7 @@ config USB_KONICAWC
39 39
40config USB_QUICKCAM_MESSENGER 40config USB_QUICKCAM_MESSENGER
41 tristate "USB Logitech Quickcam Messenger" 41 tristate "USB Logitech Quickcam Messenger"
42 depends on USB && VIDEO_DEV 42 depends on USB && VIDEO_DEV && VIDEO_V4L1
43 select VIDEO_USBVIDEO 43 select VIDEO_USBVIDEO
44 ---help--- 44 ---help---
45 Say Y or M here to enable support for the USB Logitech Quickcam 45 Say Y or M here to enable support for the USB Logitech Quickcam
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index d83a2c84d233..d7c3fcbc80f7 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -599,6 +599,10 @@ v4l_compat_translate_ioctl(struct inode *inode,
599 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n",err); 599 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n",err);
600 break; 600 break;
601 } 601 }
602
603 pict->depth = ((fmt2->fmt.pix.bytesperline<<3)
604 + (fmt2->fmt.pix.width-1) )
605 /fmt2->fmt.pix.width;
602 pict->palette = pixelformat_to_palette( 606 pict->palette = pixelformat_to_palette(
603 fmt2->fmt.pix.pixelformat); 607 fmt2->fmt.pix.pixelformat);
604 break; 608 break;
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index f06dc19e504a..8d972ffdaf98 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -202,7 +202,7 @@ static char *v4l2_memory_names[] = {
202/* ------------------------------------------------------------------ */ 202/* ------------------------------------------------------------------ */
203/* debug help functions */ 203/* debug help functions */
204 204
205#ifdef HAVE_V4L1 205#ifdef CONFIG_VIDEO_V4L1_COMPAT
206static const char *v4l1_ioctls[] = { 206static const char *v4l1_ioctls[] = {
207 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP", 207 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
208 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN", 208 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
@@ -301,7 +301,7 @@ static const char *v4l2_ioctls[] = {
301#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) 301#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
302 302
303static const char *v4l2_int_ioctls[] = { 303static const char *v4l2_int_ioctls[] = {
304#ifdef HAVE_VIDEO_DECODER 304#ifdef CONFIG_VIDEO_V4L1_COMPAT
305 [_IOC_NR(DECODER_GET_CAPABILITIES)] = "DECODER_GET_CAPABILITIES", 305 [_IOC_NR(DECODER_GET_CAPABILITIES)] = "DECODER_GET_CAPABILITIES",
306 [_IOC_NR(DECODER_GET_STATUS)] = "DECODER_GET_STATUS", 306 [_IOC_NR(DECODER_GET_STATUS)] = "DECODER_GET_STATUS",
307 [_IOC_NR(DECODER_SET_NORM)] = "DECODER_SET_NORM", 307 [_IOC_NR(DECODER_SET_NORM)] = "DECODER_SET_NORM",
@@ -367,7 +367,7 @@ void v4l_printk_ioctl(unsigned int cmd)
367 (_IOC_NR(cmd) < V4L2_INT_IOCTLS) ? 367 (_IOC_NR(cmd) < V4L2_INT_IOCTLS) ?
368 v4l2_int_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd); 368 v4l2_int_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd);
369 break; 369 break;
370#ifdef HAVE_V4L1 370#ifdef CONFIG_VIDEO_V4L1_COMPAT
371 case 'v': 371 case 'v':
372 printk("v4l1 ioctl %s, dir=%s (0x%08x)\n", 372 printk("v4l1 ioctl %s, dir=%s (0x%08x)\n",
373 (_IOC_NR(cmd) < V4L1_IOCTLS) ? 373 (_IOC_NR(cmd) < V4L1_IOCTLS) ?
@@ -414,6 +414,7 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
414 printk ("%s: tuner type=%d\n", s, *p); 414 printk ("%s: tuner type=%d\n", s, *p);
415 break; 415 break;
416 } 416 }
417#ifdef CONFIG_VIDEO_V4L1_COMPAT
417 case DECODER_SET_VBI_BYPASS: 418 case DECODER_SET_VBI_BYPASS:
418 case DECODER_ENABLE_OUTPUT: 419 case DECODER_ENABLE_OUTPUT:
419 case DECODER_GET_STATUS: 420 case DECODER_GET_STATUS:
@@ -424,6 +425,7 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
424 case VIDIOCCAPTURE: 425 case VIDIOCCAPTURE:
425 case VIDIOCSYNC: 426 case VIDIOCSYNC:
426 case VIDIOCSWRITEMODE: 427 case VIDIOCSWRITEMODE:
428#endif
427 case TUNER_SET_TYPE_ADDR: 429 case TUNER_SET_TYPE_ADDR:
428 case TUNER_SET_STANDBY: 430 case TUNER_SET_STANDBY:
429 case TDA9887_SET_CONFIG: 431 case TDA9887_SET_CONFIG:
@@ -755,6 +757,7 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
755 p->afc); 757 p->afc);
756 break; 758 break;
757 } 759 }
760#ifdef CONFIG_VIDEO_V4L1_COMPAT
758 case VIDIOCGVBIFMT: 761 case VIDIOCGVBIFMT:
759 case VIDIOCSVBIFMT: 762 case VIDIOCSVBIFMT:
760 { 763 {
@@ -924,6 +927,14 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
924 p->clipcount); 927 p->clipcount);
925 break; 928 break;
926 } 929 }
930 case VIDIOCGFREQ:
931 case VIDIOCSFREQ:
932 {
933 unsigned long *p=arg;
934 printk ("%s: value=%lu\n", s, *p);
935 break;
936 }
937#endif
927 case VIDIOC_INT_AUDIO_CLOCK_FREQ: 938 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
928 case VIDIOC_INT_I2S_CLOCK_FREQ: 939 case VIDIOC_INT_I2S_CLOCK_FREQ:
929 case VIDIOC_INT_S_STANDBY: 940 case VIDIOC_INT_S_STANDBY:
@@ -933,13 +944,6 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg)
933 printk ("%s: value=%d\n", s, *p); 944 printk ("%s: value=%d\n", s, *p);
934 break; 945 break;
935 } 946 }
936 case VIDIOCGFREQ:
937 case VIDIOCSFREQ:
938 {
939 unsigned long *p=arg;
940 printk ("%s: value=%lu\n", s, *p);
941 break;
942 }
943 case VIDIOC_G_STD: 947 case VIDIOC_G_STD:
944 case VIDIOC_S_STD: 948 case VIDIOC_S_STD:
945 case VIDIOC_QUERYSTD: 949 case VIDIOC_QUERYSTD:
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index b26ebaff226f..88bf2af2a0e7 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -760,7 +760,7 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
760 ret=vfd->vidioc_overlay(file, fh, *i); 760 ret=vfd->vidioc_overlay(file, fh, *i);
761 break; 761 break;
762 } 762 }
763#ifdef HAVE_V4L1 763#ifdef CONFIG_VIDEO_V4L1_COMPAT
764 /* --- streaming capture ------------------------------------- */ 764 /* --- streaming capture ------------------------------------- */
765 case VIDIOCGMBUF: 765 case VIDIOCGMBUF:
766 { 766 {
@@ -1512,6 +1512,7 @@ int video_register_device(struct video_device *vfd, int type, int nr)
1512 int i=0; 1512 int i=0;
1513 int base; 1513 int base;
1514 int end; 1514 int end;
1515 int ret;
1515 char *name_base; 1516 char *name_base;
1516 1517
1517 switch(type) 1518 switch(type)
@@ -1537,6 +1538,8 @@ int video_register_device(struct video_device *vfd, int type, int nr)
1537 name_base = "radio"; 1538 name_base = "radio";
1538 break; 1539 break;
1539 default: 1540 default:
1541 printk(KERN_ERR "%s called with unknown type: %d\n",
1542 __FUNCTION__, type);
1540 return -1; 1543 return -1;
1541 } 1544 }
1542 1545
@@ -1571,9 +1574,18 @@ int video_register_device(struct video_device *vfd, int type, int nr)
1571 vfd->class_dev.class = &video_class; 1574 vfd->class_dev.class = &video_class;
1572 vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor); 1575 vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
1573 sprintf(vfd->class_dev.class_id, "%s%d", name_base, i - base); 1576 sprintf(vfd->class_dev.class_id, "%s%d", name_base, i - base);
1574 class_device_register(&vfd->class_dev); 1577 ret = class_device_register(&vfd->class_dev);
1575 class_device_create_file(&vfd->class_dev, 1578 if (ret < 0) {
1576 &class_device_attr_name); 1579 printk(KERN_ERR "%s: class_device_register failed\n",
1580 __FUNCTION__);
1581 goto fail_minor;
1582 }
1583 ret = class_device_create_file(&vfd->class_dev, &class_device_attr_name);
1584 if (ret < 0) {
1585 printk(KERN_ERR "%s: class_device_create_file 'name' failed\n",
1586 __FUNCTION__);
1587 goto fail_classdev;
1588 }
1577 1589
1578#if 1 1590#if 1
1579 /* needed until all drivers are fixed */ 1591 /* needed until all drivers are fixed */
@@ -1583,6 +1595,15 @@ int video_register_device(struct video_device *vfd, int type, int nr)
1583 "http://lwn.net/Articles/36850/\n", vfd->name); 1595 "http://lwn.net/Articles/36850/\n", vfd->name);
1584#endif 1596#endif
1585 return 0; 1597 return 0;
1598
1599fail_classdev:
1600 class_device_unregister(&vfd->class_dev);
1601fail_minor:
1602 mutex_lock(&videodev_lock);
1603 video_device[vfd->minor] = NULL;
1604 vfd->minor = -1;
1605 mutex_unlock(&videodev_lock);
1606 return ret;
1586} 1607}
1587 1608
1588/** 1609/**
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 41d23c8acbd8..841884af0cc0 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -986,7 +986,7 @@ static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p)
986 file->f_flags & O_NONBLOCK)); 986 file->f_flags & O_NONBLOCK));
987} 987}
988 988
989#ifdef HAVE_V4L1 989#ifdef CONFIG_VIDEO_V4L1_COMPAT
990static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf) 990static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
991{ 991{
992 struct vivi_fh *fh=priv; 992 struct vivi_fh *fh=priv;
@@ -1328,7 +1328,7 @@ static struct video_device vivi = {
1328 .vidioc_s_ctrl = vidioc_s_ctrl, 1328 .vidioc_s_ctrl = vidioc_s_ctrl,
1329 .vidioc_streamon = vidioc_streamon, 1329 .vidioc_streamon = vidioc_streamon,
1330 .vidioc_streamoff = vidioc_streamoff, 1330 .vidioc_streamoff = vidioc_streamoff,
1331#ifdef HAVE_V4L1 1331#ifdef CONFIG_VIDEO_V4L1_COMPAT
1332 .vidiocgmbuf = vidiocgmbuf, 1332 .vidiocgmbuf = vidiocgmbuf,
1333#endif 1333#endif
1334 .tvnorms = tvnorms, 1334 .tvnorms = tvnorms,
diff --git a/drivers/media/video/zoran.h b/drivers/media/video/zoran.h
index ffcda95ed9d4..8fb4a3414e0a 100644
--- a/drivers/media/video/zoran.h
+++ b/drivers/media/video/zoran.h
@@ -267,7 +267,7 @@ struct zoran_v4l_settings {
267}; 267};
268 268
269/* whoops, this one is undeclared if !v4l2 */ 269/* whoops, this one is undeclared if !v4l2 */
270#ifndef HAVE_V4L2 270#ifndef CONFIG_VIDEO_V4L2
271struct v4l2_jpegcompression { 271struct v4l2_jpegcompression {
272 int quality; 272 int quality;
273 int APPn; 273 int APPn;
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index d9a5876eb386..5f90db27892b 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -86,7 +86,7 @@
86#include "zoran_device.h" 86#include "zoran_device.h"
87#include "zoran_card.h" 87#include "zoran_card.h"
88 88
89#ifdef HAVE_V4L2 89#ifdef CONFIG_VIDEO_V4L2
90 /* we declare some card type definitions here, they mean 90 /* we declare some card type definitions here, they mean
91 * the same as the v4l1 ZORAN_VID_TYPE above, except it's v4l2 */ 91 * the same as the v4l1 ZORAN_VID_TYPE above, except it's v4l2 */
92#define ZORAN_V4L2_VID_FLAGS ( \ 92#define ZORAN_V4L2_VID_FLAGS ( \
@@ -103,7 +103,7 @@ const struct zoran_format zoran_formats[] = {
103 { 103 {
104 .name = "15-bit RGB", 104 .name = "15-bit RGB",
105 .palette = VIDEO_PALETTE_RGB555, 105 .palette = VIDEO_PALETTE_RGB555,
106#ifdef HAVE_V4L2 106#ifdef CONFIG_VIDEO_V4L2
107#ifdef __LITTLE_ENDIAN 107#ifdef __LITTLE_ENDIAN
108 .fourcc = V4L2_PIX_FMT_RGB555, 108 .fourcc = V4L2_PIX_FMT_RGB555,
109#else 109#else
@@ -117,7 +117,7 @@ const struct zoran_format zoran_formats[] = {
117 }, { 117 }, {
118 .name = "16-bit RGB", 118 .name = "16-bit RGB",
119 .palette = VIDEO_PALETTE_RGB565, 119 .palette = VIDEO_PALETTE_RGB565,
120#ifdef HAVE_V4L2 120#ifdef CONFIG_VIDEO_V4L2
121#ifdef __LITTLE_ENDIAN 121#ifdef __LITTLE_ENDIAN
122 .fourcc = V4L2_PIX_FMT_RGB565, 122 .fourcc = V4L2_PIX_FMT_RGB565,
123#else 123#else
@@ -131,7 +131,7 @@ const struct zoran_format zoran_formats[] = {
131 }, { 131 }, {
132 .name = "24-bit RGB", 132 .name = "24-bit RGB",
133 .palette = VIDEO_PALETTE_RGB24, 133 .palette = VIDEO_PALETTE_RGB24,
134#ifdef HAVE_V4L2 134#ifdef CONFIG_VIDEO_V4L2
135#ifdef __LITTLE_ENDIAN 135#ifdef __LITTLE_ENDIAN
136 .fourcc = V4L2_PIX_FMT_BGR24, 136 .fourcc = V4L2_PIX_FMT_BGR24,
137#else 137#else
@@ -145,7 +145,7 @@ const struct zoran_format zoran_formats[] = {
145 }, { 145 }, {
146 .name = "32-bit RGB", 146 .name = "32-bit RGB",
147 .palette = VIDEO_PALETTE_RGB32, 147 .palette = VIDEO_PALETTE_RGB32,
148#ifdef HAVE_V4L2 148#ifdef CONFIG_VIDEO_V4L2
149#ifdef __LITTLE_ENDIAN 149#ifdef __LITTLE_ENDIAN
150 .fourcc = V4L2_PIX_FMT_BGR32, 150 .fourcc = V4L2_PIX_FMT_BGR32,
151#else 151#else
@@ -159,7 +159,7 @@ const struct zoran_format zoran_formats[] = {
159 }, { 159 }, {
160 .name = "4:2:2, packed, YUYV", 160 .name = "4:2:2, packed, YUYV",
161 .palette = VIDEO_PALETTE_YUV422, 161 .palette = VIDEO_PALETTE_YUV422,
162#ifdef HAVE_V4L2 162#ifdef CONFIG_VIDEO_V4L2
163 .fourcc = V4L2_PIX_FMT_YUYV, 163 .fourcc = V4L2_PIX_FMT_YUYV,
164 .colorspace = V4L2_COLORSPACE_SMPTE170M, 164 .colorspace = V4L2_COLORSPACE_SMPTE170M,
165#endif 165#endif
@@ -169,7 +169,7 @@ const struct zoran_format zoran_formats[] = {
169 }, { 169 }, {
170 .name = "Hardware-encoded Motion-JPEG", 170 .name = "Hardware-encoded Motion-JPEG",
171 .palette = -1, 171 .palette = -1,
172#ifdef HAVE_V4L2 172#ifdef CONFIG_VIDEO_V4L2
173 .fourcc = V4L2_PIX_FMT_MJPEG, 173 .fourcc = V4L2_PIX_FMT_MJPEG,
174 .colorspace = V4L2_COLORSPACE_SMPTE170M, 174 .colorspace = V4L2_COLORSPACE_SMPTE170M,
175#endif 175#endif
@@ -210,7 +210,7 @@ static int lock_norm = 0; /* 1=Don't change TV standard (norm) */
210module_param(lock_norm, int, 0); 210module_param(lock_norm, int, 0);
211MODULE_PARM_DESC(lock_norm, "Users can't change norm"); 211MODULE_PARM_DESC(lock_norm, "Users can't change norm");
212 212
213#ifdef HAVE_V4L2 213#ifdef CONFIG_VIDEO_V4L2
214 /* small helper function for calculating buffersizes for v4l2 214 /* small helper function for calculating buffersizes for v4l2
215 * we calculate the nearest higher power-of-two, which 215 * we calculate the nearest higher power-of-two, which
216 * will be the recommended buffersize */ 216 * will be the recommended buffersize */
@@ -1761,7 +1761,7 @@ setup_overlay (struct file *file,
1761 return wait_grab_pending(zr); 1761 return wait_grab_pending(zr);
1762} 1762}
1763 1763
1764#ifdef HAVE_V4L2 1764#ifdef CONFIG_VIDEO_V4L2
1765 /* get the status of a buffer in the clients buffer queue */ 1765 /* get the status of a buffer in the clients buffer queue */
1766static int 1766static int
1767zoran_v4l2_buffer_status (struct file *file, 1767zoran_v4l2_buffer_status (struct file *file,
@@ -2676,7 +2676,7 @@ zoran_do_ioctl (struct inode *inode,
2676 } 2676 }
2677 break; 2677 break;
2678 2678
2679#ifdef HAVE_V4L2 2679#ifdef CONFIG_VIDEO_V4L2
2680 2680
2681 /* The new video4linux2 capture interface - much nicer than video4linux1, since 2681 /* The new video4linux2 capture interface - much nicer than video4linux1, since
2682 * it allows for integrating the JPEG capturing calls inside standard v4l2 2682 * it allows for integrating the JPEG capturing calls inside standard v4l2
@@ -4689,7 +4689,7 @@ static struct file_operations zoran_fops = {
4689struct video_device zoran_template __devinitdata = { 4689struct video_device zoran_template __devinitdata = {
4690 .name = ZORAN_NAME, 4690 .name = ZORAN_NAME,
4691 .type = ZORAN_VID_TYPE, 4691 .type = ZORAN_VID_TYPE,
4692#ifdef HAVE_V4L2 4692#ifdef CONFIG_VIDEO_V4L2
4693 .type2 = ZORAN_V4L2_VID_FLAGS, 4693 .type2 = ZORAN_V4L2_VID_FLAGS,
4694#endif 4694#endif
4695 .hardware = ZORAN_HARDWARE, 4695 .hardware = ZORAN_HARDWARE,
diff --git a/drivers/message/fusion/Kconfig b/drivers/message/fusion/Kconfig
index bbc229852881..ea31d8470510 100644
--- a/drivers/message/fusion/Kconfig
+++ b/drivers/message/fusion/Kconfig
@@ -48,10 +48,8 @@ config FUSION_SAS
48 List of supported controllers: 48 List of supported controllers:
49 49
50 LSISAS1064 50 LSISAS1064
51 LSISAS1066
52 LSISAS1068 51 LSISAS1068
53 LSISAS1064E 52 LSISAS1064E
54 LSISAS1066E
55 LSISAS1068E 53 LSISAS1068E
56 54
57config FUSION_MAX_SGE 55config FUSION_MAX_SGE
diff --git a/drivers/message/fusion/Makefile b/drivers/message/fusion/Makefile
index 51740b346224..341691390e86 100644
--- a/drivers/message/fusion/Makefile
+++ b/drivers/message/fusion/Makefile
@@ -9,7 +9,6 @@
9#EXTRA_CFLAGS += -DMPT_DEBUG_EXIT 9#EXTRA_CFLAGS += -DMPT_DEBUG_EXIT
10#EXTRA_CFLAGS += -DMPT_DEBUG_FAIL 10#EXTRA_CFLAGS += -DMPT_DEBUG_FAIL
11 11
12
13# 12#
14# driver/module specifics... 13# driver/module specifics...
15# 14#
@@ -33,6 +32,11 @@
33# For mptfc: 32# For mptfc:
34#CFLAGS_mptfc.o += -DMPT_DEBUG_FC 33#CFLAGS_mptfc.o += -DMPT_DEBUG_FC
35 34
35# For mptsas:
36#CFLAGS_mptsas.o += -DMPT_DEBUG_SAS
37#CFLAGS_mptsas.o += -DMPT_DEBUG_SAS_WIDE
38
39
36#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-} LSI_LOGIC 40#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-} LSI_LOGIC
37 41
38obj-$(CONFIG_FUSION_SPI) += mptbase.o mptscsih.o mptspi.o 42obj-$(CONFIG_FUSION_SPI) += mptbase.o mptscsih.o mptspi.o
diff --git a/drivers/message/fusion/lsi/fc_log.h b/drivers/message/fusion/lsi/fc_log.h
deleted file mode 100644
index dc98d46f9071..000000000000
--- a/drivers/message/fusion/lsi/fc_log.h
+++ /dev/null
@@ -1,89 +0,0 @@
1/*
2 * Copyright (c) 2000-2001 LSI Logic Corporation. All rights reserved.
3 *
4 * NAME: fc_log.h
5 * SUMMARY: MPI IocLogInfo definitions for the SYMFC9xx chips
6 * DESCRIPTION: Contains the enumerated list of values that may be returned
7 * in the IOCLogInfo field of a MPI Default Reply Message.
8 *
9 * CREATION DATE: 6/02/2000
10 * ID: $Id: fc_log.h,v 4.6 2001/07/26 14:41:33 sschremm Exp $
11 */
12
13
14/*
15 * MpiIocLogInfo_t enum
16 *
17 * These 32 bit values are used in the IOCLogInfo field of the MPI reply
18 * messages.
19 * The value is 0xabcccccc where
20 * a = The type of log info as per the MPI spec. Since these codes are
21 * all for Fibre Channel this value will always be 2.
22 * b = Specifies a subclass of the firmware where
23 * 0 = FCP Initiator
24 * 1 = FCP Target
25 * 2 = LAN
26 * 3 = MPI Message Layer
27 * 4 = FC Link
28 * 5 = Context Manager
29 * 6 = Invalid Field Offset
30 * 7 = State Change Info
31 * all others are reserved for future use
32 * c = A specific value within the subclass.
33 *
34 * NOTE: Any new values should be added to the end of each subclass so that the
35 * codes remain consistent across firmware releases.
36 */
37typedef enum _MpiIocLogInfoFc
38{
39 MPI_IOCLOGINFO_FC_INIT_BASE = 0x20000000,
40 MPI_IOCLOGINFO_FC_INIT_ERROR_OUT_OF_ORDER_FRAME = 0x20000001, /* received an out of order frame - unsupported */
41 MPI_IOCLOGINFO_FC_INIT_ERROR_BAD_START_OF_FRAME = 0x20000002, /* Bad Rx Frame, bad start of frame primative */
42 MPI_IOCLOGINFO_FC_INIT_ERROR_BAD_END_OF_FRAME = 0x20000003, /* Bad Rx Frame, bad end of frame primative */
43 MPI_IOCLOGINFO_FC_INIT_ERROR_OVER_RUN = 0x20000004, /* Bad Rx Frame, overrun */
44 MPI_IOCLOGINFO_FC_INIT_ERROR_RX_OTHER = 0x20000005, /* Other errors caught by IOC which require retries */
45 MPI_IOCLOGINFO_FC_INIT_ERROR_SUBPROC_DEAD = 0x20000006, /* Main processor could not initialize sub-processor */
46 MPI_IOCLOGINFO_FC_INIT_ERROR_RX_OVERRUN = 0x20000007, /* Scatter Gather overrun */
47 MPI_IOCLOGINFO_FC_INIT_ERROR_RX_BAD_STATUS = 0x20000008, /* Receiver detected context mismatch via invalid header */
48 MPI_IOCLOGINFO_FC_INIT_ERROR_RX_UNEXPECTED_FRAME= 0x20000009, /* CtxMgr detected unsupported frame type */
49 MPI_IOCLOGINFO_FC_INIT_ERROR_LINK_FAILURE = 0x2000000A, /* Link failure occurred */
50 MPI_IOCLOGINFO_FC_INIT_ERROR_TX_TIMEOUT = 0x2000000B, /* Transmitter timeout error */
51
52 MPI_IOCLOGINFO_FC_TARGET_BASE = 0x21000000,
53 MPI_IOCLOGINFO_FC_TARGET_NO_PDISC = 0x21000001, /* not sent because we are waiting for a PDISC from the initiator */
54 MPI_IOCLOGINFO_FC_TARGET_NO_LOGIN = 0x21000002, /* not sent because we are not logged in to the remote node */
55 MPI_IOCLOGINFO_FC_TARGET_DOAR_KILLED_BY_LIP = 0x21000003, /* Data Out, Auto Response, not sent due to a LIP */
56 MPI_IOCLOGINFO_FC_TARGET_DIAR_KILLED_BY_LIP = 0x21000004, /* Data In, Auto Response, not sent due to a LIP */
57 MPI_IOCLOGINFO_FC_TARGET_DIAR_MISSING_DATA = 0x21000005, /* Data In, Auto Response, missing data frames */
58 MPI_IOCLOGINFO_FC_TARGET_DONR_KILLED_BY_LIP = 0x21000006, /* Data Out, No Response, not sent due to a LIP */
59 MPI_IOCLOGINFO_FC_TARGET_WRSP_KILLED_BY_LIP = 0x21000007, /* Auto-response after a write not sent due to a LIP */
60 MPI_IOCLOGINFO_FC_TARGET_DINR_KILLED_BY_LIP = 0x21000008, /* Data In, No Response, not completed due to a LIP */
61 MPI_IOCLOGINFO_FC_TARGET_DINR_MISSING_DATA = 0x21000009, /* Data In, No Response, missing data frames */
62 MPI_IOCLOGINFO_FC_TARGET_MRSP_KILLED_BY_LIP = 0x2100000a, /* Manual Response not sent due to a LIP */
63 MPI_IOCLOGINFO_FC_TARGET_NO_CLASS_3 = 0x2100000b, /* not sent because remote node does not support Class 3 */
64 MPI_IOCLOGINFO_FC_TARGET_LOGIN_NOT_VALID = 0x2100000c, /* not sent because login to remote node not validated */
65 MPI_IOCLOGINFO_FC_TARGET_FROM_OUTBOUND = 0x2100000e, /* cleared from the outbound queue after a logout */
66 MPI_IOCLOGINFO_FC_TARGET_WAITING_FOR_DATA_IN = 0x2100000f, /* cleared waiting for data after a logout */
67
68 MPI_IOCLOGINFO_FC_LAN_BASE = 0x22000000,
69 MPI_IOCLOGINFO_FC_LAN_TRANS_SGL_MISSING = 0x22000001, /* Transaction Context Sgl Missing */
70 MPI_IOCLOGINFO_FC_LAN_TRANS_WRONG_PLACE = 0x22000002, /* Transaction Context found before an EOB */
71 MPI_IOCLOGINFO_FC_LAN_TRANS_RES_BITS_SET = 0x22000003, /* Transaction Context value has reserved bits set */
72 MPI_IOCLOGINFO_FC_LAN_WRONG_SGL_FLAG = 0x22000004, /* Invalid SGL Flags */
73
74 MPI_IOCLOGINFO_FC_MSG_BASE = 0x23000000,
75
76 MPI_IOCLOGINFO_FC_LINK_BASE = 0x24000000,
77 MPI_IOCLOGINFO_FC_LINK_LOOP_INIT_TIMEOUT = 0x24000001, /* Loop initialization timed out */
78 MPI_IOCLOGINFO_FC_LINK_ALREADY_INITIALIZED = 0x24000002, /* Another system controller already initialized the loop */
79 MPI_IOCLOGINFO_FC_LINK_LINK_NOT_ESTABLISHED = 0x24000003, /* Not synchronized to signal or still negotiating (possible cable problem) */
80 MPI_IOCLOGINFO_FC_LINK_CRC_ERROR = 0x24000004, /* CRC check detected error on received frame */
81
82 MPI_IOCLOGINFO_FC_CTX_BASE = 0x25000000,
83
84 MPI_IOCLOGINFO_FC_INVALID_FIELD_BYTE_OFFSET = 0x26000000, /* The lower 24 bits give the byte offset of the field in the request message that is invalid */
85 MPI_IOCLOGINFO_FC_INVALID_FIELD_MAX_OFFSET = 0x26ffffff,
86
87 MPI_IOCLOGINFO_FC_STATE_CHANGE = 0x27000000 /* The lower 24 bits give additional information concerning state change */
88
89} MpiIocLogInfoFc_t;
diff --git a/drivers/message/fusion/lsi/mpi.h b/drivers/message/fusion/lsi/mpi.h
index 02cdc840a06b..81ad77622dac 100644
--- a/drivers/message/fusion/lsi/mpi.h
+++ b/drivers/message/fusion/lsi/mpi.h
@@ -6,7 +6,7 @@
6 * Title: MPI Message independent structures and definitions 6 * Title: MPI Message independent structures and definitions
7 * Creation Date: July 27, 2000 7 * Creation Date: July 27, 2000
8 * 8 *
9 * mpi.h Version: 01.05.10 9 * mpi.h Version: 01.05.11
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -76,6 +76,7 @@
76 * Added EEDP IOCStatus codes. 76 * Added EEDP IOCStatus codes.
77 * 08-03-05 01.05.09 Bumped MPI_HEADER_VERSION_UNIT. 77 * 08-03-05 01.05.09 Bumped MPI_HEADER_VERSION_UNIT.
78 * 08-30-05 01.05.10 Added 2 new IOCStatus codes for Target. 78 * 08-30-05 01.05.10 Added 2 new IOCStatus codes for Target.
79 * 03-27-06 01.05.11 Bumped MPI_HEADER_VERSION_UNIT.
79 * -------------------------------------------------------------------------- 80 * --------------------------------------------------------------------------
80 */ 81 */
81 82
@@ -106,7 +107,7 @@
106/* Note: The major versions of 0xe0 through 0xff are reserved */ 107/* Note: The major versions of 0xe0 through 0xff are reserved */
107 108
108/* versioning for this MPI header set */ 109/* versioning for this MPI header set */
109#define MPI_HEADER_VERSION_UNIT (0x0C) 110#define MPI_HEADER_VERSION_UNIT (0x0D)
110#define MPI_HEADER_VERSION_DEV (0x00) 111#define MPI_HEADER_VERSION_DEV (0x00)
111#define MPI_HEADER_VERSION_UNIT_MASK (0xFF00) 112#define MPI_HEADER_VERSION_UNIT_MASK (0xFF00)
112#define MPI_HEADER_VERSION_UNIT_SHIFT (8) 113#define MPI_HEADER_VERSION_UNIT_SHIFT (8)
diff --git a/drivers/message/fusion/lsi/mpi_cnfg.h b/drivers/message/fusion/lsi/mpi_cnfg.h
index b1becec27e1b..47e13e360c10 100644
--- a/drivers/message/fusion/lsi/mpi_cnfg.h
+++ b/drivers/message/fusion/lsi/mpi_cnfg.h
@@ -6,7 +6,7 @@
6 * Title: MPI Config message, structures, and Pages 6 * Title: MPI Config message, structures, and Pages
7 * Creation Date: July 27, 2000 7 * Creation Date: July 27, 2000
8 * 8 *
9 * mpi_cnfg.h Version: 01.05.11 9 * mpi_cnfg.h Version: 01.05.12
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -266,6 +266,16 @@
266 * Added postpone SATA Init bit to SAS IO Unit Page 1 266 * Added postpone SATA Init bit to SAS IO Unit Page 1
267 * ControlFlags. 267 * ControlFlags.
268 * Changed LogEntry format for Log Page 0. 268 * Changed LogEntry format for Log Page 0.
269 * 03-27-06 01.05.12 Added two new Flags defines for Manufacturing Page 4.
270 * Added Manufacturing Page 7.
271 * Added MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING.
272 * Added IOC Page 6.
273 * Added PrevBootDeviceForm field to CONFIG_PAGE_BIOS_2.
274 * Added MaxLBAHigh field to RAID Volume Page 0.
275 * Added Nvdata version fields to SAS IO Unit Page 0.
276 * Added AdditionalControlFlags, MaxTargetPortConnectTime,
277 * ReportDeviceMissingDelay, and IODeviceMissingDelay
278 * fields to SAS IO Unit Page 1.
269 * -------------------------------------------------------------------------- 279 * --------------------------------------------------------------------------
270 */ 280 */
271 281
@@ -631,9 +641,11 @@ typedef struct _CONFIG_PAGE_MANUFACTURING_4
631} CONFIG_PAGE_MANUFACTURING_4, MPI_POINTER PTR_CONFIG_PAGE_MANUFACTURING_4, 641} CONFIG_PAGE_MANUFACTURING_4, MPI_POINTER PTR_CONFIG_PAGE_MANUFACTURING_4,
632 ManufacturingPage4_t, MPI_POINTER pManufacturingPage4_t; 642 ManufacturingPage4_t, MPI_POINTER pManufacturingPage4_t;
633 643
634#define MPI_MANUFACTURING4_PAGEVERSION (0x03) 644#define MPI_MANUFACTURING4_PAGEVERSION (0x04)
635 645
636/* defines for the Flags field */ 646/* defines for the Flags field */
647#define MPI_MANPAGE4_FORCE_BAD_BLOCK_TABLE (0x80)
648#define MPI_MANPAGE4_FORCE_OFFLINE_FAILOVER (0x40)
637#define MPI_MANPAGE4_IME_DISABLE (0x20) 649#define MPI_MANPAGE4_IME_DISABLE (0x20)
638#define MPI_MANPAGE4_IM_DISABLE (0x10) 650#define MPI_MANPAGE4_IM_DISABLE (0x10)
639#define MPI_MANPAGE4_IS_DISABLE (0x08) 651#define MPI_MANPAGE4_IS_DISABLE (0x08)
@@ -668,6 +680,66 @@ typedef struct _CONFIG_PAGE_MANUFACTURING_6
668#define MPI_MANUFACTURING6_PAGEVERSION (0x00) 680#define MPI_MANUFACTURING6_PAGEVERSION (0x00)
669 681
670 682
683typedef struct _MPI_MANPAGE7_CONNECTOR_INFO
684{
685 U32 Pinout; /* 00h */
686 U8 Connector[16]; /* 04h */
687 U8 Location; /* 14h */
688 U8 Reserved1; /* 15h */
689 U16 Slot; /* 16h */
690 U32 Reserved2; /* 18h */
691} MPI_MANPAGE7_CONNECTOR_INFO, MPI_POINTER PTR_MPI_MANPAGE7_CONNECTOR_INFO,
692 MpiManPage7ConnectorInfo_t, MPI_POINTER pMpiManPage7ConnectorInfo_t;
693
694/* defines for the Pinout field */
695#define MPI_MANPAGE7_PINOUT_SFF_8484_L4 (0x00080000)
696#define MPI_MANPAGE7_PINOUT_SFF_8484_L3 (0x00040000)
697#define MPI_MANPAGE7_PINOUT_SFF_8484_L2 (0x00020000)
698#define MPI_MANPAGE7_PINOUT_SFF_8484_L1 (0x00010000)
699#define MPI_MANPAGE7_PINOUT_SFF_8470_L4 (0x00000800)
700#define MPI_MANPAGE7_PINOUT_SFF_8470_L3 (0x00000400)
701#define MPI_MANPAGE7_PINOUT_SFF_8470_L2 (0x00000200)
702#define MPI_MANPAGE7_PINOUT_SFF_8470_L1 (0x00000100)
703#define MPI_MANPAGE7_PINOUT_SFF_8482 (0x00000002)
704#define MPI_MANPAGE7_PINOUT_CONNECTION_UNKNOWN (0x00000001)
705
706/* defines for the Location field */
707#define MPI_MANPAGE7_LOCATION_UNKNOWN (0x01)
708#define MPI_MANPAGE7_LOCATION_INTERNAL (0x02)
709#define MPI_MANPAGE7_LOCATION_EXTERNAL (0x04)
710#define MPI_MANPAGE7_LOCATION_SWITCHABLE (0x08)
711#define MPI_MANPAGE7_LOCATION_AUTO (0x10)
712#define MPI_MANPAGE7_LOCATION_NOT_PRESENT (0x20)
713#define MPI_MANPAGE7_LOCATION_NOT_CONNECTED (0x80)
714
715/*
716 * Host code (drivers, BIOS, utilities, etc.) should leave this define set to
717 * one and check NumPhys at runtime.
718 */
719#ifndef MPI_MANPAGE7_CONNECTOR_INFO_MAX
720#define MPI_MANPAGE7_CONNECTOR_INFO_MAX (1)
721#endif
722
723typedef struct _CONFIG_PAGE_MANUFACTURING_7
724{
725 CONFIG_PAGE_HEADER Header; /* 00h */
726 U32 Reserved1; /* 04h */
727 U32 Reserved2; /* 08h */
728 U32 Flags; /* 0Ch */
729 U8 EnclosureName[16]; /* 10h */
730 U8 NumPhys; /* 20h */
731 U8 Reserved3; /* 21h */
732 U16 Reserved4; /* 22h */
733 MPI_MANPAGE7_CONNECTOR_INFO ConnectorInfo[MPI_MANPAGE7_CONNECTOR_INFO_MAX]; /* 24h */
734} CONFIG_PAGE_MANUFACTURING_7, MPI_POINTER PTR_CONFIG_PAGE_MANUFACTURING_7,
735 ManufacturingPage7_t, MPI_POINTER pManufacturingPage7_t;
736
737#define MPI_MANUFACTURING7_PAGEVERSION (0x00)
738
739/* defines for the Flags field */
740#define MPI_MANPAGE7_FLAG_USE_SLOT_INFO (0x00000001)
741
742
671/**************************************************************************** 743/****************************************************************************
672* IO Unit Config Pages 744* IO Unit Config Pages
673****************************************************************************/ 745****************************************************************************/
@@ -867,7 +939,7 @@ typedef struct _CONFIG_PAGE_IOC_2
867} CONFIG_PAGE_IOC_2, MPI_POINTER PTR_CONFIG_PAGE_IOC_2, 939} CONFIG_PAGE_IOC_2, MPI_POINTER PTR_CONFIG_PAGE_IOC_2,
868 IOCPage2_t, MPI_POINTER pIOCPage2_t; 940 IOCPage2_t, MPI_POINTER pIOCPage2_t;
869 941
870#define MPI_IOCPAGE2_PAGEVERSION (0x03) 942#define MPI_IOCPAGE2_PAGEVERSION (0x04)
871 943
872/* IOC Page 2 Capabilities flags */ 944/* IOC Page 2 Capabilities flags */
873 945
@@ -878,6 +950,7 @@ typedef struct _CONFIG_PAGE_IOC_2
878#define MPI_IOCPAGE2_CAP_FLAGS_RAID_6_SUPPORT (0x00000010) 950#define MPI_IOCPAGE2_CAP_FLAGS_RAID_6_SUPPORT (0x00000010)
879#define MPI_IOCPAGE2_CAP_FLAGS_RAID_10_SUPPORT (0x00000020) 951#define MPI_IOCPAGE2_CAP_FLAGS_RAID_10_SUPPORT (0x00000020)
880#define MPI_IOCPAGE2_CAP_FLAGS_RAID_50_SUPPORT (0x00000040) 952#define MPI_IOCPAGE2_CAP_FLAGS_RAID_50_SUPPORT (0x00000040)
953#define MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING (0x10000000)
881#define MPI_IOCPAGE2_CAP_FLAGS_SES_SUPPORT (0x20000000) 954#define MPI_IOCPAGE2_CAP_FLAGS_SES_SUPPORT (0x20000000)
882#define MPI_IOCPAGE2_CAP_FLAGS_SAFTE_SUPPORT (0x40000000) 955#define MPI_IOCPAGE2_CAP_FLAGS_SAFTE_SUPPORT (0x40000000)
883#define MPI_IOCPAGE2_CAP_FLAGS_CROSS_CHANNEL_SUPPORT (0x80000000) 956#define MPI_IOCPAGE2_CAP_FLAGS_CROSS_CHANNEL_SUPPORT (0x80000000)
@@ -975,6 +1048,44 @@ typedef struct _CONFIG_PAGE_IOC_5
975 1048
976#define MPI_IOCPAGE5_PAGEVERSION (0x00) 1049#define MPI_IOCPAGE5_PAGEVERSION (0x00)
977 1050
1051typedef struct _CONFIG_PAGE_IOC_6
1052{
1053 CONFIG_PAGE_HEADER Header; /* 00h */
1054 U32 CapabilitiesFlags; /* 04h */
1055 U8 MaxDrivesIS; /* 08h */
1056 U8 MaxDrivesIM; /* 09h */
1057 U8 MaxDrivesIME; /* 0Ah */
1058 U8 Reserved1; /* 0Bh */
1059 U8 MinDrivesIS; /* 0Ch */
1060 U8 MinDrivesIM; /* 0Dh */
1061 U8 MinDrivesIME; /* 0Eh */
1062 U8 Reserved2; /* 0Fh */
1063 U8 MaxGlobalHotSpares; /* 10h */
1064 U8 Reserved3; /* 11h */
1065 U16 Reserved4; /* 12h */
1066 U32 Reserved5; /* 14h */
1067 U32 SupportedStripeSizeMapIS; /* 18h */
1068 U32 SupportedStripeSizeMapIME; /* 1Ch */
1069 U32 Reserved6; /* 20h */
1070 U8 MetadataSize; /* 24h */
1071 U8 Reserved7; /* 25h */
1072 U16 Reserved8; /* 26h */
1073 U16 MaxBadBlockTableEntries; /* 28h */
1074 U16 Reserved9; /* 2Ah */
1075 U16 IRNvsramUsage; /* 2Ch */
1076 U16 Reserved10; /* 2Eh */
1077 U32 IRNvsramVersion; /* 30h */
1078 U32 Reserved11; /* 34h */
1079 U32 Reserved12; /* 38h */
1080} CONFIG_PAGE_IOC_6, MPI_POINTER PTR_CONFIG_PAGE_IOC_6,
1081 IOCPage6_t, MPI_POINTER pIOCPage6_t;
1082
1083#define MPI_IOCPAGE6_PAGEVERSION (0x00)
1084
1085/* IOC Page 6 Capabilities Flags */
1086
1087#define MPI_IOCPAGE6_CAP_FLAGS_GLOBAL_HOT_SPARE (0x00000001)
1088
978 1089
979/**************************************************************************** 1090/****************************************************************************
980* BIOS Config Pages 1091* BIOS Config Pages
@@ -1218,13 +1329,13 @@ typedef struct _CONFIG_PAGE_BIOS_2
1218 U32 Reserved5; /* 14h */ 1329 U32 Reserved5; /* 14h */
1219 U32 Reserved6; /* 18h */ 1330 U32 Reserved6; /* 18h */
1220 U8 BootDeviceForm; /* 1Ch */ 1331 U8 BootDeviceForm; /* 1Ch */
1221 U8 Reserved7; /* 1Dh */ 1332 U8 PrevBootDeviceForm; /* 1Ch */
1222 U16 Reserved8; /* 1Eh */ 1333 U16 Reserved8; /* 1Eh */
1223 MPI_BIOSPAGE2_BOOT_DEVICE BootDevice; /* 20h */ 1334 MPI_BIOSPAGE2_BOOT_DEVICE BootDevice; /* 20h */
1224} CONFIG_PAGE_BIOS_2, MPI_POINTER PTR_CONFIG_PAGE_BIOS_2, 1335} CONFIG_PAGE_BIOS_2, MPI_POINTER PTR_CONFIG_PAGE_BIOS_2,
1225 BIOSPage2_t, MPI_POINTER pBIOSPage2_t; 1336 BIOSPage2_t, MPI_POINTER pBIOSPage2_t;
1226 1337
1227#define MPI_BIOSPAGE2_PAGEVERSION (0x01) 1338#define MPI_BIOSPAGE2_PAGEVERSION (0x02)
1228 1339
1229#define MPI_BIOSPAGE2_FORM_MASK (0x0F) 1340#define MPI_BIOSPAGE2_FORM_MASK (0x0F)
1230#define MPI_BIOSPAGE2_FORM_ADAPTER_ORDER (0x00) 1341#define MPI_BIOSPAGE2_FORM_ADAPTER_ORDER (0x00)
@@ -2080,7 +2191,7 @@ typedef struct _CONFIG_PAGE_RAID_VOL_0
2080 RAID_VOL0_STATUS VolumeStatus; /* 08h */ 2191 RAID_VOL0_STATUS VolumeStatus; /* 08h */
2081 RAID_VOL0_SETTINGS VolumeSettings; /* 0Ch */ 2192 RAID_VOL0_SETTINGS VolumeSettings; /* 0Ch */
2082 U32 MaxLBA; /* 10h */ 2193 U32 MaxLBA; /* 10h */
2083 U32 Reserved1; /* 14h */ 2194 U32 MaxLBAHigh; /* 14h */
2084 U32 StripeSize; /* 18h */ 2195 U32 StripeSize; /* 18h */
2085 U32 Reserved2; /* 1Ch */ 2196 U32 Reserved2; /* 1Ch */
2086 U32 Reserved3; /* 20h */ 2197 U32 Reserved3; /* 20h */
@@ -2092,7 +2203,7 @@ typedef struct _CONFIG_PAGE_RAID_VOL_0
2092} CONFIG_PAGE_RAID_VOL_0, MPI_POINTER PTR_CONFIG_PAGE_RAID_VOL_0, 2203} CONFIG_PAGE_RAID_VOL_0, MPI_POINTER PTR_CONFIG_PAGE_RAID_VOL_0,
2093 RaidVolumePage0_t, MPI_POINTER pRaidVolumePage0_t; 2204 RaidVolumePage0_t, MPI_POINTER pRaidVolumePage0_t;
2094 2205
2095#define MPI_RAIDVOLPAGE0_PAGEVERSION (0x05) 2206#define MPI_RAIDVOLPAGE0_PAGEVERSION (0x06)
2096 2207
2097/* values for RAID Volume Page 0 InactiveStatus field */ 2208/* values for RAID Volume Page 0 InactiveStatus field */
2098#define MPI_RAIDVOLPAGE0_UNKNOWN_INACTIVE (0x00) 2209#define MPI_RAIDVOLPAGE0_UNKNOWN_INACTIVE (0x00)
@@ -2324,7 +2435,8 @@ typedef struct _MPI_SAS_IO_UNIT0_PHY_DATA
2324typedef struct _CONFIG_PAGE_SAS_IO_UNIT_0 2435typedef struct _CONFIG_PAGE_SAS_IO_UNIT_0
2325{ 2436{
2326 CONFIG_EXTENDED_PAGE_HEADER Header; /* 00h */ 2437 CONFIG_EXTENDED_PAGE_HEADER Header; /* 00h */
2327 U32 Reserved1; /* 08h */ 2438 U16 NvdataVersionDefault; /* 08h */
2439 U16 NvdataVersionPersistent; /* 0Ah */
2328 U8 NumPhys; /* 0Ch */ 2440 U8 NumPhys; /* 0Ch */
2329 U8 Reserved2; /* 0Dh */ 2441 U8 Reserved2; /* 0Dh */
2330 U16 Reserved3; /* 0Eh */ 2442 U16 Reserved3; /* 0Eh */
@@ -2332,7 +2444,7 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_0
2332} CONFIG_PAGE_SAS_IO_UNIT_0, MPI_POINTER PTR_CONFIG_PAGE_SAS_IO_UNIT_0, 2444} CONFIG_PAGE_SAS_IO_UNIT_0, MPI_POINTER PTR_CONFIG_PAGE_SAS_IO_UNIT_0,
2333 SasIOUnitPage0_t, MPI_POINTER pSasIOUnitPage0_t; 2445 SasIOUnitPage0_t, MPI_POINTER pSasIOUnitPage0_t;
2334 2446
2335#define MPI_SASIOUNITPAGE0_PAGEVERSION (0x03) 2447#define MPI_SASIOUNITPAGE0_PAGEVERSION (0x04)
2336 2448
2337/* values for SAS IO Unit Page 0 PortFlags */ 2449/* values for SAS IO Unit Page 0 PortFlags */
2338#define MPI_SAS_IOUNIT0_PORT_FLAGS_DISCOVERY_IN_PROGRESS (0x08) 2450#define MPI_SAS_IOUNIT0_PORT_FLAGS_DISCOVERY_IN_PROGRESS (0x08)
@@ -2373,12 +2485,13 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_0
2373 2485
2374typedef struct _MPI_SAS_IO_UNIT1_PHY_DATA 2486typedef struct _MPI_SAS_IO_UNIT1_PHY_DATA
2375{ 2487{
2376 U8 Port; /* 00h */ 2488 U8 Port; /* 00h */
2377 U8 PortFlags; /* 01h */ 2489 U8 PortFlags; /* 01h */
2378 U8 PhyFlags; /* 02h */ 2490 U8 PhyFlags; /* 02h */
2379 U8 MaxMinLinkRate; /* 03h */ 2491 U8 MaxMinLinkRate; /* 03h */
2380 U32 ControllerPhyDeviceInfo;/* 04h */ 2492 U32 ControllerPhyDeviceInfo; /* 04h */
2381 U32 Reserved1; /* 08h */ 2493 U16 MaxTargetPortConnectTime; /* 08h */
2494 U16 Reserved1; /* 0Ah */
2382} MPI_SAS_IO_UNIT1_PHY_DATA, MPI_POINTER PTR_MPI_SAS_IO_UNIT1_PHY_DATA, 2495} MPI_SAS_IO_UNIT1_PHY_DATA, MPI_POINTER PTR_MPI_SAS_IO_UNIT1_PHY_DATA,
2383 SasIOUnit1PhyData, MPI_POINTER pSasIOUnit1PhyData; 2496 SasIOUnit1PhyData, MPI_POINTER pSasIOUnit1PhyData;
2384 2497
@@ -2395,15 +2508,17 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_1
2395 CONFIG_EXTENDED_PAGE_HEADER Header; /* 00h */ 2508 CONFIG_EXTENDED_PAGE_HEADER Header; /* 00h */
2396 U16 ControlFlags; /* 08h */ 2509 U16 ControlFlags; /* 08h */
2397 U16 MaxNumSATATargets; /* 0Ah */ 2510 U16 MaxNumSATATargets; /* 0Ah */
2398 U32 Reserved1; /* 0Ch */ 2511 U16 AdditionalControlFlags; /* 0Ch */
2512 U16 Reserved1; /* 0Eh */
2399 U8 NumPhys; /* 10h */ 2513 U8 NumPhys; /* 10h */
2400 U8 SATAMaxQDepth; /* 11h */ 2514 U8 SATAMaxQDepth; /* 11h */
2401 U16 Reserved2; /* 12h */ 2515 U8 ReportDeviceMissingDelay; /* 12h */
2516 U8 IODeviceMissingDelay; /* 13h */
2402 MPI_SAS_IO_UNIT1_PHY_DATA PhyData[MPI_SAS_IOUNIT1_PHY_MAX]; /* 14h */ 2517 MPI_SAS_IO_UNIT1_PHY_DATA PhyData[MPI_SAS_IOUNIT1_PHY_MAX]; /* 14h */
2403} CONFIG_PAGE_SAS_IO_UNIT_1, MPI_POINTER PTR_CONFIG_PAGE_SAS_IO_UNIT_1, 2518} CONFIG_PAGE_SAS_IO_UNIT_1, MPI_POINTER PTR_CONFIG_PAGE_SAS_IO_UNIT_1,
2404 SasIOUnitPage1_t, MPI_POINTER pSasIOUnitPage1_t; 2519 SasIOUnitPage1_t, MPI_POINTER pSasIOUnitPage1_t;
2405 2520
2406#define MPI_SASIOUNITPAGE1_PAGEVERSION (0x05) 2521#define MPI_SASIOUNITPAGE1_PAGEVERSION (0x06)
2407 2522
2408/* values for SAS IO Unit Page 1 ControlFlags */ 2523/* values for SAS IO Unit Page 1 ControlFlags */
2409#define MPI_SAS_IOUNIT1_CONTROL_DEVICE_SELF_TEST (0x8000) 2524#define MPI_SAS_IOUNIT1_CONTROL_DEVICE_SELF_TEST (0x8000)
@@ -2428,6 +2543,13 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_1
2428#define MPI_SAS_IOUNIT1_CONTROL_FIRST_LVL_DISC_ONLY (0x0002) 2543#define MPI_SAS_IOUNIT1_CONTROL_FIRST_LVL_DISC_ONLY (0x0002)
2429#define MPI_SAS_IOUNIT1_CONTROL_CLEAR_AFFILIATION (0x0001) 2544#define MPI_SAS_IOUNIT1_CONTROL_CLEAR_AFFILIATION (0x0001)
2430 2545
2546/* values for SAS IO Unit Page 1 AdditionalControlFlags */
2547#define MPI_SAS_IOUNIT1_ACONTROL_ALLOW_TABLE_TO_TABLE (0x0001)
2548
2549/* defines for SAS IO Unit Page 1 ReportDeviceMissingDelay */
2550#define MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK (0x7F)
2551#define MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16 (0x80)
2552
2431/* values for SAS IO Unit Page 1 PortFlags */ 2553/* values for SAS IO Unit Page 1 PortFlags */
2432#define MPI_SAS_IOUNIT1_PORT_FLAGS_0_TARGET_IOC_NUM (0x00) 2554#define MPI_SAS_IOUNIT1_PORT_FLAGS_0_TARGET_IOC_NUM (0x00)
2433#define MPI_SAS_IOUNIT1_PORT_FLAGS_1_TARGET_IOC_NUM (0x04) 2555#define MPI_SAS_IOUNIT1_PORT_FLAGS_1_TARGET_IOC_NUM (0x04)
diff --git a/drivers/message/fusion/lsi/mpi_history.txt b/drivers/message/fusion/lsi/mpi_history.txt
index 4a5f8dd1d766..582cfe7c2aa1 100644
--- a/drivers/message/fusion/lsi/mpi_history.txt
+++ b/drivers/message/fusion/lsi/mpi_history.txt
@@ -6,25 +6,25 @@
6 Copyright (c) 2000-2005 LSI Logic Corporation. 6 Copyright (c) 2000-2005 LSI Logic Corporation.
7 7
8 --------------------------------------- 8 ---------------------------------------
9 Header Set Release Version: 01.05.12 9 Header Set Release Version: 01.05.13
10 Header Set Release Date: 08-30-05 10 Header Set Release Date: 03-27-06
11 --------------------------------------- 11 ---------------------------------------
12 12
13 Filename Current version Prior version 13 Filename Current version Prior version
14 ---------- --------------- ------------- 14 ---------- --------------- -------------
15 mpi.h 01.05.10 01.05.09 15 mpi.h 01.05.11 01.05.10
16 mpi_ioc.h 01.05.10 01.05.09 16 mpi_ioc.h 01.05.11 01.05.10
17 mpi_cnfg.h 01.05.11 01.05.10 17 mpi_cnfg.h 01.05.12 01.05.11
18 mpi_init.h 01.05.06 01.05.06 18 mpi_init.h 01.05.07 01.05.06
19 mpi_targ.h 01.05.05 01.05.05 19 mpi_targ.h 01.05.06 01.05.05
20 mpi_fc.h 01.05.01 01.05.01 20 mpi_fc.h 01.05.01 01.05.01
21 mpi_lan.h 01.05.01 01.05.01 21 mpi_lan.h 01.05.01 01.05.01
22 mpi_raid.h 01.05.02 01.05.02 22 mpi_raid.h 01.05.02 01.05.02
23 mpi_tool.h 01.05.03 01.05.03 23 mpi_tool.h 01.05.03 01.05.03
24 mpi_inb.h 01.05.01 01.05.01 24 mpi_inb.h 01.05.01 01.05.01
25 mpi_sas.h 01.05.02 01.05.01 25 mpi_sas.h 01.05.03 01.05.02
26 mpi_type.h 01.05.02 01.05.01 26 mpi_type.h 01.05.02 01.05.02
27 mpi_history.txt 01.05.12 01.05.11 27 mpi_history.txt 01.05.13 01.05.12
28 28
29 29
30 * Date Version Description 30 * Date Version Description
@@ -93,6 +93,7 @@ mpi.h
93 * Added EEDP IOCStatus codes. 93 * Added EEDP IOCStatus codes.
94 * 08-03-05 01.05.09 Bumped MPI_HEADER_VERSION_UNIT. 94 * 08-03-05 01.05.09 Bumped MPI_HEADER_VERSION_UNIT.
95 * 08-30-05 01.05.10 Added 2 new IOCStatus codes for Target. 95 * 08-30-05 01.05.10 Added 2 new IOCStatus codes for Target.
96 * 03-27-06 01.05.11 Bumped MPI_HEADER_VERSION_UNIT.
96 * -------------------------------------------------------------------------- 97 * --------------------------------------------------------------------------
97 98
98mpi_ioc.h 99mpi_ioc.h
@@ -170,6 +171,17 @@ mpi_ioc.h
170 * Added new ReasonCode value for SAS Device Status Change 171 * Added new ReasonCode value for SAS Device Status Change
171 * event. 172 * event.
172 * Added new family code for FC949E. 173 * Added new family code for FC949E.
174 * 03-27-06 01.05.11 Added MPI_IOCFACTS_CAPABILITY_TLR.
175 * Added additional Reason Codes and more event data fields
176 * to EVENT_DATA_SAS_DEVICE_STATUS_CHANGE.
177 * Added EVENT_DATA_SAS_BROADCAST_PRIMITIVE structure and
178 * new event.
179 * Added MPI_EVENT_SAS_SMP_ERROR and event data structure.
180 * Added MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE and event
181 * data structure.
182 * Added MPI_EVENT_SAS_INIT_TABLE_OVERFLOW and event
183 * data structure.
184 * Added MPI_EXT_IMAGE_TYPE_INITIALIZATION.
173 * -------------------------------------------------------------------------- 185 * --------------------------------------------------------------------------
174 186
175mpi_cnfg.h 187mpi_cnfg.h
@@ -425,6 +437,16 @@ mpi_cnfg.h
425 * Added postpone SATA Init bit to SAS IO Unit Page 1 437 * Added postpone SATA Init bit to SAS IO Unit Page 1
426 * ControlFlags. 438 * ControlFlags.
427 * Changed LogEntry format for Log Page 0. 439 * Changed LogEntry format for Log Page 0.
440 * 03-27-06 01.05.12 Added two new Flags defines for Manufacturing Page 4.
441 * Added Manufacturing Page 7.
442 * Added MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING.
443 * Added IOC Page 6.
444 * Added PrevBootDeviceForm field to CONFIG_PAGE_BIOS_2.
445 * Added MaxLBAHigh field to RAID Volume Page 0.
446 * Added Nvdata version fields to SAS IO Unit Page 0.
447 * Added AdditionalControlFlags, MaxTargetPortConnectTime,
448 * ReportDeviceMissingDelay, and IODeviceMissingDelay
449 * fields to SAS IO Unit Page 1.
428 * -------------------------------------------------------------------------- 450 * --------------------------------------------------------------------------
429 451
430mpi_init.h 452mpi_init.h
@@ -467,6 +489,7 @@ mpi_init.h
467 * Added four new defines for SEP SlotStatus. 489 * Added four new defines for SEP SlotStatus.
468 * 08-03-05 01.05.06 Fixed some MPI_SCSIIO32_MSGFLGS_ defines to make them 490 * 08-03-05 01.05.06 Fixed some MPI_SCSIIO32_MSGFLGS_ defines to make them
469 * unique in the first 32 characters. 491 * unique in the first 32 characters.
492 * 03-27-06 01.05.07 Added Task Management type of Clear ACA.
470 * -------------------------------------------------------------------------- 493 * --------------------------------------------------------------------------
471 494
472mpi_targ.h 495mpi_targ.h
@@ -511,6 +534,7 @@ mpi_targ.h
511 * 02-22-05 01.05.03 Changed a comment. 534 * 02-22-05 01.05.03 Changed a comment.
512 * 03-11-05 01.05.04 Removed TargetAssistExtended Request. 535 * 03-11-05 01.05.04 Removed TargetAssistExtended Request.
513 * 06-24-05 01.05.05 Added TargetAssistExtended structures and defines. 536 * 06-24-05 01.05.05 Added TargetAssistExtended structures and defines.
537 * 03-27-06 01.05.06 Added a comment.
514 * -------------------------------------------------------------------------- 538 * --------------------------------------------------------------------------
515 539
516mpi_fc.h 540mpi_fc.h
@@ -610,6 +634,10 @@ mpi_sas.h
610 * 08-30-05 01.05.02 Added DeviceInfo bit for SEP. 634 * 08-30-05 01.05.02 Added DeviceInfo bit for SEP.
611 * Added PrimFlags and Primitive field to SAS IO Unit 635 * Added PrimFlags and Primitive field to SAS IO Unit
612 * Control request, and added a new operation code. 636 * Control request, and added a new operation code.
637 * 03-27-06 01.05.03 Added Force Full Discovery, Transmit Port Select Signal,
638 * and Remove Device operations to SAS IO Unit Control.
639 * Added DevHandle field to SAS IO Unit Control request and
640 * reply.
613 * -------------------------------------------------------------------------- 641 * --------------------------------------------------------------------------
614 642
615mpi_type.h 643mpi_type.h
@@ -625,20 +653,20 @@ mpi_type.h
625 653
626mpi_history.txt Parts list history 654mpi_history.txt Parts list history
627 655
628Filename 01.05.12 01.05.11 01.05.10 01.05.09 656Filename 01.05.13 01.05.12 01.05.11 01.05.10 01.05.09
629---------- -------- -------- -------- -------- 657---------- -------- -------- -------- -------- --------
630mpi.h 01.05.10 01.05.09 01.05.08 01.05.07 658mpi.h 01.05.11 01.05.10 01.05.09 01.05.08 01.05.07
631mpi_ioc.h 01.05.10 01.05.09 01.05.09 01.05.08 659mpi_ioc.h 01.05.11 01.05.10 01.05.09 01.05.09 01.05.08
632mpi_cnfg.h 01.05.11 01.05.10 01.05.09 01.05.08 660mpi_cnfg.h 01.05.12 01.05.11 01.05.10 01.05.09 01.05.08
633mpi_init.h 01.05.06 01.05.06 01.05.05 01.05.04 661mpi_init.h 01.05.07 01.05.06 01.05.06 01.05.05 01.05.04
634mpi_targ.h 01.05.05 01.05.05 01.05.05 01.05.04 662mpi_targ.h 01.05.06 01.05.05 01.05.05 01.05.05 01.05.04
635mpi_fc.h 01.05.01 01.05.01 01.05.01 01.05.01 663mpi_fc.h 01.05.01 01.05.01 01.05.01 01.05.01 01.05.01
636mpi_lan.h 01.05.01 01.05.01 01.05.01 01.05.01 664mpi_lan.h 01.05.01 01.05.01 01.05.01 01.05.01 01.05.01
637mpi_raid.h 01.05.02 01.05.02 01.05.02 01.05.02 665mpi_raid.h 01.05.02 01.05.02 01.05.02 01.05.02 01.05.02
638mpi_tool.h 01.05.03 01.05.03 01.05.03 01.05.03 666mpi_tool.h 01.05.03 01.05.03 01.05.03 01.05.03 01.05.03
639mpi_inb.h 01.05.01 01.05.01 01.05.01 01.05.01 667mpi_inb.h 01.05.01 01.05.01 01.05.01 01.05.01 01.05.01
640mpi_sas.h 01.05.02 01.05.01 01.05.01 01.05.01 668mpi_sas.h 01.05.03 01.05.02 01.05.01 01.05.01 01.05.01
641mpi_type.h 01.05.02 01.05.01 01.05.01 01.05.01 669mpi_type.h 01.05.02 01.05.02 01.05.01 01.05.01 01.05.01
642 670
643Filename 01.05.08 01.05.07 01.05.06 01.05.05 01.05.04 01.05.03 671Filename 01.05.08 01.05.07 01.05.06 01.05.05 01.05.04 01.05.03
644---------- -------- -------- -------- -------- -------- -------- 672---------- -------- -------- -------- -------- -------- --------
diff --git a/drivers/message/fusion/lsi/mpi_init.h b/drivers/message/fusion/lsi/mpi_init.h
index 68941f459ca3..c1c678989a23 100644
--- a/drivers/message/fusion/lsi/mpi_init.h
+++ b/drivers/message/fusion/lsi/mpi_init.h
@@ -6,7 +6,7 @@
6 * Title: MPI initiator mode messages and structures 6 * Title: MPI initiator mode messages and structures
7 * Creation Date: June 8, 2000 7 * Creation Date: June 8, 2000
8 * 8 *
9 * mpi_init.h Version: 01.05.06 9 * mpi_init.h Version: 01.05.07
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -52,6 +52,7 @@
52 * Added four new defines for SEP SlotStatus. 52 * Added four new defines for SEP SlotStatus.
53 * 08-03-05 01.05.06 Fixed some MPI_SCSIIO32_MSGFLGS_ defines to make them 53 * 08-03-05 01.05.06 Fixed some MPI_SCSIIO32_MSGFLGS_ defines to make them
54 * unique in the first 32 characters. 54 * unique in the first 32 characters.
55 * 03-27-06 01.05.07 Added Task Management type of Clear ACA.
55 * -------------------------------------------------------------------------- 56 * --------------------------------------------------------------------------
56 */ 57 */
57 58
@@ -427,6 +428,7 @@ typedef struct _MSG_SCSI_TASK_MGMT
427#define MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET (0x05) 428#define MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET (0x05)
428#define MPI_SCSITASKMGMT_TASKTYPE_CLEAR_TASK_SET (0x06) 429#define MPI_SCSITASKMGMT_TASKTYPE_CLEAR_TASK_SET (0x06)
429#define MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK (0x07) 430#define MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK (0x07)
431#define MPI_SCSITASKMGMT_TASKTYPE_CLEAR_ACA (0x08)
430 432
431/* MsgFlags bits */ 433/* MsgFlags bits */
432#define MPI_SCSITASKMGMT_MSGFLAGS_TARGET_RESET_OPTION (0x00) 434#define MPI_SCSITASKMGMT_MSGFLAGS_TARGET_RESET_OPTION (0x00)
diff --git a/drivers/message/fusion/lsi/mpi_ioc.h b/drivers/message/fusion/lsi/mpi_ioc.h
index 2c5f43fa7c73..18ba407fd399 100644
--- a/drivers/message/fusion/lsi/mpi_ioc.h
+++ b/drivers/message/fusion/lsi/mpi_ioc.h
@@ -6,7 +6,7 @@
6 * Title: MPI IOC, Port, Event, FW Download, and FW Upload messages 6 * Title: MPI IOC, Port, Event, FW Download, and FW Upload messages
7 * Creation Date: August 11, 2000 7 * Creation Date: August 11, 2000
8 * 8 *
9 * mpi_ioc.h Version: 01.05.10 9 * mpi_ioc.h Version: 01.05.11
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -87,6 +87,17 @@
87 * Added new ReasonCode value for SAS Device Status Change 87 * Added new ReasonCode value for SAS Device Status Change
88 * event. 88 * event.
89 * Added new family code for FC949E. 89 * Added new family code for FC949E.
90 * 03-27-06 01.05.11 Added MPI_IOCFACTS_CAPABILITY_TLR.
91 * Added additional Reason Codes and more event data fields
92 * to EVENT_DATA_SAS_DEVICE_STATUS_CHANGE.
93 * Added EVENT_DATA_SAS_BROADCAST_PRIMITIVE structure and
94 * new event.
95 * Added MPI_EVENT_SAS_SMP_ERROR and event data structure.
96 * Added MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE and event
97 * data structure.
98 * Added MPI_EVENT_SAS_INIT_TABLE_OVERFLOW and event
99 * data structure.
100 * Added MPI_EXT_IMAGE_TYPE_INITIALIZATION.
90 * -------------------------------------------------------------------------- 101 * --------------------------------------------------------------------------
91 */ 102 */
92 103
@@ -272,6 +283,7 @@ typedef struct _MSG_IOC_FACTS_REPLY
272#define MPI_IOCFACTS_CAPABILITY_MULTICAST (0x00000100) 283#define MPI_IOCFACTS_CAPABILITY_MULTICAST (0x00000100)
273#define MPI_IOCFACTS_CAPABILITY_SCSIIO32 (0x00000200) 284#define MPI_IOCFACTS_CAPABILITY_SCSIIO32 (0x00000200)
274#define MPI_IOCFACTS_CAPABILITY_NO_SCSIIO16 (0x00000400) 285#define MPI_IOCFACTS_CAPABILITY_NO_SCSIIO16 (0x00000400)
286#define MPI_IOCFACTS_CAPABILITY_TLR (0x00000800)
275 287
276 288
277/***************************************************************************** 289/*****************************************************************************
@@ -448,30 +460,34 @@ typedef struct _MSG_EVENT_ACK_REPLY
448 460
449/* Event */ 461/* Event */
450 462
451#define MPI_EVENT_NONE (0x00000000) 463#define MPI_EVENT_NONE (0x00000000)
452#define MPI_EVENT_LOG_DATA (0x00000001) 464#define MPI_EVENT_LOG_DATA (0x00000001)
453#define MPI_EVENT_STATE_CHANGE (0x00000002) 465#define MPI_EVENT_STATE_CHANGE (0x00000002)
454#define MPI_EVENT_UNIT_ATTENTION (0x00000003) 466#define MPI_EVENT_UNIT_ATTENTION (0x00000003)
455#define MPI_EVENT_IOC_BUS_RESET (0x00000004) 467#define MPI_EVENT_IOC_BUS_RESET (0x00000004)
456#define MPI_EVENT_EXT_BUS_RESET (0x00000005) 468#define MPI_EVENT_EXT_BUS_RESET (0x00000005)
457#define MPI_EVENT_RESCAN (0x00000006) 469#define MPI_EVENT_RESCAN (0x00000006)
458#define MPI_EVENT_LINK_STATUS_CHANGE (0x00000007) 470#define MPI_EVENT_LINK_STATUS_CHANGE (0x00000007)
459#define MPI_EVENT_LOOP_STATE_CHANGE (0x00000008) 471#define MPI_EVENT_LOOP_STATE_CHANGE (0x00000008)
460#define MPI_EVENT_LOGOUT (0x00000009) 472#define MPI_EVENT_LOGOUT (0x00000009)
461#define MPI_EVENT_EVENT_CHANGE (0x0000000A) 473#define MPI_EVENT_EVENT_CHANGE (0x0000000A)
462#define MPI_EVENT_INTEGRATED_RAID (0x0000000B) 474#define MPI_EVENT_INTEGRATED_RAID (0x0000000B)
463#define MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE (0x0000000C) 475#define MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE (0x0000000C)
464#define MPI_EVENT_ON_BUS_TIMER_EXPIRED (0x0000000D) 476#define MPI_EVENT_ON_BUS_TIMER_EXPIRED (0x0000000D)
465#define MPI_EVENT_QUEUE_FULL (0x0000000E) 477#define MPI_EVENT_QUEUE_FULL (0x0000000E)
466#define MPI_EVENT_SAS_DEVICE_STATUS_CHANGE (0x0000000F) 478#define MPI_EVENT_SAS_DEVICE_STATUS_CHANGE (0x0000000F)
467#define MPI_EVENT_SAS_SES (0x00000010) 479#define MPI_EVENT_SAS_SES (0x00000010)
468#define MPI_EVENT_PERSISTENT_TABLE_FULL (0x00000011) 480#define MPI_EVENT_PERSISTENT_TABLE_FULL (0x00000011)
469#define MPI_EVENT_SAS_PHY_LINK_STATUS (0x00000012) 481#define MPI_EVENT_SAS_PHY_LINK_STATUS (0x00000012)
470#define MPI_EVENT_SAS_DISCOVERY_ERROR (0x00000013) 482#define MPI_EVENT_SAS_DISCOVERY_ERROR (0x00000013)
471#define MPI_EVENT_IR_RESYNC_UPDATE (0x00000014) 483#define MPI_EVENT_IR_RESYNC_UPDATE (0x00000014)
472#define MPI_EVENT_IR2 (0x00000015) 484#define MPI_EVENT_IR2 (0x00000015)
473#define MPI_EVENT_SAS_DISCOVERY (0x00000016) 485#define MPI_EVENT_SAS_DISCOVERY (0x00000016)
474#define MPI_EVENT_LOG_ENTRY_ADDED (0x00000021) 486#define MPI_EVENT_SAS_BROADCAST_PRIMITIVE (0x00000017)
487#define MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE (0x00000018)
488#define MPI_EVENT_SAS_INIT_TABLE_OVERFLOW (0x00000019)
489#define MPI_EVENT_SAS_SMP_ERROR (0x0000001A)
490#define MPI_EVENT_LOG_ENTRY_ADDED (0x00000021)
475 491
476/* AckRequired field values */ 492/* AckRequired field values */
477 493
@@ -558,18 +574,25 @@ typedef struct _EVENT_DATA_SAS_DEVICE_STATUS_CHANGE
558 U8 PhyNum; /* 0Eh */ 574 U8 PhyNum; /* 0Eh */
559 U8 Reserved1; /* 0Fh */ 575 U8 Reserved1; /* 0Fh */
560 U64 SASAddress; /* 10h */ 576 U64 SASAddress; /* 10h */
577 U8 LUN[8]; /* 18h */
578 U16 TaskTag; /* 20h */
579 U16 Reserved2; /* 22h */
561} EVENT_DATA_SAS_DEVICE_STATUS_CHANGE, 580} EVENT_DATA_SAS_DEVICE_STATUS_CHANGE,
562 MPI_POINTER PTR_EVENT_DATA_SAS_DEVICE_STATUS_CHANGE, 581 MPI_POINTER PTR_EVENT_DATA_SAS_DEVICE_STATUS_CHANGE,
563 MpiEventDataSasDeviceStatusChange_t, 582 MpiEventDataSasDeviceStatusChange_t,
564 MPI_POINTER pMpiEventDataSasDeviceStatusChange_t; 583 MPI_POINTER pMpiEventDataSasDeviceStatusChange_t;
565 584
566/* MPI SAS Device Status Change Event data ReasonCode values */ 585/* MPI SAS Device Status Change Event data ReasonCode values */
567#define MPI_EVENT_SAS_DEV_STAT_RC_ADDED (0x03) 586#define MPI_EVENT_SAS_DEV_STAT_RC_ADDED (0x03)
568#define MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING (0x04) 587#define MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING (0x04)
569#define MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA (0x05) 588#define MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA (0x05)
570#define MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED (0x06) 589#define MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED (0x06)
571#define MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED (0x07) 590#define MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED (0x07)
572#define MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET (0x08) 591#define MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET (0x08)
592#define MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL (0x09)
593#define MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL (0x0A)
594#define MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL (0x0B)
595#define MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL (0x0C)
573 596
574 597
575/* SCSI Event data for Queue Full event */ 598/* SCSI Event data for Queue Full event */
@@ -742,6 +765,27 @@ typedef struct _EVENT_DATA_SAS_SES
742} EVENT_DATA_SAS_SES, MPI_POINTER PTR_EVENT_DATA_SAS_SES, 765} EVENT_DATA_SAS_SES, MPI_POINTER PTR_EVENT_DATA_SAS_SES,
743 MpiEventDataSasSes_t, MPI_POINTER pMpiEventDataSasSes_t; 766 MpiEventDataSasSes_t, MPI_POINTER pMpiEventDataSasSes_t;
744 767
768/* SAS Broadcast Primitive Event data */
769
770typedef struct _EVENT_DATA_SAS_BROADCAST_PRIMITIVE
771{
772 U8 PhyNum; /* 00h */
773 U8 Port; /* 01h */
774 U8 PortWidth; /* 02h */
775 U8 Primitive; /* 04h */
776} EVENT_DATA_SAS_BROADCAST_PRIMITIVE,
777 MPI_POINTER PTR_EVENT_DATA_SAS_BROADCAST_PRIMITIVE,
778 MpiEventDataSasBroadcastPrimitive_t,
779 MPI_POINTER pMpiEventDataSasBroadcastPrimitive_t;
780
781#define MPI_EVENT_PRIMITIVE_CHANGE (0x01)
782#define MPI_EVENT_PRIMITIVE_EXPANDER (0x03)
783#define MPI_EVENT_PRIMITIVE_RESERVED2 (0x04)
784#define MPI_EVENT_PRIMITIVE_RESERVED3 (0x05)
785#define MPI_EVENT_PRIMITIVE_RESERVED4 (0x06)
786#define MPI_EVENT_PRIMITIVE_CHANGE0_RESERVED (0x07)
787#define MPI_EVENT_PRIMITIVE_CHANGE1_RESERVED (0x08)
788
745/* SAS Phy Link Status Event data */ 789/* SAS Phy Link Status Event data */
746 790
747typedef struct _EVENT_DATA_SAS_PHY_LINK_STATUS 791typedef struct _EVENT_DATA_SAS_PHY_LINK_STATUS
@@ -804,6 +848,53 @@ typedef struct _EVENT_DATA_DISCOVERY_ERROR
804#define MPI_EVENT_DSCVRY_ERR_DS_MULTPL_PATHS (0x00000800) 848#define MPI_EVENT_DSCVRY_ERR_DS_MULTPL_PATHS (0x00000800)
805#define MPI_EVENT_DSCVRY_ERR_DS_MAX_SATA_TARGETS (0x00001000) 849#define MPI_EVENT_DSCVRY_ERR_DS_MAX_SATA_TARGETS (0x00001000)
806 850
851/* SAS SMP Error Event data */
852
853typedef struct _EVENT_DATA_SAS_SMP_ERROR
854{
855 U8 Status; /* 00h */
856 U8 Port; /* 01h */
857 U8 SMPFunctionResult; /* 02h */
858 U8 Reserved1; /* 03h */
859 U64 SASAddress; /* 04h */
860} EVENT_DATA_SAS_SMP_ERROR, MPI_POINTER PTR_EVENT_DATA_SAS_SMP_ERROR,
861 MpiEventDataSasSmpError_t, MPI_POINTER pMpiEventDataSasSmpError_t;
862
863/* defines for the Status field of the SAS SMP Error event */
864#define MPI_EVENT_SAS_SMP_FUNCTION_RESULT_VALID (0x00)
865#define MPI_EVENT_SAS_SMP_CRC_ERROR (0x01)
866#define MPI_EVENT_SAS_SMP_TIMEOUT (0x02)
867#define MPI_EVENT_SAS_SMP_NO_DESTINATION (0x03)
868#define MPI_EVENT_SAS_SMP_BAD_DESTINATION (0x04)
869
870/* SAS Initiator Device Status Change Event data */
871
872typedef struct _EVENT_DATA_SAS_INIT_DEV_STATUS_CHANGE
873{
874 U8 ReasonCode; /* 00h */
875 U8 Port; /* 01h */
876 U16 DevHandle; /* 02h */
877 U64 SASAddress; /* 04h */
878} EVENT_DATA_SAS_INIT_DEV_STATUS_CHANGE,
879 MPI_POINTER PTR_EVENT_DATA_SAS_INIT_DEV_STATUS_CHANGE,
880 MpiEventDataSasInitDevStatusChange_t,
881 MPI_POINTER pMpiEventDataSasInitDevStatusChange_t;
882
883/* defines for the ReasonCode field of the SAS Initiator Device Status Change event */
884#define MPI_EVENT_SAS_INIT_RC_ADDED (0x01)
885
886/* SAS Initiator Device Table Overflow Event data */
887
888typedef struct _EVENT_DATA_SAS_INIT_TABLE_OVERFLOW
889{
890 U8 MaxInit; /* 00h */
891 U8 CurrentInit; /* 01h */
892 U16 Reserved1; /* 02h */
893} EVENT_DATA_SAS_INIT_TABLE_OVERFLOW,
894 MPI_POINTER PTR_EVENT_DATA_SAS_INIT_TABLE_OVERFLOW,
895 MpiEventDataSasInitTableOverflow_t,
896 MPI_POINTER pMpiEventDataSasInitTableOverflow_t;
897
807 898
808/***************************************************************************** 899/*****************************************************************************
809* 900*
@@ -1013,5 +1104,6 @@ typedef struct _MPI_EXT_IMAGE_HEADER
1013#define MPI_EXT_IMAGE_TYPE_FW (0x01) 1104#define MPI_EXT_IMAGE_TYPE_FW (0x01)
1014#define MPI_EXT_IMAGE_TYPE_NVDATA (0x03) 1105#define MPI_EXT_IMAGE_TYPE_NVDATA (0x03)
1015#define MPI_EXT_IMAGE_TYPE_BOOTLOADER (0x04) 1106#define MPI_EXT_IMAGE_TYPE_BOOTLOADER (0x04)
1107#define MPI_EXT_IMAGE_TYPE_INITIALIZATION (0x05)
1016 1108
1017#endif 1109#endif
diff --git a/drivers/message/fusion/lsi/mpi_log_sas.h b/drivers/message/fusion/lsi/mpi_log_sas.h
index a9c14ad132ce..871ebc08b706 100644
--- a/drivers/message/fusion/lsi/mpi_log_sas.h
+++ b/drivers/message/fusion/lsi/mpi_log_sas.h
@@ -13,6 +13,8 @@
13#ifndef IOPI_IOCLOGINFO_H_INCLUDED 13#ifndef IOPI_IOCLOGINFO_H_INCLUDED
14#define IOPI_IOCLOGINFO_H_INCLUDED 14#define IOPI_IOCLOGINFO_H_INCLUDED
15 15
16#define SAS_LOGINFO_NEXUS_LOSS 0x31170000
17#define SAS_LOGINFO_MASK 0xFFFF0000
16 18
17/****************************************************************************/ 19/****************************************************************************/
18/* IOC LOGINFO defines, 0x00000000 - 0x0FFFFFFF */ 20/* IOC LOGINFO defines, 0x00000000 - 0x0FFFFFFF */
@@ -51,6 +53,9 @@
51#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_DNM (0x00030500) /* Device Not Mapped */ 53#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_DNM (0x00030500) /* Device Not Mapped */
52#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_PERSIST (0x00030600) /* Persistent Page not found */ 54#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_PERSIST (0x00030600) /* Persistent Page not found */
53#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_DEFAULT (0x00030700) /* Default Page not found */ 55#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_DEFAULT (0x00030700) /* Default Page not found */
56
57#define IOP_LOGINFO_CODE_DIAG_MSG_ERROR (0x00040000) /* Error handling diag msg - or'd with diag status */
58
54#define IOP_LOGINFO_CODE_TASK_TERMINATED (0x00050000) 59#define IOP_LOGINFO_CODE_TASK_TERMINATED (0x00050000)
55 60
56#define IOP_LOGINFO_CODE_ENCL_MGMT_READ_ACTION_ERR0R (0x00060001) /* Read Action not supported for SEP msg */ 61#define IOP_LOGINFO_CODE_ENCL_MGMT_READ_ACTION_ERR0R (0x00060001) /* Read Action not supported for SEP msg */
@@ -103,6 +108,7 @@
103#define PL_LOGINFO_CODE_IO_EXECUTED (0x00140000) 108#define PL_LOGINFO_CODE_IO_EXECUTED (0x00140000)
104#define PL_LOGINFO_CODE_PERS_RESV_OUT_NOT_AFFIL_OWNER (0x00150000) 109#define PL_LOGINFO_CODE_PERS_RESV_OUT_NOT_AFFIL_OWNER (0x00150000)
105#define PL_LOGINFO_CODE_OPEN_TXDMA_ABORT (0x00160000) 110#define PL_LOGINFO_CODE_OPEN_TXDMA_ABORT (0x00160000)
111#define PL_LOGINFO_CODE_IO_DEVICE_MISSING_DELAY_RETRY (0x00170000)
106#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE (0x00000100) 112#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE (0x00000100)
107#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_NO_DEST_TIMEOUT (0x00000101) 113#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_NO_DEST_TIMEOUT (0x00000101)
108#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_ORR_TIMEOUT (0x0000011A) /* Open Reject (Retry) Timeout */ 114#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_ORR_TIMEOUT (0x0000011A) /* Open Reject (Retry) Timeout */
@@ -165,11 +171,81 @@
165/****************************************************************************/ 171/****************************************************************************/
166/* IR LOGINFO_CODE defines, valid if IOC_LOGINFO_ORIGINATOR = IR */ 172/* IR LOGINFO_CODE defines, valid if IOC_LOGINFO_ORIGINATOR = IR */
167/****************************************************************************/ 173/****************************************************************************/
168#define IR_LOGINFO_CODE_UNUSED1 (0x00010000) 174#define IR_LOGINFO_RAID_ACTION_ERROR (0x00010000)
169#define IR_LOGINFO_CODE_UNUSED2 (0x00020000) 175#define IR_LOGINFO_CODE_UNUSED2 (0x00020000)
176
177/* Amount of information passed down for Create Volume is too large */
178#define IR_LOGINFO_VOLUME_CREATE_INVALID_LENGTH (0x00010001)
179/* Creation of duplicate volume attempted (Bus/Target ID checked) */
180#define IR_LOGINFO_VOLUME_CREATE_DUPLICATE (0x00010002)
181/* Creation failed due to maximum number of supported volumes exceeded */
182#define IR_LOGINFO_VOLUME_CREATE_NO_SLOTS (0x00010003)
183/* Creation failed due to DMA error in trying to read from host */
184#define IR_LOGINFO_VOLUME_CREATE_DMA_ERROR (0x00010004)
185/* Creation failed due to invalid volume type passed down */
186#define IR_LOGINFO_VOLUME_CREATE_INVALID_VOLUME_TYPE (0x00010005)
187/* Creation failed due to error reading MFG Page 4 */
188#define IR_LOGINFO_VOLUME_MFG_PAGE4_ERROR (0x00010006)
189/* Creation failed when trying to create internal structures */
190#define IR_LOGINFO_VOLUME_INTERNAL_CONFIG_STRUCTURE_ERROR (0x00010007)
191
192/* Activation failed due to trying to activate an already active volume */
193#define IR_LOGINFO_VOLUME_ACTIVATING_AN_ACTIVE_VOLUME (0x00010010)
194/* Activation failed due to trying to active unsupported volume type */
195#define IR_LOGINFO_VOLUME_ACTIVATING_INVALID_VOLUME_TYPE (0x00010011)
196/* Activation failed due to trying to active too many volumes */
197#define IR_LOGINFO_VOLUME_ACTIVATING_TOO_MANY_VOLUMES (0x00010012)
198/* Activation failed due to Volume ID in use already */
199#define IR_LOGINFO_VOLUME_ACTIVATING_VOLUME_ID_IN_USE (0x00010013)
200/* Activation failed call to activateVolume returned failure */
201#define IR_LOGINFO_VOLUME_ACTIVATE_VOLUME_FAILED (0x00010014)
202/* Activation failed trying to import the volume */
203#define IR_LOGINFO_VOLUME_ACTIVATING_IMPORT_VOLUME_FAILED (0x00010015)
204
205/* Phys Disk failed, too many phys disks */
206#define IR_LOGINFO_PHYSDISK_CREATE_TOO_MANY_DISKS (0x00010020)
207/* Amount of information passed down for Create Pnysdisk is too large */
208#define IR_LOGINFO_PHYSDISK_CREATE_INVALID_LENGTH (0x00010021)
209/* Creation failed due to DMA error in trying to read from host */
210#define IR_LOGINFO_PHYSDISK_CREATE_DMA_ERROR (0x00010022)
211/* Creation failed due to invalid Bus TargetID passed down */
212#define IR_LOGINFO_PHYSDISK_CREATE_BUS_TID_INVALID (0x00010023)
213/* Creation failed due to error in creating RAID Phys Disk Config Page */
214#define IR_LOGINFO_PHYSDISK_CREATE_CONFIG_PAGE_ERROR (0x00010024)
215
216
217/* Compatibility Error : IR Disabled */
218#define IR_LOGINFO_COMPAT_ERROR_RAID_DISABLED (0x00010030)
219/* Compatibility Error : Inquiry Comand failed */
220#define IR_LOGINFO_COMPAT_ERROR_INQUIRY_FAILED (0x00010031)
221/* Compatibility Error : Device not direct access device */
222#define IR_LOGINFO_COMPAT_ERROR_NOT_DIRECT_ACCESS (0x00010032)
223/* Compatibility Error : Removable device found */
224#define IR_LOGINFO_COMPAT_ERROR_REMOVABLE_FOUND (0x00010033)
225/* Compatibility Error : Device SCSI Version not 2 or higher */
226#define IR_LOGINFO_COMPAT_ERROR_NEED_SCSI_2_OR_HIGHER (0x00010034)
227/* Compatibility Error : SATA device, 48 BIT LBA not supported */
228#define IR_LOGINFO_COMPAT_ERROR_SATA_48BIT_LBA_NOT_SUPPORTED (0x00010035)
229/* Compatibility Error : Device does not have 512 byte block sizes */
230#define IR_LOGINFO_COMPAT_ERROR_DEVICE_NOT_512_BYTE_BLOCK (0x00010036)
231/* Compatibility Error : Volume Type check failed */
232#define IR_LOGINFO_COMPAT_ERROR_VOLUME_TYPE_CHECK_FAILED (0x00010037)
233/* Compatibility Error : Volume Type is unsupported by FW */
234#define IR_LOGINFO_COMPAT_ERROR_UNSUPPORTED_VOLUME_TYPE (0x00010038)
235/* Compatibility Error : Disk drive too small for use in volume */
236#define IR_LOGINFO_COMPAT_ERROR_DISK_TOO_SMALL (0x00010039)
237/* Compatibility Error : Phys disk for Create Volume not found */
238#define IR_LOGINFO_COMPAT_ERROR_PHYS_DISK_NOT_FOUND (0x0001003A)
239/* Compatibility Error : membership count error, too many or too few disks for volume type */
240#define IR_LOGINFO_COMPAT_ERROR_MEMBERSHIP_COUNT (0x0001003B)
241/* Compatibility Error : Disk stripe sizes must be 64KB */
242#define IR_LOGINFO_COMPAT_ERROR_NON_64K_STRIPE_SIZE (0x0001003C)
243/* Compatibility Error : IME size limited to < 2TB */
244#define IR_LOGINFO_COMPAT_ERROR_IME_VOL_NOT_CURRENTLY_SUPPORTED (0x0001003D)
245
170 246
171/****************************************************************************/ 247/****************************************************************************/
172/* Defines for convienence */ 248/* Defines for convenience */
173/****************************************************************************/ 249/****************************************************************************/
174#define IOC_LOGINFO_PREFIX_IOP ((MPI_IOCLOGINFO_TYPE_SAS << MPI_IOCLOGINFO_TYPE_SHIFT) | IOC_LOGINFO_ORIGINATOR_IOP) 250#define IOC_LOGINFO_PREFIX_IOP ((MPI_IOCLOGINFO_TYPE_SAS << MPI_IOCLOGINFO_TYPE_SHIFT) | IOC_LOGINFO_ORIGINATOR_IOP)
175#define IOC_LOGINFO_PREFIX_PL ((MPI_IOCLOGINFO_TYPE_SAS << MPI_IOCLOGINFO_TYPE_SHIFT) | IOC_LOGINFO_ORIGINATOR_PL) 251#define IOC_LOGINFO_PREFIX_PL ((MPI_IOCLOGINFO_TYPE_SAS << MPI_IOCLOGINFO_TYPE_SHIFT) | IOC_LOGINFO_ORIGINATOR_PL)
diff --git a/drivers/message/fusion/lsi/mpi_sas.h b/drivers/message/fusion/lsi/mpi_sas.h
index 70514867bddf..50b8f0a8f456 100644
--- a/drivers/message/fusion/lsi/mpi_sas.h
+++ b/drivers/message/fusion/lsi/mpi_sas.h
@@ -6,7 +6,7 @@
6 * Title: MPI Serial Attached SCSI structures and definitions 6 * Title: MPI Serial Attached SCSI structures and definitions
7 * Creation Date: August 19, 2004 7 * Creation Date: August 19, 2004
8 * 8 *
9 * mpi_sas.h Version: 01.05.02 9 * mpi_sas.h Version: 01.05.03
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -17,6 +17,10 @@
17 * 08-30-05 01.05.02 Added DeviceInfo bit for SEP. 17 * 08-30-05 01.05.02 Added DeviceInfo bit for SEP.
18 * Added PrimFlags and Primitive field to SAS IO Unit 18 * Added PrimFlags and Primitive field to SAS IO Unit
19 * Control request, and added a new operation code. 19 * Control request, and added a new operation code.
20 * 03-27-06 01.05.03 Added Force Full Discovery, Transmit Port Select Signal,
21 * and Remove Device operations to SAS IO Unit Control.
22 * Added DevHandle field to SAS IO Unit Control request and
23 * reply.
20 * -------------------------------------------------------------------------- 24 * --------------------------------------------------------------------------
21 */ 25 */
22 26
@@ -209,7 +213,7 @@ typedef struct _MSG_SAS_IOUNIT_CONTROL_REQUEST
209 U8 Reserved1; /* 01h */ 213 U8 Reserved1; /* 01h */
210 U8 ChainOffset; /* 02h */ 214 U8 ChainOffset; /* 02h */
211 U8 Function; /* 03h */ 215 U8 Function; /* 03h */
212 U16 Reserved2; /* 04h */ 216 U16 DevHandle; /* 04h */
213 U8 Reserved3; /* 06h */ 217 U8 Reserved3; /* 06h */
214 U8 MsgFlags; /* 07h */ 218 U8 MsgFlags; /* 07h */
215 U32 MsgContext; /* 08h */ 219 U32 MsgContext; /* 08h */
@@ -231,6 +235,9 @@ typedef struct _MSG_SAS_IOUNIT_CONTROL_REQUEST
231#define MPI_SAS_OP_PHY_CLEAR_ERROR_LOG (0x08) 235#define MPI_SAS_OP_PHY_CLEAR_ERROR_LOG (0x08)
232#define MPI_SAS_OP_MAP_CURRENT (0x09) 236#define MPI_SAS_OP_MAP_CURRENT (0x09)
233#define MPI_SAS_OP_SEND_PRIMITIVE (0x0A) 237#define MPI_SAS_OP_SEND_PRIMITIVE (0x0A)
238#define MPI_SAS_OP_FORCE_FULL_DISCOVERY (0x0B)
239#define MPI_SAS_OP_TRANSMIT_PORT_SELECT_SIGNAL (0x0C)
240#define MPI_SAS_OP_TRANSMIT_REMOVE_DEVICE (0x0D)
234 241
235/* values for the PrimFlags field */ 242/* values for the PrimFlags field */
236#define MPI_SAS_PRIMFLAGS_SINGLE (0x08) 243#define MPI_SAS_PRIMFLAGS_SINGLE (0x08)
@@ -245,7 +252,7 @@ typedef struct _MSG_SAS_IOUNIT_CONTROL_REPLY
245 U8 Reserved1; /* 01h */ 252 U8 Reserved1; /* 01h */
246 U8 MsgLength; /* 02h */ 253 U8 MsgLength; /* 02h */
247 U8 Function; /* 03h */ 254 U8 Function; /* 03h */
248 U16 Reserved2; /* 04h */ 255 U16 DevHandle; /* 04h */
249 U8 Reserved3; /* 06h */ 256 U8 Reserved3; /* 06h */
250 U8 MsgFlags; /* 07h */ 257 U8 MsgFlags; /* 07h */
251 U32 MsgContext; /* 08h */ 258 U32 MsgContext; /* 08h */
diff --git a/drivers/message/fusion/lsi/mpi_targ.h b/drivers/message/fusion/lsi/mpi_targ.h
index 3f462859ceea..20b667315773 100644
--- a/drivers/message/fusion/lsi/mpi_targ.h
+++ b/drivers/message/fusion/lsi/mpi_targ.h
@@ -6,7 +6,7 @@
6 * Title: MPI Target mode messages and structures 6 * Title: MPI Target mode messages and structures
7 * Creation Date: June 22, 2000 7 * Creation Date: June 22, 2000
8 * 8 *
9 * mpi_targ.h Version: 01.05.05 9 * mpi_targ.h Version: 01.05.06
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -54,6 +54,7 @@
54 * 02-22-05 01.05.03 Changed a comment. 54 * 02-22-05 01.05.03 Changed a comment.
55 * 03-11-05 01.05.04 Removed TargetAssistExtended Request. 55 * 03-11-05 01.05.04 Removed TargetAssistExtended Request.
56 * 06-24-05 01.05.05 Added TargetAssistExtended structures and defines. 56 * 06-24-05 01.05.05 Added TargetAssistExtended structures and defines.
57 * 03-27-06 01.05.06 Added a comment.
57 * -------------------------------------------------------------------------- 58 * --------------------------------------------------------------------------
58 */ 59 */
59 60
@@ -351,7 +352,7 @@ typedef struct _MSG_TARGET_ASSIST_REQUEST
351#define TARGET_ASSIST_FLAGS_CONFIRMED (0x08) 352#define TARGET_ASSIST_FLAGS_CONFIRMED (0x08)
352#define TARGET_ASSIST_FLAGS_REPOST_CMD_BUFFER (0x80) 353#define TARGET_ASSIST_FLAGS_REPOST_CMD_BUFFER (0x80)
353 354
354 355/* Standard Target Mode Reply message */
355typedef struct _MSG_TARGET_ERROR_REPLY 356typedef struct _MSG_TARGET_ERROR_REPLY
356{ 357{
357 U16 Reserved; /* 00h */ 358 U16 Reserved; /* 00h */
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 57543603d6c8..29d0635cce1d 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -368,20 +368,21 @@ static irqreturn_t
368mpt_interrupt(int irq, void *bus_id, struct pt_regs *r) 368mpt_interrupt(int irq, void *bus_id, struct pt_regs *r)
369{ 369{
370 MPT_ADAPTER *ioc = bus_id; 370 MPT_ADAPTER *ioc = bus_id;
371 u32 pa; 371 u32 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
372
373 if (pa == 0xFFFFFFFF)
374 return IRQ_NONE;
372 375
373 /* 376 /*
374 * Drain the reply FIFO! 377 * Drain the reply FIFO!
375 */ 378 */
376 while (1) { 379 do {
377 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo); 380 if (pa & MPI_ADDRESS_REPLY_A_BIT)
378 if (pa == 0xFFFFFFFF)
379 return IRQ_HANDLED;
380 else if (pa & MPI_ADDRESS_REPLY_A_BIT)
381 mpt_reply(ioc, pa); 381 mpt_reply(ioc, pa);
382 else 382 else
383 mpt_turbo_reply(ioc, pa); 383 mpt_turbo_reply(ioc, pa);
384 } 384 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
385 } while (pa != 0xFFFFFFFF);
385 386
386 return IRQ_HANDLED; 387 return IRQ_HANDLED;
387} 388}
@@ -435,8 +436,6 @@ mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
435 */ 436 */
436 if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) { 437 if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) {
437 freereq = 0; 438 freereq = 0;
438 devtverboseprintk((MYIOC_s_WARN_FMT "EVENT_NOTIFICATION reply %p does not return Request frame\n",
439 ioc->name, pEvReply));
440 } else { 439 } else {
441 devtverboseprintk((MYIOC_s_WARN_FMT "EVENT_NOTIFICATION reply %p returns Request frame\n", 440 devtverboseprintk((MYIOC_s_WARN_FMT "EVENT_NOTIFICATION reply %p returns Request frame\n",
442 ioc->name, pEvReply)); 441 ioc->name, pEvReply));
@@ -677,19 +676,19 @@ int
677mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx) 676mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx)
678{ 677{
679 MPT_ADAPTER *ioc; 678 MPT_ADAPTER *ioc;
679 const struct pci_device_id *id;
680 680
681 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS) { 681 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
682 return -EINVAL; 682 return -EINVAL;
683 }
684 683
685 MptDeviceDriverHandlers[cb_idx] = dd_cbfunc; 684 MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
686 685
687 /* call per pci device probe entry point */ 686 /* call per pci device probe entry point */
688 list_for_each_entry(ioc, &ioc_list, list) { 687 list_for_each_entry(ioc, &ioc_list, list) {
689 if(dd_cbfunc->probe) { 688 id = ioc->pcidev->driver ?
690 dd_cbfunc->probe(ioc->pcidev, 689 ioc->pcidev->driver->id_table : NULL;
691 ioc->pcidev->driver->id_table); 690 if (dd_cbfunc->probe)
692 } 691 dd_cbfunc->probe(ioc->pcidev, id);
693 } 692 }
694 693
695 return 0; 694 return 0;
@@ -1055,9 +1054,8 @@ mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init)
1055 1054
1056 dinitprintk((MYIOC_s_INFO_FMT 1055 dinitprintk((MYIOC_s_INFO_FMT
1057 "host_page_buffer @ %p, dma @ %x, sz=%d bytes\n", 1056 "host_page_buffer @ %p, dma @ %x, sz=%d bytes\n",
1058 ioc->name, 1057 ioc->name, ioc->HostPageBuffer,
1059 ioc->HostPageBuffer, 1058 (u32)ioc->HostPageBuffer_dma,
1060 ioc->HostPageBuffer_dma,
1061 host_page_buffer_sz)); 1059 host_page_buffer_sz));
1062 ioc->alloc_total += host_page_buffer_sz; 1060 ioc->alloc_total += host_page_buffer_sz;
1063 ioc->HostPageBuffer_sz = host_page_buffer_sz; 1061 ioc->HostPageBuffer_sz = host_page_buffer_sz;
@@ -1219,31 +1217,25 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1219 port = psize = 0; 1217 port = psize = 0;
1220 for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) { 1218 for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) {
1221 if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) { 1219 if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
1220 if (psize)
1221 continue;
1222 /* Get I/O space! */ 1222 /* Get I/O space! */
1223 port = pci_resource_start(pdev, ii); 1223 port = pci_resource_start(pdev, ii);
1224 psize = pci_resource_len(pdev,ii); 1224 psize = pci_resource_len(pdev,ii);
1225 } else { 1225 } else {
1226 if (msize)
1227 continue;
1226 /* Get memmap */ 1228 /* Get memmap */
1227 mem_phys = pci_resource_start(pdev, ii); 1229 mem_phys = pci_resource_start(pdev, ii);
1228 msize = pci_resource_len(pdev,ii); 1230 msize = pci_resource_len(pdev,ii);
1229 break;
1230 } 1231 }
1231 } 1232 }
1232 ioc->mem_size = msize; 1233 ioc->mem_size = msize;
1233 1234
1234 if (ii == DEVICE_COUNT_RESOURCE) {
1235 printk(KERN_ERR MYNAM ": ERROR - MPT adapter has no memory regions defined!\n");
1236 kfree(ioc);
1237 return -EINVAL;
1238 }
1239
1240 dinitprintk((KERN_INFO MYNAM ": MPT adapter @ %lx, msize=%dd bytes\n", mem_phys, msize));
1241 dinitprintk((KERN_INFO MYNAM ": (port i/o @ %lx, psize=%dd bytes)\n", port, psize));
1242
1243 mem = NULL; 1235 mem = NULL;
1244 /* Get logical ptr for PciMem0 space */ 1236 /* Get logical ptr for PciMem0 space */
1245 /*mem = ioremap(mem_phys, msize);*/ 1237 /*mem = ioremap(mem_phys, msize);*/
1246 mem = ioremap(mem_phys, 0x100); 1238 mem = ioremap(mem_phys, msize);
1247 if (mem == NULL) { 1239 if (mem == NULL) {
1248 printk(KERN_ERR MYNAM ": ERROR - Unable to map adapter memory!\n"); 1240 printk(KERN_ERR MYNAM ": ERROR - Unable to map adapter memory!\n");
1249 kfree(ioc); 1241 kfree(ioc);
@@ -1343,11 +1335,6 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1343 ioc->bus_type = SAS; 1335 ioc->bus_type = SAS;
1344 ioc->errata_flag_1064 = 1; 1336 ioc->errata_flag_1064 = 1;
1345 } 1337 }
1346 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1066) {
1347 ioc->prod_name = "LSISAS1066";
1348 ioc->bus_type = SAS;
1349 ioc->errata_flag_1064 = 1;
1350 }
1351 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1068) { 1338 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1068) {
1352 ioc->prod_name = "LSISAS1068"; 1339 ioc->prod_name = "LSISAS1068";
1353 ioc->bus_type = SAS; 1340 ioc->bus_type = SAS;
@@ -1357,14 +1344,14 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1357 ioc->prod_name = "LSISAS1064E"; 1344 ioc->prod_name = "LSISAS1064E";
1358 ioc->bus_type = SAS; 1345 ioc->bus_type = SAS;
1359 } 1346 }
1360 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1066E) {
1361 ioc->prod_name = "LSISAS1066E";
1362 ioc->bus_type = SAS;
1363 }
1364 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1068E) { 1347 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1068E) {
1365 ioc->prod_name = "LSISAS1068E"; 1348 ioc->prod_name = "LSISAS1068E";
1366 ioc->bus_type = SAS; 1349 ioc->bus_type = SAS;
1367 } 1350 }
1351 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
1352 ioc->prod_name = "LSISAS1078";
1353 ioc->bus_type = SAS;
1354 }
1368 1355
1369 if (ioc->errata_flag_1064) 1356 if (ioc->errata_flag_1064)
1370 pci_disable_io_access(pdev); 1357 pci_disable_io_access(pdev);
@@ -1390,6 +1377,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1390 printk(KERN_WARNING MYNAM 1377 printk(KERN_WARNING MYNAM
1391 ": WARNING - %s did not initialize properly! (%d)\n", 1378 ": WARNING - %s did not initialize properly! (%d)\n",
1392 ioc->name, r); 1379 ioc->name, r);
1380
1393 list_del(&ioc->list); 1381 list_del(&ioc->list);
1394 if (ioc->alt_ioc) 1382 if (ioc->alt_ioc)
1395 ioc->alt_ioc->alt_ioc = NULL; 1383 ioc->alt_ioc->alt_ioc = NULL;
@@ -1772,9 +1760,9 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1772 * chips (mpt_adapter_disable, 1760 * chips (mpt_adapter_disable,
1773 * mpt_diag_reset) 1761 * mpt_diag_reset)
1774 */ 1762 */
1775 ioc->cached_fw = NULL;
1776 ddlprintk((MYIOC_s_INFO_FMT ": mpt_upload: alt_%s has cached_fw=%p \n", 1763 ddlprintk((MYIOC_s_INFO_FMT ": mpt_upload: alt_%s has cached_fw=%p \n",
1777 ioc->name, ioc->alt_ioc->name, ioc->alt_ioc->cached_fw)); 1764 ioc->name, ioc->alt_ioc->name, ioc->alt_ioc->cached_fw));
1765 ioc->alt_ioc->cached_fw = NULL;
1778 } 1766 }
1779 } else { 1767 } else {
1780 printk(KERN_WARNING MYNAM ": firmware upload failure!\n"); 1768 printk(KERN_WARNING MYNAM ": firmware upload failure!\n");
@@ -1895,7 +1883,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1895 /* FIXME? Examine results here? */ 1883 /* FIXME? Examine results here? */
1896 } 1884 }
1897 1885
1898out: 1886 out:
1899 if ((ret != 0) && irq_allocated) { 1887 if ((ret != 0) && irq_allocated) {
1900 free_irq(ioc->pci_irq, ioc); 1888 free_irq(ioc->pci_irq, ioc);
1901 if (mpt_msi_enable) 1889 if (mpt_msi_enable)
@@ -2680,6 +2668,7 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
2680 dinitprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n", 2668 dinitprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
2681 ioc->name, count)); 2669 ioc->name, count));
2682 2670
2671 ioc->aen_event_read_flag=0;
2683 return r; 2672 return r;
2684} 2673}
2685 2674
@@ -2747,6 +2736,8 @@ mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
2747 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) { 2736 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
2748 ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */ 2737 ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
2749 ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma; 2738 ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
2739 ioc->alloc_total += size;
2740 ioc->alt_ioc->alloc_total -= size;
2750 } else { 2741 } else {
2751 if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) ) 2742 if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) )
2752 ioc->alloc_total += size; 2743 ioc->alloc_total += size;
@@ -3176,6 +3167,7 @@ KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
3176static int 3167static int
3177mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag) 3168mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
3178{ 3169{
3170 MPT_ADAPTER *iocp=NULL;
3179 u32 diag0val; 3171 u32 diag0val;
3180 u32 doorbell; 3172 u32 doorbell;
3181 int hard_reset_done = 0; 3173 int hard_reset_done = 0;
@@ -3184,6 +3176,37 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
3184 u32 diag1val = 0; 3176 u32 diag1val = 0;
3185#endif 3177#endif
3186 3178
3179 if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
3180 drsprintk((MYIOC_s_WARN_FMT "%s: Doorbell=%p; 1078 reset "
3181 "address=%p\n", ioc->name, __FUNCTION__,
3182 &ioc->chip->Doorbell, &ioc->chip->Reset_1078));
3183 CHIPREG_WRITE32(&ioc->chip->Reset_1078, 0x07);
3184 if (sleepFlag == CAN_SLEEP)
3185 msleep(1);
3186 else
3187 mdelay(1);
3188
3189 for (count = 0; count < 60; count ++) {
3190 doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
3191 doorbell &= MPI_IOC_STATE_MASK;
3192
3193 drsprintk((MYIOC_s_INFO_FMT
3194 "looking for READY STATE: doorbell=%x"
3195 " count=%d\n",
3196 ioc->name, doorbell, count));
3197 if (doorbell == MPI_IOC_STATE_READY) {
3198 return 0;
3199 }
3200
3201 /* wait 1 sec */
3202 if (sleepFlag == CAN_SLEEP)
3203 msleep(1000);
3204 else
3205 mdelay(1000);
3206 }
3207 return -1;
3208 }
3209
3187 /* Clear any existing interrupts */ 3210 /* Clear any existing interrupts */
3188 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0); 3211 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3189 3212
@@ -3280,17 +3303,23 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
3280 /* FIXME? Examine results here? */ 3303 /* FIXME? Examine results here? */
3281 } 3304 }
3282 3305
3283 if (ioc->cached_fw) { 3306 if (ioc->cached_fw)
3307 iocp = ioc;
3308 else if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
3309 iocp = ioc->alt_ioc;
3310 if (iocp) {
3284 /* If the DownloadBoot operation fails, the 3311 /* If the DownloadBoot operation fails, the
3285 * IOC will be left unusable. This is a fatal error 3312 * IOC will be left unusable. This is a fatal error
3286 * case. _diag_reset will return < 0 3313 * case. _diag_reset will return < 0
3287 */ 3314 */
3288 for (count = 0; count < 30; count ++) { 3315 for (count = 0; count < 30; count ++) {
3289 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic); 3316 diag0val = CHIPREG_READ32(&iocp->chip->Diagnostic);
3290 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) { 3317 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
3291 break; 3318 break;
3292 } 3319 }
3293 3320
3321 dprintk((MYIOC_s_INFO_FMT "cached_fw: diag0val=%x count=%d\n",
3322 iocp->name, diag0val, count));
3294 /* wait 1 sec */ 3323 /* wait 1 sec */
3295 if (sleepFlag == CAN_SLEEP) { 3324 if (sleepFlag == CAN_SLEEP) {
3296 msleep (1000); 3325 msleep (1000);
@@ -3299,7 +3328,7 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
3299 } 3328 }
3300 } 3329 }
3301 if ((count = mpt_downloadboot(ioc, 3330 if ((count = mpt_downloadboot(ioc,
3302 (MpiFwHeader_t *)ioc->cached_fw, sleepFlag)) < 0) { 3331 (MpiFwHeader_t *)iocp->cached_fw, sleepFlag)) < 0) {
3303 printk(KERN_WARNING MYNAM 3332 printk(KERN_WARNING MYNAM
3304 ": firmware downloadboot failure (%d)!\n", count); 3333 ": firmware downloadboot failure (%d)!\n", count);
3305 } 3334 }
@@ -3886,18 +3915,18 @@ WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3886 3915
3887 if (sleepFlag == CAN_SLEEP) { 3916 if (sleepFlag == CAN_SLEEP) {
3888 while (--cntdn) { 3917 while (--cntdn) {
3918 msleep (1);
3889 intstat = CHIPREG_READ32(&ioc->chip->IntStatus); 3919 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3890 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS)) 3920 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
3891 break; 3921 break;
3892 msleep (1);
3893 count++; 3922 count++;
3894 } 3923 }
3895 } else { 3924 } else {
3896 while (--cntdn) { 3925 while (--cntdn) {
3926 mdelay (1);
3897 intstat = CHIPREG_READ32(&ioc->chip->IntStatus); 3927 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3898 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS)) 3928 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
3899 break; 3929 break;
3900 mdelay (1);
3901 count++; 3930 count++;
3902 } 3931 }
3903 } 3932 }
@@ -4862,6 +4891,7 @@ mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
4862 pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma); 4891 pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma);
4863 if (!pIoc4) 4892 if (!pIoc4)
4864 return; 4893 return;
4894 ioc->alloc_total += iocpage4sz;
4865 } else { 4895 } else {
4866 ioc4_dma = ioc->spi_data.IocPg4_dma; 4896 ioc4_dma = ioc->spi_data.IocPg4_dma;
4867 iocpage4sz = ioc->spi_data.IocPg4Sz; 4897 iocpage4sz = ioc->spi_data.IocPg4Sz;
@@ -4878,6 +4908,7 @@ mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
4878 } else { 4908 } else {
4879 pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma); 4909 pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma);
4880 ioc->spi_data.pIocPg4 = NULL; 4910 ioc->spi_data.pIocPg4 = NULL;
4911 ioc->alloc_total -= iocpage4sz;
4881 } 4912 }
4882} 4913}
4883 4914
@@ -5009,19 +5040,18 @@ SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
5009 EventAck_t *pAck; 5040 EventAck_t *pAck;
5010 5041
5011 if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) { 5042 if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
5012 printk(MYIOC_s_WARN_FMT "Unable to allocate event ACK " 5043 dfailprintk((MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
5013 "request frame for Event=%x EventContext=%x EventData=%x!\n", 5044 ioc->name,__FUNCTION__));
5014 ioc->name, evnp->Event, le32_to_cpu(evnp->EventContext),
5015 le32_to_cpu(evnp->Data[0]));
5016 return -1; 5045 return -1;
5017 } 5046 }
5018 memset(pAck, 0, sizeof(*pAck));
5019 5047
5020 dprintk((MYIOC_s_INFO_FMT "Sending EventAck\n", ioc->name)); 5048 devtverboseprintk((MYIOC_s_INFO_FMT "Sending EventAck\n", ioc->name));
5021 5049
5022 pAck->Function = MPI_FUNCTION_EVENT_ACK; 5050 pAck->Function = MPI_FUNCTION_EVENT_ACK;
5023 pAck->ChainOffset = 0; 5051 pAck->ChainOffset = 0;
5052 pAck->Reserved[0] = pAck->Reserved[1] = 0;
5024 pAck->MsgFlags = 0; 5053 pAck->MsgFlags = 0;
5054 pAck->Reserved1[0] = pAck->Reserved1[1] = pAck->Reserved1[2] = 0;
5025 pAck->Event = evnp->Event; 5055 pAck->Event = evnp->Event;
5026 pAck->EventContext = evnp->EventContext; 5056 pAck->EventContext = evnp->EventContext;
5027 5057
@@ -5683,9 +5713,9 @@ EventDescriptionStr(u8 event, u32 evData0, char *evStr)
5683 break; 5713 break;
5684 case MPI_EVENT_EVENT_CHANGE: 5714 case MPI_EVENT_EVENT_CHANGE:
5685 if (evData0) 5715 if (evData0)
5686 ds = "Events(ON) Change"; 5716 ds = "Events ON";
5687 else 5717 else
5688 ds = "Events(OFF) Change"; 5718 ds = "Events OFF";
5689 break; 5719 break;
5690 case MPI_EVENT_INTEGRATED_RAID: 5720 case MPI_EVENT_INTEGRATED_RAID:
5691 { 5721 {
@@ -5756,8 +5786,27 @@ EventDescriptionStr(u8 event, u32 evData0, char *evStr)
5756 break; 5786 break;
5757 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED: 5787 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
5758 snprintf(evStr, EVENT_DESCR_STR_SZ, 5788 snprintf(evStr, EVENT_DESCR_STR_SZ,
5759 "SAS Device Status Change: No Persistancy " 5789 "SAS Device Status Change: No Persistancy: id=%d", id);
5760 "Added: id=%d", id); 5790 break;
5791 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5792 snprintf(evStr, EVENT_DESCR_STR_SZ,
5793 "SAS Device Status Change: Internal Device Reset : id=%d", id);
5794 break;
5795 case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5796 snprintf(evStr, EVENT_DESCR_STR_SZ,
5797 "SAS Device Status Change: Internal Task Abort : id=%d", id);
5798 break;
5799 case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5800 snprintf(evStr, EVENT_DESCR_STR_SZ,
5801 "SAS Device Status Change: Internal Abort Task Set : id=%d", id);
5802 break;
5803 case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5804 snprintf(evStr, EVENT_DESCR_STR_SZ,
5805 "SAS Device Status Change: Internal Clear Task Set : id=%d", id);
5806 break;
5807 case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5808 snprintf(evStr, EVENT_DESCR_STR_SZ,
5809 "SAS Device Status Change: Internal Query Task : id=%d", id);
5761 break; 5810 break;
5762 default: 5811 default:
5763 snprintf(evStr, EVENT_DESCR_STR_SZ, 5812 snprintf(evStr, EVENT_DESCR_STR_SZ,
@@ -6013,7 +6062,7 @@ ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply
6013 * @ioc: Pointer to MPT_ADAPTER structure 6062 * @ioc: Pointer to MPT_ADAPTER structure
6014 * @log_info: U32 LogInfo reply word from the IOC 6063 * @log_info: U32 LogInfo reply word from the IOC
6015 * 6064 *
6016 * Refer to lsi/fc_log.h. 6065 * Refer to lsi/mpi_log_fc.h.
6017 */ 6066 */
6018static void 6067static void
6019mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info) 6068mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
@@ -6110,8 +6159,10 @@ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
6110 "Invalid SAS Address", /* 01h */ 6159 "Invalid SAS Address", /* 01h */
6111 NULL, /* 02h */ 6160 NULL, /* 02h */
6112 "Invalid Page", /* 03h */ 6161 "Invalid Page", /* 03h */
6113 NULL, /* 04h */ 6162 "Diag Message Error", /* 04h */
6114 "Task Terminated" /* 05h */ 6163 "Task Terminated", /* 05h */
6164 "Enclosure Management", /* 06h */
6165 "Target Mode" /* 07h */
6115 }; 6166 };
6116 static char *pl_code_str[] = { 6167 static char *pl_code_str[] = {
6117 NULL, /* 00h */ 6168 NULL, /* 00h */
@@ -6137,7 +6188,7 @@ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
6137 "IO Executed", /* 14h */ 6188 "IO Executed", /* 14h */
6138 "Persistant Reservation Out Not Affiliation Owner", /* 15h */ 6189 "Persistant Reservation Out Not Affiliation Owner", /* 15h */
6139 "Open Transmit DMA Abort", /* 16h */ 6190 "Open Transmit DMA Abort", /* 16h */
6140 NULL, /* 17h */ 6191 "IO Device Missing Delay Retry", /* 17h */
6141 NULL, /* 18h */ 6192 NULL, /* 18h */
6142 NULL, /* 19h */ 6193 NULL, /* 19h */
6143 NULL, /* 1Ah */ 6194 NULL, /* 1Ah */
@@ -6217,7 +6268,7 @@ static void
6217mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf) 6268mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
6218{ 6269{
6219 u32 status = ioc_status & MPI_IOCSTATUS_MASK; 6270 u32 status = ioc_status & MPI_IOCSTATUS_MASK;
6220 char *desc = ""; 6271 char *desc = NULL;
6221 6272
6222 switch (status) { 6273 switch (status) {
6223 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */ 6274 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
@@ -6327,7 +6378,7 @@ mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
6327 desc = "Others"; 6378 desc = "Others";
6328 break; 6379 break;
6329 } 6380 }
6330 if (desc != "") 6381 if (desc != NULL)
6331 printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04x): %s\n", ioc->name, status, desc); 6382 printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04x): %s\n", ioc->name, status, desc);
6332} 6383}
6333 6384
@@ -6365,7 +6416,6 @@ EXPORT_SYMBOL(mpt_alloc_fw_memory);
6365EXPORT_SYMBOL(mpt_free_fw_memory); 6416EXPORT_SYMBOL(mpt_free_fw_memory);
6366EXPORT_SYMBOL(mptbase_sas_persist_operation); 6417EXPORT_SYMBOL(mptbase_sas_persist_operation);
6367 6418
6368
6369/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 6419/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6370/* 6420/*
6371 * fusion_init - Fusion MPT base driver initialization routine. 6421 * fusion_init - Fusion MPT base driver initialization routine.
diff --git a/drivers/message/fusion/mptbase.h b/drivers/message/fusion/mptbase.h
index 32ae4d664545..c537d71c18e4 100644
--- a/drivers/message/fusion/mptbase.h
+++ b/drivers/message/fusion/mptbase.h
@@ -75,8 +75,8 @@
75#define COPYRIGHT "Copyright (c) 1999-2005 " MODULEAUTHOR 75#define COPYRIGHT "Copyright (c) 1999-2005 " MODULEAUTHOR
76#endif 76#endif
77 77
78#define MPT_LINUX_VERSION_COMMON "3.03.10" 78#define MPT_LINUX_VERSION_COMMON "3.04.01"
79#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.03.10" 79#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.04.01"
80#define WHAT_MAGIC_STRING "@" "(" "#" ")" 80#define WHAT_MAGIC_STRING "@" "(" "#" ")"
81 81
82#define show_mptmod_ver(s,ver) \ 82#define show_mptmod_ver(s,ver) \
@@ -307,7 +307,8 @@ typedef struct _SYSIF_REGS
307 u32 HostIndex; /* 50 Host Index register */ 307 u32 HostIndex; /* 50 Host Index register */
308 u32 Reserved4[15]; /* 54-8F */ 308 u32 Reserved4[15]; /* 54-8F */
309 u32 Fubar; /* 90 For Fubar usage */ 309 u32 Fubar; /* 90 For Fubar usage */
310 u32 Reserved5[27]; /* 94-FF */ 310 u32 Reserved5[1050];/* 94-10F8 */
311 u32 Reset_1078; /* 10FC Reset 1078 */
311} SYSIF_REGS; 312} SYSIF_REGS;
312 313
313/* 314/*
@@ -341,6 +342,7 @@ typedef struct _VirtTarget {
341 u8 negoFlags; /* bit field, see above */ 342 u8 negoFlags; /* bit field, see above */
342 u8 raidVolume; /* set, if RAID Volume */ 343 u8 raidVolume; /* set, if RAID Volume */
343 u8 type; /* byte 0 of Inquiry data */ 344 u8 type; /* byte 0 of Inquiry data */
345 u8 deleted; /* target in process of being removed */
344 u32 num_luns; 346 u32 num_luns;
345 u32 luns[8]; /* Max LUNs is 256 */ 347 u32 luns[8]; /* Max LUNs is 256 */
346} VirtTarget; 348} VirtTarget;
@@ -361,6 +363,7 @@ typedef struct _VirtDevice {
361#define MPT_TARGET_FLAGS_VALID_56 0x10 363#define MPT_TARGET_FLAGS_VALID_56 0x10
362#define MPT_TARGET_FLAGS_SAF_TE_ISSUED 0x20 364#define MPT_TARGET_FLAGS_SAF_TE_ISSUED 0x20
363#define MPT_TARGET_FLAGS_RAID_COMPONENT 0x40 365#define MPT_TARGET_FLAGS_RAID_COMPONENT 0x40
366#define MPT_TARGET_FLAGS_LED_ON 0x80
364 367
365/* 368/*
366 * /proc/mpt interface 369 * /proc/mpt interface
@@ -629,15 +632,14 @@ typedef struct _MPT_ADAPTER
629 struct mutex sas_discovery_mutex; 632 struct mutex sas_discovery_mutex;
630 u8 sas_discovery_runtime; 633 u8 sas_discovery_runtime;
631 u8 sas_discovery_ignore_events; 634 u8 sas_discovery_ignore_events;
635 u16 handle;
632 int sas_index; /* index refrencing */ 636 int sas_index; /* index refrencing */
633 MPT_SAS_MGMT sas_mgmt; 637 MPT_SAS_MGMT sas_mgmt;
634 int num_ports; 638 struct work_struct sas_persist_task;
635 struct work_struct mptscsih_persistTask;
636 639
637 struct work_struct fc_setup_reset_work; 640 struct work_struct fc_setup_reset_work;
638 struct list_head fc_rports; 641 struct list_head fc_rports;
639 spinlock_t fc_rescan_work_lock; 642 spinlock_t fc_rescan_work_lock;
640 int fc_rescan_work_count;
641 struct work_struct fc_rescan_work; 643 struct work_struct fc_rescan_work;
642 char fc_rescan_work_q_name[KOBJ_NAME_LEN]; 644 char fc_rescan_work_q_name[KOBJ_NAME_LEN];
643 struct workqueue_struct *fc_rescan_work_q; 645 struct workqueue_struct *fc_rescan_work_q;
@@ -892,6 +894,13 @@ typedef struct _mpt_sge {
892#define DBG_DUMP_REQUEST_FRAME_HDR(mfp) 894#define DBG_DUMP_REQUEST_FRAME_HDR(mfp)
893#endif 895#endif
894 896
897// debug sas wide ports
898#ifdef MPT_DEBUG_SAS_WIDE
899#define dsaswideprintk(x) printk x
900#else
901#define dsaswideprintk(x)
902#endif
903
895 904
896/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 905/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
897 906
@@ -971,7 +980,7 @@ typedef struct _MPT_SCSI_HOST {
971 wait_queue_head_t scandv_waitq; 980 wait_queue_head_t scandv_waitq;
972 int scandv_wait_done; 981 int scandv_wait_done;
973 long last_queue_full; 982 long last_queue_full;
974 u8 mpt_pq_filter; 983 u16 tm_iocstatus;
975} MPT_SCSI_HOST; 984} MPT_SCSI_HOST;
976 985
977/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 986/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index b4967bb8a7d6..30975ccd9947 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -2332,7 +2332,7 @@ done_free_mem:
2332} 2332}
2333 2333
2334/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2334/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2335/* Prototype Routine for the HP HOST INFO command. 2335/* Prototype Routine for the HOST INFO command.
2336 * 2336 *
2337 * Outputs: None. 2337 * Outputs: None.
2338 * Return: 0 if successful 2338 * Return: 0 if successful
@@ -2568,7 +2568,7 @@ mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size)
2568} 2568}
2569 2569
2570/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2570/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2571/* Prototype Routine for the HP TARGET INFO command. 2571/* Prototype Routine for the TARGET INFO command.
2572 * 2572 *
2573 * Outputs: None. 2573 * Outputs: None.
2574 * Return: 0 if successful 2574 * Return: 0 if successful
diff --git a/drivers/message/fusion/mptctl.h b/drivers/message/fusion/mptctl.h
index a2f8a97992e6..043941882c6e 100644
--- a/drivers/message/fusion/mptctl.h
+++ b/drivers/message/fusion/mptctl.h
@@ -354,9 +354,6 @@ struct mpt_ioctl_command32 {
354 354
355 355
356/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 356/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
357/*
358 * HP Specific IOCTL Defines and Structures
359 */
360 357
361#define CPQFCTS_IOC_MAGIC 'Z' 358#define CPQFCTS_IOC_MAGIC 'Z'
362#define HP_IOC_MAGIC 'Z' 359#define HP_IOC_MAGIC 'Z'
@@ -364,8 +361,6 @@ struct mpt_ioctl_command32 {
364#define HP_GETHOSTINFO1 _IOR(HP_IOC_MAGIC, 20, hp_host_info_rev0_t) 361#define HP_GETHOSTINFO1 _IOR(HP_IOC_MAGIC, 20, hp_host_info_rev0_t)
365#define HP_GETTARGETINFO _IOR(HP_IOC_MAGIC, 21, hp_target_info_t) 362#define HP_GETTARGETINFO _IOR(HP_IOC_MAGIC, 21, hp_target_info_t)
366 363
367/* All HP IOCTLs must include this header
368 */
369typedef struct _hp_header { 364typedef struct _hp_header {
370 unsigned int iocnum; 365 unsigned int iocnum;
371 unsigned int host; 366 unsigned int host;
diff --git a/drivers/message/fusion/mptfc.c b/drivers/message/fusion/mptfc.c
index 3ff8378ea660..85696f34c310 100644
--- a/drivers/message/fusion/mptfc.c
+++ b/drivers/message/fusion/mptfc.c
@@ -77,10 +77,6 @@ MODULE_DESCRIPTION(my_NAME);
77MODULE_LICENSE("GPL"); 77MODULE_LICENSE("GPL");
78 78
79/* Command line args */ 79/* Command line args */
80static int mpt_pq_filter = 0;
81module_param(mpt_pq_filter, int, 0);
82MODULE_PARM_DESC(mpt_pq_filter, " Enable peripheral qualifier filter: enable=1 (default=0)");
83
84#define MPTFC_DEV_LOSS_TMO (60) 80#define MPTFC_DEV_LOSS_TMO (60)
85static int mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO; /* reasonable default */ 81static int mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO; /* reasonable default */
86module_param(mptfc_dev_loss_tmo, int, 0); 82module_param(mptfc_dev_loss_tmo, int, 0);
@@ -132,21 +128,21 @@ static struct scsi_host_template mptfc_driver_template = {
132 */ 128 */
133 129
134static struct pci_device_id mptfc_pci_table[] = { 130static struct pci_device_id mptfc_pci_table[] = {
135 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC909, 131 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC909,
136 PCI_ANY_ID, PCI_ANY_ID }, 132 PCI_ANY_ID, PCI_ANY_ID },
137 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC919, 133 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919,
138 PCI_ANY_ID, PCI_ANY_ID }, 134 PCI_ANY_ID, PCI_ANY_ID },
139 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC929, 135 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929,
140 PCI_ANY_ID, PCI_ANY_ID }, 136 PCI_ANY_ID, PCI_ANY_ID },
141 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC919X, 137 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919X,
142 PCI_ANY_ID, PCI_ANY_ID }, 138 PCI_ANY_ID, PCI_ANY_ID },
143 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC929X, 139 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929X,
144 PCI_ANY_ID, PCI_ANY_ID }, 140 PCI_ANY_ID, PCI_ANY_ID },
145 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC939X, 141 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC939X,
146 PCI_ANY_ID, PCI_ANY_ID }, 142 PCI_ANY_ID, PCI_ANY_ID },
147 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC949X, 143 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949X,
148 PCI_ANY_ID, PCI_ANY_ID }, 144 PCI_ANY_ID, PCI_ANY_ID },
149 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC949ES, 145 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949E,
150 PCI_ANY_ID, PCI_ANY_ID }, 146 PCI_ANY_ID, PCI_ANY_ID },
151 {0} /* Terminating entry */ 147 {0} /* Terminating entry */
152}; 148};
@@ -513,8 +509,7 @@ mptfc_slave_alloc(struct scsi_device *sdev)
513 509
514 if (vtarget->num_luns == 0) { 510 if (vtarget->num_luns == 0) {
515 vtarget->ioc_id = hd->ioc->id; 511 vtarget->ioc_id = hd->ioc->id;
516 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES | 512 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
517 MPT_TARGET_FLAGS_VALID_INQUIRY;
518 hd->Targets[sdev->id] = vtarget; 513 hd->Targets[sdev->id] = vtarget;
519 } 514 }
520 515
@@ -674,7 +669,10 @@ mptfc_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
674 * if still doing discovery, 669 * if still doing discovery,
675 * hang loose a while until finished 670 * hang loose a while until finished
676 */ 671 */
677 if (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) { 672 if ((pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) ||
673 (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE &&
674 (pp0dest->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_TYPE_MASK)
675 == MPI_FCPORTPAGE0_FLAGS_ATTACH_NO_INIT)) {
678 if (count-- > 0) { 676 if (count-- > 0) {
679 msleep(100); 677 msleep(100);
680 goto try_again; 678 goto try_again;
@@ -900,59 +898,45 @@ mptfc_rescan_devices(void *arg)
900{ 898{
901 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg; 899 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
902 int ii; 900 int ii;
903 int work_to_do;
904 u64 pn; 901 u64 pn;
905 unsigned long flags;
906 struct mptfc_rport_info *ri; 902 struct mptfc_rport_info *ri;
907 903
908 do { 904 /* start by tagging all ports as missing */
909 /* start by tagging all ports as missing */ 905 list_for_each_entry(ri, &ioc->fc_rports, list) {
910 list_for_each_entry(ri, &ioc->fc_rports, list) { 906 if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
911 if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) { 907 ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING;
912 ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING;
913 }
914 } 908 }
909 }
915 910
916 /* 911 /*
917 * now rescan devices known to adapter, 912 * now rescan devices known to adapter,
918 * will reregister existing rports 913 * will reregister existing rports
919 */ 914 */
920 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) { 915 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
921 (void) mptfc_GetFcPortPage0(ioc, ii); 916 (void) mptfc_GetFcPortPage0(ioc, ii);
922 mptfc_init_host_attr(ioc,ii); /* refresh */ 917 mptfc_init_host_attr(ioc, ii); /* refresh */
923 mptfc_GetFcDevPage0(ioc,ii,mptfc_register_dev); 918 mptfc_GetFcDevPage0(ioc, ii, mptfc_register_dev);
924 } 919 }
925 920
926 /* delete devices still missing */ 921 /* delete devices still missing */
927 list_for_each_entry(ri, &ioc->fc_rports, list) { 922 list_for_each_entry(ri, &ioc->fc_rports, list) {
928 /* if newly missing, delete it */ 923 /* if newly missing, delete it */
929 if (ri->flags & MPT_RPORT_INFO_FLAGS_MISSING) { 924 if (ri->flags & MPT_RPORT_INFO_FLAGS_MISSING) {
930 925
931 ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED| 926 ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED|
932 MPT_RPORT_INFO_FLAGS_MISSING); 927 MPT_RPORT_INFO_FLAGS_MISSING);
933 fc_remote_port_delete(ri->rport); /* won't sleep */ 928 fc_remote_port_delete(ri->rport); /* won't sleep */
934 ri->rport = NULL; 929 ri->rport = NULL;
935 930
936 pn = (u64)ri->pg0.WWPN.High << 32 | 931 pn = (u64)ri->pg0.WWPN.High << 32 |
937 (u64)ri->pg0.WWPN.Low; 932 (u64)ri->pg0.WWPN.Low;
938 dfcprintk ((MYIOC_s_INFO_FMT 933 dfcprintk ((MYIOC_s_INFO_FMT
939 "mptfc_rescan.%d: %llx deleted\n", 934 "mptfc_rescan.%d: %llx deleted\n",
940 ioc->name, 935 ioc->name,
941 ioc->sh->host_no, 936 ioc->sh->host_no,
942 (unsigned long long)pn)); 937 (unsigned long long)pn));
943 }
944 } 938 }
945 939 }
946 /*
947 * allow multiple passes as target state
948 * might have changed during scan
949 */
950 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
951 if (ioc->fc_rescan_work_count > 2) /* only need one more */
952 ioc->fc_rescan_work_count = 2;
953 work_to_do = --ioc->fc_rescan_work_count;
954 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
955 } while (work_to_do);
956} 940}
957 941
958static int 942static int
@@ -1129,13 +1113,6 @@ mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1129 hd->timer.data = (unsigned long) hd; 1113 hd->timer.data = (unsigned long) hd;
1130 hd->timer.function = mptscsih_timer_expired; 1114 hd->timer.function = mptscsih_timer_expired;
1131 1115
1132 hd->mpt_pq_filter = mpt_pq_filter;
1133
1134 ddvprintk((MYIOC_s_INFO_FMT
1135 "mpt_pq_filter %x\n",
1136 ioc->name,
1137 mpt_pq_filter));
1138
1139 init_waitqueue_head(&hd->scandv_waitq); 1116 init_waitqueue_head(&hd->scandv_waitq);
1140 hd->scandv_wait_done = 0; 1117 hd->scandv_wait_done = 0;
1141 hd->last_queue_full = 0; 1118 hd->last_queue_full = 0;
@@ -1171,7 +1148,6 @@ mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1171 * by doing it via the workqueue, some locking is eliminated 1148 * by doing it via the workqueue, some locking is eliminated
1172 */ 1149 */
1173 1150
1174 ioc->fc_rescan_work_count = 1;
1175 queue_work(ioc->fc_rescan_work_q, &ioc->fc_rescan_work); 1151 queue_work(ioc->fc_rescan_work_q, &ioc->fc_rescan_work);
1176 flush_workqueue(ioc->fc_rescan_work_q); 1152 flush_workqueue(ioc->fc_rescan_work_q);
1177 1153
@@ -1214,10 +1190,8 @@ mptfc_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
1214 case MPI_EVENT_RESCAN: 1190 case MPI_EVENT_RESCAN:
1215 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags); 1191 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1216 if (ioc->fc_rescan_work_q) { 1192 if (ioc->fc_rescan_work_q) {
1217 if (ioc->fc_rescan_work_count++ == 0) { 1193 queue_work(ioc->fc_rescan_work_q,
1218 queue_work(ioc->fc_rescan_work_q, 1194 &ioc->fc_rescan_work);
1219 &ioc->fc_rescan_work);
1220 }
1221 } 1195 }
1222 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags); 1196 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1223 break; 1197 break;
@@ -1260,10 +1234,8 @@ mptfc_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
1260 mptfc_SetFcPortPage1_defaults(ioc); 1234 mptfc_SetFcPortPage1_defaults(ioc);
1261 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags); 1235 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1262 if (ioc->fc_rescan_work_q) { 1236 if (ioc->fc_rescan_work_q) {
1263 if (ioc->fc_rescan_work_count++ == 0) { 1237 queue_work(ioc->fc_rescan_work_q,
1264 queue_work(ioc->fc_rescan_work_q, 1238 &ioc->fc_rescan_work);
1265 &ioc->fc_rescan_work);
1266 }
1267 } 1239 }
1268 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags); 1240 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1269 } 1241 }
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 85689ab46cbc..f66f2203143a 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -50,11 +50,14 @@
50#include <linux/errno.h> 50#include <linux/errno.h>
51#include <linux/sched.h> 51#include <linux/sched.h>
52#include <linux/workqueue.h> 52#include <linux/workqueue.h>
53#include <linux/delay.h> /* for mdelay */
53 54
55#include <scsi/scsi.h>
54#include <scsi/scsi_cmnd.h> 56#include <scsi/scsi_cmnd.h>
55#include <scsi/scsi_device.h> 57#include <scsi/scsi_device.h>
56#include <scsi/scsi_host.h> 58#include <scsi/scsi_host.h>
57#include <scsi/scsi_transport_sas.h> 59#include <scsi/scsi_transport_sas.h>
60#include <scsi/scsi_dbg.h>
58 61
59#include "mptbase.h" 62#include "mptbase.h"
60#include "mptscsih.h" 63#include "mptscsih.h"
@@ -64,20 +67,19 @@
64#define my_VERSION MPT_LINUX_VERSION_COMMON 67#define my_VERSION MPT_LINUX_VERSION_COMMON
65#define MYNAM "mptsas" 68#define MYNAM "mptsas"
66 69
70/*
71 * Reserved channel for integrated raid
72 */
73#define MPTSAS_RAID_CHANNEL 1
74
67MODULE_AUTHOR(MODULEAUTHOR); 75MODULE_AUTHOR(MODULEAUTHOR);
68MODULE_DESCRIPTION(my_NAME); 76MODULE_DESCRIPTION(my_NAME);
69MODULE_LICENSE("GPL"); 77MODULE_LICENSE("GPL");
70 78
71static int mpt_pq_filter;
72module_param(mpt_pq_filter, int, 0);
73MODULE_PARM_DESC(mpt_pq_filter,
74 "Enable peripheral qualifier filter: enable=1 "
75 "(default=0)");
76
77static int mpt_pt_clear; 79static int mpt_pt_clear;
78module_param(mpt_pt_clear, int, 0); 80module_param(mpt_pt_clear, int, 0);
79MODULE_PARM_DESC(mpt_pt_clear, 81MODULE_PARM_DESC(mpt_pt_clear,
80 "Clear persistency table: enable=1 " 82 " Clear persistency table: enable=1 "
81 "(default=MPTSCSIH_PT_CLEAR=0)"); 83 "(default=MPTSCSIH_PT_CLEAR=0)");
82 84
83static int mptsasDoneCtx = -1; 85static int mptsasDoneCtx = -1;
@@ -137,23 +139,36 @@ struct mptsas_devinfo {
137 u32 device_info; /* bitfield detailed info about this device */ 139 u32 device_info; /* bitfield detailed info about this device */
138}; 140};
139 141
142/*
143 * Specific details on ports, wide/narrow
144 */
145struct mptsas_portinfo_details{
146 u16 num_phys; /* number of phys belong to this port */
147 u64 phy_bitmask; /* TODO, extend support for 255 phys */
148 struct sas_rphy *rphy; /* transport layer rphy object */
149 struct sas_port *port; /* transport layer port object */
150 struct scsi_target *starget;
151 struct mptsas_portinfo *port_info;
152};
153
140struct mptsas_phyinfo { 154struct mptsas_phyinfo {
141 u8 phy_id; /* phy index */ 155 u8 phy_id; /* phy index */
142 u8 port_id; /* port number this phy is part of */ 156 u8 port_id; /* firmware port identifier */
143 u8 negotiated_link_rate; /* nego'd link rate for this phy */ 157 u8 negotiated_link_rate; /* nego'd link rate for this phy */
144 u8 hw_link_rate; /* hardware max/min phys link rate */ 158 u8 hw_link_rate; /* hardware max/min phys link rate */
145 u8 programmed_link_rate; /* programmed max/min phy link rate */ 159 u8 programmed_link_rate; /* programmed max/min phy link rate */
160 u8 sas_port_add_phy; /* flag to request sas_port_add_phy*/
146 struct mptsas_devinfo identify; /* point to phy device info */ 161 struct mptsas_devinfo identify; /* point to phy device info */
147 struct mptsas_devinfo attached; /* point to attached device info */ 162 struct mptsas_devinfo attached; /* point to attached device info */
148 struct sas_phy *phy; 163 struct sas_phy *phy; /* transport layer phy object */
149 struct sas_rphy *rphy; 164 struct mptsas_portinfo *portinfo;
150 struct scsi_target *starget; 165 struct mptsas_portinfo_details * port_details;
151}; 166};
152 167
153struct mptsas_portinfo { 168struct mptsas_portinfo {
154 struct list_head list; 169 struct list_head list;
155 u16 handle; /* unique id to address this */ 170 u16 handle; /* unique id to address this */
156 u8 num_phys; /* number of phys */ 171 u16 num_phys; /* number of phys */
157 struct mptsas_phyinfo *phy_info; 172 struct mptsas_phyinfo *phy_info;
158}; 173};
159 174
@@ -169,7 +184,7 @@ struct mptsas_enclosure {
169 u8 sep_channel; /* SEP channel logical channel id */ 184 u8 sep_channel; /* SEP channel logical channel id */
170}; 185};
171 186
172#ifdef SASDEBUG 187#ifdef MPT_DEBUG_SAS
173static void mptsas_print_phy_data(MPI_SAS_IO_UNIT0_PHY_DATA *phy_data) 188static void mptsas_print_phy_data(MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
174{ 189{
175 printk("---- IO UNIT PAGE 0 ------------\n"); 190 printk("---- IO UNIT PAGE 0 ------------\n");
@@ -305,7 +320,7 @@ mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
305static inline int 320static inline int
306mptsas_is_end_device(struct mptsas_devinfo * attached) 321mptsas_is_end_device(struct mptsas_devinfo * attached)
307{ 322{
308 if ((attached->handle) && 323 if ((attached->sas_address) &&
309 (attached->device_info & 324 (attached->device_info &
310 MPI_SAS_DEVICE_INFO_END_DEVICE) && 325 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
311 ((attached->device_info & 326 ((attached->device_info &
@@ -319,6 +334,247 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
319 return 0; 334 return 0;
320} 335}
321 336
337/* no mutex */
338static void
339mptsas_port_delete(struct mptsas_portinfo_details * port_details)
340{
341 struct mptsas_portinfo *port_info;
342 struct mptsas_phyinfo *phy_info;
343 u8 i;
344
345 if (!port_details)
346 return;
347
348 port_info = port_details->port_info;
349 phy_info = port_info->phy_info;
350
351 dsaswideprintk((KERN_DEBUG "%s: [%p]: num_phys=%02d "
352 "bitmask=0x%016llX\n",
353 __FUNCTION__, port_details, port_details->num_phys,
354 port_details->phy_bitmask));
355
356 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
357 if(phy_info->port_details != port_details)
358 continue;
359 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
360 phy_info->port_details = NULL;
361 }
362 kfree(port_details);
363}
364
365static inline struct sas_rphy *
366mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
367{
368 if (phy_info->port_details)
369 return phy_info->port_details->rphy;
370 else
371 return NULL;
372}
373
374static inline void
375mptsas_set_rphy(struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
376{
377 if (phy_info->port_details) {
378 phy_info->port_details->rphy = rphy;
379 dsaswideprintk((KERN_DEBUG "sas_rphy_add: rphy=%p\n", rphy));
380 }
381
382#ifdef MPT_DEBUG_SAS_WIDE
383 if (rphy) {
384 dev_printk(KERN_DEBUG, &rphy->dev, "add:");
385 printk("rphy=%p release=%p\n",
386 rphy, rphy->dev.release);
387 }
388#endif
389}
390
391static inline struct sas_port *
392mptsas_get_port(struct mptsas_phyinfo *phy_info)
393{
394 if (phy_info->port_details)
395 return phy_info->port_details->port;
396 else
397 return NULL;
398}
399
400static inline void
401mptsas_set_port(struct mptsas_phyinfo *phy_info, struct sas_port *port)
402{
403 if (phy_info->port_details)
404 phy_info->port_details->port = port;
405
406#ifdef MPT_DEBUG_SAS_WIDE
407 if (port) {
408 dev_printk(KERN_DEBUG, &port->dev, "add: ");
409 printk("port=%p release=%p\n",
410 port, port->dev.release);
411 }
412#endif
413}
414
415static inline struct scsi_target *
416mptsas_get_starget(struct mptsas_phyinfo *phy_info)
417{
418 if (phy_info->port_details)
419 return phy_info->port_details->starget;
420 else
421 return NULL;
422}
423
424static inline void
425mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
426starget)
427{
428 if (phy_info->port_details)
429 phy_info->port_details->starget = starget;
430}
431
432
433/*
434 * mptsas_setup_wide_ports
435 *
436 * Updates for new and existing narrow/wide port configuration
437 * in the sas_topology
438 */
439static void
440mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
441{
442 struct mptsas_portinfo_details * port_details;
443 struct mptsas_phyinfo *phy_info, *phy_info_cmp;
444 u64 sas_address;
445 int i, j;
446
447 mutex_lock(&ioc->sas_topology_mutex);
448
449 phy_info = port_info->phy_info;
450 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
451 if (phy_info->attached.handle)
452 continue;
453 port_details = phy_info->port_details;
454 if (!port_details)
455 continue;
456 if (port_details->num_phys < 2)
457 continue;
458 /*
459 * Removing a phy from a port, letting the last
460 * phy be removed by firmware events.
461 */
462 dsaswideprintk((KERN_DEBUG
463 "%s: [%p]: deleting phy = %d\n",
464 __FUNCTION__, port_details, i));
465 port_details->num_phys--;
466 port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
467 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
468 sas_port_delete_phy(port_details->port, phy_info->phy);
469 phy_info->port_details = NULL;
470 }
471
472 /*
473 * Populate and refresh the tree
474 */
475 phy_info = port_info->phy_info;
476 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
477 sas_address = phy_info->attached.sas_address;
478 dsaswideprintk((KERN_DEBUG "phy_id=%d sas_address=0x%018llX\n",
479 i, sas_address));
480 if (!sas_address)
481 continue;
482 port_details = phy_info->port_details;
483 /*
484 * Forming a port
485 */
486 if (!port_details) {
487 port_details = kzalloc(sizeof(*port_details),
488 GFP_KERNEL);
489 if (!port_details)
490 goto out;
491 port_details->num_phys = 1;
492 port_details->port_info = port_info;
493 if (phy_info->phy_id < 64 )
494 port_details->phy_bitmask |=
495 (1 << phy_info->phy_id);
496 phy_info->sas_port_add_phy=1;
497 dsaswideprintk((KERN_DEBUG "\t\tForming port\n\t\t"
498 "phy_id=%d sas_address=0x%018llX\n",
499 i, sas_address));
500 phy_info->port_details = port_details;
501 }
502
503 if (i == port_info->num_phys - 1)
504 continue;
505 phy_info_cmp = &port_info->phy_info[i + 1];
506 for (j = i + 1 ; j < port_info->num_phys ; j++,
507 phy_info_cmp++) {
508 if (!phy_info_cmp->attached.sas_address)
509 continue;
510 if (sas_address != phy_info_cmp->attached.sas_address)
511 continue;
512 if (phy_info_cmp->port_details == port_details )
513 continue;
514 dsaswideprintk((KERN_DEBUG
515 "\t\tphy_id=%d sas_address=0x%018llX\n",
516 j, phy_info_cmp->attached.sas_address));
517 if (phy_info_cmp->port_details) {
518 port_details->rphy =
519 mptsas_get_rphy(phy_info_cmp);
520 port_details->port =
521 mptsas_get_port(phy_info_cmp);
522 port_details->starget =
523 mptsas_get_starget(phy_info_cmp);
524 port_details->num_phys =
525 phy_info_cmp->port_details->num_phys;
526 if (!phy_info_cmp->port_details->num_phys)
527 kfree(phy_info_cmp->port_details);
528 } else
529 phy_info_cmp->sas_port_add_phy=1;
530 /*
531 * Adding a phy to a port
532 */
533 phy_info_cmp->port_details = port_details;
534 if (phy_info_cmp->phy_id < 64 )
535 port_details->phy_bitmask |=
536 (1 << phy_info_cmp->phy_id);
537 port_details->num_phys++;
538 }
539 }
540
541 out:
542
543#ifdef MPT_DEBUG_SAS_WIDE
544 for (i = 0; i < port_info->num_phys; i++) {
545 port_details = port_info->phy_info[i].port_details;
546 if (!port_details)
547 continue;
548 dsaswideprintk((KERN_DEBUG
549 "%s: [%p]: phy_id=%02d num_phys=%02d "
550 "bitmask=0x%016llX\n",
551 __FUNCTION__,
552 port_details, i, port_details->num_phys,
553 port_details->phy_bitmask));
554 dsaswideprintk((KERN_DEBUG"\t\tport = %p rphy=%p\n",
555 port_details->port, port_details->rphy));
556 }
557 dsaswideprintk((KERN_DEBUG"\n"));
558#endif
559 mutex_unlock(&ioc->sas_topology_mutex);
560}
561
562static void
563mptsas_target_reset(MPT_ADAPTER *ioc, VirtTarget * vtarget)
564{
565 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
566
567 if (mptscsih_TMHandler(hd,
568 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
569 vtarget->bus_id, vtarget->target_id, 0, 0, 5) < 0) {
570 hd->tmPending = 0;
571 hd->tmState = TM_STATE_NONE;
572 printk(MYIOC_s_WARN_FMT
573 "Error processing TaskMgmt id=%d TARGET_RESET\n",
574 ioc->name, vtarget->target_id);
575 }
576}
577
322static int 578static int
323mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure, 579mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
324 u32 form, u32 form_specific) 580 u32 form, u32 form_specific)
@@ -387,24 +643,112 @@ mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
387static int 643static int
388mptsas_slave_configure(struct scsi_device *sdev) 644mptsas_slave_configure(struct scsi_device *sdev)
389{ 645{
390 struct Scsi_Host *host = sdev->host;
391 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
392 646
393 /* 647 if (sdev->channel == MPTSAS_RAID_CHANNEL)
394 * RAID volumes placed beyond the last expected port. 648 goto out;
395 * Ignore sending sas mode pages in that case..
396 */
397 if (sdev->channel < hd->ioc->num_ports)
398 sas_read_port_mode_page(sdev);
399 649
650 sas_read_port_mode_page(sdev);
651
652 out:
400 return mptscsih_slave_configure(sdev); 653 return mptscsih_slave_configure(sdev);
401} 654}
402 655
403/* 656static int
404 * This is pretty ugly. We will be able to seriously clean it up 657mptsas_target_alloc(struct scsi_target *starget)
405 * once the DV code in mptscsih goes away and we can properly 658{
406 * implement ->target_alloc. 659 struct Scsi_Host *host = dev_to_shost(&starget->dev);
407 */ 660 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
661 VirtTarget *vtarget;
662 u32 target_id;
663 u32 channel;
664 struct sas_rphy *rphy;
665 struct mptsas_portinfo *p;
666 int i;
667
668 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
669 if (!vtarget)
670 return -ENOMEM;
671
672 vtarget->starget = starget;
673 vtarget->ioc_id = hd->ioc->id;
674 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES|MPT_TARGET_FLAGS_VALID_INQUIRY;
675
676 target_id = starget->id;
677 channel = 0;
678
679 hd->Targets[target_id] = vtarget;
680
681 if (starget->channel == MPTSAS_RAID_CHANNEL)
682 goto out;
683
684 rphy = dev_to_rphy(starget->dev.parent);
685 mutex_lock(&hd->ioc->sas_topology_mutex);
686 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
687 for (i = 0; i < p->num_phys; i++) {
688 if (p->phy_info[i].attached.sas_address !=
689 rphy->identify.sas_address)
690 continue;
691 target_id = p->phy_info[i].attached.id;
692 channel = p->phy_info[i].attached.channel;
693 mptsas_set_starget(&p->phy_info[i], starget);
694
695 /*
696 * Exposing hidden raid components
697 */
698 if (mptscsih_is_phys_disk(hd->ioc, target_id)) {
699 target_id = mptscsih_raid_id_to_num(hd,
700 target_id);
701 vtarget->tflags |=
702 MPT_TARGET_FLAGS_RAID_COMPONENT;
703 }
704 mutex_unlock(&hd->ioc->sas_topology_mutex);
705 goto out;
706 }
707 }
708 mutex_unlock(&hd->ioc->sas_topology_mutex);
709
710 kfree(vtarget);
711 return -ENXIO;
712
713 out:
714 vtarget->target_id = target_id;
715 vtarget->bus_id = channel;
716 starget->hostdata = vtarget;
717 return 0;
718}
719
720static void
721mptsas_target_destroy(struct scsi_target *starget)
722{
723 struct Scsi_Host *host = dev_to_shost(&starget->dev);
724 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
725 struct sas_rphy *rphy;
726 struct mptsas_portinfo *p;
727 int i;
728
729 if (!starget->hostdata)
730 return;
731
732 if (starget->channel == MPTSAS_RAID_CHANNEL)
733 goto out;
734
735 rphy = dev_to_rphy(starget->dev.parent);
736 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
737 for (i = 0; i < p->num_phys; i++) {
738 if (p->phy_info[i].attached.sas_address !=
739 rphy->identify.sas_address)
740 continue;
741 mptsas_set_starget(&p->phy_info[i], NULL);
742 goto out;
743 }
744 }
745
746 out:
747 kfree(starget->hostdata);
748 starget->hostdata = NULL;
749}
750
751
408static int 752static int
409mptsas_slave_alloc(struct scsi_device *sdev) 753mptsas_slave_alloc(struct scsi_device *sdev)
410{ 754{
@@ -412,61 +756,38 @@ mptsas_slave_alloc(struct scsi_device *sdev)
412 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata; 756 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
413 struct sas_rphy *rphy; 757 struct sas_rphy *rphy;
414 struct mptsas_portinfo *p; 758 struct mptsas_portinfo *p;
415 VirtTarget *vtarget;
416 VirtDevice *vdev; 759 VirtDevice *vdev;
417 struct scsi_target *starget; 760 struct scsi_target *starget;
418 u32 target_id; 761 int i;
419 int i;
420 762
421 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL); 763 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
422 if (!vdev) { 764 if (!vdev) {
423 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n", 765 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
424 hd->ioc->name, sizeof(VirtDevice)); 766 hd->ioc->name, sizeof(VirtDevice));
425 return -ENOMEM; 767 return -ENOMEM;
426 } 768 }
427 sdev->hostdata = vdev;
428 starget = scsi_target(sdev); 769 starget = scsi_target(sdev);
429 vtarget = starget->hostdata; 770 vdev->vtarget = starget->hostdata;
430 vtarget->ioc_id = hd->ioc->id;
431 vdev->vtarget = vtarget;
432 if (vtarget->num_luns == 0) {
433 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES|MPT_TARGET_FLAGS_VALID_INQUIRY;
434 hd->Targets[sdev->id] = vtarget;
435 }
436 771
437 /* 772 if (sdev->channel == MPTSAS_RAID_CHANNEL)
438 RAID volumes placed beyond the last expected port.
439 */
440 if (sdev->channel == hd->ioc->num_ports) {
441 target_id = sdev->id;
442 vtarget->bus_id = 0;
443 vdev->lun = 0;
444 goto out; 773 goto out;
445 }
446 774
447 rphy = dev_to_rphy(sdev->sdev_target->dev.parent); 775 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
448 mutex_lock(&hd->ioc->sas_topology_mutex); 776 mutex_lock(&hd->ioc->sas_topology_mutex);
449 list_for_each_entry(p, &hd->ioc->sas_topology, list) { 777 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
450 for (i = 0; i < p->num_phys; i++) { 778 for (i = 0; i < p->num_phys; i++) {
451 if (p->phy_info[i].attached.sas_address == 779 if (p->phy_info[i].attached.sas_address !=
452 rphy->identify.sas_address) { 780 rphy->identify.sas_address)
453 target_id = p->phy_info[i].attached.id; 781 continue;
454 vtarget->bus_id = p->phy_info[i].attached.channel; 782 vdev->lun = sdev->lun;
455 vdev->lun = sdev->lun; 783 /*
456 p->phy_info[i].starget = sdev->sdev_target; 784 * Exposing hidden raid components
457 /* 785 */
458 * Exposing hidden disk (RAID) 786 if (mptscsih_is_phys_disk(hd->ioc,
459 */ 787 p->phy_info[i].attached.id))
460 if (mptscsih_is_phys_disk(hd->ioc, target_id)) { 788 sdev->no_uld_attach = 1;
461 target_id = mptscsih_raid_id_to_num(hd, 789 mutex_unlock(&hd->ioc->sas_topology_mutex);
462 target_id); 790 goto out;
463 vdev->vtarget->tflags |=
464 MPT_TARGET_FLAGS_RAID_COMPONENT;
465 sdev->no_uld_attach = 1;
466 }
467 mutex_unlock(&hd->ioc->sas_topology_mutex);
468 goto out;
469 }
470 } 791 }
471 } 792 }
472 mutex_unlock(&hd->ioc->sas_topology_mutex); 793 mutex_unlock(&hd->ioc->sas_topology_mutex);
@@ -475,57 +796,39 @@ mptsas_slave_alloc(struct scsi_device *sdev)
475 return -ENXIO; 796 return -ENXIO;
476 797
477 out: 798 out:
478 vtarget->target_id = target_id; 799 vdev->vtarget->num_luns++;
479 vtarget->num_luns++; 800 sdev->hostdata = vdev;
480 return 0; 801 return 0;
481} 802}
482 803
483static void 804static int
484mptsas_slave_destroy(struct scsi_device *sdev) 805mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
485{ 806{
486 struct Scsi_Host *host = sdev->host; 807 VirtDevice *vdev = SCpnt->device->hostdata;
487 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
488 VirtDevice *vdev;
489
490 /*
491 * Issue target reset to flush firmware outstanding commands.
492 */
493 vdev = sdev->hostdata;
494 if (vdev->configured_lun){
495 if (mptscsih_TMHandler(hd,
496 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
497 vdev->vtarget->bus_id,
498 vdev->vtarget->target_id,
499 0, 0, 5 /* 5 second timeout */)
500 < 0){
501
502 /* The TM request failed!
503 * Fatal error case.
504 */
505 printk(MYIOC_s_WARN_FMT
506 "Error processing TaskMgmt id=%d TARGET_RESET\n",
507 hd->ioc->name,
508 vdev->vtarget->target_id);
509 808
510 hd->tmPending = 0; 809// scsi_print_command(SCpnt);
511 hd->tmState = TM_STATE_NONE; 810 if (vdev->vtarget->deleted) {
512 } 811 SCpnt->result = DID_NO_CONNECT << 16;
812 done(SCpnt);
813 return 0;
513 } 814 }
514 mptscsih_slave_destroy(sdev); 815
816 return mptscsih_qcmd(SCpnt,done);
515} 817}
516 818
819
517static struct scsi_host_template mptsas_driver_template = { 820static struct scsi_host_template mptsas_driver_template = {
518 .module = THIS_MODULE, 821 .module = THIS_MODULE,
519 .proc_name = "mptsas", 822 .proc_name = "mptsas",
520 .proc_info = mptscsih_proc_info, 823 .proc_info = mptscsih_proc_info,
521 .name = "MPT SPI Host", 824 .name = "MPT SPI Host",
522 .info = mptscsih_info, 825 .info = mptscsih_info,
523 .queuecommand = mptscsih_qcmd, 826 .queuecommand = mptsas_qcmd,
524 .target_alloc = mptscsih_target_alloc, 827 .target_alloc = mptsas_target_alloc,
525 .slave_alloc = mptsas_slave_alloc, 828 .slave_alloc = mptsas_slave_alloc,
526 .slave_configure = mptsas_slave_configure, 829 .slave_configure = mptsas_slave_configure,
527 .target_destroy = mptscsih_target_destroy, 830 .target_destroy = mptsas_target_destroy,
528 .slave_destroy = mptsas_slave_destroy, 831 .slave_destroy = mptscsih_slave_destroy,
529 .change_queue_depth = mptscsih_change_queue_depth, 832 .change_queue_depth = mptscsih_change_queue_depth,
530 .eh_abort_handler = mptscsih_abort, 833 .eh_abort_handler = mptscsih_abort,
531 .eh_device_reset_handler = mptscsih_dev_reset, 834 .eh_device_reset_handler = mptscsih_dev_reset,
@@ -795,7 +1098,7 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
795 1098
796 port_info->num_phys = buffer->NumPhys; 1099 port_info->num_phys = buffer->NumPhys;
797 port_info->phy_info = kcalloc(port_info->num_phys, 1100 port_info->phy_info = kcalloc(port_info->num_phys,
798 sizeof(struct mptsas_phyinfo),GFP_KERNEL); 1101 sizeof(*port_info->phy_info),GFP_KERNEL);
799 if (!port_info->phy_info) { 1102 if (!port_info->phy_info) {
800 error = -ENOMEM; 1103 error = -ENOMEM;
801 goto out_free_consistent; 1104 goto out_free_consistent;
@@ -811,6 +1114,7 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
811 buffer->PhyData[i].Port; 1114 buffer->PhyData[i].Port;
812 port_info->phy_info[i].negotiated_link_rate = 1115 port_info->phy_info[i].negotiated_link_rate =
813 buffer->PhyData[i].NegotiatedLinkRate; 1116 buffer->PhyData[i].NegotiatedLinkRate;
1117 port_info->phy_info[i].portinfo = port_info;
814 } 1118 }
815 1119
816 out_free_consistent: 1120 out_free_consistent:
@@ -968,7 +1272,7 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
968 CONFIGPARMS cfg; 1272 CONFIGPARMS cfg;
969 SasExpanderPage0_t *buffer; 1273 SasExpanderPage0_t *buffer;
970 dma_addr_t dma_handle; 1274 dma_addr_t dma_handle;
971 int error; 1275 int i, error;
972 1276
973 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION; 1277 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
974 hdr.ExtPageLength = 0; 1278 hdr.ExtPageLength = 0;
@@ -1013,12 +1317,15 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
1013 port_info->num_phys = buffer->NumPhys; 1317 port_info->num_phys = buffer->NumPhys;
1014 port_info->handle = le16_to_cpu(buffer->DevHandle); 1318 port_info->handle = le16_to_cpu(buffer->DevHandle);
1015 port_info->phy_info = kcalloc(port_info->num_phys, 1319 port_info->phy_info = kcalloc(port_info->num_phys,
1016 sizeof(struct mptsas_phyinfo),GFP_KERNEL); 1320 sizeof(*port_info->phy_info),GFP_KERNEL);
1017 if (!port_info->phy_info) { 1321 if (!port_info->phy_info) {
1018 error = -ENOMEM; 1322 error = -ENOMEM;
1019 goto out_free_consistent; 1323 goto out_free_consistent;
1020 } 1324 }
1021 1325
1326 for (i = 0; i < port_info->num_phys; i++)
1327 port_info->phy_info[i].portinfo = port_info;
1328
1022 out_free_consistent: 1329 out_free_consistent:
1023 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 1330 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1024 buffer, dma_handle); 1331 buffer, dma_handle);
@@ -1161,19 +1468,23 @@ static int mptsas_probe_one_phy(struct device *dev,
1161{ 1468{
1162 MPT_ADAPTER *ioc; 1469 MPT_ADAPTER *ioc;
1163 struct sas_phy *phy; 1470 struct sas_phy *phy;
1164 int error; 1471 struct sas_port *port;
1472 int error = 0;
1165 1473
1166 if (!dev) 1474 if (!dev) {
1167 return -ENODEV; 1475 error = -ENODEV;
1476 goto out;
1477 }
1168 1478
1169 if (!phy_info->phy) { 1479 if (!phy_info->phy) {
1170 phy = sas_phy_alloc(dev, index); 1480 phy = sas_phy_alloc(dev, index);
1171 if (!phy) 1481 if (!phy) {
1172 return -ENOMEM; 1482 error = -ENOMEM;
1483 goto out;
1484 }
1173 } else 1485 } else
1174 phy = phy_info->phy; 1486 phy = phy_info->phy;
1175 1487
1176 phy->port_identifier = phy_info->port_id;
1177 mptsas_parse_device_info(&phy->identify, &phy_info->identify); 1488 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
1178 1489
1179 /* 1490 /*
@@ -1265,19 +1576,51 @@ static int mptsas_probe_one_phy(struct device *dev,
1265 error = sas_phy_add(phy); 1576 error = sas_phy_add(phy);
1266 if (error) { 1577 if (error) {
1267 sas_phy_free(phy); 1578 sas_phy_free(phy);
1268 return error; 1579 goto out;
1269 } 1580 }
1270 phy_info->phy = phy; 1581 phy_info->phy = phy;
1271 } 1582 }
1272 1583
1273 if ((phy_info->attached.handle) && 1584 if (!phy_info->attached.handle ||
1274 (!phy_info->rphy)) { 1585 !phy_info->port_details)
1586 goto out;
1587
1588 port = mptsas_get_port(phy_info);
1589 ioc = phy_to_ioc(phy_info->phy);
1590
1591 if (phy_info->sas_port_add_phy) {
1592
1593 if (!port) {
1594 port = sas_port_alloc_num(dev);
1595 if (!port) {
1596 error = -ENOMEM;
1597 goto out;
1598 }
1599 error = sas_port_add(port);
1600 if (error) {
1601 dfailprintk((MYIOC_s_ERR_FMT
1602 "%s: exit at line=%d\n", ioc->name,
1603 __FUNCTION__, __LINE__));
1604 goto out;
1605 }
1606 mptsas_set_port(phy_info, port);
1607 dsaswideprintk((KERN_DEBUG
1608 "sas_port_alloc: port=%p dev=%p port_id=%d\n",
1609 port, dev, port->port_identifier));
1610 }
1611 dsaswideprintk((KERN_DEBUG "sas_port_add_phy: phy_id=%d\n",
1612 phy_info->phy_id));
1613 sas_port_add_phy(port, phy_info->phy);
1614 phy_info->sas_port_add_phy = 0;
1615 }
1616
1617 if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
1275 1618
1276 struct sas_rphy *rphy; 1619 struct sas_rphy *rphy;
1620 struct device *parent;
1277 struct sas_identify identify; 1621 struct sas_identify identify;
1278 1622
1279 ioc = phy_to_ioc(phy_info->phy); 1623 parent = dev->parent->parent;
1280
1281 /* 1624 /*
1282 * Let the hotplug_work thread handle processing 1625 * Let the hotplug_work thread handle processing
1283 * the adding/removing of devices that occur 1626 * the adding/removing of devices that occur
@@ -1285,36 +1628,63 @@ static int mptsas_probe_one_phy(struct device *dev,
1285 */ 1628 */
1286 if (ioc->sas_discovery_runtime && 1629 if (ioc->sas_discovery_runtime &&
1287 mptsas_is_end_device(&phy_info->attached)) 1630 mptsas_is_end_device(&phy_info->attached))
1288 return 0; 1631 goto out;
1289 1632
1290 mptsas_parse_device_info(&identify, &phy_info->attached); 1633 mptsas_parse_device_info(&identify, &phy_info->attached);
1634 if (scsi_is_host_device(parent)) {
1635 struct mptsas_portinfo *port_info;
1636 int i;
1637
1638 mutex_lock(&ioc->sas_topology_mutex);
1639 port_info = mptsas_find_portinfo_by_handle(ioc,
1640 ioc->handle);
1641 mutex_unlock(&ioc->sas_topology_mutex);
1642
1643 for (i = 0; i < port_info->num_phys; i++)
1644 if (port_info->phy_info[i].identify.sas_address ==
1645 identify.sas_address)
1646 goto out;
1647
1648 } else if (scsi_is_sas_rphy(parent)) {
1649 struct sas_rphy *parent_rphy = dev_to_rphy(parent);
1650 if (identify.sas_address ==
1651 parent_rphy->identify.sas_address)
1652 goto out;
1653 }
1654
1291 switch (identify.device_type) { 1655 switch (identify.device_type) {
1292 case SAS_END_DEVICE: 1656 case SAS_END_DEVICE:
1293 rphy = sas_end_device_alloc(phy); 1657 rphy = sas_end_device_alloc(port);
1294 break; 1658 break;
1295 case SAS_EDGE_EXPANDER_DEVICE: 1659 case SAS_EDGE_EXPANDER_DEVICE:
1296 case SAS_FANOUT_EXPANDER_DEVICE: 1660 case SAS_FANOUT_EXPANDER_DEVICE:
1297 rphy = sas_expander_alloc(phy, identify.device_type); 1661 rphy = sas_expander_alloc(port, identify.device_type);
1298 break; 1662 break;
1299 default: 1663 default:
1300 rphy = NULL; 1664 rphy = NULL;
1301 break; 1665 break;
1302 } 1666 }
1303 if (!rphy) 1667 if (!rphy) {
1304 return 0; /* non-fatal: an rphy can be added later */ 1668 dfailprintk((MYIOC_s_ERR_FMT
1669 "%s: exit at line=%d\n", ioc->name,
1670 __FUNCTION__, __LINE__));
1671 goto out;
1672 }
1305 1673
1306 rphy->identify = identify; 1674 rphy->identify = identify;
1307
1308 error = sas_rphy_add(rphy); 1675 error = sas_rphy_add(rphy);
1309 if (error) { 1676 if (error) {
1677 dfailprintk((MYIOC_s_ERR_FMT
1678 "%s: exit at line=%d\n", ioc->name,
1679 __FUNCTION__, __LINE__));
1310 sas_rphy_free(rphy); 1680 sas_rphy_free(rphy);
1311 return error; 1681 goto out;
1312 } 1682 }
1313 1683 mptsas_set_rphy(phy_info, rphy);
1314 phy_info->rphy = rphy;
1315 } 1684 }
1316 1685
1317 return 0; 1686 out:
1687 return error;
1318} 1688}
1319 1689
1320static int 1690static int
@@ -1333,6 +1703,7 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1333 goto out_free_port_info; 1703 goto out_free_port_info;
1334 1704
1335 mutex_lock(&ioc->sas_topology_mutex); 1705 mutex_lock(&ioc->sas_topology_mutex);
1706 ioc->handle = hba->handle;
1336 port_info = mptsas_find_portinfo_by_handle(ioc, hba->handle); 1707 port_info = mptsas_find_portinfo_by_handle(ioc, hba->handle);
1337 if (!port_info) { 1708 if (!port_info) {
1338 port_info = hba; 1709 port_info = hba;
@@ -1342,13 +1713,11 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1342 for (i = 0; i < hba->num_phys; i++) 1713 for (i = 0; i < hba->num_phys; i++)
1343 port_info->phy_info[i].negotiated_link_rate = 1714 port_info->phy_info[i].negotiated_link_rate =
1344 hba->phy_info[i].negotiated_link_rate; 1715 hba->phy_info[i].negotiated_link_rate;
1345 if (hba->phy_info) 1716 kfree(hba->phy_info);
1346 kfree(hba->phy_info);
1347 kfree(hba); 1717 kfree(hba);
1348 hba = NULL; 1718 hba = NULL;
1349 } 1719 }
1350 mutex_unlock(&ioc->sas_topology_mutex); 1720 mutex_unlock(&ioc->sas_topology_mutex);
1351 ioc->num_ports = port_info->num_phys;
1352 1721
1353 for (i = 0; i < port_info->num_phys; i++) { 1722 for (i = 0; i < port_info->num_phys; i++) {
1354 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i], 1723 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
@@ -1362,18 +1731,19 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1362 port_info->phy_info[i].phy_id; 1731 port_info->phy_info[i].phy_id;
1363 handle = port_info->phy_info[i].identify.handle; 1732 handle = port_info->phy_info[i].identify.handle;
1364 1733
1365 if (port_info->phy_info[i].attached.handle) { 1734 if (port_info->phy_info[i].attached.handle)
1366 mptsas_sas_device_pg0(ioc, 1735 mptsas_sas_device_pg0(ioc,
1367 &port_info->phy_info[i].attached, 1736 &port_info->phy_info[i].attached,
1368 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << 1737 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1369 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 1738 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1370 port_info->phy_info[i].attached.handle); 1739 port_info->phy_info[i].attached.handle);
1371 } 1740 }
1372 1741
1742 mptsas_setup_wide_ports(ioc, port_info);
1743
1744 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
1373 mptsas_probe_one_phy(&ioc->sh->shost_gendev, 1745 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
1374 &port_info->phy_info[i], ioc->sas_index, 1); 1746 &port_info->phy_info[i], ioc->sas_index, 1);
1375 ioc->sas_index++;
1376 }
1377 1747
1378 return 0; 1748 return 0;
1379 1749
@@ -1387,6 +1757,8 @@ static int
1387mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle) 1757mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1388{ 1758{
1389 struct mptsas_portinfo *port_info, *p, *ex; 1759 struct mptsas_portinfo *port_info, *p, *ex;
1760 struct device *parent;
1761 struct sas_rphy *rphy;
1390 int error = -ENOMEM, i, j; 1762 int error = -ENOMEM, i, j;
1391 1763
1392 ex = kzalloc(sizeof(*port_info), GFP_KERNEL); 1764 ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
@@ -1408,16 +1780,13 @@ mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1408 list_add_tail(&port_info->list, &ioc->sas_topology); 1780 list_add_tail(&port_info->list, &ioc->sas_topology);
1409 } else { 1781 } else {
1410 port_info->handle = ex->handle; 1782 port_info->handle = ex->handle;
1411 if (ex->phy_info) 1783 kfree(ex->phy_info);
1412 kfree(ex->phy_info);
1413 kfree(ex); 1784 kfree(ex);
1414 ex = NULL; 1785 ex = NULL;
1415 } 1786 }
1416 mutex_unlock(&ioc->sas_topology_mutex); 1787 mutex_unlock(&ioc->sas_topology_mutex);
1417 1788
1418 for (i = 0; i < port_info->num_phys; i++) { 1789 for (i = 0; i < port_info->num_phys; i++) {
1419 struct device *parent;
1420
1421 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i], 1790 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
1422 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM << 1791 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
1423 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle); 1792 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle);
@@ -1441,34 +1810,34 @@ mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1441 port_info->phy_info[i].attached.phy_id = 1810 port_info->phy_info[i].attached.phy_id =
1442 port_info->phy_info[i].phy_id; 1811 port_info->phy_info[i].phy_id;
1443 } 1812 }
1813 }
1444 1814
1445 /* 1815 parent = &ioc->sh->shost_gendev;
1446 * If we find a parent port handle this expander is 1816 for (i = 0; i < port_info->num_phys; i++) {
1447 * attached to another expander, else it hangs of the
1448 * HBA phys.
1449 */
1450 parent = &ioc->sh->shost_gendev;
1451 mutex_lock(&ioc->sas_topology_mutex); 1817 mutex_lock(&ioc->sas_topology_mutex);
1452 list_for_each_entry(p, &ioc->sas_topology, list) { 1818 list_for_each_entry(p, &ioc->sas_topology, list) {
1453 for (j = 0; j < p->num_phys; j++) { 1819 for (j = 0; j < p->num_phys; j++) {
1454 if (port_info->phy_info[i].identify.handle == 1820 if (port_info->phy_info[i].identify.handle !=
1455 p->phy_info[j].attached.handle) 1821 p->phy_info[j].attached.handle)
1456 parent = &p->phy_info[j].rphy->dev; 1822 continue;
1823 rphy = mptsas_get_rphy(&p->phy_info[j]);
1824 parent = &rphy->dev;
1457 } 1825 }
1458 } 1826 }
1459 mutex_unlock(&ioc->sas_topology_mutex); 1827 mutex_unlock(&ioc->sas_topology_mutex);
1828 }
1460 1829
1830 mptsas_setup_wide_ports(ioc, port_info);
1831
1832 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
1461 mptsas_probe_one_phy(parent, &port_info->phy_info[i], 1833 mptsas_probe_one_phy(parent, &port_info->phy_info[i],
1462 ioc->sas_index, 0); 1834 ioc->sas_index, 0);
1463 ioc->sas_index++;
1464 }
1465 1835
1466 return 0; 1836 return 0;
1467 1837
1468 out_free_port_info: 1838 out_free_port_info:
1469 if (ex) { 1839 if (ex) {
1470 if (ex->phy_info) 1840 kfree(ex->phy_info);
1471 kfree(ex->phy_info);
1472 kfree(ex); 1841 kfree(ex);
1473 } 1842 }
1474 out: 1843 out:
@@ -1487,7 +1856,12 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1487{ 1856{
1488 struct mptsas_portinfo buffer; 1857 struct mptsas_portinfo buffer;
1489 struct mptsas_portinfo *port_info, *n, *parent; 1858 struct mptsas_portinfo *port_info, *n, *parent;
1859 struct mptsas_phyinfo *phy_info;
1860 struct scsi_target * starget;
1861 VirtTarget * vtarget;
1862 struct sas_port * port;
1490 int i; 1863 int i;
1864 u64 expander_sas_address;
1491 1865
1492 mutex_lock(&ioc->sas_topology_mutex); 1866 mutex_lock(&ioc->sas_topology_mutex);
1493 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) { 1867 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
@@ -1502,6 +1876,25 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1502 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) { 1876 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) {
1503 1877
1504 /* 1878 /*
1879 * Issue target reset to all child end devices
1880 * then mark them deleted to prevent further
1881 * IO going to them.
1882 */
1883 phy_info = port_info->phy_info;
1884 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
1885 starget = mptsas_get_starget(phy_info);
1886 if (!starget)
1887 continue;
1888 vtarget = starget->hostdata;
1889 if(vtarget->deleted)
1890 continue;
1891 vtarget->deleted = 1;
1892 mptsas_target_reset(ioc, vtarget);
1893 sas_port_delete(mptsas_get_port(phy_info));
1894 mptsas_port_delete(phy_info->port_details);
1895 }
1896
1897 /*
1505 * Obtain the port_info instance to the parent port 1898 * Obtain the port_info instance to the parent port
1506 */ 1899 */
1507 parent = mptsas_find_portinfo_by_handle(ioc, 1900 parent = mptsas_find_portinfo_by_handle(ioc,
@@ -1510,34 +1903,44 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1510 if (!parent) 1903 if (!parent)
1511 goto next_port; 1904 goto next_port;
1512 1905
1906 expander_sas_address =
1907 port_info->phy_info[0].identify.sas_address;
1908
1513 /* 1909 /*
1514 * Delete rphys in the parent that point 1910 * Delete rphys in the parent that point
1515 * to this expander. The transport layer will 1911 * to this expander. The transport layer will
1516 * cleanup all the children. 1912 * cleanup all the children.
1517 */ 1913 */
1518 for (i = 0; i < parent->num_phys; i++) { 1914 phy_info = parent->phy_info;
1519 if ((!parent->phy_info[i].rphy) || 1915 for (i = 0; i < parent->num_phys; i++, phy_info++) {
1520 (parent->phy_info[i].attached.sas_address != 1916 port = mptsas_get_port(phy_info);
1521 port_info->phy_info[i].identify.sas_address)) 1917 if (!port)
1522 continue; 1918 continue;
1523 sas_rphy_delete(parent->phy_info[i].rphy); 1919 if (phy_info->attached.sas_address !=
1524 memset(&parent->phy_info[i].attached, 0, 1920 expander_sas_address)
1525 sizeof(struct mptsas_devinfo)); 1921 continue;
1526 parent->phy_info[i].rphy = NULL; 1922#ifdef MPT_DEBUG_SAS_WIDE
1527 parent->phy_info[i].starget = NULL; 1923 dev_printk(KERN_DEBUG, &port->dev,
1924 "delete port (%d)\n", port->port_identifier);
1925#endif
1926 sas_port_delete(port);
1927 mptsas_port_delete(phy_info->port_details);
1528 } 1928 }
1529 next_port: 1929 next_port:
1930
1931 phy_info = port_info->phy_info;
1932 for (i = 0; i < port_info->num_phys; i++, phy_info++)
1933 mptsas_port_delete(phy_info->port_details);
1934
1530 list_del(&port_info->list); 1935 list_del(&port_info->list);
1531 if (port_info->phy_info) 1936 kfree(port_info->phy_info);
1532 kfree(port_info->phy_info);
1533 kfree(port_info); 1937 kfree(port_info);
1534 } 1938 }
1535 /* 1939 /*
1536 * Free this memory allocated from inside 1940 * Free this memory allocated from inside
1537 * mptsas_sas_expander_pg0 1941 * mptsas_sas_expander_pg0
1538 */ 1942 */
1539 if (buffer.phy_info) 1943 kfree(buffer.phy_info);
1540 kfree(buffer.phy_info);
1541 } 1944 }
1542 mutex_unlock(&ioc->sas_topology_mutex); 1945 mutex_unlock(&ioc->sas_topology_mutex);
1543} 1946}
@@ -1563,7 +1966,7 @@ mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
1563 if (!ioc->raid_data.pIocPg2->NumActiveVolumes) 1966 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
1564 goto out; 1967 goto out;
1565 for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++) { 1968 for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1566 scsi_add_device(ioc->sh, ioc->num_ports, 1969 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
1567 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0); 1970 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
1568 } 1971 }
1569 out: 1972 out:
@@ -1573,60 +1976,59 @@ mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
1573/* 1976/*
1574 * Work queue thread to handle Runtime discovery 1977 * Work queue thread to handle Runtime discovery
1575 * Mere purpose is the hot add/delete of expanders 1978 * Mere purpose is the hot add/delete of expanders
1979 *(Mutex UNLOCKED)
1576 */ 1980 */
1577static void 1981static void
1578mptscsih_discovery_work(void * arg) 1982__mptsas_discovery_work(MPT_ADAPTER *ioc)
1579{ 1983{
1580 struct mptsas_discovery_event *ev = arg;
1581 MPT_ADAPTER *ioc = ev->ioc;
1582 u32 handle = 0xFFFF; 1984 u32 handle = 0xFFFF;
1583 1985
1584 mutex_lock(&ioc->sas_discovery_mutex);
1585 ioc->sas_discovery_runtime=1; 1986 ioc->sas_discovery_runtime=1;
1586 mptsas_delete_expander_phys(ioc); 1987 mptsas_delete_expander_phys(ioc);
1587 mptsas_probe_hba_phys(ioc); 1988 mptsas_probe_hba_phys(ioc);
1588 while (!mptsas_probe_expander_phys(ioc, &handle)) 1989 while (!mptsas_probe_expander_phys(ioc, &handle))
1589 ; 1990 ;
1590 kfree(ev);
1591 ioc->sas_discovery_runtime=0; 1991 ioc->sas_discovery_runtime=0;
1992}
1993
1994/*
1995 * Work queue thread to handle Runtime discovery
1996 * Mere purpose is the hot add/delete of expanders
1997 *(Mutex LOCKED)
1998 */
1999static void
2000mptsas_discovery_work(void * arg)
2001{
2002 struct mptsas_discovery_event *ev = arg;
2003 MPT_ADAPTER *ioc = ev->ioc;
2004
2005 mutex_lock(&ioc->sas_discovery_mutex);
2006 __mptsas_discovery_work(ioc);
1592 mutex_unlock(&ioc->sas_discovery_mutex); 2007 mutex_unlock(&ioc->sas_discovery_mutex);
2008 kfree(ev);
1593} 2009}
1594 2010
1595static struct mptsas_phyinfo * 2011static struct mptsas_phyinfo *
1596mptsas_find_phyinfo_by_parent(MPT_ADAPTER *ioc, u16 parent_handle, u8 phy_id) 2012mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
1597{ 2013{
1598 struct mptsas_portinfo *port_info; 2014 struct mptsas_portinfo *port_info;
1599 struct mptsas_devinfo device_info;
1600 struct mptsas_phyinfo *phy_info = NULL; 2015 struct mptsas_phyinfo *phy_info = NULL;
1601 int i, error; 2016 int i;
1602
1603 /*
1604 * Retrieve the parent sas_address
1605 */
1606 error = mptsas_sas_device_pg0(ioc, &device_info,
1607 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1608 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1609 parent_handle);
1610 if (error)
1611 return NULL;
1612 2017
1613 /*
1614 * The phy_info structures are never deallocated during lifetime of
1615 * a host, so the code below is safe without additional refcounting.
1616 */
1617 mutex_lock(&ioc->sas_topology_mutex); 2018 mutex_lock(&ioc->sas_topology_mutex);
1618 list_for_each_entry(port_info, &ioc->sas_topology, list) { 2019 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1619 for (i = 0; i < port_info->num_phys; i++) { 2020 for (i = 0; i < port_info->num_phys; i++) {
1620 if (port_info->phy_info[i].identify.sas_address == 2021 if (port_info->phy_info[i].attached.sas_address
1621 device_info.sas_address && 2022 != sas_address)
1622 port_info->phy_info[i].phy_id == phy_id) { 2023 continue;
1623 phy_info = &port_info->phy_info[i]; 2024 if (!mptsas_is_end_device(
1624 break; 2025 &port_info->phy_info[i].attached))
1625 } 2026 continue;
2027 phy_info = &port_info->phy_info[i];
2028 break;
1626 } 2029 }
1627 } 2030 }
1628 mutex_unlock(&ioc->sas_topology_mutex); 2031 mutex_unlock(&ioc->sas_topology_mutex);
1629
1630 return phy_info; 2032 return phy_info;
1631} 2033}
1632 2034
@@ -1637,21 +2039,19 @@ mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
1637 struct mptsas_phyinfo *phy_info = NULL; 2039 struct mptsas_phyinfo *phy_info = NULL;
1638 int i; 2040 int i;
1639 2041
1640 /*
1641 * The phy_info structures are never deallocated during lifetime of
1642 * a host, so the code below is safe without additional refcounting.
1643 */
1644 mutex_lock(&ioc->sas_topology_mutex); 2042 mutex_lock(&ioc->sas_topology_mutex);
1645 list_for_each_entry(port_info, &ioc->sas_topology, list) { 2043 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1646 for (i = 0; i < port_info->num_phys; i++) 2044 for (i = 0; i < port_info->num_phys; i++) {
1647 if (mptsas_is_end_device(&port_info->phy_info[i].attached)) 2045 if (port_info->phy_info[i].attached.id != id)
1648 if (port_info->phy_info[i].attached.id == id) { 2046 continue;
1649 phy_info = &port_info->phy_info[i]; 2047 if (!mptsas_is_end_device(
1650 break; 2048 &port_info->phy_info[i].attached))
1651 } 2049 continue;
2050 phy_info = &port_info->phy_info[i];
2051 break;
2052 }
1652 } 2053 }
1653 mutex_unlock(&ioc->sas_topology_mutex); 2054 mutex_unlock(&ioc->sas_topology_mutex);
1654
1655 return phy_info; 2055 return phy_info;
1656} 2056}
1657 2057
@@ -1659,7 +2059,7 @@ mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
1659 * Work queue thread to clear the persitency table 2059 * Work queue thread to clear the persitency table
1660 */ 2060 */
1661static void 2061static void
1662mptscsih_sas_persist_clear_table(void * arg) 2062mptsas_persist_clear_table(void * arg)
1663{ 2063{
1664 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg; 2064 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
1665 2065
@@ -1680,7 +2080,6 @@ mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
1680 mptsas_reprobe_lun); 2080 mptsas_reprobe_lun);
1681} 2081}
1682 2082
1683
1684/* 2083/*
1685 * Work queue thread to handle SAS hotplug events 2084 * Work queue thread to handle SAS hotplug events
1686 */ 2085 */
@@ -1691,14 +2090,17 @@ mptsas_hotplug_work(void *arg)
1691 MPT_ADAPTER *ioc = ev->ioc; 2090 MPT_ADAPTER *ioc = ev->ioc;
1692 struct mptsas_phyinfo *phy_info; 2091 struct mptsas_phyinfo *phy_info;
1693 struct sas_rphy *rphy; 2092 struct sas_rphy *rphy;
2093 struct sas_port *port;
1694 struct scsi_device *sdev; 2094 struct scsi_device *sdev;
2095 struct scsi_target * starget;
1695 struct sas_identify identify; 2096 struct sas_identify identify;
1696 char *ds = NULL; 2097 char *ds = NULL;
1697 struct mptsas_devinfo sas_device; 2098 struct mptsas_devinfo sas_device;
1698 VirtTarget *vtarget; 2099 VirtTarget *vtarget;
2100 VirtDevice *vdevice;
1699 2101
1700 mutex_lock(&ioc->sas_discovery_mutex);
1701 2102
2103 mutex_lock(&ioc->sas_discovery_mutex);
1702 switch (ev->event_type) { 2104 switch (ev->event_type) {
1703 case MPTSAS_DEL_DEVICE: 2105 case MPTSAS_DEL_DEVICE:
1704 2106
@@ -1707,24 +2109,50 @@ mptsas_hotplug_work(void *arg)
1707 /* 2109 /*
1708 * Sanity checks, for non-existing phys and remote rphys. 2110 * Sanity checks, for non-existing phys and remote rphys.
1709 */ 2111 */
1710 if (!phy_info) 2112 if (!phy_info || !phy_info->port_details) {
2113 dfailprintk((MYIOC_s_ERR_FMT
2114 "%s: exit at line=%d\n", ioc->name,
2115 __FUNCTION__, __LINE__));
1711 break; 2116 break;
1712 if (!phy_info->rphy) 2117 }
2118 rphy = mptsas_get_rphy(phy_info);
2119 if (!rphy) {
2120 dfailprintk((MYIOC_s_ERR_FMT
2121 "%s: exit at line=%d\n", ioc->name,
2122 __FUNCTION__, __LINE__));
1713 break; 2123 break;
1714 if (phy_info->starget) { 2124 }
1715 vtarget = phy_info->starget->hostdata; 2125 port = mptsas_get_port(phy_info);
2126 if (!port) {
2127 dfailprintk((MYIOC_s_ERR_FMT
2128 "%s: exit at line=%d\n", ioc->name,
2129 __FUNCTION__, __LINE__));
2130 break;
2131 }
1716 2132
1717 if (!vtarget) 2133 starget = mptsas_get_starget(phy_info);
2134 if (starget) {
2135 vtarget = starget->hostdata;
2136
2137 if (!vtarget) {
2138 dfailprintk((MYIOC_s_ERR_FMT
2139 "%s: exit at line=%d\n", ioc->name,
2140 __FUNCTION__, __LINE__));
1718 break; 2141 break;
2142 }
2143
1719 /* 2144 /*
1720 * Handling RAID components 2145 * Handling RAID components
1721 */ 2146 */
1722 if (ev->phys_disk_num_valid) { 2147 if (ev->phys_disk_num_valid) {
1723 vtarget->target_id = ev->phys_disk_num; 2148 vtarget->target_id = ev->phys_disk_num;
1724 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT; 2149 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
1725 mptsas_reprobe_target(vtarget->starget, 1); 2150 mptsas_reprobe_target(starget, 1);
1726 break; 2151 break;
1727 } 2152 }
2153
2154 vtarget->deleted = 1;
2155 mptsas_target_reset(ioc, vtarget);
1728 } 2156 }
1729 2157
1730 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET) 2158 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET)
@@ -1738,10 +2166,12 @@ mptsas_hotplug_work(void *arg)
1738 "removing %s device, channel %d, id %d, phy %d\n", 2166 "removing %s device, channel %d, id %d, phy %d\n",
1739 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id); 2167 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
1740 2168
1741 sas_rphy_delete(phy_info->rphy); 2169#ifdef MPT_DEBUG_SAS_WIDE
1742 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo)); 2170 dev_printk(KERN_DEBUG, &port->dev,
1743 phy_info->rphy = NULL; 2171 "delete port (%d)\n", port->port_identifier);
1744 phy_info->starget = NULL; 2172#endif
2173 sas_port_delete(port);
2174 mptsas_port_delete(phy_info->port_details);
1745 break; 2175 break;
1746 case MPTSAS_ADD_DEVICE: 2176 case MPTSAS_ADD_DEVICE:
1747 2177
@@ -1753,59 +2183,60 @@ mptsas_hotplug_work(void *arg)
1753 */ 2183 */
1754 if (mptsas_sas_device_pg0(ioc, &sas_device, 2184 if (mptsas_sas_device_pg0(ioc, &sas_device,
1755 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << 2185 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
1756 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id)) 2186 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id)) {
2187 dfailprintk((MYIOC_s_ERR_FMT
2188 "%s: exit at line=%d\n", ioc->name,
2189 __FUNCTION__, __LINE__));
1757 break; 2190 break;
2191 }
1758 2192
1759 phy_info = mptsas_find_phyinfo_by_parent(ioc, 2193 ssleep(2);
1760 sas_device.handle_parent, sas_device.phy_id); 2194 __mptsas_discovery_work(ioc);
1761 2195
1762 if (!phy_info) { 2196 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
1763 u32 handle = 0xFFFF; 2197 sas_device.sas_address);
1764 2198
1765 /* 2199 if (!phy_info || !phy_info->port_details) {
1766 * Its possible when an expander has been hot added 2200 dfailprintk((MYIOC_s_ERR_FMT
1767 * containing attached devices, the sas firmware 2201 "%s: exit at line=%d\n", ioc->name,
1768 * may send a RC_ADDED event prior to the 2202 __FUNCTION__, __LINE__));
1769 * DISCOVERY STOP event. If that occurs, our 2203 break;
1770 * view of the topology in the driver in respect to this
1771 * expander might of not been setup, and we hit this
1772 * condition.
1773 * Therefore, this code kicks off discovery to
1774 * refresh the data.
1775 * Then again, we check whether the parent phy has
1776 * been created.
1777 */
1778 ioc->sas_discovery_runtime=1;
1779 mptsas_delete_expander_phys(ioc);
1780 mptsas_probe_hba_phys(ioc);
1781 while (!mptsas_probe_expander_phys(ioc, &handle))
1782 ;
1783 ioc->sas_discovery_runtime=0;
1784
1785 phy_info = mptsas_find_phyinfo_by_parent(ioc,
1786 sas_device.handle_parent, sas_device.phy_id);
1787 if (!phy_info)
1788 break;
1789 } 2204 }
1790 2205
1791 if (phy_info->starget) { 2206 starget = mptsas_get_starget(phy_info);
1792 vtarget = phy_info->starget->hostdata; 2207 if (starget) {
2208 vtarget = starget->hostdata;
1793 2209
1794 if (!vtarget) 2210 if (!vtarget) {
2211 dfailprintk((MYIOC_s_ERR_FMT
2212 "%s: exit at line=%d\n", ioc->name,
2213 __FUNCTION__, __LINE__));
1795 break; 2214 break;
2215 }
1796 /* 2216 /*
1797 * Handling RAID components 2217 * Handling RAID components
1798 */ 2218 */
1799 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) { 2219 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1800 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT; 2220 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
1801 vtarget->target_id = ev->id; 2221 vtarget->target_id = ev->id;
1802 mptsas_reprobe_target(phy_info->starget, 0); 2222 mptsas_reprobe_target(starget, 0);
1803 } 2223 }
1804 break; 2224 break;
1805 } 2225 }
1806 2226
1807 if (phy_info->rphy) 2227 if (mptsas_get_rphy(phy_info)) {
2228 dfailprintk((MYIOC_s_ERR_FMT
2229 "%s: exit at line=%d\n", ioc->name,
2230 __FUNCTION__, __LINE__));
2231 break;
2232 }
2233 port = mptsas_get_port(phy_info);
2234 if (!port) {
2235 dfailprintk((MYIOC_s_ERR_FMT
2236 "%s: exit at line=%d\n", ioc->name,
2237 __FUNCTION__, __LINE__));
1808 break; 2238 break;
2239 }
1809 2240
1810 memcpy(&phy_info->attached, &sas_device, 2241 memcpy(&phy_info->attached, &sas_device,
1811 sizeof(struct mptsas_devinfo)); 2242 sizeof(struct mptsas_devinfo));
@@ -1822,59 +2253,48 @@ mptsas_hotplug_work(void *arg)
1822 ioc->name, ds, ev->channel, ev->id, ev->phy_id); 2253 ioc->name, ds, ev->channel, ev->id, ev->phy_id);
1823 2254
1824 mptsas_parse_device_info(&identify, &phy_info->attached); 2255 mptsas_parse_device_info(&identify, &phy_info->attached);
1825 switch (identify.device_type) { 2256 rphy = sas_end_device_alloc(port);
1826 case SAS_END_DEVICE: 2257 if (!rphy) {
1827 rphy = sas_end_device_alloc(phy_info->phy); 2258 dfailprintk((MYIOC_s_ERR_FMT
1828 break; 2259 "%s: exit at line=%d\n", ioc->name,
1829 case SAS_EDGE_EXPANDER_DEVICE: 2260 __FUNCTION__, __LINE__));
1830 case SAS_FANOUT_EXPANDER_DEVICE:
1831 rphy = sas_expander_alloc(phy_info->phy, identify.device_type);
1832 break;
1833 default:
1834 rphy = NULL;
1835 break;
1836 }
1837 if (!rphy)
1838 break; /* non-fatal: an rphy can be added later */ 2261 break; /* non-fatal: an rphy can be added later */
2262 }
1839 2263
1840 rphy->identify = identify; 2264 rphy->identify = identify;
1841 if (sas_rphy_add(rphy)) { 2265 if (sas_rphy_add(rphy)) {
2266 dfailprintk((MYIOC_s_ERR_FMT
2267 "%s: exit at line=%d\n", ioc->name,
2268 __FUNCTION__, __LINE__));
1842 sas_rphy_free(rphy); 2269 sas_rphy_free(rphy);
1843 break; 2270 break;
1844 } 2271 }
1845 2272 mptsas_set_rphy(phy_info, rphy);
1846 phy_info->rphy = rphy;
1847 break; 2273 break;
1848 case MPTSAS_ADD_RAID: 2274 case MPTSAS_ADD_RAID:
1849 sdev = scsi_device_lookup( 2275 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
1850 ioc->sh, 2276 ev->id, 0);
1851 ioc->num_ports,
1852 ev->id,
1853 0);
1854 if (sdev) { 2277 if (sdev) {
1855 scsi_device_put(sdev); 2278 scsi_device_put(sdev);
1856 break; 2279 break;
1857 } 2280 }
1858 printk(MYIOC_s_INFO_FMT 2281 printk(MYIOC_s_INFO_FMT
1859 "attaching raid volume, channel %d, id %d\n", 2282 "attaching raid volume, channel %d, id %d\n",
1860 ioc->name, ioc->num_ports, ev->id); 2283 ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
1861 scsi_add_device(ioc->sh, 2284 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, ev->id, 0);
1862 ioc->num_ports,
1863 ev->id,
1864 0);
1865 mpt_findImVolumes(ioc); 2285 mpt_findImVolumes(ioc);
1866 break; 2286 break;
1867 case MPTSAS_DEL_RAID: 2287 case MPTSAS_DEL_RAID:
1868 sdev = scsi_device_lookup( 2288 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
1869 ioc->sh, 2289 ev->id, 0);
1870 ioc->num_ports,
1871 ev->id,
1872 0);
1873 if (!sdev) 2290 if (!sdev)
1874 break; 2291 break;
1875 printk(MYIOC_s_INFO_FMT 2292 printk(MYIOC_s_INFO_FMT
1876 "removing raid volume, channel %d, id %d\n", 2293 "removing raid volume, channel %d, id %d\n",
1877 ioc->name, ioc->num_ports, ev->id); 2294 ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
2295 vdevice = sdev->hostdata;
2296 vdevice->vtarget->deleted = 1;
2297 mptsas_target_reset(ioc, vdevice->vtarget);
1878 scsi_remove_device(sdev); 2298 scsi_remove_device(sdev);
1879 scsi_device_put(sdev); 2299 scsi_device_put(sdev);
1880 mpt_findImVolumes(ioc); 2300 mpt_findImVolumes(ioc);
@@ -1884,12 +2304,13 @@ mptsas_hotplug_work(void *arg)
1884 break; 2304 break;
1885 } 2305 }
1886 2306
1887 kfree(ev);
1888 mutex_unlock(&ioc->sas_discovery_mutex); 2307 mutex_unlock(&ioc->sas_discovery_mutex);
2308 kfree(ev);
2309
1889} 2310}
1890 2311
1891static void 2312static void
1892mptscsih_send_sas_event(MPT_ADAPTER *ioc, 2313mptsas_send_sas_event(MPT_ADAPTER *ioc,
1893 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data) 2314 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
1894{ 2315{
1895 struct mptsas_hotplug_event *ev; 2316 struct mptsas_hotplug_event *ev;
@@ -1905,7 +2326,7 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1905 switch (sas_event_data->ReasonCode) { 2326 switch (sas_event_data->ReasonCode) {
1906 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED: 2327 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
1907 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING: 2328 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
1908 ev = kmalloc(sizeof(*ev), GFP_ATOMIC); 2329 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
1909 if (!ev) { 2330 if (!ev) {
1910 printk(KERN_WARNING "mptsas: lost hotplug event\n"); 2331 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1911 break; 2332 break;
@@ -1935,10 +2356,9 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1935 /* 2356 /*
1936 * Persistent table is full. 2357 * Persistent table is full.
1937 */ 2358 */
1938 INIT_WORK(&ioc->mptscsih_persistTask, 2359 INIT_WORK(&ioc->sas_persist_task,
1939 mptscsih_sas_persist_clear_table, 2360 mptsas_persist_clear_table, (void *)ioc);
1940 (void *)ioc); 2361 schedule_work(&ioc->sas_persist_task);
1941 schedule_work(&ioc->mptscsih_persistTask);
1942 break; 2362 break;
1943 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA: 2363 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
1944 /* TODO */ 2364 /* TODO */
@@ -1950,7 +2370,7 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1950} 2370}
1951 2371
1952static void 2372static void
1953mptscsih_send_raid_event(MPT_ADAPTER *ioc, 2373mptsas_send_raid_event(MPT_ADAPTER *ioc,
1954 EVENT_DATA_RAID *raid_event_data) 2374 EVENT_DATA_RAID *raid_event_data)
1955{ 2375{
1956 struct mptsas_hotplug_event *ev; 2376 struct mptsas_hotplug_event *ev;
@@ -1960,13 +2380,12 @@ mptscsih_send_raid_event(MPT_ADAPTER *ioc,
1960 if (ioc->bus_type != SAS) 2380 if (ioc->bus_type != SAS)
1961 return; 2381 return;
1962 2382
1963 ev = kmalloc(sizeof(*ev), GFP_ATOMIC); 2383 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
1964 if (!ev) { 2384 if (!ev) {
1965 printk(KERN_WARNING "mptsas: lost hotplug event\n"); 2385 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1966 return; 2386 return;
1967 } 2387 }
1968 2388
1969 memset(ev,0,sizeof(struct mptsas_hotplug_event));
1970 INIT_WORK(&ev->work, mptsas_hotplug_work, ev); 2389 INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
1971 ev->ioc = ioc; 2390 ev->ioc = ioc;
1972 ev->id = raid_event_data->VolumeID; 2391 ev->id = raid_event_data->VolumeID;
@@ -2028,7 +2447,7 @@ mptscsih_send_raid_event(MPT_ADAPTER *ioc,
2028} 2447}
2029 2448
2030static void 2449static void
2031mptscsih_send_discovery(MPT_ADAPTER *ioc, 2450mptsas_send_discovery_event(MPT_ADAPTER *ioc,
2032 EVENT_DATA_SAS_DISCOVERY *discovery_data) 2451 EVENT_DATA_SAS_DISCOVERY *discovery_data)
2033{ 2452{
2034 struct mptsas_discovery_event *ev; 2453 struct mptsas_discovery_event *ev;
@@ -2043,11 +2462,10 @@ mptscsih_send_discovery(MPT_ADAPTER *ioc,
2043 if (discovery_data->DiscoveryStatus) 2462 if (discovery_data->DiscoveryStatus)
2044 return; 2463 return;
2045 2464
2046 ev = kmalloc(sizeof(*ev), GFP_ATOMIC); 2465 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2047 if (!ev) 2466 if (!ev)
2048 return; 2467 return;
2049 memset(ev,0,sizeof(struct mptsas_discovery_event)); 2468 INIT_WORK(&ev->work, mptsas_discovery_work, ev);
2050 INIT_WORK(&ev->work, mptscsih_discovery_work, ev);
2051 ev->ioc = ioc; 2469 ev->ioc = ioc;
2052 schedule_work(&ev->work); 2470 schedule_work(&ev->work);
2053}; 2471};
@@ -2075,21 +2493,21 @@ mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
2075 2493
2076 switch (event) { 2494 switch (event) {
2077 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE: 2495 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
2078 mptscsih_send_sas_event(ioc, 2496 mptsas_send_sas_event(ioc,
2079 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data); 2497 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data);
2080 break; 2498 break;
2081 case MPI_EVENT_INTEGRATED_RAID: 2499 case MPI_EVENT_INTEGRATED_RAID:
2082 mptscsih_send_raid_event(ioc, 2500 mptsas_send_raid_event(ioc,
2083 (EVENT_DATA_RAID *)reply->Data); 2501 (EVENT_DATA_RAID *)reply->Data);
2084 break; 2502 break;
2085 case MPI_EVENT_PERSISTENT_TABLE_FULL: 2503 case MPI_EVENT_PERSISTENT_TABLE_FULL:
2086 INIT_WORK(&ioc->mptscsih_persistTask, 2504 INIT_WORK(&ioc->sas_persist_task,
2087 mptscsih_sas_persist_clear_table, 2505 mptsas_persist_clear_table,
2088 (void *)ioc); 2506 (void *)ioc);
2089 schedule_work(&ioc->mptscsih_persistTask); 2507 schedule_work(&ioc->sas_persist_task);
2090 break; 2508 break;
2091 case MPI_EVENT_SAS_DISCOVERY: 2509 case MPI_EVENT_SAS_DISCOVERY:
2092 mptscsih_send_discovery(ioc, 2510 mptsas_send_discovery_event(ioc,
2093 (EVENT_DATA_SAS_DISCOVERY *)reply->Data); 2511 (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
2094 break; 2512 break;
2095 default: 2513 default:
@@ -2279,7 +2697,6 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2279 hd->timer.data = (unsigned long) hd; 2697 hd->timer.data = (unsigned long) hd;
2280 hd->timer.function = mptscsih_timer_expired; 2698 hd->timer.function = mptscsih_timer_expired;
2281 2699
2282 hd->mpt_pq_filter = mpt_pq_filter;
2283 ioc->sas_data.ptClear = mpt_pt_clear; 2700 ioc->sas_data.ptClear = mpt_pt_clear;
2284 2701
2285 if (ioc->sas_data.ptClear==1) { 2702 if (ioc->sas_data.ptClear==1) {
@@ -2287,12 +2704,6 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2287 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT); 2704 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
2288 } 2705 }
2289 2706
2290 ddvprintk((MYIOC_s_INFO_FMT
2291 "mpt_pq_filter %x mpt_pq_filter %x\n",
2292 ioc->name,
2293 mpt_pq_filter,
2294 mpt_pq_filter));
2295
2296 init_waitqueue_head(&hd->scandv_waitq); 2707 init_waitqueue_head(&hd->scandv_waitq);
2297 hd->scandv_wait_done = 0; 2708 hd->scandv_wait_done = 0;
2298 hd->last_queue_full = 0; 2709 hd->last_queue_full = 0;
@@ -2308,7 +2719,7 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2308 2719
2309 return 0; 2720 return 0;
2310 2721
2311out_mptsas_probe: 2722 out_mptsas_probe:
2312 2723
2313 mptscsih_remove(pdev); 2724 mptscsih_remove(pdev);
2314 return error; 2725 return error;
@@ -2318,6 +2729,7 @@ static void __devexit mptsas_remove(struct pci_dev *pdev)
2318{ 2729{
2319 MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 2730 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2320 struct mptsas_portinfo *p, *n; 2731 struct mptsas_portinfo *p, *n;
2732 int i;
2321 2733
2322 ioc->sas_discovery_ignore_events=1; 2734 ioc->sas_discovery_ignore_events=1;
2323 sas_remove_host(ioc->sh); 2735 sas_remove_host(ioc->sh);
@@ -2325,8 +2737,9 @@ static void __devexit mptsas_remove(struct pci_dev *pdev)
2325 mutex_lock(&ioc->sas_topology_mutex); 2737 mutex_lock(&ioc->sas_topology_mutex);
2326 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) { 2738 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
2327 list_del(&p->list); 2739 list_del(&p->list);
2328 if (p->phy_info) 2740 for (i = 0 ; i < p->num_phys ; i++)
2329 kfree(p->phy_info); 2741 mptsas_port_delete(p->phy_info[i].port_details);
2742 kfree(p->phy_info);
2330 kfree(p); 2743 kfree(p);
2331 } 2744 }
2332 mutex_unlock(&ioc->sas_topology_mutex); 2745 mutex_unlock(&ioc->sas_topology_mutex);
@@ -2335,17 +2748,15 @@ static void __devexit mptsas_remove(struct pci_dev *pdev)
2335} 2748}
2336 2749
2337static struct pci_device_id mptsas_pci_table[] = { 2750static struct pci_device_id mptsas_pci_table[] = {
2338 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064, 2751 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
2339 PCI_ANY_ID, PCI_ANY_ID },
2340 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066,
2341 PCI_ANY_ID, PCI_ANY_ID }, 2752 PCI_ANY_ID, PCI_ANY_ID },
2342 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068, 2753 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
2343 PCI_ANY_ID, PCI_ANY_ID }, 2754 PCI_ANY_ID, PCI_ANY_ID },
2344 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064E, 2755 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
2345 PCI_ANY_ID, PCI_ANY_ID }, 2756 PCI_ANY_ID, PCI_ANY_ID },
2346 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066E, 2757 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
2347 PCI_ANY_ID, PCI_ANY_ID }, 2758 PCI_ANY_ID, PCI_ANY_ID },
2348 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068E, 2759 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
2349 PCI_ANY_ID, PCI_ANY_ID }, 2760 PCI_ANY_ID, PCI_ANY_ID },
2350 {0} /* Terminating entry */ 2761 {0} /* Terminating entry */
2351}; 2762};
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index 8242b16e3168..30524dc54b16 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -66,6 +66,7 @@
66 66
67#include "mptbase.h" 67#include "mptbase.h"
68#include "mptscsih.h" 68#include "mptscsih.h"
69#include "lsi/mpi_log_sas.h"
69 70
70/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 71/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
71#define my_NAME "Fusion MPT SCSI Host driver" 72#define my_NAME "Fusion MPT SCSI Host driver"
@@ -127,7 +128,7 @@ static void mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx);
127static void mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply); 128static void mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply);
128static int mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd); 129static int mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd);
129static int mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout ); 130static int mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout );
130static u32 SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc); 131static int SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc);
131 132
132static int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout); 133static int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout);
133 134
@@ -497,6 +498,34 @@ nextSGEset:
497 return SUCCESS; 498 return SUCCESS;
498} /* mptscsih_AddSGE() */ 499} /* mptscsih_AddSGE() */
499 500
501static void
502mptscsih_issue_sep_command(MPT_ADAPTER *ioc, VirtTarget *vtarget,
503 U32 SlotStatus)
504{
505 MPT_FRAME_HDR *mf;
506 SEPRequest_t *SEPMsg;
507
508 if (ioc->bus_type == FC)
509 return;
510
511 if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
512 dfailprintk((MYIOC_s_WARN_FMT "%s: no msg frames!!\n",
513 ioc->name,__FUNCTION__));
514 return;
515 }
516
517 SEPMsg = (SEPRequest_t *)mf;
518 SEPMsg->Function = MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
519 SEPMsg->Bus = vtarget->bus_id;
520 SEPMsg->TargetID = vtarget->target_id;
521 SEPMsg->Action = MPI_SEP_REQ_ACTION_WRITE_STATUS;
522 SEPMsg->SlotStatus = SlotStatus;
523 devtverboseprintk((MYIOC_s_WARN_FMT
524 "Sending SEP cmd=%x id=%d bus=%d\n",
525 ioc->name, SlotStatus, SEPMsg->TargetID, SEPMsg->Bus));
526 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
527}
528
500/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 529/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
501/* 530/*
502 * mptscsih_io_done - Main SCSI IO callback routine registered to 531 * mptscsih_io_done - Main SCSI IO callback routine registered to
@@ -520,6 +549,8 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
520 SCSIIORequest_t *pScsiReq; 549 SCSIIORequest_t *pScsiReq;
521 SCSIIOReply_t *pScsiReply; 550 SCSIIOReply_t *pScsiReply;
522 u16 req_idx, req_idx_MR; 551 u16 req_idx, req_idx_MR;
552 VirtDevice *vdev;
553 VirtTarget *vtarget;
523 554
524 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata; 555 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
525 556
@@ -538,6 +569,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
538 } 569 }
539 570
540 sc = hd->ScsiLookup[req_idx]; 571 sc = hd->ScsiLookup[req_idx];
572 hd->ScsiLookup[req_idx] = NULL;
541 if (sc == NULL) { 573 if (sc == NULL) {
542 MPIHeader_t *hdr = (MPIHeader_t *)mf; 574 MPIHeader_t *hdr = (MPIHeader_t *)mf;
543 575
@@ -553,6 +585,12 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
553 return 1; 585 return 1;
554 } 586 }
555 587
588 if ((unsigned char *)mf != sc->host_scribble) {
589 mptscsih_freeChainBuffers(ioc, req_idx);
590 return 1;
591 }
592
593 sc->host_scribble = NULL;
556 sc->result = DID_OK << 16; /* Set default reply as OK */ 594 sc->result = DID_OK << 16; /* Set default reply as OK */
557 pScsiReq = (SCSIIORequest_t *) mf; 595 pScsiReq = (SCSIIORequest_t *) mf;
558 pScsiReply = (SCSIIOReply_t *) mr; 596 pScsiReply = (SCSIIOReply_t *) mr;
@@ -640,10 +678,36 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
640 678
641 if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF) 679 if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF)
642 hd->sel_timeout[pScsiReq->TargetID]++; 680 hd->sel_timeout[pScsiReq->TargetID]++;
681
682 vdev = sc->device->hostdata;
683 if (!vdev)
684 break;
685 vtarget = vdev->vtarget;
686 if (vtarget->tflags & MPT_TARGET_FLAGS_LED_ON) {
687 mptscsih_issue_sep_command(ioc, vtarget,
688 MPI_SEP_REQ_SLOTSTATUS_UNCONFIGURED);
689 vtarget->tflags &= ~MPT_TARGET_FLAGS_LED_ON;
690 }
643 break; 691 break;
644 692
645 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
646 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */ 693 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
694 if ( ioc->bus_type == SAS ) {
695 u16 ioc_status = le16_to_cpu(pScsiReply->IOCStatus);
696 if (ioc_status & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
697 u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
698 log_info &=SAS_LOGINFO_MASK;
699 if (log_info == SAS_LOGINFO_NEXUS_LOSS) {
700 sc->result = (DID_BUS_BUSY << 16);
701 break;
702 }
703 }
704 }
705
706 /*
707 * Allow non-SAS & non-NEXUS_LOSS to drop into below code
708 */
709
710 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
647 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */ 711 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
648 /* Linux handles an unsolicited DID_RESET better 712 /* Linux handles an unsolicited DID_RESET better
649 * than an unsolicited DID_ABORT. 713 * than an unsolicited DID_ABORT.
@@ -658,7 +722,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
658 sc->result=DID_SOFT_ERROR << 16; 722 sc->result=DID_SOFT_ERROR << 16;
659 else /* Sufficient data transfer occurred */ 723 else /* Sufficient data transfer occurred */
660 sc->result = (DID_OK << 16) | scsi_status; 724 sc->result = (DID_OK << 16) | scsi_status;
661 dreplyprintk((KERN_NOTICE 725 dreplyprintk((KERN_NOTICE
662 "RESIDUAL_MISMATCH: result=%x on id=%d\n", sc->result, sc->device->id)); 726 "RESIDUAL_MISMATCH: result=%x on id=%d\n", sc->result, sc->device->id));
663 break; 727 break;
664 728
@@ -784,8 +848,6 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
784 sc->request_bufflen, sc->sc_data_direction); 848 sc->request_bufflen, sc->sc_data_direction);
785 } 849 }
786 850
787 hd->ScsiLookup[req_idx] = NULL;
788
789 sc->scsi_done(sc); /* Issue the command callback */ 851 sc->scsi_done(sc); /* Issue the command callback */
790 852
791 /* Free Chain buffers */ 853 /* Free Chain buffers */
@@ -827,9 +889,17 @@ mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
827 dmfprintk(( "flush: ScsiDone (mf=%p,sc=%p)\n", 889 dmfprintk(( "flush: ScsiDone (mf=%p,sc=%p)\n",
828 mf, SCpnt)); 890 mf, SCpnt));
829 891
892 /* Free Chain buffers */
893 mptscsih_freeChainBuffers(ioc, ii);
894
895 /* Free Message frames */
896 mpt_free_msg_frame(ioc, mf);
897
898 if ((unsigned char *)mf != SCpnt->host_scribble)
899 continue;
900
830 /* Set status, free OS resources (SG DMA buffers) 901 /* Set status, free OS resources (SG DMA buffers)
831 * Do OS callback 902 * Do OS callback
832 * Free driver resources (chain, msg buffers)
833 */ 903 */
834 if (SCpnt->use_sg) { 904 if (SCpnt->use_sg) {
835 pci_unmap_sg(ioc->pcidev, 905 pci_unmap_sg(ioc->pcidev,
@@ -845,12 +915,6 @@ mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
845 SCpnt->result = DID_RESET << 16; 915 SCpnt->result = DID_RESET << 16;
846 SCpnt->host_scribble = NULL; 916 SCpnt->host_scribble = NULL;
847 917
848 /* Free Chain buffers */
849 mptscsih_freeChainBuffers(ioc, ii);
850
851 /* Free Message frames */
852 mpt_free_msg_frame(ioc, mf);
853
854 SCpnt->scsi_done(SCpnt); /* Issue the command callback */ 918 SCpnt->scsi_done(SCpnt); /* Issue the command callback */
855 } 919 }
856 } 920 }
@@ -887,10 +951,10 @@ mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
887 if ((sc = hd->ScsiLookup[ii]) != NULL) { 951 if ((sc = hd->ScsiLookup[ii]) != NULL) {
888 952
889 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(hd->ioc, ii); 953 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(hd->ioc, ii);
890 954 if (mf == NULL)
955 continue;
891 dsprintk(( "search_running: found (sc=%p, mf = %p) target %d, lun %d \n", 956 dsprintk(( "search_running: found (sc=%p, mf = %p) target %d, lun %d \n",
892 hd->ScsiLookup[ii], mf, mf->TargetID, mf->LUN[1])); 957 hd->ScsiLookup[ii], mf, mf->TargetID, mf->LUN[1]));
893
894 if ((mf->TargetID != ((u8)vdevice->vtarget->target_id)) || (mf->LUN[1] != ((u8) vdevice->lun))) 958 if ((mf->TargetID != ((u8)vdevice->vtarget->target_id)) || (mf->LUN[1] != ((u8) vdevice->lun)))
895 continue; 959 continue;
896 960
@@ -899,6 +963,8 @@ mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
899 hd->ScsiLookup[ii] = NULL; 963 hd->ScsiLookup[ii] = NULL;
900 mptscsih_freeChainBuffers(hd->ioc, ii); 964 mptscsih_freeChainBuffers(hd->ioc, ii);
901 mpt_free_msg_frame(hd->ioc, (MPT_FRAME_HDR *)mf); 965 mpt_free_msg_frame(hd->ioc, (MPT_FRAME_HDR *)mf);
966 if ((unsigned char *)mf != sc->host_scribble)
967 continue;
902 if (sc->use_sg) { 968 if (sc->use_sg) {
903 pci_unmap_sg(hd->ioc->pcidev, 969 pci_unmap_sg(hd->ioc->pcidev,
904 (struct scatterlist *) sc->request_buffer, 970 (struct scatterlist *) sc->request_buffer,
@@ -1341,8 +1407,8 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1341 goto fail; 1407 goto fail;
1342 } 1408 }
1343 1409
1410 SCpnt->host_scribble = (unsigned char *)mf;
1344 hd->ScsiLookup[my_idx] = SCpnt; 1411 hd->ScsiLookup[my_idx] = SCpnt;
1345 SCpnt->host_scribble = NULL;
1346 1412
1347 mpt_put_msg_frame(hd->ioc->DoneCtx, hd->ioc, mf); 1413 mpt_put_msg_frame(hd->ioc->DoneCtx, hd->ioc, mf);
1348 dmfprintk((MYIOC_s_INFO_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n", 1414 dmfprintk((MYIOC_s_INFO_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",
@@ -1529,6 +1595,12 @@ mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, in
1529 rc = mpt_HardResetHandler(hd->ioc, CAN_SLEEP); 1595 rc = mpt_HardResetHandler(hd->ioc, CAN_SLEEP);
1530 } 1596 }
1531 1597
1598 /*
1599 * Check IOCStatus from TM reply message
1600 */
1601 if (hd->tm_iocstatus != MPI_IOCSTATUS_SUCCESS)
1602 rc = FAILED;
1603
1532 dtmprintk((MYIOC_s_INFO_FMT "TMHandler rc = %d!\n", hd->ioc->name, rc)); 1604 dtmprintk((MYIOC_s_INFO_FMT "TMHandler rc = %d!\n", hd->ioc->name, rc));
1533 1605
1534 return rc; 1606 return rc;
@@ -1654,6 +1726,7 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
1654 int scpnt_idx; 1726 int scpnt_idx;
1655 int retval; 1727 int retval;
1656 VirtDevice *vdev; 1728 VirtDevice *vdev;
1729 ulong sn = SCpnt->serial_number;
1657 1730
1658 /* If we can't locate our host adapter structure, return FAILED status. 1731 /* If we can't locate our host adapter structure, return FAILED status.
1659 */ 1732 */
@@ -1707,6 +1780,11 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
1707 vdev->vtarget->bus_id, vdev->vtarget->target_id, vdev->lun, 1780 vdev->vtarget->bus_id, vdev->vtarget->target_id, vdev->lun,
1708 ctx2abort, mptscsih_get_tm_timeout(hd->ioc)); 1781 ctx2abort, mptscsih_get_tm_timeout(hd->ioc));
1709 1782
1783 if (SCPNT_TO_LOOKUP_IDX(SCpnt) == scpnt_idx &&
1784 SCpnt->serial_number == sn) {
1785 retval = FAILED;
1786 }
1787
1710 printk (KERN_WARNING MYNAM ": %s: task abort: %s (sc=%p)\n", 1788 printk (KERN_WARNING MYNAM ": %s: task abort: %s (sc=%p)\n",
1711 hd->ioc->name, 1789 hd->ioc->name,
1712 ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt); 1790 ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
@@ -2023,6 +2101,7 @@ mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *m
2023 DBG_DUMP_TM_REPLY_FRAME((u32 *)pScsiTmReply); 2101 DBG_DUMP_TM_REPLY_FRAME((u32 *)pScsiTmReply);
2024 2102
2025 iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK; 2103 iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
2104 hd->tm_iocstatus = iocstatus;
2026 dtmprintk((MYIOC_s_WARN_FMT " SCSI TaskMgmt (%d) IOCStatus=%04x IOCLogInfo=%08x\n", 2105 dtmprintk((MYIOC_s_WARN_FMT " SCSI TaskMgmt (%d) IOCStatus=%04x IOCLogInfo=%08x\n",
2027 ioc->name, tmType, iocstatus, le32_to_cpu(pScsiTmReply->IOCLogInfo))); 2106 ioc->name, tmType, iocstatus, le32_to_cpu(pScsiTmReply->IOCLogInfo)));
2028 /* Error? (anything non-zero?) */ 2107 /* Error? (anything non-zero?) */
@@ -2401,6 +2480,13 @@ mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR
2401 ioc->events[idx].data[1] = (sense_data[13] << 8) || sense_data[12]; 2480 ioc->events[idx].data[1] = (sense_data[13] << 8) || sense_data[12];
2402 2481
2403 ioc->eventContext++; 2482 ioc->eventContext++;
2483 if (hd->ioc->pcidev->vendor ==
2484 PCI_VENDOR_ID_IBM) {
2485 mptscsih_issue_sep_command(hd->ioc,
2486 vdev->vtarget, MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
2487 vdev->vtarget->tflags |=
2488 MPT_TARGET_FLAGS_LED_ON;
2489 }
2404 } 2490 }
2405 } 2491 }
2406 } else { 2492 } else {
@@ -2409,7 +2495,7 @@ mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR
2409 } 2495 }
2410} 2496}
2411 2497
2412static u32 2498static int
2413SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc) 2499SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc)
2414{ 2500{
2415 MPT_SCSI_HOST *hd; 2501 MPT_SCSI_HOST *hd;
diff --git a/drivers/message/fusion/mptspi.c b/drivers/message/fusion/mptspi.c
index 3201de053943..e4cc3dd5fc9f 100644
--- a/drivers/message/fusion/mptspi.c
+++ b/drivers/message/fusion/mptspi.c
@@ -83,10 +83,6 @@ static int mpt_saf_te = MPTSCSIH_SAF_TE;
83module_param(mpt_saf_te, int, 0); 83module_param(mpt_saf_te, int, 0);
84MODULE_PARM_DESC(mpt_saf_te, " Force enabling SEP Processor: enable=1 (default=MPTSCSIH_SAF_TE=0)"); 84MODULE_PARM_DESC(mpt_saf_te, " Force enabling SEP Processor: enable=1 (default=MPTSCSIH_SAF_TE=0)");
85 85
86static int mpt_pq_filter = 0;
87module_param(mpt_pq_filter, int, 0);
88MODULE_PARM_DESC(mpt_pq_filter, " Enable peripheral qualifier filter: enable=1 (default=0)");
89
90static void mptspi_write_offset(struct scsi_target *, int); 86static void mptspi_write_offset(struct scsi_target *, int);
91static void mptspi_write_width(struct scsi_target *, int); 87static void mptspi_write_width(struct scsi_target *, int);
92static int mptspi_write_spi_device_pg1(struct scsi_target *, 88static int mptspi_write_spi_device_pg1(struct scsi_target *,
@@ -775,9 +771,9 @@ static struct spi_function_template mptspi_transport_functions = {
775 */ 771 */
776 772
777static struct pci_device_id mptspi_pci_table[] = { 773static struct pci_device_id mptspi_pci_table[] = {
778 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1030, 774 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_53C1030,
779 PCI_ANY_ID, PCI_ANY_ID }, 775 PCI_ANY_ID, PCI_ANY_ID },
780 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_1030_53C1035, 776 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_53C1035,
781 PCI_ANY_ID, PCI_ANY_ID }, 777 PCI_ANY_ID, PCI_ANY_ID },
782 {0} /* Terminating entry */ 778 {0} /* Terminating entry */
783}; 779};
@@ -1047,14 +1043,12 @@ mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1047 hd->timer.function = mptscsih_timer_expired; 1043 hd->timer.function = mptscsih_timer_expired;
1048 1044
1049 ioc->spi_data.Saf_Te = mpt_saf_te; 1045 ioc->spi_data.Saf_Te = mpt_saf_te;
1050 hd->mpt_pq_filter = mpt_pq_filter;
1051 1046
1052 hd->negoNvram = MPT_SCSICFG_USE_NVRAM; 1047 hd->negoNvram = MPT_SCSICFG_USE_NVRAM;
1053 ddvprintk((MYIOC_s_INFO_FMT 1048 ddvprintk((MYIOC_s_INFO_FMT
1054 "saf_te %x mpt_pq_filter %x\n", 1049 "saf_te %x\n",
1055 ioc->name, 1050 ioc->name,
1056 mpt_saf_te, 1051 mpt_saf_te));
1057 mpt_pq_filter));
1058 ioc->spi_data.noQas = 0; 1052 ioc->spi_data.noQas = 0;
1059 1053
1060 init_waitqueue_head(&hd->scandv_waitq); 1054 init_waitqueue_head(&hd->scandv_waitq);
diff --git a/drivers/message/i2o/core.h b/drivers/message/i2o/core.h
index 184974cc734d..dc388a3ff5e0 100644
--- a/drivers/message/i2o/core.h
+++ b/drivers/message/i2o/core.h
@@ -38,6 +38,9 @@ extern struct device_attribute i2o_device_attrs[];
38extern void i2o_device_remove(struct i2o_device *); 38extern void i2o_device_remove(struct i2o_device *);
39extern int i2o_device_parse_lct(struct i2o_controller *); 39extern int i2o_device_parse_lct(struct i2o_controller *);
40 40
41int i2o_parm_issue(struct i2o_device *i2o_dev, int cmd, void *oplist,
42 int oplen, void *reslist, int reslen);
43
41/* IOP */ 44/* IOP */
42extern struct i2o_controller *i2o_iop_alloc(void); 45extern struct i2o_controller *i2o_iop_alloc(void);
43 46
diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
index 89daf67b764d..7d23e082bf26 100644
--- a/drivers/message/i2o/i2o_config.c
+++ b/drivers/message/i2o/i2o_config.c
@@ -36,9 +36,9 @@
36 36
37#include <asm/uaccess.h> 37#include <asm/uaccess.h>
38 38
39#define SG_TABLESIZE 30 39#include "core.h"
40 40
41extern int i2o_parm_issue(struct i2o_device *, int, void *, int, void *, int); 41#define SG_TABLESIZE 30
42 42
43static int i2o_cfg_ioctl(struct inode *, struct file *, unsigned int, 43static int i2o_cfg_ioctl(struct inode *, struct file *, unsigned int,
44 unsigned long); 44 unsigned long);
diff --git a/drivers/mfd/ucb1x00-core.c b/drivers/mfd/ucb1x00-core.c
index 632bc218c86a..2bf32721eb53 100644
--- a/drivers/mfd/ucb1x00-core.c
+++ b/drivers/mfd/ucb1x00-core.c
@@ -479,7 +479,7 @@ static int ucb1x00_probe(struct mcp *mcp)
479 mcp_enable(mcp); 479 mcp_enable(mcp);
480 id = mcp_reg_read(mcp, UCB_ID); 480 id = mcp_reg_read(mcp, UCB_ID);
481 481
482 if (id != UCB_ID_1200 && id != UCB_ID_1300) { 482 if (id != UCB_ID_1200 && id != UCB_ID_1300 && id != UCB_ID_TC35143) {
483 printk(KERN_WARNING "UCB1x00 ID not found: %04x\n", id); 483 printk(KERN_WARNING "UCB1x00 ID not found: %04x\n", id);
484 goto err_disable; 484 goto err_disable;
485 } 485 }
diff --git a/drivers/mfd/ucb1x00.h b/drivers/mfd/ucb1x00.h
index 9c9a647d8b7b..ca8df8072d43 100644
--- a/drivers/mfd/ucb1x00.h
+++ b/drivers/mfd/ucb1x00.h
@@ -94,6 +94,7 @@
94#define UCB_ID 0x0c 94#define UCB_ID 0x0c
95#define UCB_ID_1200 0x1004 95#define UCB_ID_1200 0x1004
96#define UCB_ID_1300 0x1005 96#define UCB_ID_1300 0x1005
97#define UCB_ID_TC35143 0x9712
97 98
98#define UCB_MODE 0x0d 99#define UCB_MODE 0x0d
99#define UCB_MODE_DYN_VFLAG_ENA (1 << 12) 100#define UCB_MODE_DYN_VFLAG_ENA (1 << 12)
diff --git a/drivers/mmc/imxmmc.c b/drivers/mmc/imxmmc.c
index 7ca9e95bdf89..fb6565b98f32 100644
--- a/drivers/mmc/imxmmc.c
+++ b/drivers/mmc/imxmmc.c
@@ -91,6 +91,8 @@ struct imxmci_host {
91 int dma_allocated; 91 int dma_allocated;
92 92
93 unsigned char actual_bus_width; 93 unsigned char actual_bus_width;
94
95 int prev_cmd_code;
94}; 96};
95 97
96#define IMXMCI_PEND_IRQ_b 0 98#define IMXMCI_PEND_IRQ_b 0
@@ -248,16 +250,14 @@ static void imxmci_setup_data(struct imxmci_host *host, struct mmc_data *data)
248 * partial FIFO fills and reads. The length has to be rounded up to burst size multiple. 250 * partial FIFO fills and reads. The length has to be rounded up to burst size multiple.
249 * This is required for SCR read at least. 251 * This is required for SCR read at least.
250 */ 252 */
251 if (datasz < 64) { 253 if (datasz < 512) {
252 host->dma_size = datasz; 254 host->dma_size = datasz;
253 if (data->flags & MMC_DATA_READ) { 255 if (data->flags & MMC_DATA_READ) {
254 host->dma_dir = DMA_FROM_DEVICE; 256 host->dma_dir = DMA_FROM_DEVICE;
255 257
256 /* Hack to enable read SCR */ 258 /* Hack to enable read SCR */
257 if(datasz < 16) { 259 MMC_NOB = 1;
258 MMC_NOB = 1; 260 MMC_BLK_LEN = 512;
259 MMC_BLK_LEN = 16;
260 }
261 } else { 261 } else {
262 host->dma_dir = DMA_TO_DEVICE; 262 host->dma_dir = DMA_TO_DEVICE;
263 } 263 }
@@ -409,6 +409,9 @@ static void imxmci_finish_request(struct imxmci_host *host, struct mmc_request *
409 409
410 spin_unlock_irqrestore(&host->lock, flags); 410 spin_unlock_irqrestore(&host->lock, flags);
411 411
412 if(req && req->cmd)
413 host->prev_cmd_code = req->cmd->opcode;
414
412 host->req = NULL; 415 host->req = NULL;
413 host->cmd = NULL; 416 host->cmd = NULL;
414 host->data = NULL; 417 host->data = NULL;
@@ -553,7 +556,6 @@ static int imxmci_cpu_driven_data(struct imxmci_host *host, unsigned int *pstat)
553{ 556{
554 int i; 557 int i;
555 int burst_len; 558 int burst_len;
556 int flush_len;
557 int trans_done = 0; 559 int trans_done = 0;
558 unsigned int stat = *pstat; 560 unsigned int stat = *pstat;
559 561
@@ -566,44 +568,43 @@ static int imxmci_cpu_driven_data(struct imxmci_host *host, unsigned int *pstat)
566 dev_dbg(mmc_dev(host->mmc), "imxmci_cpu_driven_data running STATUS = 0x%x\n", 568 dev_dbg(mmc_dev(host->mmc), "imxmci_cpu_driven_data running STATUS = 0x%x\n",
567 stat); 569 stat);
568 570
571 udelay(20); /* required for clocks < 8MHz*/
572
569 if(host->dma_dir == DMA_FROM_DEVICE) { 573 if(host->dma_dir == DMA_FROM_DEVICE) {
570 imxmci_busy_wait_for_status(host, &stat, 574 imxmci_busy_wait_for_status(host, &stat,
571 STATUS_APPL_BUFF_FF | STATUS_DATA_TRANS_DONE, 575 STATUS_APPL_BUFF_FF | STATUS_DATA_TRANS_DONE,
572 20, "imxmci_cpu_driven_data read"); 576 50, "imxmci_cpu_driven_data read");
573 577
574 while((stat & (STATUS_APPL_BUFF_FF | STATUS_DATA_TRANS_DONE)) && 578 while((stat & (STATUS_APPL_BUFF_FF | STATUS_DATA_TRANS_DONE)) &&
575 (host->data_cnt < host->dma_size)) { 579 (host->data_cnt < 512)) {
576 if(burst_len >= host->dma_size - host->data_cnt) { 580
577 flush_len = burst_len; 581 udelay(20); /* required for clocks < 8MHz*/
578 burst_len = host->dma_size - host->data_cnt;
579 flush_len -= burst_len;
580 host->data_cnt = host->dma_size;
581 trans_done = 1;
582 } else {
583 flush_len = 0;
584 host->data_cnt += burst_len;
585 }
586 582
587 for(i = burst_len; i>=2 ; i-=2) { 583 for(i = burst_len; i>=2 ; i-=2) {
588 *(host->data_ptr++) = MMC_BUFFER_ACCESS; 584 u16 data;
589 udelay(20); /* required for clocks < 8MHz*/ 585 data = MMC_BUFFER_ACCESS;
586 udelay(10); /* required for clocks < 8MHz*/
587 if(host->data_cnt+2 <= host->dma_size) {
588 *(host->data_ptr++) = data;
589 } else {
590 if(host->data_cnt < host->dma_size)
591 *(u8*)(host->data_ptr) = data;
592 }
593 host->data_cnt += 2;
590 } 594 }
591 595
592 if(i == 1)
593 *(u8*)(host->data_ptr) = MMC_BUFFER_ACCESS;
594
595 stat = MMC_STATUS; 596 stat = MMC_STATUS;
596 597
597 /* Flush extra bytes from FIFO */ 598 dev_dbg(mmc_dev(host->mmc), "imxmci_cpu_driven_data read %d burst %d STATUS = 0x%x\n",
598 while(flush_len && !(stat & STATUS_DATA_TRANS_DONE)){ 599 host->data_cnt, burst_len, stat);
599 i = MMC_BUFFER_ACCESS;
600 stat = MMC_STATUS;
601 stat &= ~STATUS_CRC_READ_ERR; /* Stupid but required there */
602 }
603
604 dev_dbg(mmc_dev(host->mmc), "imxmci_cpu_driven_data read burst %d STATUS = 0x%x\n",
605 burst_len, stat);
606 } 600 }
601
602 if((stat & STATUS_DATA_TRANS_DONE) && (host->data_cnt >= 512))
603 trans_done = 1;
604
605 if(host->dma_size & 0x1ff)
606 stat &= ~STATUS_CRC_READ_ERR;
607
607 } else { 608 } else {
608 imxmci_busy_wait_for_status(host, &stat, 609 imxmci_busy_wait_for_status(host, &stat,
609 STATUS_APPL_BUFF_FE, 610 STATUS_APPL_BUFF_FE,
@@ -692,8 +693,8 @@ static void imxmci_tasklet_fnc(unsigned long data)
692 what, stat, MMC_INT_MASK); 693 what, stat, MMC_INT_MASK);
693 dev_err(mmc_dev(host->mmc), "CMD_DAT_CONT = 0x%04x, MMC_BLK_LEN = 0x%04x, MMC_NOB = 0x%04x, DMA_CCR = 0x%08x\n", 694 dev_err(mmc_dev(host->mmc), "CMD_DAT_CONT = 0x%04x, MMC_BLK_LEN = 0x%04x, MMC_NOB = 0x%04x, DMA_CCR = 0x%08x\n",
694 MMC_CMD_DAT_CONT, MMC_BLK_LEN, MMC_NOB, CCR(host->dma)); 695 MMC_CMD_DAT_CONT, MMC_BLK_LEN, MMC_NOB, CCR(host->dma));
695 dev_err(mmc_dev(host->mmc), "CMD%d, bus %d-bit, dma_size = 0x%x\n", 696 dev_err(mmc_dev(host->mmc), "CMD%d, prevCMD%d, bus %d-bit, dma_size = 0x%x\n",
696 host->cmd?host->cmd->opcode:0, 1<<host->actual_bus_width, host->dma_size); 697 host->cmd?host->cmd->opcode:0, host->prev_cmd_code, 1<<host->actual_bus_width, host->dma_size);
697 } 698 }
698 699
699 if(!host->present || timeout) 700 if(!host->present || timeout)
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 247ff2f23ac9..74eaaee66de0 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -128,7 +128,7 @@ static void mmc_wait_done(struct mmc_request *mrq)
128 128
129int mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq) 129int mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
130{ 130{
131 DECLARE_COMPLETION(complete); 131 DECLARE_COMPLETION_ONSTACK(complete);
132 132
133 mrq->done_data = &complete; 133 mrq->done_data = &complete;
134 mrq->done = mmc_wait_done; 134 mrq->done = mmc_wait_done;
@@ -247,6 +247,55 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, unsigned int rca,
247 247
248EXPORT_SYMBOL(mmc_wait_for_app_cmd); 248EXPORT_SYMBOL(mmc_wait_for_app_cmd);
249 249
250/**
251 * mmc_set_data_timeout - set the timeout for a data command
252 * @data: data phase for command
253 * @card: the MMC card associated with the data transfer
254 * @write: flag to differentiate reads from writes
255 */
256void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card,
257 int write)
258{
259 unsigned int mult;
260
261 /*
262 * SD cards use a 100 multiplier rather than 10
263 */
264 mult = mmc_card_sd(card) ? 100 : 10;
265
266 /*
267 * Scale up the multiplier (and therefore the timeout) by
268 * the r2w factor for writes.
269 */
270 if (write)
271 mult <<= card->csd.r2w_factor;
272
273 data->timeout_ns = card->csd.tacc_ns * mult;
274 data->timeout_clks = card->csd.tacc_clks * mult;
275
276 /*
277 * SD cards also have an upper limit on the timeout.
278 */
279 if (mmc_card_sd(card)) {
280 unsigned int timeout_us, limit_us;
281
282 timeout_us = data->timeout_ns / 1000;
283 timeout_us += data->timeout_clks * 1000 /
284 (card->host->ios.clock / 1000);
285
286 if (write)
287 limit_us = 250000;
288 else
289 limit_us = 100000;
290
291 if (timeout_us > limit_us) {
292 data->timeout_ns = limit_us * 1000;
293 data->timeout_clks = 0;
294 }
295 }
296}
297EXPORT_SYMBOL(mmc_set_data_timeout);
298
250static int mmc_select_card(struct mmc_host *host, struct mmc_card *card); 299static int mmc_select_card(struct mmc_host *host, struct mmc_card *card);
251 300
252/** 301/**
@@ -908,11 +957,9 @@ static void mmc_read_scrs(struct mmc_host *host)
908{ 957{
909 int err; 958 int err;
910 struct mmc_card *card; 959 struct mmc_card *card;
911
912 struct mmc_request mrq; 960 struct mmc_request mrq;
913 struct mmc_command cmd; 961 struct mmc_command cmd;
914 struct mmc_data data; 962 struct mmc_data data;
915
916 struct scatterlist sg; 963 struct scatterlist sg;
917 964
918 list_for_each_entry(card, &host->cards, node) { 965 list_for_each_entry(card, &host->cards, node) {
@@ -947,8 +994,8 @@ static void mmc_read_scrs(struct mmc_host *host)
947 994
948 memset(&data, 0, sizeof(struct mmc_data)); 995 memset(&data, 0, sizeof(struct mmc_data));
949 996
950 data.timeout_ns = card->csd.tacc_ns * 10; 997 mmc_set_data_timeout(&data, card, 0);
951 data.timeout_clks = card->csd.tacc_clks * 10; 998
952 data.blksz_bits = 3; 999 data.blksz_bits = 3;
953 data.blksz = 1 << 3; 1000 data.blksz = 1 << 3;
954 data.blocks = 1; 1001 data.blocks = 1;
diff --git a/drivers/mmc/mmc_block.c b/drivers/mmc/mmc_block.c
index 115cc21094b9..a0e0dad1b419 100644
--- a/drivers/mmc/mmc_block.c
+++ b/drivers/mmc/mmc_block.c
@@ -30,6 +30,7 @@
30#include <linux/mutex.h> 30#include <linux/mutex.h>
31 31
32#include <linux/mmc/card.h> 32#include <linux/mmc/card.h>
33#include <linux/mmc/host.h>
33#include <linux/mmc/protocol.h> 34#include <linux/mmc/protocol.h>
34 35
35#include <asm/system.h> 36#include <asm/system.h>
@@ -171,8 +172,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
171 172
172 brq.cmd.arg = req->sector << 9; 173 brq.cmd.arg = req->sector << 9;
173 brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 174 brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
174 brq.data.timeout_ns = card->csd.tacc_ns * 10;
175 brq.data.timeout_clks = card->csd.tacc_clks * 10;
176 brq.data.blksz_bits = md->block_bits; 175 brq.data.blksz_bits = md->block_bits;
177 brq.data.blksz = 1 << md->block_bits; 176 brq.data.blksz = 1 << md->block_bits;
178 brq.data.blocks = req->nr_sectors >> (md->block_bits - 9); 177 brq.data.blocks = req->nr_sectors >> (md->block_bits - 9);
@@ -180,6 +179,8 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
180 brq.stop.arg = 0; 179 brq.stop.arg = 0;
181 brq.stop.flags = MMC_RSP_R1B | MMC_CMD_AC; 180 brq.stop.flags = MMC_RSP_R1B | MMC_CMD_AC;
182 181
182 mmc_set_data_timeout(&brq.data, card, rq_data_dir(req) != READ);
183
183 if (rq_data_dir(req) == READ) { 184 if (rq_data_dir(req) == READ) {
184 brq.cmd.opcode = brq.data.blocks > 1 ? MMC_READ_MULTIPLE_BLOCK : MMC_READ_SINGLE_BLOCK; 185 brq.cmd.opcode = brq.data.blocks > 1 ? MMC_READ_MULTIPLE_BLOCK : MMC_READ_SINGLE_BLOCK;
185 brq.data.flags |= MMC_DATA_READ; 186 brq.data.flags |= MMC_DATA_READ;
@@ -187,12 +188,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
187 brq.cmd.opcode = MMC_WRITE_BLOCK; 188 brq.cmd.opcode = MMC_WRITE_BLOCK;
188 brq.data.flags |= MMC_DATA_WRITE; 189 brq.data.flags |= MMC_DATA_WRITE;
189 brq.data.blocks = 1; 190 brq.data.blocks = 1;
190
191 /*
192 * Scale up the timeout by the r2w factor
193 */
194 brq.data.timeout_ns <<= card->csd.r2w_factor;
195 brq.data.timeout_clks <<= card->csd.r2w_factor;
196 } 191 }
197 192
198 if (brq.data.blocks > 1) { 193 if (brq.data.blocks > 1) {
@@ -324,52 +319,11 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
324 md->read_only = mmc_blk_readonly(card); 319 md->read_only = mmc_blk_readonly(card);
325 320
326 /* 321 /*
327 * Figure out a workable block size. MMC cards have: 322 * Both SD and MMC specifications state (although a bit
328 * - two block sizes, one for read and one for write. 323 * unclearly in the MMC case) that a block size of 512
329 * - may support partial reads and/or writes 324 * bytes must always be supported by the card.
330 * (allows block sizes smaller than specified)
331 */
332 md->block_bits = card->csd.read_blkbits;
333 if (card->csd.write_blkbits != card->csd.read_blkbits) {
334 if (card->csd.write_blkbits < card->csd.read_blkbits &&
335 card->csd.read_partial) {
336 /*
337 * write block size is smaller than read block
338 * size, but we support partial reads, so choose
339 * the smaller write block size.
340 */
341 md->block_bits = card->csd.write_blkbits;
342 } else if (card->csd.write_blkbits > card->csd.read_blkbits &&
343 card->csd.write_partial) {
344 /*
345 * read block size is smaller than write block
346 * size, but we support partial writes. Use read
347 * block size.
348 */
349 } else {
350 /*
351 * We don't support this configuration for writes.
352 */
353 printk(KERN_ERR "%s: unable to select block size for "
354 "writing (rb%u wb%u rp%u wp%u)\n",
355 mmc_card_id(card),
356 1 << card->csd.read_blkbits,
357 1 << card->csd.write_blkbits,
358 card->csd.read_partial,
359 card->csd.write_partial);
360 md->read_only = 1;
361 }
362 }
363
364 /*
365 * Refuse to allow block sizes smaller than 512 bytes.
366 */ 325 */
367 if (md->block_bits < 9) { 326 md->block_bits = 9;
368 printk(KERN_ERR "%s: unable to support block size %u\n",
369 mmc_card_id(card), 1 << md->block_bits);
370 ret = -EINVAL;
371 goto err_kfree;
372 }
373 327
374 md->disk = alloc_disk(1 << MMC_SHIFT); 328 md->disk = alloc_disk(1 << MMC_SHIFT);
375 if (md->disk == NULL) { 329 if (md->disk == NULL) {
diff --git a/drivers/mmc/mmc_queue.c b/drivers/mmc/mmc_queue.c
index 0b9682e9a357..74f8cdeeff0f 100644
--- a/drivers/mmc/mmc_queue.c
+++ b/drivers/mmc/mmc_queue.c
@@ -79,7 +79,8 @@ static int mmc_queue_thread(void *d)
79 spin_lock_irq(q->queue_lock); 79 spin_lock_irq(q->queue_lock);
80 set_current_state(TASK_INTERRUPTIBLE); 80 set_current_state(TASK_INTERRUPTIBLE);
81 if (!blk_queue_plugged(q)) 81 if (!blk_queue_plugged(q))
82 mq->req = req = elv_next_request(q); 82 req = elv_next_request(q);
83 mq->req = req;
83 spin_unlock_irq(q->queue_lock); 84 spin_unlock_irq(q->queue_lock);
84 85
85 if (!req) { 86 if (!req) {
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 893319108ba4..4e21b3b9d330 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -565,7 +565,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
565 if (cmd->data) 565 if (cmd->data)
566 flags |= SDHCI_CMD_DATA; 566 flags |= SDHCI_CMD_DATA;
567 567
568 writel(SDHCI_MAKE_CMD(cmd->opcode, flags), 568 writew(SDHCI_MAKE_CMD(cmd->opcode, flags),
569 host->ioaddr + SDHCI_COMMAND); 569 host->ioaddr + SDHCI_COMMAND);
570} 570}
571 571
@@ -1193,10 +1193,8 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
1193 version = (version & SDHCI_SPEC_VER_MASK) >> SDHCI_SPEC_VER_SHIFT; 1193 version = (version & SDHCI_SPEC_VER_MASK) >> SDHCI_SPEC_VER_SHIFT;
1194 if (version != 0) { 1194 if (version != 0) {
1195 printk(KERN_ERR "%s: Unknown controller version (%d). " 1195 printk(KERN_ERR "%s: Unknown controller version (%d). "
1196 "Cowardly refusing to continue.\n", host->slot_descr, 1196 "You may experience problems.\n", host->slot_descr,
1197 version); 1197 version);
1198 ret = -ENODEV;
1199 goto unmap;
1200 } 1198 }
1201 1199
1202 caps = readl(host->ioaddr + SDHCI_CAPABILITIES); 1200 caps = readl(host->ioaddr + SDHCI_CAPABILITIES);
diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c
index 8a30ef3ae419..c351c6d1a18a 100644
--- a/drivers/mmc/wbsd.c
+++ b/drivers/mmc/wbsd.c
@@ -41,7 +41,7 @@
41#include "wbsd.h" 41#include "wbsd.h"
42 42
43#define DRIVER_NAME "wbsd" 43#define DRIVER_NAME "wbsd"
44#define DRIVER_VERSION "1.5" 44#define DRIVER_VERSION "1.6"
45 45
46#define DBG(x...) \ 46#define DBG(x...) \
47 pr_debug(DRIVER_NAME ": " x) 47 pr_debug(DRIVER_NAME ": " x)
@@ -1439,13 +1439,13 @@ static int __devinit wbsd_scan(struct wbsd_host *host)
1439 1439
1440static int __devinit wbsd_request_region(struct wbsd_host *host, int base) 1440static int __devinit wbsd_request_region(struct wbsd_host *host, int base)
1441{ 1441{
1442 if (io & 0x7) 1442 if (base & 0x7)
1443 return -EINVAL; 1443 return -EINVAL;
1444 1444
1445 if (!request_region(base, 8, DRIVER_NAME)) 1445 if (!request_region(base, 8, DRIVER_NAME))
1446 return -EIO; 1446 return -EIO;
1447 1447
1448 host->base = io; 1448 host->base = base;
1449 1449
1450 return 0; 1450 return 0;
1451} 1451}
@@ -1773,7 +1773,7 @@ static int __devinit wbsd_init(struct device *dev, int base, int irq, int dma,
1773 /* 1773 /*
1774 * Request resources. 1774 * Request resources.
1775 */ 1775 */
1776 ret = wbsd_request_resources(host, io, irq, dma); 1776 ret = wbsd_request_resources(host, base, irq, dma);
1777 if (ret) { 1777 if (ret) {
1778 wbsd_release_resources(host); 1778 wbsd_release_resources(host);
1779 wbsd_free_mmc(dev); 1779 wbsd_free_mmc(dev);
@@ -1861,6 +1861,7 @@ static void __devexit wbsd_shutdown(struct device *dev, int pnp)
1861 1861
1862static int __devinit wbsd_probe(struct platform_device *dev) 1862static int __devinit wbsd_probe(struct platform_device *dev)
1863{ 1863{
1864 /* Use the module parameters for resources */
1864 return wbsd_init(&dev->dev, io, irq, dma, 0); 1865 return wbsd_init(&dev->dev, io, irq, dma, 0);
1865} 1866}
1866 1867
diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
index c54e40464d82..603a7951ac9b 100644
--- a/drivers/mtd/devices/doc2000.c
+++ b/drivers/mtd/devices/doc2000.c
@@ -55,10 +55,6 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
55 size_t *retlen, u_char *buf); 55 size_t *retlen, u_char *buf);
56static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, 56static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
57 size_t *retlen, const u_char *buf); 57 size_t *retlen, const u_char *buf);
58static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
59 size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
60static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
61 size_t *retlen, const u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
62static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, 58static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
63 struct mtd_oob_ops *ops); 59 struct mtd_oob_ops *ops);
64static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, 60static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
@@ -615,17 +611,10 @@ EXPORT_SYMBOL_GPL(DoC2k_init);
615static int doc_read(struct mtd_info *mtd, loff_t from, size_t len, 611static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
616 size_t * retlen, u_char * buf) 612 size_t * retlen, u_char * buf)
617{ 613{
618 /* Just a special case of doc_read_ecc */
619 return doc_read_ecc(mtd, from, len, retlen, buf, NULL, NULL);
620}
621
622static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
623 size_t * retlen, u_char * buf, u_char * eccbuf, struct nand_oobinfo *oobsel)
624{
625 struct DiskOnChip *this = mtd->priv; 614 struct DiskOnChip *this = mtd->priv;
626 void __iomem *docptr = this->virtadr; 615 void __iomem *docptr = this->virtadr;
627 struct Nand *mychip; 616 struct Nand *mychip;
628 unsigned char syndrome[6]; 617 unsigned char syndrome[6], eccbuf[6];
629 volatile char dummy; 618 volatile char dummy;
630 int i, len256 = 0, ret=0; 619 int i, len256 = 0, ret=0;
631 size_t left = len; 620 size_t left = len;
@@ -673,15 +662,9 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
673 DoC_Address(this, ADDR_COLUMN_PAGE, from, CDSN_CTRL_WP, 662 DoC_Address(this, ADDR_COLUMN_PAGE, from, CDSN_CTRL_WP,
674 CDSN_CTRL_ECC_IO); 663 CDSN_CTRL_ECC_IO);
675 664
676 if (eccbuf) { 665 /* Prime the ECC engine */
677 /* Prime the ECC engine */ 666 WriteDOC(DOC_ECC_RESET, docptr, ECCConf);
678 WriteDOC(DOC_ECC_RESET, docptr, ECCConf); 667 WriteDOC(DOC_ECC_EN, docptr, ECCConf);
679 WriteDOC(DOC_ECC_EN, docptr, ECCConf);
680 } else {
681 /* disable the ECC engine */
682 WriteDOC(DOC_ECC_RESET, docptr, ECCConf);
683 WriteDOC(DOC_ECC_DIS, docptr, ECCConf);
684 }
685 668
686 /* treat crossing 256-byte sector for 2M x 8bits devices */ 669 /* treat crossing 256-byte sector for 2M x 8bits devices */
687 if (this->page256 && from + len > (from | 0xff) + 1) { 670 if (this->page256 && from + len > (from | 0xff) + 1) {
@@ -698,58 +681,59 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
698 /* Let the caller know we completed it */ 681 /* Let the caller know we completed it */
699 *retlen += len; 682 *retlen += len;
700 683
701 if (eccbuf) { 684 /* Read the ECC data through the DiskOnChip ECC logic */
702 /* Read the ECC data through the DiskOnChip ECC logic */ 685 /* Note: this will work even with 2M x 8bit devices as */
703 /* Note: this will work even with 2M x 8bit devices as */ 686 /* they have 8 bytes of OOB per 256 page. mf. */
704 /* they have 8 bytes of OOB per 256 page. mf. */ 687 DoC_ReadBuf(this, eccbuf, 6);
705 DoC_ReadBuf(this, eccbuf, 6);
706
707 /* Flush the pipeline */
708 if (DoC_is_Millennium(this)) {
709 dummy = ReadDOC(docptr, ECCConf);
710 dummy = ReadDOC(docptr, ECCConf);
711 i = ReadDOC(docptr, ECCConf);
712 } else {
713 dummy = ReadDOC(docptr, 2k_ECCStatus);
714 dummy = ReadDOC(docptr, 2k_ECCStatus);
715 i = ReadDOC(docptr, 2k_ECCStatus);
716 }
717 688
718 /* Check the ECC Status */ 689 /* Flush the pipeline */
719 if (i & 0x80) { 690 if (DoC_is_Millennium(this)) {
720 int nb_errors; 691 dummy = ReadDOC(docptr, ECCConf);
721 /* There was an ECC error */ 692 dummy = ReadDOC(docptr, ECCConf);
693 i = ReadDOC(docptr, ECCConf);
694 } else {
695 dummy = ReadDOC(docptr, 2k_ECCStatus);
696 dummy = ReadDOC(docptr, 2k_ECCStatus);
697 i = ReadDOC(docptr, 2k_ECCStatus);
698 }
699
700 /* Check the ECC Status */
701 if (i & 0x80) {
702 int nb_errors;
703 /* There was an ECC error */
722#ifdef ECC_DEBUG 704#ifdef ECC_DEBUG
723 printk(KERN_ERR "DiskOnChip ECC Error: Read at %lx\n", (long)from); 705 printk(KERN_ERR "DiskOnChip ECC Error: Read at %lx\n", (long)from);
724#endif 706#endif
725 /* Read the ECC syndrom through the DiskOnChip ECC logic. 707 /* Read the ECC syndrom through the DiskOnChip ECC
726 These syndrome will be all ZERO when there is no error */ 708 logic. These syndrome will be all ZERO when there
727 for (i = 0; i < 6; i++) { 709 is no error */
728 syndrome[i] = 710 for (i = 0; i < 6; i++) {
729 ReadDOC(docptr, ECCSyndrome0 + i); 711 syndrome[i] =
730 } 712 ReadDOC(docptr, ECCSyndrome0 + i);
731 nb_errors = doc_decode_ecc(buf, syndrome); 713 }
714 nb_errors = doc_decode_ecc(buf, syndrome);
732 715
733#ifdef ECC_DEBUG 716#ifdef ECC_DEBUG
734 printk(KERN_ERR "Errors corrected: %x\n", nb_errors); 717 printk(KERN_ERR "Errors corrected: %x\n", nb_errors);
735#endif 718#endif
736 if (nb_errors < 0) { 719 if (nb_errors < 0) {
737 /* We return error, but have actually done the read. Not that 720 /* We return error, but have actually done the
738 this can be told to user-space, via sys_read(), but at least 721 read. Not that this can be told to
739 MTD-aware stuff can know about it by checking *retlen */ 722 user-space, via sys_read(), but at least
740 ret = -EIO; 723 MTD-aware stuff can know about it by
741 } 724 checking *retlen */
725 ret = -EIO;
742 } 726 }
727 }
743 728
744#ifdef PSYCHO_DEBUG 729#ifdef PSYCHO_DEBUG
745 printk(KERN_DEBUG "ECC DATA at %lxB: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n", 730 printk(KERN_DEBUG "ECC DATA at %lxB: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
746 (long)from, eccbuf[0], eccbuf[1], eccbuf[2], 731 (long)from, eccbuf[0], eccbuf[1], eccbuf[2],
747 eccbuf[3], eccbuf[4], eccbuf[5]); 732 eccbuf[3], eccbuf[4], eccbuf[5]);
748#endif 733#endif
749 734
750 /* disable the ECC engine */ 735 /* disable the ECC engine */
751 WriteDOC(DOC_ECC_DIS, docptr , ECCConf); 736 WriteDOC(DOC_ECC_DIS, docptr , ECCConf);
752 }
753 737
754 /* according to 11.4.1, we need to wait for the busy line 738 /* according to 11.4.1, we need to wait for the busy line
755 * drop if we read to the end of the page. */ 739 * drop if we read to the end of the page. */
@@ -771,17 +755,10 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
771static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, 755static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
772 size_t * retlen, const u_char * buf) 756 size_t * retlen, const u_char * buf)
773{ 757{
774 char eccbuf[6];
775 return doc_write_ecc(mtd, to, len, retlen, buf, eccbuf, NULL);
776}
777
778static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
779 size_t * retlen, const u_char * buf,
780 u_char * eccbuf, struct nand_oobinfo *oobsel)
781{
782 struct DiskOnChip *this = mtd->priv; 758 struct DiskOnChip *this = mtd->priv;
783 int di; /* Yes, DI is a hangover from when I was disassembling the binary driver */ 759 int di; /* Yes, DI is a hangover from when I was disassembling the binary driver */
784 void __iomem *docptr = this->virtadr; 760 void __iomem *docptr = this->virtadr;
761 unsigned char eccbuf[6];
785 volatile char dummy; 762 volatile char dummy;
786 int len256 = 0; 763 int len256 = 0;
787 struct Nand *mychip; 764 struct Nand *mychip;
@@ -835,15 +812,9 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
835 DoC_Command(this, NAND_CMD_SEQIN, 0); 812 DoC_Command(this, NAND_CMD_SEQIN, 0);
836 DoC_Address(this, ADDR_COLUMN_PAGE, to, 0, CDSN_CTRL_ECC_IO); 813 DoC_Address(this, ADDR_COLUMN_PAGE, to, 0, CDSN_CTRL_ECC_IO);
837 814
838 if (eccbuf) { 815 /* Prime the ECC engine */
839 /* Prime the ECC engine */ 816 WriteDOC(DOC_ECC_RESET, docptr, ECCConf);
840 WriteDOC(DOC_ECC_RESET, docptr, ECCConf); 817 WriteDOC(DOC_ECC_EN | DOC_ECC_RW, docptr, ECCConf);
841 WriteDOC(DOC_ECC_EN | DOC_ECC_RW, docptr, ECCConf);
842 } else {
843 /* disable the ECC engine */
844 WriteDOC(DOC_ECC_RESET, docptr, ECCConf);
845 WriteDOC(DOC_ECC_DIS, docptr, ECCConf);
846 }
847 818
848 /* treat crossing 256-byte sector for 2M x 8bits devices */ 819 /* treat crossing 256-byte sector for 2M x 8bits devices */
849 if (this->page256 && to + len > (to | 0xff) + 1) { 820 if (this->page256 && to + len > (to | 0xff) + 1) {
@@ -873,39 +844,35 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
873 844
874 DoC_WriteBuf(this, &buf[len256], len - len256); 845 DoC_WriteBuf(this, &buf[len256], len - len256);
875 846
876 if (eccbuf) { 847 WriteDOC(CDSN_CTRL_ECC_IO | CDSN_CTRL_CE, docptr, CDSNControl);
877 WriteDOC(CDSN_CTRL_ECC_IO | CDSN_CTRL_CE, docptr,
878 CDSNControl);
879
880 if (DoC_is_Millennium(this)) {
881 WriteDOC(0, docptr, NOP);
882 WriteDOC(0, docptr, NOP);
883 WriteDOC(0, docptr, NOP);
884 } else {
885 WriteDOC_(0, docptr, this->ioreg);
886 WriteDOC_(0, docptr, this->ioreg);
887 WriteDOC_(0, docptr, this->ioreg);
888 }
889 848
890 WriteDOC(CDSN_CTRL_ECC_IO | CDSN_CTRL_FLASH_IO | CDSN_CTRL_CE, docptr, 849 if (DoC_is_Millennium(this)) {
891 CDSNControl); 850 WriteDOC(0, docptr, NOP);
851 WriteDOC(0, docptr, NOP);
852 WriteDOC(0, docptr, NOP);
853 } else {
854 WriteDOC_(0, docptr, this->ioreg);
855 WriteDOC_(0, docptr, this->ioreg);
856 WriteDOC_(0, docptr, this->ioreg);
857 }
892 858
893 /* Read the ECC data through the DiskOnChip ECC logic */ 859 WriteDOC(CDSN_CTRL_ECC_IO | CDSN_CTRL_FLASH_IO | CDSN_CTRL_CE, docptr,
894 for (di = 0; di < 6; di++) { 860 CDSNControl);
895 eccbuf[di] = ReadDOC(docptr, ECCSyndrome0 + di);
896 }
897 861
898 /* Reset the ECC engine */ 862 /* Read the ECC data through the DiskOnChip ECC logic */
899 WriteDOC(DOC_ECC_DIS, docptr, ECCConf); 863 for (di = 0; di < 6; di++) {
864 eccbuf[di] = ReadDOC(docptr, ECCSyndrome0 + di);
865 }
866
867 /* Reset the ECC engine */
868 WriteDOC(DOC_ECC_DIS, docptr, ECCConf);
900 869
901#ifdef PSYCHO_DEBUG 870#ifdef PSYCHO_DEBUG
902 printk 871 printk
903 ("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n", 872 ("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
904 (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3], 873 (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],
905 eccbuf[4], eccbuf[5]); 874 eccbuf[4], eccbuf[5]);
906#endif 875#endif
907 }
908
909 DoC_Command(this, NAND_CMD_PAGEPROG, 0); 876 DoC_Command(this, NAND_CMD_PAGEPROG, 0);
910 877
911 DoC_Command(this, NAND_CMD_STATUS, CDSN_CTRL_WP); 878 DoC_Command(this, NAND_CMD_STATUS, CDSN_CTRL_WP);
diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
index 0cf022a69e65..0e2a9326f717 100644
--- a/drivers/mtd/devices/doc2001.c
+++ b/drivers/mtd/devices/doc2001.c
@@ -37,12 +37,6 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
37 size_t *retlen, u_char *buf); 37 size_t *retlen, u_char *buf);
38static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, 38static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39 size_t *retlen, const u_char *buf); 39 size_t *retlen, const u_char *buf);
40static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
41 size_t *retlen, u_char *buf, u_char *eccbuf,
42 struct nand_oobinfo *oobsel);
43static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
44 size_t *retlen, const u_char *buf, u_char *eccbuf,
45 struct nand_oobinfo *oobsel);
46static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, 40static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
47 struct mtd_oob_ops *ops); 41 struct mtd_oob_ops *ops);
48static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, 42static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
@@ -397,17 +391,9 @@ EXPORT_SYMBOL_GPL(DoCMil_init);
397static int doc_read (struct mtd_info *mtd, loff_t from, size_t len, 391static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
398 size_t *retlen, u_char *buf) 392 size_t *retlen, u_char *buf)
399{ 393{
400 /* Just a special case of doc_read_ecc */
401 return doc_read_ecc(mtd, from, len, retlen, buf, NULL, NULL);
402}
403
404static int doc_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
405 size_t *retlen, u_char *buf, u_char *eccbuf,
406 struct nand_oobinfo *oobsel)
407{
408 int i, ret; 394 int i, ret;
409 volatile char dummy; 395 volatile char dummy;
410 unsigned char syndrome[6]; 396 unsigned char syndrome[6], eccbuf[6];
411 struct DiskOnChip *this = mtd->priv; 397 struct DiskOnChip *this = mtd->priv;
412 void __iomem *docptr = this->virtadr; 398 void __iomem *docptr = this->virtadr;
413 struct Nand *mychip = &this->chips[from >> (this->chipshift)]; 399 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
@@ -437,15 +423,9 @@ static int doc_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
437 DoC_Address(docptr, 3, from, CDSN_CTRL_WP, 0x00); 423 DoC_Address(docptr, 3, from, CDSN_CTRL_WP, 0x00);
438 DoC_WaitReady(docptr); 424 DoC_WaitReady(docptr);
439 425
440 if (eccbuf) { 426 /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/
441 /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/ 427 WriteDOC (DOC_ECC_RESET, docptr, ECCConf);
442 WriteDOC (DOC_ECC_RESET, docptr, ECCConf); 428 WriteDOC (DOC_ECC_EN, docptr, ECCConf);
443 WriteDOC (DOC_ECC_EN, docptr, ECCConf);
444 } else {
445 /* disable the ECC engine */
446 WriteDOC (DOC_ECC_RESET, docptr, ECCConf);
447 WriteDOC (DOC_ECC_DIS, docptr, ECCConf);
448 }
449 429
450 /* Read the data via the internal pipeline through CDSN IO register, 430 /* Read the data via the internal pipeline through CDSN IO register,
451 see Pipelined Read Operations 11.3 */ 431 see Pipelined Read Operations 11.3 */
@@ -465,58 +445,56 @@ static int doc_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
465 *retlen = len; 445 *retlen = len;
466 ret = 0; 446 ret = 0;
467 447
468 if (eccbuf) { 448 /* Read the ECC data from Spare Data Area,
469 /* Read the ECC data from Spare Data Area, 449 see Reed-Solomon EDC/ECC 11.1 */
470 see Reed-Solomon EDC/ECC 11.1 */ 450 dummy = ReadDOC(docptr, ReadPipeInit);
471 dummy = ReadDOC(docptr, ReadPipeInit);
472#ifndef USE_MEMCPY 451#ifndef USE_MEMCPY
473 for (i = 0; i < 5; i++) { 452 for (i = 0; i < 5; i++) {
474 /* N.B. you have to increase the source address in this way or the 453 /* N.B. you have to increase the source address in this way or the
475 ECC logic will not work properly */ 454 ECC logic will not work properly */
476 eccbuf[i] = ReadDOC(docptr, Mil_CDSN_IO + i); 455 eccbuf[i] = ReadDOC(docptr, Mil_CDSN_IO + i);
477 } 456 }
478#else 457#else
479 memcpy_fromio(eccbuf, docptr + DoC_Mil_CDSN_IO, 5); 458 memcpy_fromio(eccbuf, docptr + DoC_Mil_CDSN_IO, 5);
480#endif 459#endif
481 eccbuf[5] = ReadDOC(docptr, LastDataRead); 460 eccbuf[5] = ReadDOC(docptr, LastDataRead);
482 461
483 /* Flush the pipeline */ 462 /* Flush the pipeline */
484 dummy = ReadDOC(docptr, ECCConf); 463 dummy = ReadDOC(docptr, ECCConf);
485 dummy = ReadDOC(docptr, ECCConf); 464 dummy = ReadDOC(docptr, ECCConf);
486 465
487 /* Check the ECC Status */ 466 /* Check the ECC Status */
488 if (ReadDOC(docptr, ECCConf) & 0x80) { 467 if (ReadDOC(docptr, ECCConf) & 0x80) {
489 int nb_errors; 468 int nb_errors;
490 /* There was an ECC error */ 469 /* There was an ECC error */
491#ifdef ECC_DEBUG 470#ifdef ECC_DEBUG
492 printk("DiskOnChip ECC Error: Read at %lx\n", (long)from); 471 printk("DiskOnChip ECC Error: Read at %lx\n", (long)from);
493#endif 472#endif
494 /* Read the ECC syndrom through the DiskOnChip ECC logic. 473 /* Read the ECC syndrom through the DiskOnChip ECC logic.
495 These syndrome will be all ZERO when there is no error */ 474 These syndrome will be all ZERO when there is no error */
496 for (i = 0; i < 6; i++) { 475 for (i = 0; i < 6; i++) {
497 syndrome[i] = ReadDOC(docptr, ECCSyndrome0 + i); 476 syndrome[i] = ReadDOC(docptr, ECCSyndrome0 + i);
498 } 477 }
499 nb_errors = doc_decode_ecc(buf, syndrome); 478 nb_errors = doc_decode_ecc(buf, syndrome);
500#ifdef ECC_DEBUG 479#ifdef ECC_DEBUG
501 printk("ECC Errors corrected: %x\n", nb_errors); 480 printk("ECC Errors corrected: %x\n", nb_errors);
502#endif 481#endif
503 if (nb_errors < 0) { 482 if (nb_errors < 0) {
504 /* We return error, but have actually done the read. Not that 483 /* We return error, but have actually done the read. Not that
505 this can be told to user-space, via sys_read(), but at least 484 this can be told to user-space, via sys_read(), but at least
506 MTD-aware stuff can know about it by checking *retlen */ 485 MTD-aware stuff can know about it by checking *retlen */
507 ret = -EIO; 486 ret = -EIO;
508 }
509 } 487 }
488 }
510 489
511#ifdef PSYCHO_DEBUG 490#ifdef PSYCHO_DEBUG
512 printk("ECC DATA at %lx: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n", 491 printk("ECC DATA at %lx: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
513 (long)from, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3], 492 (long)from, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],
514 eccbuf[4], eccbuf[5]); 493 eccbuf[4], eccbuf[5]);
515#endif 494#endif
516 495
517 /* disable the ECC engine */ 496 /* disable the ECC engine */
518 WriteDOC(DOC_ECC_DIS, docptr , ECCConf); 497 WriteDOC(DOC_ECC_DIS, docptr , ECCConf);
519 }
520 498
521 return ret; 499 return ret;
522} 500}
@@ -524,15 +502,8 @@ static int doc_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
524static int doc_write (struct mtd_info *mtd, loff_t to, size_t len, 502static int doc_write (struct mtd_info *mtd, loff_t to, size_t len,
525 size_t *retlen, const u_char *buf) 503 size_t *retlen, const u_char *buf)
526{ 504{
527 char eccbuf[6];
528 return doc_write_ecc(mtd, to, len, retlen, buf, eccbuf, NULL);
529}
530
531static int doc_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
532 size_t *retlen, const u_char *buf, u_char *eccbuf,
533 struct nand_oobinfo *oobsel)
534{
535 int i,ret = 0; 505 int i,ret = 0;
506 char eccbuf[6];
536 volatile char dummy; 507 volatile char dummy;
537 struct DiskOnChip *this = mtd->priv; 508 struct DiskOnChip *this = mtd->priv;
538 void __iomem *docptr = this->virtadr; 509 void __iomem *docptr = this->virtadr;
@@ -573,15 +544,9 @@ static int doc_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
573 DoC_Address(docptr, 3, to, 0x00, 0x00); 544 DoC_Address(docptr, 3, to, 0x00, 0x00);
574 DoC_WaitReady(docptr); 545 DoC_WaitReady(docptr);
575 546
576 if (eccbuf) { 547 /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/
577 /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/ 548 WriteDOC (DOC_ECC_RESET, docptr, ECCConf);
578 WriteDOC (DOC_ECC_RESET, docptr, ECCConf); 549 WriteDOC (DOC_ECC_EN | DOC_ECC_RW, docptr, ECCConf);
579 WriteDOC (DOC_ECC_EN | DOC_ECC_RW, docptr, ECCConf);
580 } else {
581 /* disable the ECC engine */
582 WriteDOC (DOC_ECC_RESET, docptr, ECCConf);
583 WriteDOC (DOC_ECC_DIS, docptr, ECCConf);
584 }
585 550
586 /* Write the data via the internal pipeline through CDSN IO register, 551 /* Write the data via the internal pipeline through CDSN IO register,
587 see Pipelined Write Operations 11.2 */ 552 see Pipelined Write Operations 11.2 */
@@ -596,46 +561,44 @@ static int doc_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
596#endif 561#endif
597 WriteDOC(0x00, docptr, WritePipeTerm); 562 WriteDOC(0x00, docptr, WritePipeTerm);
598 563
599 if (eccbuf) { 564 /* Write ECC data to flash, the ECC info is generated by the DiskOnChip ECC logic
600 /* Write ECC data to flash, the ECC info is generated by the DiskOnChip ECC logic 565 see Reed-Solomon EDC/ECC 11.1 */
601 see Reed-Solomon EDC/ECC 11.1 */ 566 WriteDOC(0, docptr, NOP);
602 WriteDOC(0, docptr, NOP); 567 WriteDOC(0, docptr, NOP);
603 WriteDOC(0, docptr, NOP); 568 WriteDOC(0, docptr, NOP);
604 WriteDOC(0, docptr, NOP);
605 569
606 /* Read the ECC data through the DiskOnChip ECC logic */ 570 /* Read the ECC data through the DiskOnChip ECC logic */
607 for (i = 0; i < 6; i++) { 571 for (i = 0; i < 6; i++) {
608 eccbuf[i] = ReadDOC(docptr, ECCSyndrome0 + i); 572 eccbuf[i] = ReadDOC(docptr, ECCSyndrome0 + i);
609 } 573 }
610 574
611 /* ignore the ECC engine */ 575 /* ignore the ECC engine */
612 WriteDOC(DOC_ECC_DIS, docptr , ECCConf); 576 WriteDOC(DOC_ECC_DIS, docptr , ECCConf);
613 577
614#ifndef USE_MEMCPY 578#ifndef USE_MEMCPY
615 /* Write the ECC data to flash */ 579 /* Write the ECC data to flash */
616 for (i = 0; i < 6; i++) { 580 for (i = 0; i < 6; i++) {
617 /* N.B. you have to increase the source address in this way or the 581 /* N.B. you have to increase the source address in this way or the
618 ECC logic will not work properly */ 582 ECC logic will not work properly */
619 WriteDOC(eccbuf[i], docptr, Mil_CDSN_IO + i); 583 WriteDOC(eccbuf[i], docptr, Mil_CDSN_IO + i);
620 } 584 }
621#else 585#else
622 memcpy_toio(docptr + DoC_Mil_CDSN_IO, eccbuf, 6); 586 memcpy_toio(docptr + DoC_Mil_CDSN_IO, eccbuf, 6);
623#endif 587#endif
624 588
625 /* write the block status BLOCK_USED (0x5555) at the end of ECC data 589 /* write the block status BLOCK_USED (0x5555) at the end of ECC data
626 FIXME: this is only a hack for programming the IPL area for LinuxBIOS 590 FIXME: this is only a hack for programming the IPL area for LinuxBIOS
627 and should be replace with proper codes in user space utilities */ 591 and should be replace with proper codes in user space utilities */
628 WriteDOC(0x55, docptr, Mil_CDSN_IO); 592 WriteDOC(0x55, docptr, Mil_CDSN_IO);
629 WriteDOC(0x55, docptr, Mil_CDSN_IO + 1); 593 WriteDOC(0x55, docptr, Mil_CDSN_IO + 1);
630 594
631 WriteDOC(0x00, docptr, WritePipeTerm); 595 WriteDOC(0x00, docptr, WritePipeTerm);
632 596
633#ifdef PSYCHO_DEBUG 597#ifdef PSYCHO_DEBUG
634 printk("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n", 598 printk("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
635 (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3], 599 (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],
636 eccbuf[4], eccbuf[5]); 600 eccbuf[4], eccbuf[5]);
637#endif 601#endif
638 }
639 602
640 /* Commit the Page Program command and wait for ready 603 /* Commit the Page Program command and wait for ready
641 see Software Requirement 11.4 item 1.*/ 604 see Software Requirement 11.4 item 1.*/
diff --git a/drivers/mtd/devices/doc2001plus.c b/drivers/mtd/devices/doc2001plus.c
index 66cb1e50469a..92dbb47f2ac3 100644
--- a/drivers/mtd/devices/doc2001plus.c
+++ b/drivers/mtd/devices/doc2001plus.c
@@ -41,12 +41,6 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
41 size_t *retlen, u_char *buf); 41 size_t *retlen, u_char *buf);
42static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, 42static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
43 size_t *retlen, const u_char *buf); 43 size_t *retlen, const u_char *buf);
44static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
45 size_t *retlen, u_char *buf, u_char *eccbuf,
46 struct nand_oobinfo *oobsel);
47static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
48 size_t *retlen, const u_char *buf, u_char *eccbuf,
49 struct nand_oobinfo *oobsel);
50static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, 44static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
51 struct mtd_oob_ops *ops); 45 struct mtd_oob_ops *ops);
52static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, 46static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
@@ -595,18 +589,10 @@ static int doc_dumpblk(struct mtd_info *mtd, loff_t from)
595static int doc_read(struct mtd_info *mtd, loff_t from, size_t len, 589static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
596 size_t *retlen, u_char *buf) 590 size_t *retlen, u_char *buf)
597{ 591{
598 /* Just a special case of doc_read_ecc */
599 return doc_read_ecc(mtd, from, len, retlen, buf, NULL, NULL);
600}
601
602static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
603 size_t *retlen, u_char *buf, u_char *eccbuf,
604 struct nand_oobinfo *oobsel)
605{
606 int ret, i; 592 int ret, i;
607 volatile char dummy; 593 volatile char dummy;
608 loff_t fofs; 594 loff_t fofs;
609 unsigned char syndrome[6]; 595 unsigned char syndrome[6], eccbuf[6];
610 struct DiskOnChip *this = mtd->priv; 596 struct DiskOnChip *this = mtd->priv;
611 void __iomem * docptr = this->virtadr; 597 void __iomem * docptr = this->virtadr;
612 struct Nand *mychip = &this->chips[from >> (this->chipshift)]; 598 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
@@ -644,56 +630,51 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
644 WriteDOC(0, docptr, Mplus_FlashControl); 630 WriteDOC(0, docptr, Mplus_FlashControl);
645 DoC_WaitReady(docptr); 631 DoC_WaitReady(docptr);
646 632
647 if (eccbuf) { 633 /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/
648 /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/ 634 WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
649 WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf); 635 WriteDOC(DOC_ECC_EN, docptr, Mplus_ECCConf);
650 WriteDOC(DOC_ECC_EN, docptr, Mplus_ECCConf);
651 } else {
652 /* disable the ECC engine */
653 WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
654 }
655 636
656 /* Let the caller know we completed it */ 637 /* Let the caller know we completed it */
657 *retlen = len; 638 *retlen = len;
658 ret = 0; 639 ret = 0;
659 640
660 ReadDOC(docptr, Mplus_ReadPipeInit); 641 ReadDOC(docptr, Mplus_ReadPipeInit);
661 ReadDOC(docptr, Mplus_ReadPipeInit); 642 ReadDOC(docptr, Mplus_ReadPipeInit);
662 643
663 if (eccbuf) { 644 /* Read the data via the internal pipeline through CDSN IO
664 /* Read the data via the internal pipeline through CDSN IO 645 register, see Pipelined Read Operations 11.3 */
665 register, see Pipelined Read Operations 11.3 */ 646 MemReadDOC(docptr, buf, len);
666 MemReadDOC(docptr, buf, len);
667 647
668 /* Read the ECC data following raw data */ 648 /* Read the ECC data following raw data */
669 MemReadDOC(docptr, eccbuf, 4); 649 MemReadDOC(docptr, eccbuf, 4);
670 eccbuf[4] = ReadDOC(docptr, Mplus_LastDataRead); 650 eccbuf[4] = ReadDOC(docptr, Mplus_LastDataRead);
671 eccbuf[5] = ReadDOC(docptr, Mplus_LastDataRead); 651 eccbuf[5] = ReadDOC(docptr, Mplus_LastDataRead);
672 652
673 /* Flush the pipeline */ 653 /* Flush the pipeline */
674 dummy = ReadDOC(docptr, Mplus_ECCConf); 654 dummy = ReadDOC(docptr, Mplus_ECCConf);
675 dummy = ReadDOC(docptr, Mplus_ECCConf); 655 dummy = ReadDOC(docptr, Mplus_ECCConf);
676 656
677 /* Check the ECC Status */ 657 /* Check the ECC Status */
678 if (ReadDOC(docptr, Mplus_ECCConf) & 0x80) { 658 if (ReadDOC(docptr, Mplus_ECCConf) & 0x80) {
679 int nb_errors; 659 int nb_errors;
680 /* There was an ECC error */ 660 /* There was an ECC error */
681#ifdef ECC_DEBUG 661#ifdef ECC_DEBUG
682 printk("DiskOnChip ECC Error: Read at %lx\n", (long)from); 662 printk("DiskOnChip ECC Error: Read at %lx\n", (long)from);
683#endif 663#endif
684 /* Read the ECC syndrom through the DiskOnChip ECC logic. 664 /* Read the ECC syndrom through the DiskOnChip ECC logic.
685 These syndrome will be all ZERO when there is no error */ 665 These syndrome will be all ZERO when there is no error */
686 for (i = 0; i < 6; i++) 666 for (i = 0; i < 6; i++)
687 syndrome[i] = ReadDOC(docptr, Mplus_ECCSyndrome0 + i); 667 syndrome[i] = ReadDOC(docptr, Mplus_ECCSyndrome0 + i);
688 668
689 nb_errors = doc_decode_ecc(buf, syndrome); 669 nb_errors = doc_decode_ecc(buf, syndrome);
690#ifdef ECC_DEBUG 670#ifdef ECC_DEBUG
691 printk("ECC Errors corrected: %x\n", nb_errors); 671 printk("ECC Errors corrected: %x\n", nb_errors);
692#endif 672#endif
693 if (nb_errors < 0) { 673 if (nb_errors < 0) {
694 /* We return error, but have actually done the read. Not that 674 /* We return error, but have actually done the
695 this can be told to user-space, via sys_read(), but at least 675 read. Not that this can be told to user-space, via
696 MTD-aware stuff can know about it by checking *retlen */ 676 sys_read(), but at least MTD-aware stuff can know
677 about it by checking *retlen */
697#ifdef ECC_DEBUG 678#ifdef ECC_DEBUG
698 printk("%s(%d): Millennium Plus ECC error (from=0x%x:\n", 679 printk("%s(%d): Millennium Plus ECC error (from=0x%x:\n",
699 __FILE__, __LINE__, (int)from); 680 __FILE__, __LINE__, (int)from);
@@ -707,24 +688,16 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
707 eccbuf[3], eccbuf[4], eccbuf[5]); 688 eccbuf[3], eccbuf[4], eccbuf[5]);
708#endif 689#endif
709 ret = -EIO; 690 ret = -EIO;
710 }
711 } 691 }
692 }
712 693
713#ifdef PSYCHO_DEBUG 694#ifdef PSYCHO_DEBUG
714 printk("ECC DATA at %lx: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n", 695 printk("ECC DATA at %lx: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
715 (long)from, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3], 696 (long)from, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],
716 eccbuf[4], eccbuf[5]); 697 eccbuf[4], eccbuf[5]);
717#endif 698#endif
718 699 /* disable the ECC engine */
719 /* disable the ECC engine */ 700 WriteDOC(DOC_ECC_DIS, docptr , Mplus_ECCConf);
720 WriteDOC(DOC_ECC_DIS, docptr , Mplus_ECCConf);
721 } else {
722 /* Read the data via the internal pipeline through CDSN IO
723 register, see Pipelined Read Operations 11.3 */
724 MemReadDOC(docptr, buf, len-2);
725 buf[len-2] = ReadDOC(docptr, Mplus_LastDataRead);
726 buf[len-1] = ReadDOC(docptr, Mplus_LastDataRead);
727 }
728 701
729 /* Disable flash internally */ 702 /* Disable flash internally */
730 WriteDOC(0, docptr, Mplus_FlashSelect); 703 WriteDOC(0, docptr, Mplus_FlashSelect);
@@ -735,17 +708,10 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
735static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, 708static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
736 size_t *retlen, const u_char *buf) 709 size_t *retlen, const u_char *buf)
737{ 710{
738 char eccbuf[6];
739 return doc_write_ecc(mtd, to, len, retlen, buf, eccbuf, NULL);
740}
741
742static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
743 size_t *retlen, const u_char *buf, u_char *eccbuf,
744 struct nand_oobinfo *oobsel)
745{
746 int i, before, ret = 0; 711 int i, before, ret = 0;
747 loff_t fto; 712 loff_t fto;
748 volatile char dummy; 713 volatile char dummy;
714 char eccbuf[6];
749 struct DiskOnChip *this = mtd->priv; 715 struct DiskOnChip *this = mtd->priv;
750 void __iomem * docptr = this->virtadr; 716 void __iomem * docptr = this->virtadr;
751 struct Nand *mychip = &this->chips[to >> (this->chipshift)]; 717 struct Nand *mychip = &this->chips[to >> (this->chipshift)];
@@ -795,46 +761,42 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
795 /* Disable the ECC engine */ 761 /* Disable the ECC engine */
796 WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf); 762 WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
797 763
798 if (eccbuf) { 764 if (before) {
799 if (before) { 765 /* Write the block status BLOCK_USED (0x5555) */
800 /* Write the block status BLOCK_USED (0x5555) */ 766 WriteDOC(0x55, docptr, Mil_CDSN_IO);
801 WriteDOC(0x55, docptr, Mil_CDSN_IO); 767 WriteDOC(0x55, docptr, Mil_CDSN_IO);
802 WriteDOC(0x55, docptr, Mil_CDSN_IO);
803 }
804
805 /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/
806 WriteDOC(DOC_ECC_EN | DOC_ECC_RW, docptr, Mplus_ECCConf);
807 } 768 }
808 769
770 /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/
771 WriteDOC(DOC_ECC_EN | DOC_ECC_RW, docptr, Mplus_ECCConf);
772
809 MemWriteDOC(docptr, (unsigned char *) buf, len); 773 MemWriteDOC(docptr, (unsigned char *) buf, len);
810 774
811 if (eccbuf) { 775 /* Write ECC data to flash, the ECC info is generated by
812 /* Write ECC data to flash, the ECC info is generated by 776 the DiskOnChip ECC logic see Reed-Solomon EDC/ECC 11.1 */
813 the DiskOnChip ECC logic see Reed-Solomon EDC/ECC 11.1 */ 777 DoC_Delay(docptr, 3);
814 DoC_Delay(docptr, 3);
815 778
816 /* Read the ECC data through the DiskOnChip ECC logic */ 779 /* Read the ECC data through the DiskOnChip ECC logic */
817 for (i = 0; i < 6; i++) 780 for (i = 0; i < 6; i++)
818 eccbuf[i] = ReadDOC(docptr, Mplus_ECCSyndrome0 + i); 781 eccbuf[i] = ReadDOC(docptr, Mplus_ECCSyndrome0 + i);
819 782
820 /* disable the ECC engine */ 783 /* disable the ECC engine */
821 WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf); 784 WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf);
822 785
823 /* Write the ECC data to flash */ 786 /* Write the ECC data to flash */
824 MemWriteDOC(docptr, eccbuf, 6); 787 MemWriteDOC(docptr, eccbuf, 6);
825 788
826 if (!before) { 789 if (!before) {
827 /* Write the block status BLOCK_USED (0x5555) */ 790 /* Write the block status BLOCK_USED (0x5555) */
828 WriteDOC(0x55, docptr, Mil_CDSN_IO+6); 791 WriteDOC(0x55, docptr, Mil_CDSN_IO+6);
829 WriteDOC(0x55, docptr, Mil_CDSN_IO+7); 792 WriteDOC(0x55, docptr, Mil_CDSN_IO+7);
830 } 793 }
831 794
832#ifdef PSYCHO_DEBUG 795#ifdef PSYCHO_DEBUG
833 printk("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n", 796 printk("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
834 (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3], 797 (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],
835 eccbuf[4], eccbuf[5]); 798 eccbuf[4], eccbuf[5]);
836#endif 799#endif
837 }
838 800
839 WriteDOC(0x00, docptr, Mplus_WritePipeTerm); 801 WriteDOC(0x00, docptr, Mplus_WritePipeTerm);
840 WriteDOC(0x00, docptr, Mplus_WritePipeTerm); 802 WriteDOC(0x00, docptr, Mplus_WritePipeTerm);
diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
index d7897dc6b3c8..a0ba07c36ee9 100644
--- a/drivers/mtd/nand/ams-delta.c
+++ b/drivers/mtd/nand/ams-delta.c
@@ -130,11 +130,13 @@ static void ams_delta_hwcontrol(struct mtd_info *mtd, int cmd,
130 if (ctrl & NAND_CTRL_CHANGE) { 130 if (ctrl & NAND_CTRL_CHANGE) {
131 unsigned long bits; 131 unsigned long bits;
132 132
133 bits = (~ctrl & NAND_NCE) << 2; 133 bits = (~ctrl & NAND_NCE) ? AMS_DELTA_LATCH2_NAND_NCE : 0;
134 bits |= (ctrl & NAND_CLE) << 7; 134 bits |= (ctrl & NAND_CLE) ? AMS_DELTA_LATCH2_NAND_CLE : 0;
135 bits |= (ctrl & NAND_ALE) << 6; 135 bits |= (ctrl & NAND_ALE) ? AMS_DELTA_LATCH2_NAND_ALE : 0;
136 136
137 ams_delta_latch2_write(0xC2, bits); 137 ams_delta_latch2_write(AMS_DELTA_LATCH2_NAND_CLE |
138 AMS_DELTA_LATCH2_NAND_ALE |
139 AMS_DELTA_LATCH2_NAND_NCE, bits);
138 } 140 }
139 141
140 if (cmd != NAND_CMD_NONE) 142 if (cmd != NAND_CMD_NONE)
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 80a76654d963..0a54d003ef34 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -155,7 +155,7 @@ static u16 nand_read_word(struct mtd_info *mtd)
155/** 155/**
156 * nand_select_chip - [DEFAULT] control CE line 156 * nand_select_chip - [DEFAULT] control CE line
157 * @mtd: MTD device structure 157 * @mtd: MTD device structure
158 * @chip: chipnumber to select, -1 for deselect 158 * @chipnr: chipnumber to select, -1 for deselect
159 * 159 *
160 * Default select function for 1 chip devices. 160 * Default select function for 1 chip devices.
161 */ 161 */
@@ -542,7 +542,6 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
542 * Send command to NAND device. This is the version for the new large page 542 * Send command to NAND device. This is the version for the new large page
543 * devices We dont have the separate regions as we have in the small page 543 * devices We dont have the separate regions as we have in the small page
544 * devices. We must emulate NAND_CMD_READOOB to keep the code compatible. 544 * devices. We must emulate NAND_CMD_READOOB to keep the code compatible.
545 *
546 */ 545 */
547static void nand_command_lp(struct mtd_info *mtd, unsigned int command, 546static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
548 int column, int page_addr) 547 int column, int page_addr)
@@ -656,7 +655,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
656 655
657/** 656/**
658 * nand_get_device - [GENERIC] Get chip for selected access 657 * nand_get_device - [GENERIC] Get chip for selected access
659 * @this: the nand chip descriptor 658 * @chip: the nand chip descriptor
660 * @mtd: MTD device structure 659 * @mtd: MTD device structure
661 * @new_state: the state which is requested 660 * @new_state: the state which is requested
662 * 661 *
@@ -696,13 +695,12 @@ nand_get_device(struct nand_chip *chip, struct mtd_info *mtd, int new_state)
696/** 695/**
697 * nand_wait - [DEFAULT] wait until the command is done 696 * nand_wait - [DEFAULT] wait until the command is done
698 * @mtd: MTD device structure 697 * @mtd: MTD device structure
699 * @this: NAND chip structure 698 * @chip: NAND chip structure
700 * 699 *
701 * Wait for command done. This applies to erase and program only 700 * Wait for command done. This applies to erase and program only
702 * Erase can take up to 400ms and program up to 20ms according to 701 * Erase can take up to 400ms and program up to 20ms according to
703 * general NAND and SmartMedia specs 702 * general NAND and SmartMedia specs
704 * 703 */
705*/
706static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip) 704static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
707{ 705{
708 706
@@ -896,6 +894,7 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
896/** 894/**
897 * nand_transfer_oob - [Internal] Transfer oob to client buffer 895 * nand_transfer_oob - [Internal] Transfer oob to client buffer
898 * @chip: nand chip structure 896 * @chip: nand chip structure
897 * @oob: oob destination address
899 * @ops: oob ops structure 898 * @ops: oob ops structure
900 */ 899 */
901static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob, 900static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob,
@@ -946,6 +945,7 @@ static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob,
946 * 945 *
947 * @mtd: MTD device structure 946 * @mtd: MTD device structure
948 * @from: offset to read from 947 * @from: offset to read from
948 * @ops: oob ops structure
949 * 949 *
950 * Internal function. Called with chip held. 950 * Internal function. Called with chip held.
951 */ 951 */
@@ -1093,9 +1093,10 @@ static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
1093 1093
1094 ret = nand_do_read_ops(mtd, from, &chip->ops); 1094 ret = nand_do_read_ops(mtd, from, &chip->ops);
1095 1095
1096 *retlen = chip->ops.retlen;
1097
1096 nand_release_device(mtd); 1098 nand_release_device(mtd);
1097 1099
1098 *retlen = chip->ops.retlen;
1099 return ret; 1100 return ret;
1100} 1101}
1101 1102
@@ -1203,7 +1204,7 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd,
1203 pos = steps * (eccsize + chunk); 1204 pos = steps * (eccsize + chunk);
1204 steps = 0; 1205 steps = 0;
1205 } else 1206 } else
1206 pos = eccsize + chunk; 1207 pos = eccsize;
1207 1208
1208 chip->cmdfunc(mtd, NAND_CMD_SEQIN, pos, page); 1209 chip->cmdfunc(mtd, NAND_CMD_SEQIN, pos, page);
1209 for (i = 0; i < steps; i++) { 1210 for (i = 0; i < steps; i++) {
@@ -1566,7 +1567,7 @@ static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob,
1566 bytes = min_t(size_t, len, free->length); 1567 bytes = min_t(size_t, len, free->length);
1567 boffs = free->offset; 1568 boffs = free->offset;
1568 } 1569 }
1569 memcpy(chip->oob_poi + woffs, oob, bytes); 1570 memcpy(chip->oob_poi + boffs, oob, bytes);
1570 oob += bytes; 1571 oob += bytes;
1571 } 1572 }
1572 return oob; 1573 return oob;
@@ -1691,9 +1692,10 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
1691 1692
1692 ret = nand_do_write_ops(mtd, to, &chip->ops); 1693 ret = nand_do_write_ops(mtd, to, &chip->ops);
1693 1694
1695 *retlen = chip->ops.retlen;
1696
1694 nand_release_device(mtd); 1697 nand_release_device(mtd);
1695 1698
1696 *retlen = chip->ops.retlen;
1697 return ret; 1699 return ret;
1698} 1700}
1699 1701
@@ -1760,7 +1762,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1760/** 1762/**
1761 * nand_write_oob - [MTD Interface] NAND write data and/or out-of-band 1763 * nand_write_oob - [MTD Interface] NAND write data and/or out-of-band
1762 * @mtd: MTD device structure 1764 * @mtd: MTD device structure
1763 * @from: offset to read from 1765 * @to: offset to write to
1764 * @ops: oob operation description structure 1766 * @ops: oob operation description structure
1765 */ 1767 */
1766static int nand_write_oob(struct mtd_info *mtd, loff_t to, 1768static int nand_write_oob(struct mtd_info *mtd, loff_t to,
@@ -2055,7 +2057,7 @@ static void nand_sync(struct mtd_info *mtd)
2055/** 2057/**
2056 * nand_block_isbad - [MTD Interface] Check if block at offset is bad 2058 * nand_block_isbad - [MTD Interface] Check if block at offset is bad
2057 * @mtd: MTD device structure 2059 * @mtd: MTD device structure
2058 * @ofs: offset relative to mtd start 2060 * @offs: offset relative to mtd start
2059 */ 2061 */
2060static int nand_block_isbad(struct mtd_info *mtd, loff_t offs) 2062static int nand_block_isbad(struct mtd_info *mtd, loff_t offs)
2061{ 2063{
diff --git a/drivers/mtd/nand/nand_ecc.c b/drivers/mtd/nand/nand_ecc.c
index 2a163e4084df..dd438ca47d9a 100644
--- a/drivers/mtd/nand/nand_ecc.c
+++ b/drivers/mtd/nand/nand_ecc.c
@@ -65,8 +65,7 @@ static const u_char nand_ecc_precalc_table[] = {
65}; 65};
66 66
67/** 67/**
68 * nand_calculate_ecc - [NAND Interface] Calculate 3 byte ECC code 68 * nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256-byte block
69 * for 256 byte block
70 * @mtd: MTD block structure 69 * @mtd: MTD block structure
71 * @dat: raw data 70 * @dat: raw data
72 * @ecc_code: buffer for ECC 71 * @ecc_code: buffer for ECC
diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c
index 21743658d150..fbeedc3184e9 100644
--- a/drivers/mtd/nand/sharpsl.c
+++ b/drivers/mtd/nand/sharpsl.c
@@ -237,11 +237,6 @@ static int __init sharpsl_nand_init(void)
237 } 237 }
238 } 238 }
239 239
240 if (machine_is_husky() || machine_is_borzoi() || machine_is_akita()) {
241 /* Need to use small eraseblock size for backward compatibility */
242 sharpsl_mtd->flags |= MTD_NO_VIRTBLOCKS;
243 }
244
245 add_mtd_partitions(sharpsl_mtd, sharpsl_partition_info, nr_partitions); 240 add_mtd_partitions(sharpsl_mtd, sharpsl_partition_info, nr_partitions);
246 241
247 /* Return happy */ 242 /* Return happy */
@@ -255,8 +250,6 @@ module_init(sharpsl_nand_init);
255 */ 250 */
256static void __exit sharpsl_nand_cleanup(void) 251static void __exit sharpsl_nand_cleanup(void)
257{ 252{
258 struct nand_chip *this = (struct nand_chip *)&sharpsl_mtd[1];
259
260 /* Release resources, unregister device */ 253 /* Release resources, unregister device */
261 nand_release(sharpsl_mtd); 254 nand_release(sharpsl_mtd);
262 255
diff --git a/drivers/net/3c515.c b/drivers/net/3c515.c
index 4532b17e40ea..aedfddf20cb3 100644
--- a/drivers/net/3c515.c
+++ b/drivers/net/3c515.c
@@ -1003,7 +1003,8 @@ static int corkscrew_start_xmit(struct sk_buff *skb,
1003 /* Calculate the next Tx descriptor entry. */ 1003 /* Calculate the next Tx descriptor entry. */
1004 int entry = vp->cur_tx % TX_RING_SIZE; 1004 int entry = vp->cur_tx % TX_RING_SIZE;
1005 struct boom_tx_desc *prev_entry; 1005 struct boom_tx_desc *prev_entry;
1006 unsigned long flags, i; 1006 unsigned long flags;
1007 int i;
1007 1008
1008 if (vp->tx_full) /* No room to transmit with */ 1009 if (vp->tx_full) /* No room to transmit with */
1009 return 1; 1010 return 1;
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index 8ab03b4a885e..80e8ca013e44 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -17,172 +17,6 @@
17 410 Severn Ave., Suite 210 17 410 Severn Ave., Suite 210
18 Annapolis MD 21403 18 Annapolis MD 21403
19 19
20 Linux Kernel Additions:
21
22 0.99H+lk0.9 - David S. Miller - softnet, PCI DMA updates
23 0.99H+lk1.0 - Jeff Garzik <jgarzik@pobox.com>
24 Remove compatibility defines for kernel versions < 2.2.x.
25 Update for new 2.3.x module interface
26 LK1.1.2 (March 19, 2000)
27 * New PCI interface (jgarzik)
28
29 LK1.1.3 25 April 2000, Andrew Morton <andrewm@uow.edu.au>
30 - Merged with 3c575_cb.c
31 - Don't set RxComplete in boomerang interrupt enable reg
32 - spinlock in vortex_timer to protect mdio functions
33 - disable local interrupts around call to vortex_interrupt in
34 vortex_tx_timeout() (So vortex_interrupt can use spin_lock())
35 - Select window 3 in vortex_timer()'s write to Wn3_MAC_Ctrl
36 - In vortex_start_xmit(), move the lock to _after_ we've altered
37 vp->cur_tx and vp->tx_full. This defeats the race between
38 vortex_start_xmit() and vortex_interrupt which was identified
39 by Bogdan Costescu.
40 - Merged back support for six new cards from various sources
41 - Set vortex_have_pci if pci_module_init returns zero (fixes cardbus
42 insertion oops)
43 - Tell it that 3c905C has NWAY for 100bT autoneg
44 - Fix handling of SetStatusEnd in 'Too much work..' code, as
45 per 2.3.99's 3c575_cb (Dave Hinds).
46 - Split ISR into two for vortex & boomerang
47 - Fix MOD_INC/DEC races
48 - Handle resource allocation failures.
49 - Fix 3CCFE575CT LED polarity
50 - Make tx_interrupt_mitigation the default
51
52 LK1.1.4 25 April 2000, Andrew Morton <andrewm@uow.edu.au>
53 - Add extra TxReset to vortex_up() to fix 575_cb hotplug initialisation probs.
54 - Put vortex_info_tbl into __devinitdata
55 - In the vortex_error StatsFull HACK, disable stats in vp->intr_enable as well
56 as in the hardware.
57 - Increased the loop counter in issue_and_wait from 2,000 to 4,000.
58
59 LK1.1.5 28 April 2000, andrewm
60 - Added powerpc defines (John Daniel <jdaniel@etresoft.com> said these work...)
61 - Some extra diagnostics
62 - In vortex_error(), reset the Tx on maxCollisions. Otherwise most
63 chips usually get a Tx timeout.
64 - Added extra_reset module parm
65 - Replaced some inline timer manip with mod_timer
66 (Franois romieu <Francois.Romieu@nic.fr>)
67 - In vortex_up(), don't make Wn3_config initialisation dependent upon has_nway
68 (this came across from 3c575_cb).
69
70 LK1.1.6 06 Jun 2000, andrewm
71 - Backed out the PPC defines.
72 - Use del_timer_sync(), mod_timer().
73 - Fix wrapped ulong comparison in boomerang_rx()
74 - Add IS_TORNADO, use it to suppress 3c905C checksum error msg
75 (Donald Becker, I Lee Hetherington <ilh@sls.lcs.mit.edu>)
76 - Replace union wn3_config with BFINS/BFEXT manipulation for
77 sparc64 (Pete Zaitcev, Peter Jones)
78 - In vortex_error, do_tx_reset and vortex_tx_timeout(Vortex):
79 do a netif_wake_queue() to better recover from errors. (Anders Pedersen,
80 Donald Becker)
81 - Print a warning on out-of-memory (rate limited to 1 per 10 secs)
82 - Added two more Cardbus 575 NICs: 5b57 and 6564 (Paul Wagland)
83
84 LK1.1.7 2 Jul 2000 andrewm
85 - Better handling of shared IRQs
86 - Reset the transmitter on a Tx reclaim error
87 - Fixed crash under OOM during vortex_open() (Mark Hemment)
88 - Fix Rx cessation problem during OOM (help from Mark Hemment)
89 - The spinlocks around the mdio access were blocking interrupts for 300uS.
90 Fix all this to use spin_lock_bh() within mdio_read/write
91 - Only write to TxFreeThreshold if it's a boomerang - other NICs don't
92 have one.
93 - Added 802.3x MAC-layer flow control support
94
95 LK1.1.8 13 Aug 2000 andrewm
96 - Ignore request_region() return value - already reserved if Cardbus.
97 - Merged some additional Cardbus flags from Don's 0.99Qk
98 - Some fixes for 3c556 (Fred Maciel)
99 - Fix for EISA initialisation (Jan Rekorajski)
100 - Renamed MII_XCVR_PWR and EEPROM_230 to align with 3c575_cb and D. Becker's drivers
101 - Fixed MII_XCVR_PWR for 3CCFE575CT
102 - Added INVERT_LED_PWR, used it.
103 - Backed out the extra_reset stuff
104
105 LK1.1.9 12 Sep 2000 andrewm
106 - Backed out the tx_reset_resume flags. It was a no-op.
107 - In vortex_error, don't reset the Tx on txReclaim errors
108 - In vortex_error, don't reset the Tx on maxCollisions errors.
109 Hence backed out all the DownListPtr logic here.
110 - In vortex_error, give Tornado cards a partial TxReset on
111 maxCollisions (David Hinds). Defined MAX_COLLISION_RESET for this.
112 - Redid some driver flags and device names based on pcmcia_cs-3.1.20.
113 - Fixed a bug where, if vp->tx_full is set when the interface
114 is downed, it remains set when the interface is upped. Bad
115 things happen.
116
117 LK1.1.10 17 Sep 2000 andrewm
118 - Added EEPROM_8BIT for 3c555 (Fred Maciel)
119 - Added experimental support for the 3c556B Laptop Hurricane (Louis Gerbarg)
120 - Add HAS_NWAY to "3c900 Cyclone 10Mbps TPO"
121
122 LK1.1.11 13 Nov 2000 andrewm
123 - Dump MOD_INC/DEC_USE_COUNT, use SET_MODULE_OWNER
124
125 LK1.1.12 1 Jan 2001 andrewm (2.4.0-pre1)
126 - Call pci_enable_device before we request our IRQ (Tobias Ringstrom)
127 - Add 3c590 PCI latency timer hack to vortex_probe1 (from 0.99Ra)
128 - Added extended issue_and_wait for the 3c905CX.
129 - Look for an MII on PHY index 24 first (3c905CX oddity).
130 - Add HAS_NWAY to 3cSOHO100-TX (Brett Frankenberger)
131 - Don't free skbs we don't own on oom path in vortex_open().
132
133 LK1.1.13 27 Jan 2001
134 - Added explicit `medialock' flag so we can truly
135 lock the media type down with `options'.
136 - "check ioremap return and some tidbits" (Arnaldo Carvalho de Melo <acme@conectiva.com.br>)
137 - Added and used EEPROM_NORESET for 3c556B PM resumes.
138 - Fixed leakage of vp->rx_ring.
139 - Break out separate HAS_HWCKSM device capability flag.
140 - Kill vp->tx_full (ANK)
141 - Merge zerocopy fragment handling (ANK?)
142
143 LK1.1.14 15 Feb 2001
144 - Enable WOL. Can be turned on with `enable_wol' module option.
145 - EISA and PCI initialisation fixes (jgarzik, Manfred Spraul)
146 - If a device's internalconfig register reports it has NWAY,
147 use it, even if autoselect is enabled.
148
149 LK1.1.15 6 June 2001 akpm
150 - Prevent double counting of received bytes (Lars Christensen)
151 - Add ethtool support (jgarzik)
152 - Add module parm descriptions (Andrzej M. Krzysztofowicz)
153 - Implemented alloc_etherdev() API
154 - Special-case the 'Tx error 82' message.
155
156 LK1.1.16 18 July 2001 akpm
157 - Make NETIF_F_SG dependent upon nr_free_highpages(), not on CONFIG_HIGHMEM
158 - Lessen verbosity of bootup messages
159 - Fix WOL - use new PM API functions.
160 - Use netif_running() instead of vp->open in suspend/resume.
161 - Don't reset the interface logic on open/close/rmmod. It upsets
162 autonegotiation, and hence DHCP (from 0.99T).
163 - Back out EEPROM_NORESET flag because of the above (we do it for all
164 NICs).
165 - Correct 3c982 identification string
166 - Rename wait_for_completion() to issue_and_wait() to avoid completion.h
167 clash.
168
169 LK1.1.17 18Dec01 akpm
170 - PCI ID 9805 is a Python-T, not a dual-port Cyclone. Apparently.
171 And it has NWAY.
172 - Mask our advertised modes (vp->advertising) with our capabilities
173 (MII reg5) when deciding which duplex mode to use.
174 - Add `global_options' as default for options[]. Ditto global_enable_wol,
175 global_full_duplex.
176
177 LK1.1.18 01Jul02 akpm
178 - Fix for undocumented transceiver power-up bit on some 3c566B's
179 (Donald Becker, Rahul Karnik)
180
181 - See http://www.zip.com.au/~akpm/linux/#3c59x-2.3 for more details.
182 - Also see Documentation/networking/vortex.txt
183
184 LK1.1.19 10Nov02 Marc Zyngier <maz@wild-wind.fr.eu.org>
185 - EISA sysfs integration.
186*/ 20*/
187 21
188/* 22/*
@@ -1897,7 +1731,7 @@ vortex_timer(unsigned long data)
1897 printk(KERN_DEBUG "dev->watchdog_timeo=%d\n", dev->watchdog_timeo); 1731 printk(KERN_DEBUG "dev->watchdog_timeo=%d\n", dev->watchdog_timeo);
1898 } 1732 }
1899 1733
1900 disable_irq(dev->irq); 1734 disable_irq_lockdep(dev->irq);
1901 old_window = ioread16(ioaddr + EL3_CMD) >> 13; 1735 old_window = ioread16(ioaddr + EL3_CMD) >> 13;
1902 EL3WINDOW(4); 1736 EL3WINDOW(4);
1903 media_status = ioread16(ioaddr + Wn4_Media); 1737 media_status = ioread16(ioaddr + Wn4_Media);
@@ -1978,7 +1812,7 @@ leave_media_alone:
1978 dev->name, media_tbl[dev->if_port].name); 1812 dev->name, media_tbl[dev->if_port].name);
1979 1813
1980 EL3WINDOW(old_window); 1814 EL3WINDOW(old_window);
1981 enable_irq(dev->irq); 1815 enable_irq_lockdep(dev->irq);
1982 mod_timer(&vp->timer, RUN_AT(next_tick)); 1816 mod_timer(&vp->timer, RUN_AT(next_tick));
1983 if (vp->deferred) 1817 if (vp->deferred)
1984 iowrite16(FakeIntr, ioaddr + EL3_CMD); 1818 iowrite16(FakeIntr, ioaddr + EL3_CMD);
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index 1959654cbec8..1428bb7715af 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -1836,9 +1836,10 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1836 1836
1837 if (pdev->vendor == PCI_VENDOR_ID_REALTEK && 1837 if (pdev->vendor == PCI_VENDOR_ID_REALTEK &&
1838 pdev->device == PCI_DEVICE_ID_REALTEK_8139 && pci_rev < 0x20) { 1838 pdev->device == PCI_DEVICE_ID_REALTEK_8139 && pci_rev < 0x20) {
1839 printk(KERN_ERR PFX "pci dev %s (id %04x:%04x rev %02x) is not an 8139C+ compatible chip\n", 1839 dev_err(&pdev->dev,
1840 pci_name(pdev), pdev->vendor, pdev->device, pci_rev); 1840 "This (id %04x:%04x rev %02x) is not an 8139C+ compatible chip\n",
1841 printk(KERN_ERR PFX "Try the \"8139too\" driver instead.\n"); 1841 pdev->vendor, pdev->device, pci_rev);
1842 dev_err(&pdev->dev, "Try the \"8139too\" driver instead.\n");
1842 return -ENODEV; 1843 return -ENODEV;
1843 } 1844 }
1844 1845
@@ -1876,14 +1877,13 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1876 pciaddr = pci_resource_start(pdev, 1); 1877 pciaddr = pci_resource_start(pdev, 1);
1877 if (!pciaddr) { 1878 if (!pciaddr) {
1878 rc = -EIO; 1879 rc = -EIO;
1879 printk(KERN_ERR PFX "no MMIO resource for pci dev %s\n", 1880 dev_err(&pdev->dev, "no MMIO resource\n");
1880 pci_name(pdev));
1881 goto err_out_res; 1881 goto err_out_res;
1882 } 1882 }
1883 if (pci_resource_len(pdev, 1) < CP_REGS_SIZE) { 1883 if (pci_resource_len(pdev, 1) < CP_REGS_SIZE) {
1884 rc = -EIO; 1884 rc = -EIO;
1885 printk(KERN_ERR PFX "MMIO resource (%llx) too small on pci dev %s\n", 1885 dev_err(&pdev->dev, "MMIO resource (%llx) too small\n",
1886 (unsigned long long)pci_resource_len(pdev, 1), pci_name(pdev)); 1886 (unsigned long long)pci_resource_len(pdev, 1));
1887 goto err_out_res; 1887 goto err_out_res;
1888 } 1888 }
1889 1889
@@ -1897,14 +1897,15 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1897 1897
1898 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 1898 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1899 if (rc) { 1899 if (rc) {
1900 printk(KERN_ERR PFX "No usable DMA configuration, " 1900 dev_err(&pdev->dev,
1901 "aborting.\n"); 1901 "No usable DMA configuration, aborting.\n");
1902 goto err_out_res; 1902 goto err_out_res;
1903 } 1903 }
1904 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 1904 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
1905 if (rc) { 1905 if (rc) {
1906 printk(KERN_ERR PFX "No usable consistent DMA configuration, " 1906 dev_err(&pdev->dev,
1907 "aborting.\n"); 1907 "No usable consistent DMA configuration, "
1908 "aborting.\n");
1908 goto err_out_res; 1909 goto err_out_res;
1909 } 1910 }
1910 } 1911 }
@@ -1915,9 +1916,9 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1915 regs = ioremap(pciaddr, CP_REGS_SIZE); 1916 regs = ioremap(pciaddr, CP_REGS_SIZE);
1916 if (!regs) { 1917 if (!regs) {
1917 rc = -EIO; 1918 rc = -EIO;
1918 printk(KERN_ERR PFX "Cannot map PCI MMIO (%llx@%llx) on pci dev %s\n", 1919 dev_err(&pdev->dev, "Cannot map PCI MMIO (%Lx@%Lx)\n",
1919 (unsigned long long)pci_resource_len(pdev, 1), 1920 (unsigned long long)pci_resource_len(pdev, 1),
1920 (unsigned long long)pciaddr, pci_name(pdev)); 1921 (unsigned long long)pciaddr);
1921 goto err_out_res; 1922 goto err_out_res;
1922 } 1923 }
1923 dev->base_addr = (unsigned long) regs; 1924 dev->base_addr = (unsigned long) regs;
@@ -1986,7 +1987,8 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1986 /* enable busmastering and memory-write-invalidate */ 1987 /* enable busmastering and memory-write-invalidate */
1987 pci_set_master(pdev); 1988 pci_set_master(pdev);
1988 1989
1989 if (cp->wol_enabled) cp_set_d3_state (cp); 1990 if (cp->wol_enabled)
1991 cp_set_d3_state (cp);
1990 1992
1991 return 0; 1993 return 0;
1992 1994
@@ -2011,7 +2013,8 @@ static void cp_remove_one (struct pci_dev *pdev)
2011 BUG_ON(!dev); 2013 BUG_ON(!dev);
2012 unregister_netdev(dev); 2014 unregister_netdev(dev);
2013 iounmap(cp->regs); 2015 iounmap(cp->regs);
2014 if (cp->wol_enabled) pci_set_power_state (pdev, PCI_D0); 2016 if (cp->wol_enabled)
2017 pci_set_power_state (pdev, PCI_D0);
2015 pci_release_regions(pdev); 2018 pci_release_regions(pdev);
2016 pci_clear_mwi(pdev); 2019 pci_clear_mwi(pdev);
2017 pci_disable_device(pdev); 2020 pci_disable_device(pdev);
diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index 717506b2b13a..e4f4eaff7679 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -768,7 +768,7 @@ static int __devinit rtl8139_init_board (struct pci_dev *pdev,
768 /* dev and priv zeroed in alloc_etherdev */ 768 /* dev and priv zeroed in alloc_etherdev */
769 dev = alloc_etherdev (sizeof (*tp)); 769 dev = alloc_etherdev (sizeof (*tp));
770 if (dev == NULL) { 770 if (dev == NULL) {
771 printk (KERN_ERR PFX "%s: Unable to alloc new net device\n", pci_name(pdev)); 771 dev_err(&pdev->dev, "Unable to alloc new net device\n");
772 return -ENOMEM; 772 return -ENOMEM;
773 } 773 }
774 SET_MODULE_OWNER(dev); 774 SET_MODULE_OWNER(dev);
@@ -800,31 +800,31 @@ static int __devinit rtl8139_init_board (struct pci_dev *pdev,
800#ifdef USE_IO_OPS 800#ifdef USE_IO_OPS
801 /* make sure PCI base addr 0 is PIO */ 801 /* make sure PCI base addr 0 is PIO */
802 if (!(pio_flags & IORESOURCE_IO)) { 802 if (!(pio_flags & IORESOURCE_IO)) {
803 printk (KERN_ERR PFX "%s: region #0 not a PIO resource, aborting\n", pci_name(pdev)); 803 dev_err(&pdev->dev, "region #0 not a PIO resource, aborting\n");
804 rc = -ENODEV; 804 rc = -ENODEV;
805 goto err_out; 805 goto err_out;
806 } 806 }
807 /* check for weird/broken PCI region reporting */ 807 /* check for weird/broken PCI region reporting */
808 if (pio_len < RTL_MIN_IO_SIZE) { 808 if (pio_len < RTL_MIN_IO_SIZE) {
809 printk (KERN_ERR PFX "%s: Invalid PCI I/O region size(s), aborting\n", pci_name(pdev)); 809 dev_err(&pdev->dev, "Invalid PCI I/O region size(s), aborting\n");
810 rc = -ENODEV; 810 rc = -ENODEV;
811 goto err_out; 811 goto err_out;
812 } 812 }
813#else 813#else
814 /* make sure PCI base addr 1 is MMIO */ 814 /* make sure PCI base addr 1 is MMIO */
815 if (!(mmio_flags & IORESOURCE_MEM)) { 815 if (!(mmio_flags & IORESOURCE_MEM)) {
816 printk (KERN_ERR PFX "%s: region #1 not an MMIO resource, aborting\n", pci_name(pdev)); 816 dev_err(&pdev->dev, "region #1 not an MMIO resource, aborting\n");
817 rc = -ENODEV; 817 rc = -ENODEV;
818 goto err_out; 818 goto err_out;
819 } 819 }
820 if (mmio_len < RTL_MIN_IO_SIZE) { 820 if (mmio_len < RTL_MIN_IO_SIZE) {
821 printk (KERN_ERR PFX "%s: Invalid PCI mem region size(s), aborting\n", pci_name(pdev)); 821 dev_err(&pdev->dev, "Invalid PCI mem region size(s), aborting\n");
822 rc = -ENODEV; 822 rc = -ENODEV;
823 goto err_out; 823 goto err_out;
824 } 824 }
825#endif 825#endif
826 826
827 rc = pci_request_regions (pdev, "8139too"); 827 rc = pci_request_regions (pdev, DRV_NAME);
828 if (rc) 828 if (rc)
829 goto err_out; 829 goto err_out;
830 disable_dev_on_err = 1; 830 disable_dev_on_err = 1;
@@ -835,7 +835,7 @@ static int __devinit rtl8139_init_board (struct pci_dev *pdev,
835#ifdef USE_IO_OPS 835#ifdef USE_IO_OPS
836 ioaddr = ioport_map(pio_start, pio_len); 836 ioaddr = ioport_map(pio_start, pio_len);
837 if (!ioaddr) { 837 if (!ioaddr) {
838 printk (KERN_ERR PFX "%s: cannot map PIO, aborting\n", pci_name(pdev)); 838 dev_err(&pdev->dev, "cannot map PIO, aborting\n");
839 rc = -EIO; 839 rc = -EIO;
840 goto err_out; 840 goto err_out;
841 } 841 }
@@ -846,7 +846,7 @@ static int __devinit rtl8139_init_board (struct pci_dev *pdev,
846 /* ioremap MMIO region */ 846 /* ioremap MMIO region */
847 ioaddr = pci_iomap(pdev, 1, 0); 847 ioaddr = pci_iomap(pdev, 1, 0);
848 if (ioaddr == NULL) { 848 if (ioaddr == NULL) {
849 printk (KERN_ERR PFX "%s: cannot remap MMIO, aborting\n", pci_name(pdev)); 849 dev_err(&pdev->dev, "cannot remap MMIO, aborting\n");
850 rc = -EIO; 850 rc = -EIO;
851 goto err_out; 851 goto err_out;
852 } 852 }
@@ -860,8 +860,7 @@ static int __devinit rtl8139_init_board (struct pci_dev *pdev,
860 860
861 /* check for missing/broken hardware */ 861 /* check for missing/broken hardware */
862 if (RTL_R32 (TxConfig) == 0xFFFFFFFF) { 862 if (RTL_R32 (TxConfig) == 0xFFFFFFFF) {
863 printk (KERN_ERR PFX "%s: Chip not responding, ignoring board\n", 863 dev_err(&pdev->dev, "Chip not responding, ignoring board\n");
864 pci_name(pdev));
865 rc = -EIO; 864 rc = -EIO;
866 goto err_out; 865 goto err_out;
867 } 866 }
@@ -875,9 +874,10 @@ static int __devinit rtl8139_init_board (struct pci_dev *pdev,
875 } 874 }
876 875
877 /* if unknown chip, assume array element #0, original RTL-8139 in this case */ 876 /* if unknown chip, assume array element #0, original RTL-8139 in this case */
878 printk (KERN_DEBUG PFX "%s: unknown chip version, assuming RTL-8139\n", 877 dev_printk (KERN_DEBUG, &pdev->dev,
879 pci_name(pdev)); 878 "unknown chip version, assuming RTL-8139\n");
880 printk (KERN_DEBUG PFX "%s: TxConfig = 0x%lx\n", pci_name(pdev), RTL_R32 (TxConfig)); 879 dev_printk (KERN_DEBUG, &pdev->dev,
880 "TxConfig = 0x%lx\n", RTL_R32 (TxConfig));
881 tp->chipset = 0; 881 tp->chipset = 0;
882 882
883match: 883match:
@@ -954,9 +954,11 @@ static int __devinit rtl8139_init_one (struct pci_dev *pdev,
954 954
955 if (pdev->vendor == PCI_VENDOR_ID_REALTEK && 955 if (pdev->vendor == PCI_VENDOR_ID_REALTEK &&
956 pdev->device == PCI_DEVICE_ID_REALTEK_8139 && pci_rev >= 0x20) { 956 pdev->device == PCI_DEVICE_ID_REALTEK_8139 && pci_rev >= 0x20) {
957 printk(KERN_INFO PFX "pci dev %s (id %04x:%04x rev %02x) is an enhanced 8139C+ chip\n", 957 dev_info(&pdev->dev,
958 pci_name(pdev), pdev->vendor, pdev->device, pci_rev); 958 "This (id %04x:%04x rev %02x) is an enhanced 8139C+ chip\n",
959 printk(KERN_INFO PFX "Use the \"8139cp\" driver for improved performance and stability.\n"); 959 pdev->vendor, pdev->device, pci_rev);
960 dev_info(&pdev->dev,
961 "Use the \"8139cp\" driver for improved performance and stability.\n");
960 } 962 }
961 963
962 i = rtl8139_init_board (pdev, &dev); 964 i = rtl8139_init_board (pdev, &dev);
@@ -1707,6 +1709,7 @@ static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
1707 void __iomem *ioaddr = tp->mmio_addr; 1709 void __iomem *ioaddr = tp->mmio_addr;
1708 unsigned int entry; 1710 unsigned int entry;
1709 unsigned int len = skb->len; 1711 unsigned int len = skb->len;
1712 unsigned long flags;
1710 1713
1711 /* Calculate the next Tx descriptor entry. */ 1714 /* Calculate the next Tx descriptor entry. */
1712 entry = tp->cur_tx % NUM_TX_DESC; 1715 entry = tp->cur_tx % NUM_TX_DESC;
@@ -1723,7 +1726,7 @@ static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
1723 return 0; 1726 return 0;
1724 } 1727 }
1725 1728
1726 spin_lock_irq(&tp->lock); 1729 spin_lock_irqsave(&tp->lock, flags);
1727 RTL_W32_F (TxStatus0 + (entry * sizeof (u32)), 1730 RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
1728 tp->tx_flag | max(len, (unsigned int)ETH_ZLEN)); 1731 tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
1729 1732
@@ -1734,7 +1737,7 @@ static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
1734 1737
1735 if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx) 1738 if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx)
1736 netif_stop_queue (dev); 1739 netif_stop_queue (dev);
1737 spin_unlock_irq(&tp->lock); 1740 spin_unlock_irqrestore(&tp->lock, flags);
1738 1741
1739 if (netif_msg_tx_queued(tp)) 1742 if (netif_msg_tx_queued(tp))
1740 printk (KERN_DEBUG "%s: Queued Tx packet size %u to slot %d.\n", 1743 printk (KERN_DEBUG "%s: Queued Tx packet size %u to slot %d.\n",
diff --git a/drivers/net/82596.c b/drivers/net/82596.c
index 7e2ca9571467..257d3bce3993 100644
--- a/drivers/net/82596.c
+++ b/drivers/net/82596.c
@@ -899,7 +899,7 @@ memory_squeeze:
899} 899}
900 900
901 901
902static inline void i596_cleanup_cmd(struct net_device *dev, struct i596_private *lp) 902static void i596_cleanup_cmd(struct net_device *dev, struct i596_private *lp)
903{ 903{
904 struct i596_cmd *ptr; 904 struct i596_cmd *ptr;
905 905
@@ -932,7 +932,8 @@ static inline void i596_cleanup_cmd(struct net_device *dev, struct i596_private
932 lp->scb.cmd = I596_NULL; 932 lp->scb.cmd = I596_NULL;
933} 933}
934 934
935static inline void i596_reset(struct net_device *dev, struct i596_private *lp, int ioaddr) 935static void i596_reset(struct net_device *dev, struct i596_private *lp,
936 int ioaddr)
936{ 937{
937 unsigned long flags; 938 unsigned long flags;
938 939
@@ -1578,7 +1579,7 @@ static int debug = -1;
1578module_param(debug, int, 0); 1579module_param(debug, int, 0);
1579MODULE_PARM_DESC(debug, "i82596 debug mask"); 1580MODULE_PARM_DESC(debug, "i82596 debug mask");
1580 1581
1581int init_module(void) 1582int __init init_module(void)
1582{ 1583{
1583 if (debug >= 0) 1584 if (debug >= 0)
1584 i596_debug = debug; 1585 i596_debug = debug;
@@ -1588,7 +1589,7 @@ int init_module(void)
1588 return 0; 1589 return 0;
1589} 1590}
1590 1591
1591void cleanup_module(void) 1592void __exit cleanup_module(void)
1592{ 1593{
1593 unregister_netdev(dev_82596); 1594 unregister_netdev(dev_82596);
1594#ifdef __mc68000__ 1595#ifdef __mc68000__
diff --git a/drivers/net/8390.c b/drivers/net/8390.c
index 86be96af9c8f..d2935ae39814 100644
--- a/drivers/net/8390.c
+++ b/drivers/net/8390.c
@@ -249,7 +249,7 @@ void ei_tx_timeout(struct net_device *dev)
249 249
250 /* Ugly but a reset can be slow, yet must be protected */ 250 /* Ugly but a reset can be slow, yet must be protected */
251 251
252 disable_irq_nosync(dev->irq); 252 disable_irq_nosync_lockdep(dev->irq);
253 spin_lock(&ei_local->page_lock); 253 spin_lock(&ei_local->page_lock);
254 254
255 /* Try to restart the card. Perhaps the user has fixed something. */ 255 /* Try to restart the card. Perhaps the user has fixed something. */
@@ -257,7 +257,7 @@ void ei_tx_timeout(struct net_device *dev)
257 NS8390_init(dev, 1); 257 NS8390_init(dev, 1);
258 258
259 spin_unlock(&ei_local->page_lock); 259 spin_unlock(&ei_local->page_lock);
260 enable_irq(dev->irq); 260 enable_irq_lockdep(dev->irq);
261 netif_wake_queue(dev); 261 netif_wake_queue(dev);
262} 262}
263 263
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 39189903e355..a2bd8119270e 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -1724,6 +1724,20 @@ config VIA_RHINE_MMIO
1724 1724
1725 If unsure, say Y. 1725 If unsure, say Y.
1726 1726
1727config VIA_RHINE_NAPI
1728 bool "Use Rx Polling (NAPI)"
1729 depends on VIA_RHINE
1730 help
1731 NAPI is a new driver API designed to reduce CPU and interrupt load
1732 when the driver is receiving lots of packets from the card.
1733
1734 If your estimated Rx load is 10kpps or more, or if the card will be
1735 deployed on potentially unfriendly networks (e.g. in a firewall),
1736 then say Y here.
1737
1738 See <file:Documentation/networking/NAPI_HOWTO.txt> for more
1739 information.
1740
1727config LAN_SAA9730 1741config LAN_SAA9730
1728 bool "Philips SAA9730 Ethernet support (EXPERIMENTAL)" 1742 bool "Philips SAA9730 Ethernet support (EXPERIMENTAL)"
1729 depends on NET_PCI && EXPERIMENTAL && MIPS 1743 depends on NET_PCI && EXPERIMENTAL && MIPS
@@ -2219,6 +2233,33 @@ config GFAR_NAPI
2219 bool "NAPI Support" 2233 bool "NAPI Support"
2220 depends on GIANFAR 2234 depends on GIANFAR
2221 2235
2236config UCC_GETH
2237 tristate "Freescale QE UCC GETH"
2238 depends on QUICC_ENGINE && UCC_FAST
2239 help
2240 This driver supports the Gigabit Ethernet mode of QE UCC.
2241 QE can be found on MPC836x CPUs.
2242
2243config UGETH_NAPI
2244 bool "NAPI Support"
2245 depends on UCC_GETH
2246
2247config UGETH_MAGIC_PACKET
2248 bool "Magic Packet detection support"
2249 depends on UCC_GETH
2250
2251config UGETH_FILTERING
2252 bool "Mac address filtering support"
2253 depends on UCC_GETH
2254
2255config UGETH_TX_ON_DEMOND
2256 bool "Transmit on Demond support"
2257 depends on UCC_GETH
2258
2259config UGETH_HAS_GIGA
2260 bool
2261 depends on UCC_GETH && MPC836x
2262
2222config MV643XX_ETH 2263config MV643XX_ETH
2223 tristate "MV-643XX Ethernet support" 2264 tristate "MV-643XX Ethernet support"
2224 depends on MOMENCO_OCELOT_C || MOMENCO_JAGUAR_ATX || MV64360 || MOMENCO_OCELOT_3 || PPC_MULTIPLATFORM 2265 depends on MOMENCO_OCELOT_C || MOMENCO_JAGUAR_ATX || MV64360 || MOMENCO_OCELOT_3 || PPC_MULTIPLATFORM
@@ -2352,7 +2393,7 @@ config MYRI10GE
2352 you will need a newer firmware image. 2393 you will need a newer firmware image.
2353 You may get this image or more information, at: 2394 You may get this image or more information, at:
2354 2395
2355 <http://www.myri.com/Myri-10G/> 2396 <http://www.myri.com/scs/download-Myri10GE.html>
2356 2397
2357 To compile this driver as a module, choose M here and read 2398 To compile this driver as a module, choose M here and read
2358 <file:Documentation/networking/net-modules.txt>. The module 2399 <file:Documentation/networking/net-modules.txt>. The module
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index c91e95126f78..8427bf9dec9d 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -18,6 +18,9 @@ gianfar_driver-objs := gianfar.o \
18 gianfar_mii.o \ 18 gianfar_mii.o \
19 gianfar_sysfs.o 19 gianfar_sysfs.o
20 20
21obj-$(CONFIG_UCC_GETH) += ucc_geth_driver.o
22ucc_geth_driver-objs := ucc_geth.o ucc_geth_phy.o
23
21# 24#
22# link order important here 25# link order important here
23# 26#
diff --git a/drivers/net/ac3200.c b/drivers/net/ac3200.c
index 7952dc6d77e3..0fbbcb75af69 100644
--- a/drivers/net/ac3200.c
+++ b/drivers/net/ac3200.c
@@ -370,8 +370,7 @@ MODULE_PARM_DESC(mem, "Memory base address(es)");
370MODULE_DESCRIPTION("Ansel AC3200 EISA ethernet driver"); 370MODULE_DESCRIPTION("Ansel AC3200 EISA ethernet driver");
371MODULE_LICENSE("GPL"); 371MODULE_LICENSE("GPL");
372 372
373int 373int __init init_module(void)
374init_module(void)
375{ 374{
376 struct net_device *dev; 375 struct net_device *dev;
377 int this_dev, found = 0; 376 int this_dev, found = 0;
diff --git a/drivers/net/appletalk/Kconfig b/drivers/net/appletalk/Kconfig
index b14e89004c3a..0a0e0cd81a23 100644
--- a/drivers/net/appletalk/Kconfig
+++ b/drivers/net/appletalk/Kconfig
@@ -29,7 +29,7 @@ config ATALK
29 even politically correct people are allowed to say Y here. 29 even politically correct people are allowed to say Y here.
30 30
31config DEV_APPLETALK 31config DEV_APPLETALK
32 bool "Appletalk interfaces support" 32 tristate "Appletalk interfaces support"
33 depends on ATALK 33 depends on ATALK
34 help 34 help
35 AppleTalk is the protocol that Apple computers can use to communicate 35 AppleTalk is the protocol that Apple computers can use to communicate
diff --git a/drivers/net/appletalk/cops.c b/drivers/net/appletalk/cops.c
index 1d01ac0000e4..ae7f828344d9 100644
--- a/drivers/net/appletalk/cops.c
+++ b/drivers/net/appletalk/cops.c
@@ -1030,7 +1030,7 @@ module_param(io, int, 0);
1030module_param(irq, int, 0); 1030module_param(irq, int, 0);
1031module_param(board_type, int, 0); 1031module_param(board_type, int, 0);
1032 1032
1033int init_module(void) 1033int __init init_module(void)
1034{ 1034{
1035 if (io == 0) 1035 if (io == 0)
1036 printk(KERN_WARNING "%s: You shouldn't autoprobe with insmod\n", 1036 printk(KERN_WARNING "%s: You shouldn't autoprobe with insmod\n",
diff --git a/drivers/net/at1700.c b/drivers/net/at1700.c
index 5d7929c79bce..4ca061c2d5b2 100644
--- a/drivers/net/at1700.c
+++ b/drivers/net/at1700.c
@@ -901,7 +901,7 @@ MODULE_PARM_DESC(io, "AT1700/FMV18X I/O base address");
901MODULE_PARM_DESC(irq, "AT1700/FMV18X IRQ number"); 901MODULE_PARM_DESC(irq, "AT1700/FMV18X IRQ number");
902MODULE_PARM_DESC(net_debug, "AT1700/FMV18X debug level (0-6)"); 902MODULE_PARM_DESC(net_debug, "AT1700/FMV18X debug level (0-6)");
903 903
904int init_module(void) 904int __init init_module(void)
905{ 905{
906 if (io == 0) 906 if (io == 0)
907 printk("at1700: You should not use auto-probing with insmod!\n"); 907 printk("at1700: You should not use auto-probing with insmod!\n");
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index cd98d31dee8c..bea0fc0ede2f 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -2120,13 +2120,14 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
2120 2120
2121 err = pci_enable_device(pdev); 2121 err = pci_enable_device(pdev);
2122 if (err) { 2122 if (err) {
2123 printk(KERN_ERR PFX "Cannot enable PCI device, " 2123 dev_err(&pdev->dev, "Cannot enable PCI device, "
2124 "aborting.\n"); 2124 "aborting.\n");
2125 return err; 2125 return err;
2126 } 2126 }
2127 2127
2128 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { 2128 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
2129 printk(KERN_ERR PFX "Cannot find proper PCI device " 2129 dev_err(&pdev->dev,
2130 "Cannot find proper PCI device "
2130 "base address, aborting.\n"); 2131 "base address, aborting.\n");
2131 err = -ENODEV; 2132 err = -ENODEV;
2132 goto err_out_disable_pdev; 2133 goto err_out_disable_pdev;
@@ -2134,8 +2135,8 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
2134 2135
2135 err = pci_request_regions(pdev, DRV_MODULE_NAME); 2136 err = pci_request_regions(pdev, DRV_MODULE_NAME);
2136 if (err) { 2137 if (err) {
2137 printk(KERN_ERR PFX "Cannot obtain PCI resources, " 2138 dev_err(&pdev->dev,
2138 "aborting.\n"); 2139 "Cannot obtain PCI resources, aborting.\n");
2139 goto err_out_disable_pdev; 2140 goto err_out_disable_pdev;
2140 } 2141 }
2141 2142
@@ -2143,15 +2144,13 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
2143 2144
2144 err = pci_set_dma_mask(pdev, (u64) B44_DMA_MASK); 2145 err = pci_set_dma_mask(pdev, (u64) B44_DMA_MASK);
2145 if (err) { 2146 if (err) {
2146 printk(KERN_ERR PFX "No usable DMA configuration, " 2147 dev_err(&pdev->dev, "No usable DMA configuration, aborting.\n");
2147 "aborting.\n");
2148 goto err_out_free_res; 2148 goto err_out_free_res;
2149 } 2149 }
2150 2150
2151 err = pci_set_consistent_dma_mask(pdev, (u64) B44_DMA_MASK); 2151 err = pci_set_consistent_dma_mask(pdev, (u64) B44_DMA_MASK);
2152 if (err) { 2152 if (err) {
2153 printk(KERN_ERR PFX "No usable DMA configuration, " 2153 dev_err(&pdev->dev, "No usable DMA configuration, aborting.\n");
2154 "aborting.\n");
2155 goto err_out_free_res; 2154 goto err_out_free_res;
2156 } 2155 }
2157 2156
@@ -2160,7 +2159,7 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
2160 2159
2161 dev = alloc_etherdev(sizeof(*bp)); 2160 dev = alloc_etherdev(sizeof(*bp));
2162 if (!dev) { 2161 if (!dev) {
2163 printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n"); 2162 dev_err(&pdev->dev, "Etherdev alloc failed, aborting.\n");
2164 err = -ENOMEM; 2163 err = -ENOMEM;
2165 goto err_out_free_res; 2164 goto err_out_free_res;
2166 } 2165 }
@@ -2181,8 +2180,7 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
2181 2180
2182 bp->regs = ioremap(b44reg_base, b44reg_len); 2181 bp->regs = ioremap(b44reg_base, b44reg_len);
2183 if (bp->regs == 0UL) { 2182 if (bp->regs == 0UL) {
2184 printk(KERN_ERR PFX "Cannot map device registers, " 2183 dev_err(&pdev->dev, "Cannot map device registers, aborting.\n");
2185 "aborting.\n");
2186 err = -ENOMEM; 2184 err = -ENOMEM;
2187 goto err_out_free_dev; 2185 goto err_out_free_dev;
2188 } 2186 }
@@ -2212,8 +2210,8 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
2212 2210
2213 err = b44_get_invariants(bp); 2211 err = b44_get_invariants(bp);
2214 if (err) { 2212 if (err) {
2215 printk(KERN_ERR PFX "Problem fetching invariants of chip, " 2213 dev_err(&pdev->dev,
2216 "aborting.\n"); 2214 "Problem fetching invariants of chip, aborting.\n");
2217 goto err_out_iounmap; 2215 goto err_out_iounmap;
2218 } 2216 }
2219 2217
@@ -2233,8 +2231,7 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
2233 2231
2234 err = register_netdev(dev); 2232 err = register_netdev(dev);
2235 if (err) { 2233 if (err) {
2236 printk(KERN_ERR PFX "Cannot register net device, " 2234 dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
2237 "aborting.\n");
2238 goto err_out_iounmap; 2235 goto err_out_iounmap;
2239 } 2236 }
2240 2237
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 4f4db5ae503b..652eb05a6c2d 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -56,8 +56,8 @@
56 56
57#define DRV_MODULE_NAME "bnx2" 57#define DRV_MODULE_NAME "bnx2"
58#define PFX DRV_MODULE_NAME ": " 58#define PFX DRV_MODULE_NAME ": "
59#define DRV_MODULE_VERSION "1.4.43" 59#define DRV_MODULE_VERSION "1.4.44"
60#define DRV_MODULE_RELDATE "June 28, 2006" 60#define DRV_MODULE_RELDATE "August 10, 2006"
61 61
62#define RUN_AT(x) (jiffies + (x)) 62#define RUN_AT(x) (jiffies + (x))
63 63
@@ -209,8 +209,10 @@ MODULE_DEVICE_TABLE(pci, bnx2_pci_tbl);
209 209
210static inline u32 bnx2_tx_avail(struct bnx2 *bp) 210static inline u32 bnx2_tx_avail(struct bnx2 *bp)
211{ 211{
212 u32 diff = TX_RING_IDX(bp->tx_prod) - TX_RING_IDX(bp->tx_cons); 212 u32 diff;
213 213
214 smp_mb();
215 diff = TX_RING_IDX(bp->tx_prod) - TX_RING_IDX(bp->tx_cons);
214 if (diff > MAX_TX_DESC_CNT) 216 if (diff > MAX_TX_DESC_CNT)
215 diff = (diff & MAX_TX_DESC_CNT) - 1; 217 diff = (diff & MAX_TX_DESC_CNT) - 1;
216 return (bp->tx_ring_size - diff); 218 return (bp->tx_ring_size - diff);
@@ -1569,7 +1571,7 @@ bnx2_alloc_rx_skb(struct bnx2 *bp, u16 index)
1569 struct rx_bd *rxbd = &bp->rx_desc_ring[RX_RING(index)][RX_IDX(index)]; 1571 struct rx_bd *rxbd = &bp->rx_desc_ring[RX_RING(index)][RX_IDX(index)];
1570 unsigned long align; 1572 unsigned long align;
1571 1573
1572 skb = dev_alloc_skb(bp->rx_buf_size); 1574 skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
1573 if (skb == NULL) { 1575 if (skb == NULL) {
1574 return -ENOMEM; 1576 return -ENOMEM;
1575 } 1577 }
@@ -1578,7 +1580,6 @@ bnx2_alloc_rx_skb(struct bnx2 *bp, u16 index)
1578 skb_reserve(skb, 8 - align); 1580 skb_reserve(skb, 8 - align);
1579 } 1581 }
1580 1582
1581 skb->dev = bp->dev;
1582 mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size, 1583 mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size,
1583 PCI_DMA_FROMDEVICE); 1584 PCI_DMA_FROMDEVICE);
1584 1585
@@ -1639,7 +1640,7 @@ bnx2_tx_int(struct bnx2 *bp)
1639 skb = tx_buf->skb; 1640 skb = tx_buf->skb;
1640#ifdef BCM_TSO 1641#ifdef BCM_TSO
1641 /* partial BD completions possible with TSO packets */ 1642 /* partial BD completions possible with TSO packets */
1642 if (skb_shinfo(skb)->gso_size) { 1643 if (skb_is_gso(skb)) {
1643 u16 last_idx, last_ring_idx; 1644 u16 last_idx, last_ring_idx;
1644 1645
1645 last_idx = sw_cons + 1646 last_idx = sw_cons +
@@ -1686,15 +1687,20 @@ bnx2_tx_int(struct bnx2 *bp)
1686 } 1687 }
1687 1688
1688 bp->tx_cons = sw_cons; 1689 bp->tx_cons = sw_cons;
1690 /* Need to make the tx_cons update visible to bnx2_start_xmit()
1691 * before checking for netif_queue_stopped(). Without the
1692 * memory barrier, there is a small possibility that bnx2_start_xmit()
1693 * will miss it and cause the queue to be stopped forever.
1694 */
1695 smp_mb();
1689 1696
1690 if (unlikely(netif_queue_stopped(bp->dev))) { 1697 if (unlikely(netif_queue_stopped(bp->dev)) &&
1691 spin_lock(&bp->tx_lock); 1698 (bnx2_tx_avail(bp) > bp->tx_wake_thresh)) {
1699 netif_tx_lock(bp->dev);
1692 if ((netif_queue_stopped(bp->dev)) && 1700 if ((netif_queue_stopped(bp->dev)) &&
1693 (bnx2_tx_avail(bp) > MAX_SKB_FRAGS)) { 1701 (bnx2_tx_avail(bp) > bp->tx_wake_thresh))
1694
1695 netif_wake_queue(bp->dev); 1702 netif_wake_queue(bp->dev);
1696 } 1703 netif_tx_unlock(bp->dev);
1697 spin_unlock(&bp->tx_lock);
1698 } 1704 }
1699} 1705}
1700 1706
@@ -1786,7 +1792,7 @@ bnx2_rx_int(struct bnx2 *bp, int budget)
1786 if ((bp->dev->mtu > 1500) && (len <= RX_COPY_THRESH)) { 1792 if ((bp->dev->mtu > 1500) && (len <= RX_COPY_THRESH)) {
1787 struct sk_buff *new_skb; 1793 struct sk_buff *new_skb;
1788 1794
1789 new_skb = dev_alloc_skb(len + 2); 1795 new_skb = netdev_alloc_skb(bp->dev, len + 2);
1790 if (new_skb == NULL) 1796 if (new_skb == NULL)
1791 goto reuse_rx; 1797 goto reuse_rx;
1792 1798
@@ -1797,7 +1803,6 @@ bnx2_rx_int(struct bnx2 *bp, int budget)
1797 1803
1798 skb_reserve(new_skb, 2); 1804 skb_reserve(new_skb, 2);
1799 skb_put(new_skb, len); 1805 skb_put(new_skb, len);
1800 new_skb->dev = bp->dev;
1801 1806
1802 bnx2_reuse_rx_skb(bp, skb, 1807 bnx2_reuse_rx_skb(bp, skb,
1803 sw_ring_cons, sw_ring_prod); 1808 sw_ring_cons, sw_ring_prod);
@@ -3503,6 +3508,8 @@ bnx2_init_tx_ring(struct bnx2 *bp)
3503 struct tx_bd *txbd; 3508 struct tx_bd *txbd;
3504 u32 val; 3509 u32 val;
3505 3510
3511 bp->tx_wake_thresh = bp->tx_ring_size / 2;
3512
3506 txbd = &bp->tx_desc_ring[MAX_TX_DESC_CNT]; 3513 txbd = &bp->tx_desc_ring[MAX_TX_DESC_CNT];
3507 3514
3508 txbd->tx_bd_haddr_hi = (u64) bp->tx_desc_mapping >> 32; 3515 txbd->tx_bd_haddr_hi = (u64) bp->tx_desc_mapping >> 32;
@@ -3952,7 +3959,7 @@ bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
3952 return -EINVAL; 3959 return -EINVAL;
3953 3960
3954 pkt_size = 1514; 3961 pkt_size = 1514;
3955 skb = dev_alloc_skb(pkt_size); 3962 skb = netdev_alloc_skb(bp->dev, pkt_size);
3956 if (!skb) 3963 if (!skb)
3957 return -ENOMEM; 3964 return -ENOMEM;
3958 packet = skb_put(skb, pkt_size); 3965 packet = skb_put(skb, pkt_size);
@@ -4390,10 +4397,8 @@ bnx2_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
4390#endif 4397#endif
4391 4398
4392/* Called with netif_tx_lock. 4399/* Called with netif_tx_lock.
4393 * hard_start_xmit is pseudo-lockless - a lock is only required when 4400 * bnx2_tx_int() runs without netif_tx_lock unless it needs to call
4394 * the tx queue is full. This way, we get the benefit of lockless 4401 * netif_wake_queue().
4395 * operations most of the time without the complexities to handle
4396 * netif_stop_queue/wake_queue race conditions.
4397 */ 4402 */
4398static int 4403static int
4399bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev) 4404bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
@@ -4512,12 +4517,9 @@ bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
4512 dev->trans_start = jiffies; 4517 dev->trans_start = jiffies;
4513 4518
4514 if (unlikely(bnx2_tx_avail(bp) <= MAX_SKB_FRAGS)) { 4519 if (unlikely(bnx2_tx_avail(bp) <= MAX_SKB_FRAGS)) {
4515 spin_lock(&bp->tx_lock);
4516 netif_stop_queue(dev); 4520 netif_stop_queue(dev);
4517 4521 if (bnx2_tx_avail(bp) > bp->tx_wake_thresh)
4518 if (bnx2_tx_avail(bp) > MAX_SKB_FRAGS)
4519 netif_wake_queue(dev); 4522 netif_wake_queue(dev);
4520 spin_unlock(&bp->tx_lock);
4521 } 4523 }
4522 4524
4523 return NETDEV_TX_OK; 4525 return NETDEV_TX_OK;
@@ -5575,20 +5577,20 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5575 /* enable device (incl. PCI PM wakeup), and bus-mastering */ 5577 /* enable device (incl. PCI PM wakeup), and bus-mastering */
5576 rc = pci_enable_device(pdev); 5578 rc = pci_enable_device(pdev);
5577 if (rc) { 5579 if (rc) {
5578 printk(KERN_ERR PFX "Cannot enable PCI device, aborting."); 5580 dev_err(&pdev->dev, "Cannot enable PCI device, aborting.");
5579 goto err_out; 5581 goto err_out;
5580 } 5582 }
5581 5583
5582 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { 5584 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
5583 printk(KERN_ERR PFX "Cannot find PCI device base address, " 5585 dev_err(&pdev->dev,
5584 "aborting.\n"); 5586 "Cannot find PCI device base address, aborting.\n");
5585 rc = -ENODEV; 5587 rc = -ENODEV;
5586 goto err_out_disable; 5588 goto err_out_disable;
5587 } 5589 }
5588 5590
5589 rc = pci_request_regions(pdev, DRV_MODULE_NAME); 5591 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
5590 if (rc) { 5592 if (rc) {
5591 printk(KERN_ERR PFX "Cannot obtain PCI resources, aborting.\n"); 5593 dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting.\n");
5592 goto err_out_disable; 5594 goto err_out_disable;
5593 } 5595 }
5594 5596
@@ -5596,15 +5598,15 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5596 5598
5597 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); 5599 bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
5598 if (bp->pm_cap == 0) { 5600 if (bp->pm_cap == 0) {
5599 printk(KERN_ERR PFX "Cannot find power management capability, " 5601 dev_err(&pdev->dev,
5600 "aborting.\n"); 5602 "Cannot find power management capability, aborting.\n");
5601 rc = -EIO; 5603 rc = -EIO;
5602 goto err_out_release; 5604 goto err_out_release;
5603 } 5605 }
5604 5606
5605 bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX); 5607 bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX);
5606 if (bp->pcix_cap == 0) { 5608 if (bp->pcix_cap == 0) {
5607 printk(KERN_ERR PFX "Cannot find PCIX capability, aborting.\n"); 5609 dev_err(&pdev->dev, "Cannot find PCIX capability, aborting.\n");
5608 rc = -EIO; 5610 rc = -EIO;
5609 goto err_out_release; 5611 goto err_out_release;
5610 } 5612 }
@@ -5612,14 +5614,14 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5612 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) { 5614 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
5613 bp->flags |= USING_DAC_FLAG; 5615 bp->flags |= USING_DAC_FLAG;
5614 if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) != 0) { 5616 if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) != 0) {
5615 printk(KERN_ERR PFX "pci_set_consistent_dma_mask " 5617 dev_err(&pdev->dev,
5616 "failed, aborting.\n"); 5618 "pci_set_consistent_dma_mask failed, aborting.\n");
5617 rc = -EIO; 5619 rc = -EIO;
5618 goto err_out_release; 5620 goto err_out_release;
5619 } 5621 }
5620 } 5622 }
5621 else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) { 5623 else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) {
5622 printk(KERN_ERR PFX "System does not support DMA, aborting.\n"); 5624 dev_err(&pdev->dev, "System does not support DMA, aborting.\n");
5623 rc = -EIO; 5625 rc = -EIO;
5624 goto err_out_release; 5626 goto err_out_release;
5625 } 5627 }
@@ -5628,7 +5630,6 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5628 bp->pdev = pdev; 5630 bp->pdev = pdev;
5629 5631
5630 spin_lock_init(&bp->phy_lock); 5632 spin_lock_init(&bp->phy_lock);
5631 spin_lock_init(&bp->tx_lock);
5632 INIT_WORK(&bp->reset_task, bnx2_reset_task, bp); 5633 INIT_WORK(&bp->reset_task, bnx2_reset_task, bp);
5633 5634
5634 dev->base_addr = dev->mem_start = pci_resource_start(pdev, 0); 5635 dev->base_addr = dev->mem_start = pci_resource_start(pdev, 0);
@@ -5639,7 +5640,7 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5639 bp->regview = ioremap_nocache(dev->base_addr, mem_len); 5640 bp->regview = ioremap_nocache(dev->base_addr, mem_len);
5640 5641
5641 if (!bp->regview) { 5642 if (!bp->regview) {
5642 printk(KERN_ERR PFX "Cannot map register space, aborting.\n"); 5643 dev_err(&pdev->dev, "Cannot map register space, aborting.\n");
5643 rc = -ENOMEM; 5644 rc = -ENOMEM;
5644 goto err_out_release; 5645 goto err_out_release;
5645 } 5646 }
@@ -5711,8 +5712,8 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5711 else if ((CHIP_ID(bp) == CHIP_ID_5706_A1) && 5712 else if ((CHIP_ID(bp) == CHIP_ID_5706_A1) &&
5712 !(bp->flags & PCIX_FLAG)) { 5713 !(bp->flags & PCIX_FLAG)) {
5713 5714
5714 printk(KERN_ERR PFX "5706 A1 can only be used in a PCIX bus, " 5715 dev_err(&pdev->dev,
5715 "aborting.\n"); 5716 "5706 A1 can only be used in a PCIX bus, aborting.\n");
5716 goto err_out_unmap; 5717 goto err_out_unmap;
5717 } 5718 }
5718 5719
@@ -5733,7 +5734,7 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5733 5734
5734 if ((reg & BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK) != 5735 if ((reg & BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
5735 BNX2_DEV_INFO_SIGNATURE_MAGIC) { 5736 BNX2_DEV_INFO_SIGNATURE_MAGIC) {
5736 printk(KERN_ERR PFX "Firmware not running, aborting.\n"); 5737 dev_err(&pdev->dev, "Firmware not running, aborting.\n");
5737 rc = -ENODEV; 5738 rc = -ENODEV;
5738 goto err_out_unmap; 5739 goto err_out_unmap;
5739 } 5740 }
@@ -5751,7 +5752,7 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5751 bp->mac_addr[5] = (u8) reg; 5752 bp->mac_addr[5] = (u8) reg;
5752 5753
5753 bp->tx_ring_size = MAX_TX_DESC_CNT; 5754 bp->tx_ring_size = MAX_TX_DESC_CNT;
5754 bnx2_set_rx_ring_size(bp, 100); 5755 bnx2_set_rx_ring_size(bp, 255);
5755 5756
5756 bp->rx_csum = 1; 5757 bp->rx_csum = 1;
5757 5758
@@ -5895,7 +5896,7 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
5895#endif 5896#endif
5896 5897
5897 if ((rc = register_netdev(dev))) { 5898 if ((rc = register_netdev(dev))) {
5898 printk(KERN_ERR PFX "Cannot register net device\n"); 5899 dev_err(&pdev->dev, "Cannot register net device\n");
5899 if (bp->regview) 5900 if (bp->regview)
5900 iounmap(bp->regview); 5901 iounmap(bp->regview);
5901 pci_release_regions(pdev); 5902 pci_release_regions(pdev);
diff --git a/drivers/net/bnx2.h b/drivers/net/bnx2.h
index 658c5ee95c73..fe804763c607 100644
--- a/drivers/net/bnx2.h
+++ b/drivers/net/bnx2.h
@@ -3890,10 +3890,6 @@ struct bnx2 {
3890 u32 tx_prod_bseq __attribute__((aligned(L1_CACHE_BYTES))); 3890 u32 tx_prod_bseq __attribute__((aligned(L1_CACHE_BYTES)));
3891 u16 tx_prod; 3891 u16 tx_prod;
3892 3892
3893 struct tx_bd *tx_desc_ring;
3894 struct sw_bd *tx_buf_ring;
3895 int tx_ring_size;
3896
3897 u16 tx_cons __attribute__((aligned(L1_CACHE_BYTES))); 3893 u16 tx_cons __attribute__((aligned(L1_CACHE_BYTES)));
3898 u16 hw_tx_cons; 3894 u16 hw_tx_cons;
3899 3895
@@ -3916,9 +3912,11 @@ struct bnx2 {
3916 struct sw_bd *rx_buf_ring; 3912 struct sw_bd *rx_buf_ring;
3917 struct rx_bd *rx_desc_ring[MAX_RX_RINGS]; 3913 struct rx_bd *rx_desc_ring[MAX_RX_RINGS];
3918 3914
3919 /* Only used to synchronize netif_stop_queue/wake_queue when tx */ 3915 /* TX constants */
3920 /* ring is full */ 3916 struct tx_bd *tx_desc_ring;
3921 spinlock_t tx_lock; 3917 struct sw_bd *tx_buf_ring;
3918 int tx_ring_size;
3919 u32 tx_wake_thresh;
3922 3920
3923 /* End of fields used in the performance code paths. */ 3921 /* End of fields used in the performance code paths. */
3924 3922
diff --git a/drivers/net/cassini.c b/drivers/net/cassini.c
index d33130f64700..a31544ccb3c4 100644
--- a/drivers/net/cassini.c
+++ b/drivers/net/cassini.c
@@ -4887,13 +4887,12 @@ static int __devinit cas_init_one(struct pci_dev *pdev,
4887 4887
4888 err = pci_enable_device(pdev); 4888 err = pci_enable_device(pdev);
4889 if (err) { 4889 if (err) {
4890 printk(KERN_ERR PFX "Cannot enable PCI device, " 4890 dev_err(&pdev->dev, "Cannot enable PCI device, aborting.\n");
4891 "aborting.\n");
4892 return err; 4891 return err;
4893 } 4892 }
4894 4893
4895 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { 4894 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
4896 printk(KERN_ERR PFX "Cannot find proper PCI device " 4895 dev_err(&pdev->dev, "Cannot find proper PCI device "
4897 "base address, aborting.\n"); 4896 "base address, aborting.\n");
4898 err = -ENODEV; 4897 err = -ENODEV;
4899 goto err_out_disable_pdev; 4898 goto err_out_disable_pdev;
@@ -4901,7 +4900,7 @@ static int __devinit cas_init_one(struct pci_dev *pdev,
4901 4900
4902 dev = alloc_etherdev(sizeof(*cp)); 4901 dev = alloc_etherdev(sizeof(*cp));
4903 if (!dev) { 4902 if (!dev) {
4904 printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n"); 4903 dev_err(&pdev->dev, "Etherdev alloc failed, aborting.\n");
4905 err = -ENOMEM; 4904 err = -ENOMEM;
4906 goto err_out_disable_pdev; 4905 goto err_out_disable_pdev;
4907 } 4906 }
@@ -4910,8 +4909,7 @@ static int __devinit cas_init_one(struct pci_dev *pdev,
4910 4909
4911 err = pci_request_regions(pdev, dev->name); 4910 err = pci_request_regions(pdev, dev->name);
4912 if (err) { 4911 if (err) {
4913 printk(KERN_ERR PFX "Cannot obtain PCI resources, " 4912 dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting.\n");
4914 "aborting.\n");
4915 goto err_out_free_netdev; 4913 goto err_out_free_netdev;
4916 } 4914 }
4917 pci_set_master(pdev); 4915 pci_set_master(pdev);
@@ -4941,7 +4939,7 @@ static int __devinit cas_init_one(struct pci_dev *pdev,
4941 if (pci_write_config_byte(pdev, 4939 if (pci_write_config_byte(pdev,
4942 PCI_CACHE_LINE_SIZE, 4940 PCI_CACHE_LINE_SIZE,
4943 cas_cacheline_size)) { 4941 cas_cacheline_size)) {
4944 printk(KERN_ERR PFX "Could not set PCI cache " 4942 dev_err(&pdev->dev, "Could not set PCI cache "
4945 "line size\n"); 4943 "line size\n");
4946 goto err_write_cacheline; 4944 goto err_write_cacheline;
4947 } 4945 }
@@ -4955,7 +4953,7 @@ static int __devinit cas_init_one(struct pci_dev *pdev,
4955 err = pci_set_consistent_dma_mask(pdev, 4953 err = pci_set_consistent_dma_mask(pdev,
4956 DMA_64BIT_MASK); 4954 DMA_64BIT_MASK);
4957 if (err < 0) { 4955 if (err < 0) {
4958 printk(KERN_ERR PFX "Unable to obtain 64-bit DMA " 4956 dev_err(&pdev->dev, "Unable to obtain 64-bit DMA "
4959 "for consistent allocations\n"); 4957 "for consistent allocations\n");
4960 goto err_out_free_res; 4958 goto err_out_free_res;
4961 } 4959 }
@@ -4963,7 +4961,7 @@ static int __devinit cas_init_one(struct pci_dev *pdev,
4963 } else { 4961 } else {
4964 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 4962 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4965 if (err) { 4963 if (err) {
4966 printk(KERN_ERR PFX "No usable DMA configuration, " 4964 dev_err(&pdev->dev, "No usable DMA configuration, "
4967 "aborting.\n"); 4965 "aborting.\n");
4968 goto err_out_free_res; 4966 goto err_out_free_res;
4969 } 4967 }
@@ -5023,8 +5021,7 @@ static int __devinit cas_init_one(struct pci_dev *pdev,
5023 /* give us access to cassini registers */ 5021 /* give us access to cassini registers */
5024 cp->regs = pci_iomap(pdev, 0, casreg_len); 5022 cp->regs = pci_iomap(pdev, 0, casreg_len);
5025 if (cp->regs == 0UL) { 5023 if (cp->regs == 0UL) {
5026 printk(KERN_ERR PFX "Cannot map device registers, " 5024 dev_err(&pdev->dev, "Cannot map device registers, aborting.\n");
5027 "aborting.\n");
5028 goto err_out_free_res; 5025 goto err_out_free_res;
5029 } 5026 }
5030 cp->casreg_len = casreg_len; 5027 cp->casreg_len = casreg_len;
@@ -5040,8 +5037,7 @@ static int __devinit cas_init_one(struct pci_dev *pdev,
5040 pci_alloc_consistent(pdev, sizeof(struct cas_init_block), 5037 pci_alloc_consistent(pdev, sizeof(struct cas_init_block),
5041 &cp->block_dvma); 5038 &cp->block_dvma);
5042 if (!cp->init_block) { 5039 if (!cp->init_block) {
5043 printk(KERN_ERR PFX "Cannot allocate init block, " 5040 dev_err(&pdev->dev, "Cannot allocate init block, aborting.\n");
5044 "aborting.\n");
5045 goto err_out_iounmap; 5041 goto err_out_iounmap;
5046 } 5042 }
5047 5043
@@ -5085,8 +5081,7 @@ static int __devinit cas_init_one(struct pci_dev *pdev,
5085 dev->features |= NETIF_F_HIGHDMA; 5081 dev->features |= NETIF_F_HIGHDMA;
5086 5082
5087 if (register_netdev(dev)) { 5083 if (register_netdev(dev)) {
5088 printk(KERN_ERR PFX "Cannot register net device, " 5084 dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
5089 "aborting.\n");
5090 goto err_out_free_consistent; 5085 goto err_out_free_consistent;
5091 } 5086 }
5092 5087
diff --git a/drivers/net/chelsio/sge.c b/drivers/net/chelsio/sge.c
index 87f94d939ff8..61b3754f50ff 100644
--- a/drivers/net/chelsio/sge.c
+++ b/drivers/net/chelsio/sge.c
@@ -1417,7 +1417,7 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
1417 struct cpl_tx_pkt *cpl; 1417 struct cpl_tx_pkt *cpl;
1418 1418
1419#ifdef NETIF_F_TSO 1419#ifdef NETIF_F_TSO
1420 if (skb_shinfo(skb)->gso_size) { 1420 if (skb_is_gso(skb)) {
1421 int eth_type; 1421 int eth_type;
1422 struct cpl_tx_pkt_lso *hdr; 1422 struct cpl_tx_pkt_lso *hdr;
1423 1423
diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
index 47eecce35fa4..2dcca79b1f6a 100644
--- a/drivers/net/cs89x0.c
+++ b/drivers/net/cs89x0.c
@@ -1905,8 +1905,7 @@ MODULE_LICENSE("GPL");
1905 1905
1906*/ 1906*/
1907 1907
1908int 1908int __init init_module(void)
1909init_module(void)
1910{ 1909{
1911 struct net_device *dev = alloc_etherdev(sizeof(struct net_local)); 1910 struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
1912 struct net_local *lp; 1911 struct net_local *lp;
diff --git a/drivers/net/declance.c b/drivers/net/declance.c
index 2038ca7e49ce..6ad5796121c8 100644
--- a/drivers/net/declance.c
+++ b/drivers/net/declance.c
@@ -703,8 +703,8 @@ static irqreturn_t lance_dma_merr_int(const int irq, void *dev_id,
703 return IRQ_HANDLED; 703 return IRQ_HANDLED;
704} 704}
705 705
706static irqreturn_t 706static irqreturn_t lance_interrupt(const int irq, void *dev_id,
707lance_interrupt(const int irq, void *dev_id, struct pt_regs *regs) 707 struct pt_regs *regs)
708{ 708{
709 struct net_device *dev = (struct net_device *) dev_id; 709 struct net_device *dev = (struct net_device *) dev_id;
710 struct lance_private *lp = netdev_priv(dev); 710 struct lance_private *lp = netdev_priv(dev);
@@ -1253,7 +1253,7 @@ static int __init dec_lance_init(const int type, const int slot)
1253 return 0; 1253 return 0;
1254 1254
1255err_out_free_dev: 1255err_out_free_dev:
1256 kfree(dev); 1256 free_netdev(dev);
1257 1257
1258err_out: 1258err_out:
1259 return ret; 1259 return ret;
@@ -1299,6 +1299,7 @@ static void __exit dec_lance_cleanup(void)
1299 while (root_lance_dev) { 1299 while (root_lance_dev) {
1300 struct net_device *dev = root_lance_dev; 1300 struct net_device *dev = root_lance_dev;
1301 struct lance_private *lp = netdev_priv(dev); 1301 struct lance_private *lp = netdev_priv(dev);
1302
1302 unregister_netdev(dev); 1303 unregister_netdev(dev);
1303#ifdef CONFIG_TC 1304#ifdef CONFIG_TC
1304 if (lp->slot >= 0) 1305 if (lp->slot >= 0)
diff --git a/drivers/net/dl2k.c b/drivers/net/dl2k.c
index 4b6ddb70f921..402961e68c89 100644
--- a/drivers/net/dl2k.c
+++ b/drivers/net/dl2k.c
@@ -9,49 +9,10 @@
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11*/ 11*/
12/*
13 Rev Date Description
14 ==========================================================================
15 0.01 2001/05/03 Created DL2000-based linux driver
16 0.02 2001/05/21 Added VLAN and hardware checksum support.
17 1.00 2001/06/26 Added jumbo frame support.
18 1.01 2001/08/21 Added two parameters, rx_coalesce and rx_timeout.
19 1.02 2001/10/08 Supported fiber media.
20 Added flow control parameters.
21 1.03 2001/10/12 Changed the default media to 1000mbps_fd for
22 the fiber devices.
23 1.04 2001/11/08 Fixed Tx stopped when tx very busy.
24 1.05 2001/11/22 Fixed Tx stopped when unidirectional tx busy.
25 1.06 2001/12/13 Fixed disconnect bug at 10Mbps mode.
26 Fixed tx_full flag incorrect.
27 Added tx_coalesce paramter.
28 1.07 2002/01/03 Fixed miscount of RX frame error.
29 1.08 2002/01/17 Fixed the multicast bug.
30 1.09 2002/03/07 Move rx-poll-now to re-fill loop.
31 Added rio_timer() to watch rx buffers.
32 1.10 2002/04/16 Fixed miscount of carrier error.
33 1.11 2002/05/23 Added ISR schedule scheme
34 Fixed miscount of rx frame error for DGE-550SX.
35 Fixed VLAN bug.
36 1.12 2002/06/13 Lock tx_coalesce=1 on 10/100Mbps mode.
37 1.13 2002/08/13 1. Fix disconnection (many tx:carrier/rx:frame
38 errs) with some mainboards.
39 2. Use definition "DRV_NAME" "DRV_VERSION"
40 "DRV_RELDATE" for flexibility.
41 1.14 2002/08/14 Support ethtool.
42 1.15 2002/08/27 Changed the default media to Auto-Negotiation
43 for the fiber devices.
44 1.16 2002/09/04 More power down time for fiber devices auto-
45 negotiation.
46 Fix disconnect bug after ifup and ifdown.
47 1.17 2002/10/03 Fix RMON statistics overflow.
48 Always use I/O mapping to access eeprom,
49 avoid system freezing with some chipsets.
50 12
51*/
52#define DRV_NAME "D-Link DL2000-based linux driver" 13#define DRV_NAME "D-Link DL2000-based linux driver"
53#define DRV_VERSION "v1.17b" 14#define DRV_VERSION "v1.18"
54#define DRV_RELDATE "2006/03/10" 15#define DRV_RELDATE "2006/06/27"
55#include "dl2k.h" 16#include "dl2k.h"
56#include <linux/dma-mapping.h> 17#include <linux/dma-mapping.h>
57 18
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index 1b758b707134..a860ebbbf815 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -339,6 +339,17 @@ static void dm9000_timeout(struct net_device *dev)
339 spin_unlock_irqrestore(&db->lock,flags); 339 spin_unlock_irqrestore(&db->lock,flags);
340} 340}
341 341
342#ifdef CONFIG_NET_POLL_CONTROLLER
343/*
344 *Used by netconsole
345 */
346static void dm9000_poll_controller(struct net_device *dev)
347{
348 disable_irq(dev->irq);
349 dm9000_interrupt(dev->irq,dev,NULL);
350 enable_irq(dev->irq);
351}
352#endif
342 353
343/* dm9000_release_board 354/* dm9000_release_board
344 * 355 *
@@ -366,8 +377,8 @@ dm9000_release_board(struct platform_device *pdev, struct board_info *db)
366 kfree(db->data_req); 377 kfree(db->data_req);
367 } 378 }
368 379
369 if (db->addr_res != NULL) { 380 if (db->addr_req != NULL) {
370 release_resource(db->addr_res); 381 release_resource(db->addr_req);
371 kfree(db->addr_req); 382 kfree(db->addr_req);
372 } 383 }
373} 384}
@@ -538,6 +549,9 @@ dm9000_probe(struct platform_device *pdev)
538 ndev->stop = &dm9000_stop; 549 ndev->stop = &dm9000_stop;
539 ndev->get_stats = &dm9000_get_stats; 550 ndev->get_stats = &dm9000_get_stats;
540 ndev->set_multicast_list = &dm9000_hash_table; 551 ndev->set_multicast_list = &dm9000_hash_table;
552#ifdef CONFIG_NET_POLL_CONTROLLER
553 ndev->poll_controller = &dm9000_poll_controller;
554#endif
541 555
542#ifdef DM9000_PROGRAM_EEPROM 556#ifdef DM9000_PROGRAM_EEPROM
543 program_eeprom(db); 557 program_eeprom(db);
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 36d511729f71..2146cf74425e 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -132,6 +132,7 @@ static int __init dummy_init_module(void)
132 for (i = 0; i < numdummies && !err; i++) 132 for (i = 0; i < numdummies && !err; i++)
133 err = dummy_init_one(i); 133 err = dummy_init_one(i);
134 if (err) { 134 if (err) {
135 i--;
135 while (--i >= 0) 136 while (--i >= 0)
136 dummy_free_one(i); 137 dummy_free_one(i);
137 } 138 }
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index 91ef5f2fd768..ce850f1078b5 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -173,8 +173,11 @@ MODULE_LICENSE("GPL");
173MODULE_VERSION(DRV_VERSION); 173MODULE_VERSION(DRV_VERSION);
174 174
175static int debug = 3; 175static int debug = 3;
176static int eeprom_bad_csum_allow = 0;
176module_param(debug, int, 0); 177module_param(debug, int, 0);
178module_param(eeprom_bad_csum_allow, int, 0);
177MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 179MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
180MODULE_PARM_DESC(eeprom_bad_csum_allow, "Allow bad eeprom checksums");
178#define DPRINTK(nlevel, klevel, fmt, args...) \ 181#define DPRINTK(nlevel, klevel, fmt, args...) \
179 (void)((NETIF_MSG_##nlevel & nic->msg_enable) && \ 182 (void)((NETIF_MSG_##nlevel & nic->msg_enable) && \
180 printk(KERN_##klevel PFX "%s: %s: " fmt, nic->netdev->name, \ 183 printk(KERN_##klevel PFX "%s: %s: " fmt, nic->netdev->name, \
@@ -756,7 +759,8 @@ static int e100_eeprom_load(struct nic *nic)
756 checksum = le16_to_cpu(0xBABA - checksum); 759 checksum = le16_to_cpu(0xBABA - checksum);
757 if(checksum != nic->eeprom[nic->eeprom_wc - 1]) { 760 if(checksum != nic->eeprom[nic->eeprom_wc - 1]) {
758 DPRINTK(PROBE, ERR, "EEPROM corrupted\n"); 761 DPRINTK(PROBE, ERR, "EEPROM corrupted\n");
759 return -EAGAIN; 762 if (!eeprom_bad_csum_allow)
763 return -EAGAIN;
760 } 764 }
761 765
762 return 0; 766 return 0;
diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index 3042d33e2d4d..d304297c496c 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -68,7 +68,6 @@
68#ifdef NETIF_F_TSO 68#ifdef NETIF_F_TSO
69#include <net/checksum.h> 69#include <net/checksum.h>
70#endif 70#endif
71#include <linux/workqueue.h>
72#include <linux/mii.h> 71#include <linux/mii.h>
73#include <linux/ethtool.h> 72#include <linux/ethtool.h>
74#include <linux/if_vlan.h> 73#include <linux/if_vlan.h>
@@ -111,6 +110,9 @@ struct e1000_adapter;
111#define E1000_MIN_RXD 80 110#define E1000_MIN_RXD 80
112#define E1000_MAX_82544_RXD 4096 111#define E1000_MAX_82544_RXD 4096
113 112
113/* this is the size past which hardware will drop packets when setting LPE=0 */
114#define MAXIMUM_ETHERNET_VLAN_SIZE 1522
115
114/* Supported Rx Buffer Sizes */ 116/* Supported Rx Buffer Sizes */
115#define E1000_RXBUFFER_128 128 /* Used for packet split */ 117#define E1000_RXBUFFER_128 128 /* Used for packet split */
116#define E1000_RXBUFFER_256 256 /* Used for packet split */ 118#define E1000_RXBUFFER_256 256 /* Used for packet split */
@@ -143,6 +145,7 @@ struct e1000_adapter;
143 145
144#define AUTO_ALL_MODES 0 146#define AUTO_ALL_MODES 0
145#define E1000_EEPROM_82544_APM 0x0004 147#define E1000_EEPROM_82544_APM 0x0004
148#define E1000_EEPROM_ICH8_APME 0x0004
146#define E1000_EEPROM_APME 0x0400 149#define E1000_EEPROM_APME 0x0400
147 150
148#ifndef E1000_MASTER_SLAVE 151#ifndef E1000_MASTER_SLAVE
@@ -254,7 +257,6 @@ struct e1000_adapter {
254 spinlock_t tx_queue_lock; 257 spinlock_t tx_queue_lock;
255#endif 258#endif
256 atomic_t irq_sem; 259 atomic_t irq_sem;
257 struct work_struct watchdog_task;
258 struct work_struct reset_task; 260 struct work_struct reset_task;
259 uint8_t fc_autoneg; 261 uint8_t fc_autoneg;
260 262
@@ -339,8 +341,14 @@ struct e1000_adapter {
339#ifdef NETIF_F_TSO 341#ifdef NETIF_F_TSO
340 boolean_t tso_force; 342 boolean_t tso_force;
341#endif 343#endif
344 boolean_t smart_power_down; /* phy smart power down */
345 unsigned long flags;
342}; 346};
343 347
348enum e1000_state_t {
349 __E1000_DRIVER_TESTING,
350 __E1000_RESETTING,
351};
344 352
345/* e1000_main.c */ 353/* e1000_main.c */
346extern char e1000_driver_name[]; 354extern char e1000_driver_name[];
@@ -348,6 +356,7 @@ extern char e1000_driver_version[];
348int e1000_up(struct e1000_adapter *adapter); 356int e1000_up(struct e1000_adapter *adapter);
349void e1000_down(struct e1000_adapter *adapter); 357void e1000_down(struct e1000_adapter *adapter);
350void e1000_reset(struct e1000_adapter *adapter); 358void e1000_reset(struct e1000_adapter *adapter);
359void e1000_reinit_locked(struct e1000_adapter *adapter);
351int e1000_setup_all_tx_resources(struct e1000_adapter *adapter); 360int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
352void e1000_free_all_tx_resources(struct e1000_adapter *adapter); 361void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
353int e1000_setup_all_rx_resources(struct e1000_adapter *adapter); 362int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index d19664891768..88a82ba88f57 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -109,7 +109,8 @@ e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
109 SUPPORTED_1000baseT_Full| 109 SUPPORTED_1000baseT_Full|
110 SUPPORTED_Autoneg | 110 SUPPORTED_Autoneg |
111 SUPPORTED_TP); 111 SUPPORTED_TP);
112 112 if (hw->phy_type == e1000_phy_ife)
113 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
113 ecmd->advertising = ADVERTISED_TP; 114 ecmd->advertising = ADVERTISED_TP;
114 115
115 if (hw->autoneg == 1) { 116 if (hw->autoneg == 1) {
@@ -203,11 +204,9 @@ e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
203 204
204 /* reset the link */ 205 /* reset the link */
205 206
206 if (netif_running(adapter->netdev)) { 207 if (netif_running(adapter->netdev))
207 e1000_down(adapter); 208 e1000_reinit_locked(adapter);
208 e1000_reset(adapter); 209 else
209 e1000_up(adapter);
210 } else
211 e1000_reset(adapter); 210 e1000_reset(adapter);
212 211
213 return 0; 212 return 0;
@@ -254,10 +253,9 @@ e1000_set_pauseparam(struct net_device *netdev,
254 hw->original_fc = hw->fc; 253 hw->original_fc = hw->fc;
255 254
256 if (adapter->fc_autoneg == AUTONEG_ENABLE) { 255 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
257 if (netif_running(adapter->netdev)) { 256 if (netif_running(adapter->netdev))
258 e1000_down(adapter); 257 e1000_reinit_locked(adapter);
259 e1000_up(adapter); 258 else
260 } else
261 e1000_reset(adapter); 259 e1000_reset(adapter);
262 } else 260 } else
263 return ((hw->media_type == e1000_media_type_fiber) ? 261 return ((hw->media_type == e1000_media_type_fiber) ?
@@ -279,10 +277,9 @@ e1000_set_rx_csum(struct net_device *netdev, uint32_t data)
279 struct e1000_adapter *adapter = netdev_priv(netdev); 277 struct e1000_adapter *adapter = netdev_priv(netdev);
280 adapter->rx_csum = data; 278 adapter->rx_csum = data;
281 279
282 if (netif_running(netdev)) { 280 if (netif_running(netdev))
283 e1000_down(adapter); 281 e1000_reinit_locked(adapter);
284 e1000_up(adapter); 282 else
285 } else
286 e1000_reset(adapter); 283 e1000_reset(adapter);
287 return 0; 284 return 0;
288} 285}
@@ -577,6 +574,7 @@ e1000_get_drvinfo(struct net_device *netdev,
577 case e1000_82572: 574 case e1000_82572:
578 case e1000_82573: 575 case e1000_82573:
579 case e1000_80003es2lan: 576 case e1000_80003es2lan:
577 case e1000_ich8lan:
580 sprintf(firmware_version, "%d.%d-%d", 578 sprintf(firmware_version, "%d.%d-%d",
581 (eeprom_data & 0xF000) >> 12, 579 (eeprom_data & 0xF000) >> 12,
582 (eeprom_data & 0x0FF0) >> 4, 580 (eeprom_data & 0x0FF0) >> 4,
@@ -631,6 +629,9 @@ e1000_set_ringparam(struct net_device *netdev,
631 tx_ring_size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues; 629 tx_ring_size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
632 rx_ring_size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues; 630 rx_ring_size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
633 631
632 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
633 msleep(1);
634
634 if (netif_running(adapter->netdev)) 635 if (netif_running(adapter->netdev))
635 e1000_down(adapter); 636 e1000_down(adapter);
636 637
@@ -691,9 +692,11 @@ e1000_set_ringparam(struct net_device *netdev,
691 adapter->rx_ring = rx_new; 692 adapter->rx_ring = rx_new;
692 adapter->tx_ring = tx_new; 693 adapter->tx_ring = tx_new;
693 if ((err = e1000_up(adapter))) 694 if ((err = e1000_up(adapter)))
694 return err; 695 goto err_setup;
695 } 696 }
696 697
698 clear_bit(__E1000_RESETTING, &adapter->flags);
699
697 return 0; 700 return 0;
698err_setup_tx: 701err_setup_tx:
699 e1000_free_all_rx_resources(adapter); 702 e1000_free_all_rx_resources(adapter);
@@ -701,6 +704,8 @@ err_setup_rx:
701 adapter->rx_ring = rx_old; 704 adapter->rx_ring = rx_old;
702 adapter->tx_ring = tx_old; 705 adapter->tx_ring = tx_old;
703 e1000_up(adapter); 706 e1000_up(adapter);
707err_setup:
708 clear_bit(__E1000_RESETTING, &adapter->flags);
704 return err; 709 return err;
705} 710}
706 711
@@ -754,6 +759,7 @@ e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
754 toggle = 0x7FFFF3FF; 759 toggle = 0x7FFFF3FF;
755 break; 760 break;
756 case e1000_82573: 761 case e1000_82573:
762 case e1000_ich8lan:
757 toggle = 0x7FFFF033; 763 toggle = 0x7FFFF033;
758 break; 764 break;
759 default: 765 default:
@@ -773,11 +779,12 @@ e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
773 } 779 }
774 /* restore previous status */ 780 /* restore previous status */
775 E1000_WRITE_REG(&adapter->hw, STATUS, before); 781 E1000_WRITE_REG(&adapter->hw, STATUS, before);
776 782 if (adapter->hw.mac_type != e1000_ich8lan) {
777 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF); 783 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
778 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF); 784 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
779 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF); 785 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
780 REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF); 786 REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
787 }
781 REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF); 788 REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
782 REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF); 789 REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
783 REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF); 790 REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
@@ -790,20 +797,22 @@ e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
790 REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF); 797 REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
791 798
792 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000); 799 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
793 REG_SET_AND_CHECK(RCTL, 0x06DFB3FE, 0x003FFFFB); 800 before = (adapter->hw.mac_type == e1000_ich8lan ?
801 0x06C3B33E : 0x06DFB3FE);
802 REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
794 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000); 803 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
795 804
796 if (adapter->hw.mac_type >= e1000_82543) { 805 if (adapter->hw.mac_type >= e1000_82543) {
797 806
798 REG_SET_AND_CHECK(RCTL, 0x06DFB3FE, 0xFFFFFFFF); 807 REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
799 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF); 808 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
800 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF); 809 if (adapter->hw.mac_type != e1000_ich8lan)
810 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
801 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF); 811 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
802 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF); 812 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
803 813 value = (adapter->hw.mac_type == e1000_ich8lan ?
804 for (i = 0; i < E1000_RAR_ENTRIES; i++) { 814 E1000_RAR_ENTRIES_ICH8LAN : E1000_RAR_ENTRIES);
805 REG_PATTERN_TEST(RA + ((i << 1) << 2), 0xFFFFFFFF, 815 for (i = 0; i < value; i++) {
806 0xFFFFFFFF);
807 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF, 816 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
808 0xFFFFFFFF); 817 0xFFFFFFFF);
809 } 818 }
@@ -817,7 +826,9 @@ e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
817 826
818 } 827 }
819 828
820 for (i = 0; i < E1000_MC_TBL_SIZE; i++) 829 value = (adapter->hw.mac_type == e1000_ich8lan ?
830 E1000_MC_TBL_SIZE_ICH8LAN : E1000_MC_TBL_SIZE);
831 for (i = 0; i < value; i++)
821 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF); 832 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
822 833
823 *data = 0; 834 *data = 0;
@@ -889,6 +900,8 @@ e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
889 /* Test each interrupt */ 900 /* Test each interrupt */
890 for (; i < 10; i++) { 901 for (; i < 10; i++) {
891 902
903 if (adapter->hw.mac_type == e1000_ich8lan && i == 8)
904 continue;
892 /* Interrupt to test */ 905 /* Interrupt to test */
893 mask = 1 << i; 906 mask = 1 << i;
894 907
@@ -1246,18 +1259,33 @@ e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1246 } else if (adapter->hw.phy_type == e1000_phy_gg82563) { 1259 } else if (adapter->hw.phy_type == e1000_phy_gg82563) {
1247 e1000_write_phy_reg(&adapter->hw, 1260 e1000_write_phy_reg(&adapter->hw,
1248 GG82563_PHY_KMRN_MODE_CTRL, 1261 GG82563_PHY_KMRN_MODE_CTRL,
1249 0x1CE); 1262 0x1CC);
1250 } 1263 }
1251 /* force 1000, set loopback */
1252 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x4140);
1253 1264
1254 /* Now set up the MAC to the same speed/duplex as the PHY. */
1255 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL); 1265 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1256 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ 1266
1257 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ 1267 if (adapter->hw.phy_type == e1000_phy_ife) {
1258 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ 1268 /* force 100, set loopback */
1259 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */ 1269 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x6100);
1260 E1000_CTRL_FD); /* Force Duplex to FULL */ 1270
1271 /* Now set up the MAC to the same speed/duplex as the PHY. */
1272 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1273 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1274 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1275 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1276 E1000_CTRL_FD); /* Force Duplex to FULL */
1277 } else {
1278 /* force 1000, set loopback */
1279 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x4140);
1280
1281 /* Now set up the MAC to the same speed/duplex as the PHY. */
1282 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1283 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1284 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1285 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1286 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1287 E1000_CTRL_FD); /* Force Duplex to FULL */
1288 }
1261 1289
1262 if (adapter->hw.media_type == e1000_media_type_copper && 1290 if (adapter->hw.media_type == e1000_media_type_copper &&
1263 adapter->hw.phy_type == e1000_phy_m88) { 1291 adapter->hw.phy_type == e1000_phy_m88) {
@@ -1317,6 +1345,7 @@ e1000_set_phy_loopback(struct e1000_adapter *adapter)
1317 case e1000_82572: 1345 case e1000_82572:
1318 case e1000_82573: 1346 case e1000_82573:
1319 case e1000_80003es2lan: 1347 case e1000_80003es2lan:
1348 case e1000_ich8lan:
1320 return e1000_integrated_phy_loopback(adapter); 1349 return e1000_integrated_phy_loopback(adapter);
1321 break; 1350 break;
1322 1351
@@ -1568,6 +1597,7 @@ e1000_diag_test(struct net_device *netdev,
1568 struct e1000_adapter *adapter = netdev_priv(netdev); 1597 struct e1000_adapter *adapter = netdev_priv(netdev);
1569 boolean_t if_running = netif_running(netdev); 1598 boolean_t if_running = netif_running(netdev);
1570 1599
1600 set_bit(__E1000_DRIVER_TESTING, &adapter->flags);
1571 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { 1601 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1572 /* Offline tests */ 1602 /* Offline tests */
1573 1603
@@ -1582,7 +1612,8 @@ e1000_diag_test(struct net_device *netdev,
1582 eth_test->flags |= ETH_TEST_FL_FAILED; 1612 eth_test->flags |= ETH_TEST_FL_FAILED;
1583 1613
1584 if (if_running) 1614 if (if_running)
1585 e1000_down(adapter); 1615 /* indicate we're in test mode */
1616 dev_close(netdev);
1586 else 1617 else
1587 e1000_reset(adapter); 1618 e1000_reset(adapter);
1588 1619
@@ -1607,8 +1638,9 @@ e1000_diag_test(struct net_device *netdev,
1607 adapter->hw.autoneg = autoneg; 1638 adapter->hw.autoneg = autoneg;
1608 1639
1609 e1000_reset(adapter); 1640 e1000_reset(adapter);
1641 clear_bit(__E1000_DRIVER_TESTING, &adapter->flags);
1610 if (if_running) 1642 if (if_running)
1611 e1000_up(adapter); 1643 dev_open(netdev);
1612 } else { 1644 } else {
1613 /* Online tests */ 1645 /* Online tests */
1614 if (e1000_link_test(adapter, &data[4])) 1646 if (e1000_link_test(adapter, &data[4]))
@@ -1619,6 +1651,8 @@ e1000_diag_test(struct net_device *netdev,
1619 data[1] = 0; 1651 data[1] = 0;
1620 data[2] = 0; 1652 data[2] = 0;
1621 data[3] = 0; 1653 data[3] = 0;
1654
1655 clear_bit(__E1000_DRIVER_TESTING, &adapter->flags);
1622 } 1656 }
1623 msleep_interruptible(4 * 1000); 1657 msleep_interruptible(4 * 1000);
1624} 1658}
@@ -1778,21 +1812,18 @@ e1000_phys_id(struct net_device *netdev, uint32_t data)
1778 mod_timer(&adapter->blink_timer, jiffies); 1812 mod_timer(&adapter->blink_timer, jiffies);
1779 msleep_interruptible(data * 1000); 1813 msleep_interruptible(data * 1000);
1780 del_timer_sync(&adapter->blink_timer); 1814 del_timer_sync(&adapter->blink_timer);
1781 } else if (adapter->hw.mac_type < e1000_82573) { 1815 } else if (adapter->hw.phy_type == e1000_phy_ife) {
1782 E1000_WRITE_REG(&adapter->hw, LEDCTL, 1816 if (!adapter->blink_timer.function) {
1783 (E1000_LEDCTL_LED2_BLINK_RATE | 1817 init_timer(&adapter->blink_timer);
1784 E1000_LEDCTL_LED0_BLINK | E1000_LEDCTL_LED2_BLINK | 1818 adapter->blink_timer.function = e1000_led_blink_callback;
1785 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED2_MODE_SHIFT) | 1819 adapter->blink_timer.data = (unsigned long) adapter;
1786 (E1000_LEDCTL_MODE_LINK_ACTIVITY << E1000_LEDCTL_LED0_MODE_SHIFT) | 1820 }
1787 (E1000_LEDCTL_MODE_LED_OFF << E1000_LEDCTL_LED1_MODE_SHIFT))); 1821 mod_timer(&adapter->blink_timer, jiffies);
1788 msleep_interruptible(data * 1000); 1822 msleep_interruptible(data * 1000);
1823 del_timer_sync(&adapter->blink_timer);
1824 e1000_write_phy_reg(&(adapter->hw), IFE_PHY_SPECIAL_CONTROL_LED, 0);
1789 } else { 1825 } else {
1790 E1000_WRITE_REG(&adapter->hw, LEDCTL, 1826 e1000_blink_led_start(&adapter->hw);
1791 (E1000_LEDCTL_LED2_BLINK_RATE |
1792 E1000_LEDCTL_LED1_BLINK | E1000_LEDCTL_LED2_BLINK |
1793 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED2_MODE_SHIFT) |
1794 (E1000_LEDCTL_MODE_LINK_ACTIVITY << E1000_LEDCTL_LED1_MODE_SHIFT) |
1795 (E1000_LEDCTL_MODE_LED_OFF << E1000_LEDCTL_LED0_MODE_SHIFT)));
1796 msleep_interruptible(data * 1000); 1827 msleep_interruptible(data * 1000);
1797 } 1828 }
1798 1829
@@ -1807,10 +1838,8 @@ static int
1807e1000_nway_reset(struct net_device *netdev) 1838e1000_nway_reset(struct net_device *netdev)
1808{ 1839{
1809 struct e1000_adapter *adapter = netdev_priv(netdev); 1840 struct e1000_adapter *adapter = netdev_priv(netdev);
1810 if (netif_running(netdev)) { 1841 if (netif_running(netdev))
1811 e1000_down(adapter); 1842 e1000_reinit_locked(adapter);
1812 e1000_up(adapter);
1813 }
1814 return 0; 1843 return 0;
1815} 1844}
1816 1845
diff --git a/drivers/net/e1000/e1000_hw.c b/drivers/net/e1000/e1000_hw.c
index 3959039b16ec..b3b919116e0f 100644
--- a/drivers/net/e1000/e1000_hw.c
+++ b/drivers/net/e1000/e1000_hw.c
@@ -101,9 +101,37 @@ static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset,
101 101
102#define E1000_WRITE_REG_IO(a, reg, val) \ 102#define E1000_WRITE_REG_IO(a, reg, val) \
103 e1000_write_reg_io((a), E1000_##reg, val) 103 e1000_write_reg_io((a), E1000_##reg, val)
104static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw); 104static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
105 uint16_t duplex);
105static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw); 106static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
106 107
108static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw,
109 uint32_t segment);
110static int32_t e1000_get_software_flag(struct e1000_hw *hw);
111static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
112static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
113static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
114static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset,
115 uint16_t words, uint16_t *data);
116static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index,
117 uint8_t* data);
118static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index,
119 uint16_t *data);
120static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr,
121 uint16_t *data);
122static void e1000_release_software_flag(struct e1000_hw *hw);
123static void e1000_release_software_semaphore(struct e1000_hw *hw);
124static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw,
125 uint32_t no_snoop);
126static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw,
127 uint32_t index, uint8_t byte);
128static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset,
129 uint16_t words, uint16_t *data);
130static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index,
131 uint8_t data);
132static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr,
133 uint16_t data);
134
107/* IGP cable length table */ 135/* IGP cable length table */
108static const 136static const
109uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = 137uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
@@ -156,6 +184,14 @@ e1000_set_phy_type(struct e1000_hw *hw)
156 hw->phy_type = e1000_phy_igp; 184 hw->phy_type = e1000_phy_igp;
157 break; 185 break;
158 } 186 }
187 case IGP03E1000_E_PHY_ID:
188 hw->phy_type = e1000_phy_igp_3;
189 break;
190 case IFE_E_PHY_ID:
191 case IFE_PLUS_E_PHY_ID:
192 case IFE_C_E_PHY_ID:
193 hw->phy_type = e1000_phy_ife;
194 break;
159 case GG82563_E_PHY_ID: 195 case GG82563_E_PHY_ID:
160 if (hw->mac_type == e1000_80003es2lan) { 196 if (hw->mac_type == e1000_80003es2lan) {
161 hw->phy_type = e1000_phy_gg82563; 197 hw->phy_type = e1000_phy_gg82563;
@@ -332,6 +368,7 @@ e1000_set_mac_type(struct e1000_hw *hw)
332 break; 368 break;
333 case E1000_DEV_ID_82541EI: 369 case E1000_DEV_ID_82541EI:
334 case E1000_DEV_ID_82541EI_MOBILE: 370 case E1000_DEV_ID_82541EI_MOBILE:
371 case E1000_DEV_ID_82541ER_LOM:
335 hw->mac_type = e1000_82541; 372 hw->mac_type = e1000_82541;
336 break; 373 break;
337 case E1000_DEV_ID_82541ER: 374 case E1000_DEV_ID_82541ER:
@@ -341,6 +378,7 @@ e1000_set_mac_type(struct e1000_hw *hw)
341 hw->mac_type = e1000_82541_rev_2; 378 hw->mac_type = e1000_82541_rev_2;
342 break; 379 break;
343 case E1000_DEV_ID_82547EI: 380 case E1000_DEV_ID_82547EI:
381 case E1000_DEV_ID_82547EI_MOBILE:
344 hw->mac_type = e1000_82547; 382 hw->mac_type = e1000_82547;
345 break; 383 break;
346 case E1000_DEV_ID_82547GI: 384 case E1000_DEV_ID_82547GI:
@@ -354,6 +392,7 @@ e1000_set_mac_type(struct e1000_hw *hw)
354 case E1000_DEV_ID_82572EI_COPPER: 392 case E1000_DEV_ID_82572EI_COPPER:
355 case E1000_DEV_ID_82572EI_FIBER: 393 case E1000_DEV_ID_82572EI_FIBER:
356 case E1000_DEV_ID_82572EI_SERDES: 394 case E1000_DEV_ID_82572EI_SERDES:
395 case E1000_DEV_ID_82572EI:
357 hw->mac_type = e1000_82572; 396 hw->mac_type = e1000_82572;
358 break; 397 break;
359 case E1000_DEV_ID_82573E: 398 case E1000_DEV_ID_82573E:
@@ -361,16 +400,29 @@ e1000_set_mac_type(struct e1000_hw *hw)
361 case E1000_DEV_ID_82573L: 400 case E1000_DEV_ID_82573L:
362 hw->mac_type = e1000_82573; 401 hw->mac_type = e1000_82573;
363 break; 402 break;
403 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
404 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
364 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT: 405 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
365 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT: 406 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
366 hw->mac_type = e1000_80003es2lan; 407 hw->mac_type = e1000_80003es2lan;
367 break; 408 break;
409 case E1000_DEV_ID_ICH8_IGP_M_AMT:
410 case E1000_DEV_ID_ICH8_IGP_AMT:
411 case E1000_DEV_ID_ICH8_IGP_C:
412 case E1000_DEV_ID_ICH8_IFE:
413 case E1000_DEV_ID_ICH8_IGP_M:
414 hw->mac_type = e1000_ich8lan;
415 break;
368 default: 416 default:
369 /* Should never have loaded on this device */ 417 /* Should never have loaded on this device */
370 return -E1000_ERR_MAC_TYPE; 418 return -E1000_ERR_MAC_TYPE;
371 } 419 }
372 420
373 switch(hw->mac_type) { 421 switch(hw->mac_type) {
422 case e1000_ich8lan:
423 hw->swfwhw_semaphore_present = TRUE;
424 hw->asf_firmware_present = TRUE;
425 break;
374 case e1000_80003es2lan: 426 case e1000_80003es2lan:
375 hw->swfw_sync_present = TRUE; 427 hw->swfw_sync_present = TRUE;
376 /* fall through */ 428 /* fall through */
@@ -423,6 +475,7 @@ e1000_set_media_type(struct e1000_hw *hw)
423 case e1000_82542_rev2_1: 475 case e1000_82542_rev2_1:
424 hw->media_type = e1000_media_type_fiber; 476 hw->media_type = e1000_media_type_fiber;
425 break; 477 break;
478 case e1000_ich8lan:
426 case e1000_82573: 479 case e1000_82573:
427 /* The STATUS_TBIMODE bit is reserved or reused for the this 480 /* The STATUS_TBIMODE bit is reserved or reused for the this
428 * device. 481 * device.
@@ -527,6 +580,14 @@ e1000_reset_hw(struct e1000_hw *hw)
527 } while(timeout); 580 } while(timeout);
528 } 581 }
529 582
583 /* Workaround for ICH8 bit corruption issue in FIFO memory */
584 if (hw->mac_type == e1000_ich8lan) {
585 /* Set Tx and Rx buffer allocation to 8k apiece. */
586 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
587 /* Set Packet Buffer Size to 16k. */
588 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
589 }
590
530 /* Issue a global reset to the MAC. This will reset the chip's 591 /* Issue a global reset to the MAC. This will reset the chip's
531 * transmit, receive, DMA, and link units. It will not effect 592 * transmit, receive, DMA, and link units. It will not effect
532 * the current PCI configuration. The global reset bit is self- 593 * the current PCI configuration. The global reset bit is self-
@@ -550,6 +611,20 @@ e1000_reset_hw(struct e1000_hw *hw)
550 /* Reset is performed on a shadow of the control register */ 611 /* Reset is performed on a shadow of the control register */
551 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST)); 612 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
552 break; 613 break;
614 case e1000_ich8lan:
615 if (!hw->phy_reset_disable &&
616 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
617 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
618 * at the same time to make sure the interface between
619 * MAC and the external PHY is reset.
620 */
621 ctrl |= E1000_CTRL_PHY_RST;
622 }
623
624 e1000_get_software_flag(hw);
625 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
626 msec_delay(5);
627 break;
553 default: 628 default:
554 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST)); 629 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
555 break; 630 break;
@@ -591,6 +666,7 @@ e1000_reset_hw(struct e1000_hw *hw)
591 /* fall through */ 666 /* fall through */
592 case e1000_82571: 667 case e1000_82571:
593 case e1000_82572: 668 case e1000_82572:
669 case e1000_ich8lan:
594 case e1000_80003es2lan: 670 case e1000_80003es2lan:
595 ret_val = e1000_get_auto_rd_done(hw); 671 ret_val = e1000_get_auto_rd_done(hw);
596 if(ret_val) 672 if(ret_val)
@@ -633,6 +709,12 @@ e1000_reset_hw(struct e1000_hw *hw)
633 e1000_pci_set_mwi(hw); 709 e1000_pci_set_mwi(hw);
634 } 710 }
635 711
712 if (hw->mac_type == e1000_ich8lan) {
713 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
714 kab |= E1000_KABGTXD_BGSQLBIAS;
715 E1000_WRITE_REG(hw, KABGTXD, kab);
716 }
717
636 return E1000_SUCCESS; 718 return E1000_SUCCESS;
637} 719}
638 720
@@ -675,9 +757,12 @@ e1000_init_hw(struct e1000_hw *hw)
675 757
676 /* Disabling VLAN filtering. */ 758 /* Disabling VLAN filtering. */
677 DEBUGOUT("Initializing the IEEE VLAN\n"); 759 DEBUGOUT("Initializing the IEEE VLAN\n");
678 if (hw->mac_type < e1000_82545_rev_3) 760 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
679 E1000_WRITE_REG(hw, VET, 0); 761 if (hw->mac_type != e1000_ich8lan) {
680 e1000_clear_vfta(hw); 762 if (hw->mac_type < e1000_82545_rev_3)
763 E1000_WRITE_REG(hw, VET, 0);
764 e1000_clear_vfta(hw);
765 }
681 766
682 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */ 767 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
683 if(hw->mac_type == e1000_82542_rev2_0) { 768 if(hw->mac_type == e1000_82542_rev2_0) {
@@ -705,8 +790,14 @@ e1000_init_hw(struct e1000_hw *hw)
705 /* Zero out the Multicast HASH table */ 790 /* Zero out the Multicast HASH table */
706 DEBUGOUT("Zeroing the MTA\n"); 791 DEBUGOUT("Zeroing the MTA\n");
707 mta_size = E1000_MC_TBL_SIZE; 792 mta_size = E1000_MC_TBL_SIZE;
708 for(i = 0; i < mta_size; i++) 793 if (hw->mac_type == e1000_ich8lan)
794 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
795 for(i = 0; i < mta_size; i++) {
709 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); 796 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
797 /* use write flush to prevent Memory Write Block (MWB) from
798 * occuring when accessing our register space */
799 E1000_WRITE_FLUSH(hw);
800 }
710 801
711 /* Set the PCI priority bit correctly in the CTRL register. This 802 /* Set the PCI priority bit correctly in the CTRL register. This
712 * determines if the adapter gives priority to receives, or if it 803 * determines if the adapter gives priority to receives, or if it
@@ -744,6 +835,10 @@ e1000_init_hw(struct e1000_hw *hw)
744 break; 835 break;
745 } 836 }
746 837
838 /* More time needed for PHY to initialize */
839 if (hw->mac_type == e1000_ich8lan)
840 msec_delay(15);
841
747 /* Call a subroutine to configure the link and setup flow control. */ 842 /* Call a subroutine to configure the link and setup flow control. */
748 ret_val = e1000_setup_link(hw); 843 ret_val = e1000_setup_link(hw);
749 844
@@ -757,6 +852,7 @@ e1000_init_hw(struct e1000_hw *hw)
757 case e1000_82571: 852 case e1000_82571:
758 case e1000_82572: 853 case e1000_82572:
759 case e1000_82573: 854 case e1000_82573:
855 case e1000_ich8lan:
760 case e1000_80003es2lan: 856 case e1000_80003es2lan:
761 ctrl |= E1000_TXDCTL_COUNT_DESC; 857 ctrl |= E1000_TXDCTL_COUNT_DESC;
762 break; 858 break;
@@ -795,6 +891,7 @@ e1000_init_hw(struct e1000_hw *hw)
795 /* Fall through */ 891 /* Fall through */
796 case e1000_82571: 892 case e1000_82571:
797 case e1000_82572: 893 case e1000_82572:
894 case e1000_ich8lan:
798 ctrl = E1000_READ_REG(hw, TXDCTL1); 895 ctrl = E1000_READ_REG(hw, TXDCTL1);
799 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB; 896 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
800 if(hw->mac_type >= e1000_82571) 897 if(hw->mac_type >= e1000_82571)
@@ -818,6 +915,11 @@ e1000_init_hw(struct e1000_hw *hw)
818 */ 915 */
819 e1000_clear_hw_cntrs(hw); 916 e1000_clear_hw_cntrs(hw);
820 917
918 /* ICH8 No-snoop bits are opposite polarity.
919 * Set to snoop by default after reset. */
920 if (hw->mac_type == e1000_ich8lan)
921 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
922
821 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER || 923 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
822 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) { 924 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
823 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); 925 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
@@ -905,6 +1007,7 @@ e1000_setup_link(struct e1000_hw *hw)
905 */ 1007 */
906 if (hw->fc == e1000_fc_default) { 1008 if (hw->fc == e1000_fc_default) {
907 switch (hw->mac_type) { 1009 switch (hw->mac_type) {
1010 case e1000_ich8lan:
908 case e1000_82573: 1011 case e1000_82573:
909 hw->fc = e1000_fc_full; 1012 hw->fc = e1000_fc_full;
910 break; 1013 break;
@@ -971,9 +1074,12 @@ e1000_setup_link(struct e1000_hw *hw)
971 */ 1074 */
972 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n"); 1075 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
973 1076
974 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW); 1077 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
975 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH); 1078 if (hw->mac_type != e1000_ich8lan) {
976 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE); 1079 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1080 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1081 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1082 }
977 1083
978 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time); 1084 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
979 1085
@@ -1237,12 +1343,13 @@ e1000_copper_link_igp_setup(struct e1000_hw *hw)
1237 1343
1238 /* Wait 10ms for MAC to configure PHY from eeprom settings */ 1344 /* Wait 10ms for MAC to configure PHY from eeprom settings */
1239 msec_delay(15); 1345 msec_delay(15);
1240 1346 if (hw->mac_type != e1000_ich8lan) {
1241 /* Configure activity LED after PHY reset */ 1347 /* Configure activity LED after PHY reset */
1242 led_ctrl = E1000_READ_REG(hw, LEDCTL); 1348 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1243 led_ctrl &= IGP_ACTIVITY_LED_MASK; 1349 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1244 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); 1350 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1245 E1000_WRITE_REG(hw, LEDCTL, led_ctrl); 1351 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1352 }
1246 1353
1247 /* disable lplu d3 during driver init */ 1354 /* disable lplu d3 during driver init */
1248 ret_val = e1000_set_d3_lplu_state(hw, FALSE); 1355 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
@@ -1478,8 +1585,7 @@ e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1478 if (ret_val) 1585 if (ret_val)
1479 return ret_val; 1586 return ret_val;
1480 1587
1481 /* Enable Pass False Carrier on the PHY */ 1588 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1482 phy_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
1483 1589
1484 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, 1590 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1485 phy_data); 1591 phy_data);
@@ -1561,28 +1667,40 @@ e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1561 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; 1667 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1562 if(hw->disable_polarity_correction == 1) 1668 if(hw->disable_polarity_correction == 1)
1563 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; 1669 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1564 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); 1670 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1565 if(ret_val) 1671 if (ret_val)
1566 return ret_val;
1567
1568 /* Force TX_CLK in the Extended PHY Specific Control Register
1569 * to 25MHz clock.
1570 */
1571 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1572 if(ret_val)
1573 return ret_val; 1672 return ret_val;
1574 1673
1575 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1576
1577 if (hw->phy_revision < M88E1011_I_REV_4) { 1674 if (hw->phy_revision < M88E1011_I_REV_4) {
1578 /* Configure Master and Slave downshift values */ 1675 /* Force TX_CLK in the Extended PHY Specific Control Register
1579 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK | 1676 * to 25MHz clock.
1677 */
1678 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1679 if (ret_val)
1680 return ret_val;
1681
1682 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1683
1684 if ((hw->phy_revision == E1000_REVISION_2) &&
1685 (hw->phy_id == M88E1111_I_PHY_ID)) {
1686 /* Vidalia Phy, set the downshift counter to 5x */
1687 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1688 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1689 ret_val = e1000_write_phy_reg(hw,
1690 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1691 if (ret_val)
1692 return ret_val;
1693 } else {
1694 /* Configure Master and Slave downshift values */
1695 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1580 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); 1696 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1581 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X | 1697 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1582 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); 1698 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1583 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data); 1699 ret_val = e1000_write_phy_reg(hw,
1584 if(ret_val) 1700 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1585 return ret_val; 1701 if (ret_val)
1702 return ret_val;
1703 }
1586 } 1704 }
1587 1705
1588 /* SW Reset the PHY so all changes take effect */ 1706 /* SW Reset the PHY so all changes take effect */
@@ -1620,6 +1738,10 @@ e1000_copper_link_autoneg(struct e1000_hw *hw)
1620 if(hw->autoneg_advertised == 0) 1738 if(hw->autoneg_advertised == 0)
1621 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; 1739 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1622 1740
1741 /* IFE phy only supports 10/100 */
1742 if (hw->phy_type == e1000_phy_ife)
1743 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1744
1623 DEBUGOUT("Reconfiguring auto-neg advertisement params\n"); 1745 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1624 ret_val = e1000_phy_setup_autoneg(hw); 1746 ret_val = e1000_phy_setup_autoneg(hw);
1625 if(ret_val) { 1747 if(ret_val) {
@@ -1717,6 +1839,26 @@ e1000_setup_copper_link(struct e1000_hw *hw)
1717 1839
1718 DEBUGFUNC("e1000_setup_copper_link"); 1840 DEBUGFUNC("e1000_setup_copper_link");
1719 1841
1842 switch (hw->mac_type) {
1843 case e1000_80003es2lan:
1844 case e1000_ich8lan:
1845 /* Set the mac to wait the maximum time between each
1846 * iteration and increase the max iterations when
1847 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1848 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1849 if (ret_val)
1850 return ret_val;
1851 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
1852 if (ret_val)
1853 return ret_val;
1854 reg_data |= 0x3F;
1855 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1856 if (ret_val)
1857 return ret_val;
1858 default:
1859 break;
1860 }
1861
1720 /* Check if it is a valid PHY and set PHY mode if necessary. */ 1862 /* Check if it is a valid PHY and set PHY mode if necessary. */
1721 ret_val = e1000_copper_link_preconfig(hw); 1863 ret_val = e1000_copper_link_preconfig(hw);
1722 if(ret_val) 1864 if(ret_val)
@@ -1724,10 +1866,8 @@ e1000_setup_copper_link(struct e1000_hw *hw)
1724 1866
1725 switch (hw->mac_type) { 1867 switch (hw->mac_type) {
1726 case e1000_80003es2lan: 1868 case e1000_80003es2lan:
1727 ret_val = e1000_read_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL, 1869 /* Kumeran registers are written-only */
1728 &reg_data); 1870 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
1729 if (ret_val)
1730 return ret_val;
1731 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING; 1871 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1732 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL, 1872 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1733 reg_data); 1873 reg_data);
@@ -1739,6 +1879,7 @@ e1000_setup_copper_link(struct e1000_hw *hw)
1739 } 1879 }
1740 1880
1741 if (hw->phy_type == e1000_phy_igp || 1881 if (hw->phy_type == e1000_phy_igp ||
1882 hw->phy_type == e1000_phy_igp_3 ||
1742 hw->phy_type == e1000_phy_igp_2) { 1883 hw->phy_type == e1000_phy_igp_2) {
1743 ret_val = e1000_copper_link_igp_setup(hw); 1884 ret_val = e1000_copper_link_igp_setup(hw);
1744 if(ret_val) 1885 if(ret_val)
@@ -1803,7 +1944,7 @@ e1000_setup_copper_link(struct e1000_hw *hw)
1803* hw - Struct containing variables accessed by shared code 1944* hw - Struct containing variables accessed by shared code
1804******************************************************************************/ 1945******************************************************************************/
1805static int32_t 1946static int32_t
1806e1000_configure_kmrn_for_10_100(struct e1000_hw *hw) 1947e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
1807{ 1948{
1808 int32_t ret_val = E1000_SUCCESS; 1949 int32_t ret_val = E1000_SUCCESS;
1809 uint32_t tipg; 1950 uint32_t tipg;
@@ -1823,6 +1964,18 @@ e1000_configure_kmrn_for_10_100(struct e1000_hw *hw)
1823 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100; 1964 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
1824 E1000_WRITE_REG(hw, TIPG, tipg); 1965 E1000_WRITE_REG(hw, TIPG, tipg);
1825 1966
1967 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
1968
1969 if (ret_val)
1970 return ret_val;
1971
1972 if (duplex == HALF_DUPLEX)
1973 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
1974 else
1975 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
1976
1977 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
1978
1826 return ret_val; 1979 return ret_val;
1827} 1980}
1828 1981
@@ -1847,6 +2000,14 @@ e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
1847 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000; 2000 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1848 E1000_WRITE_REG(hw, TIPG, tipg); 2001 E1000_WRITE_REG(hw, TIPG, tipg);
1849 2002
2003 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2004
2005 if (ret_val)
2006 return ret_val;
2007
2008 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2009 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2010
1850 return ret_val; 2011 return ret_val;
1851} 2012}
1852 2013
@@ -1869,10 +2030,13 @@ e1000_phy_setup_autoneg(struct e1000_hw *hw)
1869 if(ret_val) 2030 if(ret_val)
1870 return ret_val; 2031 return ret_val;
1871 2032
1872 /* Read the MII 1000Base-T Control Register (Address 9). */ 2033 if (hw->phy_type != e1000_phy_ife) {
1873 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg); 2034 /* Read the MII 1000Base-T Control Register (Address 9). */
1874 if(ret_val) 2035 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1875 return ret_val; 2036 if (ret_val)
2037 return ret_val;
2038 } else
2039 mii_1000t_ctrl_reg=0;
1876 2040
1877 /* Need to parse both autoneg_advertised and fc and set up 2041 /* Need to parse both autoneg_advertised and fc and set up
1878 * the appropriate PHY registers. First we will parse for 2042 * the appropriate PHY registers. First we will parse for
@@ -1923,6 +2087,9 @@ e1000_phy_setup_autoneg(struct e1000_hw *hw)
1923 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) { 2087 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1924 DEBUGOUT("Advertise 1000mb Full duplex\n"); 2088 DEBUGOUT("Advertise 1000mb Full duplex\n");
1925 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; 2089 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
2090 if (hw->phy_type == e1000_phy_ife) {
2091 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2092 }
1926 } 2093 }
1927 2094
1928 /* Check for a software override of the flow control settings, and 2095 /* Check for a software override of the flow control settings, and
@@ -1984,9 +2151,11 @@ e1000_phy_setup_autoneg(struct e1000_hw *hw)
1984 2151
1985 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); 2152 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1986 2153
1987 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg); 2154 if (hw->phy_type != e1000_phy_ife) {
1988 if(ret_val) 2155 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1989 return ret_val; 2156 if (ret_val)
2157 return ret_val;
2158 }
1990 2159
1991 return E1000_SUCCESS; 2160 return E1000_SUCCESS;
1992} 2161}
@@ -2089,6 +2258,18 @@ e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2089 2258
2090 /* Need to reset the PHY or these changes will be ignored */ 2259 /* Need to reset the PHY or these changes will be ignored */
2091 mii_ctrl_reg |= MII_CR_RESET; 2260 mii_ctrl_reg |= MII_CR_RESET;
2261 /* Disable MDI-X support for 10/100 */
2262 } else if (hw->phy_type == e1000_phy_ife) {
2263 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2264 if (ret_val)
2265 return ret_val;
2266
2267 phy_data &= ~IFE_PMC_AUTO_MDIX;
2268 phy_data &= ~IFE_PMC_FORCE_MDIX;
2269
2270 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2271 if (ret_val)
2272 return ret_val;
2092 } else { 2273 } else {
2093 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI 2274 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2094 * forced whenever speed or duplex are forced. 2275 * forced whenever speed or duplex are forced.
@@ -2721,8 +2902,12 @@ e1000_check_for_link(struct e1000_hw *hw)
2721 */ 2902 */
2722 if(hw->tbi_compatibility_en) { 2903 if(hw->tbi_compatibility_en) {
2723 uint16_t speed, duplex; 2904 uint16_t speed, duplex;
2724 e1000_get_speed_and_duplex(hw, &speed, &duplex); 2905 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2725 if(speed != SPEED_1000) { 2906 if (ret_val) {
2907 DEBUGOUT("Error getting link speed and duplex\n");
2908 return ret_val;
2909 }
2910 if (speed != SPEED_1000) {
2726 /* If link speed is not set to gigabit speed, we do not need 2911 /* If link speed is not set to gigabit speed, we do not need
2727 * to enable TBI compatibility. 2912 * to enable TBI compatibility.
2728 */ 2913 */
@@ -2889,7 +3074,13 @@ e1000_get_speed_and_duplex(struct e1000_hw *hw,
2889 if (*speed == SPEED_1000) 3074 if (*speed == SPEED_1000)
2890 ret_val = e1000_configure_kmrn_for_1000(hw); 3075 ret_val = e1000_configure_kmrn_for_1000(hw);
2891 else 3076 else
2892 ret_val = e1000_configure_kmrn_for_10_100(hw); 3077 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3078 if (ret_val)
3079 return ret_val;
3080 }
3081
3082 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3083 ret_val = e1000_kumeran_lock_loss_workaround(hw);
2893 if (ret_val) 3084 if (ret_val)
2894 return ret_val; 3085 return ret_val;
2895 } 3086 }
@@ -3069,7 +3260,7 @@ e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3069 return data; 3260 return data;
3070} 3261}
3071 3262
3072int32_t 3263static int32_t
3073e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask) 3264e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3074{ 3265{
3075 uint32_t swfw_sync = 0; 3266 uint32_t swfw_sync = 0;
@@ -3079,6 +3270,9 @@ e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3079 3270
3080 DEBUGFUNC("e1000_swfw_sync_acquire"); 3271 DEBUGFUNC("e1000_swfw_sync_acquire");
3081 3272
3273 if (hw->swfwhw_semaphore_present)
3274 return e1000_get_software_flag(hw);
3275
3082 if (!hw->swfw_sync_present) 3276 if (!hw->swfw_sync_present)
3083 return e1000_get_hw_eeprom_semaphore(hw); 3277 return e1000_get_hw_eeprom_semaphore(hw);
3084 3278
@@ -3110,7 +3304,7 @@ e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3110 return E1000_SUCCESS; 3304 return E1000_SUCCESS;
3111} 3305}
3112 3306
3113void 3307static void
3114e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask) 3308e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3115{ 3309{
3116 uint32_t swfw_sync; 3310 uint32_t swfw_sync;
@@ -3118,6 +3312,11 @@ e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3118 3312
3119 DEBUGFUNC("e1000_swfw_sync_release"); 3313 DEBUGFUNC("e1000_swfw_sync_release");
3120 3314
3315 if (hw->swfwhw_semaphore_present) {
3316 e1000_release_software_flag(hw);
3317 return;
3318 }
3319
3121 if (!hw->swfw_sync_present) { 3320 if (!hw->swfw_sync_present) {
3122 e1000_put_hw_eeprom_semaphore(hw); 3321 e1000_put_hw_eeprom_semaphore(hw);
3123 return; 3322 return;
@@ -3160,7 +3359,8 @@ e1000_read_phy_reg(struct e1000_hw *hw,
3160 if (e1000_swfw_sync_acquire(hw, swfw)) 3359 if (e1000_swfw_sync_acquire(hw, swfw))
3161 return -E1000_ERR_SWFW_SYNC; 3360 return -E1000_ERR_SWFW_SYNC;
3162 3361
3163 if((hw->phy_type == e1000_phy_igp || 3362 if ((hw->phy_type == e1000_phy_igp ||
3363 hw->phy_type == e1000_phy_igp_3 ||
3164 hw->phy_type == e1000_phy_igp_2) && 3364 hw->phy_type == e1000_phy_igp_2) &&
3165 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { 3365 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3166 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, 3366 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
@@ -3299,7 +3499,8 @@ e1000_write_phy_reg(struct e1000_hw *hw,
3299 if (e1000_swfw_sync_acquire(hw, swfw)) 3499 if (e1000_swfw_sync_acquire(hw, swfw))
3300 return -E1000_ERR_SWFW_SYNC; 3500 return -E1000_ERR_SWFW_SYNC;
3301 3501
3302 if((hw->phy_type == e1000_phy_igp || 3502 if ((hw->phy_type == e1000_phy_igp ||
3503 hw->phy_type == e1000_phy_igp_3 ||
3303 hw->phy_type == e1000_phy_igp_2) && 3504 hw->phy_type == e1000_phy_igp_2) &&
3304 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { 3505 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3305 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, 3506 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
@@ -3401,7 +3602,7 @@ e1000_write_phy_reg_ex(struct e1000_hw *hw,
3401 return E1000_SUCCESS; 3602 return E1000_SUCCESS;
3402} 3603}
3403 3604
3404int32_t 3605static int32_t
3405e1000_read_kmrn_reg(struct e1000_hw *hw, 3606e1000_read_kmrn_reg(struct e1000_hw *hw,
3406 uint32_t reg_addr, 3607 uint32_t reg_addr,
3407 uint16_t *data) 3608 uint16_t *data)
@@ -3434,7 +3635,7 @@ e1000_read_kmrn_reg(struct e1000_hw *hw,
3434 return E1000_SUCCESS; 3635 return E1000_SUCCESS;
3435} 3636}
3436 3637
3437int32_t 3638static int32_t
3438e1000_write_kmrn_reg(struct e1000_hw *hw, 3639e1000_write_kmrn_reg(struct e1000_hw *hw,
3439 uint32_t reg_addr, 3640 uint32_t reg_addr,
3440 uint16_t data) 3641 uint16_t data)
@@ -3514,7 +3715,7 @@ e1000_phy_hw_reset(struct e1000_hw *hw)
3514 E1000_WRITE_FLUSH(hw); 3715 E1000_WRITE_FLUSH(hw);
3515 3716
3516 if (hw->mac_type >= e1000_82571) 3717 if (hw->mac_type >= e1000_82571)
3517 msec_delay(10); 3718 msec_delay_irq(10);
3518 e1000_swfw_sync_release(hw, swfw); 3719 e1000_swfw_sync_release(hw, swfw);
3519 } else { 3720 } else {
3520 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR 3721 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
@@ -3544,6 +3745,12 @@ e1000_phy_hw_reset(struct e1000_hw *hw)
3544 ret_val = e1000_get_phy_cfg_done(hw); 3745 ret_val = e1000_get_phy_cfg_done(hw);
3545 e1000_release_software_semaphore(hw); 3746 e1000_release_software_semaphore(hw);
3546 3747
3748 if ((hw->mac_type == e1000_ich8lan) &&
3749 (hw->phy_type == e1000_phy_igp_3)) {
3750 ret_val = e1000_init_lcd_from_nvm(hw);
3751 if (ret_val)
3752 return ret_val;
3753 }
3547 return ret_val; 3754 return ret_val;
3548} 3755}
3549 3756
@@ -3572,9 +3779,11 @@ e1000_phy_reset(struct e1000_hw *hw)
3572 case e1000_82541_rev_2: 3779 case e1000_82541_rev_2:
3573 case e1000_82571: 3780 case e1000_82571:
3574 case e1000_82572: 3781 case e1000_82572:
3782 case e1000_ich8lan:
3575 ret_val = e1000_phy_hw_reset(hw); 3783 ret_val = e1000_phy_hw_reset(hw);
3576 if(ret_val) 3784 if(ret_val)
3577 return ret_val; 3785 return ret_val;
3786
3578 break; 3787 break;
3579 default: 3788 default:
3580 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); 3789 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
@@ -3597,11 +3806,120 @@ e1000_phy_reset(struct e1000_hw *hw)
3597} 3806}
3598 3807
3599/****************************************************************************** 3808/******************************************************************************
3809* Work-around for 82566 power-down: on D3 entry-
3810* 1) disable gigabit link
3811* 2) write VR power-down enable
3812* 3) read it back
3813* if successful continue, else issue LCD reset and repeat
3814*
3815* hw - struct containing variables accessed by shared code
3816******************************************************************************/
3817void
3818e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3819{
3820 int32_t reg;
3821 uint16_t phy_data;
3822 int32_t retry = 0;
3823
3824 DEBUGFUNC("e1000_phy_powerdown_workaround");
3825
3826 if (hw->phy_type != e1000_phy_igp_3)
3827 return;
3828
3829 do {
3830 /* Disable link */
3831 reg = E1000_READ_REG(hw, PHY_CTRL);
3832 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3833 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3834
3835 /* Write VR power-down enable */
3836 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3837 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data |
3838 IGP3_VR_CTRL_MODE_SHUT);
3839
3840 /* Read it back and test */
3841 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
3842 if ((phy_data & IGP3_VR_CTRL_MODE_SHUT) || retry)
3843 break;
3844
3845 /* Issue PHY reset and repeat at most one more time */
3846 reg = E1000_READ_REG(hw, CTRL);
3847 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3848 retry++;
3849 } while (retry);
3850
3851 return;
3852
3853}
3854
3855/******************************************************************************
3856* Work-around for 82566 Kumeran PCS lock loss:
3857* On link status change (i.e. PCI reset, speed change) and link is up and
3858* speed is gigabit-
3859* 0) if workaround is optionally disabled do nothing
3860* 1) wait 1ms for Kumeran link to come up
3861* 2) check Kumeran Diagnostic register PCS lock loss bit
3862* 3) if not set the link is locked (all is good), otherwise...
3863* 4) reset the PHY
3864* 5) repeat up to 10 times
3865* Note: this is only called for IGP3 copper when speed is 1gb.
3866*
3867* hw - struct containing variables accessed by shared code
3868******************************************************************************/
3869static int32_t
3870e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3871{
3872 int32_t ret_val;
3873 int32_t reg;
3874 int32_t cnt;
3875 uint16_t phy_data;
3876
3877 if (hw->kmrn_lock_loss_workaround_disabled)
3878 return E1000_SUCCESS;
3879
3880 /* Make sure link is up before proceeding. If not just return.
3881 * Attempting this while link is negotiating fouls up link
3882 * stability */
3883 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3884 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3885
3886 if (phy_data & MII_SR_LINK_STATUS) {
3887 for (cnt = 0; cnt < 10; cnt++) {
3888 /* read once to clear */
3889 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3890 if (ret_val)
3891 return ret_val;
3892 /* and again to get new status */
3893 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
3894 if (ret_val)
3895 return ret_val;
3896
3897 /* check for PCS lock */
3898 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
3899 return E1000_SUCCESS;
3900
3901 /* Issue PHY reset */
3902 e1000_phy_hw_reset(hw);
3903 msec_delay_irq(5);
3904 }
3905 /* Disable GigE link negotiation */
3906 reg = E1000_READ_REG(hw, PHY_CTRL);
3907 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3908 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3909
3910 /* unable to acquire PCS lock */
3911 return E1000_ERR_PHY;
3912 }
3913
3914 return E1000_SUCCESS;
3915}
3916
3917/******************************************************************************
3600* Probes the expected PHY address for known PHY IDs 3918* Probes the expected PHY address for known PHY IDs
3601* 3919*
3602* hw - Struct containing variables accessed by shared code 3920* hw - Struct containing variables accessed by shared code
3603******************************************************************************/ 3921******************************************************************************/
3604static int32_t 3922int32_t
3605e1000_detect_gig_phy(struct e1000_hw *hw) 3923e1000_detect_gig_phy(struct e1000_hw *hw)
3606{ 3924{
3607 int32_t phy_init_status, ret_val; 3925 int32_t phy_init_status, ret_val;
@@ -3613,8 +3931,8 @@ e1000_detect_gig_phy(struct e1000_hw *hw)
3613 /* The 82571 firmware may still be configuring the PHY. In this 3931 /* The 82571 firmware may still be configuring the PHY. In this
3614 * case, we cannot access the PHY until the configuration is done. So 3932 * case, we cannot access the PHY until the configuration is done. So
3615 * we explicitly set the PHY values. */ 3933 * we explicitly set the PHY values. */
3616 if(hw->mac_type == e1000_82571 || 3934 if (hw->mac_type == e1000_82571 ||
3617 hw->mac_type == e1000_82572) { 3935 hw->mac_type == e1000_82572) {
3618 hw->phy_id = IGP01E1000_I_PHY_ID; 3936 hw->phy_id = IGP01E1000_I_PHY_ID;
3619 hw->phy_type = e1000_phy_igp_2; 3937 hw->phy_type = e1000_phy_igp_2;
3620 return E1000_SUCCESS; 3938 return E1000_SUCCESS;
@@ -3631,7 +3949,7 @@ e1000_detect_gig_phy(struct e1000_hw *hw)
3631 3949
3632 /* Read the PHY ID Registers to identify which PHY is onboard. */ 3950 /* Read the PHY ID Registers to identify which PHY is onboard. */
3633 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); 3951 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3634 if(ret_val) 3952 if (ret_val)
3635 return ret_val; 3953 return ret_val;
3636 3954
3637 hw->phy_id = (uint32_t) (phy_id_high << 16); 3955 hw->phy_id = (uint32_t) (phy_id_high << 16);
@@ -3669,6 +3987,12 @@ e1000_detect_gig_phy(struct e1000_hw *hw)
3669 case e1000_80003es2lan: 3987 case e1000_80003es2lan:
3670 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE; 3988 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
3671 break; 3989 break;
3990 case e1000_ich8lan:
3991 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
3992 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
3993 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
3994 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
3995 break;
3672 default: 3996 default:
3673 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type); 3997 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3674 return -E1000_ERR_CONFIG; 3998 return -E1000_ERR_CONFIG;
@@ -3784,6 +4108,53 @@ e1000_phy_igp_get_info(struct e1000_hw *hw,
3784} 4108}
3785 4109
3786/****************************************************************************** 4110/******************************************************************************
4111* Get PHY information from various PHY registers for ife PHY only.
4112*
4113* hw - Struct containing variables accessed by shared code
4114* phy_info - PHY information structure
4115******************************************************************************/
4116static int32_t
4117e1000_phy_ife_get_info(struct e1000_hw *hw,
4118 struct e1000_phy_info *phy_info)
4119{
4120 int32_t ret_val;
4121 uint16_t phy_data, polarity;
4122
4123 DEBUGFUNC("e1000_phy_ife_get_info");
4124
4125 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4126 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4127
4128 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4129 if (ret_val)
4130 return ret_val;
4131 phy_info->polarity_correction =
4132 (phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4133 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT;
4134
4135 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4136 ret_val = e1000_check_polarity(hw, &polarity);
4137 if (ret_val)
4138 return ret_val;
4139 } else {
4140 /* Polarity is forced. */
4141 polarity = (phy_data & IFE_PSC_FORCE_POLARITY) >>
4142 IFE_PSC_FORCE_POLARITY_SHIFT;
4143 }
4144 phy_info->cable_polarity = polarity;
4145
4146 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4147 if (ret_val)
4148 return ret_val;
4149
4150 phy_info->mdix_mode =
4151 (phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4152 IFE_PMC_MDIX_MODE_SHIFT;
4153
4154 return E1000_SUCCESS;
4155}
4156
4157/******************************************************************************
3787* Get PHY information from various PHY registers fot m88 PHY only. 4158* Get PHY information from various PHY registers fot m88 PHY only.
3788* 4159*
3789* hw - Struct containing variables accessed by shared code 4160* hw - Struct containing variables accessed by shared code
@@ -3898,9 +4269,12 @@ e1000_phy_get_info(struct e1000_hw *hw,
3898 return -E1000_ERR_CONFIG; 4269 return -E1000_ERR_CONFIG;
3899 } 4270 }
3900 4271
3901 if(hw->phy_type == e1000_phy_igp || 4272 if (hw->phy_type == e1000_phy_igp ||
4273 hw->phy_type == e1000_phy_igp_3 ||
3902 hw->phy_type == e1000_phy_igp_2) 4274 hw->phy_type == e1000_phy_igp_2)
3903 return e1000_phy_igp_get_info(hw, phy_info); 4275 return e1000_phy_igp_get_info(hw, phy_info);
4276 else if (hw->phy_type == e1000_phy_ife)
4277 return e1000_phy_ife_get_info(hw, phy_info);
3904 else 4278 else
3905 return e1000_phy_m88_get_info(hw, phy_info); 4279 return e1000_phy_m88_get_info(hw, phy_info);
3906} 4280}
@@ -4049,6 +4423,35 @@ e1000_init_eeprom_params(struct e1000_hw *hw)
4049 eeprom->use_eerd = TRUE; 4423 eeprom->use_eerd = TRUE;
4050 eeprom->use_eewr = FALSE; 4424 eeprom->use_eewr = FALSE;
4051 break; 4425 break;
4426 case e1000_ich8lan:
4427 {
4428 int32_t i = 0;
4429 uint32_t flash_size = E1000_READ_ICH8_REG(hw, ICH8_FLASH_GFPREG);
4430
4431 eeprom->type = e1000_eeprom_ich8;
4432 eeprom->use_eerd = FALSE;
4433 eeprom->use_eewr = FALSE;
4434 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4435
4436 /* Zero the shadow RAM structure. But don't load it from NVM
4437 * so as to save time for driver init */
4438 if (hw->eeprom_shadow_ram != NULL) {
4439 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4440 hw->eeprom_shadow_ram[i].modified = FALSE;
4441 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4442 }
4443 }
4444
4445 hw->flash_base_addr = (flash_size & ICH8_GFPREG_BASE_MASK) *
4446 ICH8_FLASH_SECTOR_SIZE;
4447
4448 hw->flash_bank_size = ((flash_size >> 16) & ICH8_GFPREG_BASE_MASK) + 1;
4449 hw->flash_bank_size -= (flash_size & ICH8_GFPREG_BASE_MASK);
4450 hw->flash_bank_size *= ICH8_FLASH_SECTOR_SIZE;
4451 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4452
4453 break;
4454 }
4052 default: 4455 default:
4053 break; 4456 break;
4054 } 4457 }
@@ -4469,7 +4872,10 @@ e1000_read_eeprom(struct e1000_hw *hw,
4469 return ret_val; 4872 return ret_val;
4470 } 4873 }
4471 4874
4472 if(eeprom->type == e1000_eeprom_spi) { 4875 if (eeprom->type == e1000_eeprom_ich8)
4876 return e1000_read_eeprom_ich8(hw, offset, words, data);
4877
4878 if (eeprom->type == e1000_eeprom_spi) {
4473 uint16_t word_in; 4879 uint16_t word_in;
4474 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI; 4880 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
4475 4881
@@ -4636,7 +5042,10 @@ e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
4636 5042
4637 DEBUGFUNC("e1000_is_onboard_nvm_eeprom"); 5043 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
4638 5044
4639 if(hw->mac_type == e1000_82573) { 5045 if (hw->mac_type == e1000_ich8lan)
5046 return FALSE;
5047
5048 if (hw->mac_type == e1000_82573) {
4640 eecd = E1000_READ_REG(hw, EECD); 5049 eecd = E1000_READ_REG(hw, EECD);
4641 5050
4642 /* Isolate bits 15 & 16 */ 5051 /* Isolate bits 15 & 16 */
@@ -4686,8 +5095,22 @@ e1000_validate_eeprom_checksum(struct e1000_hw *hw)
4686 } 5095 }
4687 } 5096 }
4688 5097
4689 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { 5098 if (hw->mac_type == e1000_ich8lan) {
4690 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { 5099 /* Drivers must allocate the shadow ram structure for the
5100 * EEPROM checksum to be updated. Otherwise, this bit as well
5101 * as the checksum must both be set correctly for this
5102 * validation to pass.
5103 */
5104 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5105 if ((eeprom_data & 0x40) == 0) {
5106 eeprom_data |= 0x40;
5107 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5108 e1000_update_eeprom_checksum(hw);
5109 }
5110 }
5111
5112 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5113 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4691 DEBUGOUT("EEPROM Read Error\n"); 5114 DEBUGOUT("EEPROM Read Error\n");
4692 return -E1000_ERR_EEPROM; 5115 return -E1000_ERR_EEPROM;
4693 } 5116 }
@@ -4713,6 +5136,7 @@ e1000_validate_eeprom_checksum(struct e1000_hw *hw)
4713int32_t 5136int32_t
4714e1000_update_eeprom_checksum(struct e1000_hw *hw) 5137e1000_update_eeprom_checksum(struct e1000_hw *hw)
4715{ 5138{
5139 uint32_t ctrl_ext;
4716 uint16_t checksum = 0; 5140 uint16_t checksum = 0;
4717 uint16_t i, eeprom_data; 5141 uint16_t i, eeprom_data;
4718 5142
@@ -4731,6 +5155,14 @@ e1000_update_eeprom_checksum(struct e1000_hw *hw)
4731 return -E1000_ERR_EEPROM; 5155 return -E1000_ERR_EEPROM;
4732 } else if (hw->eeprom.type == e1000_eeprom_flash) { 5156 } else if (hw->eeprom.type == e1000_eeprom_flash) {
4733 e1000_commit_shadow_ram(hw); 5157 e1000_commit_shadow_ram(hw);
5158 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5159 e1000_commit_shadow_ram(hw);
5160 /* Reload the EEPROM, or else modifications will not appear
5161 * until after next adapter reset. */
5162 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5163 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5164 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5165 msec_delay(10);
4734 } 5166 }
4735 return E1000_SUCCESS; 5167 return E1000_SUCCESS;
4736} 5168}
@@ -4770,6 +5202,9 @@ e1000_write_eeprom(struct e1000_hw *hw,
4770 if(eeprom->use_eewr == TRUE) 5202 if(eeprom->use_eewr == TRUE)
4771 return e1000_write_eeprom_eewr(hw, offset, words, data); 5203 return e1000_write_eeprom_eewr(hw, offset, words, data);
4772 5204
5205 if (eeprom->type == e1000_eeprom_ich8)
5206 return e1000_write_eeprom_ich8(hw, offset, words, data);
5207
4773 /* Prepare the EEPROM for writing */ 5208 /* Prepare the EEPROM for writing */
4774 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) 5209 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4775 return -E1000_ERR_EEPROM; 5210 return -E1000_ERR_EEPROM;
@@ -4957,11 +5392,17 @@ e1000_commit_shadow_ram(struct e1000_hw *hw)
4957 uint32_t flop = 0; 5392 uint32_t flop = 0;
4958 uint32_t i = 0; 5393 uint32_t i = 0;
4959 int32_t error = E1000_SUCCESS; 5394 int32_t error = E1000_SUCCESS;
4960 5395 uint32_t old_bank_offset = 0;
4961 /* The flop register will be used to determine if flash type is STM */ 5396 uint32_t new_bank_offset = 0;
4962 flop = E1000_READ_REG(hw, FLOP); 5397 uint32_t sector_retries = 0;
5398 uint8_t low_byte = 0;
5399 uint8_t high_byte = 0;
5400 uint8_t temp_byte = 0;
5401 boolean_t sector_write_failed = FALSE;
4963 5402
4964 if (hw->mac_type == e1000_82573) { 5403 if (hw->mac_type == e1000_82573) {
5404 /* The flop register will be used to determine if flash type is STM */
5405 flop = E1000_READ_REG(hw, FLOP);
4965 for (i=0; i < attempts; i++) { 5406 for (i=0; i < attempts; i++) {
4966 eecd = E1000_READ_REG(hw, EECD); 5407 eecd = E1000_READ_REG(hw, EECD);
4967 if ((eecd & E1000_EECD_FLUPD) == 0) { 5408 if ((eecd & E1000_EECD_FLUPD) == 0) {
@@ -4995,6 +5436,106 @@ e1000_commit_shadow_ram(struct e1000_hw *hw)
4995 } 5436 }
4996 } 5437 }
4997 5438
5439 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5440 /* We're writing to the opposite bank so if we're on bank 1,
5441 * write to bank 0 etc. We also need to erase the segment that
5442 * is going to be written */
5443 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5444 new_bank_offset = hw->flash_bank_size * 2;
5445 old_bank_offset = 0;
5446 e1000_erase_ich8_4k_segment(hw, 1);
5447 } else {
5448 old_bank_offset = hw->flash_bank_size * 2;
5449 new_bank_offset = 0;
5450 e1000_erase_ich8_4k_segment(hw, 0);
5451 }
5452
5453 do {
5454 sector_write_failed = FALSE;
5455 /* Loop for every byte in the shadow RAM,
5456 * which is in units of words. */
5457 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5458 /* Determine whether to write the value stored
5459 * in the other NVM bank or a modified value stored
5460 * in the shadow RAM */
5461 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5462 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5463 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5464 &temp_byte);
5465 udelay(100);
5466 error = e1000_verify_write_ich8_byte(hw,
5467 (i << 1) + new_bank_offset,
5468 low_byte);
5469 if (error != E1000_SUCCESS)
5470 sector_write_failed = TRUE;
5471 high_byte =
5472 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
5473 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5474 &temp_byte);
5475 udelay(100);
5476 } else {
5477 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5478 &low_byte);
5479 udelay(100);
5480 error = e1000_verify_write_ich8_byte(hw,
5481 (i << 1) + new_bank_offset, low_byte);
5482 if (error != E1000_SUCCESS)
5483 sector_write_failed = TRUE;
5484 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5485 &high_byte);
5486 }
5487
5488 /* If the word is 0x13, then make sure the signature bits
5489 * (15:14) are 11b until the commit has completed.
5490 * This will allow us to write 10b which indicates the
5491 * signature is valid. We want to do this after the write
5492 * has completed so that we don't mark the segment valid
5493 * while the write is still in progress */
5494 if (i == E1000_ICH8_NVM_SIG_WORD)
5495 high_byte = E1000_ICH8_NVM_SIG_MASK | high_byte;
5496
5497 error = e1000_verify_write_ich8_byte(hw,
5498 (i << 1) + new_bank_offset + 1, high_byte);
5499 if (error != E1000_SUCCESS)
5500 sector_write_failed = TRUE;
5501
5502 if (sector_write_failed == FALSE) {
5503 /* Clear the now not used entry in the cache */
5504 hw->eeprom_shadow_ram[i].modified = FALSE;
5505 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
5506 }
5507 }
5508
5509 /* Don't bother writing the segment valid bits if sector
5510 * programming failed. */
5511 if (sector_write_failed == FALSE) {
5512 /* Finally validate the new segment by setting bit 15:14
5513 * to 10b in word 0x13 , this can be done without an
5514 * erase as well since these bits are 11 to start with
5515 * and we need to change bit 14 to 0b */
5516 e1000_read_ich8_byte(hw,
5517 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5518 &high_byte);
5519 high_byte &= 0xBF;
5520 error = e1000_verify_write_ich8_byte(hw,
5521 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
5522 high_byte);
5523 if (error != E1000_SUCCESS)
5524 sector_write_failed = TRUE;
5525
5526 /* And invalidate the previously valid segment by setting
5527 * its signature word (0x13) high_byte to 0b. This can be
5528 * done without an erase because flash erase sets all bits
5529 * to 1's. We can write 1's to 0's without an erase */
5530 error = e1000_verify_write_ich8_byte(hw,
5531 E1000_ICH8_NVM_SIG_WORD * 2 + 1 + old_bank_offset,
5532 0);
5533 if (error != E1000_SUCCESS)
5534 sector_write_failed = TRUE;
5535 }
5536 } while (++sector_retries < 10 && sector_write_failed == TRUE);
5537 }
5538
4998 return error; 5539 return error;
4999} 5540}
5000 5541
@@ -5102,15 +5643,19 @@ e1000_init_rx_addrs(struct e1000_hw *hw)
5102 * the other port. */ 5643 * the other port. */
5103 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE)) 5644 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5104 rar_num -= 1; 5645 rar_num -= 1;
5646 if (hw->mac_type == e1000_ich8lan)
5647 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5648
5105 /* Zero out the other 15 receive addresses. */ 5649 /* Zero out the other 15 receive addresses. */
5106 DEBUGOUT("Clearing RAR[1-15]\n"); 5650 DEBUGOUT("Clearing RAR[1-15]\n");
5107 for(i = 1; i < rar_num; i++) { 5651 for(i = 1; i < rar_num; i++) {
5108 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); 5652 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5653 E1000_WRITE_FLUSH(hw);
5109 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); 5654 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5655 E1000_WRITE_FLUSH(hw);
5110 } 5656 }
5111} 5657}
5112 5658
5113#if 0
5114/****************************************************************************** 5659/******************************************************************************
5115 * Updates the MAC's list of multicast addresses. 5660 * Updates the MAC's list of multicast addresses.
5116 * 5661 *
@@ -5125,6 +5670,7 @@ e1000_init_rx_addrs(struct e1000_hw *hw)
5125 * for the first 15 multicast addresses, and hashes the rest into the 5670 * for the first 15 multicast addresses, and hashes the rest into the
5126 * multicast table. 5671 * multicast table.
5127 *****************************************************************************/ 5672 *****************************************************************************/
5673#if 0
5128void 5674void
5129e1000_mc_addr_list_update(struct e1000_hw *hw, 5675e1000_mc_addr_list_update(struct e1000_hw *hw,
5130 uint8_t *mc_addr_list, 5676 uint8_t *mc_addr_list,
@@ -5145,6 +5691,8 @@ e1000_mc_addr_list_update(struct e1000_hw *hw,
5145 /* Clear RAR[1-15] */ 5691 /* Clear RAR[1-15] */
5146 DEBUGOUT(" Clearing RAR[1-15]\n"); 5692 DEBUGOUT(" Clearing RAR[1-15]\n");
5147 num_rar_entry = E1000_RAR_ENTRIES; 5693 num_rar_entry = E1000_RAR_ENTRIES;
5694 if (hw->mac_type == e1000_ich8lan)
5695 num_rar_entry = E1000_RAR_ENTRIES_ICH8LAN;
5148 /* Reserve a spot for the Locally Administered Address to work around 5696 /* Reserve a spot for the Locally Administered Address to work around
5149 * an 82571 issue in which a reset on one port will reload the MAC on 5697 * an 82571 issue in which a reset on one port will reload the MAC on
5150 * the other port. */ 5698 * the other port. */
@@ -5153,14 +5701,19 @@ e1000_mc_addr_list_update(struct e1000_hw *hw,
5153 5701
5154 for(i = rar_used_count; i < num_rar_entry; i++) { 5702 for(i = rar_used_count; i < num_rar_entry; i++) {
5155 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); 5703 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
5704 E1000_WRITE_FLUSH(hw);
5156 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); 5705 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
5706 E1000_WRITE_FLUSH(hw);
5157 } 5707 }
5158 5708
5159 /* Clear the MTA */ 5709 /* Clear the MTA */
5160 DEBUGOUT(" Clearing MTA\n"); 5710 DEBUGOUT(" Clearing MTA\n");
5161 num_mta_entry = E1000_NUM_MTA_REGISTERS; 5711 num_mta_entry = E1000_NUM_MTA_REGISTERS;
5712 if (hw->mac_type == e1000_ich8lan)
5713 num_mta_entry = E1000_NUM_MTA_REGISTERS_ICH8LAN;
5162 for(i = 0; i < num_mta_entry; i++) { 5714 for(i = 0; i < num_mta_entry; i++) {
5163 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); 5715 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
5716 E1000_WRITE_FLUSH(hw);
5164 } 5717 }
5165 5718
5166 /* Add the new addresses */ 5719 /* Add the new addresses */
@@ -5217,24 +5770,46 @@ e1000_hash_mc_addr(struct e1000_hw *hw,
5217 * LSB MSB 5770 * LSB MSB
5218 */ 5771 */
5219 case 0: 5772 case 0:
5220 /* [47:36] i.e. 0x563 for above example address */ 5773 if (hw->mac_type == e1000_ich8lan) {
5221 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4)); 5774 /* [47:38] i.e. 0x158 for above example address */
5775 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5776 } else {
5777 /* [47:36] i.e. 0x563 for above example address */
5778 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5779 }
5222 break; 5780 break;
5223 case 1: 5781 case 1:
5224 /* [46:35] i.e. 0xAC6 for above example address */ 5782 if (hw->mac_type == e1000_ich8lan) {
5225 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5)); 5783 /* [46:37] i.e. 0x2B1 for above example address */
5784 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5785 } else {
5786 /* [46:35] i.e. 0xAC6 for above example address */
5787 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5788 }
5226 break; 5789 break;
5227 case 2: 5790 case 2:
5228 /* [45:34] i.e. 0x5D8 for above example address */ 5791 if (hw->mac_type == e1000_ich8lan) {
5229 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6)); 5792 /*[45:36] i.e. 0x163 for above example address */
5793 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5794 } else {
5795 /* [45:34] i.e. 0x5D8 for above example address */
5796 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5797 }
5230 break; 5798 break;
5231 case 3: 5799 case 3:
5232 /* [43:32] i.e. 0x634 for above example address */ 5800 if (hw->mac_type == e1000_ich8lan) {
5233 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8)); 5801 /* [43:34] i.e. 0x18D for above example address */
5802 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5803 } else {
5804 /* [43:32] i.e. 0x634 for above example address */
5805 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5806 }
5234 break; 5807 break;
5235 } 5808 }
5236 5809
5237 hash_value &= 0xFFF; 5810 hash_value &= 0xFFF;
5811 if (hw->mac_type == e1000_ich8lan)
5812 hash_value &= 0x3FF;
5238 5813
5239 return hash_value; 5814 return hash_value;
5240} 5815}
@@ -5262,6 +5837,8 @@ e1000_mta_set(struct e1000_hw *hw,
5262 * register are determined by the lower 5 bits of the value. 5837 * register are determined by the lower 5 bits of the value.
5263 */ 5838 */
5264 hash_reg = (hash_value >> 5) & 0x7F; 5839 hash_reg = (hash_value >> 5) & 0x7F;
5840 if (hw->mac_type == e1000_ich8lan)
5841 hash_reg &= 0x1F;
5265 hash_bit = hash_value & 0x1F; 5842 hash_bit = hash_value & 0x1F;
5266 5843
5267 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg); 5844 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
@@ -5275,9 +5852,12 @@ e1000_mta_set(struct e1000_hw *hw,
5275 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) { 5852 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
5276 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1)); 5853 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5277 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta); 5854 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5855 E1000_WRITE_FLUSH(hw);
5278 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp); 5856 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
5857 E1000_WRITE_FLUSH(hw);
5279 } else { 5858 } else {
5280 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta); 5859 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
5860 E1000_WRITE_FLUSH(hw);
5281 } 5861 }
5282} 5862}
5283 5863
@@ -5334,7 +5914,9 @@ e1000_rar_set(struct e1000_hw *hw,
5334 } 5914 }
5335 5915
5336 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low); 5916 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
5917 E1000_WRITE_FLUSH(hw);
5337 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high); 5918 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
5919 E1000_WRITE_FLUSH(hw);
5338} 5920}
5339 5921
5340/****************************************************************************** 5922/******************************************************************************
@@ -5351,12 +5933,18 @@ e1000_write_vfta(struct e1000_hw *hw,
5351{ 5933{
5352 uint32_t temp; 5934 uint32_t temp;
5353 5935
5354 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) { 5936 if (hw->mac_type == e1000_ich8lan)
5937 return;
5938
5939 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
5355 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1)); 5940 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5356 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); 5941 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5942 E1000_WRITE_FLUSH(hw);
5357 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp); 5943 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
5944 E1000_WRITE_FLUSH(hw);
5358 } else { 5945 } else {
5359 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); 5946 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
5947 E1000_WRITE_FLUSH(hw);
5360 } 5948 }
5361} 5949}
5362 5950
@@ -5373,6 +5961,9 @@ e1000_clear_vfta(struct e1000_hw *hw)
5373 uint32_t vfta_offset = 0; 5961 uint32_t vfta_offset = 0;
5374 uint32_t vfta_bit_in_reg = 0; 5962 uint32_t vfta_bit_in_reg = 0;
5375 5963
5964 if (hw->mac_type == e1000_ich8lan)
5965 return;
5966
5376 if (hw->mac_type == e1000_82573) { 5967 if (hw->mac_type == e1000_82573) {
5377 if (hw->mng_cookie.vlan_id != 0) { 5968 if (hw->mng_cookie.vlan_id != 0) {
5378 /* The VFTA is a 4096b bit-field, each identifying a single VLAN 5969 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
@@ -5392,6 +5983,7 @@ e1000_clear_vfta(struct e1000_hw *hw)
5392 * manageability unit */ 5983 * manageability unit */
5393 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0; 5984 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
5394 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value); 5985 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
5986 E1000_WRITE_FLUSH(hw);
5395 } 5987 }
5396} 5988}
5397 5989
@@ -5421,9 +6013,18 @@ e1000_id_led_init(struct e1000_hw * hw)
5421 DEBUGOUT("EEPROM Read Error\n"); 6013 DEBUGOUT("EEPROM Read Error\n");
5422 return -E1000_ERR_EEPROM; 6014 return -E1000_ERR_EEPROM;
5423 } 6015 }
5424 if((eeprom_data== ID_LED_RESERVED_0000) || 6016
5425 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT; 6017 if ((hw->mac_type == e1000_82573) &&
5426 for(i = 0; i < 4; i++) { 6018 (eeprom_data == ID_LED_RESERVED_82573))
6019 eeprom_data = ID_LED_DEFAULT_82573;
6020 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6021 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6022 if (hw->mac_type == e1000_ich8lan)
6023 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6024 else
6025 eeprom_data = ID_LED_DEFAULT;
6026 }
6027 for (i = 0; i < 4; i++) {
5427 temp = (eeprom_data >> (i << 2)) & led_mask; 6028 temp = (eeprom_data >> (i << 2)) & led_mask;
5428 switch(temp) { 6029 switch(temp) {
5429 case ID_LED_ON1_DEF2: 6030 case ID_LED_ON1_DEF2:
@@ -5519,6 +6120,44 @@ e1000_setup_led(struct e1000_hw *hw)
5519} 6120}
5520 6121
5521/****************************************************************************** 6122/******************************************************************************
6123 * Used on 82571 and later Si that has LED blink bits.
6124 * Callers must use their own timer and should have already called
6125 * e1000_id_led_init()
6126 * Call e1000_cleanup led() to stop blinking
6127 *
6128 * hw - Struct containing variables accessed by shared code
6129 *****************************************************************************/
6130int32_t
6131e1000_blink_led_start(struct e1000_hw *hw)
6132{
6133 int16_t i;
6134 uint32_t ledctl_blink = 0;
6135
6136 DEBUGFUNC("e1000_id_led_blink_on");
6137
6138 if (hw->mac_type < e1000_82571) {
6139 /* Nothing to do */
6140 return E1000_SUCCESS;
6141 }
6142 if (hw->media_type == e1000_media_type_fiber) {
6143 /* always blink LED0 for PCI-E fiber */
6144 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6145 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6146 } else {
6147 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6148 ledctl_blink = hw->ledctl_mode2;
6149 for (i=0; i < 4; i++)
6150 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6151 E1000_LEDCTL_MODE_LED_ON)
6152 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6153 }
6154
6155 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6156
6157 return E1000_SUCCESS;
6158}
6159
6160/******************************************************************************
5522 * Restores the saved state of the SW controlable LED. 6161 * Restores the saved state of the SW controlable LED.
5523 * 6162 *
5524 * hw - Struct containing variables accessed by shared code 6163 * hw - Struct containing variables accessed by shared code
@@ -5548,6 +6187,10 @@ e1000_cleanup_led(struct e1000_hw *hw)
5548 return ret_val; 6187 return ret_val;
5549 /* Fall Through */ 6188 /* Fall Through */
5550 default: 6189 default:
6190 if (hw->phy_type == e1000_phy_ife) {
6191 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6192 break;
6193 }
5551 /* Restore LEDCTL settings */ 6194 /* Restore LEDCTL settings */
5552 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default); 6195 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
5553 break; 6196 break;
@@ -5592,7 +6235,10 @@ e1000_led_on(struct e1000_hw *hw)
5592 /* Clear SW Defineable Pin 0 to turn on the LED */ 6235 /* Clear SW Defineable Pin 0 to turn on the LED */
5593 ctrl &= ~E1000_CTRL_SWDPIN0; 6236 ctrl &= ~E1000_CTRL_SWDPIN0;
5594 ctrl |= E1000_CTRL_SWDPIO0; 6237 ctrl |= E1000_CTRL_SWDPIO0;
5595 } else if(hw->media_type == e1000_media_type_copper) { 6238 } else if (hw->phy_type == e1000_phy_ife) {
6239 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6240 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6241 } else if (hw->media_type == e1000_media_type_copper) {
5596 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2); 6242 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
5597 return E1000_SUCCESS; 6243 return E1000_SUCCESS;
5598 } 6244 }
@@ -5640,7 +6286,10 @@ e1000_led_off(struct e1000_hw *hw)
5640 /* Set SW Defineable Pin 0 to turn off the LED */ 6286 /* Set SW Defineable Pin 0 to turn off the LED */
5641 ctrl |= E1000_CTRL_SWDPIN0; 6287 ctrl |= E1000_CTRL_SWDPIN0;
5642 ctrl |= E1000_CTRL_SWDPIO0; 6288 ctrl |= E1000_CTRL_SWDPIO0;
5643 } else if(hw->media_type == e1000_media_type_copper) { 6289 } else if (hw->phy_type == e1000_phy_ife) {
6290 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6291 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6292 } else if (hw->media_type == e1000_media_type_copper) {
5644 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1); 6293 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5645 return E1000_SUCCESS; 6294 return E1000_SUCCESS;
5646 } 6295 }
@@ -5678,12 +6327,16 @@ e1000_clear_hw_cntrs(struct e1000_hw *hw)
5678 temp = E1000_READ_REG(hw, XOFFRXC); 6327 temp = E1000_READ_REG(hw, XOFFRXC);
5679 temp = E1000_READ_REG(hw, XOFFTXC); 6328 temp = E1000_READ_REG(hw, XOFFTXC);
5680 temp = E1000_READ_REG(hw, FCRUC); 6329 temp = E1000_READ_REG(hw, FCRUC);
6330
6331 if (hw->mac_type != e1000_ich8lan) {
5681 temp = E1000_READ_REG(hw, PRC64); 6332 temp = E1000_READ_REG(hw, PRC64);
5682 temp = E1000_READ_REG(hw, PRC127); 6333 temp = E1000_READ_REG(hw, PRC127);
5683 temp = E1000_READ_REG(hw, PRC255); 6334 temp = E1000_READ_REG(hw, PRC255);
5684 temp = E1000_READ_REG(hw, PRC511); 6335 temp = E1000_READ_REG(hw, PRC511);
5685 temp = E1000_READ_REG(hw, PRC1023); 6336 temp = E1000_READ_REG(hw, PRC1023);
5686 temp = E1000_READ_REG(hw, PRC1522); 6337 temp = E1000_READ_REG(hw, PRC1522);
6338 }
6339
5687 temp = E1000_READ_REG(hw, GPRC); 6340 temp = E1000_READ_REG(hw, GPRC);
5688 temp = E1000_READ_REG(hw, BPRC); 6341 temp = E1000_READ_REG(hw, BPRC);
5689 temp = E1000_READ_REG(hw, MPRC); 6342 temp = E1000_READ_REG(hw, MPRC);
@@ -5703,12 +6356,16 @@ e1000_clear_hw_cntrs(struct e1000_hw *hw)
5703 temp = E1000_READ_REG(hw, TOTH); 6356 temp = E1000_READ_REG(hw, TOTH);
5704 temp = E1000_READ_REG(hw, TPR); 6357 temp = E1000_READ_REG(hw, TPR);
5705 temp = E1000_READ_REG(hw, TPT); 6358 temp = E1000_READ_REG(hw, TPT);
6359
6360 if (hw->mac_type != e1000_ich8lan) {
5706 temp = E1000_READ_REG(hw, PTC64); 6361 temp = E1000_READ_REG(hw, PTC64);
5707 temp = E1000_READ_REG(hw, PTC127); 6362 temp = E1000_READ_REG(hw, PTC127);
5708 temp = E1000_READ_REG(hw, PTC255); 6363 temp = E1000_READ_REG(hw, PTC255);
5709 temp = E1000_READ_REG(hw, PTC511); 6364 temp = E1000_READ_REG(hw, PTC511);
5710 temp = E1000_READ_REG(hw, PTC1023); 6365 temp = E1000_READ_REG(hw, PTC1023);
5711 temp = E1000_READ_REG(hw, PTC1522); 6366 temp = E1000_READ_REG(hw, PTC1522);
6367 }
6368
5712 temp = E1000_READ_REG(hw, MPTC); 6369 temp = E1000_READ_REG(hw, MPTC);
5713 temp = E1000_READ_REG(hw, BPTC); 6370 temp = E1000_READ_REG(hw, BPTC);
5714 6371
@@ -5731,6 +6388,9 @@ e1000_clear_hw_cntrs(struct e1000_hw *hw)
5731 6388
5732 temp = E1000_READ_REG(hw, IAC); 6389 temp = E1000_READ_REG(hw, IAC);
5733 temp = E1000_READ_REG(hw, ICRXOC); 6390 temp = E1000_READ_REG(hw, ICRXOC);
6391
6392 if (hw->mac_type == e1000_ich8lan) return;
6393
5734 temp = E1000_READ_REG(hw, ICRXPTC); 6394 temp = E1000_READ_REG(hw, ICRXPTC);
5735 temp = E1000_READ_REG(hw, ICRXATC); 6395 temp = E1000_READ_REG(hw, ICRXATC);
5736 temp = E1000_READ_REG(hw, ICTXPTC); 6396 temp = E1000_READ_REG(hw, ICTXPTC);
@@ -5911,6 +6571,7 @@ e1000_get_bus_info(struct e1000_hw *hw)
5911 hw->bus_width = e1000_bus_width_pciex_1; 6571 hw->bus_width = e1000_bus_width_pciex_1;
5912 break; 6572 break;
5913 case e1000_82571: 6573 case e1000_82571:
6574 case e1000_ich8lan:
5914 case e1000_80003es2lan: 6575 case e1000_80003es2lan:
5915 hw->bus_type = e1000_bus_type_pci_express; 6576 hw->bus_type = e1000_bus_type_pci_express;
5916 hw->bus_speed = e1000_bus_speed_2500; 6577 hw->bus_speed = e1000_bus_speed_2500;
@@ -5948,8 +6609,6 @@ e1000_get_bus_info(struct e1000_hw *hw)
5948 break; 6609 break;
5949 } 6610 }
5950} 6611}
5951
5952#if 0
5953/****************************************************************************** 6612/******************************************************************************
5954 * Reads a value from one of the devices registers using port I/O (as opposed 6613 * Reads a value from one of the devices registers using port I/O (as opposed
5955 * memory mapped I/O). Only 82544 and newer devices support port I/O. 6614 * memory mapped I/O). Only 82544 and newer devices support port I/O.
@@ -5957,6 +6616,7 @@ e1000_get_bus_info(struct e1000_hw *hw)
5957 * hw - Struct containing variables accessed by shared code 6616 * hw - Struct containing variables accessed by shared code
5958 * offset - offset to read from 6617 * offset - offset to read from
5959 *****************************************************************************/ 6618 *****************************************************************************/
6619#if 0
5960uint32_t 6620uint32_t
5961e1000_read_reg_io(struct e1000_hw *hw, 6621e1000_read_reg_io(struct e1000_hw *hw,
5962 uint32_t offset) 6622 uint32_t offset)
@@ -6012,8 +6672,6 @@ e1000_get_cable_length(struct e1000_hw *hw,
6012{ 6672{
6013 int32_t ret_val; 6673 int32_t ret_val;
6014 uint16_t agc_value = 0; 6674 uint16_t agc_value = 0;
6015 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6016 uint16_t max_agc = 0;
6017 uint16_t i, phy_data; 6675 uint16_t i, phy_data;
6018 uint16_t cable_length; 6676 uint16_t cable_length;
6019 6677
@@ -6086,6 +6744,8 @@ e1000_get_cable_length(struct e1000_hw *hw,
6086 break; 6744 break;
6087 } 6745 }
6088 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */ 6746 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
6747 uint16_t cur_agc_value;
6748 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
6089 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = 6749 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6090 {IGP01E1000_PHY_AGC_A, 6750 {IGP01E1000_PHY_AGC_A,
6091 IGP01E1000_PHY_AGC_B, 6751 IGP01E1000_PHY_AGC_B,
@@ -6098,23 +6758,23 @@ e1000_get_cable_length(struct e1000_hw *hw,
6098 if(ret_val) 6758 if(ret_val)
6099 return ret_val; 6759 return ret_val;
6100 6760
6101 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT; 6761 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
6102 6762
6103 /* Array bound check. */ 6763 /* Value bound check. */
6104 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) || 6764 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6105 (cur_agc == 0)) 6765 (cur_agc_value == 0))
6106 return -E1000_ERR_PHY; 6766 return -E1000_ERR_PHY;
6107 6767
6108 agc_value += cur_agc; 6768 agc_value += cur_agc_value;
6109 6769
6110 /* Update minimal AGC value. */ 6770 /* Update minimal AGC value. */
6111 if(min_agc > cur_agc) 6771 if (min_agc_value > cur_agc_value)
6112 min_agc = cur_agc; 6772 min_agc_value = cur_agc_value;
6113 } 6773 }
6114 6774
6115 /* Remove the minimal AGC result for length < 50m */ 6775 /* Remove the minimal AGC result for length < 50m */
6116 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) { 6776 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6117 agc_value -= min_agc; 6777 agc_value -= min_agc_value;
6118 6778
6119 /* Get the average length of the remaining 3 channels */ 6779 /* Get the average length of the remaining 3 channels */
6120 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1); 6780 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
@@ -6130,7 +6790,10 @@ e1000_get_cable_length(struct e1000_hw *hw,
6130 IGP01E1000_AGC_RANGE) : 0; 6790 IGP01E1000_AGC_RANGE) : 0;
6131 *max_length = e1000_igp_cable_length_table[agc_value] + 6791 *max_length = e1000_igp_cable_length_table[agc_value] +
6132 IGP01E1000_AGC_RANGE; 6792 IGP01E1000_AGC_RANGE;
6133 } else if (hw->phy_type == e1000_phy_igp_2) { 6793 } else if (hw->phy_type == e1000_phy_igp_2 ||
6794 hw->phy_type == e1000_phy_igp_3) {
6795 uint16_t cur_agc_index, max_agc_index = 0;
6796 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
6134 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = 6797 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6135 {IGP02E1000_PHY_AGC_A, 6798 {IGP02E1000_PHY_AGC_A,
6136 IGP02E1000_PHY_AGC_B, 6799 IGP02E1000_PHY_AGC_B,
@@ -6145,19 +6808,27 @@ e1000_get_cable_length(struct e1000_hw *hw,
6145 /* Getting bits 15:9, which represent the combination of course and 6808 /* Getting bits 15:9, which represent the combination of course and
6146 * fine gain values. The result is a number that can be put into 6809 * fine gain values. The result is a number that can be put into
6147 * the lookup table to obtain the approximate cable length. */ 6810 * the lookup table to obtain the approximate cable length. */
6148 cur_agc = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) & 6811 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6149 IGP02E1000_AGC_LENGTH_MASK; 6812 IGP02E1000_AGC_LENGTH_MASK;
6150 6813
6151 /* Remove min & max AGC values from calculation. */ 6814 /* Array index bound check. */
6152 if (e1000_igp_2_cable_length_table[min_agc] > e1000_igp_2_cable_length_table[cur_agc]) 6815 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6153 min_agc = cur_agc; 6816 (cur_agc_index == 0))
6154 if (e1000_igp_2_cable_length_table[max_agc] < e1000_igp_2_cable_length_table[cur_agc]) 6817 return -E1000_ERR_PHY;
6155 max_agc = cur_agc;
6156 6818
6157 agc_value += e1000_igp_2_cable_length_table[cur_agc]; 6819 /* Remove min & max AGC values from calculation. */
6820 if (e1000_igp_2_cable_length_table[min_agc_index] >
6821 e1000_igp_2_cable_length_table[cur_agc_index])
6822 min_agc_index = cur_agc_index;
6823 if (e1000_igp_2_cable_length_table[max_agc_index] <
6824 e1000_igp_2_cable_length_table[cur_agc_index])
6825 max_agc_index = cur_agc_index;
6826
6827 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
6158 } 6828 }
6159 6829
6160 agc_value -= (e1000_igp_2_cable_length_table[min_agc] + e1000_igp_2_cable_length_table[max_agc]); 6830 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6831 e1000_igp_2_cable_length_table[max_agc_index]);
6161 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2); 6832 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6162 6833
6163 /* Calculate cable length with the error range of +/- 10 meters. */ 6834 /* Calculate cable length with the error range of +/- 10 meters. */
@@ -6203,7 +6874,8 @@ e1000_check_polarity(struct e1000_hw *hw,
6203 return ret_val; 6874 return ret_val;
6204 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >> 6875 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
6205 M88E1000_PSSR_REV_POLARITY_SHIFT; 6876 M88E1000_PSSR_REV_POLARITY_SHIFT;
6206 } else if(hw->phy_type == e1000_phy_igp || 6877 } else if (hw->phy_type == e1000_phy_igp ||
6878 hw->phy_type == e1000_phy_igp_3 ||
6207 hw->phy_type == e1000_phy_igp_2) { 6879 hw->phy_type == e1000_phy_igp_2) {
6208 /* Read the Status register to check the speed */ 6880 /* Read the Status register to check the speed */
6209 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, 6881 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
@@ -6229,6 +6901,13 @@ e1000_check_polarity(struct e1000_hw *hw,
6229 * 100 Mbps this bit is always 0) */ 6901 * 100 Mbps this bit is always 0) */
6230 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED; 6902 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
6231 } 6903 }
6904 } else if (hw->phy_type == e1000_phy_ife) {
6905 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6906 &phy_data);
6907 if (ret_val)
6908 return ret_val;
6909 *polarity = (phy_data & IFE_PESC_POLARITY_REVERSED) >>
6910 IFE_PESC_POLARITY_REVERSED_SHIFT;
6232 } 6911 }
6233 return E1000_SUCCESS; 6912 return E1000_SUCCESS;
6234} 6913}
@@ -6256,7 +6935,8 @@ e1000_check_downshift(struct e1000_hw *hw)
6256 6935
6257 DEBUGFUNC("e1000_check_downshift"); 6936 DEBUGFUNC("e1000_check_downshift");
6258 6937
6259 if(hw->phy_type == e1000_phy_igp || 6938 if (hw->phy_type == e1000_phy_igp ||
6939 hw->phy_type == e1000_phy_igp_3 ||
6260 hw->phy_type == e1000_phy_igp_2) { 6940 hw->phy_type == e1000_phy_igp_2) {
6261 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH, 6941 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6262 &phy_data); 6942 &phy_data);
@@ -6273,6 +6953,9 @@ e1000_check_downshift(struct e1000_hw *hw)
6273 6953
6274 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >> 6954 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6275 M88E1000_PSSR_DOWNSHIFT_SHIFT; 6955 M88E1000_PSSR_DOWNSHIFT_SHIFT;
6956 } else if (hw->phy_type == e1000_phy_ife) {
6957 /* e1000_phy_ife supports 10/100 speed only */
6958 hw->speed_downgraded = FALSE;
6276 } 6959 }
6277 6960
6278 return E1000_SUCCESS; 6961 return E1000_SUCCESS;
@@ -6317,7 +7000,9 @@ e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6317 7000
6318 if(speed == SPEED_1000) { 7001 if(speed == SPEED_1000) {
6319 7002
6320 e1000_get_cable_length(hw, &min_length, &max_length); 7003 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7004 if (ret_val)
7005 return ret_val;
6321 7006
6322 if((hw->dsp_config_state == e1000_dsp_config_enabled) && 7007 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
6323 min_length >= e1000_igp_cable_length_50) { 7008 min_length >= e1000_igp_cable_length_50) {
@@ -6525,20 +7210,27 @@ static int32_t
6525e1000_set_d3_lplu_state(struct e1000_hw *hw, 7210e1000_set_d3_lplu_state(struct e1000_hw *hw,
6526 boolean_t active) 7211 boolean_t active)
6527{ 7212{
7213 uint32_t phy_ctrl = 0;
6528 int32_t ret_val; 7214 int32_t ret_val;
6529 uint16_t phy_data; 7215 uint16_t phy_data;
6530 DEBUGFUNC("e1000_set_d3_lplu_state"); 7216 DEBUGFUNC("e1000_set_d3_lplu_state");
6531 7217
6532 if(hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2) 7218 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7219 && hw->phy_type != e1000_phy_igp_3)
6533 return E1000_SUCCESS; 7220 return E1000_SUCCESS;
6534 7221
6535 /* During driver activity LPLU should not be used or it will attain link 7222 /* During driver activity LPLU should not be used or it will attain link
6536 * from the lowest speeds starting from 10Mbps. The capability is used for 7223 * from the lowest speeds starting from 10Mbps. The capability is used for
6537 * Dx transitions and states */ 7224 * Dx transitions and states */
6538 if(hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) { 7225 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
6539 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data); 7226 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
6540 if(ret_val) 7227 if (ret_val)
6541 return ret_val; 7228 return ret_val;
7229 } else if (hw->mac_type == e1000_ich8lan) {
7230 /* MAC writes into PHY register based on the state transition
7231 * and start auto-negotiation. SW driver can overwrite the settings
7232 * in CSR PHY power control E1000_PHY_CTRL register. */
7233 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
6542 } else { 7234 } else {
6543 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); 7235 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6544 if(ret_val) 7236 if(ret_val)
@@ -6553,11 +7245,16 @@ e1000_set_d3_lplu_state(struct e1000_hw *hw,
6553 if(ret_val) 7245 if(ret_val)
6554 return ret_val; 7246 return ret_val;
6555 } else { 7247 } else {
7248 if (hw->mac_type == e1000_ich8lan) {
7249 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7250 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7251 } else {
6556 phy_data &= ~IGP02E1000_PM_D3_LPLU; 7252 phy_data &= ~IGP02E1000_PM_D3_LPLU;
6557 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, 7253 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6558 phy_data); 7254 phy_data);
6559 if (ret_val) 7255 if (ret_val)
6560 return ret_val; 7256 return ret_val;
7257 }
6561 } 7258 }
6562 7259
6563 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during 7260 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
@@ -6593,17 +7290,22 @@ e1000_set_d3_lplu_state(struct e1000_hw *hw,
6593 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) { 7290 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
6594 7291
6595 if(hw->mac_type == e1000_82541_rev_2 || 7292 if(hw->mac_type == e1000_82541_rev_2 ||
6596 hw->mac_type == e1000_82547_rev_2) { 7293 hw->mac_type == e1000_82547_rev_2) {
6597 phy_data |= IGP01E1000_GMII_FLEX_SPD; 7294 phy_data |= IGP01E1000_GMII_FLEX_SPD;
6598 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data); 7295 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
6599 if(ret_val) 7296 if(ret_val)
6600 return ret_val; 7297 return ret_val;
6601 } else { 7298 } else {
7299 if (hw->mac_type == e1000_ich8lan) {
7300 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7301 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7302 } else {
6602 phy_data |= IGP02E1000_PM_D3_LPLU; 7303 phy_data |= IGP02E1000_PM_D3_LPLU;
6603 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, 7304 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
6604 phy_data); 7305 phy_data);
6605 if (ret_val) 7306 if (ret_val)
6606 return ret_val; 7307 return ret_val;
7308 }
6607 } 7309 }
6608 7310
6609 /* When LPLU is enabled we should disable SmartSpeed */ 7311 /* When LPLU is enabled we should disable SmartSpeed */
@@ -6638,6 +7340,7 @@ static int32_t
6638e1000_set_d0_lplu_state(struct e1000_hw *hw, 7340e1000_set_d0_lplu_state(struct e1000_hw *hw,
6639 boolean_t active) 7341 boolean_t active)
6640{ 7342{
7343 uint32_t phy_ctrl = 0;
6641 int32_t ret_val; 7344 int32_t ret_val;
6642 uint16_t phy_data; 7345 uint16_t phy_data;
6643 DEBUGFUNC("e1000_set_d0_lplu_state"); 7346 DEBUGFUNC("e1000_set_d0_lplu_state");
@@ -6645,15 +7348,24 @@ e1000_set_d0_lplu_state(struct e1000_hw *hw,
6645 if(hw->mac_type <= e1000_82547_rev_2) 7348 if(hw->mac_type <= e1000_82547_rev_2)
6646 return E1000_SUCCESS; 7349 return E1000_SUCCESS;
6647 7350
7351 if (hw->mac_type == e1000_ich8lan) {
7352 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7353 } else {
6648 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); 7354 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6649 if(ret_val) 7355 if(ret_val)
6650 return ret_val; 7356 return ret_val;
7357 }
6651 7358
6652 if (!active) { 7359 if (!active) {
7360 if (hw->mac_type == e1000_ich8lan) {
7361 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7362 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7363 } else {
6653 phy_data &= ~IGP02E1000_PM_D0_LPLU; 7364 phy_data &= ~IGP02E1000_PM_D0_LPLU;
6654 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); 7365 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6655 if (ret_val) 7366 if (ret_val)
6656 return ret_val; 7367 return ret_val;
7368 }
6657 7369
6658 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during 7370 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6659 * Dx states where the power conservation is most important. During 7371 * Dx states where the power conservation is most important. During
@@ -6686,10 +7398,15 @@ e1000_set_d0_lplu_state(struct e1000_hw *hw,
6686 7398
6687 } else { 7399 } else {
6688 7400
7401 if (hw->mac_type == e1000_ich8lan) {
7402 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7403 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7404 } else {
6689 phy_data |= IGP02E1000_PM_D0_LPLU; 7405 phy_data |= IGP02E1000_PM_D0_LPLU;
6690 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); 7406 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6691 if (ret_val) 7407 if (ret_val)
6692 return ret_val; 7408 return ret_val;
7409 }
6693 7410
6694 /* When LPLU is enabled we should disable SmartSpeed */ 7411 /* When LPLU is enabled we should disable SmartSpeed */
6695 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data); 7412 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
@@ -6928,8 +7645,10 @@ e1000_mng_write_cmd_header(struct e1000_hw * hw,
6928 7645
6929 length >>= 2; 7646 length >>= 2;
6930 /* The device driver writes the relevant command block into the ram area. */ 7647 /* The device driver writes the relevant command block into the ram area. */
6931 for (i = 0; i < length; i++) 7648 for (i = 0; i < length; i++) {
6932 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i)); 7649 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
7650 E1000_WRITE_FLUSH(hw);
7651 }
6933 7652
6934 return E1000_SUCCESS; 7653 return E1000_SUCCESS;
6935} 7654}
@@ -6961,15 +7680,18 @@ e1000_mng_write_commit(
6961 * returns - TRUE when the mode is IAMT or FALSE. 7680 * returns - TRUE when the mode is IAMT or FALSE.
6962 ****************************************************************************/ 7681 ****************************************************************************/
6963boolean_t 7682boolean_t
6964e1000_check_mng_mode( 7683e1000_check_mng_mode(struct e1000_hw *hw)
6965 struct e1000_hw *hw)
6966{ 7684{
6967 uint32_t fwsm; 7685 uint32_t fwsm;
6968 7686
6969 fwsm = E1000_READ_REG(hw, FWSM); 7687 fwsm = E1000_READ_REG(hw, FWSM);
6970 7688
6971 if((fwsm & E1000_FWSM_MODE_MASK) == 7689 if (hw->mac_type == e1000_ich8lan) {
6972 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT)) 7690 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7691 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7692 return TRUE;
7693 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7694 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
6973 return TRUE; 7695 return TRUE;
6974 7696
6975 return FALSE; 7697 return FALSE;
@@ -7209,7 +7931,6 @@ e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7209 E1000_WRITE_REG(hw, CTRL, ctrl); 7931 E1000_WRITE_REG(hw, CTRL, ctrl);
7210} 7932}
7211 7933
7212#if 0
7213/*************************************************************************** 7934/***************************************************************************
7214 * 7935 *
7215 * Enables PCI-Express master access. 7936 * Enables PCI-Express master access.
@@ -7219,6 +7940,7 @@ e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7219 * returns: - none. 7940 * returns: - none.
7220 * 7941 *
7221 ***************************************************************************/ 7942 ***************************************************************************/
7943#if 0
7222void 7944void
7223e1000_enable_pciex_master(struct e1000_hw *hw) 7945e1000_enable_pciex_master(struct e1000_hw *hw)
7224{ 7946{
@@ -7299,8 +8021,10 @@ e1000_get_auto_rd_done(struct e1000_hw *hw)
7299 case e1000_82572: 8021 case e1000_82572:
7300 case e1000_82573: 8022 case e1000_82573:
7301 case e1000_80003es2lan: 8023 case e1000_80003es2lan:
7302 while(timeout) { 8024 case e1000_ich8lan:
7303 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break; 8025 while (timeout) {
8026 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8027 break;
7304 else msec_delay(1); 8028 else msec_delay(1);
7305 timeout--; 8029 timeout--;
7306 } 8030 }
@@ -7340,7 +8064,7 @@ e1000_get_phy_cfg_done(struct e1000_hw *hw)
7340 8064
7341 switch (hw->mac_type) { 8065 switch (hw->mac_type) {
7342 default: 8066 default:
7343 msec_delay(10); 8067 msec_delay_irq(10);
7344 break; 8068 break;
7345 case e1000_80003es2lan: 8069 case e1000_80003es2lan:
7346 /* Separate *_CFG_DONE_* bit for each port */ 8070 /* Separate *_CFG_DONE_* bit for each port */
@@ -7457,7 +8181,7 @@ e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
7457 * E1000_SUCCESS at any other case. 8181 * E1000_SUCCESS at any other case.
7458 * 8182 *
7459 ***************************************************************************/ 8183 ***************************************************************************/
7460int32_t 8184static int32_t
7461e1000_get_software_semaphore(struct e1000_hw *hw) 8185e1000_get_software_semaphore(struct e1000_hw *hw)
7462{ 8186{
7463 int32_t timeout = hw->eeprom.word_size + 1; 8187 int32_t timeout = hw->eeprom.word_size + 1;
@@ -7492,7 +8216,7 @@ e1000_get_software_semaphore(struct e1000_hw *hw)
7492 * hw: Struct containing variables accessed by shared code 8216 * hw: Struct containing variables accessed by shared code
7493 * 8217 *
7494 ***************************************************************************/ 8218 ***************************************************************************/
7495void 8219static void
7496e1000_release_software_semaphore(struct e1000_hw *hw) 8220e1000_release_software_semaphore(struct e1000_hw *hw)
7497{ 8221{
7498 uint32_t swsm; 8222 uint32_t swsm;
@@ -7523,6 +8247,13 @@ int32_t
7523e1000_check_phy_reset_block(struct e1000_hw *hw) 8247e1000_check_phy_reset_block(struct e1000_hw *hw)
7524{ 8248{
7525 uint32_t manc = 0; 8249 uint32_t manc = 0;
8250 uint32_t fwsm = 0;
8251
8252 if (hw->mac_type == e1000_ich8lan) {
8253 fwsm = E1000_READ_REG(hw, FWSM);
8254 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8255 : E1000_BLK_PHY_RESET;
8256 }
7526 8257
7527 if (hw->mac_type > e1000_82547_rev_2) 8258 if (hw->mac_type > e1000_82547_rev_2)
7528 manc = E1000_READ_REG(hw, MANC); 8259 manc = E1000_READ_REG(hw, MANC);
@@ -7549,6 +8280,8 @@ e1000_arc_subsystem_valid(struct e1000_hw *hw)
7549 if((fwsm & E1000_FWSM_MODE_MASK) != 0) 8280 if((fwsm & E1000_FWSM_MODE_MASK) != 0)
7550 return TRUE; 8281 return TRUE;
7551 break; 8282 break;
8283 case e1000_ich8lan:
8284 return TRUE;
7552 default: 8285 default:
7553 break; 8286 break;
7554 } 8287 }
@@ -7556,4 +8289,854 @@ e1000_arc_subsystem_valid(struct e1000_hw *hw)
7556} 8289}
7557 8290
7558 8291
8292/******************************************************************************
8293 * Configure PCI-Ex no-snoop
8294 *
8295 * hw - Struct containing variables accessed by shared code.
8296 * no_snoop - Bitmap of no-snoop events.
8297 *
8298 * returns: E1000_SUCCESS
8299 *
8300 *****************************************************************************/
8301static int32_t
8302e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8303{
8304 uint32_t gcr_reg = 0;
8305
8306 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8307
8308 if (hw->bus_type == e1000_bus_type_unknown)
8309 e1000_get_bus_info(hw);
8310
8311 if (hw->bus_type != e1000_bus_type_pci_express)
8312 return E1000_SUCCESS;
8313
8314 if (no_snoop) {
8315 gcr_reg = E1000_READ_REG(hw, GCR);
8316 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8317 gcr_reg |= no_snoop;
8318 E1000_WRITE_REG(hw, GCR, gcr_reg);
8319 }
8320 if (hw->mac_type == e1000_ich8lan) {
8321 uint32_t ctrl_ext;
8322
8323 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8324
8325 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8326 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8327 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8328 }
8329
8330 return E1000_SUCCESS;
8331}
8332
8333/***************************************************************************
8334 *
8335 * Get software semaphore FLAG bit (SWFLAG).
8336 * SWFLAG is used to synchronize the access to all shared resource between
8337 * SW, FW and HW.
8338 *
8339 * hw: Struct containing variables accessed by shared code
8340 *
8341 ***************************************************************************/
8342static int32_t
8343e1000_get_software_flag(struct e1000_hw *hw)
8344{
8345 int32_t timeout = PHY_CFG_TIMEOUT;
8346 uint32_t extcnf_ctrl;
8347
8348 DEBUGFUNC("e1000_get_software_flag");
8349
8350 if (hw->mac_type == e1000_ich8lan) {
8351 while (timeout) {
8352 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8353 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8354 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8355
8356 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8357 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8358 break;
8359 msec_delay_irq(1);
8360 timeout--;
8361 }
8362
8363 if (!timeout) {
8364 DEBUGOUT("FW or HW locks the resource too long.\n");
8365 return -E1000_ERR_CONFIG;
8366 }
8367 }
8368
8369 return E1000_SUCCESS;
8370}
8371
8372/***************************************************************************
8373 *
8374 * Release software semaphore FLAG bit (SWFLAG).
8375 * SWFLAG is used to synchronize the access to all shared resource between
8376 * SW, FW and HW.
8377 *
8378 * hw: Struct containing variables accessed by shared code
8379 *
8380 ***************************************************************************/
8381static void
8382e1000_release_software_flag(struct e1000_hw *hw)
8383{
8384 uint32_t extcnf_ctrl;
8385
8386 DEBUGFUNC("e1000_release_software_flag");
8387
8388 if (hw->mac_type == e1000_ich8lan) {
8389 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8390 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8391 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8392 }
8393
8394 return;
8395}
8396
8397/***************************************************************************
8398 *
8399 * Disable dynamic power down mode in ife PHY.
8400 * It can be used to workaround band-gap problem.
8401 *
8402 * hw: Struct containing variables accessed by shared code
8403 *
8404 ***************************************************************************/
8405#if 0
8406int32_t
8407e1000_ife_disable_dynamic_power_down(struct e1000_hw *hw)
8408{
8409 uint16_t phy_data;
8410 int32_t ret_val = E1000_SUCCESS;
8411
8412 DEBUGFUNC("e1000_ife_disable_dynamic_power_down");
8413
8414 if (hw->phy_type == e1000_phy_ife) {
8415 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
8416 if (ret_val)
8417 return ret_val;
8418
8419 phy_data |= IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN;
8420 ret_val = e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, phy_data);
8421 }
8422
8423 return ret_val;
8424}
8425#endif /* 0 */
8426
8427/***************************************************************************
8428 *
8429 * Enable dynamic power down mode in ife PHY.
8430 * It can be used to workaround band-gap problem.
8431 *
8432 * hw: Struct containing variables accessed by shared code
8433 *
8434 ***************************************************************************/
8435#if 0
8436int32_t
8437e1000_ife_enable_dynamic_power_down(struct e1000_hw *hw)
8438{
8439 uint16_t phy_data;
8440 int32_t ret_val = E1000_SUCCESS;
8441
8442 DEBUGFUNC("e1000_ife_enable_dynamic_power_down");
8443
8444 if (hw->phy_type == e1000_phy_ife) {
8445 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
8446 if (ret_val)
8447 return ret_val;
8448
8449 phy_data &= ~IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN;
8450 ret_val = e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, phy_data);
8451 }
8452
8453 return ret_val;
8454}
8455#endif /* 0 */
8456
8457/******************************************************************************
8458 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8459 * register.
8460 *
8461 * hw - Struct containing variables accessed by shared code
8462 * offset - offset of word in the EEPROM to read
8463 * data - word read from the EEPROM
8464 * words - number of words to read
8465 *****************************************************************************/
8466static int32_t
8467e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8468 uint16_t *data)
8469{
8470 int32_t error = E1000_SUCCESS;
8471 uint32_t flash_bank = 0;
8472 uint32_t act_offset = 0;
8473 uint32_t bank_offset = 0;
8474 uint16_t word = 0;
8475 uint16_t i = 0;
8476
8477 /* We need to know which is the valid flash bank. In the event
8478 * that we didn't allocate eeprom_shadow_ram, we may not be
8479 * managing flash_bank. So it cannot be trusted and needs
8480 * to be updated with each read.
8481 */
8482 /* Value of bit 22 corresponds to the flash bank we're on. */
8483 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8484
8485 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8486 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8487
8488 error = e1000_get_software_flag(hw);
8489 if (error != E1000_SUCCESS)
8490 return error;
8491
8492 for (i = 0; i < words; i++) {
8493 if (hw->eeprom_shadow_ram != NULL &&
8494 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8495 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8496 } else {
8497 /* The NVM part needs a byte offset, hence * 2 */
8498 act_offset = bank_offset + ((offset + i) * 2);
8499 error = e1000_read_ich8_word(hw, act_offset, &word);
8500 if (error != E1000_SUCCESS)
8501 break;
8502 data[i] = word;
8503 }
8504 }
8505
8506 e1000_release_software_flag(hw);
8507
8508 return error;
8509}
8510
8511/******************************************************************************
8512 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8513 * register. Actually, writes are written to the shadow ram cache in the hw
8514 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8515 * the NVM, which occurs when the NVM checksum is updated.
8516 *
8517 * hw - Struct containing variables accessed by shared code
8518 * offset - offset of word in the EEPROM to write
8519 * words - number of words to write
8520 * data - words to write to the EEPROM
8521 *****************************************************************************/
8522static int32_t
8523e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8524 uint16_t *data)
8525{
8526 uint32_t i = 0;
8527 int32_t error = E1000_SUCCESS;
8528
8529 error = e1000_get_software_flag(hw);
8530 if (error != E1000_SUCCESS)
8531 return error;
8532
8533 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8534 * allocated. Subsequent reads to the modified words are read from
8535 * this cached structure as well. Writes will only go into this
8536 * cached structure unless it's followed by a call to
8537 * e1000_update_eeprom_checksum() where it will commit the changes
8538 * and clear the "modified" field.
8539 */
8540 if (hw->eeprom_shadow_ram != NULL) {
8541 for (i = 0; i < words; i++) {
8542 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8543 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8544 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8545 } else {
8546 error = -E1000_ERR_EEPROM;
8547 break;
8548 }
8549 }
8550 } else {
8551 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8552 * as they don't perform any NVM writes. An attempt in doing so
8553 * will result in this error.
8554 */
8555 error = -E1000_ERR_EEPROM;
8556 }
8557
8558 e1000_release_software_flag(hw);
8559
8560 return error;
8561}
8562
8563/******************************************************************************
8564 * This function does initial flash setup so that a new read/write/erase cycle
8565 * can be started.
8566 *
8567 * hw - The pointer to the hw structure
8568 ****************************************************************************/
8569static int32_t
8570e1000_ich8_cycle_init(struct e1000_hw *hw)
8571{
8572 union ich8_hws_flash_status hsfsts;
8573 int32_t error = E1000_ERR_EEPROM;
8574 int32_t i = 0;
8575
8576 DEBUGFUNC("e1000_ich8_cycle_init");
8577
8578 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8579
8580 /* May be check the Flash Des Valid bit in Hw status */
8581 if (hsfsts.hsf_status.fldesvalid == 0) {
8582 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8583 return error;
8584 }
8585
8586 /* Clear FCERR in Hw status by writing 1 */
8587 /* Clear DAEL in Hw status by writing a 1 */
8588 hsfsts.hsf_status.flcerr = 1;
8589 hsfsts.hsf_status.dael = 1;
8590
8591 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8592
8593 /* Either we should have a hardware SPI cycle in progress bit to check
8594 * against, in order to start a new cycle or FDONE bit should be changed
8595 * in the hardware so that it is 1 after harware reset, which can then be
8596 * used as an indication whether a cycle is in progress or has been
8597 * completed .. we should also have some software semaphore mechanism to
8598 * guard FDONE or the cycle in progress bit so that two threads access to
8599 * those bits can be sequentiallized or a way so that 2 threads dont
8600 * start the cycle at the same time */
8601
8602 if (hsfsts.hsf_status.flcinprog == 0) {
8603 /* There is no cycle running at present, so we can start a cycle */
8604 /* Begin by setting Flash Cycle Done. */
8605 hsfsts.hsf_status.flcdone = 1;
8606 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8607 error = E1000_SUCCESS;
8608 } else {
8609 /* otherwise poll for sometime so the current cycle has a chance
8610 * to end before giving up. */
8611 for (i = 0; i < ICH8_FLASH_COMMAND_TIMEOUT; i++) {
8612 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8613 if (hsfsts.hsf_status.flcinprog == 0) {
8614 error = E1000_SUCCESS;
8615 break;
8616 }
8617 udelay(1);
8618 }
8619 if (error == E1000_SUCCESS) {
8620 /* Successful in waiting for previous cycle to timeout,
8621 * now set the Flash Cycle Done. */
8622 hsfsts.hsf_status.flcdone = 1;
8623 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFSTS, hsfsts.regval);
8624 } else {
8625 DEBUGOUT("Flash controller busy, cannot get access");
8626 }
8627 }
8628 return error;
8629}
8630
8631/******************************************************************************
8632 * This function starts a flash cycle and waits for its completion
8633 *
8634 * hw - The pointer to the hw structure
8635 ****************************************************************************/
8636static int32_t
8637e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8638{
8639 union ich8_hws_flash_ctrl hsflctl;
8640 union ich8_hws_flash_status hsfsts;
8641 int32_t error = E1000_ERR_EEPROM;
8642 uint32_t i = 0;
8643
8644 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
8645 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8646 hsflctl.hsf_ctrl.flcgo = 1;
8647 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8648
8649 /* wait till FDONE bit is set to 1 */
8650 do {
8651 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8652 if (hsfsts.hsf_status.flcdone == 1)
8653 break;
8654 udelay(1);
8655 i++;
8656 } while (i < timeout);
8657 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8658 error = E1000_SUCCESS;
8659 }
8660 return error;
8661}
8662
8663/******************************************************************************
8664 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8665 *
8666 * hw - The pointer to the hw structure
8667 * index - The index of the byte or word to read.
8668 * size - Size of data to read, 1=byte 2=word
8669 * data - Pointer to the word to store the value read.
8670 *****************************************************************************/
8671static int32_t
8672e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8673 uint32_t size, uint16_t* data)
8674{
8675 union ich8_hws_flash_status hsfsts;
8676 union ich8_hws_flash_ctrl hsflctl;
8677 uint32_t flash_linear_address;
8678 uint32_t flash_data = 0;
8679 int32_t error = -E1000_ERR_EEPROM;
8680 int32_t count = 0;
8681
8682 DEBUGFUNC("e1000_read_ich8_data");
8683
8684 if (size < 1 || size > 2 || data == 0x0 ||
8685 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8686 return error;
8687
8688 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8689 hw->flash_base_addr;
8690
8691 do {
8692 udelay(1);
8693 /* Steps */
8694 error = e1000_ich8_cycle_init(hw);
8695 if (error != E1000_SUCCESS)
8696 break;
8697
8698 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8699 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8700 hsflctl.hsf_ctrl.fldbcount = size - 1;
8701 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_READ;
8702 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8703
8704 /* Write the last 24 bits of index into Flash Linear address field in
8705 * Flash Address */
8706 /* TODO: TBD maybe check the index against the size of flash */
8707
8708 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8709
8710 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8711
8712 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8713 * sequence a few more times, else read in (shift in) the Flash Data0,
8714 * the order is least significant byte first msb to lsb */
8715 if (error == E1000_SUCCESS) {
8716 flash_data = E1000_READ_ICH8_REG(hw, ICH8_FLASH_FDATA0);
8717 if (size == 1) {
8718 *data = (uint8_t)(flash_data & 0x000000FF);
8719 } else if (size == 2) {
8720 *data = (uint16_t)(flash_data & 0x0000FFFF);
8721 }
8722 break;
8723 } else {
8724 /* If we've gotten here, then things are probably completely hosed,
8725 * but if the error condition is detected, it won't hurt to give
8726 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8727 */
8728 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8729 if (hsfsts.hsf_status.flcerr == 1) {
8730 /* Repeat for some time before giving up. */
8731 continue;
8732 } else if (hsfsts.hsf_status.flcdone == 0) {
8733 DEBUGOUT("Timeout error - flash cycle did not complete.");
8734 break;
8735 }
8736 }
8737 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8738
8739 return error;
8740}
8741
8742/******************************************************************************
8743 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8744 *
8745 * hw - The pointer to the hw structure
8746 * index - The index of the byte/word to read.
8747 * size - Size of data to read, 1=byte 2=word
8748 * data - The byte(s) to write to the NVM.
8749 *****************************************************************************/
8750static int32_t
8751e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8752 uint16_t data)
8753{
8754 union ich8_hws_flash_status hsfsts;
8755 union ich8_hws_flash_ctrl hsflctl;
8756 uint32_t flash_linear_address;
8757 uint32_t flash_data = 0;
8758 int32_t error = -E1000_ERR_EEPROM;
8759 int32_t count = 0;
8760
8761 DEBUGFUNC("e1000_write_ich8_data");
8762
8763 if (size < 1 || size > 2 || data > size * 0xff ||
8764 index > ICH8_FLASH_LINEAR_ADDR_MASK)
8765 return error;
8766
8767 flash_linear_address = (ICH8_FLASH_LINEAR_ADDR_MASK & index) +
8768 hw->flash_base_addr;
8769
8770 do {
8771 udelay(1);
8772 /* Steps */
8773 error = e1000_ich8_cycle_init(hw);
8774 if (error != E1000_SUCCESS)
8775 break;
8776
8777 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8778 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8779 hsflctl.hsf_ctrl.fldbcount = size -1;
8780 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_WRITE;
8781 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8782
8783 /* Write the last 24 bits of index into Flash Linear address field in
8784 * Flash Address */
8785 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8786
8787 if (size == 1)
8788 flash_data = (uint32_t)data & 0x00FF;
8789 else
8790 flash_data = (uint32_t)data;
8791
8792 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FDATA0, flash_data);
8793
8794 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8795 * sequence a few more times else done */
8796 error = e1000_ich8_flash_cycle(hw, ICH8_FLASH_COMMAND_TIMEOUT);
8797 if (error == E1000_SUCCESS) {
8798 break;
8799 } else {
8800 /* If we're here, then things are most likely completely hosed,
8801 * but if the error condition is detected, it won't hurt to give
8802 * it another try...ICH8_FLASH_CYCLE_REPEAT_COUNT times.
8803 */
8804 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8805 if (hsfsts.hsf_status.flcerr == 1) {
8806 /* Repeat for some time before giving up. */
8807 continue;
8808 } else if (hsfsts.hsf_status.flcdone == 0) {
8809 DEBUGOUT("Timeout error - flash cycle did not complete.");
8810 break;
8811 }
8812 }
8813 } while (count++ < ICH8_FLASH_CYCLE_REPEAT_COUNT);
8814
8815 return error;
8816}
8817
8818/******************************************************************************
8819 * Reads a single byte from the NVM using the ICH8 flash access registers.
8820 *
8821 * hw - pointer to e1000_hw structure
8822 * index - The index of the byte to read.
8823 * data - Pointer to a byte to store the value read.
8824 *****************************************************************************/
8825static int32_t
8826e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8827{
8828 int32_t status = E1000_SUCCESS;
8829 uint16_t word = 0;
8830
8831 status = e1000_read_ich8_data(hw, index, 1, &word);
8832 if (status == E1000_SUCCESS) {
8833 *data = (uint8_t)word;
8834 }
8835
8836 return status;
8837}
8838
8839/******************************************************************************
8840 * Writes a single byte to the NVM using the ICH8 flash access registers.
8841 * Performs verification by reading back the value and then going through
8842 * a retry algorithm before giving up.
8843 *
8844 * hw - pointer to e1000_hw structure
8845 * index - The index of the byte to write.
8846 * byte - The byte to write to the NVM.
8847 *****************************************************************************/
8848static int32_t
8849e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8850{
8851 int32_t error = E1000_SUCCESS;
8852 int32_t program_retries;
8853 uint8_t temp_byte;
8854
8855 e1000_write_ich8_byte(hw, index, byte);
8856 udelay(100);
8857
8858 for (program_retries = 0; program_retries < 100; program_retries++) {
8859 e1000_read_ich8_byte(hw, index, &temp_byte);
8860 if (temp_byte == byte)
8861 break;
8862 udelay(10);
8863 e1000_write_ich8_byte(hw, index, byte);
8864 udelay(100);
8865 }
8866 if (program_retries == 100)
8867 error = E1000_ERR_EEPROM;
8868
8869 return error;
8870}
8871
8872/******************************************************************************
8873 * Writes a single byte to the NVM using the ICH8 flash access registers.
8874 *
8875 * hw - pointer to e1000_hw structure
8876 * index - The index of the byte to read.
8877 * data - The byte to write to the NVM.
8878 *****************************************************************************/
8879static int32_t
8880e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8881{
8882 int32_t status = E1000_SUCCESS;
8883 uint16_t word = (uint16_t)data;
8884
8885 status = e1000_write_ich8_data(hw, index, 1, word);
8886
8887 return status;
8888}
8889
8890/******************************************************************************
8891 * Reads a word from the NVM using the ICH8 flash access registers.
8892 *
8893 * hw - pointer to e1000_hw structure
8894 * index - The starting byte index of the word to read.
8895 * data - Pointer to a word to store the value read.
8896 *****************************************************************************/
8897static int32_t
8898e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8899{
8900 int32_t status = E1000_SUCCESS;
8901 status = e1000_read_ich8_data(hw, index, 2, data);
8902 return status;
8903}
8904
8905/******************************************************************************
8906 * Writes a word to the NVM using the ICH8 flash access registers.
8907 *
8908 * hw - pointer to e1000_hw structure
8909 * index - The starting byte index of the word to read.
8910 * data - The word to write to the NVM.
8911 *****************************************************************************/
8912#if 0
8913int32_t
8914e1000_write_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t data)
8915{
8916 int32_t status = E1000_SUCCESS;
8917 status = e1000_write_ich8_data(hw, index, 2, data);
8918 return status;
8919}
8920#endif /* 0 */
8921
8922/******************************************************************************
8923 * Erases the bank specified. Each bank is a 4k block. Segments are 0 based.
8924 * segment N is 4096 * N + flash_reg_addr.
8925 *
8926 * hw - pointer to e1000_hw structure
8927 * segment - 0 for first segment, 1 for second segment, etc.
8928 *****************************************************************************/
8929static int32_t
8930e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t segment)
8931{
8932 union ich8_hws_flash_status hsfsts;
8933 union ich8_hws_flash_ctrl hsflctl;
8934 uint32_t flash_linear_address;
8935 int32_t count = 0;
8936 int32_t error = E1000_ERR_EEPROM;
8937 int32_t iteration, seg_size;
8938 int32_t sector_size;
8939 int32_t j = 0;
8940 int32_t error_flag = 0;
8941
8942 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
8943
8944 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8945 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8946 * consecutive sectors. The start index for the nth Hw sector can be
8947 * calculated as = segment * 4096 + n * 256
8948 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8949 * The start index for the nth Hw sector can be calculated
8950 * as = segment * 4096
8951 * 10: Error condition
8952 * 11: The Hw sector size is much bigger than the size asked to
8953 * erase...error condition */
8954 if (hsfsts.hsf_status.berasesz == 0x0) {
8955 /* Hw sector size 256 */
8956 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_256;
8957 iteration = ICH8_FLASH_SECTOR_SIZE / ICH8_FLASH_SEG_SIZE_256;
8958 } else if (hsfsts.hsf_status.berasesz == 0x1) {
8959 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_4K;
8960 iteration = 1;
8961 } else if (hsfsts.hsf_status.berasesz == 0x3) {
8962 sector_size = seg_size = ICH8_FLASH_SEG_SIZE_64K;
8963 iteration = 1;
8964 } else {
8965 return error;
8966 }
8967
8968 for (j = 0; j < iteration ; j++) {
8969 do {
8970 count++;
8971 /* Steps */
8972 error = e1000_ich8_cycle_init(hw);
8973 if (error != E1000_SUCCESS) {
8974 error_flag = 1;
8975 break;
8976 }
8977
8978 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8979 * Control */
8980 hsflctl.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFCTL);
8981 hsflctl.hsf_ctrl.flcycle = ICH8_CYCLE_ERASE;
8982 E1000_WRITE_ICH8_REG16(hw, ICH8_FLASH_HSFCTL, hsflctl.regval);
8983
8984 /* Write the last 24 bits of an index within the block into Flash
8985 * Linear address field in Flash Address. This probably needs to
8986 * be calculated here based off the on-chip segment size and the
8987 * software segment size assumed (4K) */
8988 /* TBD */
8989 flash_linear_address = segment * sector_size + j * seg_size;
8990 flash_linear_address &= ICH8_FLASH_LINEAR_ADDR_MASK;
8991 flash_linear_address += hw->flash_base_addr;
8992
8993 E1000_WRITE_ICH8_REG(hw, ICH8_FLASH_FADDR, flash_linear_address);
8994
8995 error = e1000_ich8_flash_cycle(hw, 1000000);
8996 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8997 * sequence a few more times else Done */
8998 if (error == E1000_SUCCESS) {
8999 break;
9000 } else {
9001 hsfsts.regval = E1000_READ_ICH8_REG16(hw, ICH8_FLASH_HSFSTS);
9002 if (hsfsts.hsf_status.flcerr == 1) {
9003 /* repeat for some time before giving up */
9004 continue;
9005 } else if (hsfsts.hsf_status.flcdone == 0) {
9006 error_flag = 1;
9007 break;
9008 }
9009 }
9010 } while ((count < ICH8_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
9011 if (error_flag == 1)
9012 break;
9013 }
9014 if (error_flag != 1)
9015 error = E1000_SUCCESS;
9016 return error;
9017}
9018
9019/******************************************************************************
9020 *
9021 * Reverse duplex setting without breaking the link.
9022 *
9023 * hw: Struct containing variables accessed by shared code
9024 *
9025 *****************************************************************************/
9026#if 0
9027int32_t
9028e1000_duplex_reversal(struct e1000_hw *hw)
9029{
9030 int32_t ret_val;
9031 uint16_t phy_data;
9032
9033 if (hw->phy_type != e1000_phy_igp_3)
9034 return E1000_SUCCESS;
9035
9036 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
9037 if (ret_val)
9038 return ret_val;
9039
9040 phy_data ^= MII_CR_FULL_DUPLEX;
9041
9042 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
9043 if (ret_val)
9044 return ret_val;
9045
9046 ret_val = e1000_read_phy_reg(hw, IGP3E1000_PHY_MISC_CTRL, &phy_data);
9047 if (ret_val)
9048 return ret_val;
9049
9050 phy_data |= IGP3_PHY_MISC_DUPLEX_MANUAL_SET;
9051 ret_val = e1000_write_phy_reg(hw, IGP3E1000_PHY_MISC_CTRL, phy_data);
9052
9053 return ret_val;
9054}
9055#endif /* 0 */
9056
9057static int32_t
9058e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
9059 uint32_t cnf_base_addr, uint32_t cnf_size)
9060{
9061 uint32_t ret_val = E1000_SUCCESS;
9062 uint16_t word_addr, reg_data, reg_addr;
9063 uint16_t i;
9064
9065 /* cnf_base_addr is in DWORD */
9066 word_addr = (uint16_t)(cnf_base_addr << 1);
9067
9068 /* cnf_size is returned in size of dwords */
9069 for (i = 0; i < cnf_size; i++) {
9070 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, &reg_data);
9071 if (ret_val)
9072 return ret_val;
9073
9074 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, &reg_addr);
9075 if (ret_val)
9076 return ret_val;
9077
9078 ret_val = e1000_get_software_flag(hw);
9079 if (ret_val != E1000_SUCCESS)
9080 return ret_val;
9081
9082 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
9083
9084 e1000_release_software_flag(hw);
9085 }
9086
9087 return ret_val;
9088}
9089
9090
9091static int32_t
9092e1000_init_lcd_from_nvm(struct e1000_hw *hw)
9093{
9094 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
9095
9096 if (hw->phy_type != e1000_phy_igp_3)
9097 return E1000_SUCCESS;
9098
9099 /* Check if SW needs configure the PHY */
9100 reg_data = E1000_READ_REG(hw, FEXTNVM);
9101 if (!(reg_data & FEXTNVM_SW_CONFIG))
9102 return E1000_SUCCESS;
9103
9104 /* Wait for basic configuration completes before proceeding*/
9105 loop = 0;
9106 do {
9107 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
9108 udelay(100);
9109 loop++;
9110 } while ((!reg_data) && (loop < 50));
9111
9112 /* Clear the Init Done bit for the next init event */
9113 reg_data = E1000_READ_REG(hw, STATUS);
9114 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
9115 E1000_WRITE_REG(hw, STATUS, reg_data);
9116
9117 /* Make sure HW does not configure LCD from PHY extended configuration
9118 before SW configuration */
9119 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9120 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9121 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9122 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9123 cnf_size >>= 16;
9124 if (cnf_size) {
9125 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9126 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9127 /* cnf_base_addr is in DWORD */
9128 cnf_base_addr >>= 16;
9129
9130 /* Configure LCD from extended configuration region. */
9131 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9132 cnf_size);
9133 if (ret_val)
9134 return ret_val;
9135 }
9136 }
9137
9138 return E1000_SUCCESS;
9139}
9140
9141
7559 9142
diff --git a/drivers/net/e1000/e1000_hw.h b/drivers/net/e1000/e1000_hw.h
index 467c9ed944f8..375b95518c31 100644
--- a/drivers/net/e1000/e1000_hw.h
+++ b/drivers/net/e1000/e1000_hw.h
@@ -62,6 +62,7 @@ typedef enum {
62 e1000_82572, 62 e1000_82572,
63 e1000_82573, 63 e1000_82573,
64 e1000_80003es2lan, 64 e1000_80003es2lan,
65 e1000_ich8lan,
65 e1000_num_macs 66 e1000_num_macs
66} e1000_mac_type; 67} e1000_mac_type;
67 68
@@ -70,6 +71,7 @@ typedef enum {
70 e1000_eeprom_spi, 71 e1000_eeprom_spi,
71 e1000_eeprom_microwire, 72 e1000_eeprom_microwire,
72 e1000_eeprom_flash, 73 e1000_eeprom_flash,
74 e1000_eeprom_ich8,
73 e1000_eeprom_none, /* No NVM support */ 75 e1000_eeprom_none, /* No NVM support */
74 e1000_num_eeprom_types 76 e1000_num_eeprom_types
75} e1000_eeprom_type; 77} e1000_eeprom_type;
@@ -98,6 +100,11 @@ typedef enum {
98 e1000_fc_default = 0xFF 100 e1000_fc_default = 0xFF
99} e1000_fc_type; 101} e1000_fc_type;
100 102
103struct e1000_shadow_ram {
104 uint16_t eeprom_word;
105 boolean_t modified;
106};
107
101/* PCI bus types */ 108/* PCI bus types */
102typedef enum { 109typedef enum {
103 e1000_bus_type_unknown = 0, 110 e1000_bus_type_unknown = 0,
@@ -218,6 +225,8 @@ typedef enum {
218 e1000_phy_igp, 225 e1000_phy_igp,
219 e1000_phy_igp_2, 226 e1000_phy_igp_2,
220 e1000_phy_gg82563, 227 e1000_phy_gg82563,
228 e1000_phy_igp_3,
229 e1000_phy_ife,
221 e1000_phy_undefined = 0xFF 230 e1000_phy_undefined = 0xFF
222} e1000_phy_type; 231} e1000_phy_type;
223 232
@@ -313,10 +322,9 @@ int32_t e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *phy
313int32_t e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data); 322int32_t e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
314int32_t e1000_phy_hw_reset(struct e1000_hw *hw); 323int32_t e1000_phy_hw_reset(struct e1000_hw *hw);
315int32_t e1000_phy_reset(struct e1000_hw *hw); 324int32_t e1000_phy_reset(struct e1000_hw *hw);
325void e1000_phy_powerdown_workaround(struct e1000_hw *hw);
316int32_t e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info); 326int32_t e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
317int32_t e1000_validate_mdi_setting(struct e1000_hw *hw); 327int32_t e1000_validate_mdi_setting(struct e1000_hw *hw);
318int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data);
319int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
320 328
321/* EEPROM Functions */ 329/* EEPROM Functions */
322int32_t e1000_init_eeprom_params(struct e1000_hw *hw); 330int32_t e1000_init_eeprom_params(struct e1000_hw *hw);
@@ -331,6 +339,7 @@ uint32_t e1000_enable_mng_pass_thru(struct e1000_hw *hw);
331#define E1000_MNG_DHCP_COOKIE_OFFSET 0x6F0 /* Cookie offset */ 339#define E1000_MNG_DHCP_COOKIE_OFFSET 0x6F0 /* Cookie offset */
332#define E1000_MNG_DHCP_COOKIE_LENGTH 0x10 /* Cookie length */ 340#define E1000_MNG_DHCP_COOKIE_LENGTH 0x10 /* Cookie length */
333#define E1000_MNG_IAMT_MODE 0x3 341#define E1000_MNG_IAMT_MODE 0x3
342#define E1000_MNG_ICH_IAMT_MODE 0x2
334#define E1000_IAMT_SIGNATURE 0x544D4149 /* Intel(R) Active Management Technology signature */ 343#define E1000_IAMT_SIGNATURE 0x544D4149 /* Intel(R) Active Management Technology signature */
335 344
336#define E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT 0x1 /* DHCP parsing enabled */ 345#define E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT 0x1 /* DHCP parsing enabled */
@@ -386,11 +395,8 @@ int32_t e1000_update_eeprom_checksum(struct e1000_hw *hw);
386int32_t e1000_write_eeprom(struct e1000_hw *hw, uint16_t reg, uint16_t words, uint16_t *data); 395int32_t e1000_write_eeprom(struct e1000_hw *hw, uint16_t reg, uint16_t words, uint16_t *data);
387int32_t e1000_read_part_num(struct e1000_hw *hw, uint32_t * part_num); 396int32_t e1000_read_part_num(struct e1000_hw *hw, uint32_t * part_num);
388int32_t e1000_read_mac_addr(struct e1000_hw * hw); 397int32_t e1000_read_mac_addr(struct e1000_hw * hw);
389int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
390void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
391 398
392/* Filters (multicast, vlan, receive) */ 399/* Filters (multicast, vlan, receive) */
393void e1000_mc_addr_list_update(struct e1000_hw *hw, uint8_t * mc_addr_list, uint32_t mc_addr_count, uint32_t pad, uint32_t rar_used_count);
394uint32_t e1000_hash_mc_addr(struct e1000_hw *hw, uint8_t * mc_addr); 400uint32_t e1000_hash_mc_addr(struct e1000_hw *hw, uint8_t * mc_addr);
395void e1000_mta_set(struct e1000_hw *hw, uint32_t hash_value); 401void e1000_mta_set(struct e1000_hw *hw, uint32_t hash_value);
396void e1000_rar_set(struct e1000_hw *hw, uint8_t * mc_addr, uint32_t rar_index); 402void e1000_rar_set(struct e1000_hw *hw, uint8_t * mc_addr, uint32_t rar_index);
@@ -401,6 +407,7 @@ int32_t e1000_setup_led(struct e1000_hw *hw);
401int32_t e1000_cleanup_led(struct e1000_hw *hw); 407int32_t e1000_cleanup_led(struct e1000_hw *hw);
402int32_t e1000_led_on(struct e1000_hw *hw); 408int32_t e1000_led_on(struct e1000_hw *hw);
403int32_t e1000_led_off(struct e1000_hw *hw); 409int32_t e1000_led_off(struct e1000_hw *hw);
410int32_t e1000_blink_led_start(struct e1000_hw *hw);
404 411
405/* Adaptive IFS Functions */ 412/* Adaptive IFS Functions */
406 413
@@ -414,15 +421,16 @@ void e1000_pci_clear_mwi(struct e1000_hw *hw);
414void e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t * value); 421void e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t * value);
415void e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t * value); 422void e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t * value);
416/* Port I/O is only supported on 82544 and newer */ 423/* Port I/O is only supported on 82544 and newer */
417uint32_t e1000_io_read(struct e1000_hw *hw, unsigned long port);
418uint32_t e1000_read_reg_io(struct e1000_hw *hw, uint32_t offset);
419void e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value); 424void e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value);
420void e1000_enable_pciex_master(struct e1000_hw *hw);
421int32_t e1000_disable_pciex_master(struct e1000_hw *hw); 425int32_t e1000_disable_pciex_master(struct e1000_hw *hw);
422int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
423void e1000_release_software_semaphore(struct e1000_hw *hw);
424int32_t e1000_check_phy_reset_block(struct e1000_hw *hw); 426int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
425 427
428
429#define E1000_READ_REG_IO(a, reg) \
430 e1000_read_reg_io((a), E1000_##reg)
431#define E1000_WRITE_REG_IO(a, reg, val) \
432 e1000_write_reg_io((a), E1000_##reg, val)
433
426/* PCI Device IDs */ 434/* PCI Device IDs */
427#define E1000_DEV_ID_82542 0x1000 435#define E1000_DEV_ID_82542 0x1000
428#define E1000_DEV_ID_82543GC_FIBER 0x1001 436#define E1000_DEV_ID_82543GC_FIBER 0x1001
@@ -446,6 +454,7 @@ int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
446#define E1000_DEV_ID_82546EB_QUAD_COPPER 0x101D 454#define E1000_DEV_ID_82546EB_QUAD_COPPER 0x101D
447#define E1000_DEV_ID_82541EI 0x1013 455#define E1000_DEV_ID_82541EI 0x1013
448#define E1000_DEV_ID_82541EI_MOBILE 0x1018 456#define E1000_DEV_ID_82541EI_MOBILE 0x1018
457#define E1000_DEV_ID_82541ER_LOM 0x1014
449#define E1000_DEV_ID_82541ER 0x1078 458#define E1000_DEV_ID_82541ER 0x1078
450#define E1000_DEV_ID_82547GI 0x1075 459#define E1000_DEV_ID_82547GI 0x1075
451#define E1000_DEV_ID_82541GI 0x1076 460#define E1000_DEV_ID_82541GI 0x1076
@@ -457,18 +466,28 @@ int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
457#define E1000_DEV_ID_82546GB_PCIE 0x108A 466#define E1000_DEV_ID_82546GB_PCIE 0x108A
458#define E1000_DEV_ID_82546GB_QUAD_COPPER 0x1099 467#define E1000_DEV_ID_82546GB_QUAD_COPPER 0x1099
459#define E1000_DEV_ID_82547EI 0x1019 468#define E1000_DEV_ID_82547EI 0x1019
469#define E1000_DEV_ID_82547EI_MOBILE 0x101A
460#define E1000_DEV_ID_82571EB_COPPER 0x105E 470#define E1000_DEV_ID_82571EB_COPPER 0x105E
461#define E1000_DEV_ID_82571EB_FIBER 0x105F 471#define E1000_DEV_ID_82571EB_FIBER 0x105F
462#define E1000_DEV_ID_82571EB_SERDES 0x1060 472#define E1000_DEV_ID_82571EB_SERDES 0x1060
463#define E1000_DEV_ID_82572EI_COPPER 0x107D 473#define E1000_DEV_ID_82572EI_COPPER 0x107D
464#define E1000_DEV_ID_82572EI_FIBER 0x107E 474#define E1000_DEV_ID_82572EI_FIBER 0x107E
465#define E1000_DEV_ID_82572EI_SERDES 0x107F 475#define E1000_DEV_ID_82572EI_SERDES 0x107F
476#define E1000_DEV_ID_82572EI 0x10B9
466#define E1000_DEV_ID_82573E 0x108B 477#define E1000_DEV_ID_82573E 0x108B
467#define E1000_DEV_ID_82573E_IAMT 0x108C 478#define E1000_DEV_ID_82573E_IAMT 0x108C
468#define E1000_DEV_ID_82573L 0x109A 479#define E1000_DEV_ID_82573L 0x109A
469#define E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 0x10B5 480#define E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 0x10B5
470#define E1000_DEV_ID_80003ES2LAN_COPPER_DPT 0x1096 481#define E1000_DEV_ID_80003ES2LAN_COPPER_DPT 0x1096
471#define E1000_DEV_ID_80003ES2LAN_SERDES_DPT 0x1098 482#define E1000_DEV_ID_80003ES2LAN_SERDES_DPT 0x1098
483#define E1000_DEV_ID_80003ES2LAN_COPPER_SPT 0x10BA
484#define E1000_DEV_ID_80003ES2LAN_SERDES_SPT 0x10BB
485
486#define E1000_DEV_ID_ICH8_IGP_M_AMT 0x1049
487#define E1000_DEV_ID_ICH8_IGP_AMT 0x104A
488#define E1000_DEV_ID_ICH8_IGP_C 0x104B
489#define E1000_DEV_ID_ICH8_IFE 0x104C
490#define E1000_DEV_ID_ICH8_IGP_M 0x104D
472 491
473 492
474#define NODE_ADDRESS_SIZE 6 493#define NODE_ADDRESS_SIZE 6
@@ -539,6 +558,14 @@ int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
539 E1000_IMS_RXSEQ | \ 558 E1000_IMS_RXSEQ | \
540 E1000_IMS_LSC) 559 E1000_IMS_LSC)
541 560
561/* Additional interrupts need to be handled for e1000_ich8lan:
562 DSW = The FW changed the status of the DISSW bit in FWSM
563 PHYINT = The LAN connected device generates an interrupt
564 EPRST = Manageability reset event */
565#define IMS_ICH8LAN_ENABLE_MASK (\
566 E1000_IMS_DSW | \
567 E1000_IMS_PHYINT | \
568 E1000_IMS_EPRST)
542 569
543/* Number of high/low register pairs in the RAR. The RAR (Receive Address 570/* Number of high/low register pairs in the RAR. The RAR (Receive Address
544 * Registers) holds the directed and multicast addresses that we monitor. We 571 * Registers) holds the directed and multicast addresses that we monitor. We
@@ -546,6 +573,7 @@ int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
546 * E1000_RAR_ENTRIES - 1 multicast addresses. 573 * E1000_RAR_ENTRIES - 1 multicast addresses.
547 */ 574 */
548#define E1000_RAR_ENTRIES 15 575#define E1000_RAR_ENTRIES 15
576#define E1000_RAR_ENTRIES_ICH8LAN 7
549 577
550#define MIN_NUMBER_OF_DESCRIPTORS 8 578#define MIN_NUMBER_OF_DESCRIPTORS 8
551#define MAX_NUMBER_OF_DESCRIPTORS 0xFFF8 579#define MAX_NUMBER_OF_DESCRIPTORS 0xFFF8
@@ -767,6 +795,9 @@ struct e1000_data_desc {
767#define E1000_MC_TBL_SIZE 128 /* Multicast Filter Table (4096 bits) */ 795#define E1000_MC_TBL_SIZE 128 /* Multicast Filter Table (4096 bits) */
768#define E1000_VLAN_FILTER_TBL_SIZE 128 /* VLAN Filter Table (4096 bits) */ 796#define E1000_VLAN_FILTER_TBL_SIZE 128 /* VLAN Filter Table (4096 bits) */
769 797
798#define E1000_NUM_UNICAST_ICH8LAN 7
799#define E1000_MC_TBL_SIZE_ICH8LAN 32
800
770 801
771/* Receive Address Register */ 802/* Receive Address Register */
772struct e1000_rar { 803struct e1000_rar {
@@ -776,6 +807,7 @@ struct e1000_rar {
776 807
777/* Number of entries in the Multicast Table Array (MTA). */ 808/* Number of entries in the Multicast Table Array (MTA). */
778#define E1000_NUM_MTA_REGISTERS 128 809#define E1000_NUM_MTA_REGISTERS 128
810#define E1000_NUM_MTA_REGISTERS_ICH8LAN 32
779 811
780/* IPv4 Address Table Entry */ 812/* IPv4 Address Table Entry */
781struct e1000_ipv4_at_entry { 813struct e1000_ipv4_at_entry {
@@ -786,6 +818,7 @@ struct e1000_ipv4_at_entry {
786/* Four wakeup IP addresses are supported */ 818/* Four wakeup IP addresses are supported */
787#define E1000_WAKEUP_IP_ADDRESS_COUNT_MAX 4 819#define E1000_WAKEUP_IP_ADDRESS_COUNT_MAX 4
788#define E1000_IP4AT_SIZE E1000_WAKEUP_IP_ADDRESS_COUNT_MAX 820#define E1000_IP4AT_SIZE E1000_WAKEUP_IP_ADDRESS_COUNT_MAX
821#define E1000_IP4AT_SIZE_ICH8LAN 3
789#define E1000_IP6AT_SIZE 1 822#define E1000_IP6AT_SIZE 1
790 823
791/* IPv6 Address Table Entry */ 824/* IPv6 Address Table Entry */
@@ -844,6 +877,7 @@ struct e1000_ffvt_entry {
844#define E1000_FLA 0x0001C /* Flash Access - RW */ 877#define E1000_FLA 0x0001C /* Flash Access - RW */
845#define E1000_MDIC 0x00020 /* MDI Control - RW */ 878#define E1000_MDIC 0x00020 /* MDI Control - RW */
846#define E1000_SCTL 0x00024 /* SerDes Control - RW */ 879#define E1000_SCTL 0x00024 /* SerDes Control - RW */
880#define E1000_FEXTNVM 0x00028 /* Future Extended NVM register */
847#define E1000_FCAL 0x00028 /* Flow Control Address Low - RW */ 881#define E1000_FCAL 0x00028 /* Flow Control Address Low - RW */
848#define E1000_FCAH 0x0002C /* Flow Control Address High -RW */ 882#define E1000_FCAH 0x0002C /* Flow Control Address High -RW */
849#define E1000_FCT 0x00030 /* Flow Control Type - RW */ 883#define E1000_FCT 0x00030 /* Flow Control Type - RW */
@@ -872,6 +906,8 @@ struct e1000_ffvt_entry {
872#define E1000_LEDCTL 0x00E00 /* LED Control - RW */ 906#define E1000_LEDCTL 0x00E00 /* LED Control - RW */
873#define E1000_EXTCNF_CTRL 0x00F00 /* Extended Configuration Control */ 907#define E1000_EXTCNF_CTRL 0x00F00 /* Extended Configuration Control */
874#define E1000_EXTCNF_SIZE 0x00F08 /* Extended Configuration Size */ 908#define E1000_EXTCNF_SIZE 0x00F08 /* Extended Configuration Size */
909#define E1000_PHY_CTRL 0x00F10 /* PHY Control Register in CSR */
910#define FEXTNVM_SW_CONFIG 0x0001
875#define E1000_PBA 0x01000 /* Packet Buffer Allocation - RW */ 911#define E1000_PBA 0x01000 /* Packet Buffer Allocation - RW */
876#define E1000_PBS 0x01008 /* Packet Buffer Size */ 912#define E1000_PBS 0x01008 /* Packet Buffer Size */
877#define E1000_EEMNGCTL 0x01010 /* MNG EEprom Control */ 913#define E1000_EEMNGCTL 0x01010 /* MNG EEprom Control */
@@ -899,11 +935,13 @@ struct e1000_ffvt_entry {
899#define E1000_RDH0 E1000_RDH /* RX Desc Head (0) - RW */ 935#define E1000_RDH0 E1000_RDH /* RX Desc Head (0) - RW */
900#define E1000_RDT0 E1000_RDT /* RX Desc Tail (0) - RW */ 936#define E1000_RDT0 E1000_RDT /* RX Desc Tail (0) - RW */
901#define E1000_RDTR0 E1000_RDTR /* RX Delay Timer (0) - RW */ 937#define E1000_RDTR0 E1000_RDTR /* RX Delay Timer (0) - RW */
902#define E1000_RXDCTL 0x02828 /* RX Descriptor Control - RW */ 938#define E1000_RXDCTL 0x02828 /* RX Descriptor Control queue 0 - RW */
939#define E1000_RXDCTL1 0x02928 /* RX Descriptor Control queue 1 - RW */
903#define E1000_RADV 0x0282C /* RX Interrupt Absolute Delay Timer - RW */ 940#define E1000_RADV 0x0282C /* RX Interrupt Absolute Delay Timer - RW */
904#define E1000_RSRPD 0x02C00 /* RX Small Packet Detect - RW */ 941#define E1000_RSRPD 0x02C00 /* RX Small Packet Detect - RW */
905#define E1000_RAID 0x02C08 /* Receive Ack Interrupt Delay - RW */ 942#define E1000_RAID 0x02C08 /* Receive Ack Interrupt Delay - RW */
906#define E1000_TXDMAC 0x03000 /* TX DMA Control - RW */ 943#define E1000_TXDMAC 0x03000 /* TX DMA Control - RW */
944#define E1000_KABGTXD 0x03004 /* AFE Band Gap Transmit Ref Data */
907#define E1000_TDFH 0x03410 /* TX Data FIFO Head - RW */ 945#define E1000_TDFH 0x03410 /* TX Data FIFO Head - RW */
908#define E1000_TDFT 0x03418 /* TX Data FIFO Tail - RW */ 946#define E1000_TDFT 0x03418 /* TX Data FIFO Tail - RW */
909#define E1000_TDFHS 0x03420 /* TX Data FIFO Head Saved - RW */ 947#define E1000_TDFHS 0x03420 /* TX Data FIFO Head Saved - RW */
@@ -1050,6 +1088,7 @@ struct e1000_ffvt_entry {
1050#define E1000_82542_FLA E1000_FLA 1088#define E1000_82542_FLA E1000_FLA
1051#define E1000_82542_MDIC E1000_MDIC 1089#define E1000_82542_MDIC E1000_MDIC
1052#define E1000_82542_SCTL E1000_SCTL 1090#define E1000_82542_SCTL E1000_SCTL
1091#define E1000_82542_FEXTNVM E1000_FEXTNVM
1053#define E1000_82542_FCAL E1000_FCAL 1092#define E1000_82542_FCAL E1000_FCAL
1054#define E1000_82542_FCAH E1000_FCAH 1093#define E1000_82542_FCAH E1000_FCAH
1055#define E1000_82542_FCT E1000_FCT 1094#define E1000_82542_FCT E1000_FCT
@@ -1073,6 +1112,19 @@ struct e1000_ffvt_entry {
1073#define E1000_82542_RDLEN0 E1000_82542_RDLEN 1112#define E1000_82542_RDLEN0 E1000_82542_RDLEN
1074#define E1000_82542_RDH0 E1000_82542_RDH 1113#define E1000_82542_RDH0 E1000_82542_RDH
1075#define E1000_82542_RDT0 E1000_82542_RDT 1114#define E1000_82542_RDT0 E1000_82542_RDT
1115#define E1000_82542_SRRCTL(_n) (0x280C + ((_n) << 8)) /* Split and Replication
1116 * RX Control - RW */
1117#define E1000_82542_DCA_RXCTRL(_n) (0x02814 + ((_n) << 8))
1118#define E1000_82542_RDBAH3 0x02B04 /* RX Desc Base High Queue 3 - RW */
1119#define E1000_82542_RDBAL3 0x02B00 /* RX Desc Low Queue 3 - RW */
1120#define E1000_82542_RDLEN3 0x02B08 /* RX Desc Length Queue 3 - RW */
1121#define E1000_82542_RDH3 0x02B10 /* RX Desc Head Queue 3 - RW */
1122#define E1000_82542_RDT3 0x02B18 /* RX Desc Tail Queue 3 - RW */
1123#define E1000_82542_RDBAL2 0x02A00 /* RX Desc Base Low Queue 2 - RW */
1124#define E1000_82542_RDBAH2 0x02A04 /* RX Desc Base High Queue 2 - RW */
1125#define E1000_82542_RDLEN2 0x02A08 /* RX Desc Length Queue 2 - RW */
1126#define E1000_82542_RDH2 0x02A10 /* RX Desc Head Queue 2 - RW */
1127#define E1000_82542_RDT2 0x02A18 /* RX Desc Tail Queue 2 - RW */
1076#define E1000_82542_RDTR1 0x00130 1128#define E1000_82542_RDTR1 0x00130
1077#define E1000_82542_RDBAL1 0x00138 1129#define E1000_82542_RDBAL1 0x00138
1078#define E1000_82542_RDBAH1 0x0013C 1130#define E1000_82542_RDBAH1 0x0013C
@@ -1110,11 +1162,14 @@ struct e1000_ffvt_entry {
1110#define E1000_82542_FLOP E1000_FLOP 1162#define E1000_82542_FLOP E1000_FLOP
1111#define E1000_82542_EXTCNF_CTRL E1000_EXTCNF_CTRL 1163#define E1000_82542_EXTCNF_CTRL E1000_EXTCNF_CTRL
1112#define E1000_82542_EXTCNF_SIZE E1000_EXTCNF_SIZE 1164#define E1000_82542_EXTCNF_SIZE E1000_EXTCNF_SIZE
1165#define E1000_82542_PHY_CTRL E1000_PHY_CTRL
1113#define E1000_82542_ERT E1000_ERT 1166#define E1000_82542_ERT E1000_ERT
1114#define E1000_82542_RXDCTL E1000_RXDCTL 1167#define E1000_82542_RXDCTL E1000_RXDCTL
1168#define E1000_82542_RXDCTL1 E1000_RXDCTL1
1115#define E1000_82542_RADV E1000_RADV 1169#define E1000_82542_RADV E1000_RADV
1116#define E1000_82542_RSRPD E1000_RSRPD 1170#define E1000_82542_RSRPD E1000_RSRPD
1117#define E1000_82542_TXDMAC E1000_TXDMAC 1171#define E1000_82542_TXDMAC E1000_TXDMAC
1172#define E1000_82542_KABGTXD E1000_KABGTXD
1118#define E1000_82542_TDFHS E1000_TDFHS 1173#define E1000_82542_TDFHS E1000_TDFHS
1119#define E1000_82542_TDFTS E1000_TDFTS 1174#define E1000_82542_TDFTS E1000_TDFTS
1120#define E1000_82542_TDFPC E1000_TDFPC 1175#define E1000_82542_TDFPC E1000_TDFPC
@@ -1310,13 +1365,16 @@ struct e1000_hw_stats {
1310 1365
1311/* Structure containing variables used by the shared code (e1000_hw.c) */ 1366/* Structure containing variables used by the shared code (e1000_hw.c) */
1312struct e1000_hw { 1367struct e1000_hw {
1313 uint8_t __iomem *hw_addr; 1368 uint8_t *hw_addr;
1314 uint8_t *flash_address; 1369 uint8_t *flash_address;
1315 e1000_mac_type mac_type; 1370 e1000_mac_type mac_type;
1316 e1000_phy_type phy_type; 1371 e1000_phy_type phy_type;
1317 uint32_t phy_init_script; 1372 uint32_t phy_init_script;
1318 e1000_media_type media_type; 1373 e1000_media_type media_type;
1319 void *back; 1374 void *back;
1375 struct e1000_shadow_ram *eeprom_shadow_ram;
1376 uint32_t flash_bank_size;
1377 uint32_t flash_base_addr;
1320 e1000_fc_type fc; 1378 e1000_fc_type fc;
1321 e1000_bus_speed bus_speed; 1379 e1000_bus_speed bus_speed;
1322 e1000_bus_width bus_width; 1380 e1000_bus_width bus_width;
@@ -1328,6 +1386,7 @@ struct e1000_hw {
1328 uint32_t asf_firmware_present; 1386 uint32_t asf_firmware_present;
1329 uint32_t eeprom_semaphore_present; 1387 uint32_t eeprom_semaphore_present;
1330 uint32_t swfw_sync_present; 1388 uint32_t swfw_sync_present;
1389 uint32_t swfwhw_semaphore_present;
1331 unsigned long io_base; 1390 unsigned long io_base;
1332 uint32_t phy_id; 1391 uint32_t phy_id;
1333 uint32_t phy_revision; 1392 uint32_t phy_revision;
@@ -1387,6 +1446,7 @@ struct e1000_hw {
1387 boolean_t in_ifs_mode; 1446 boolean_t in_ifs_mode;
1388 boolean_t mng_reg_access_disabled; 1447 boolean_t mng_reg_access_disabled;
1389 boolean_t leave_av_bit_off; 1448 boolean_t leave_av_bit_off;
1449 boolean_t kmrn_lock_loss_workaround_disabled;
1390}; 1450};
1391 1451
1392 1452
@@ -1435,6 +1495,7 @@ struct e1000_hw {
1435#define E1000_CTRL_RTE 0x20000000 /* Routing tag enable */ 1495#define E1000_CTRL_RTE 0x20000000 /* Routing tag enable */
1436#define E1000_CTRL_VME 0x40000000 /* IEEE VLAN mode enable */ 1496#define E1000_CTRL_VME 0x40000000 /* IEEE VLAN mode enable */
1437#define E1000_CTRL_PHY_RST 0x80000000 /* PHY Reset */ 1497#define E1000_CTRL_PHY_RST 0x80000000 /* PHY Reset */
1498#define E1000_CTRL_SW2FW_INT 0x02000000 /* Initiate an interrupt to manageability engine */
1438 1499
1439/* Device Status */ 1500/* Device Status */
1440#define E1000_STATUS_FD 0x00000001 /* Full duplex.0=half,1=full */ 1501#define E1000_STATUS_FD 0x00000001 /* Full duplex.0=half,1=full */
@@ -1449,6 +1510,8 @@ struct e1000_hw {
1449#define E1000_STATUS_SPEED_10 0x00000000 /* Speed 10Mb/s */ 1510#define E1000_STATUS_SPEED_10 0x00000000 /* Speed 10Mb/s */
1450#define E1000_STATUS_SPEED_100 0x00000040 /* Speed 100Mb/s */ 1511#define E1000_STATUS_SPEED_100 0x00000040 /* Speed 100Mb/s */
1451#define E1000_STATUS_SPEED_1000 0x00000080 /* Speed 1000Mb/s */ 1512#define E1000_STATUS_SPEED_1000 0x00000080 /* Speed 1000Mb/s */
1513#define E1000_STATUS_LAN_INIT_DONE 0x00000200 /* Lan Init Completion
1514 by EEPROM/Flash */
1452#define E1000_STATUS_ASDV 0x00000300 /* Auto speed detect value */ 1515#define E1000_STATUS_ASDV 0x00000300 /* Auto speed detect value */
1453#define E1000_STATUS_DOCK_CI 0x00000800 /* Change in Dock/Undock state. Clear on write '0'. */ 1516#define E1000_STATUS_DOCK_CI 0x00000800 /* Change in Dock/Undock state. Clear on write '0'. */
1454#define E1000_STATUS_GIO_MASTER_ENABLE 0x00080000 /* Status of Master requests. */ 1517#define E1000_STATUS_GIO_MASTER_ENABLE 0x00080000 /* Status of Master requests. */
@@ -1506,6 +1569,10 @@ struct e1000_hw {
1506#define E1000_STM_OPCODE 0xDB00 1569#define E1000_STM_OPCODE 0xDB00
1507#define E1000_HICR_FW_RESET 0xC0 1570#define E1000_HICR_FW_RESET 0xC0
1508 1571
1572#define E1000_SHADOW_RAM_WORDS 2048
1573#define E1000_ICH8_NVM_SIG_WORD 0x13
1574#define E1000_ICH8_NVM_SIG_MASK 0xC0
1575
1509/* EEPROM Read */ 1576/* EEPROM Read */
1510#define E1000_EERD_START 0x00000001 /* Start Read */ 1577#define E1000_EERD_START 0x00000001 /* Start Read */
1511#define E1000_EERD_DONE 0x00000010 /* Read Done */ 1578#define E1000_EERD_DONE 0x00000010 /* Read Done */
@@ -1551,7 +1618,6 @@ struct e1000_hw {
1551#define E1000_CTRL_EXT_WR_WMARK_320 0x01000000 1618#define E1000_CTRL_EXT_WR_WMARK_320 0x01000000
1552#define E1000_CTRL_EXT_WR_WMARK_384 0x02000000 1619#define E1000_CTRL_EXT_WR_WMARK_384 0x02000000
1553#define E1000_CTRL_EXT_WR_WMARK_448 0x03000000 1620#define E1000_CTRL_EXT_WR_WMARK_448 0x03000000
1554#define E1000_CTRL_EXT_CANC 0x04000000 /* Interrupt delay cancellation */
1555#define E1000_CTRL_EXT_DRV_LOAD 0x10000000 /* Driver loaded bit for FW */ 1621#define E1000_CTRL_EXT_DRV_LOAD 0x10000000 /* Driver loaded bit for FW */
1556#define E1000_CTRL_EXT_IAME 0x08000000 /* Interrupt acknowledge Auto-mask */ 1622#define E1000_CTRL_EXT_IAME 0x08000000 /* Interrupt acknowledge Auto-mask */
1557#define E1000_CTRL_EXT_INT_TIMER_CLR 0x20000000 /* Clear Interrupt timers after IMS clear */ 1623#define E1000_CTRL_EXT_INT_TIMER_CLR 0x20000000 /* Clear Interrupt timers after IMS clear */
@@ -1591,12 +1657,31 @@ struct e1000_hw {
1591#define E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS 0x00000800 1657#define E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS 0x00000800
1592 1658
1593/* In-Band Control */ 1659/* In-Band Control */
1660#define E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT 0x00000500
1594#define E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING 0x00000010 1661#define E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING 0x00000010
1595 1662
1596/* Half-Duplex Control */ 1663/* Half-Duplex Control */
1597#define E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT 0x00000004 1664#define E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT 0x00000004
1598#define E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT 0x00000000 1665#define E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT 0x00000000
1599 1666
1667#define E1000_KUMCTRLSTA_OFFSET_K0S_CTRL 0x0000001E
1668
1669#define E1000_KUMCTRLSTA_DIAG_FELPBK 0x2000
1670#define E1000_KUMCTRLSTA_DIAG_NELPBK 0x1000
1671
1672#define E1000_KUMCTRLSTA_K0S_100_EN 0x2000
1673#define E1000_KUMCTRLSTA_K0S_GBE_EN 0x1000
1674#define E1000_KUMCTRLSTA_K0S_ENTRY_LATENCY_MASK 0x0003
1675
1676#define E1000_KABGTXD_BGSQLBIAS 0x00050000
1677
1678#define E1000_PHY_CTRL_SPD_EN 0x00000001
1679#define E1000_PHY_CTRL_D0A_LPLU 0x00000002
1680#define E1000_PHY_CTRL_NOND0A_LPLU 0x00000004
1681#define E1000_PHY_CTRL_NOND0A_GBE_DISABLE 0x00000008
1682#define E1000_PHY_CTRL_GBE_DISABLE 0x00000040
1683#define E1000_PHY_CTRL_B2B_EN 0x00000080
1684
1600/* LED Control */ 1685/* LED Control */
1601#define E1000_LEDCTL_LED0_MODE_MASK 0x0000000F 1686#define E1000_LEDCTL_LED0_MODE_MASK 0x0000000F
1602#define E1000_LEDCTL_LED0_MODE_SHIFT 0 1687#define E1000_LEDCTL_LED0_MODE_SHIFT 0
@@ -1666,6 +1751,9 @@ struct e1000_hw {
1666#define E1000_ICR_RXD_FIFO_PAR1 0x01000000 /* queue 1 Rx descriptor FIFO parity error */ 1751#define E1000_ICR_RXD_FIFO_PAR1 0x01000000 /* queue 1 Rx descriptor FIFO parity error */
1667#define E1000_ICR_TXD_FIFO_PAR1 0x02000000 /* queue 1 Tx descriptor FIFO parity error */ 1752#define E1000_ICR_TXD_FIFO_PAR1 0x02000000 /* queue 1 Tx descriptor FIFO parity error */
1668#define E1000_ICR_ALL_PARITY 0x03F00000 /* all parity error bits */ 1753#define E1000_ICR_ALL_PARITY 0x03F00000 /* all parity error bits */
1754#define E1000_ICR_DSW 0x00000020 /* FW changed the status of DISSW bit in the FWSM */
1755#define E1000_ICR_PHYINT 0x00001000 /* LAN connected device generates an interrupt */
1756#define E1000_ICR_EPRST 0x00100000 /* ME handware reset occurs */
1669 1757
1670/* Interrupt Cause Set */ 1758/* Interrupt Cause Set */
1671#define E1000_ICS_TXDW E1000_ICR_TXDW /* Transmit desc written back */ 1759#define E1000_ICS_TXDW E1000_ICR_TXDW /* Transmit desc written back */
@@ -1692,6 +1780,9 @@ struct e1000_hw {
1692#define E1000_ICS_PB_PAR E1000_ICR_PB_PAR /* packet buffer parity error */ 1780#define E1000_ICS_PB_PAR E1000_ICR_PB_PAR /* packet buffer parity error */
1693#define E1000_ICS_RXD_FIFO_PAR1 E1000_ICR_RXD_FIFO_PAR1 /* queue 1 Rx descriptor FIFO parity error */ 1781#define E1000_ICS_RXD_FIFO_PAR1 E1000_ICR_RXD_FIFO_PAR1 /* queue 1 Rx descriptor FIFO parity error */
1694#define E1000_ICS_TXD_FIFO_PAR1 E1000_ICR_TXD_FIFO_PAR1 /* queue 1 Tx descriptor FIFO parity error */ 1782#define E1000_ICS_TXD_FIFO_PAR1 E1000_ICR_TXD_FIFO_PAR1 /* queue 1 Tx descriptor FIFO parity error */
1783#define E1000_ICS_DSW E1000_ICR_DSW
1784#define E1000_ICS_PHYINT E1000_ICR_PHYINT
1785#define E1000_ICS_EPRST E1000_ICR_EPRST
1695 1786
1696/* Interrupt Mask Set */ 1787/* Interrupt Mask Set */
1697#define E1000_IMS_TXDW E1000_ICR_TXDW /* Transmit desc written back */ 1788#define E1000_IMS_TXDW E1000_ICR_TXDW /* Transmit desc written back */
@@ -1718,6 +1809,9 @@ struct e1000_hw {
1718#define E1000_IMS_PB_PAR E1000_ICR_PB_PAR /* packet buffer parity error */ 1809#define E1000_IMS_PB_PAR E1000_ICR_PB_PAR /* packet buffer parity error */
1719#define E1000_IMS_RXD_FIFO_PAR1 E1000_ICR_RXD_FIFO_PAR1 /* queue 1 Rx descriptor FIFO parity error */ 1810#define E1000_IMS_RXD_FIFO_PAR1 E1000_ICR_RXD_FIFO_PAR1 /* queue 1 Rx descriptor FIFO parity error */
1720#define E1000_IMS_TXD_FIFO_PAR1 E1000_ICR_TXD_FIFO_PAR1 /* queue 1 Tx descriptor FIFO parity error */ 1811#define E1000_IMS_TXD_FIFO_PAR1 E1000_ICR_TXD_FIFO_PAR1 /* queue 1 Tx descriptor FIFO parity error */
1812#define E1000_IMS_DSW E1000_ICR_DSW
1813#define E1000_IMS_PHYINT E1000_ICR_PHYINT
1814#define E1000_IMS_EPRST E1000_ICR_EPRST
1721 1815
1722/* Interrupt Mask Clear */ 1816/* Interrupt Mask Clear */
1723#define E1000_IMC_TXDW E1000_ICR_TXDW /* Transmit desc written back */ 1817#define E1000_IMC_TXDW E1000_ICR_TXDW /* Transmit desc written back */
@@ -1744,6 +1838,9 @@ struct e1000_hw {
1744#define E1000_IMC_PB_PAR E1000_ICR_PB_PAR /* packet buffer parity error */ 1838#define E1000_IMC_PB_PAR E1000_ICR_PB_PAR /* packet buffer parity error */
1745#define E1000_IMC_RXD_FIFO_PAR1 E1000_ICR_RXD_FIFO_PAR1 /* queue 1 Rx descriptor FIFO parity error */ 1839#define E1000_IMC_RXD_FIFO_PAR1 E1000_ICR_RXD_FIFO_PAR1 /* queue 1 Rx descriptor FIFO parity error */
1746#define E1000_IMC_TXD_FIFO_PAR1 E1000_ICR_TXD_FIFO_PAR1 /* queue 1 Tx descriptor FIFO parity error */ 1840#define E1000_IMC_TXD_FIFO_PAR1 E1000_ICR_TXD_FIFO_PAR1 /* queue 1 Tx descriptor FIFO parity error */
1841#define E1000_IMC_DSW E1000_ICR_DSW
1842#define E1000_IMC_PHYINT E1000_ICR_PHYINT
1843#define E1000_IMC_EPRST E1000_ICR_EPRST
1747 1844
1748/* Receive Control */ 1845/* Receive Control */
1749#define E1000_RCTL_RST 0x00000001 /* Software reset */ 1846#define E1000_RCTL_RST 0x00000001 /* Software reset */
@@ -1918,9 +2015,10 @@ struct e1000_hw {
1918#define E1000_MRQC_RSS_FIELD_MASK 0xFFFF0000 2015#define E1000_MRQC_RSS_FIELD_MASK 0xFFFF0000
1919#define E1000_MRQC_RSS_FIELD_IPV4_TCP 0x00010000 2016#define E1000_MRQC_RSS_FIELD_IPV4_TCP 0x00010000
1920#define E1000_MRQC_RSS_FIELD_IPV4 0x00020000 2017#define E1000_MRQC_RSS_FIELD_IPV4 0x00020000
1921#define E1000_MRQC_RSS_FIELD_IPV6_TCP 0x00040000 2018#define E1000_MRQC_RSS_FIELD_IPV6_TCP_EX 0x00040000
1922#define E1000_MRQC_RSS_FIELD_IPV6_EX 0x00080000 2019#define E1000_MRQC_RSS_FIELD_IPV6_EX 0x00080000
1923#define E1000_MRQC_RSS_FIELD_IPV6 0x00100000 2020#define E1000_MRQC_RSS_FIELD_IPV6 0x00100000
2021#define E1000_MRQC_RSS_FIELD_IPV6_TCP 0x00200000
1924 2022
1925/* Definitions for power management and wakeup registers */ 2023/* Definitions for power management and wakeup registers */
1926/* Wake Up Control */ 2024/* Wake Up Control */
@@ -2010,6 +2108,15 @@ struct e1000_hw {
2010#define E1000_FWSM_MODE_SHIFT 1 2108#define E1000_FWSM_MODE_SHIFT 1
2011#define E1000_FWSM_FW_VALID 0x00008000 /* FW established a valid mode */ 2109#define E1000_FWSM_FW_VALID 0x00008000 /* FW established a valid mode */
2012 2110
2111#define E1000_FWSM_RSPCIPHY 0x00000040 /* Reset PHY on PCI reset */
2112#define E1000_FWSM_DISSW 0x10000000 /* FW disable SW Write Access */
2113#define E1000_FWSM_SKUSEL_MASK 0x60000000 /* LAN SKU select */
2114#define E1000_FWSM_SKUEL_SHIFT 29
2115#define E1000_FWSM_SKUSEL_EMB 0x0 /* Embedded SKU */
2116#define E1000_FWSM_SKUSEL_CONS 0x1 /* Consumer SKU */
2117#define E1000_FWSM_SKUSEL_PERF_100 0x2 /* Perf & Corp 10/100 SKU */
2118#define E1000_FWSM_SKUSEL_PERF_GBE 0x3 /* Perf & Copr GbE SKU */
2119
2013/* FFLT Debug Register */ 2120/* FFLT Debug Register */
2014#define E1000_FFLT_DBG_INVC 0x00100000 /* Invalid /C/ code handling */ 2121#define E1000_FFLT_DBG_INVC 0x00100000 /* Invalid /C/ code handling */
2015 2122
@@ -2082,6 +2189,8 @@ struct e1000_host_command_info {
2082 E1000_GCR_TXDSCW_NO_SNOOP | \ 2189 E1000_GCR_TXDSCW_NO_SNOOP | \
2083 E1000_GCR_TXDSCR_NO_SNOOP) 2190 E1000_GCR_TXDSCR_NO_SNOOP)
2084 2191
2192#define PCI_EX_82566_SNOOP_ALL PCI_EX_NO_SNOOP_ALL
2193
2085#define E1000_GCR_L1_ACT_WITHOUT_L0S_RX 0x08000000 2194#define E1000_GCR_L1_ACT_WITHOUT_L0S_RX 0x08000000
2086/* Function Active and Power State to MNG */ 2195/* Function Active and Power State to MNG */
2087#define E1000_FACTPS_FUNC0_POWER_STATE_MASK 0x00000003 2196#define E1000_FACTPS_FUNC0_POWER_STATE_MASK 0x00000003
@@ -2140,8 +2249,10 @@ struct e1000_host_command_info {
2140#define EEPROM_PHY_CLASS_WORD 0x0007 2249#define EEPROM_PHY_CLASS_WORD 0x0007
2141#define EEPROM_INIT_CONTROL1_REG 0x000A 2250#define EEPROM_INIT_CONTROL1_REG 0x000A
2142#define EEPROM_INIT_CONTROL2_REG 0x000F 2251#define EEPROM_INIT_CONTROL2_REG 0x000F
2252#define EEPROM_SWDEF_PINS_CTRL_PORT_1 0x0010
2143#define EEPROM_INIT_CONTROL3_PORT_B 0x0014 2253#define EEPROM_INIT_CONTROL3_PORT_B 0x0014
2144#define EEPROM_INIT_3GIO_3 0x001A 2254#define EEPROM_INIT_3GIO_3 0x001A
2255#define EEPROM_SWDEF_PINS_CTRL_PORT_0 0x0020
2145#define EEPROM_INIT_CONTROL3_PORT_A 0x0024 2256#define EEPROM_INIT_CONTROL3_PORT_A 0x0024
2146#define EEPROM_CFG 0x0012 2257#define EEPROM_CFG 0x0012
2147#define EEPROM_FLASH_VERSION 0x0032 2258#define EEPROM_FLASH_VERSION 0x0032
@@ -2153,10 +2264,16 @@ struct e1000_host_command_info {
2153/* Word definitions for ID LED Settings */ 2264/* Word definitions for ID LED Settings */
2154#define ID_LED_RESERVED_0000 0x0000 2265#define ID_LED_RESERVED_0000 0x0000
2155#define ID_LED_RESERVED_FFFF 0xFFFF 2266#define ID_LED_RESERVED_FFFF 0xFFFF
2267#define ID_LED_RESERVED_82573 0xF746
2268#define ID_LED_DEFAULT_82573 0x1811
2156#define ID_LED_DEFAULT ((ID_LED_OFF1_ON2 << 12) | \ 2269#define ID_LED_DEFAULT ((ID_LED_OFF1_ON2 << 12) | \
2157 (ID_LED_OFF1_OFF2 << 8) | \ 2270 (ID_LED_OFF1_OFF2 << 8) | \
2158 (ID_LED_DEF1_DEF2 << 4) | \ 2271 (ID_LED_DEF1_DEF2 << 4) | \
2159 (ID_LED_DEF1_DEF2)) 2272 (ID_LED_DEF1_DEF2))
2273#define ID_LED_DEFAULT_ICH8LAN ((ID_LED_DEF1_DEF2 << 12) | \
2274 (ID_LED_DEF1_OFF2 << 8) | \
2275 (ID_LED_DEF1_ON2 << 4) | \
2276 (ID_LED_DEF1_DEF2))
2160#define ID_LED_DEF1_DEF2 0x1 2277#define ID_LED_DEF1_DEF2 0x1
2161#define ID_LED_DEF1_ON2 0x2 2278#define ID_LED_DEF1_ON2 0x2
2162#define ID_LED_DEF1_OFF2 0x3 2279#define ID_LED_DEF1_OFF2 0x3
@@ -2191,6 +2308,11 @@ struct e1000_host_command_info {
2191#define EEPROM_WORD0F_ASM_DIR 0x2000 2308#define EEPROM_WORD0F_ASM_DIR 0x2000
2192#define EEPROM_WORD0F_ANE 0x0800 2309#define EEPROM_WORD0F_ANE 0x0800
2193#define EEPROM_WORD0F_SWPDIO_EXT 0x00F0 2310#define EEPROM_WORD0F_SWPDIO_EXT 0x00F0
2311#define EEPROM_WORD0F_LPLU 0x0001
2312
2313/* Mask bits for fields in Word 0x10/0x20 of the EEPROM */
2314#define EEPROM_WORD1020_GIGA_DISABLE 0x0010
2315#define EEPROM_WORD1020_GIGA_DISABLE_NON_D0A 0x0008
2194 2316
2195/* Mask bits for fields in Word 0x1a of the EEPROM */ 2317/* Mask bits for fields in Word 0x1a of the EEPROM */
2196#define EEPROM_WORD1A_ASPM_MASK 0x000C 2318#define EEPROM_WORD1A_ASPM_MASK 0x000C
@@ -2265,23 +2387,29 @@ struct e1000_host_command_info {
2265#define E1000_EXTCNF_CTRL_D_UD_OWNER 0x00000010 2387#define E1000_EXTCNF_CTRL_D_UD_OWNER 0x00000010
2266#define E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP 0x00000020 2388#define E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP 0x00000020
2267#define E1000_EXTCNF_CTRL_MDIO_HW_OWNERSHIP 0x00000040 2389#define E1000_EXTCNF_CTRL_MDIO_HW_OWNERSHIP 0x00000040
2268#define E1000_EXTCNF_CTRL_EXT_CNF_POINTER 0x1FFF0000 2390#define E1000_EXTCNF_CTRL_EXT_CNF_POINTER 0x0FFF0000
2269 2391
2270#define E1000_EXTCNF_SIZE_EXT_PHY_LENGTH 0x000000FF 2392#define E1000_EXTCNF_SIZE_EXT_PHY_LENGTH 0x000000FF
2271#define E1000_EXTCNF_SIZE_EXT_DOCK_LENGTH 0x0000FF00 2393#define E1000_EXTCNF_SIZE_EXT_DOCK_LENGTH 0x0000FF00
2272#define E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH 0x00FF0000 2394#define E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH 0x00FF0000
2395#define E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE 0x00000001
2396#define E1000_EXTCNF_CTRL_SWFLAG 0x00000020
2273 2397
2274/* PBA constants */ 2398/* PBA constants */
2399#define E1000_PBA_8K 0x0008 /* 8KB, default Rx allocation */
2275#define E1000_PBA_12K 0x000C /* 12KB, default Rx allocation */ 2400#define E1000_PBA_12K 0x000C /* 12KB, default Rx allocation */
2276#define E1000_PBA_16K 0x0010 /* 16KB, default TX allocation */ 2401#define E1000_PBA_16K 0x0010 /* 16KB, default TX allocation */
2277#define E1000_PBA_22K 0x0016 2402#define E1000_PBA_22K 0x0016
2278#define E1000_PBA_24K 0x0018 2403#define E1000_PBA_24K 0x0018
2279#define E1000_PBA_30K 0x001E 2404#define E1000_PBA_30K 0x001E
2280#define E1000_PBA_32K 0x0020 2405#define E1000_PBA_32K 0x0020
2406#define E1000_PBA_34K 0x0022
2281#define E1000_PBA_38K 0x0026 2407#define E1000_PBA_38K 0x0026
2282#define E1000_PBA_40K 0x0028 2408#define E1000_PBA_40K 0x0028
2283#define E1000_PBA_48K 0x0030 /* 48KB, default RX allocation */ 2409#define E1000_PBA_48K 0x0030 /* 48KB, default RX allocation */
2284 2410
2411#define E1000_PBS_16K E1000_PBA_16K
2412
2285/* Flow Control Constants */ 2413/* Flow Control Constants */
2286#define FLOW_CONTROL_ADDRESS_LOW 0x00C28001 2414#define FLOW_CONTROL_ADDRESS_LOW 0x00C28001
2287#define FLOW_CONTROL_ADDRESS_HIGH 0x00000100 2415#define FLOW_CONTROL_ADDRESS_HIGH 0x00000100
@@ -2336,7 +2464,7 @@ struct e1000_host_command_info {
2336/* Number of milliseconds we wait for Eeprom auto read bit done after MAC reset */ 2464/* Number of milliseconds we wait for Eeprom auto read bit done after MAC reset */
2337#define AUTO_READ_DONE_TIMEOUT 10 2465#define AUTO_READ_DONE_TIMEOUT 10
2338/* Number of milliseconds we wait for PHY configuration done after MAC reset */ 2466/* Number of milliseconds we wait for PHY configuration done after MAC reset */
2339#define PHY_CFG_TIMEOUT 40 2467#define PHY_CFG_TIMEOUT 100
2340 2468
2341#define E1000_TX_BUFFER_SIZE ((uint32_t)1514) 2469#define E1000_TX_BUFFER_SIZE ((uint32_t)1514)
2342 2470
@@ -2764,6 +2892,17 @@ struct e1000_host_command_info {
2764#define M88E1000_EPSCR_TX_CLK_25 0x0070 /* 25 MHz TX_CLK */ 2892#define M88E1000_EPSCR_TX_CLK_25 0x0070 /* 25 MHz TX_CLK */
2765#define M88E1000_EPSCR_TX_CLK_0 0x0000 /* NO TX_CLK */ 2893#define M88E1000_EPSCR_TX_CLK_0 0x0000 /* NO TX_CLK */
2766 2894
2895/* M88EC018 Rev 2 specific DownShift settings */
2896#define M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK 0x0E00
2897#define M88EC018_EPSCR_DOWNSHIFT_COUNTER_1X 0x0000
2898#define M88EC018_EPSCR_DOWNSHIFT_COUNTER_2X 0x0200
2899#define M88EC018_EPSCR_DOWNSHIFT_COUNTER_3X 0x0400
2900#define M88EC018_EPSCR_DOWNSHIFT_COUNTER_4X 0x0600
2901#define M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X 0x0800
2902#define M88EC018_EPSCR_DOWNSHIFT_COUNTER_6X 0x0A00
2903#define M88EC018_EPSCR_DOWNSHIFT_COUNTER_7X 0x0C00
2904#define M88EC018_EPSCR_DOWNSHIFT_COUNTER_8X 0x0E00
2905
2767/* IGP01E1000 Specific Port Config Register - R/W */ 2906/* IGP01E1000 Specific Port Config Register - R/W */
2768#define IGP01E1000_PSCFR_AUTO_MDIX_PAR_DETECT 0x0010 2907#define IGP01E1000_PSCFR_AUTO_MDIX_PAR_DETECT 0x0010
2769#define IGP01E1000_PSCFR_PRE_EN 0x0020 2908#define IGP01E1000_PSCFR_PRE_EN 0x0020
@@ -2990,6 +3129,221 @@ struct e1000_host_command_info {
2990#define L1LXT971A_PHY_ID 0x001378E0 3129#define L1LXT971A_PHY_ID 0x001378E0
2991#define GG82563_E_PHY_ID 0x01410CA0 3130#define GG82563_E_PHY_ID 0x01410CA0
2992 3131
3132
3133/* Bits...
3134 * 15-5: page
3135 * 4-0: register offset
3136 */
3137#define PHY_PAGE_SHIFT 5
3138#define PHY_REG(page, reg) \
3139 (((page) << PHY_PAGE_SHIFT) | ((reg) & MAX_PHY_REG_ADDRESS))
3140
3141#define IGP3_PHY_PORT_CTRL \
3142 PHY_REG(769, 17) /* Port General Configuration */
3143#define IGP3_PHY_RATE_ADAPT_CTRL \
3144 PHY_REG(769, 25) /* Rate Adapter Control Register */
3145
3146#define IGP3_KMRN_FIFO_CTRL_STATS \
3147 PHY_REG(770, 16) /* KMRN FIFO's control/status register */
3148#define IGP3_KMRN_POWER_MNG_CTRL \
3149 PHY_REG(770, 17) /* KMRN Power Management Control Register */
3150#define IGP3_KMRN_INBAND_CTRL \
3151 PHY_REG(770, 18) /* KMRN Inband Control Register */
3152#define IGP3_KMRN_DIAG \
3153 PHY_REG(770, 19) /* KMRN Diagnostic register */
3154#define IGP3_KMRN_DIAG_PCS_LOCK_LOSS 0x0002 /* RX PCS is not synced */
3155#define IGP3_KMRN_ACK_TIMEOUT \
3156 PHY_REG(770, 20) /* KMRN Acknowledge Timeouts register */
3157
3158#define IGP3_VR_CTRL \
3159 PHY_REG(776, 18) /* Voltage regulator control register */
3160#define IGP3_VR_CTRL_MODE_SHUT 0x0200 /* Enter powerdown, shutdown VRs */
3161
3162#define IGP3_CAPABILITY \
3163 PHY_REG(776, 19) /* IGP3 Capability Register */
3164
3165/* Capabilities for SKU Control */
3166#define IGP3_CAP_INITIATE_TEAM 0x0001 /* Able to initiate a team */
3167#define IGP3_CAP_WFM 0x0002 /* Support WoL and PXE */
3168#define IGP3_CAP_ASF 0x0004 /* Support ASF */
3169#define IGP3_CAP_LPLU 0x0008 /* Support Low Power Link Up */
3170#define IGP3_CAP_DC_AUTO_SPEED 0x0010 /* Support AC/DC Auto Link Speed */
3171#define IGP3_CAP_SPD 0x0020 /* Support Smart Power Down */
3172#define IGP3_CAP_MULT_QUEUE 0x0040 /* Support 2 tx & 2 rx queues */
3173#define IGP3_CAP_RSS 0x0080 /* Support RSS */
3174#define IGP3_CAP_8021PQ 0x0100 /* Support 802.1Q & 802.1p */
3175#define IGP3_CAP_AMT_CB 0x0200 /* Support active manageability and circuit breaker */
3176
3177#define IGP3_PPC_JORDAN_EN 0x0001
3178#define IGP3_PPC_JORDAN_GIGA_SPEED 0x0002
3179
3180#define IGP3_KMRN_PMC_EE_IDLE_LINK_DIS 0x0001
3181#define IGP3_KMRN_PMC_K0S_ENTRY_LATENCY_MASK 0x001E
3182#define IGP3_KMRN_PMC_K0S_MODE1_EN_GIGA 0x0020
3183#define IGP3_KMRN_PMC_K0S_MODE1_EN_100 0x0040
3184
3185#define IGP3E1000_PHY_MISC_CTRL 0x1B /* Misc. Ctrl register */
3186#define IGP3_PHY_MISC_DUPLEX_MANUAL_SET 0x1000 /* Duplex Manual Set */
3187
3188#define IGP3_KMRN_EXT_CTRL PHY_REG(770, 18)
3189#define IGP3_KMRN_EC_DIS_INBAND 0x0080
3190
3191#define IGP03E1000_E_PHY_ID 0x02A80390
3192#define IFE_E_PHY_ID 0x02A80330 /* 10/100 PHY */
3193#define IFE_PLUS_E_PHY_ID 0x02A80320
3194#define IFE_C_E_PHY_ID 0x02A80310
3195
3196#define IFE_PHY_EXTENDED_STATUS_CONTROL 0x10 /* 100BaseTx Extended Status, Control and Address */
3197#define IFE_PHY_SPECIAL_CONTROL 0x11 /* 100BaseTx PHY special control register */
3198#define IFE_PHY_RCV_FALSE_CARRIER 0x13 /* 100BaseTx Receive False Carrier Counter */
3199#define IFE_PHY_RCV_DISCONNECT 0x14 /* 100BaseTx Receive Disconnet Counter */
3200#define IFE_PHY_RCV_ERROT_FRAME 0x15 /* 100BaseTx Receive Error Frame Counter */
3201#define IFE_PHY_RCV_SYMBOL_ERR 0x16 /* Receive Symbol Error Counter */
3202#define IFE_PHY_PREM_EOF_ERR 0x17 /* 100BaseTx Receive Premature End Of Frame Error Counter */
3203#define IFE_PHY_RCV_EOF_ERR 0x18 /* 10BaseT Receive End Of Frame Error Counter */
3204#define IFE_PHY_TX_JABBER_DETECT 0x19 /* 10BaseT Transmit Jabber Detect Counter */
3205#define IFE_PHY_EQUALIZER 0x1A /* PHY Equalizer Control and Status */
3206#define IFE_PHY_SPECIAL_CONTROL_LED 0x1B /* PHY special control and LED configuration */
3207#define IFE_PHY_MDIX_CONTROL 0x1C /* MDI/MDI-X Control register */
3208#define IFE_PHY_HWI_CONTROL 0x1D /* Hardware Integrity Control (HWI) */
3209
3210#define IFE_PESC_REDUCED_POWER_DOWN_DISABLE 0x2000 /* Defaut 1 = Disable auto reduced power down */
3211#define IFE_PESC_100BTX_POWER_DOWN 0x0400 /* Indicates the power state of 100BASE-TX */
3212#define IFE_PESC_10BTX_POWER_DOWN 0x0200 /* Indicates the power state of 10BASE-T */
3213#define IFE_PESC_POLARITY_REVERSED 0x0100 /* Indicates 10BASE-T polarity */
3214#define IFE_PESC_PHY_ADDR_MASK 0x007C /* Bit 6:2 for sampled PHY address */
3215#define IFE_PESC_SPEED 0x0002 /* Auto-negotiation speed result 1=100Mbs, 0=10Mbs */
3216#define IFE_PESC_DUPLEX 0x0001 /* Auto-negotiation duplex result 1=Full, 0=Half */
3217#define IFE_PESC_POLARITY_REVERSED_SHIFT 8
3218
3219#define IFE_PSC_DISABLE_DYNAMIC_POWER_DOWN 0x0100 /* 1 = Dyanmic Power Down disabled */
3220#define IFE_PSC_FORCE_POLARITY 0x0020 /* 1=Reversed Polarity, 0=Normal */
3221#define IFE_PSC_AUTO_POLARITY_DISABLE 0x0010 /* 1=Auto Polarity Disabled, 0=Enabled */
3222#define IFE_PSC_JABBER_FUNC_DISABLE 0x0001 /* 1=Jabber Disabled, 0=Normal Jabber Operation */
3223#define IFE_PSC_FORCE_POLARITY_SHIFT 5
3224#define IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT 4
3225
3226#define IFE_PMC_AUTO_MDIX 0x0080 /* 1=enable MDI/MDI-X feature, default 0=disabled */
3227#define IFE_PMC_FORCE_MDIX 0x0040 /* 1=force MDIX-X, 0=force MDI */
3228#define IFE_PMC_MDIX_STATUS 0x0020 /* 1=MDI-X, 0=MDI */
3229#define IFE_PMC_AUTO_MDIX_COMPLETE 0x0010 /* Resolution algorthm is completed */
3230#define IFE_PMC_MDIX_MODE_SHIFT 6
3231#define IFE_PHC_MDIX_RESET_ALL_MASK 0x0000 /* Disable auto MDI-X */
3232
3233#define IFE_PHC_HWI_ENABLE 0x8000 /* Enable the HWI feature */
3234#define IFE_PHC_ABILITY_CHECK 0x4000 /* 1= Test Passed, 0=failed */
3235#define IFE_PHC_TEST_EXEC 0x2000 /* PHY launch test pulses on the wire */
3236#define IFE_PHC_HIGHZ 0x0200 /* 1 = Open Circuit */
3237#define IFE_PHC_LOWZ 0x0400 /* 1 = Short Circuit */
3238#define IFE_PHC_LOW_HIGH_Z_MASK 0x0600 /* Mask for indication type of problem on the line */
3239#define IFE_PHC_DISTANCE_MASK 0x01FF /* Mask for distance to the cable problem, in 80cm granularity */
3240#define IFE_PHC_RESET_ALL_MASK 0x0000 /* Disable HWI */
3241#define IFE_PSCL_PROBE_MODE 0x0020 /* LED Probe mode */
3242#define IFE_PSCL_PROBE_LEDS_OFF 0x0006 /* Force LEDs 0 and 2 off */
3243#define IFE_PSCL_PROBE_LEDS_ON 0x0007 /* Force LEDs 0 and 2 on */
3244
3245#define ICH8_FLASH_COMMAND_TIMEOUT 500 /* 500 ms , should be adjusted */
3246#define ICH8_FLASH_CYCLE_REPEAT_COUNT 10 /* 10 cycles , should be adjusted */
3247#define ICH8_FLASH_SEG_SIZE_256 256
3248#define ICH8_FLASH_SEG_SIZE_4K 4096
3249#define ICH8_FLASH_SEG_SIZE_64K 65536
3250
3251#define ICH8_CYCLE_READ 0x0
3252#define ICH8_CYCLE_RESERVED 0x1
3253#define ICH8_CYCLE_WRITE 0x2
3254#define ICH8_CYCLE_ERASE 0x3
3255
3256#define ICH8_FLASH_GFPREG 0x0000
3257#define ICH8_FLASH_HSFSTS 0x0004
3258#define ICH8_FLASH_HSFCTL 0x0006
3259#define ICH8_FLASH_FADDR 0x0008
3260#define ICH8_FLASH_FDATA0 0x0010
3261#define ICH8_FLASH_FRACC 0x0050
3262#define ICH8_FLASH_FREG0 0x0054
3263#define ICH8_FLASH_FREG1 0x0058
3264#define ICH8_FLASH_FREG2 0x005C
3265#define ICH8_FLASH_FREG3 0x0060
3266#define ICH8_FLASH_FPR0 0x0074
3267#define ICH8_FLASH_FPR1 0x0078
3268#define ICH8_FLASH_SSFSTS 0x0090
3269#define ICH8_FLASH_SSFCTL 0x0092
3270#define ICH8_FLASH_PREOP 0x0094
3271#define ICH8_FLASH_OPTYPE 0x0096
3272#define ICH8_FLASH_OPMENU 0x0098
3273
3274#define ICH8_FLASH_REG_MAPSIZE 0x00A0
3275#define ICH8_FLASH_SECTOR_SIZE 4096
3276#define ICH8_GFPREG_BASE_MASK 0x1FFF
3277#define ICH8_FLASH_LINEAR_ADDR_MASK 0x00FFFFFF
3278
3279/* ICH8 GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
3280/* Offset 04h HSFSTS */
3281union ich8_hws_flash_status {
3282 struct ich8_hsfsts {
3283#ifdef E1000_BIG_ENDIAN
3284 uint16_t reserved2 :6;
3285 uint16_t fldesvalid :1;
3286 uint16_t flockdn :1;
3287 uint16_t flcdone :1;
3288 uint16_t flcerr :1;
3289 uint16_t dael :1;
3290 uint16_t berasesz :2;
3291 uint16_t flcinprog :1;
3292 uint16_t reserved1 :2;
3293#else
3294 uint16_t flcdone :1; /* bit 0 Flash Cycle Done */
3295 uint16_t flcerr :1; /* bit 1 Flash Cycle Error */
3296 uint16_t dael :1; /* bit 2 Direct Access error Log */
3297 uint16_t berasesz :2; /* bit 4:3 Block/Sector Erase Size */
3298 uint16_t flcinprog :1; /* bit 5 flash SPI cycle in Progress */
3299 uint16_t reserved1 :2; /* bit 13:6 Reserved */
3300 uint16_t reserved2 :6; /* bit 13:6 Reserved */
3301 uint16_t fldesvalid :1; /* bit 14 Flash Descriptor Valid */
3302 uint16_t flockdn :1; /* bit 15 Flash Configuration Lock-Down */
3303#endif
3304 } hsf_status;
3305 uint16_t regval;
3306};
3307
3308/* ICH8 GbE Flash Hardware Sequencing Flash control Register bit breakdown */
3309/* Offset 06h FLCTL */
3310union ich8_hws_flash_ctrl {
3311 struct ich8_hsflctl {
3312#ifdef E1000_BIG_ENDIAN
3313 uint16_t fldbcount :2;
3314 uint16_t flockdn :6;
3315 uint16_t flcgo :1;
3316 uint16_t flcycle :2;
3317 uint16_t reserved :5;
3318#else
3319 uint16_t flcgo :1; /* 0 Flash Cycle Go */
3320 uint16_t flcycle :2; /* 2:1 Flash Cycle */
3321 uint16_t reserved :5; /* 7:3 Reserved */
3322 uint16_t fldbcount :2; /* 9:8 Flash Data Byte Count */
3323 uint16_t flockdn :6; /* 15:10 Reserved */
3324#endif
3325 } hsf_ctrl;
3326 uint16_t regval;
3327};
3328
3329/* ICH8 Flash Region Access Permissions */
3330union ich8_hws_flash_regacc {
3331 struct ich8_flracc {
3332#ifdef E1000_BIG_ENDIAN
3333 uint32_t gmwag :8;
3334 uint32_t gmrag :8;
3335 uint32_t grwa :8;
3336 uint32_t grra :8;
3337#else
3338 uint32_t grra :8; /* 0:7 GbE region Read Access */
3339 uint32_t grwa :8; /* 8:15 GbE region Write Access */
3340 uint32_t gmrag :8; /* 23:16 GbE Master Read Access Grant */
3341 uint32_t gmwag :8; /* 31:24 GbE Master Write Access Grant */
3342#endif
3343 } hsf_flregacc;
3344 uint16_t regval;
3345};
3346
2993/* Miscellaneous PHY bit definitions. */ 3347/* Miscellaneous PHY bit definitions. */
2994#define PHY_PREAMBLE 0xFFFFFFFF 3348#define PHY_PREAMBLE 0xFFFFFFFF
2995#define PHY_SOF 0x01 3349#define PHY_SOF 0x01
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index f77624f5f17b..98ef9f85482f 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -36,7 +36,7 @@ static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
36#else 36#else
37#define DRIVERNAPI "-NAPI" 37#define DRIVERNAPI "-NAPI"
38#endif 38#endif
39#define DRV_VERSION "7.0.38-k4"DRIVERNAPI 39#define DRV_VERSION "7.1.9-k4"DRIVERNAPI
40char e1000_driver_version[] = DRV_VERSION; 40char e1000_driver_version[] = DRV_VERSION;
41static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation."; 41static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
42 42
@@ -73,6 +73,11 @@ static struct pci_device_id e1000_pci_tbl[] = {
73 INTEL_E1000_ETHERNET_DEVICE(0x1026), 73 INTEL_E1000_ETHERNET_DEVICE(0x1026),
74 INTEL_E1000_ETHERNET_DEVICE(0x1027), 74 INTEL_E1000_ETHERNET_DEVICE(0x1027),
75 INTEL_E1000_ETHERNET_DEVICE(0x1028), 75 INTEL_E1000_ETHERNET_DEVICE(0x1028),
76 INTEL_E1000_ETHERNET_DEVICE(0x1049),
77 INTEL_E1000_ETHERNET_DEVICE(0x104A),
78 INTEL_E1000_ETHERNET_DEVICE(0x104B),
79 INTEL_E1000_ETHERNET_DEVICE(0x104C),
80 INTEL_E1000_ETHERNET_DEVICE(0x104D),
76 INTEL_E1000_ETHERNET_DEVICE(0x105E), 81 INTEL_E1000_ETHERNET_DEVICE(0x105E),
77 INTEL_E1000_ETHERNET_DEVICE(0x105F), 82 INTEL_E1000_ETHERNET_DEVICE(0x105F),
78 INTEL_E1000_ETHERNET_DEVICE(0x1060), 83 INTEL_E1000_ETHERNET_DEVICE(0x1060),
@@ -96,6 +101,8 @@ static struct pci_device_id e1000_pci_tbl[] = {
96 INTEL_E1000_ETHERNET_DEVICE(0x109A), 101 INTEL_E1000_ETHERNET_DEVICE(0x109A),
97 INTEL_E1000_ETHERNET_DEVICE(0x10B5), 102 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
98 INTEL_E1000_ETHERNET_DEVICE(0x10B9), 103 INTEL_E1000_ETHERNET_DEVICE(0x10B9),
104 INTEL_E1000_ETHERNET_DEVICE(0x10BA),
105 INTEL_E1000_ETHERNET_DEVICE(0x10BB),
99 /* required last entry */ 106 /* required last entry */
100 {0,} 107 {0,}
101}; 108};
@@ -133,7 +140,6 @@ static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
133static void e1000_set_multi(struct net_device *netdev); 140static void e1000_set_multi(struct net_device *netdev);
134static void e1000_update_phy_info(unsigned long data); 141static void e1000_update_phy_info(unsigned long data);
135static void e1000_watchdog(unsigned long data); 142static void e1000_watchdog(unsigned long data);
136static void e1000_watchdog_task(struct e1000_adapter *adapter);
137static void e1000_82547_tx_fifo_stall(unsigned long data); 143static void e1000_82547_tx_fifo_stall(unsigned long data);
138static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev); 144static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
139static struct net_device_stats * e1000_get_stats(struct net_device *netdev); 145static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
@@ -178,8 +184,8 @@ static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
178static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); 184static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
179static void e1000_restore_vlan(struct e1000_adapter *adapter); 185static void e1000_restore_vlan(struct e1000_adapter *adapter);
180 186
181#ifdef CONFIG_PM
182static int e1000_suspend(struct pci_dev *pdev, pm_message_t state); 187static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
188#ifdef CONFIG_PM
183static int e1000_resume(struct pci_dev *pdev); 189static int e1000_resume(struct pci_dev *pdev);
184#endif 190#endif
185static void e1000_shutdown(struct pci_dev *pdev); 191static void e1000_shutdown(struct pci_dev *pdev);
@@ -206,8 +212,8 @@ static struct pci_driver e1000_driver = {
206 .probe = e1000_probe, 212 .probe = e1000_probe,
207 .remove = __devexit_p(e1000_remove), 213 .remove = __devexit_p(e1000_remove),
208 /* Power Managment Hooks */ 214 /* Power Managment Hooks */
209#ifdef CONFIG_PM
210 .suspend = e1000_suspend, 215 .suspend = e1000_suspend,
216#ifdef CONFIG_PM
211 .resume = e1000_resume, 217 .resume = e1000_resume,
212#endif 218#endif
213 .shutdown = e1000_shutdown, 219 .shutdown = e1000_shutdown,
@@ -261,6 +267,44 @@ e1000_exit_module(void)
261 267
262module_exit(e1000_exit_module); 268module_exit(e1000_exit_module);
263 269
270static int e1000_request_irq(struct e1000_adapter *adapter)
271{
272 struct net_device *netdev = adapter->netdev;
273 int flags, err = 0;
274
275 flags = IRQF_SHARED;
276#ifdef CONFIG_PCI_MSI
277 if (adapter->hw.mac_type > e1000_82547_rev_2) {
278 adapter->have_msi = TRUE;
279 if ((err = pci_enable_msi(adapter->pdev))) {
280 DPRINTK(PROBE, ERR,
281 "Unable to allocate MSI interrupt Error: %d\n", err);
282 adapter->have_msi = FALSE;
283 }
284 }
285 if (adapter->have_msi)
286 flags &= ~IRQF_SHARED;
287#endif
288 if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags,
289 netdev->name, netdev)))
290 DPRINTK(PROBE, ERR,
291 "Unable to allocate interrupt Error: %d\n", err);
292
293 return err;
294}
295
296static void e1000_free_irq(struct e1000_adapter *adapter)
297{
298 struct net_device *netdev = adapter->netdev;
299
300 free_irq(adapter->pdev->irq, netdev);
301
302#ifdef CONFIG_PCI_MSI
303 if (adapter->have_msi)
304 pci_disable_msi(adapter->pdev);
305#endif
306}
307
264/** 308/**
265 * e1000_irq_disable - Mask off interrupt generation on the NIC 309 * e1000_irq_disable - Mask off interrupt generation on the NIC
266 * @adapter: board private structure 310 * @adapter: board private structure
@@ -329,6 +373,7 @@ e1000_release_hw_control(struct e1000_adapter *adapter)
329{ 373{
330 uint32_t ctrl_ext; 374 uint32_t ctrl_ext;
331 uint32_t swsm; 375 uint32_t swsm;
376 uint32_t extcnf;
332 377
333 /* Let firmware taken over control of h/w */ 378 /* Let firmware taken over control of h/w */
334 switch (adapter->hw.mac_type) { 379 switch (adapter->hw.mac_type) {
@@ -343,6 +388,11 @@ e1000_release_hw_control(struct e1000_adapter *adapter)
343 swsm = E1000_READ_REG(&adapter->hw, SWSM); 388 swsm = E1000_READ_REG(&adapter->hw, SWSM);
344 E1000_WRITE_REG(&adapter->hw, SWSM, 389 E1000_WRITE_REG(&adapter->hw, SWSM,
345 swsm & ~E1000_SWSM_DRV_LOAD); 390 swsm & ~E1000_SWSM_DRV_LOAD);
391 case e1000_ich8lan:
392 extcnf = E1000_READ_REG(&adapter->hw, CTRL_EXT);
393 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
394 extcnf & ~E1000_CTRL_EXT_DRV_LOAD);
395 break;
346 default: 396 default:
347 break; 397 break;
348 } 398 }
@@ -364,6 +414,7 @@ e1000_get_hw_control(struct e1000_adapter *adapter)
364{ 414{
365 uint32_t ctrl_ext; 415 uint32_t ctrl_ext;
366 uint32_t swsm; 416 uint32_t swsm;
417 uint32_t extcnf;
367 /* Let firmware know the driver has taken over */ 418 /* Let firmware know the driver has taken over */
368 switch (adapter->hw.mac_type) { 419 switch (adapter->hw.mac_type) {
369 case e1000_82571: 420 case e1000_82571:
@@ -378,6 +429,11 @@ e1000_get_hw_control(struct e1000_adapter *adapter)
378 E1000_WRITE_REG(&adapter->hw, SWSM, 429 E1000_WRITE_REG(&adapter->hw, SWSM,
379 swsm | E1000_SWSM_DRV_LOAD); 430 swsm | E1000_SWSM_DRV_LOAD);
380 break; 431 break;
432 case e1000_ich8lan:
433 extcnf = E1000_READ_REG(&adapter->hw, EXTCNF_CTRL);
434 E1000_WRITE_REG(&adapter->hw, EXTCNF_CTRL,
435 extcnf | E1000_EXTCNF_CTRL_SWFLAG);
436 break;
381 default: 437 default:
382 break; 438 break;
383 } 439 }
@@ -387,18 +443,10 @@ int
387e1000_up(struct e1000_adapter *adapter) 443e1000_up(struct e1000_adapter *adapter)
388{ 444{
389 struct net_device *netdev = adapter->netdev; 445 struct net_device *netdev = adapter->netdev;
390 int i, err; 446 int i;
391 447
392 /* hardware has been reset, we need to reload some things */ 448 /* hardware has been reset, we need to reload some things */
393 449
394 /* Reset the PHY if it was previously powered down */
395 if (adapter->hw.media_type == e1000_media_type_copper) {
396 uint16_t mii_reg;
397 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
398 if (mii_reg & MII_CR_POWER_DOWN)
399 e1000_phy_hw_reset(&adapter->hw);
400 }
401
402 e1000_set_multi(netdev); 450 e1000_set_multi(netdev);
403 451
404 e1000_restore_vlan(adapter); 452 e1000_restore_vlan(adapter);
@@ -415,24 +463,6 @@ e1000_up(struct e1000_adapter *adapter)
415 E1000_DESC_UNUSED(ring)); 463 E1000_DESC_UNUSED(ring));
416 } 464 }
417 465
418#ifdef CONFIG_PCI_MSI
419 if (adapter->hw.mac_type > e1000_82547_rev_2) {
420 adapter->have_msi = TRUE;
421 if ((err = pci_enable_msi(adapter->pdev))) {
422 DPRINTK(PROBE, ERR,
423 "Unable to allocate MSI interrupt Error: %d\n", err);
424 adapter->have_msi = FALSE;
425 }
426 }
427#endif
428 if ((err = request_irq(adapter->pdev->irq, &e1000_intr,
429 IRQF_SHARED | IRQF_SAMPLE_RANDOM,
430 netdev->name, netdev))) {
431 DPRINTK(PROBE, ERR,
432 "Unable to allocate interrupt Error: %d\n", err);
433 return err;
434 }
435
436 adapter->tx_queue_len = netdev->tx_queue_len; 466 adapter->tx_queue_len = netdev->tx_queue_len;
437 467
438 mod_timer(&adapter->watchdog_timer, jiffies); 468 mod_timer(&adapter->watchdog_timer, jiffies);
@@ -445,21 +475,60 @@ e1000_up(struct e1000_adapter *adapter)
445 return 0; 475 return 0;
446} 476}
447 477
478/**
479 * e1000_power_up_phy - restore link in case the phy was powered down
480 * @adapter: address of board private structure
481 *
482 * The phy may be powered down to save power and turn off link when the
483 * driver is unloaded and wake on lan is not enabled (among others)
484 * *** this routine MUST be followed by a call to e1000_reset ***
485 *
486 **/
487
488static void e1000_power_up_phy(struct e1000_adapter *adapter)
489{
490 uint16_t mii_reg = 0;
491
492 /* Just clear the power down bit to wake the phy back up */
493 if (adapter->hw.media_type == e1000_media_type_copper) {
494 /* according to the manual, the phy will retain its
495 * settings across a power-down/up cycle */
496 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
497 mii_reg &= ~MII_CR_POWER_DOWN;
498 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
499 }
500}
501
502static void e1000_power_down_phy(struct e1000_adapter *adapter)
503{
504 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
505 e1000_check_mng_mode(&adapter->hw);
506 /* Power down the PHY so no link is implied when interface is down
507 * The PHY cannot be powered down if any of the following is TRUE
508 * (a) WoL is enabled
509 * (b) AMT is active
510 * (c) SoL/IDER session is active */
511 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
512 adapter->hw.mac_type != e1000_ich8lan &&
513 adapter->hw.media_type == e1000_media_type_copper &&
514 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
515 !mng_mode_enabled &&
516 !e1000_check_phy_reset_block(&adapter->hw)) {
517 uint16_t mii_reg = 0;
518 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
519 mii_reg |= MII_CR_POWER_DOWN;
520 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
521 mdelay(1);
522 }
523}
524
448void 525void
449e1000_down(struct e1000_adapter *adapter) 526e1000_down(struct e1000_adapter *adapter)
450{ 527{
451 struct net_device *netdev = adapter->netdev; 528 struct net_device *netdev = adapter->netdev;
452 boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
453 e1000_check_mng_mode(&adapter->hw);
454 529
455 e1000_irq_disable(adapter); 530 e1000_irq_disable(adapter);
456 531
457 free_irq(adapter->pdev->irq, netdev);
458#ifdef CONFIG_PCI_MSI
459 if (adapter->hw.mac_type > e1000_82547_rev_2 &&
460 adapter->have_msi == TRUE)
461 pci_disable_msi(adapter->pdev);
462#endif
463 del_timer_sync(&adapter->tx_fifo_stall_timer); 532 del_timer_sync(&adapter->tx_fifo_stall_timer);
464 del_timer_sync(&adapter->watchdog_timer); 533 del_timer_sync(&adapter->watchdog_timer);
465 del_timer_sync(&adapter->phy_info_timer); 534 del_timer_sync(&adapter->phy_info_timer);
@@ -476,23 +545,17 @@ e1000_down(struct e1000_adapter *adapter)
476 e1000_reset(adapter); 545 e1000_reset(adapter);
477 e1000_clean_all_tx_rings(adapter); 546 e1000_clean_all_tx_rings(adapter);
478 e1000_clean_all_rx_rings(adapter); 547 e1000_clean_all_rx_rings(adapter);
548}
479 549
480 /* Power down the PHY so no link is implied when interface is down * 550void
481 * The PHY cannot be powered down if any of the following is TRUE * 551e1000_reinit_locked(struct e1000_adapter *adapter)
482 * (a) WoL is enabled 552{
483 * (b) AMT is active 553 WARN_ON(in_interrupt());
484 * (c) SoL/IDER session is active */ 554 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
485 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 && 555 msleep(1);
486 adapter->hw.media_type == e1000_media_type_copper && 556 e1000_down(adapter);
487 !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) && 557 e1000_up(adapter);
488 !mng_mode_enabled && 558 clear_bit(__E1000_RESETTING, &adapter->flags);
489 !e1000_check_phy_reset_block(&adapter->hw)) {
490 uint16_t mii_reg;
491 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
492 mii_reg |= MII_CR_POWER_DOWN;
493 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
494 mdelay(1);
495 }
496} 559}
497 560
498void 561void
@@ -518,6 +581,9 @@ e1000_reset(struct e1000_adapter *adapter)
518 case e1000_82573: 581 case e1000_82573:
519 pba = E1000_PBA_12K; 582 pba = E1000_PBA_12K;
520 break; 583 break;
584 case e1000_ich8lan:
585 pba = E1000_PBA_8K;
586 break;
521 default: 587 default:
522 pba = E1000_PBA_48K; 588 pba = E1000_PBA_48K;
523 break; 589 break;
@@ -542,6 +608,12 @@ e1000_reset(struct e1000_adapter *adapter)
542 /* Set the FC high water mark to 90% of the FIFO size. 608 /* Set the FC high water mark to 90% of the FIFO size.
543 * Required to clear last 3 LSB */ 609 * Required to clear last 3 LSB */
544 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8; 610 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
611 /* We can't use 90% on small FIFOs because the remainder
612 * would be less than 1 full frame. In this case, we size
613 * it to allow at least a full frame above the high water
614 * mark. */
615 if (pba < E1000_PBA_16K)
616 fc_high_water_mark = (pba * 1024) - 1600;
545 617
546 adapter->hw.fc_high_water = fc_high_water_mark; 618 adapter->hw.fc_high_water = fc_high_water_mark;
547 adapter->hw.fc_low_water = fc_high_water_mark - 8; 619 adapter->hw.fc_low_water = fc_high_water_mark - 8;
@@ -564,6 +636,23 @@ e1000_reset(struct e1000_adapter *adapter)
564 636
565 e1000_reset_adaptive(&adapter->hw); 637 e1000_reset_adaptive(&adapter->hw);
566 e1000_phy_get_info(&adapter->hw, &adapter->phy_info); 638 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
639
640 if (!adapter->smart_power_down &&
641 (adapter->hw.mac_type == e1000_82571 ||
642 adapter->hw.mac_type == e1000_82572)) {
643 uint16_t phy_data = 0;
644 /* speed up time to link by disabling smart power down, ignore
645 * the return value of this function because there is nothing
646 * different we would do if it failed */
647 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
648 &phy_data);
649 phy_data &= ~IGP02E1000_PM_SPD;
650 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
651 phy_data);
652 }
653
654 if (adapter->hw.mac_type < e1000_ich8lan)
655 /* FIXME: this code is duplicate and wrong for PCI Express */
567 if (adapter->en_mng_pt) { 656 if (adapter->en_mng_pt) {
568 manc = E1000_READ_REG(&adapter->hw, MANC); 657 manc = E1000_READ_REG(&adapter->hw, MANC);
569 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST); 658 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
@@ -590,6 +679,7 @@ e1000_probe(struct pci_dev *pdev,
590 struct net_device *netdev; 679 struct net_device *netdev;
591 struct e1000_adapter *adapter; 680 struct e1000_adapter *adapter;
592 unsigned long mmio_start, mmio_len; 681 unsigned long mmio_start, mmio_len;
682 unsigned long flash_start, flash_len;
593 683
594 static int cards_found = 0; 684 static int cards_found = 0;
595 static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */ 685 static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
@@ -599,10 +689,12 @@ e1000_probe(struct pci_dev *pdev,
599 if ((err = pci_enable_device(pdev))) 689 if ((err = pci_enable_device(pdev)))
600 return err; 690 return err;
601 691
602 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) { 692 if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
693 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
603 pci_using_dac = 1; 694 pci_using_dac = 1;
604 } else { 695 } else {
605 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) { 696 if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
697 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
606 E1000_ERR("No usable DMA configuration, aborting\n"); 698 E1000_ERR("No usable DMA configuration, aborting\n");
607 return err; 699 return err;
608 } 700 }
@@ -682,6 +774,19 @@ e1000_probe(struct pci_dev *pdev,
682 if ((err = e1000_sw_init(adapter))) 774 if ((err = e1000_sw_init(adapter)))
683 goto err_sw_init; 775 goto err_sw_init;
684 776
777 /* Flash BAR mapping must happen after e1000_sw_init
778 * because it depends on mac_type */
779 if ((adapter->hw.mac_type == e1000_ich8lan) &&
780 (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
781 flash_start = pci_resource_start(pdev, 1);
782 flash_len = pci_resource_len(pdev, 1);
783 adapter->hw.flash_address = ioremap(flash_start, flash_len);
784 if (!adapter->hw.flash_address) {
785 err = -EIO;
786 goto err_flashmap;
787 }
788 }
789
685 if ((err = e1000_check_phy_reset_block(&adapter->hw))) 790 if ((err = e1000_check_phy_reset_block(&adapter->hw)))
686 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n"); 791 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
687 792
@@ -700,6 +805,8 @@ e1000_probe(struct pci_dev *pdev,
700 NETIF_F_HW_VLAN_TX | 805 NETIF_F_HW_VLAN_TX |
701 NETIF_F_HW_VLAN_RX | 806 NETIF_F_HW_VLAN_RX |
702 NETIF_F_HW_VLAN_FILTER; 807 NETIF_F_HW_VLAN_FILTER;
808 if (adapter->hw.mac_type == e1000_ich8lan)
809 netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
703 } 810 }
704 811
705#ifdef NETIF_F_TSO 812#ifdef NETIF_F_TSO
@@ -715,11 +822,17 @@ e1000_probe(struct pci_dev *pdev,
715 if (pci_using_dac) 822 if (pci_using_dac)
716 netdev->features |= NETIF_F_HIGHDMA; 823 netdev->features |= NETIF_F_HIGHDMA;
717 824
718 /* hard_start_xmit is safe against parallel locking */
719 netdev->features |= NETIF_F_LLTX; 825 netdev->features |= NETIF_F_LLTX;
720 826
721 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw); 827 adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
722 828
829 /* initialize eeprom parameters */
830
831 if (e1000_init_eeprom_params(&adapter->hw)) {
832 E1000_ERR("EEPROM initialization failed\n");
833 return -EIO;
834 }
835
723 /* before reading the EEPROM, reset the controller to 836 /* before reading the EEPROM, reset the controller to
724 * put the device in a known good starting state */ 837 * put the device in a known good starting state */
725 838
@@ -758,9 +871,6 @@ e1000_probe(struct pci_dev *pdev,
758 adapter->watchdog_timer.function = &e1000_watchdog; 871 adapter->watchdog_timer.function = &e1000_watchdog;
759 adapter->watchdog_timer.data = (unsigned long) adapter; 872 adapter->watchdog_timer.data = (unsigned long) adapter;
760 873
761 INIT_WORK(&adapter->watchdog_task,
762 (void (*)(void *))e1000_watchdog_task, adapter);
763
764 init_timer(&adapter->phy_info_timer); 874 init_timer(&adapter->phy_info_timer);
765 adapter->phy_info_timer.function = &e1000_update_phy_info; 875 adapter->phy_info_timer.function = &e1000_update_phy_info;
766 adapter->phy_info_timer.data = (unsigned long) adapter; 876 adapter->phy_info_timer.data = (unsigned long) adapter;
@@ -790,6 +900,11 @@ e1000_probe(struct pci_dev *pdev,
790 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); 900 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
791 eeprom_apme_mask = E1000_EEPROM_82544_APM; 901 eeprom_apme_mask = E1000_EEPROM_82544_APM;
792 break; 902 break;
903 case e1000_ich8lan:
904 e1000_read_eeprom(&adapter->hw,
905 EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
906 eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
907 break;
793 case e1000_82546: 908 case e1000_82546:
794 case e1000_82546_rev_3: 909 case e1000_82546_rev_3:
795 case e1000_82571: 910 case e1000_82571:
@@ -849,6 +964,9 @@ e1000_probe(struct pci_dev *pdev,
849 return 0; 964 return 0;
850 965
851err_register: 966err_register:
967 if (adapter->hw.flash_address)
968 iounmap(adapter->hw.flash_address);
969err_flashmap:
852err_sw_init: 970err_sw_init:
853err_eeprom: 971err_eeprom:
854 iounmap(adapter->hw.hw_addr); 972 iounmap(adapter->hw.hw_addr);
@@ -882,6 +1000,7 @@ e1000_remove(struct pci_dev *pdev)
882 flush_scheduled_work(); 1000 flush_scheduled_work();
883 1001
884 if (adapter->hw.mac_type >= e1000_82540 && 1002 if (adapter->hw.mac_type >= e1000_82540 &&
1003 adapter->hw.mac_type != e1000_ich8lan &&
885 adapter->hw.media_type == e1000_media_type_copper) { 1004 adapter->hw.media_type == e1000_media_type_copper) {
886 manc = E1000_READ_REG(&adapter->hw, MANC); 1005 manc = E1000_READ_REG(&adapter->hw, MANC);
887 if (manc & E1000_MANC_SMBUS_EN) { 1006 if (manc & E1000_MANC_SMBUS_EN) {
@@ -910,6 +1029,8 @@ e1000_remove(struct pci_dev *pdev)
910#endif 1029#endif
911 1030
912 iounmap(adapter->hw.hw_addr); 1031 iounmap(adapter->hw.hw_addr);
1032 if (adapter->hw.flash_address)
1033 iounmap(adapter->hw.flash_address);
913 pci_release_regions(pdev); 1034 pci_release_regions(pdev);
914 1035
915 free_netdev(netdev); 1036 free_netdev(netdev);
@@ -947,7 +1068,7 @@ e1000_sw_init(struct e1000_adapter *adapter)
947 1068
948 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); 1069 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
949 1070
950 adapter->rx_buffer_len = MAXIMUM_ETHERNET_FRAME_SIZE; 1071 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
951 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128; 1072 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
952 hw->max_frame_size = netdev->mtu + 1073 hw->max_frame_size = netdev->mtu +
953 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; 1074 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
@@ -960,13 +1081,6 @@ e1000_sw_init(struct e1000_adapter *adapter)
960 return -EIO; 1081 return -EIO;
961 } 1082 }
962 1083
963 /* initialize eeprom parameters */
964
965 if (e1000_init_eeprom_params(hw)) {
966 E1000_ERR("EEPROM initialization failed\n");
967 return -EIO;
968 }
969
970 switch (hw->mac_type) { 1084 switch (hw->mac_type) {
971 default: 1085 default:
972 break; 1086 break;
@@ -1078,6 +1192,10 @@ e1000_open(struct net_device *netdev)
1078 struct e1000_adapter *adapter = netdev_priv(netdev); 1192 struct e1000_adapter *adapter = netdev_priv(netdev);
1079 int err; 1193 int err;
1080 1194
1195 /* disallow open during test */
1196 if (test_bit(__E1000_DRIVER_TESTING, &adapter->flags))
1197 return -EBUSY;
1198
1081 /* allocate transmit descriptors */ 1199 /* allocate transmit descriptors */
1082 1200
1083 if ((err = e1000_setup_all_tx_resources(adapter))) 1201 if ((err = e1000_setup_all_tx_resources(adapter)))
@@ -1088,6 +1206,12 @@ e1000_open(struct net_device *netdev)
1088 if ((err = e1000_setup_all_rx_resources(adapter))) 1206 if ((err = e1000_setup_all_rx_resources(adapter)))
1089 goto err_setup_rx; 1207 goto err_setup_rx;
1090 1208
1209 err = e1000_request_irq(adapter);
1210 if (err)
1211 goto err_up;
1212
1213 e1000_power_up_phy(adapter);
1214
1091 if ((err = e1000_up(adapter))) 1215 if ((err = e1000_up(adapter)))
1092 goto err_up; 1216 goto err_up;
1093 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; 1217 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
@@ -1131,7 +1255,10 @@ e1000_close(struct net_device *netdev)
1131{ 1255{
1132 struct e1000_adapter *adapter = netdev_priv(netdev); 1256 struct e1000_adapter *adapter = netdev_priv(netdev);
1133 1257
1258 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1134 e1000_down(adapter); 1259 e1000_down(adapter);
1260 e1000_power_down_phy(adapter);
1261 e1000_free_irq(adapter);
1135 1262
1136 e1000_free_all_tx_resources(adapter); 1263 e1000_free_all_tx_resources(adapter);
1137 e1000_free_all_rx_resources(adapter); 1264 e1000_free_all_rx_resources(adapter);
@@ -1189,8 +1316,7 @@ e1000_setup_tx_resources(struct e1000_adapter *adapter,
1189 int size; 1316 int size;
1190 1317
1191 size = sizeof(struct e1000_buffer) * txdr->count; 1318 size = sizeof(struct e1000_buffer) * txdr->count;
1192 1319 txdr->buffer_info = vmalloc(size);
1193 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1194 if (!txdr->buffer_info) { 1320 if (!txdr->buffer_info) {
1195 DPRINTK(PROBE, ERR, 1321 DPRINTK(PROBE, ERR,
1196 "Unable to allocate memory for the transmit descriptor ring\n"); 1322 "Unable to allocate memory for the transmit descriptor ring\n");
@@ -1302,13 +1428,13 @@ e1000_configure_tx(struct e1000_adapter *adapter)
1302 tdba = adapter->tx_ring[0].dma; 1428 tdba = adapter->tx_ring[0].dma;
1303 tdlen = adapter->tx_ring[0].count * 1429 tdlen = adapter->tx_ring[0].count *
1304 sizeof(struct e1000_tx_desc); 1430 sizeof(struct e1000_tx_desc);
1305 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1306 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1307 E1000_WRITE_REG(hw, TDLEN, tdlen); 1431 E1000_WRITE_REG(hw, TDLEN, tdlen);
1308 E1000_WRITE_REG(hw, TDH, 0); 1432 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1433 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1309 E1000_WRITE_REG(hw, TDT, 0); 1434 E1000_WRITE_REG(hw, TDT, 0);
1310 adapter->tx_ring[0].tdh = E1000_TDH; 1435 E1000_WRITE_REG(hw, TDH, 0);
1311 adapter->tx_ring[0].tdt = E1000_TDT; 1436 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
1437 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
1312 break; 1438 break;
1313 } 1439 }
1314 1440
@@ -1418,7 +1544,7 @@ e1000_setup_rx_resources(struct e1000_adapter *adapter,
1418 int size, desc_len; 1544 int size, desc_len;
1419 1545
1420 size = sizeof(struct e1000_buffer) * rxdr->count; 1546 size = sizeof(struct e1000_buffer) * rxdr->count;
1421 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus)); 1547 rxdr->buffer_info = vmalloc(size);
1422 if (!rxdr->buffer_info) { 1548 if (!rxdr->buffer_info) {
1423 DPRINTK(PROBE, ERR, 1549 DPRINTK(PROBE, ERR,
1424 "Unable to allocate memory for the receive descriptor ring\n"); 1550 "Unable to allocate memory for the receive descriptor ring\n");
@@ -1560,9 +1686,6 @@ e1000_setup_rctl(struct e1000_adapter *adapter)
1560 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | 1686 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1561 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT); 1687 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1562 1688
1563 if (adapter->hw.mac_type > e1000_82543)
1564 rctl |= E1000_RCTL_SECRC;
1565
1566 if (adapter->hw.tbi_compatibility_on == 1) 1689 if (adapter->hw.tbi_compatibility_on == 1)
1567 rctl |= E1000_RCTL_SBP; 1690 rctl |= E1000_RCTL_SBP;
1568 else 1691 else
@@ -1628,7 +1751,7 @@ e1000_setup_rctl(struct e1000_adapter *adapter)
1628 rfctl |= E1000_RFCTL_IPV6_DIS; 1751 rfctl |= E1000_RFCTL_IPV6_DIS;
1629 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl); 1752 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1630 1753
1631 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC; 1754 rctl |= E1000_RCTL_DTYP_PS;
1632 1755
1633 psrctl |= adapter->rx_ps_bsize0 >> 1756 psrctl |= adapter->rx_ps_bsize0 >>
1634 E1000_PSRCTL_BSIZE0_SHIFT; 1757 E1000_PSRCTL_BSIZE0_SHIFT;
@@ -1712,13 +1835,13 @@ e1000_configure_rx(struct e1000_adapter *adapter)
1712 case 1: 1835 case 1:
1713 default: 1836 default:
1714 rdba = adapter->rx_ring[0].dma; 1837 rdba = adapter->rx_ring[0].dma;
1715 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1716 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1717 E1000_WRITE_REG(hw, RDLEN, rdlen); 1838 E1000_WRITE_REG(hw, RDLEN, rdlen);
1718 E1000_WRITE_REG(hw, RDH, 0); 1839 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1840 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1719 E1000_WRITE_REG(hw, RDT, 0); 1841 E1000_WRITE_REG(hw, RDT, 0);
1720 adapter->rx_ring[0].rdh = E1000_RDH; 1842 E1000_WRITE_REG(hw, RDH, 0);
1721 adapter->rx_ring[0].rdt = E1000_RDT; 1843 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
1844 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
1722 break; 1845 break;
1723 } 1846 }
1724 1847
@@ -1741,9 +1864,6 @@ e1000_configure_rx(struct e1000_adapter *adapter)
1741 E1000_WRITE_REG(hw, RXCSUM, rxcsum); 1864 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1742 } 1865 }
1743 1866
1744 if (hw->mac_type == e1000_82573)
1745 E1000_WRITE_REG(hw, ERT, 0x0100);
1746
1747 /* Enable Receives */ 1867 /* Enable Receives */
1748 E1000_WRITE_REG(hw, RCTL, rctl); 1868 E1000_WRITE_REG(hw, RCTL, rctl);
1749} 1869}
@@ -2083,6 +2203,12 @@ e1000_set_multi(struct net_device *netdev)
2083 uint32_t rctl; 2203 uint32_t rctl;
2084 uint32_t hash_value; 2204 uint32_t hash_value;
2085 int i, rar_entries = E1000_RAR_ENTRIES; 2205 int i, rar_entries = E1000_RAR_ENTRIES;
2206 int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
2207 E1000_NUM_MTA_REGISTERS_ICH8LAN :
2208 E1000_NUM_MTA_REGISTERS;
2209
2210 if (adapter->hw.mac_type == e1000_ich8lan)
2211 rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
2086 2212
2087 /* reserve RAR[14] for LAA over-write work-around */ 2213 /* reserve RAR[14] for LAA over-write work-around */
2088 if (adapter->hw.mac_type == e1000_82571) 2214 if (adapter->hw.mac_type == e1000_82571)
@@ -2121,14 +2247,18 @@ e1000_set_multi(struct net_device *netdev)
2121 mc_ptr = mc_ptr->next; 2247 mc_ptr = mc_ptr->next;
2122 } else { 2248 } else {
2123 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); 2249 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2250 E1000_WRITE_FLUSH(hw);
2124 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); 2251 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2252 E1000_WRITE_FLUSH(hw);
2125 } 2253 }
2126 } 2254 }
2127 2255
2128 /* clear the old settings from the multicast hash table */ 2256 /* clear the old settings from the multicast hash table */
2129 2257
2130 for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++) 2258 for (i = 0; i < mta_reg_count; i++) {
2131 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); 2259 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2260 E1000_WRITE_FLUSH(hw);
2261 }
2132 2262
2133 /* load any remaining addresses into the hash table */ 2263 /* load any remaining addresses into the hash table */
2134 2264
@@ -2201,19 +2331,19 @@ static void
2201e1000_watchdog(unsigned long data) 2331e1000_watchdog(unsigned long data)
2202{ 2332{
2203 struct e1000_adapter *adapter = (struct e1000_adapter *) data; 2333 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2204
2205 /* Do the rest outside of interrupt context */
2206 schedule_work(&adapter->watchdog_task);
2207}
2208
2209static void
2210e1000_watchdog_task(struct e1000_adapter *adapter)
2211{
2212 struct net_device *netdev = adapter->netdev; 2334 struct net_device *netdev = adapter->netdev;
2213 struct e1000_tx_ring *txdr = adapter->tx_ring; 2335 struct e1000_tx_ring *txdr = adapter->tx_ring;
2214 uint32_t link, tctl; 2336 uint32_t link, tctl;
2215 2337 int32_t ret_val;
2216 e1000_check_for_link(&adapter->hw); 2338
2339 ret_val = e1000_check_for_link(&adapter->hw);
2340 if ((ret_val == E1000_ERR_PHY) &&
2341 (adapter->hw.phy_type == e1000_phy_igp_3) &&
2342 (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
2343 /* See e1000_kumeran_lock_loss_workaround() */
2344 DPRINTK(LINK, INFO,
2345 "Gigabit has been disabled, downgrading speed\n");
2346 }
2217 if (adapter->hw.mac_type == e1000_82573) { 2347 if (adapter->hw.mac_type == e1000_82573) {
2218 e1000_enable_tx_pkt_filtering(&adapter->hw); 2348 e1000_enable_tx_pkt_filtering(&adapter->hw);
2219 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id) 2349 if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
@@ -2394,7 +2524,7 @@ e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2394 uint8_t ipcss, ipcso, tucss, tucso, hdr_len; 2524 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2395 int err; 2525 int err;
2396 2526
2397 if (skb_shinfo(skb)->gso_size) { 2527 if (skb_is_gso(skb)) {
2398 if (skb_header_cloned(skb)) { 2528 if (skb_header_cloned(skb)) {
2399 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); 2529 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2400 if (err) 2530 if (err)
@@ -2519,7 +2649,7 @@ e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2519 * tso gets written back prematurely before the data is fully 2649 * tso gets written back prematurely before the data is fully
2520 * DMA'd to the controller */ 2650 * DMA'd to the controller */
2521 if (!skb->data_len && tx_ring->last_tx_tso && 2651 if (!skb->data_len && tx_ring->last_tx_tso &&
2522 !skb_shinfo(skb)->gso_size) { 2652 !skb_is_gso(skb)) {
2523 tx_ring->last_tx_tso = 0; 2653 tx_ring->last_tx_tso = 0;
2524 size -= 4; 2654 size -= 4;
2525 } 2655 }
@@ -2779,9 +2909,10 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2779 case e1000_82571: 2909 case e1000_82571:
2780 case e1000_82572: 2910 case e1000_82572:
2781 case e1000_82573: 2911 case e1000_82573:
2912 case e1000_ich8lan:
2782 pull_size = min((unsigned int)4, skb->data_len); 2913 pull_size = min((unsigned int)4, skb->data_len);
2783 if (!__pskb_pull_tail(skb, pull_size)) { 2914 if (!__pskb_pull_tail(skb, pull_size)) {
2784 printk(KERN_ERR 2915 DPRINTK(DRV, ERR,
2785 "__pskb_pull_tail failed.\n"); 2916 "__pskb_pull_tail failed.\n");
2786 dev_kfree_skb_any(skb); 2917 dev_kfree_skb_any(skb);
2787 return NETDEV_TX_OK; 2918 return NETDEV_TX_OK;
@@ -2806,8 +2937,7 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2806 2937
2807#ifdef NETIF_F_TSO 2938#ifdef NETIF_F_TSO
2808 /* Controller Erratum workaround */ 2939 /* Controller Erratum workaround */
2809 if (!skb->data_len && tx_ring->last_tx_tso && 2940 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
2810 !skb_shinfo(skb)->gso_size)
2811 count++; 2941 count++;
2812#endif 2942#endif
2813 2943
@@ -2919,8 +3049,7 @@ e1000_reset_task(struct net_device *netdev)
2919{ 3049{
2920 struct e1000_adapter *adapter = netdev_priv(netdev); 3050 struct e1000_adapter *adapter = netdev_priv(netdev);
2921 3051
2922 e1000_down(adapter); 3052 e1000_reinit_locked(adapter);
2923 e1000_up(adapter);
2924} 3053}
2925 3054
2926/** 3055/**
@@ -2964,6 +3093,7 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu)
2964 /* Adapter-specific max frame size limits. */ 3093 /* Adapter-specific max frame size limits. */
2965 switch (adapter->hw.mac_type) { 3094 switch (adapter->hw.mac_type) {
2966 case e1000_undefined ... e1000_82542_rev2_1: 3095 case e1000_undefined ... e1000_82542_rev2_1:
3096 case e1000_ich8lan:
2967 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { 3097 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2968 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); 3098 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
2969 return -EINVAL; 3099 return -EINVAL;
@@ -2997,7 +3127,7 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu)
2997 break; 3127 break;
2998 } 3128 }
2999 3129
3000 /* NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN 3130 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3001 * means we reserve 2 more, this pushes us to allocate from the next 3131 * means we reserve 2 more, this pushes us to allocate from the next
3002 * larger slab size 3132 * larger slab size
3003 * i.e. RXBUFFER_2048 --> size-4096 slab */ 3133 * i.e. RXBUFFER_2048 --> size-4096 slab */
@@ -3018,7 +3148,6 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu)
3018 adapter->rx_buffer_len = E1000_RXBUFFER_16384; 3148 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3019 3149
3020 /* adjust allocation if LPE protects us, and we aren't using SBP */ 3150 /* adjust allocation if LPE protects us, and we aren't using SBP */
3021#define MAXIMUM_ETHERNET_VLAN_SIZE 1522
3022 if (!adapter->hw.tbi_compatibility_on && 3151 if (!adapter->hw.tbi_compatibility_on &&
3023 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) || 3152 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
3024 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))) 3153 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
@@ -3026,10 +3155,8 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu)
3026 3155
3027 netdev->mtu = new_mtu; 3156 netdev->mtu = new_mtu;
3028 3157
3029 if (netif_running(netdev)) { 3158 if (netif_running(netdev))
3030 e1000_down(adapter); 3159 e1000_reinit_locked(adapter);
3031 e1000_up(adapter);
3032 }
3033 3160
3034 adapter->hw.max_frame_size = max_frame; 3161 adapter->hw.max_frame_size = max_frame;
3035 3162
@@ -3074,12 +3201,15 @@ e1000_update_stats(struct e1000_adapter *adapter)
3074 adapter->stats.bprc += E1000_READ_REG(hw, BPRC); 3201 adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3075 adapter->stats.mprc += E1000_READ_REG(hw, MPRC); 3202 adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3076 adapter->stats.roc += E1000_READ_REG(hw, ROC); 3203 adapter->stats.roc += E1000_READ_REG(hw, ROC);
3204
3205 if (adapter->hw.mac_type != e1000_ich8lan) {
3077 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64); 3206 adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3078 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127); 3207 adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3079 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255); 3208 adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3080 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511); 3209 adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3081 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023); 3210 adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3082 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522); 3211 adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3212 }
3083 3213
3084 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS); 3214 adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3085 adapter->stats.mpc += E1000_READ_REG(hw, MPC); 3215 adapter->stats.mpc += E1000_READ_REG(hw, MPC);
@@ -3107,12 +3237,16 @@ e1000_update_stats(struct e1000_adapter *adapter)
3107 adapter->stats.totl += E1000_READ_REG(hw, TOTL); 3237 adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3108 adapter->stats.toth += E1000_READ_REG(hw, TOTH); 3238 adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3109 adapter->stats.tpr += E1000_READ_REG(hw, TPR); 3239 adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3240
3241 if (adapter->hw.mac_type != e1000_ich8lan) {
3110 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64); 3242 adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3111 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127); 3243 adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3112 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255); 3244 adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3113 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511); 3245 adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3114 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023); 3246 adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3115 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522); 3247 adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3248 }
3249
3116 adapter->stats.mptc += E1000_READ_REG(hw, MPTC); 3250 adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3117 adapter->stats.bptc += E1000_READ_REG(hw, BPTC); 3251 adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3118 3252
@@ -3134,6 +3268,8 @@ e1000_update_stats(struct e1000_adapter *adapter)
3134 if (hw->mac_type > e1000_82547_rev_2) { 3268 if (hw->mac_type > e1000_82547_rev_2) {
3135 adapter->stats.iac += E1000_READ_REG(hw, IAC); 3269 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3136 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC); 3270 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3271
3272 if (adapter->hw.mac_type != e1000_ich8lan) {
3137 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC); 3273 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3138 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC); 3274 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3139 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC); 3275 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
@@ -3141,6 +3277,7 @@ e1000_update_stats(struct e1000_adapter *adapter)
3141 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC); 3277 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3142 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC); 3278 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3143 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC); 3279 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3280 }
3144 } 3281 }
3145 3282
3146 /* Fill out the OS statistics structure */ 3283 /* Fill out the OS statistics structure */
@@ -3249,8 +3386,8 @@ e1000_intr(int irq, void *data, struct pt_regs *regs)
3249 E1000_WRITE_REG(hw, IMC, ~0); 3386 E1000_WRITE_REG(hw, IMC, ~0);
3250 E1000_WRITE_FLUSH(hw); 3387 E1000_WRITE_FLUSH(hw);
3251 } 3388 }
3252 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0]))) 3389 if (likely(netif_rx_schedule_prep(netdev)))
3253 __netif_rx_schedule(&adapter->polling_netdev[0]); 3390 __netif_rx_schedule(netdev);
3254 else 3391 else
3255 e1000_irq_enable(adapter); 3392 e1000_irq_enable(adapter);
3256#else 3393#else
@@ -3293,34 +3430,26 @@ e1000_clean(struct net_device *poll_dev, int *budget)
3293{ 3430{
3294 struct e1000_adapter *adapter; 3431 struct e1000_adapter *adapter;
3295 int work_to_do = min(*budget, poll_dev->quota); 3432 int work_to_do = min(*budget, poll_dev->quota);
3296 int tx_cleaned = 0, i = 0, work_done = 0; 3433 int tx_cleaned = 0, work_done = 0;
3297 3434
3298 /* Must NOT use netdev_priv macro here. */ 3435 /* Must NOT use netdev_priv macro here. */
3299 adapter = poll_dev->priv; 3436 adapter = poll_dev->priv;
3300 3437
3301 /* Keep link state information with original netdev */ 3438 /* Keep link state information with original netdev */
3302 if (!netif_carrier_ok(adapter->netdev)) 3439 if (!netif_carrier_ok(poll_dev))
3303 goto quit_polling; 3440 goto quit_polling;
3304 3441
3305 while (poll_dev != &adapter->polling_netdev[i]) { 3442 /* e1000_clean is called per-cpu. This lock protects
3306 i++; 3443 * tx_ring[0] from being cleaned by multiple cpus
3307 BUG_ON(i == adapter->num_rx_queues); 3444 * simultaneously. A failure obtaining the lock means
3445 * tx_ring[0] is currently being cleaned anyway. */
3446 if (spin_trylock(&adapter->tx_queue_lock)) {
3447 tx_cleaned = e1000_clean_tx_irq(adapter,
3448 &adapter->tx_ring[0]);
3449 spin_unlock(&adapter->tx_queue_lock);
3308 } 3450 }
3309 3451
3310 if (likely(adapter->num_tx_queues == 1)) { 3452 adapter->clean_rx(adapter, &adapter->rx_ring[0],
3311 /* e1000_clean is called per-cpu. This lock protects
3312 * tx_ring[0] from being cleaned by multiple cpus
3313 * simultaneously. A failure obtaining the lock means
3314 * tx_ring[0] is currently being cleaned anyway. */
3315 if (spin_trylock(&adapter->tx_queue_lock)) {
3316 tx_cleaned = e1000_clean_tx_irq(adapter,
3317 &adapter->tx_ring[0]);
3318 spin_unlock(&adapter->tx_queue_lock);
3319 }
3320 } else
3321 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3322
3323 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3324 &work_done, work_to_do); 3453 &work_done, work_to_do);
3325 3454
3326 *budget -= work_done; 3455 *budget -= work_done;
@@ -3328,7 +3457,7 @@ e1000_clean(struct net_device *poll_dev, int *budget)
3328 3457
3329 /* If no Tx and not enough Rx work done, exit the polling mode */ 3458 /* If no Tx and not enough Rx work done, exit the polling mode */
3330 if ((!tx_cleaned && (work_done == 0)) || 3459 if ((!tx_cleaned && (work_done == 0)) ||
3331 !netif_running(adapter->netdev)) { 3460 !netif_running(poll_dev)) {
3332quit_polling: 3461quit_polling:
3333 netif_rx_complete(poll_dev); 3462 netif_rx_complete(poll_dev);
3334 e1000_irq_enable(adapter); 3463 e1000_irq_enable(adapter);
@@ -3543,11 +3672,15 @@ e1000_clean_rx_irq(struct e1000_adapter *adapter,
3543 3672
3544 length = le16_to_cpu(rx_desc->length); 3673 length = le16_to_cpu(rx_desc->length);
3545 3674
3675 /* adjust length to remove Ethernet CRC */
3676 length -= 4;
3677
3546 if (unlikely(!(status & E1000_RXD_STAT_EOP))) { 3678 if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
3547 /* All receives must fit into a single buffer */ 3679 /* All receives must fit into a single buffer */
3548 E1000_DBG("%s: Receive packet consumed multiple" 3680 E1000_DBG("%s: Receive packet consumed multiple"
3549 " buffers\n", netdev->name); 3681 " buffers\n", netdev->name);
3550 dev_kfree_skb_irq(skb); 3682 /* recycle */
3683 buffer_info-> skb = skb;
3551 goto next_desc; 3684 goto next_desc;
3552 } 3685 }
3553 3686
@@ -3575,7 +3708,7 @@ e1000_clean_rx_irq(struct e1000_adapter *adapter,
3575#define E1000_CB_LENGTH 256 3708#define E1000_CB_LENGTH 256
3576 if (length < E1000_CB_LENGTH) { 3709 if (length < E1000_CB_LENGTH) {
3577 struct sk_buff *new_skb = 3710 struct sk_buff *new_skb =
3578 dev_alloc_skb(length + NET_IP_ALIGN); 3711 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
3579 if (new_skb) { 3712 if (new_skb) {
3580 skb_reserve(new_skb, NET_IP_ALIGN); 3713 skb_reserve(new_skb, NET_IP_ALIGN);
3581 new_skb->dev = netdev; 3714 new_skb->dev = netdev;
@@ -3675,7 +3808,6 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3675 buffer_info = &rx_ring->buffer_info[i]; 3808 buffer_info = &rx_ring->buffer_info[i];
3676 3809
3677 while (staterr & E1000_RXD_STAT_DD) { 3810 while (staterr & E1000_RXD_STAT_DD) {
3678 buffer_info = &rx_ring->buffer_info[i];
3679 ps_page = &rx_ring->ps_page[i]; 3811 ps_page = &rx_ring->ps_page[i];
3680 ps_page_dma = &rx_ring->ps_page_dma[i]; 3812 ps_page_dma = &rx_ring->ps_page_dma[i];
3681#ifdef CONFIG_E1000_NAPI 3813#ifdef CONFIG_E1000_NAPI
@@ -3747,8 +3879,9 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3747 pci_dma_sync_single_for_device(pdev, 3879 pci_dma_sync_single_for_device(pdev,
3748 ps_page_dma->ps_page_dma[0], 3880 ps_page_dma->ps_page_dma[0],
3749 PAGE_SIZE, PCI_DMA_FROMDEVICE); 3881 PAGE_SIZE, PCI_DMA_FROMDEVICE);
3882 /* remove the CRC */
3883 l1 -= 4;
3750 skb_put(skb, l1); 3884 skb_put(skb, l1);
3751 length += l1;
3752 goto copydone; 3885 goto copydone;
3753 } /* if */ 3886 } /* if */
3754 } 3887 }
@@ -3767,6 +3900,10 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3767 skb->truesize += length; 3900 skb->truesize += length;
3768 } 3901 }
3769 3902
3903 /* strip the ethernet crc, problem is we're using pages now so
3904 * this whole operation can get a little cpu intensive */
3905 pskb_trim(skb, skb->len - 4);
3906
3770copydone: 3907copydone:
3771 e1000_rx_checksum(adapter, staterr, 3908 e1000_rx_checksum(adapter, staterr,
3772 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb); 3909 le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
@@ -3842,7 +3979,7 @@ e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3842 3979
3843 while (cleaned_count--) { 3980 while (cleaned_count--) {
3844 if (!(skb = buffer_info->skb)) 3981 if (!(skb = buffer_info->skb))
3845 skb = dev_alloc_skb(bufsz); 3982 skb = netdev_alloc_skb(netdev, bufsz);
3846 else { 3983 else {
3847 skb_trim(skb, 0); 3984 skb_trim(skb, 0);
3848 goto map_skb; 3985 goto map_skb;
@@ -3860,7 +3997,7 @@ e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3860 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes " 3997 DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3861 "at %p\n", bufsz, skb->data); 3998 "at %p\n", bufsz, skb->data);
3862 /* Try again, without freeing the previous */ 3999 /* Try again, without freeing the previous */
3863 skb = dev_alloc_skb(bufsz); 4000 skb = netdev_alloc_skb(netdev, bufsz);
3864 /* Failed allocation, critical failure */ 4001 /* Failed allocation, critical failure */
3865 if (!skb) { 4002 if (!skb) {
3866 dev_kfree_skb(oldskb); 4003 dev_kfree_skb(oldskb);
@@ -3984,7 +4121,8 @@ e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
3984 rx_desc->read.buffer_addr[j+1] = ~0; 4121 rx_desc->read.buffer_addr[j+1] = ~0;
3985 } 4122 }
3986 4123
3987 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN); 4124 skb = netdev_alloc_skb(netdev,
4125 adapter->rx_ps_bsize0 + NET_IP_ALIGN);
3988 4126
3989 if (unlikely(!skb)) { 4127 if (unlikely(!skb)) {
3990 adapter->alloc_rx_buff_failed++; 4128 adapter->alloc_rx_buff_failed++;
@@ -4180,10 +4318,9 @@ e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4180 return retval; 4318 return retval;
4181 } 4319 }
4182 } 4320 }
4183 if (netif_running(adapter->netdev)) { 4321 if (netif_running(adapter->netdev))
4184 e1000_down(adapter); 4322 e1000_reinit_locked(adapter);
4185 e1000_up(adapter); 4323 else
4186 } else
4187 e1000_reset(adapter); 4324 e1000_reset(adapter);
4188 break; 4325 break;
4189 case M88E1000_PHY_SPEC_CTRL: 4326 case M88E1000_PHY_SPEC_CTRL:
@@ -4200,10 +4337,9 @@ e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4200 case PHY_CTRL: 4337 case PHY_CTRL:
4201 if (mii_reg & MII_CR_POWER_DOWN) 4338 if (mii_reg & MII_CR_POWER_DOWN)
4202 break; 4339 break;
4203 if (netif_running(adapter->netdev)) { 4340 if (netif_running(adapter->netdev))
4204 e1000_down(adapter); 4341 e1000_reinit_locked(adapter);
4205 e1000_up(adapter); 4342 else
4206 } else
4207 e1000_reset(adapter); 4343 e1000_reset(adapter);
4208 break; 4344 break;
4209 } 4345 }
@@ -4250,11 +4386,13 @@ e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4250 pci_write_config_word(adapter->pdev, reg, *value); 4386 pci_write_config_word(adapter->pdev, reg, *value);
4251} 4387}
4252 4388
4389#if 0
4253uint32_t 4390uint32_t
4254e1000_io_read(struct e1000_hw *hw, unsigned long port) 4391e1000_io_read(struct e1000_hw *hw, unsigned long port)
4255{ 4392{
4256 return inl(port); 4393 return inl(port);
4257} 4394}
4395#endif /* 0 */
4258 4396
4259void 4397void
4260e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value) 4398e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
@@ -4277,18 +4415,21 @@ e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4277 ctrl |= E1000_CTRL_VME; 4415 ctrl |= E1000_CTRL_VME;
4278 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); 4416 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4279 4417
4418 if (adapter->hw.mac_type != e1000_ich8lan) {
4280 /* enable VLAN receive filtering */ 4419 /* enable VLAN receive filtering */
4281 rctl = E1000_READ_REG(&adapter->hw, RCTL); 4420 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4282 rctl |= E1000_RCTL_VFE; 4421 rctl |= E1000_RCTL_VFE;
4283 rctl &= ~E1000_RCTL_CFIEN; 4422 rctl &= ~E1000_RCTL_CFIEN;
4284 E1000_WRITE_REG(&adapter->hw, RCTL, rctl); 4423 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4285 e1000_update_mng_vlan(adapter); 4424 e1000_update_mng_vlan(adapter);
4425 }
4286 } else { 4426 } else {
4287 /* disable VLAN tag insert/strip */ 4427 /* disable VLAN tag insert/strip */
4288 ctrl = E1000_READ_REG(&adapter->hw, CTRL); 4428 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4289 ctrl &= ~E1000_CTRL_VME; 4429 ctrl &= ~E1000_CTRL_VME;
4290 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); 4430 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4291 4431
4432 if (adapter->hw.mac_type != e1000_ich8lan) {
4292 /* disable VLAN filtering */ 4433 /* disable VLAN filtering */
4293 rctl = E1000_READ_REG(&adapter->hw, RCTL); 4434 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4294 rctl &= ~E1000_RCTL_VFE; 4435 rctl &= ~E1000_RCTL_VFE;
@@ -4297,6 +4438,7 @@ e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4297 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); 4438 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4298 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; 4439 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4299 } 4440 }
4441 }
4300 } 4442 }
4301 4443
4302 e1000_irq_enable(adapter); 4444 e1000_irq_enable(adapter);
@@ -4458,12 +4600,16 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4458 struct e1000_adapter *adapter = netdev_priv(netdev); 4600 struct e1000_adapter *adapter = netdev_priv(netdev);
4459 uint32_t ctrl, ctrl_ext, rctl, manc, status; 4601 uint32_t ctrl, ctrl_ext, rctl, manc, status;
4460 uint32_t wufc = adapter->wol; 4602 uint32_t wufc = adapter->wol;
4603#ifdef CONFIG_PM
4461 int retval = 0; 4604 int retval = 0;
4605#endif
4462 4606
4463 netif_device_detach(netdev); 4607 netif_device_detach(netdev);
4464 4608
4465 if (netif_running(netdev)) 4609 if (netif_running(netdev)) {
4610 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
4466 e1000_down(adapter); 4611 e1000_down(adapter);
4612 }
4467 4613
4468#ifdef CONFIG_PM 4614#ifdef CONFIG_PM
4469 /* Implement our own version of pci_save_state(pdev) because pci- 4615 /* Implement our own version of pci_save_state(pdev) because pci-
@@ -4521,7 +4667,9 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4521 pci_enable_wake(pdev, PCI_D3cold, 0); 4667 pci_enable_wake(pdev, PCI_D3cold, 0);
4522 } 4668 }
4523 4669
4670 /* FIXME: this code is incorrect for PCI Express */
4524 if (adapter->hw.mac_type >= e1000_82540 && 4671 if (adapter->hw.mac_type >= e1000_82540 &&
4672 adapter->hw.mac_type != e1000_ich8lan &&
4525 adapter->hw.media_type == e1000_media_type_copper) { 4673 adapter->hw.media_type == e1000_media_type_copper) {
4526 manc = E1000_READ_REG(&adapter->hw, MANC); 4674 manc = E1000_READ_REG(&adapter->hw, MANC);
4527 if (manc & E1000_MANC_SMBUS_EN) { 4675 if (manc & E1000_MANC_SMBUS_EN) {
@@ -4532,6 +4680,9 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4532 } 4680 }
4533 } 4681 }
4534 4682
4683 if (adapter->hw.phy_type == e1000_phy_igp_3)
4684 e1000_phy_powerdown_workaround(&adapter->hw);
4685
4535 /* Release control of h/w to f/w. If f/w is AMT enabled, this 4686 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4536 * would have already happened in close and is redundant. */ 4687 * would have already happened in close and is redundant. */
4537 e1000_release_hw_control(adapter); 4688 e1000_release_hw_control(adapter);
@@ -4567,7 +4718,9 @@ e1000_resume(struct pci_dev *pdev)
4567 4718
4568 netif_device_attach(netdev); 4719 netif_device_attach(netdev);
4569 4720
4721 /* FIXME: this code is incorrect for PCI Express */
4570 if (adapter->hw.mac_type >= e1000_82540 && 4722 if (adapter->hw.mac_type >= e1000_82540 &&
4723 adapter->hw.mac_type != e1000_ich8lan &&
4571 adapter->hw.media_type == e1000_media_type_copper) { 4724 adapter->hw.media_type == e1000_media_type_copper) {
4572 manc = E1000_READ_REG(&adapter->hw, MANC); 4725 manc = E1000_READ_REG(&adapter->hw, MANC);
4573 manc &= ~(E1000_MANC_ARP_EN); 4726 manc &= ~(E1000_MANC_ARP_EN);
@@ -4601,6 +4754,7 @@ static void
4601e1000_netpoll(struct net_device *netdev) 4754e1000_netpoll(struct net_device *netdev)
4602{ 4755{
4603 struct e1000_adapter *adapter = netdev_priv(netdev); 4756 struct e1000_adapter *adapter = netdev_priv(netdev);
4757
4604 disable_irq(adapter->pdev->irq); 4758 disable_irq(adapter->pdev->irq);
4605 e1000_intr(adapter->pdev->irq, netdev, NULL); 4759 e1000_intr(adapter->pdev->irq, netdev, NULL);
4606 e1000_clean_tx_irq(adapter, adapter->tx_ring); 4760 e1000_clean_tx_irq(adapter, adapter->tx_ring);
diff --git a/drivers/net/e1000/e1000_osdep.h b/drivers/net/e1000/e1000_osdep.h
index 048d052be29d..2d3e8b06cab0 100644
--- a/drivers/net/e1000/e1000_osdep.h
+++ b/drivers/net/e1000/e1000_osdep.h
@@ -127,4 +127,17 @@ typedef enum {
127 127
128#define E1000_WRITE_FLUSH(a) E1000_READ_REG(a, STATUS) 128#define E1000_WRITE_FLUSH(a) E1000_READ_REG(a, STATUS)
129 129
130#define E1000_WRITE_ICH8_REG(a, reg, value) ( \
131 writel((value), ((a)->flash_address + reg)))
132
133#define E1000_READ_ICH8_REG(a, reg) ( \
134 readl((a)->flash_address + reg))
135
136#define E1000_WRITE_ICH8_REG16(a, reg, value) ( \
137 writew((value), ((a)->flash_address + reg)))
138
139#define E1000_READ_ICH8_REG16(a, reg) ( \
140 readw((a)->flash_address + reg))
141
142
130#endif /* _E1000_OSDEP_H_ */ 143#endif /* _E1000_OSDEP_H_ */
diff --git a/drivers/net/e1000/e1000_param.c b/drivers/net/e1000/e1000_param.c
index e55f8969a0fb..0ef413172c68 100644
--- a/drivers/net/e1000/e1000_param.c
+++ b/drivers/net/e1000/e1000_param.c
@@ -45,6 +45,16 @@
45 */ 45 */
46 46
47#define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET } 47#define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
48/* Module Parameters are always initialized to -1, so that the driver
49 * can tell the difference between no user specified value or the
50 * user asking for the default value.
51 * The true default values are loaded in when e1000_check_options is called.
52 *
53 * This is a GCC extension to ANSI C.
54 * See the item "Labeled Elements in Initializers" in the section
55 * "Extensions to the C Language Family" of the GCC documentation.
56 */
57
48#define E1000_PARAM(X, desc) \ 58#define E1000_PARAM(X, desc) \
49 static int __devinitdata X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \ 59 static int __devinitdata X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
50 static int num_##X = 0; \ 60 static int num_##X = 0; \
@@ -183,6 +193,24 @@ E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
183 193
184E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate"); 194E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
185 195
196/* Enable Smart Power Down of the PHY
197 *
198 * Valid Range: 0, 1
199 *
200 * Default Value: 0 (disabled)
201 */
202
203E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
204
205/* Enable Kumeran Lock Loss workaround
206 *
207 * Valid Range: 0, 1
208 *
209 * Default Value: 1 (enabled)
210 */
211
212E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
213
186#define AUTONEG_ADV_DEFAULT 0x2F 214#define AUTONEG_ADV_DEFAULT 0x2F
187#define AUTONEG_ADV_MASK 0x2F 215#define AUTONEG_ADV_MASK 0x2F
188#define FLOW_CONTROL_DEFAULT FLOW_CONTROL_FULL 216#define FLOW_CONTROL_DEFAULT FLOW_CONTROL_FULL
@@ -296,6 +324,7 @@ e1000_check_options(struct e1000_adapter *adapter)
296 DPRINTK(PROBE, NOTICE, 324 DPRINTK(PROBE, NOTICE,
297 "Warning: no configuration for board #%i\n", bd); 325 "Warning: no configuration for board #%i\n", bd);
298 DPRINTK(PROBE, NOTICE, "Using defaults for all values\n"); 326 DPRINTK(PROBE, NOTICE, "Using defaults for all values\n");
327 bd = E1000_MAX_NIC;
299 } 328 }
300 329
301 { /* Transmit Descriptor Count */ 330 { /* Transmit Descriptor Count */
@@ -313,14 +342,9 @@ e1000_check_options(struct e1000_adapter *adapter)
313 opt.arg.r.max = mac_type < e1000_82544 ? 342 opt.arg.r.max = mac_type < e1000_82544 ?
314 E1000_MAX_TXD : E1000_MAX_82544_TXD; 343 E1000_MAX_TXD : E1000_MAX_82544_TXD;
315 344
316 if (num_TxDescriptors > bd) { 345 tx_ring->count = TxDescriptors[bd];
317 tx_ring->count = TxDescriptors[bd]; 346 e1000_validate_option(&tx_ring->count, &opt, adapter);
318 e1000_validate_option(&tx_ring->count, &opt, adapter); 347 E1000_ROUNDUP(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
319 E1000_ROUNDUP(tx_ring->count,
320 REQ_TX_DESCRIPTOR_MULTIPLE);
321 } else {
322 tx_ring->count = opt.def;
323 }
324 for (i = 0; i < adapter->num_tx_queues; i++) 348 for (i = 0; i < adapter->num_tx_queues; i++)
325 tx_ring[i].count = tx_ring->count; 349 tx_ring[i].count = tx_ring->count;
326 } 350 }
@@ -339,14 +363,9 @@ e1000_check_options(struct e1000_adapter *adapter)
339 opt.arg.r.max = mac_type < e1000_82544 ? E1000_MAX_RXD : 363 opt.arg.r.max = mac_type < e1000_82544 ? E1000_MAX_RXD :
340 E1000_MAX_82544_RXD; 364 E1000_MAX_82544_RXD;
341 365
342 if (num_RxDescriptors > bd) { 366 rx_ring->count = RxDescriptors[bd];
343 rx_ring->count = RxDescriptors[bd]; 367 e1000_validate_option(&rx_ring->count, &opt, adapter);
344 e1000_validate_option(&rx_ring->count, &opt, adapter); 368 E1000_ROUNDUP(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
345 E1000_ROUNDUP(rx_ring->count,
346 REQ_RX_DESCRIPTOR_MULTIPLE);
347 } else {
348 rx_ring->count = opt.def;
349 }
350 for (i = 0; i < adapter->num_rx_queues; i++) 369 for (i = 0; i < adapter->num_rx_queues; i++)
351 rx_ring[i].count = rx_ring->count; 370 rx_ring[i].count = rx_ring->count;
352 } 371 }
@@ -358,13 +377,9 @@ e1000_check_options(struct e1000_adapter *adapter)
358 .def = OPTION_ENABLED 377 .def = OPTION_ENABLED
359 }; 378 };
360 379
361 if (num_XsumRX > bd) { 380 int rx_csum = XsumRX[bd];
362 int rx_csum = XsumRX[bd]; 381 e1000_validate_option(&rx_csum, &opt, adapter);
363 e1000_validate_option(&rx_csum, &opt, adapter); 382 adapter->rx_csum = rx_csum;
364 adapter->rx_csum = rx_csum;
365 } else {
366 adapter->rx_csum = opt.def;
367 }
368 } 383 }
369 { /* Flow Control */ 384 { /* Flow Control */
370 385
@@ -384,13 +399,9 @@ e1000_check_options(struct e1000_adapter *adapter)
384 .p = fc_list }} 399 .p = fc_list }}
385 }; 400 };
386 401
387 if (num_FlowControl > bd) { 402 int fc = FlowControl[bd];
388 int fc = FlowControl[bd]; 403 e1000_validate_option(&fc, &opt, adapter);
389 e1000_validate_option(&fc, &opt, adapter); 404 adapter->hw.fc = adapter->hw.original_fc = fc;
390 adapter->hw.fc = adapter->hw.original_fc = fc;
391 } else {
392 adapter->hw.fc = adapter->hw.original_fc = opt.def;
393 }
394 } 405 }
395 { /* Transmit Interrupt Delay */ 406 { /* Transmit Interrupt Delay */
396 struct e1000_option opt = { 407 struct e1000_option opt = {
@@ -402,13 +413,8 @@ e1000_check_options(struct e1000_adapter *adapter)
402 .max = MAX_TXDELAY }} 413 .max = MAX_TXDELAY }}
403 }; 414 };
404 415
405 if (num_TxIntDelay > bd) { 416 adapter->tx_int_delay = TxIntDelay[bd];
406 adapter->tx_int_delay = TxIntDelay[bd]; 417 e1000_validate_option(&adapter->tx_int_delay, &opt, adapter);
407 e1000_validate_option(&adapter->tx_int_delay, &opt,
408 adapter);
409 } else {
410 adapter->tx_int_delay = opt.def;
411 }
412 } 418 }
413 { /* Transmit Absolute Interrupt Delay */ 419 { /* Transmit Absolute Interrupt Delay */
414 struct e1000_option opt = { 420 struct e1000_option opt = {
@@ -420,13 +426,9 @@ e1000_check_options(struct e1000_adapter *adapter)
420 .max = MAX_TXABSDELAY }} 426 .max = MAX_TXABSDELAY }}
421 }; 427 };
422 428
423 if (num_TxAbsIntDelay > bd) { 429 adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
424 adapter->tx_abs_int_delay = TxAbsIntDelay[bd]; 430 e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
425 e1000_validate_option(&adapter->tx_abs_int_delay, &opt, 431 adapter);
426 adapter);
427 } else {
428 adapter->tx_abs_int_delay = opt.def;
429 }
430 } 432 }
431 { /* Receive Interrupt Delay */ 433 { /* Receive Interrupt Delay */
432 struct e1000_option opt = { 434 struct e1000_option opt = {
@@ -438,13 +440,8 @@ e1000_check_options(struct e1000_adapter *adapter)
438 .max = MAX_RXDELAY }} 440 .max = MAX_RXDELAY }}
439 }; 441 };
440 442
441 if (num_RxIntDelay > bd) { 443 adapter->rx_int_delay = RxIntDelay[bd];
442 adapter->rx_int_delay = RxIntDelay[bd]; 444 e1000_validate_option(&adapter->rx_int_delay, &opt, adapter);
443 e1000_validate_option(&adapter->rx_int_delay, &opt,
444 adapter);
445 } else {
446 adapter->rx_int_delay = opt.def;
447 }
448 } 445 }
449 { /* Receive Absolute Interrupt Delay */ 446 { /* Receive Absolute Interrupt Delay */
450 struct e1000_option opt = { 447 struct e1000_option opt = {
@@ -456,13 +453,9 @@ e1000_check_options(struct e1000_adapter *adapter)
456 .max = MAX_RXABSDELAY }} 453 .max = MAX_RXABSDELAY }}
457 }; 454 };
458 455
459 if (num_RxAbsIntDelay > bd) { 456 adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
460 adapter->rx_abs_int_delay = RxAbsIntDelay[bd]; 457 e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
461 e1000_validate_option(&adapter->rx_abs_int_delay, &opt, 458 adapter);
462 adapter);
463 } else {
464 adapter->rx_abs_int_delay = opt.def;
465 }
466 } 459 }
467 { /* Interrupt Throttling Rate */ 460 { /* Interrupt Throttling Rate */
468 struct e1000_option opt = { 461 struct e1000_option opt = {
@@ -474,26 +467,44 @@ e1000_check_options(struct e1000_adapter *adapter)
474 .max = MAX_ITR }} 467 .max = MAX_ITR }}
475 }; 468 };
476 469
477 if (num_InterruptThrottleRate > bd) { 470 adapter->itr = InterruptThrottleRate[bd];
478 adapter->itr = InterruptThrottleRate[bd]; 471 switch (adapter->itr) {
479 switch (adapter->itr) { 472 case 0:
480 case 0: 473 DPRINTK(PROBE, INFO, "%s turned off\n", opt.name);
481 DPRINTK(PROBE, INFO, "%s turned off\n", 474 break;
482 opt.name); 475 case 1:
483 break; 476 DPRINTK(PROBE, INFO, "%s set to dynamic mode\n",
484 case 1: 477 opt.name);
485 DPRINTK(PROBE, INFO, "%s set to dynamic mode\n", 478 break;
486 opt.name); 479 default:
487 break; 480 e1000_validate_option(&adapter->itr, &opt, adapter);
488 default: 481 break;
489 e1000_validate_option(&adapter->itr, &opt,
490 adapter);
491 break;
492 }
493 } else {
494 adapter->itr = opt.def;
495 } 482 }
496 } 483 }
484 { /* Smart Power Down */
485 struct e1000_option opt = {
486 .type = enable_option,
487 .name = "PHY Smart Power Down",
488 .err = "defaulting to Disabled",
489 .def = OPTION_DISABLED
490 };
491
492 int spd = SmartPowerDownEnable[bd];
493 e1000_validate_option(&spd, &opt, adapter);
494 adapter->smart_power_down = spd;
495 }
496 { /* Kumeran Lock Loss Workaround */
497 struct e1000_option opt = {
498 .type = enable_option,
499 .name = "Kumeran Lock Loss Workaround",
500 .err = "defaulting to Enabled",
501 .def = OPTION_ENABLED
502 };
503
504 int kmrn_lock_loss = KumeranLockLoss[bd];
505 e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
506 adapter->hw.kmrn_lock_loss_workaround_disabled = !kmrn_lock_loss;
507 }
497 508
498 switch (adapter->hw.media_type) { 509 switch (adapter->hw.media_type) {
499 case e1000_media_type_fiber: 510 case e1000_media_type_fiber:
@@ -519,17 +530,18 @@ static void __devinit
519e1000_check_fiber_options(struct e1000_adapter *adapter) 530e1000_check_fiber_options(struct e1000_adapter *adapter)
520{ 531{
521 int bd = adapter->bd_number; 532 int bd = adapter->bd_number;
522 if (num_Speed > bd) { 533 bd = bd > E1000_MAX_NIC ? E1000_MAX_NIC : bd;
534 if ((Speed[bd] != OPTION_UNSET)) {
523 DPRINTK(PROBE, INFO, "Speed not valid for fiber adapters, " 535 DPRINTK(PROBE, INFO, "Speed not valid for fiber adapters, "
524 "parameter ignored\n"); 536 "parameter ignored\n");
525 } 537 }
526 538
527 if (num_Duplex > bd) { 539 if ((Duplex[bd] != OPTION_UNSET)) {
528 DPRINTK(PROBE, INFO, "Duplex not valid for fiber adapters, " 540 DPRINTK(PROBE, INFO, "Duplex not valid for fiber adapters, "
529 "parameter ignored\n"); 541 "parameter ignored\n");
530 } 542 }
531 543
532 if ((num_AutoNeg > bd) && (AutoNeg[bd] != 0x20)) { 544 if ((AutoNeg[bd] != OPTION_UNSET) && (AutoNeg[bd] != 0x20)) {
533 DPRINTK(PROBE, INFO, "AutoNeg other than 1000/Full is " 545 DPRINTK(PROBE, INFO, "AutoNeg other than 1000/Full is "
534 "not valid for fiber adapters, " 546 "not valid for fiber adapters, "
535 "parameter ignored\n"); 547 "parameter ignored\n");
@@ -548,6 +560,7 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
548{ 560{
549 int speed, dplx, an; 561 int speed, dplx, an;
550 int bd = adapter->bd_number; 562 int bd = adapter->bd_number;
563 bd = bd > E1000_MAX_NIC ? E1000_MAX_NIC : bd;
551 564
552 { /* Speed */ 565 { /* Speed */
553 struct e1000_opt_list speed_list[] = {{ 0, "" }, 566 struct e1000_opt_list speed_list[] = {{ 0, "" },
@@ -564,12 +577,8 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
564 .p = speed_list }} 577 .p = speed_list }}
565 }; 578 };
566 579
567 if (num_Speed > bd) { 580 speed = Speed[bd];
568 speed = Speed[bd]; 581 e1000_validate_option(&speed, &opt, adapter);
569 e1000_validate_option(&speed, &opt, adapter);
570 } else {
571 speed = opt.def;
572 }
573 } 582 }
574 { /* Duplex */ 583 { /* Duplex */
575 struct e1000_opt_list dplx_list[] = {{ 0, "" }, 584 struct e1000_opt_list dplx_list[] = {{ 0, "" },
@@ -591,15 +600,11 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
591 "Speed/Duplex/AutoNeg parameter ignored.\n"); 600 "Speed/Duplex/AutoNeg parameter ignored.\n");
592 return; 601 return;
593 } 602 }
594 if (num_Duplex > bd) { 603 dplx = Duplex[bd];
595 dplx = Duplex[bd]; 604 e1000_validate_option(&dplx, &opt, adapter);
596 e1000_validate_option(&dplx, &opt, adapter);
597 } else {
598 dplx = opt.def;
599 }
600 } 605 }
601 606
602 if ((num_AutoNeg > bd) && (speed != 0 || dplx != 0)) { 607 if (AutoNeg[bd] != OPTION_UNSET && (speed != 0 || dplx != 0)) {
603 DPRINTK(PROBE, INFO, 608 DPRINTK(PROBE, INFO,
604 "AutoNeg specified along with Speed or Duplex, " 609 "AutoNeg specified along with Speed or Duplex, "
605 "parameter ignored\n"); 610 "parameter ignored\n");
@@ -648,19 +653,15 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
648 .p = an_list }} 653 .p = an_list }}
649 }; 654 };
650 655
651 if (num_AutoNeg > bd) { 656 an = AutoNeg[bd];
652 an = AutoNeg[bd]; 657 e1000_validate_option(&an, &opt, adapter);
653 e1000_validate_option(&an, &opt, adapter);
654 } else {
655 an = opt.def;
656 }
657 adapter->hw.autoneg_advertised = an; 658 adapter->hw.autoneg_advertised = an;
658 } 659 }
659 660
660 switch (speed + dplx) { 661 switch (speed + dplx) {
661 case 0: 662 case 0:
662 adapter->hw.autoneg = adapter->fc_autoneg = 1; 663 adapter->hw.autoneg = adapter->fc_autoneg = 1;
663 if ((num_Speed > bd) && (speed != 0 || dplx != 0)) 664 if (Speed[bd] != OPTION_UNSET || Duplex[bd] != OPTION_UNSET)
664 DPRINTK(PROBE, INFO, 665 DPRINTK(PROBE, INFO,
665 "Speed and duplex autonegotiation enabled\n"); 666 "Speed and duplex autonegotiation enabled\n");
666 break; 667 break;
diff --git a/drivers/net/e2100.c b/drivers/net/e2100.c
index e5c5cd2a2712..e4e733a380e3 100644
--- a/drivers/net/e2100.c
+++ b/drivers/net/e2100.c
@@ -425,8 +425,8 @@ MODULE_LICENSE("GPL");
425 425
426/* This is set up so that only a single autoprobe takes place per call. 426/* This is set up so that only a single autoprobe takes place per call.
427ISA device autoprobes on a running machine are not recommended. */ 427ISA device autoprobes on a running machine are not recommended. */
428int 428
429init_module(void) 429int __init init_module(void)
430{ 430{
431 struct net_device *dev; 431 struct net_device *dev;
432 int this_dev, found = 0; 432 int this_dev, found = 0;
diff --git a/drivers/net/eepro.c b/drivers/net/eepro.c
index 20d31430c74f..8dc61d65dd23 100644
--- a/drivers/net/eepro.c
+++ b/drivers/net/eepro.c
@@ -1807,8 +1807,7 @@ MODULE_PARM_DESC(irq, "EtherExpress Pro/10 IRQ number(s)");
1807MODULE_PARM_DESC(mem, "EtherExpress Pro/10 Rx buffer size(es) in kB (3-29)"); 1807MODULE_PARM_DESC(mem, "EtherExpress Pro/10 Rx buffer size(es) in kB (3-29)");
1808MODULE_PARM_DESC(autodetect, "EtherExpress Pro/10 force board(s) detection (0-1)"); 1808MODULE_PARM_DESC(autodetect, "EtherExpress Pro/10 force board(s) detection (0-1)");
1809 1809
1810int 1810int __init init_module(void)
1811init_module(void)
1812{ 1811{
1813 struct net_device *dev; 1812 struct net_device *dev;
1814 int i; 1813 int i;
diff --git a/drivers/net/eepro100.c b/drivers/net/eepro100.c
index 2ad327542927..e445988c92ee 100644
--- a/drivers/net/eepro100.c
+++ b/drivers/net/eepro100.c
@@ -555,12 +555,12 @@ static int __devinit eepro100_init_one (struct pci_dev *pdev,
555 555
556 if (!request_region(pci_resource_start(pdev, 1), 556 if (!request_region(pci_resource_start(pdev, 1),
557 pci_resource_len(pdev, 1), "eepro100")) { 557 pci_resource_len(pdev, 1), "eepro100")) {
558 printk (KERN_ERR "eepro100: cannot reserve I/O ports\n"); 558 dev_err(&pdev->dev, "eepro100: cannot reserve I/O ports\n");
559 goto err_out_none; 559 goto err_out_none;
560 } 560 }
561 if (!request_mem_region(pci_resource_start(pdev, 0), 561 if (!request_mem_region(pci_resource_start(pdev, 0),
562 pci_resource_len(pdev, 0), "eepro100")) { 562 pci_resource_len(pdev, 0), "eepro100")) {
563 printk (KERN_ERR "eepro100: cannot reserve MMIO region\n"); 563 dev_err(&pdev->dev, "eepro100: cannot reserve MMIO region\n");
564 goto err_out_free_pio_region; 564 goto err_out_free_pio_region;
565 } 565 }
566 566
@@ -573,7 +573,7 @@ static int __devinit eepro100_init_one (struct pci_dev *pdev,
573 573
574 ioaddr = pci_iomap(pdev, pci_bar, 0); 574 ioaddr = pci_iomap(pdev, pci_bar, 0);
575 if (!ioaddr) { 575 if (!ioaddr) {
576 printk (KERN_ERR "eepro100: cannot remap IO\n"); 576 dev_err(&pdev->dev, "eepro100: cannot remap IO\n");
577 goto err_out_free_mmio_region; 577 goto err_out_free_mmio_region;
578 } 578 }
579 579
diff --git a/drivers/net/eexpress.c b/drivers/net/eexpress.c
index 33291bcf6d4c..0701c1d810ca 100644
--- a/drivers/net/eexpress.c
+++ b/drivers/net/eexpress.c
@@ -1698,7 +1698,7 @@ MODULE_LICENSE("GPL");
1698 * are specified, we verify and then use them. If no parameters are given, we 1698 * are specified, we verify and then use them. If no parameters are given, we
1699 * autoprobe for one card only. 1699 * autoprobe for one card only.
1700 */ 1700 */
1701int init_module(void) 1701int __init init_module(void)
1702{ 1702{
1703 struct net_device *dev; 1703 struct net_device *dev;
1704 int this_dev, found = 0; 1704 int this_dev, found = 0;
diff --git a/drivers/net/epic100.c b/drivers/net/epic100.c
index 9f3e09a3d88c..a67650ccf084 100644
--- a/drivers/net/epic100.c
+++ b/drivers/net/epic100.c
@@ -19,62 +19,15 @@
19 19
20 Information and updates available at 20 Information and updates available at
21 http://www.scyld.com/network/epic100.html 21 http://www.scyld.com/network/epic100.html
22 [this link no longer provides anything useful -jgarzik]
22 23
23 --------------------------------------------------------------------- 24 ---------------------------------------------------------------------
24 25
25 Linux kernel-specific changes:
26
27 LK1.1.2 (jgarzik):
28 * Merge becker version 1.09 (4/08/2000)
29
30 LK1.1.3:
31 * Major bugfix to 1.09 driver (Francis Romieu)
32
33 LK1.1.4 (jgarzik):
34 * Merge becker test version 1.09 (5/29/2000)
35
36 LK1.1.5:
37 * Fix locking (jgarzik)
38 * Limit 83c175 probe to ethernet-class PCI devices (rgooch)
39
40 LK1.1.6:
41 * Merge becker version 1.11
42 * Move pci_enable_device before any PCI BAR len checks
43
44 LK1.1.7:
45 * { fill me in }
46
47 LK1.1.8:
48 * ethtool driver info support (jgarzik)
49
50 LK1.1.9:
51 * ethtool media get/set support (jgarzik)
52
53 LK1.1.10:
54 * revert MII transceiver init change (jgarzik)
55
56 LK1.1.11:
57 * implement ETHTOOL_[GS]SET, _NWAY_RST, _[GS]MSGLVL, _GLINK (jgarzik)
58 * replace some MII-related magic numbers with constants
59
60 LK1.1.12:
61 * fix power-up sequence
62
63 LK1.1.13:
64 * revert version 1.1.12, power-up sequence "fix"
65
66 LK1.1.14 (Kryzsztof Halasa):
67 * fix spurious bad initializations
68 * pound phy a la SMSC's app note on the subject
69
70 AC1.1.14ac
71 * fix power up/down for ethtool that broke in 1.11
72
73*/ 26*/
74 27
75#define DRV_NAME "epic100" 28#define DRV_NAME "epic100"
76#define DRV_VERSION "1.11+LK1.1.14+AC1.1.14" 29#define DRV_VERSION "2.0"
77#define DRV_RELDATE "June 2, 2004" 30#define DRV_RELDATE "June 27, 2006"
78 31
79/* The user-configurable values. 32/* The user-configurable values.
80 These may be modified when a driver module is loaded.*/ 33 These may be modified when a driver module is loaded.*/
@@ -204,19 +157,15 @@ typedef enum {
204 157
205struct epic_chip_info { 158struct epic_chip_info {
206 const char *name; 159 const char *name;
207 int io_size; /* Needed for I/O region check or ioremap(). */
208 int drv_flags; /* Driver use, intended as capability flags. */ 160 int drv_flags; /* Driver use, intended as capability flags. */
209}; 161};
210 162
211 163
212/* indexed by chip_t */ 164/* indexed by chip_t */
213static const struct epic_chip_info pci_id_tbl[] = { 165static const struct epic_chip_info pci_id_tbl[] = {
214 { "SMSC EPIC/100 83c170", 166 { "SMSC EPIC/100 83c170", TYPE2_INTR | NO_MII | MII_PWRDWN },
215 EPIC_TOTAL_SIZE, TYPE2_INTR | NO_MII | MII_PWRDWN }, 167 { "SMSC EPIC/100 83c170", TYPE2_INTR },
216 { "SMSC EPIC/100 83c170", 168 { "SMSC EPIC/C 83c175", TYPE2_INTR | MII_PWRDWN },
217 EPIC_TOTAL_SIZE, TYPE2_INTR },
218 { "SMSC EPIC/C 83c175",
219 EPIC_TOTAL_SIZE, TYPE2_INTR | MII_PWRDWN },
220}; 169};
221 170
222 171
@@ -385,8 +334,8 @@ static int __devinit epic_init_one (struct pci_dev *pdev,
385 goto out; 334 goto out;
386 irq = pdev->irq; 335 irq = pdev->irq;
387 336
388 if (pci_resource_len(pdev, 0) < pci_id_tbl[chip_idx].io_size) { 337 if (pci_resource_len(pdev, 0) < EPIC_TOTAL_SIZE) {
389 printk (KERN_ERR "card %d: no PCI region space\n", card_idx); 338 dev_err(&pdev->dev, "no PCI region space\n");
390 ret = -ENODEV; 339 ret = -ENODEV;
391 goto err_out_disable; 340 goto err_out_disable;
392 } 341 }
@@ -401,7 +350,7 @@ static int __devinit epic_init_one (struct pci_dev *pdev,
401 350
402 dev = alloc_etherdev(sizeof (*ep)); 351 dev = alloc_etherdev(sizeof (*ep));
403 if (!dev) { 352 if (!dev) {
404 printk (KERN_ERR "card %d: no memory for eth device\n", card_idx); 353 dev_err(&pdev->dev, "no memory for eth device\n");
405 goto err_out_free_res; 354 goto err_out_free_res;
406 } 355 }
407 SET_MODULE_OWNER(dev); 356 SET_MODULE_OWNER(dev);
@@ -413,7 +362,7 @@ static int __devinit epic_init_one (struct pci_dev *pdev,
413 ioaddr = pci_resource_start (pdev, 1); 362 ioaddr = pci_resource_start (pdev, 1);
414 ioaddr = (long) ioremap (ioaddr, pci_resource_len (pdev, 1)); 363 ioaddr = (long) ioremap (ioaddr, pci_resource_len (pdev, 1));
415 if (!ioaddr) { 364 if (!ioaddr) {
416 printk (KERN_ERR DRV_NAME " %d: ioremap failed\n", card_idx); 365 dev_err(&pdev->dev, "ioremap failed\n");
417 goto err_out_free_netdev; 366 goto err_out_free_netdev;
418 } 367 }
419#endif 368#endif
@@ -473,8 +422,7 @@ static int __devinit epic_init_one (struct pci_dev *pdev,
473 ((u16 *)dev->dev_addr)[i] = le16_to_cpu(inw(ioaddr + LAN0 + i*4)); 422 ((u16 *)dev->dev_addr)[i] = le16_to_cpu(inw(ioaddr + LAN0 + i*4));
474 423
475 if (debug > 2) { 424 if (debug > 2) {
476 printk(KERN_DEBUG DRV_NAME "(%s): EEPROM contents\n", 425 dev_printk(KERN_DEBUG, &pdev->dev, "EEPROM contents:\n");
477 pci_name(pdev));
478 for (i = 0; i < 64; i++) 426 for (i = 0; i < 64; i++)
479 printk(" %4.4x%s", read_eeprom(ioaddr, i), 427 printk(" %4.4x%s", read_eeprom(ioaddr, i),
480 i % 16 == 15 ? "\n" : ""); 428 i % 16 == 15 ? "\n" : "");
@@ -496,21 +444,23 @@ static int __devinit epic_init_one (struct pci_dev *pdev,
496 int mii_status = mdio_read(dev, phy, MII_BMSR); 444 int mii_status = mdio_read(dev, phy, MII_BMSR);
497 if (mii_status != 0xffff && mii_status != 0x0000) { 445 if (mii_status != 0xffff && mii_status != 0x0000) {
498 ep->phys[phy_idx++] = phy; 446 ep->phys[phy_idx++] = phy;
499 printk(KERN_INFO DRV_NAME "(%s): MII transceiver #%d control " 447 dev_info(&pdev->dev,
500 "%4.4x status %4.4x.\n", 448 "MII transceiver #%d control "
501 pci_name(pdev), phy, mdio_read(dev, phy, 0), mii_status); 449 "%4.4x status %4.4x.\n",
450 phy, mdio_read(dev, phy, 0), mii_status);
502 } 451 }
503 } 452 }
504 ep->mii_phy_cnt = phy_idx; 453 ep->mii_phy_cnt = phy_idx;
505 if (phy_idx != 0) { 454 if (phy_idx != 0) {
506 phy = ep->phys[0]; 455 phy = ep->phys[0];
507 ep->mii.advertising = mdio_read(dev, phy, MII_ADVERTISE); 456 ep->mii.advertising = mdio_read(dev, phy, MII_ADVERTISE);
508 printk(KERN_INFO DRV_NAME "(%s): Autonegotiation advertising %4.4x link " 457 dev_info(&pdev->dev,
458 "Autonegotiation advertising %4.4x link "
509 "partner %4.4x.\n", 459 "partner %4.4x.\n",
510 pci_name(pdev), ep->mii.advertising, mdio_read(dev, phy, 5)); 460 ep->mii.advertising, mdio_read(dev, phy, 5));
511 } else if ( ! (ep->chip_flags & NO_MII)) { 461 } else if ( ! (ep->chip_flags & NO_MII)) {
512 printk(KERN_WARNING DRV_NAME "(%s): ***WARNING***: No MII transceiver found!\n", 462 dev_warn(&pdev->dev,
513 pci_name(pdev)); 463 "***WARNING***: No MII transceiver found!\n");
514 /* Use the known PHY address of the EPII. */ 464 /* Use the known PHY address of the EPII. */
515 ep->phys[0] = 3; 465 ep->phys[0] = 3;
516 } 466 }
@@ -525,8 +475,7 @@ static int __devinit epic_init_one (struct pci_dev *pdev,
525 /* The lower four bits are the media type. */ 475 /* The lower four bits are the media type. */
526 if (duplex) { 476 if (duplex) {
527 ep->mii.force_media = ep->mii.full_duplex = 1; 477 ep->mii.force_media = ep->mii.full_duplex = 1;
528 printk(KERN_INFO DRV_NAME "(%s): Forced full duplex operation requested.\n", 478 dev_info(&pdev->dev, "Forced full duplex requested.\n");
529 pci_name(pdev));
530 } 479 }
531 dev->if_port = ep->default_port = option; 480 dev->if_port = ep->default_port = option;
532 481
diff --git a/drivers/net/es3210.c b/drivers/net/es3210.c
index 6b0ab1eac3fb..fd7b32a24ea4 100644
--- a/drivers/net/es3210.c
+++ b/drivers/net/es3210.c
@@ -421,8 +421,7 @@ MODULE_PARM_DESC(mem, "memory base address(es)");
421MODULE_DESCRIPTION("Racal-Interlan ES3210 EISA ethernet driver"); 421MODULE_DESCRIPTION("Racal-Interlan ES3210 EISA ethernet driver");
422MODULE_LICENSE("GPL"); 422MODULE_LICENSE("GPL");
423 423
424int 424int __init init_module(void)
425init_module(void)
426{ 425{
427 struct net_device *dev; 426 struct net_device *dev;
428 int this_dev, found = 0; 427 int this_dev, found = 0;
diff --git a/drivers/net/eth16i.c b/drivers/net/eth16i.c
index 4bf76f86d8e9..ca42efa9143c 100644
--- a/drivers/net/eth16i.c
+++ b/drivers/net/eth16i.c
@@ -1434,7 +1434,7 @@ MODULE_PARM_DESC(mediatype, "eth16i media type of interface(s) (bnc,tp,dix,auto,
1434module_param(debug, int, 0); 1434module_param(debug, int, 0);
1435MODULE_PARM_DESC(debug, "eth16i debug level (0-6)"); 1435MODULE_PARM_DESC(debug, "eth16i debug level (0-6)");
1436 1436
1437int init_module(void) 1437int __init init_module(void)
1438{ 1438{
1439 int this_dev, found = 0; 1439 int this_dev, found = 0;
1440 struct net_device *dev; 1440 struct net_device *dev;
diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
index c701951dcd6f..567e27413cfd 100644
--- a/drivers/net/fealnx.c
+++ b/drivers/net/fealnx.c
@@ -92,7 +92,7 @@ static int full_duplex[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1 };
92#include <asm/uaccess.h> 92#include <asm/uaccess.h>
93 93
94/* These identify the driver base version and may not be removed. */ 94/* These identify the driver base version and may not be removed. */
95static char version[] __devinitdata = 95static char version[] =
96KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE "\n"; 96KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE "\n";
97 97
98 98
@@ -124,7 +124,9 @@ MODULE_PARM_DESC(multicast_filter_limit, "fealnx maximum number of filtered mult
124MODULE_PARM_DESC(options, "fealnx: Bits 0-3: media type, bit 17: full duplex"); 124MODULE_PARM_DESC(options, "fealnx: Bits 0-3: media type, bit 17: full duplex");
125MODULE_PARM_DESC(full_duplex, "fealnx full duplex setting(s) (1)"); 125MODULE_PARM_DESC(full_duplex, "fealnx full duplex setting(s) (1)");
126 126
127#define MIN_REGION_SIZE 136 127enum {
128 MIN_REGION_SIZE = 136,
129};
128 130
129/* A chip capabilities table, matching the entries in pci_tbl[] above. */ 131/* A chip capabilities table, matching the entries in pci_tbl[] above. */
130enum chip_capability_flags { 132enum chip_capability_flags {
@@ -146,14 +148,13 @@ enum phy_type_flags {
146 148
147struct chip_info { 149struct chip_info {
148 char *chip_name; 150 char *chip_name;
149 int io_size;
150 int flags; 151 int flags;
151}; 152};
152 153
153static const struct chip_info skel_netdrv_tbl[] = { 154static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
154 {"100/10M Ethernet PCI Adapter", 136, HAS_MII_XCVR}, 155 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
155 {"100/10M Ethernet PCI Adapter", 136, HAS_CHIP_XCVR}, 156 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
156 {"1000/100/10M Ethernet PCI Adapter", 136, HAS_MII_XCVR}, 157 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
157}; 158};
158 159
159/* Offsets to the Command and Status Registers. */ 160/* Offsets to the Command and Status Registers. */
@@ -504,13 +505,14 @@ static int __devinit fealnx_init_one(struct pci_dev *pdev,
504 505
505 len = pci_resource_len(pdev, bar); 506 len = pci_resource_len(pdev, bar);
506 if (len < MIN_REGION_SIZE) { 507 if (len < MIN_REGION_SIZE) {
507 printk(KERN_ERR "%s: region size %ld too small, aborting\n", 508 dev_err(&pdev->dev,
508 boardname, len); 509 "region size %ld too small, aborting\n", len);
509 return -ENODEV; 510 return -ENODEV;
510 } 511 }
511 512
512 i = pci_request_regions(pdev, boardname); 513 i = pci_request_regions(pdev, boardname);
513 if (i) return i; 514 if (i)
515 return i;
514 516
515 irq = pdev->irq; 517 irq = pdev->irq;
516 518
@@ -576,9 +578,9 @@ static int __devinit fealnx_init_one(struct pci_dev *pdev,
576 578
577 if (mii_status != 0xffff && mii_status != 0x0000) { 579 if (mii_status != 0xffff && mii_status != 0x0000) {
578 np->phys[phy_idx++] = phy; 580 np->phys[phy_idx++] = phy;
579 printk(KERN_INFO 581 dev_info(&pdev->dev,
580 "%s: MII PHY found at address %d, status " 582 "MII PHY found at address %d, status "
581 "0x%4.4x.\n", dev->name, phy, mii_status); 583 "0x%4.4x.\n", phy, mii_status);
582 /* get phy type */ 584 /* get phy type */
583 { 585 {
584 unsigned int data; 586 unsigned int data;
@@ -601,10 +603,10 @@ static int __devinit fealnx_init_one(struct pci_dev *pdev,
601 } 603 }
602 604
603 np->mii_cnt = phy_idx; 605 np->mii_cnt = phy_idx;
604 if (phy_idx == 0) { 606 if (phy_idx == 0)
605 printk(KERN_WARNING "%s: MII PHY not found -- this device may " 607 dev_warn(&pdev->dev,
606 "not operate correctly.\n", dev->name); 608 "MII PHY not found -- this device may "
607 } 609 "not operate correctly.\n");
608 } else { 610 } else {
609 np->phys[0] = 32; 611 np->phys[0] = 32;
610/* 89/6/23 add, (begin) */ 612/* 89/6/23 add, (begin) */
@@ -630,7 +632,7 @@ static int __devinit fealnx_init_one(struct pci_dev *pdev,
630 np->mii.full_duplex = full_duplex[card_idx]; 632 np->mii.full_duplex = full_duplex[card_idx];
631 633
632 if (np->mii.full_duplex) { 634 if (np->mii.full_duplex) {
633 printk(KERN_INFO "%s: Media type forced to Full Duplex.\n", dev->name); 635 dev_info(&pdev->dev, "Media type forced to Full Duplex.\n");
634/* 89/6/13 add, (begin) */ 636/* 89/6/13 add, (begin) */
635// if (np->PHYType==MarvellPHY) 637// if (np->PHYType==MarvellPHY)
636 if ((np->PHYType == MarvellPHY) || (np->PHYType == LevelOnePHY)) { 638 if ((np->PHYType == MarvellPHY) || (np->PHYType == LevelOnePHY)) {
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index 3c90003f4230..11b8f1b43dd5 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -240,10 +240,12 @@ enum {
240#define NVREG_RNDSEED_FORCE2 0x2d00 240#define NVREG_RNDSEED_FORCE2 0x2d00
241#define NVREG_RNDSEED_FORCE3 0x7400 241#define NVREG_RNDSEED_FORCE3 0x7400
242 242
243 NvRegUnknownSetupReg1 = 0xA0, 243 NvRegTxDeferral = 0xA0,
244#define NVREG_UNKSETUP1_VAL 0x16070f 244#define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
245 NvRegUnknownSetupReg2 = 0xA4, 245#define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f
246#define NVREG_UNKSETUP2_VAL 0x16 246#define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f
247 NvRegRxDeferral = 0xA4,
248#define NVREG_RX_DEFERRAL_DEFAULT 0x16
247 NvRegMacAddrA = 0xA8, 249 NvRegMacAddrA = 0xA8,
248 NvRegMacAddrB = 0xAC, 250 NvRegMacAddrB = 0xAC,
249 NvRegMulticastAddrA = 0xB0, 251 NvRegMulticastAddrA = 0xB0,
@@ -269,8 +271,10 @@ enum {
269#define NVREG_LINKSPEED_MASK (0xFFF) 271#define NVREG_LINKSPEED_MASK (0xFFF)
270 NvRegUnknownSetupReg5 = 0x130, 272 NvRegUnknownSetupReg5 = 0x130,
271#define NVREG_UNKSETUP5_BIT31 (1<<31) 273#define NVREG_UNKSETUP5_BIT31 (1<<31)
272 NvRegUnknownSetupReg3 = 0x13c, 274 NvRegTxWatermark = 0x13c,
273#define NVREG_UNKSETUP3_VAL1 0x200010 275#define NVREG_TX_WM_DESC1_DEFAULT 0x0200010
276#define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000
277#define NVREG_TX_WM_DESC2_3_1000 0xfe08000
274 NvRegTxRxControl = 0x144, 278 NvRegTxRxControl = 0x144,
275#define NVREG_TXRXCTL_KICK 0x0001 279#define NVREG_TXRXCTL_KICK 0x0001
276#define NVREG_TXRXCTL_BIT1 0x0002 280#define NVREG_TXRXCTL_BIT1 0x0002
@@ -658,7 +662,7 @@ static const struct register_test nv_registers_test[] = {
658 { NvRegMisc1, 0x03c }, 662 { NvRegMisc1, 0x03c },
659 { NvRegOffloadConfig, 0x03ff }, 663 { NvRegOffloadConfig, 0x03ff },
660 { NvRegMulticastAddrA, 0xffffffff }, 664 { NvRegMulticastAddrA, 0xffffffff },
661 { NvRegUnknownSetupReg3, 0x0ff }, 665 { NvRegTxWatermark, 0x0ff },
662 { NvRegWakeUpFlags, 0x07777 }, 666 { NvRegWakeUpFlags, 0x07777 },
663 { 0,0 } 667 { 0,0 }
664}; 668};
@@ -1495,7 +1499,7 @@ static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
1495 np->tx_skbuff[nr] = skb; 1499 np->tx_skbuff[nr] = skb;
1496 1500
1497#ifdef NETIF_F_TSO 1501#ifdef NETIF_F_TSO
1498 if (skb_shinfo(skb)->gso_size) 1502 if (skb_is_gso(skb))
1499 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT); 1503 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
1500 else 1504 else
1501#endif 1505#endif
@@ -2127,7 +2131,7 @@ static int nv_update_linkspeed(struct net_device *dev)
2127 int newdup = np->duplex; 2131 int newdup = np->duplex;
2128 int mii_status; 2132 int mii_status;
2129 int retval = 0; 2133 int retval = 0;
2130 u32 control_1000, status_1000, phyreg, pause_flags; 2134 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
2131 2135
2132 /* BMSR_LSTATUS is latched, read it twice: 2136 /* BMSR_LSTATUS is latched, read it twice:
2133 * we want the current value. 2137 * we want the current value.
@@ -2245,6 +2249,26 @@ set_speed:
2245 phyreg |= PHY_1000; 2249 phyreg |= PHY_1000;
2246 writel(phyreg, base + NvRegPhyInterface); 2250 writel(phyreg, base + NvRegPhyInterface);
2247 2251
2252 if (phyreg & PHY_RGMII) {
2253 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2254 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
2255 else
2256 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
2257 } else {
2258 txreg = NVREG_TX_DEFERRAL_DEFAULT;
2259 }
2260 writel(txreg, base + NvRegTxDeferral);
2261
2262 if (np->desc_ver == DESC_VER_1) {
2263 txreg = NVREG_TX_WM_DESC1_DEFAULT;
2264 } else {
2265 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2266 txreg = NVREG_TX_WM_DESC2_3_1000;
2267 else
2268 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
2269 }
2270 writel(txreg, base + NvRegTxWatermark);
2271
2248 writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD), 2272 writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD),
2249 base + NvRegMisc1); 2273 base + NvRegMisc1);
2250 pci_push(base); 2274 pci_push(base);
@@ -2735,21 +2759,21 @@ static void nv_do_nic_poll(unsigned long data)
2735 2759
2736 if (!using_multi_irqs(dev)) { 2760 if (!using_multi_irqs(dev)) {
2737 if (np->msi_flags & NV_MSI_X_ENABLED) 2761 if (np->msi_flags & NV_MSI_X_ENABLED)
2738 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector); 2762 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
2739 else 2763 else
2740 disable_irq(dev->irq); 2764 disable_irq_lockdep(dev->irq);
2741 mask = np->irqmask; 2765 mask = np->irqmask;
2742 } else { 2766 } else {
2743 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) { 2767 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
2744 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector); 2768 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
2745 mask |= NVREG_IRQ_RX_ALL; 2769 mask |= NVREG_IRQ_RX_ALL;
2746 } 2770 }
2747 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) { 2771 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
2748 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector); 2772 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
2749 mask |= NVREG_IRQ_TX_ALL; 2773 mask |= NVREG_IRQ_TX_ALL;
2750 } 2774 }
2751 if (np->nic_poll_irq & NVREG_IRQ_OTHER) { 2775 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
2752 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector); 2776 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
2753 mask |= NVREG_IRQ_OTHER; 2777 mask |= NVREG_IRQ_OTHER;
2754 } 2778 }
2755 } 2779 }
@@ -2761,23 +2785,23 @@ static void nv_do_nic_poll(unsigned long data)
2761 pci_push(base); 2785 pci_push(base);
2762 2786
2763 if (!using_multi_irqs(dev)) { 2787 if (!using_multi_irqs(dev)) {
2764 nv_nic_irq((int) 0, (void *) data, (struct pt_regs *) NULL); 2788 nv_nic_irq(0, dev, NULL);
2765 if (np->msi_flags & NV_MSI_X_ENABLED) 2789 if (np->msi_flags & NV_MSI_X_ENABLED)
2766 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector); 2790 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
2767 else 2791 else
2768 enable_irq(dev->irq); 2792 enable_irq_lockdep(dev->irq);
2769 } else { 2793 } else {
2770 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) { 2794 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
2771 nv_nic_irq_rx((int) 0, (void *) data, (struct pt_regs *) NULL); 2795 nv_nic_irq_rx(0, dev, NULL);
2772 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector); 2796 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
2773 } 2797 }
2774 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) { 2798 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
2775 nv_nic_irq_tx((int) 0, (void *) data, (struct pt_regs *) NULL); 2799 nv_nic_irq_tx(0, dev, NULL);
2776 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector); 2800 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
2777 } 2801 }
2778 if (np->nic_poll_irq & NVREG_IRQ_OTHER) { 2802 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
2779 nv_nic_irq_other((int) 0, (void *) data, (struct pt_regs *) NULL); 2803 nv_nic_irq_other(0, dev, NULL);
2780 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector); 2804 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
2781 } 2805 }
2782 } 2806 }
2783} 2807}
@@ -3910,7 +3934,10 @@ static int nv_open(struct net_device *dev)
3910 3934
3911 /* 5) continue setup */ 3935 /* 5) continue setup */
3912 writel(np->linkspeed, base + NvRegLinkSpeed); 3936 writel(np->linkspeed, base + NvRegLinkSpeed);
3913 writel(NVREG_UNKSETUP3_VAL1, base + NvRegUnknownSetupReg3); 3937 if (np->desc_ver == DESC_VER_1)
3938 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
3939 else
3940 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
3914 writel(np->txrxctl_bits, base + NvRegTxRxControl); 3941 writel(np->txrxctl_bits, base + NvRegTxRxControl);
3915 writel(np->vlanctl_bits, base + NvRegVlanControl); 3942 writel(np->vlanctl_bits, base + NvRegVlanControl);
3916 pci_push(base); 3943 pci_push(base);
@@ -3932,8 +3959,8 @@ static int nv_open(struct net_device *dev)
3932 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus); 3959 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
3933 get_random_bytes(&i, sizeof(i)); 3960 get_random_bytes(&i, sizeof(i));
3934 writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed); 3961 writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed);
3935 writel(NVREG_UNKSETUP1_VAL, base + NvRegUnknownSetupReg1); 3962 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
3936 writel(NVREG_UNKSETUP2_VAL, base + NvRegUnknownSetupReg2); 3963 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
3937 if (poll_interval == -1) { 3964 if (poll_interval == -1) {
3938 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) 3965 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
3939 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval); 3966 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
diff --git a/drivers/net/fs_enet/Makefile b/drivers/net/fs_enet/Makefile
index d6dd3f2fb43e..02d4dc18ba69 100644
--- a/drivers/net/fs_enet/Makefile
+++ b/drivers/net/fs_enet/Makefile
@@ -4,7 +4,7 @@
4 4
5obj-$(CONFIG_FS_ENET) += fs_enet.o 5obj-$(CONFIG_FS_ENET) += fs_enet.o
6 6
7obj-$(CONFIG_8xx) += mac-fec.o mac-scc.o 7obj-$(CONFIG_8xx) += mac-fec.o mac-scc.o mii-fec.o
8obj-$(CONFIG_8260) += mac-fcc.o 8obj-$(CONFIG_CPM2) += mac-fcc.o mii-bitbang.o
9 9
10fs_enet-objs := fs_enet-main.o fs_enet-mii.o mii-bitbang.o mii-fixed.o 10fs_enet-objs := fs_enet-main.o
diff --git a/drivers/net/fs_enet/fec.h b/drivers/net/fs_enet/fec.h
new file mode 100644
index 000000000000..e980527e2b99
--- /dev/null
+++ b/drivers/net/fs_enet/fec.h
@@ -0,0 +1,42 @@
1#ifndef FS_ENET_FEC_H
2#define FS_ENET_FEC_H
3
4/* CRC polynomium used by the FEC for the multicast group filtering */
5#define FEC_CRC_POLY 0x04C11DB7
6
7#define FEC_MAX_MULTICAST_ADDRS 64
8
9/* Interrupt events/masks.
10*/
11#define FEC_ENET_HBERR 0x80000000U /* Heartbeat error */
12#define FEC_ENET_BABR 0x40000000U /* Babbling receiver */
13#define FEC_ENET_BABT 0x20000000U /* Babbling transmitter */
14#define FEC_ENET_GRA 0x10000000U /* Graceful stop complete */
15#define FEC_ENET_TXF 0x08000000U /* Full frame transmitted */
16#define FEC_ENET_TXB 0x04000000U /* A buffer was transmitted */
17#define FEC_ENET_RXF 0x02000000U /* Full frame received */
18#define FEC_ENET_RXB 0x01000000U /* A buffer was received */
19#define FEC_ENET_MII 0x00800000U /* MII interrupt */
20#define FEC_ENET_EBERR 0x00400000U /* SDMA bus error */
21
22#define FEC_ECNTRL_PINMUX 0x00000004
23#define FEC_ECNTRL_ETHER_EN 0x00000002
24#define FEC_ECNTRL_RESET 0x00000001
25
26#define FEC_RCNTRL_BC_REJ 0x00000010
27#define FEC_RCNTRL_PROM 0x00000008
28#define FEC_RCNTRL_MII_MODE 0x00000004
29#define FEC_RCNTRL_DRT 0x00000002
30#define FEC_RCNTRL_LOOP 0x00000001
31
32#define FEC_TCNTRL_FDEN 0x00000004
33#define FEC_TCNTRL_HBC 0x00000002
34#define FEC_TCNTRL_GTS 0x00000001
35
36
37
38/*
39 * Delay to wait for FEC reset command to complete (in us)
40 */
41#define FEC_RESET_DELAY 50
42#endif
diff --git a/drivers/net/fs_enet/fs_enet-main.c b/drivers/net/fs_enet/fs_enet-main.c
index f6abff5846b3..df62506a1787 100644
--- a/drivers/net/fs_enet/fs_enet-main.c
+++ b/drivers/net/fs_enet/fs_enet-main.c
@@ -37,6 +37,7 @@
37#include <linux/bitops.h> 37#include <linux/bitops.h>
38#include <linux/fs.h> 38#include <linux/fs.h>
39#include <linux/platform_device.h> 39#include <linux/platform_device.h>
40#include <linux/phy.h>
40 41
41#include <linux/vmalloc.h> 42#include <linux/vmalloc.h>
42#include <asm/pgtable.h> 43#include <asm/pgtable.h>
@@ -682,35 +683,6 @@ static void fs_free_irq(struct net_device *dev, int irq)
682 (*fep->ops->post_free_irq)(dev, irq); 683 (*fep->ops->post_free_irq)(dev, irq);
683} 684}
684 685
685/**********************************************************************************/
686
687/* This interrupt occurs when the PHY detects a link change. */
688static irqreturn_t
689fs_mii_link_interrupt(int irq, void *dev_id, struct pt_regs *regs)
690{
691 struct net_device *dev = dev_id;
692 struct fs_enet_private *fep;
693 const struct fs_platform_info *fpi;
694
695 fep = netdev_priv(dev);
696 fpi = fep->fpi;
697
698 /*
699 * Acknowledge the interrupt if possible. If we have not
700 * found the PHY yet we can't process or acknowledge the
701 * interrupt now. Instead we ignore this interrupt for now,
702 * which we can do since it is edge triggered. It will be
703 * acknowledged later by fs_enet_open().
704 */
705 if (!fep->phy)
706 return IRQ_NONE;
707
708 fs_mii_ack_int(dev);
709 fs_mii_link_status_change_check(dev, 0);
710
711 return IRQ_HANDLED;
712}
713
714static void fs_timeout(struct net_device *dev) 686static void fs_timeout(struct net_device *dev)
715{ 687{
716 struct fs_enet_private *fep = netdev_priv(dev); 688 struct fs_enet_private *fep = netdev_priv(dev);
@@ -722,10 +694,13 @@ static void fs_timeout(struct net_device *dev)
722 spin_lock_irqsave(&fep->lock, flags); 694 spin_lock_irqsave(&fep->lock, flags);
723 695
724 if (dev->flags & IFF_UP) { 696 if (dev->flags & IFF_UP) {
697 phy_stop(fep->phydev);
725 (*fep->ops->stop)(dev); 698 (*fep->ops->stop)(dev);
726 (*fep->ops->restart)(dev); 699 (*fep->ops->restart)(dev);
700 phy_start(fep->phydev);
727 } 701 }
728 702
703 phy_start(fep->phydev);
729 wake = fep->tx_free && !(CBDR_SC(fep->cur_tx) & BD_ENET_TX_READY); 704 wake = fep->tx_free && !(CBDR_SC(fep->cur_tx) & BD_ENET_TX_READY);
730 spin_unlock_irqrestore(&fep->lock, flags); 705 spin_unlock_irqrestore(&fep->lock, flags);
731 706
@@ -733,35 +708,112 @@ static void fs_timeout(struct net_device *dev)
733 netif_wake_queue(dev); 708 netif_wake_queue(dev);
734} 709}
735 710
711/*-----------------------------------------------------------------------------
712 * generic link-change handler - should be sufficient for most cases
713 *-----------------------------------------------------------------------------*/
714static void generic_adjust_link(struct net_device *dev)
715{
716 struct fs_enet_private *fep = netdev_priv(dev);
717 struct phy_device *phydev = fep->phydev;
718 int new_state = 0;
719
720 if (phydev->link) {
721
722 /* adjust to duplex mode */
723 if (phydev->duplex != fep->oldduplex){
724 new_state = 1;
725 fep->oldduplex = phydev->duplex;
726 }
727
728 if (phydev->speed != fep->oldspeed) {
729 new_state = 1;
730 fep->oldspeed = phydev->speed;
731 }
732
733 if (!fep->oldlink) {
734 new_state = 1;
735 fep->oldlink = 1;
736 netif_schedule(dev);
737 netif_carrier_on(dev);
738 netif_start_queue(dev);
739 }
740
741 if (new_state)
742 fep->ops->restart(dev);
743
744 } else if (fep->oldlink) {
745 new_state = 1;
746 fep->oldlink = 0;
747 fep->oldspeed = 0;
748 fep->oldduplex = -1;
749 netif_carrier_off(dev);
750 netif_stop_queue(dev);
751 }
752
753 if (new_state && netif_msg_link(fep))
754 phy_print_status(phydev);
755}
756
757
758static void fs_adjust_link(struct net_device *dev)
759{
760 struct fs_enet_private *fep = netdev_priv(dev);
761 unsigned long flags;
762
763 spin_lock_irqsave(&fep->lock, flags);
764
765 if(fep->ops->adjust_link)
766 fep->ops->adjust_link(dev);
767 else
768 generic_adjust_link(dev);
769
770 spin_unlock_irqrestore(&fep->lock, flags);
771}
772
773static int fs_init_phy(struct net_device *dev)
774{
775 struct fs_enet_private *fep = netdev_priv(dev);
776 struct phy_device *phydev;
777
778 fep->oldlink = 0;
779 fep->oldspeed = 0;
780 fep->oldduplex = -1;
781 if(fep->fpi->bus_id)
782 phydev = phy_connect(dev, fep->fpi->bus_id, &fs_adjust_link, 0);
783 else {
784 printk("No phy bus ID specified in BSP code\n");
785 return -EINVAL;
786 }
787 if (IS_ERR(phydev)) {
788 printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
789 return PTR_ERR(phydev);
790 }
791
792 fep->phydev = phydev;
793
794 return 0;
795}
796
797
736static int fs_enet_open(struct net_device *dev) 798static int fs_enet_open(struct net_device *dev)
737{ 799{
738 struct fs_enet_private *fep = netdev_priv(dev); 800 struct fs_enet_private *fep = netdev_priv(dev);
739 const struct fs_platform_info *fpi = fep->fpi;
740 int r; 801 int r;
802 int err;
741 803
742 /* Install our interrupt handler. */ 804 /* Install our interrupt handler. */
743 r = fs_request_irq(dev, fep->interrupt, "fs_enet-mac", fs_enet_interrupt); 805 r = fs_request_irq(dev, fep->interrupt, "fs_enet-mac", fs_enet_interrupt);
744 if (r != 0) { 806 if (r != 0) {
745 printk(KERN_ERR DRV_MODULE_NAME 807 printk(KERN_ERR DRV_MODULE_NAME
746 ": %s Could not allocate FEC IRQ!", dev->name); 808 ": %s Could not allocate FS_ENET IRQ!", dev->name);
747 return -EINVAL; 809 return -EINVAL;
748 } 810 }
749 811
750 /* Install our phy interrupt handler */ 812 err = fs_init_phy(dev);
751 if (fpi->phy_irq != -1) { 813 if(err)
752 814 return err;
753 r = fs_request_irq(dev, fpi->phy_irq, "fs_enet-phy", fs_mii_link_interrupt);
754 if (r != 0) {
755 printk(KERN_ERR DRV_MODULE_NAME
756 ": %s Could not allocate PHY IRQ!", dev->name);
757 fs_free_irq(dev, fep->interrupt);
758 return -EINVAL;
759 }
760 }
761 815
762 fs_mii_startup(dev); 816 phy_start(fep->phydev);
763 netif_carrier_off(dev);
764 fs_mii_link_status_change_check(dev, 1);
765 817
766 return 0; 818 return 0;
767} 819}
@@ -769,20 +821,19 @@ static int fs_enet_open(struct net_device *dev)
769static int fs_enet_close(struct net_device *dev) 821static int fs_enet_close(struct net_device *dev)
770{ 822{
771 struct fs_enet_private *fep = netdev_priv(dev); 823 struct fs_enet_private *fep = netdev_priv(dev);
772 const struct fs_platform_info *fpi = fep->fpi;
773 unsigned long flags; 824 unsigned long flags;
774 825
775 netif_stop_queue(dev); 826 netif_stop_queue(dev);
776 netif_carrier_off(dev); 827 netif_carrier_off(dev);
777 fs_mii_shutdown(dev); 828 phy_stop(fep->phydev);
778 829
779 spin_lock_irqsave(&fep->lock, flags); 830 spin_lock_irqsave(&fep->lock, flags);
780 (*fep->ops->stop)(dev); 831 (*fep->ops->stop)(dev);
781 spin_unlock_irqrestore(&fep->lock, flags); 832 spin_unlock_irqrestore(&fep->lock, flags);
782 833
783 /* release any irqs */ 834 /* release any irqs */
784 if (fpi->phy_irq != -1) 835 phy_disconnect(fep->phydev);
785 fs_free_irq(dev, fpi->phy_irq); 836 fep->phydev = NULL;
786 fs_free_irq(dev, fep->interrupt); 837 fs_free_irq(dev, fep->interrupt);
787 838
788 return 0; 839 return 0;
@@ -830,33 +881,19 @@ static void fs_get_regs(struct net_device *dev, struct ethtool_regs *regs,
830static int fs_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 881static int fs_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
831{ 882{
832 struct fs_enet_private *fep = netdev_priv(dev); 883 struct fs_enet_private *fep = netdev_priv(dev);
833 unsigned long flags; 884 return phy_ethtool_gset(fep->phydev, cmd);
834 int rc;
835
836 spin_lock_irqsave(&fep->lock, flags);
837 rc = mii_ethtool_gset(&fep->mii_if, cmd);
838 spin_unlock_irqrestore(&fep->lock, flags);
839
840 return rc;
841} 885}
842 886
843static int fs_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 887static int fs_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
844{ 888{
845 struct fs_enet_private *fep = netdev_priv(dev); 889 struct fs_enet_private *fep = netdev_priv(dev);
846 unsigned long flags; 890 phy_ethtool_sset(fep->phydev, cmd);
847 int rc; 891 return 0;
848
849 spin_lock_irqsave(&fep->lock, flags);
850 rc = mii_ethtool_sset(&fep->mii_if, cmd);
851 spin_unlock_irqrestore(&fep->lock, flags);
852
853 return rc;
854} 892}
855 893
856static int fs_nway_reset(struct net_device *dev) 894static int fs_nway_reset(struct net_device *dev)
857{ 895{
858 struct fs_enet_private *fep = netdev_priv(dev); 896 return 0;
859 return mii_nway_restart(&fep->mii_if);
860} 897}
861 898
862static u32 fs_get_msglevel(struct net_device *dev) 899static u32 fs_get_msglevel(struct net_device *dev)
@@ -898,7 +935,7 @@ static int fs_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
898 return -EINVAL; 935 return -EINVAL;
899 936
900 spin_lock_irqsave(&fep->lock, flags); 937 spin_lock_irqsave(&fep->lock, flags);
901 rc = generic_mii_ioctl(&fep->mii_if, mii, cmd, NULL); 938 rc = phy_mii_ioctl(fep->phydev, mii, cmd);
902 spin_unlock_irqrestore(&fep->lock, flags); 939 spin_unlock_irqrestore(&fep->lock, flags);
903 return rc; 940 return rc;
904} 941}
@@ -1030,12 +1067,6 @@ static struct net_device *fs_init_instance(struct device *dev,
1030 } 1067 }
1031 registered = 1; 1068 registered = 1;
1032 1069
1033 err = fs_mii_connect(ndev);
1034 if (err != 0) {
1035 printk(KERN_ERR DRV_MODULE_NAME
1036 ": %s fs_mii_connect failed.\n", ndev->name);
1037 goto err;
1038 }
1039 1070
1040 return ndev; 1071 return ndev;
1041 1072
@@ -1073,8 +1104,6 @@ static int fs_cleanup_instance(struct net_device *ndev)
1073 1104
1074 fpi = fep->fpi; 1105 fpi = fep->fpi;
1075 1106
1076 fs_mii_disconnect(ndev);
1077
1078 unregister_netdev(ndev); 1107 unregister_netdev(ndev);
1079 1108
1080 dma_free_coherent(fep->dev, (fpi->tx_ring + fpi->rx_ring) * sizeof(cbd_t), 1109 dma_free_coherent(fep->dev, (fpi->tx_ring + fpi->rx_ring) * sizeof(cbd_t),
@@ -1196,17 +1225,39 @@ static int __init fs_init(void)
1196 r = setup_immap(); 1225 r = setup_immap();
1197 if (r != 0) 1226 if (r != 0)
1198 return r; 1227 return r;
1199 r = driver_register(&fs_enet_fec_driver); 1228
1229#ifdef CONFIG_FS_ENET_HAS_FCC
1230 /* let's insert mii stuff */
1231 r = fs_enet_mdio_bb_init();
1232
1233 if (r != 0) {
1234 printk(KERN_ERR DRV_MODULE_NAME
1235 "BB PHY init failed.\n");
1236 return r;
1237 }
1238 r = driver_register(&fs_enet_fcc_driver);
1200 if (r != 0) 1239 if (r != 0)
1201 goto err; 1240 goto err;
1241#endif
1202 1242
1203 r = driver_register(&fs_enet_fcc_driver); 1243#ifdef CONFIG_FS_ENET_HAS_FEC
1244 r = fs_enet_mdio_fec_init();
1245 if (r != 0) {
1246 printk(KERN_ERR DRV_MODULE_NAME
1247 "FEC PHY init failed.\n");
1248 return r;
1249 }
1250
1251 r = driver_register(&fs_enet_fec_driver);
1204 if (r != 0) 1252 if (r != 0)
1205 goto err; 1253 goto err;
1254#endif
1206 1255
1256#ifdef CONFIG_FS_ENET_HAS_SCC
1207 r = driver_register(&fs_enet_scc_driver); 1257 r = driver_register(&fs_enet_scc_driver);
1208 if (r != 0) 1258 if (r != 0)
1209 goto err; 1259 goto err;
1260#endif
1210 1261
1211 return 0; 1262 return 0;
1212err: 1263err:
diff --git a/drivers/net/fs_enet/fs_enet-mii.c b/drivers/net/fs_enet/fs_enet-mii.c
deleted file mode 100644
index b7e6e21725cb..000000000000
--- a/drivers/net/fs_enet/fs_enet-mii.c
+++ /dev/null
@@ -1,505 +0,0 @@
1/*
2 * Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
3 *
4 * Copyright (c) 2003 Intracom S.A.
5 * by Pantelis Antoniou <panto@intracom.gr>
6 *
7 * 2005 (c) MontaVista Software, Inc.
8 * Vitaly Bordug <vbordug@ru.mvista.com>
9 *
10 * Heavily based on original FEC driver by Dan Malek <dan@embeddededge.com>
11 * and modifications by Joakim Tjernlund <joakim.tjernlund@lumentis.se>
12 *
13 * This file is licensed under the terms of the GNU General Public License
14 * version 2. This program is licensed "as is" without any warranty of any
15 * kind, whether express or implied.
16 */
17
18
19#include <linux/module.h>
20#include <linux/types.h>
21#include <linux/kernel.h>
22#include <linux/sched.h>
23#include <linux/string.h>
24#include <linux/ptrace.h>
25#include <linux/errno.h>
26#include <linux/ioport.h>
27#include <linux/slab.h>
28#include <linux/interrupt.h>
29#include <linux/pci.h>
30#include <linux/init.h>
31#include <linux/delay.h>
32#include <linux/netdevice.h>
33#include <linux/etherdevice.h>
34#include <linux/skbuff.h>
35#include <linux/spinlock.h>
36#include <linux/mii.h>
37#include <linux/ethtool.h>
38#include <linux/bitops.h>
39
40#include <asm/pgtable.h>
41#include <asm/irq.h>
42#include <asm/uaccess.h>
43
44#include "fs_enet.h"
45
46/*************************************************/
47
48/*
49 * Generic PHY support.
50 * Should work for all PHYs, but link change is detected by polling
51 */
52
53static void generic_timer_callback(unsigned long data)
54{
55 struct net_device *dev = (struct net_device *)data;
56 struct fs_enet_private *fep = netdev_priv(dev);
57
58 fep->phy_timer_list.expires = jiffies + HZ / 2;
59
60 add_timer(&fep->phy_timer_list);
61
62 fs_mii_link_status_change_check(dev, 0);
63}
64
65static void generic_startup(struct net_device *dev)
66{
67 struct fs_enet_private *fep = netdev_priv(dev);
68
69 fep->phy_timer_list.expires = jiffies + HZ / 2; /* every 500ms */
70 fep->phy_timer_list.data = (unsigned long)dev;
71 fep->phy_timer_list.function = generic_timer_callback;
72 add_timer(&fep->phy_timer_list);
73}
74
75static void generic_shutdown(struct net_device *dev)
76{
77 struct fs_enet_private *fep = netdev_priv(dev);
78
79 del_timer_sync(&fep->phy_timer_list);
80}
81
82/* ------------------------------------------------------------------------- */
83/* The Davicom DM9161 is used on the NETTA board */
84
85/* register definitions */
86
87#define MII_DM9161_ANAR 4 /* Aux. Config Register */
88#define MII_DM9161_ACR 16 /* Aux. Config Register */
89#define MII_DM9161_ACSR 17 /* Aux. Config/Status Register */
90#define MII_DM9161_10TCSR 18 /* 10BaseT Config/Status Reg. */
91#define MII_DM9161_INTR 21 /* Interrupt Register */
92#define MII_DM9161_RECR 22 /* Receive Error Counter Reg. */
93#define MII_DM9161_DISCR 23 /* Disconnect Counter Register */
94
95static void dm9161_startup(struct net_device *dev)
96{
97 struct fs_enet_private *fep = netdev_priv(dev);
98
99 fs_mii_write(dev, fep->mii_if.phy_id, MII_DM9161_INTR, 0x0000);
100 /* Start autonegotiation */
101 fs_mii_write(dev, fep->mii_if.phy_id, MII_BMCR, 0x1200);
102
103 set_current_state(TASK_UNINTERRUPTIBLE);
104 schedule_timeout(HZ*8);
105}
106
107static void dm9161_ack_int(struct net_device *dev)
108{
109 struct fs_enet_private *fep = netdev_priv(dev);
110
111 fs_mii_read(dev, fep->mii_if.phy_id, MII_DM9161_INTR);
112}
113
114static void dm9161_shutdown(struct net_device *dev)
115{
116 struct fs_enet_private *fep = netdev_priv(dev);
117
118 fs_mii_write(dev, fep->mii_if.phy_id, MII_DM9161_INTR, 0x0f00);
119}
120
121/**********************************************************************************/
122
123static const struct phy_info phy_info[] = {
124 {
125 .id = 0x00181b88,
126 .name = "DM9161",
127 .startup = dm9161_startup,
128 .ack_int = dm9161_ack_int,
129 .shutdown = dm9161_shutdown,
130 }, {
131 .id = 0,
132 .name = "GENERIC",
133 .startup = generic_startup,
134 .shutdown = generic_shutdown,
135 },
136};
137
138/**********************************************************************************/
139
140static int phy_id_detect(struct net_device *dev)
141{
142 struct fs_enet_private *fep = netdev_priv(dev);
143 const struct fs_platform_info *fpi = fep->fpi;
144 struct fs_enet_mii_bus *bus = fep->mii_bus;
145 int i, r, start, end, phytype, physubtype;
146 const struct phy_info *phy;
147 int phy_hwid, phy_id;
148
149 phy_hwid = -1;
150 fep->phy = NULL;
151
152 /* auto-detect? */
153 if (fpi->phy_addr == -1) {
154 start = 1;
155 end = 32;
156 } else { /* direct */
157 start = fpi->phy_addr;
158 end = start + 1;
159 }
160
161 for (phy_id = start; phy_id < end; phy_id++) {
162 /* skip already used phy addresses on this bus */
163 if (bus->usage_map & (1 << phy_id))
164 continue;
165 r = fs_mii_read(dev, phy_id, MII_PHYSID1);
166 if (r == -1 || (phytype = (r & 0xffff)) == 0xffff)
167 continue;
168 r = fs_mii_read(dev, phy_id, MII_PHYSID2);
169 if (r == -1 || (physubtype = (r & 0xffff)) == 0xffff)
170 continue;
171 phy_hwid = (phytype << 16) | physubtype;
172 if (phy_hwid != -1)
173 break;
174 }
175
176 if (phy_hwid == -1) {
177 printk(KERN_ERR DRV_MODULE_NAME
178 ": %s No PHY detected! range=0x%02x-0x%02x\n",
179 dev->name, start, end);
180 return -1;
181 }
182
183 for (i = 0, phy = phy_info; i < ARRAY_SIZE(phy_info); i++, phy++)
184 if (phy->id == (phy_hwid >> 4) || phy->id == 0)
185 break;
186
187 if (i >= ARRAY_SIZE(phy_info)) {
188 printk(KERN_ERR DRV_MODULE_NAME
189 ": %s PHY id 0x%08x is not supported!\n",
190 dev->name, phy_hwid);
191 return -1;
192 }
193
194 fep->phy = phy;
195
196 /* mark this address as used */
197 bus->usage_map |= (1 << phy_id);
198
199 printk(KERN_INFO DRV_MODULE_NAME
200 ": %s Phy @ 0x%x, type %s (0x%08x)%s\n",
201 dev->name, phy_id, fep->phy->name, phy_hwid,
202 fpi->phy_addr == -1 ? " (auto-detected)" : "");
203
204 return phy_id;
205}
206
207void fs_mii_startup(struct net_device *dev)
208{
209 struct fs_enet_private *fep = netdev_priv(dev);
210
211 if (fep->phy->startup)
212 (*fep->phy->startup) (dev);
213}
214
215void fs_mii_shutdown(struct net_device *dev)
216{
217 struct fs_enet_private *fep = netdev_priv(dev);
218
219 if (fep->phy->shutdown)
220 (*fep->phy->shutdown) (dev);
221}
222
223void fs_mii_ack_int(struct net_device *dev)
224{
225 struct fs_enet_private *fep = netdev_priv(dev);
226
227 if (fep->phy->ack_int)
228 (*fep->phy->ack_int) (dev);
229}
230
231#define MII_LINK 0x0001
232#define MII_HALF 0x0002
233#define MII_FULL 0x0004
234#define MII_BASE4 0x0008
235#define MII_10M 0x0010
236#define MII_100M 0x0020
237#define MII_1G 0x0040
238#define MII_10G 0x0080
239
240/* return full mii info at one gulp, with a usable form */
241static unsigned int mii_full_status(struct mii_if_info *mii)
242{
243 unsigned int status;
244 int bmsr, adv, lpa, neg;
245 struct fs_enet_private* fep = netdev_priv(mii->dev);
246
247 /* first, a dummy read, needed to latch some MII phys */
248 (void)mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
249 bmsr = mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
250
251 /* no link */
252 if ((bmsr & BMSR_LSTATUS) == 0)
253 return 0;
254
255 status = MII_LINK;
256
257 /* Lets look what ANEG says if it's supported - otherwize we shall
258 take the right values from the platform info*/
259 if(!mii->force_media) {
260 /* autoneg not completed; don't bother */
261 if ((bmsr & BMSR_ANEGCOMPLETE) == 0)
262 return 0;
263
264 adv = (*mii->mdio_read)(mii->dev, mii->phy_id, MII_ADVERTISE);
265 lpa = (*mii->mdio_read)(mii->dev, mii->phy_id, MII_LPA);
266
267 neg = lpa & adv;
268 } else {
269 neg = fep->fpi->bus_info->lpa;
270 }
271
272 if (neg & LPA_100FULL)
273 status |= MII_FULL | MII_100M;
274 else if (neg & LPA_100BASE4)
275 status |= MII_FULL | MII_BASE4 | MII_100M;
276 else if (neg & LPA_100HALF)
277 status |= MII_HALF | MII_100M;
278 else if (neg & LPA_10FULL)
279 status |= MII_FULL | MII_10M;
280 else
281 status |= MII_HALF | MII_10M;
282
283 return status;
284}
285
286void fs_mii_link_status_change_check(struct net_device *dev, int init_media)
287{
288 struct fs_enet_private *fep = netdev_priv(dev);
289 struct mii_if_info *mii = &fep->mii_if;
290 unsigned int mii_status;
291 int ok_to_print, link, duplex, speed;
292 unsigned long flags;
293
294 ok_to_print = netif_msg_link(fep);
295
296 mii_status = mii_full_status(mii);
297
298 if (!init_media && mii_status == fep->last_mii_status)
299 return;
300
301 fep->last_mii_status = mii_status;
302
303 link = !!(mii_status & MII_LINK);
304 duplex = !!(mii_status & MII_FULL);
305 speed = (mii_status & MII_100M) ? 100 : 10;
306
307 if (link == 0) {
308 netif_carrier_off(mii->dev);
309 netif_stop_queue(dev);
310 if (!init_media) {
311 spin_lock_irqsave(&fep->lock, flags);
312 (*fep->ops->stop)(dev);
313 spin_unlock_irqrestore(&fep->lock, flags);
314 }
315
316 if (ok_to_print)
317 printk(KERN_INFO "%s: link down\n", mii->dev->name);
318
319 } else {
320
321 mii->full_duplex = duplex;
322
323 netif_carrier_on(mii->dev);
324
325 spin_lock_irqsave(&fep->lock, flags);
326 fep->duplex = duplex;
327 fep->speed = speed;
328 (*fep->ops->restart)(dev);
329 spin_unlock_irqrestore(&fep->lock, flags);
330
331 netif_start_queue(dev);
332
333 if (ok_to_print)
334 printk(KERN_INFO "%s: link up, %dMbps, %s-duplex\n",
335 dev->name, speed, duplex ? "full" : "half");
336 }
337}
338
339/**********************************************************************************/
340
341int fs_mii_read(struct net_device *dev, int phy_id, int location)
342{
343 struct fs_enet_private *fep = netdev_priv(dev);
344 struct fs_enet_mii_bus *bus = fep->mii_bus;
345
346 unsigned long flags;
347 int ret;
348
349 spin_lock_irqsave(&bus->mii_lock, flags);
350 ret = (*bus->mii_read)(bus, phy_id, location);
351 spin_unlock_irqrestore(&bus->mii_lock, flags);
352
353 return ret;
354}
355
356void fs_mii_write(struct net_device *dev, int phy_id, int location, int value)
357{
358 struct fs_enet_private *fep = netdev_priv(dev);
359 struct fs_enet_mii_bus *bus = fep->mii_bus;
360 unsigned long flags;
361
362 spin_lock_irqsave(&bus->mii_lock, flags);
363 (*bus->mii_write)(bus, phy_id, location, value);
364 spin_unlock_irqrestore(&bus->mii_lock, flags);
365}
366
367/*****************************************************************************/
368
369/* list of all registered mii buses */
370static LIST_HEAD(fs_mii_bus_list);
371
372static struct fs_enet_mii_bus *lookup_bus(int method, int id)
373{
374 struct list_head *ptr;
375 struct fs_enet_mii_bus *bus;
376
377 list_for_each(ptr, &fs_mii_bus_list) {
378 bus = list_entry(ptr, struct fs_enet_mii_bus, list);
379 if (bus->bus_info->method == method &&
380 bus->bus_info->id == id)
381 return bus;
382 }
383 return NULL;
384}
385
386static struct fs_enet_mii_bus *create_bus(const struct fs_mii_bus_info *bi)
387{
388 struct fs_enet_mii_bus *bus;
389 int ret = 0;
390
391 bus = kmalloc(sizeof(*bus), GFP_KERNEL);
392 if (bus == NULL) {
393 ret = -ENOMEM;
394 goto err;
395 }
396 memset(bus, 0, sizeof(*bus));
397 spin_lock_init(&bus->mii_lock);
398 bus->bus_info = bi;
399 bus->refs = 0;
400 bus->usage_map = 0;
401
402 /* perform initialization */
403 switch (bi->method) {
404
405 case fsmii_fixed:
406 ret = fs_mii_fixed_init(bus);
407 if (ret != 0)
408 goto err;
409 break;
410
411 case fsmii_bitbang:
412 ret = fs_mii_bitbang_init(bus);
413 if (ret != 0)
414 goto err;
415 break;
416#ifdef CONFIG_FS_ENET_HAS_FEC
417 case fsmii_fec:
418 ret = fs_mii_fec_init(bus);
419 if (ret != 0)
420 goto err;
421 break;
422#endif
423 default:
424 ret = -EINVAL;
425 goto err;
426 }
427
428 list_add(&bus->list, &fs_mii_bus_list);
429
430 return bus;
431
432err:
433 kfree(bus);
434 return ERR_PTR(ret);
435}
436
437static void destroy_bus(struct fs_enet_mii_bus *bus)
438{
439 /* remove from bus list */
440 list_del(&bus->list);
441
442 /* nothing more needed */
443 kfree(bus);
444}
445
446int fs_mii_connect(struct net_device *dev)
447{
448 struct fs_enet_private *fep = netdev_priv(dev);
449 const struct fs_platform_info *fpi = fep->fpi;
450 struct fs_enet_mii_bus *bus = NULL;
451
452 /* check method validity */
453 switch (fpi->bus_info->method) {
454 case fsmii_fixed:
455 case fsmii_bitbang:
456 break;
457#ifdef CONFIG_FS_ENET_HAS_FEC
458 case fsmii_fec:
459 break;
460#endif
461 default:
462 printk(KERN_ERR DRV_MODULE_NAME
463 ": %s Unknown MII bus method (%d)!\n",
464 dev->name, fpi->bus_info->method);
465 return -EINVAL;
466 }
467
468 bus = lookup_bus(fpi->bus_info->method, fpi->bus_info->id);
469
470 /* if not found create new bus */
471 if (bus == NULL) {
472 bus = create_bus(fpi->bus_info);
473 if (IS_ERR(bus)) {
474 printk(KERN_ERR DRV_MODULE_NAME
475 ": %s MII bus creation failure!\n", dev->name);
476 return PTR_ERR(bus);
477 }
478 }
479
480 bus->refs++;
481
482 fep->mii_bus = bus;
483
484 fep->mii_if.dev = dev;
485 fep->mii_if.phy_id_mask = 0x1f;
486 fep->mii_if.reg_num_mask = 0x1f;
487 fep->mii_if.mdio_read = fs_mii_read;
488 fep->mii_if.mdio_write = fs_mii_write;
489 fep->mii_if.force_media = fpi->bus_info->disable_aneg;
490 fep->mii_if.phy_id = phy_id_detect(dev);
491
492 return 0;
493}
494
495void fs_mii_disconnect(struct net_device *dev)
496{
497 struct fs_enet_private *fep = netdev_priv(dev);
498 struct fs_enet_mii_bus *bus = NULL;
499
500 bus = fep->mii_bus;
501 fep->mii_bus = NULL;
502
503 if (--bus->refs <= 0)
504 destroy_bus(bus);
505}
diff --git a/drivers/net/fs_enet/fs_enet.h b/drivers/net/fs_enet/fs_enet.h
index e7ec96c964a9..95022c005f75 100644
--- a/drivers/net/fs_enet/fs_enet.h
+++ b/drivers/net/fs_enet/fs_enet.h
@@ -5,6 +5,7 @@
5#include <linux/netdevice.h> 5#include <linux/netdevice.h>
6#include <linux/types.h> 6#include <linux/types.h>
7#include <linux/list.h> 7#include <linux/list.h>
8#include <linux/phy.h>
8 9
9#include <linux/fs_enet_pd.h> 10#include <linux/fs_enet_pd.h>
10 11
@@ -12,12 +13,30 @@
12 13
13#ifdef CONFIG_CPM1 14#ifdef CONFIG_CPM1
14#include <asm/commproc.h> 15#include <asm/commproc.h>
16
17struct fec_info {
18 fec_t* fecp;
19 u32 mii_speed;
20};
15#endif 21#endif
16 22
17#ifdef CONFIG_CPM2 23#ifdef CONFIG_CPM2
18#include <asm/cpm2.h> 24#include <asm/cpm2.h>
19#endif 25#endif
20 26
27/* This is used to operate with pins.
28 Note that the actual port size may
29 be different; cpm(s) handle it OK */
30struct bb_info {
31 u8 mdio_dat_msk;
32 u8 mdio_dir_msk;
33 u8 *mdio_dir;
34 u8 *mdio_dat;
35 u8 mdc_msk;
36 u8 *mdc_dat;
37 int delay;
38};
39
21/* hw driver ops */ 40/* hw driver ops */
22struct fs_ops { 41struct fs_ops {
23 int (*setup_data)(struct net_device *dev); 42 int (*setup_data)(struct net_device *dev);
@@ -25,6 +44,7 @@ struct fs_ops {
25 void (*free_bd)(struct net_device *dev); 44 void (*free_bd)(struct net_device *dev);
26 void (*cleanup_data)(struct net_device *dev); 45 void (*cleanup_data)(struct net_device *dev);
27 void (*set_multicast_list)(struct net_device *dev); 46 void (*set_multicast_list)(struct net_device *dev);
47 void (*adjust_link)(struct net_device *dev);
28 void (*restart)(struct net_device *dev); 48 void (*restart)(struct net_device *dev);
29 void (*stop)(struct net_device *dev); 49 void (*stop)(struct net_device *dev);
30 void (*pre_request_irq)(struct net_device *dev, int irq); 50 void (*pre_request_irq)(struct net_device *dev, int irq);
@@ -100,10 +120,6 @@ struct fs_enet_mii_bus {
100 }; 120 };
101}; 121};
102 122
103int fs_mii_bitbang_init(struct fs_enet_mii_bus *bus);
104int fs_mii_fixed_init(struct fs_enet_mii_bus *bus);
105int fs_mii_fec_init(struct fs_enet_mii_bus *bus);
106
107struct fs_enet_private { 123struct fs_enet_private {
108 struct device *dev; /* pointer back to the device (must be initialized first) */ 124 struct device *dev; /* pointer back to the device (must be initialized first) */
109 spinlock_t lock; /* during all ops except TX pckt processing */ 125 spinlock_t lock; /* during all ops except TX pckt processing */
@@ -130,7 +146,8 @@ struct fs_enet_private {
130 struct fs_enet_mii_bus *mii_bus; 146 struct fs_enet_mii_bus *mii_bus;
131 int interrupt; 147 int interrupt;
132 148
133 int duplex, speed; /* current settings */ 149 struct phy_device *phydev;
150 int oldduplex, oldspeed, oldlink; /* current settings */
134 151
135 /* event masks */ 152 /* event masks */
136 u32 ev_napi_rx; /* mask of NAPI rx events */ 153 u32 ev_napi_rx; /* mask of NAPI rx events */
@@ -168,15 +185,9 @@ struct fs_enet_private {
168}; 185};
169 186
170/***************************************************************************/ 187/***************************************************************************/
171 188int fs_enet_mdio_bb_init(void);
172int fs_mii_read(struct net_device *dev, int phy_id, int location); 189int fs_mii_fixed_init(struct fs_enet_mii_bus *bus);
173void fs_mii_write(struct net_device *dev, int phy_id, int location, int value); 190int fs_enet_mdio_fec_init(void);
174
175void fs_mii_startup(struct net_device *dev);
176void fs_mii_shutdown(struct net_device *dev);
177void fs_mii_ack_int(struct net_device *dev);
178
179void fs_mii_link_status_change_check(struct net_device *dev, int init_media);
180 191
181void fs_init_bds(struct net_device *dev); 192void fs_init_bds(struct net_device *dev);
182void fs_cleanup_bds(struct net_device *dev); 193void fs_cleanup_bds(struct net_device *dev);
@@ -194,7 +205,6 @@ int fs_enet_platform_init(void);
194void fs_enet_platform_cleanup(void); 205void fs_enet_platform_cleanup(void);
195 206
196/***************************************************************************/ 207/***************************************************************************/
197
198/* buffer descriptor access macros */ 208/* buffer descriptor access macros */
199 209
200/* access macros */ 210/* access macros */
diff --git a/drivers/net/fs_enet/mac-fcc.c b/drivers/net/fs_enet/mac-fcc.c
index 64e20982c1fe..1ff2597b8495 100644
--- a/drivers/net/fs_enet/mac-fcc.c
+++ b/drivers/net/fs_enet/mac-fcc.c
@@ -34,6 +34,7 @@
34#include <linux/bitops.h> 34#include <linux/bitops.h>
35#include <linux/fs.h> 35#include <linux/fs.h>
36#include <linux/platform_device.h> 36#include <linux/platform_device.h>
37#include <linux/phy.h>
37 38
38#include <asm/immap_cpm2.h> 39#include <asm/immap_cpm2.h>
39#include <asm/mpc8260.h> 40#include <asm/mpc8260.h>
@@ -122,22 +123,32 @@ static int do_pd_setup(struct fs_enet_private *fep)
122 123
123 /* Attach the memory for the FCC Parameter RAM */ 124 /* Attach the memory for the FCC Parameter RAM */
124 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_pram"); 125 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_pram");
125 fep->fcc.ep = (void *)r->start; 126 fep->fcc.ep = (void *)ioremap(r->start, r->end - r->start + 1);
126
127 if (fep->fcc.ep == NULL) 127 if (fep->fcc.ep == NULL)
128 return -EINVAL; 128 return -EINVAL;
129 129
130 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_regs"); 130 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_regs");
131 fep->fcc.fccp = (void *)r->start; 131 fep->fcc.fccp = (void *)ioremap(r->start, r->end - r->start + 1);
132
133 if (fep->fcc.fccp == NULL) 132 if (fep->fcc.fccp == NULL)
134 return -EINVAL; 133 return -EINVAL;
135 134
136 fep->fcc.fcccp = (void *)fep->fpi->fcc_regs_c; 135 if (fep->fpi->fcc_regs_c) {
136
137 fep->fcc.fcccp = (void *)fep->fpi->fcc_regs_c;
138 } else {
139 r = platform_get_resource_byname(pdev, IORESOURCE_MEM,
140 "fcc_regs_c");
141 fep->fcc.fcccp = (void *)ioremap(r->start,
142 r->end - r->start + 1);
143 }
137 144
138 if (fep->fcc.fcccp == NULL) 145 if (fep->fcc.fcccp == NULL)
139 return -EINVAL; 146 return -EINVAL;
140 147
148 fep->fcc.mem = (void *)fep->fpi->mem_offset;
149 if (fep->fcc.mem == NULL)
150 return -EINVAL;
151
141 return 0; 152 return 0;
142} 153}
143 154
@@ -155,8 +166,6 @@ static int setup_data(struct net_device *dev)
155 if ((unsigned int)fep->fcc.idx >= 3) /* max 3 FCCs */ 166 if ((unsigned int)fep->fcc.idx >= 3) /* max 3 FCCs */
156 return -EINVAL; 167 return -EINVAL;
157 168
158 fep->fcc.mem = (void *)fpi->mem_offset;
159
160 if (do_pd_setup(fep) != 0) 169 if (do_pd_setup(fep) != 0)
161 return -EINVAL; 170 return -EINVAL;
162 171
@@ -394,7 +403,7 @@ static void restart(struct net_device *dev)
394 403
395 /* adjust to speed (for RMII mode) */ 404 /* adjust to speed (for RMII mode) */
396 if (fpi->use_rmii) { 405 if (fpi->use_rmii) {
397 if (fep->speed == 100) 406 if (fep->phydev->speed == 100)
398 C8(fcccp, fcc_gfemr, 0x20); 407 C8(fcccp, fcc_gfemr, 0x20);
399 else 408 else
400 S8(fcccp, fcc_gfemr, 0x20); 409 S8(fcccp, fcc_gfemr, 0x20);
@@ -420,7 +429,7 @@ static void restart(struct net_device *dev)
420 S32(fccp, fcc_fpsmr, FCC_PSMR_RMII); 429 S32(fccp, fcc_fpsmr, FCC_PSMR_RMII);
421 430
422 /* adjust to duplex mode */ 431 /* adjust to duplex mode */
423 if (fep->duplex) 432 if (fep->phydev->duplex)
424 S32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB); 433 S32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
425 else 434 else
426 C32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB); 435 C32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
@@ -486,7 +495,10 @@ static void rx_bd_done(struct net_device *dev)
486 495
487static void tx_kickstart(struct net_device *dev) 496static void tx_kickstart(struct net_device *dev)
488{ 497{
489 /* nothing */ 498 struct fs_enet_private *fep = netdev_priv(dev);
499 fcc_t *fccp = fep->fcc.fccp;
500
501 S32(fccp, fcc_ftodr, 0x80);
490} 502}
491 503
492static u32 get_int_events(struct net_device *dev) 504static u32 get_int_events(struct net_device *dev)
diff --git a/drivers/net/fs_enet/mac-fec.c b/drivers/net/fs_enet/mac-fec.c
index e09547077529..c2c5fd419bd0 100644
--- a/drivers/net/fs_enet/mac-fec.c
+++ b/drivers/net/fs_enet/mac-fec.c
@@ -46,6 +46,7 @@
46#endif 46#endif
47 47
48#include "fs_enet.h" 48#include "fs_enet.h"
49#include "fec.h"
49 50
50/*************************************************/ 51/*************************************************/
51 52
@@ -75,50 +76,8 @@
75/* clear bits */ 76/* clear bits */
76#define FC(_fecp, _reg, _v) FW(_fecp, _reg, FR(_fecp, _reg) & ~(_v)) 77#define FC(_fecp, _reg, _v) FW(_fecp, _reg, FR(_fecp, _reg) & ~(_v))
77 78
78
79/* CRC polynomium used by the FEC for the multicast group filtering */
80#define FEC_CRC_POLY 0x04C11DB7
81
82#define FEC_MAX_MULTICAST_ADDRS 64
83
84/* Interrupt events/masks.
85*/
86#define FEC_ENET_HBERR 0x80000000U /* Heartbeat error */
87#define FEC_ENET_BABR 0x40000000U /* Babbling receiver */
88#define FEC_ENET_BABT 0x20000000U /* Babbling transmitter */
89#define FEC_ENET_GRA 0x10000000U /* Graceful stop complete */
90#define FEC_ENET_TXF 0x08000000U /* Full frame transmitted */
91#define FEC_ENET_TXB 0x04000000U /* A buffer was transmitted */
92#define FEC_ENET_RXF 0x02000000U /* Full frame received */
93#define FEC_ENET_RXB 0x01000000U /* A buffer was received */
94#define FEC_ENET_MII 0x00800000U /* MII interrupt */
95#define FEC_ENET_EBERR 0x00400000U /* SDMA bus error */
96
97#define FEC_ECNTRL_PINMUX 0x00000004
98#define FEC_ECNTRL_ETHER_EN 0x00000002
99#define FEC_ECNTRL_RESET 0x00000001
100
101#define FEC_RCNTRL_BC_REJ 0x00000010
102#define FEC_RCNTRL_PROM 0x00000008
103#define FEC_RCNTRL_MII_MODE 0x00000004
104#define FEC_RCNTRL_DRT 0x00000002
105#define FEC_RCNTRL_LOOP 0x00000001
106
107#define FEC_TCNTRL_FDEN 0x00000004
108#define FEC_TCNTRL_HBC 0x00000002
109#define FEC_TCNTRL_GTS 0x00000001
110
111
112/* Make MII read/write commands for the FEC.
113*/
114#define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
115#define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | (VAL & 0xffff))
116#define mk_mii_end 0
117
118#define FEC_MII_LOOPS 10000
119
120/* 79/*
121 * Delay to wait for FEC reset command to complete (in us) 80 * Delay to wait for FEC reset command to complete (in us)
122 */ 81 */
123#define FEC_RESET_DELAY 50 82#define FEC_RESET_DELAY 50
124 83
@@ -303,13 +262,15 @@ static void restart(struct net_device *dev)
303 int r; 262 int r;
304 u32 addrhi, addrlo; 263 u32 addrhi, addrlo;
305 264
265 struct mii_bus* mii = fep->phydev->bus;
266 struct fec_info* fec_inf = mii->priv;
267
306 r = whack_reset(fep->fec.fecp); 268 r = whack_reset(fep->fec.fecp);
307 if (r != 0) 269 if (r != 0)
308 printk(KERN_ERR DRV_MODULE_NAME 270 printk(KERN_ERR DRV_MODULE_NAME
309 ": %s FEC Reset FAILED!\n", dev->name); 271 ": %s FEC Reset FAILED!\n", dev->name);
310
311 /* 272 /*
312 * Set station address. 273 * Set station address.
313 */ 274 */
314 addrhi = ((u32) dev->dev_addr[0] << 24) | 275 addrhi = ((u32) dev->dev_addr[0] << 24) |
315 ((u32) dev->dev_addr[1] << 16) | 276 ((u32) dev->dev_addr[1] << 16) |
@@ -350,12 +311,12 @@ static void restart(struct net_device *dev)
350 FW(fecp, fun_code, 0x78000000); 311 FW(fecp, fun_code, 0x78000000);
351 312
352 /* 313 /*
353 * Set MII speed. 314 * Set MII speed.
354 */ 315 */
355 FW(fecp, mii_speed, fep->mii_bus->fec.mii_speed); 316 FW(fecp, mii_speed, fec_inf->mii_speed);
356 317
357 /* 318 /*
358 * Clear any outstanding interrupt. 319 * Clear any outstanding interrupt.
359 */ 320 */
360 FW(fecp, ievent, 0xffc0); 321 FW(fecp, ievent, 0xffc0);
361 FW(fecp, ivec, (fep->interrupt / 2) << 29); 322 FW(fecp, ivec, (fep->interrupt / 2) << 29);
@@ -390,11 +351,12 @@ static void restart(struct net_device *dev)
390 } 351 }
391#endif 352#endif
392 353
354
393 FW(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */ 355 FW(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
394 /* 356 /*
395 * adjust to duplex mode 357 * adjust to duplex mode
396 */ 358 */
397 if (fep->duplex) { 359 if (fep->phydev->duplex) {
398 FC(fecp, r_cntrl, FEC_RCNTRL_DRT); 360 FC(fecp, r_cntrl, FEC_RCNTRL_DRT);
399 FS(fecp, x_cntrl, FEC_TCNTRL_FDEN); /* FD enable */ 361 FS(fecp, x_cntrl, FEC_TCNTRL_FDEN); /* FD enable */
400 } else { 362 } else {
@@ -418,9 +380,11 @@ static void restart(struct net_device *dev)
418static void stop(struct net_device *dev) 380static void stop(struct net_device *dev)
419{ 381{
420 struct fs_enet_private *fep = netdev_priv(dev); 382 struct fs_enet_private *fep = netdev_priv(dev);
383 const struct fs_platform_info *fpi = fep->fpi;
421 fec_t *fecp = fep->fec.fecp; 384 fec_t *fecp = fep->fec.fecp;
422 struct fs_enet_mii_bus *bus = fep->mii_bus; 385
423 const struct fs_mii_bus_info *bi = bus->bus_info; 386 struct fec_info* feci= fep->phydev->bus->priv;
387
424 int i; 388 int i;
425 389
426 if ((FR(fecp, ecntrl) & FEC_ECNTRL_ETHER_EN) == 0) 390 if ((FR(fecp, ecntrl) & FEC_ECNTRL_ETHER_EN) == 0)
@@ -444,11 +408,11 @@ static void stop(struct net_device *dev)
444 fs_cleanup_bds(dev); 408 fs_cleanup_bds(dev);
445 409
446 /* shut down FEC1? that's where the mii bus is */ 410 /* shut down FEC1? that's where the mii bus is */
447 if (fep->fec.idx == 0 && bus->refs > 1 && bi->method == fsmii_fec) { 411 if (fpi->has_phy) {
448 FS(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */ 412 FS(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
449 FS(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN); 413 FS(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
450 FW(fecp, ievent, FEC_ENET_MII); 414 FW(fecp, ievent, FEC_ENET_MII);
451 FW(fecp, mii_speed, bus->fec.mii_speed); 415 FW(fecp, mii_speed, feci->mii_speed);
452 } 416 }
453} 417}
454 418
@@ -583,73 +547,3 @@ const struct fs_ops fs_fec_ops = {
583 .free_bd = free_bd, 547 .free_bd = free_bd,
584}; 548};
585 549
586/***********************************************************************/
587
588static int mii_read(struct fs_enet_mii_bus *bus, int phy_id, int location)
589{
590 fec_t *fecp = bus->fec.fecp;
591 int i, ret = -1;
592
593 if ((FR(fecp, r_cntrl) & FEC_RCNTRL_MII_MODE) == 0)
594 BUG();
595
596 /* Add PHY address to register command. */
597 FW(fecp, mii_data, (phy_id << 23) | mk_mii_read(location));
598
599 for (i = 0; i < FEC_MII_LOOPS; i++)
600 if ((FR(fecp, ievent) & FEC_ENET_MII) != 0)
601 break;
602
603 if (i < FEC_MII_LOOPS) {
604 FW(fecp, ievent, FEC_ENET_MII);
605 ret = FR(fecp, mii_data) & 0xffff;
606 }
607
608 return ret;
609}
610
611static void mii_write(struct fs_enet_mii_bus *bus, int phy_id, int location, int value)
612{
613 fec_t *fecp = bus->fec.fecp;
614 int i;
615
616 /* this must never happen */
617 if ((FR(fecp, r_cntrl) & FEC_RCNTRL_MII_MODE) == 0)
618 BUG();
619
620 /* Add PHY address to register command. */
621 FW(fecp, mii_data, (phy_id << 23) | mk_mii_write(location, value));
622
623 for (i = 0; i < FEC_MII_LOOPS; i++)
624 if ((FR(fecp, ievent) & FEC_ENET_MII) != 0)
625 break;
626
627 if (i < FEC_MII_LOOPS)
628 FW(fecp, ievent, FEC_ENET_MII);
629}
630
631int fs_mii_fec_init(struct fs_enet_mii_bus *bus)
632{
633 bd_t *bd = (bd_t *)__res;
634 const struct fs_mii_bus_info *bi = bus->bus_info;
635 fec_t *fecp;
636
637 if (bi->id != 0)
638 return -1;
639
640 bus->fec.fecp = &((immap_t *)fs_enet_immap)->im_cpm.cp_fec;
641 bus->fec.mii_speed = ((((bd->bi_intfreq + 4999999) / 2500000) / 2)
642 & 0x3F) << 1;
643
644 fecp = bus->fec.fecp;
645
646 FS(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
647 FS(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
648 FW(fecp, ievent, FEC_ENET_MII);
649 FW(fecp, mii_speed, bus->fec.mii_speed);
650
651 bus->mii_read = mii_read;
652 bus->mii_write = mii_write;
653
654 return 0;
655}
diff --git a/drivers/net/fs_enet/mac-scc.c b/drivers/net/fs_enet/mac-scc.c
index eaa24fab645f..95ec5872c507 100644
--- a/drivers/net/fs_enet/mac-scc.c
+++ b/drivers/net/fs_enet/mac-scc.c
@@ -369,7 +369,7 @@ static void restart(struct net_device *dev)
369 W16(sccp, scc_psmr, SCC_PSMR_ENCRC | SCC_PSMR_NIB22); 369 W16(sccp, scc_psmr, SCC_PSMR_ENCRC | SCC_PSMR_NIB22);
370 370
371 /* Set full duplex mode if needed */ 371 /* Set full duplex mode if needed */
372 if (fep->duplex) 372 if (fep->phydev->duplex)
373 S16(sccp, scc_psmr, SCC_PSMR_LPB | SCC_PSMR_FDE); 373 S16(sccp, scc_psmr, SCC_PSMR_LPB | SCC_PSMR_FDE);
374 374
375 S32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); 375 S32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
@@ -500,6 +500,8 @@ static void tx_restart(struct net_device *dev)
500 scc_cr_cmd(fep, CPM_CR_RESTART_TX); 500 scc_cr_cmd(fep, CPM_CR_RESTART_TX);
501} 501}
502 502
503
504
503/*************************************************************************/ 505/*************************************************************************/
504 506
505const struct fs_ops fs_scc_ops = { 507const struct fs_ops fs_scc_ops = {
diff --git a/drivers/net/fs_enet/mii-bitbang.c b/drivers/net/fs_enet/mii-bitbang.c
index 48f9cf83ab6f..0b9b8b5c847c 100644
--- a/drivers/net/fs_enet/mii-bitbang.c
+++ b/drivers/net/fs_enet/mii-bitbang.c
@@ -33,6 +33,7 @@
33#include <linux/mii.h> 33#include <linux/mii.h>
34#include <linux/ethtool.h> 34#include <linux/ethtool.h>
35#include <linux/bitops.h> 35#include <linux/bitops.h>
36#include <linux/platform_device.h>
36 37
37#include <asm/pgtable.h> 38#include <asm/pgtable.h>
38#include <asm/irq.h> 39#include <asm/irq.h>
@@ -40,129 +41,25 @@
40 41
41#include "fs_enet.h" 42#include "fs_enet.h"
42 43
43#ifdef CONFIG_8xx 44static int bitbang_prep_bit(u8 **datp, u8 *mskp,
44static int bitbang_prep_bit(u8 **dirp, u8 **datp, u8 *mskp, int port, int bit) 45 struct fs_mii_bit *mii_bit)
45{ 46{
46 immap_t *im = (immap_t *)fs_enet_immap; 47 void *dat;
47 void *dir, *dat, *ppar;
48 int adv; 48 int adv;
49 u8 msk; 49 u8 msk;
50 50
51 switch (port) { 51 dat = (void*) mii_bit->offset;
52 case fsiop_porta:
53 dir = &im->im_ioport.iop_padir;
54 dat = &im->im_ioport.iop_padat;
55 ppar = &im->im_ioport.iop_papar;
56 break;
57
58 case fsiop_portb:
59 dir = &im->im_cpm.cp_pbdir;
60 dat = &im->im_cpm.cp_pbdat;
61 ppar = &im->im_cpm.cp_pbpar;
62 break;
63
64 case fsiop_portc:
65 dir = &im->im_ioport.iop_pcdir;
66 dat = &im->im_ioport.iop_pcdat;
67 ppar = &im->im_ioport.iop_pcpar;
68 break;
69
70 case fsiop_portd:
71 dir = &im->im_ioport.iop_pddir;
72 dat = &im->im_ioport.iop_pddat;
73 ppar = &im->im_ioport.iop_pdpar;
74 break;
75
76 case fsiop_porte:
77 dir = &im->im_cpm.cp_pedir;
78 dat = &im->im_cpm.cp_pedat;
79 ppar = &im->im_cpm.cp_pepar;
80 break;
81
82 default:
83 printk(KERN_ERR DRV_MODULE_NAME
84 "Illegal port value %d!\n", port);
85 return -EINVAL;
86 }
87
88 adv = bit >> 3;
89 dir = (char *)dir + adv;
90 dat = (char *)dat + adv;
91 ppar = (char *)ppar + adv;
92
93 msk = 1 << (7 - (bit & 7));
94 if ((in_8(ppar) & msk) != 0) {
95 printk(KERN_ERR DRV_MODULE_NAME
96 "pin %d on port %d is not general purpose!\n", bit, port);
97 return -EINVAL;
98 }
99
100 *dirp = dir;
101 *datp = dat;
102 *mskp = msk;
103
104 return 0;
105}
106#endif
107
108#ifdef CONFIG_8260
109static int bitbang_prep_bit(u8 **dirp, u8 **datp, u8 *mskp, int port, int bit)
110{
111 iop_cpm2_t *io = &((cpm2_map_t *)fs_enet_immap)->im_ioport;
112 void *dir, *dat, *ppar;
113 int adv;
114 u8 msk;
115
116 switch (port) {
117 case fsiop_porta:
118 dir = &io->iop_pdira;
119 dat = &io->iop_pdata;
120 ppar = &io->iop_ppara;
121 break;
122
123 case fsiop_portb:
124 dir = &io->iop_pdirb;
125 dat = &io->iop_pdatb;
126 ppar = &io->iop_pparb;
127 break;
128
129 case fsiop_portc:
130 dir = &io->iop_pdirc;
131 dat = &io->iop_pdatc;
132 ppar = &io->iop_pparc;
133 break;
134
135 case fsiop_portd:
136 dir = &io->iop_pdird;
137 dat = &io->iop_pdatd;
138 ppar = &io->iop_ppard;
139 break;
140
141 default:
142 printk(KERN_ERR DRV_MODULE_NAME
143 "Illegal port value %d!\n", port);
144 return -EINVAL;
145 }
146 52
147 adv = bit >> 3; 53 adv = mii_bit->bit >> 3;
148 dir = (char *)dir + adv;
149 dat = (char *)dat + adv; 54 dat = (char *)dat + adv;
150 ppar = (char *)ppar + adv;
151 55
152 msk = 1 << (7 - (bit & 7)); 56 msk = 1 << (7 - (mii_bit->bit & 7));
153 if ((in_8(ppar) & msk) != 0) {
154 printk(KERN_ERR DRV_MODULE_NAME
155 "pin %d on port %d is not general purpose!\n", bit, port);
156 return -EINVAL;
157 }
158 57
159 *dirp = dir;
160 *datp = dat; 58 *datp = dat;
161 *mskp = msk; 59 *mskp = msk;
162 60
163 return 0; 61 return 0;
164} 62}
165#endif
166 63
167static inline void bb_set(u8 *p, u8 m) 64static inline void bb_set(u8 *p, u8 m)
168{ 65{
@@ -179,44 +76,44 @@ static inline int bb_read(u8 *p, u8 m)
179 return (in_8(p) & m) != 0; 76 return (in_8(p) & m) != 0;
180} 77}
181 78
182static inline void mdio_active(struct fs_enet_mii_bus *bus) 79static inline void mdio_active(struct bb_info *bitbang)
183{ 80{
184 bb_set(bus->bitbang.mdio_dir, bus->bitbang.mdio_msk); 81 bb_set(bitbang->mdio_dir, bitbang->mdio_dir_msk);
185} 82}
186 83
187static inline void mdio_tristate(struct fs_enet_mii_bus *bus) 84static inline void mdio_tristate(struct bb_info *bitbang )
188{ 85{
189 bb_clr(bus->bitbang.mdio_dir, bus->bitbang.mdio_msk); 86 bb_clr(bitbang->mdio_dir, bitbang->mdio_dir_msk);
190} 87}
191 88
192static inline int mdio_read(struct fs_enet_mii_bus *bus) 89static inline int mdio_read(struct bb_info *bitbang )
193{ 90{
194 return bb_read(bus->bitbang.mdio_dat, bus->bitbang.mdio_msk); 91 return bb_read(bitbang->mdio_dat, bitbang->mdio_dat_msk);
195} 92}
196 93
197static inline void mdio(struct fs_enet_mii_bus *bus, int what) 94static inline void mdio(struct bb_info *bitbang , int what)
198{ 95{
199 if (what) 96 if (what)
200 bb_set(bus->bitbang.mdio_dat, bus->bitbang.mdio_msk); 97 bb_set(bitbang->mdio_dat, bitbang->mdio_dat_msk);
201 else 98 else
202 bb_clr(bus->bitbang.mdio_dat, bus->bitbang.mdio_msk); 99 bb_clr(bitbang->mdio_dat, bitbang->mdio_dat_msk);
203} 100}
204 101
205static inline void mdc(struct fs_enet_mii_bus *bus, int what) 102static inline void mdc(struct bb_info *bitbang , int what)
206{ 103{
207 if (what) 104 if (what)
208 bb_set(bus->bitbang.mdc_dat, bus->bitbang.mdc_msk); 105 bb_set(bitbang->mdc_dat, bitbang->mdc_msk);
209 else 106 else
210 bb_clr(bus->bitbang.mdc_dat, bus->bitbang.mdc_msk); 107 bb_clr(bitbang->mdc_dat, bitbang->mdc_msk);
211} 108}
212 109
213static inline void mii_delay(struct fs_enet_mii_bus *bus) 110static inline void mii_delay(struct bb_info *bitbang )
214{ 111{
215 udelay(bus->bus_info->i.bitbang.delay); 112 udelay(bitbang->delay);
216} 113}
217 114
218/* Utility to send the preamble, address, and register (common to read and write). */ 115/* Utility to send the preamble, address, and register (common to read and write). */
219static void bitbang_pre(struct fs_enet_mii_bus *bus, int read, u8 addr, u8 reg) 116static void bitbang_pre(struct bb_info *bitbang , int read, u8 addr, u8 reg)
220{ 117{
221 int j; 118 int j;
222 119
@@ -228,177 +125,284 @@ static void bitbang_pre(struct fs_enet_mii_bus *bus, int read, u8 addr, u8 reg)
228 * but it is safer and will be much more robust. 125 * but it is safer and will be much more robust.
229 */ 126 */
230 127
231 mdio_active(bus); 128 mdio_active(bitbang);
232 mdio(bus, 1); 129 mdio(bitbang, 1);
233 for (j = 0; j < 32; j++) { 130 for (j = 0; j < 32; j++) {
234 mdc(bus, 0); 131 mdc(bitbang, 0);
235 mii_delay(bus); 132 mii_delay(bitbang);
236 mdc(bus, 1); 133 mdc(bitbang, 1);
237 mii_delay(bus); 134 mii_delay(bitbang);
238 } 135 }
239 136
240 /* send the start bit (01) and the read opcode (10) or write (10) */ 137 /* send the start bit (01) and the read opcode (10) or write (10) */
241 mdc(bus, 0); 138 mdc(bitbang, 0);
242 mdio(bus, 0); 139 mdio(bitbang, 0);
243 mii_delay(bus); 140 mii_delay(bitbang);
244 mdc(bus, 1); 141 mdc(bitbang, 1);
245 mii_delay(bus); 142 mii_delay(bitbang);
246 mdc(bus, 0); 143 mdc(bitbang, 0);
247 mdio(bus, 1); 144 mdio(bitbang, 1);
248 mii_delay(bus); 145 mii_delay(bitbang);
249 mdc(bus, 1); 146 mdc(bitbang, 1);
250 mii_delay(bus); 147 mii_delay(bitbang);
251 mdc(bus, 0); 148 mdc(bitbang, 0);
252 mdio(bus, read); 149 mdio(bitbang, read);
253 mii_delay(bus); 150 mii_delay(bitbang);
254 mdc(bus, 1); 151 mdc(bitbang, 1);
255 mii_delay(bus); 152 mii_delay(bitbang);
256 mdc(bus, 0); 153 mdc(bitbang, 0);
257 mdio(bus, !read); 154 mdio(bitbang, !read);
258 mii_delay(bus); 155 mii_delay(bitbang);
259 mdc(bus, 1); 156 mdc(bitbang, 1);
260 mii_delay(bus); 157 mii_delay(bitbang);
261 158
262 /* send the PHY address */ 159 /* send the PHY address */
263 for (j = 0; j < 5; j++) { 160 for (j = 0; j < 5; j++) {
264 mdc(bus, 0); 161 mdc(bitbang, 0);
265 mdio(bus, (addr & 0x10) != 0); 162 mdio(bitbang, (addr & 0x10) != 0);
266 mii_delay(bus); 163 mii_delay(bitbang);
267 mdc(bus, 1); 164 mdc(bitbang, 1);
268 mii_delay(bus); 165 mii_delay(bitbang);
269 addr <<= 1; 166 addr <<= 1;
270 } 167 }
271 168
272 /* send the register address */ 169 /* send the register address */
273 for (j = 0; j < 5; j++) { 170 for (j = 0; j < 5; j++) {
274 mdc(bus, 0); 171 mdc(bitbang, 0);
275 mdio(bus, (reg & 0x10) != 0); 172 mdio(bitbang, (reg & 0x10) != 0);
276 mii_delay(bus); 173 mii_delay(bitbang);
277 mdc(bus, 1); 174 mdc(bitbang, 1);
278 mii_delay(bus); 175 mii_delay(bitbang);
279 reg <<= 1; 176 reg <<= 1;
280 } 177 }
281} 178}
282 179
283static int mii_read(struct fs_enet_mii_bus *bus, int phy_id, int location) 180static int fs_enet_mii_bb_read(struct mii_bus *bus , int phy_id, int location)
284{ 181{
285 u16 rdreg; 182 u16 rdreg;
286 int ret, j; 183 int ret, j;
287 u8 addr = phy_id & 0xff; 184 u8 addr = phy_id & 0xff;
288 u8 reg = location & 0xff; 185 u8 reg = location & 0xff;
186 struct bb_info* bitbang = bus->priv;
289 187
290 bitbang_pre(bus, 1, addr, reg); 188 bitbang_pre(bitbang, 1, addr, reg);
291 189
292 /* tri-state our MDIO I/O pin so we can read */ 190 /* tri-state our MDIO I/O pin so we can read */
293 mdc(bus, 0); 191 mdc(bitbang, 0);
294 mdio_tristate(bus); 192 mdio_tristate(bitbang);
295 mii_delay(bus); 193 mii_delay(bitbang);
296 mdc(bus, 1); 194 mdc(bitbang, 1);
297 mii_delay(bus); 195 mii_delay(bitbang);
298 196
299 /* check the turnaround bit: the PHY should be driving it to zero */ 197 /* check the turnaround bit: the PHY should be driving it to zero */
300 if (mdio_read(bus) != 0) { 198 if (mdio_read(bitbang) != 0) {
301 /* PHY didn't drive TA low */ 199 /* PHY didn't drive TA low */
302 for (j = 0; j < 32; j++) { 200 for (j = 0; j < 32; j++) {
303 mdc(bus, 0); 201 mdc(bitbang, 0);
304 mii_delay(bus); 202 mii_delay(bitbang);
305 mdc(bus, 1); 203 mdc(bitbang, 1);
306 mii_delay(bus); 204 mii_delay(bitbang);
307 } 205 }
308 ret = -1; 206 ret = -1;
309 goto out; 207 goto out;
310 } 208 }
311 209
312 mdc(bus, 0); 210 mdc(bitbang, 0);
313 mii_delay(bus); 211 mii_delay(bitbang);
314 212
315 /* read 16 bits of register data, MSB first */ 213 /* read 16 bits of register data, MSB first */
316 rdreg = 0; 214 rdreg = 0;
317 for (j = 0; j < 16; j++) { 215 for (j = 0; j < 16; j++) {
318 mdc(bus, 1); 216 mdc(bitbang, 1);
319 mii_delay(bus); 217 mii_delay(bitbang);
320 rdreg <<= 1; 218 rdreg <<= 1;
321 rdreg |= mdio_read(bus); 219 rdreg |= mdio_read(bitbang);
322 mdc(bus, 0); 220 mdc(bitbang, 0);
323 mii_delay(bus); 221 mii_delay(bitbang);
324 } 222 }
325 223
326 mdc(bus, 1); 224 mdc(bitbang, 1);
327 mii_delay(bus); 225 mii_delay(bitbang);
328 mdc(bus, 0); 226 mdc(bitbang, 0);
329 mii_delay(bus); 227 mii_delay(bitbang);
330 mdc(bus, 1); 228 mdc(bitbang, 1);
331 mii_delay(bus); 229 mii_delay(bitbang);
332 230
333 ret = rdreg; 231 ret = rdreg;
334out: 232out:
335 return ret; 233 return ret;
336} 234}
337 235
338static void mii_write(struct fs_enet_mii_bus *bus, int phy_id, int location, int val) 236static int fs_enet_mii_bb_write(struct mii_bus *bus, int phy_id, int location, u16 val)
339{ 237{
340 int j; 238 int j;
239 struct bb_info* bitbang = bus->priv;
240
341 u8 addr = phy_id & 0xff; 241 u8 addr = phy_id & 0xff;
342 u8 reg = location & 0xff; 242 u8 reg = location & 0xff;
343 u16 value = val & 0xffff; 243 u16 value = val & 0xffff;
344 244
345 bitbang_pre(bus, 0, addr, reg); 245 bitbang_pre(bitbang, 0, addr, reg);
346 246
347 /* send the turnaround (10) */ 247 /* send the turnaround (10) */
348 mdc(bus, 0); 248 mdc(bitbang, 0);
349 mdio(bus, 1); 249 mdio(bitbang, 1);
350 mii_delay(bus); 250 mii_delay(bitbang);
351 mdc(bus, 1); 251 mdc(bitbang, 1);
352 mii_delay(bus); 252 mii_delay(bitbang);
353 mdc(bus, 0); 253 mdc(bitbang, 0);
354 mdio(bus, 0); 254 mdio(bitbang, 0);
355 mii_delay(bus); 255 mii_delay(bitbang);
356 mdc(bus, 1); 256 mdc(bitbang, 1);
357 mii_delay(bus); 257 mii_delay(bitbang);
358 258
359 /* write 16 bits of register data, MSB first */ 259 /* write 16 bits of register data, MSB first */
360 for (j = 0; j < 16; j++) { 260 for (j = 0; j < 16; j++) {
361 mdc(bus, 0); 261 mdc(bitbang, 0);
362 mdio(bus, (value & 0x8000) != 0); 262 mdio(bitbang, (value & 0x8000) != 0);
363 mii_delay(bus); 263 mii_delay(bitbang);
364 mdc(bus, 1); 264 mdc(bitbang, 1);
365 mii_delay(bus); 265 mii_delay(bitbang);
366 value <<= 1; 266 value <<= 1;
367 } 267 }
368 268
369 /* 269 /*
370 * Tri-state the MDIO line. 270 * Tri-state the MDIO line.
371 */ 271 */
372 mdio_tristate(bus); 272 mdio_tristate(bitbang);
373 mdc(bus, 0); 273 mdc(bitbang, 0);
374 mii_delay(bus); 274 mii_delay(bitbang);
375 mdc(bus, 1); 275 mdc(bitbang, 1);
376 mii_delay(bus); 276 mii_delay(bitbang);
277 return 0;
377} 278}
378 279
379int fs_mii_bitbang_init(struct fs_enet_mii_bus *bus) 280static int fs_enet_mii_bb_reset(struct mii_bus *bus)
281{
282 /*nothing here - dunno how to reset it*/
283 return 0;
284}
285
286static int fs_mii_bitbang_init(struct bb_info *bitbang, struct fs_mii_bb_platform_info* fmpi)
380{ 287{
381 const struct fs_mii_bus_info *bi = bus->bus_info;
382 int r; 288 int r;
383 289
384 r = bitbang_prep_bit(&bus->bitbang.mdio_dir, 290 bitbang->delay = fmpi->delay;
385 &bus->bitbang.mdio_dat, 291
386 &bus->bitbang.mdio_msk, 292 r = bitbang_prep_bit(&bitbang->mdio_dir,
387 bi->i.bitbang.mdio_port, 293 &bitbang->mdio_dir_msk,
388 bi->i.bitbang.mdio_bit); 294 &fmpi->mdio_dir);
389 if (r != 0) 295 if (r != 0)
390 return r; 296 return r;
391 297
392 r = bitbang_prep_bit(&bus->bitbang.mdc_dir, 298 r = bitbang_prep_bit(&bitbang->mdio_dat,
393 &bus->bitbang.mdc_dat, 299 &bitbang->mdio_dat_msk,
394 &bus->bitbang.mdc_msk, 300 &fmpi->mdio_dat);
395 bi->i.bitbang.mdc_port,
396 bi->i.bitbang.mdc_bit);
397 if (r != 0) 301 if (r != 0)
398 return r; 302 return r;
399 303
400 bus->mii_read = mii_read; 304 r = bitbang_prep_bit(&bitbang->mdc_dat,
401 bus->mii_write = mii_write; 305 &bitbang->mdc_msk,
306 &fmpi->mdc_dat);
307 if (r != 0)
308 return r;
402 309
403 return 0; 310 return 0;
404} 311}
312
313
314static int __devinit fs_enet_mdio_probe(struct device *dev)
315{
316 struct platform_device *pdev = to_platform_device(dev);
317 struct fs_mii_bb_platform_info *pdata;
318 struct mii_bus *new_bus;
319 struct bb_info *bitbang;
320 int err = 0;
321
322 if (NULL == dev)
323 return -EINVAL;
324
325 new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL);
326
327 if (NULL == new_bus)
328 return -ENOMEM;
329
330 bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);
331
332 if (NULL == bitbang)
333 return -ENOMEM;
334
335 new_bus->name = "BB MII Bus",
336 new_bus->read = &fs_enet_mii_bb_read,
337 new_bus->write = &fs_enet_mii_bb_write,
338 new_bus->reset = &fs_enet_mii_bb_reset,
339 new_bus->id = pdev->id;
340
341 new_bus->phy_mask = ~0x9;
342 pdata = (struct fs_mii_bb_platform_info *)pdev->dev.platform_data;
343
344 if (NULL == pdata) {
345 printk(KERN_ERR "gfar mdio %d: Missing platform data!\n", pdev->id);
346 return -ENODEV;
347 }
348
349 /*set up workspace*/
350 fs_mii_bitbang_init(bitbang, pdata);
351
352 new_bus->priv = bitbang;
353
354 new_bus->irq = pdata->irq;
355
356 new_bus->dev = dev;
357 dev_set_drvdata(dev, new_bus);
358
359 err = mdiobus_register(new_bus);
360
361 if (0 != err) {
362 printk (KERN_ERR "%s: Cannot register as MDIO bus\n",
363 new_bus->name);
364 goto bus_register_fail;
365 }
366
367 return 0;
368
369bus_register_fail:
370 kfree(bitbang);
371 kfree(new_bus);
372
373 return err;
374}
375
376
377static int fs_enet_mdio_remove(struct device *dev)
378{
379 struct mii_bus *bus = dev_get_drvdata(dev);
380
381 mdiobus_unregister(bus);
382
383 dev_set_drvdata(dev, NULL);
384
385 iounmap((void *) (&bus->priv));
386 bus->priv = NULL;
387 kfree(bus);
388
389 return 0;
390}
391
392static struct device_driver fs_enet_bb_mdio_driver = {
393 .name = "fsl-bb-mdio",
394 .bus = &platform_bus_type,
395 .probe = fs_enet_mdio_probe,
396 .remove = fs_enet_mdio_remove,
397};
398
399int fs_enet_mdio_bb_init(void)
400{
401 return driver_register(&fs_enet_bb_mdio_driver);
402}
403
404void fs_enet_mdio_bb_exit(void)
405{
406 driver_unregister(&fs_enet_bb_mdio_driver);
407}
408
diff --git a/drivers/net/fs_enet/mii-fec.c b/drivers/net/fs_enet/mii-fec.c
new file mode 100644
index 000000000000..1328e10caa35
--- /dev/null
+++ b/drivers/net/fs_enet/mii-fec.c
@@ -0,0 +1,243 @@
1/*
2 * Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
3 *
4 * Copyright (c) 2003 Intracom S.A.
5 * by Pantelis Antoniou <panto@intracom.gr>
6 *
7 * 2005 (c) MontaVista Software, Inc.
8 * Vitaly Bordug <vbordug@ru.mvista.com>
9 *
10 * This file is licensed under the terms of the GNU General Public License
11 * version 2. This program is licensed "as is" without any warranty of any
12 * kind, whether express or implied.
13 */
14
15
16#include <linux/config.h>
17#include <linux/module.h>
18#include <linux/types.h>
19#include <linux/kernel.h>
20#include <linux/sched.h>
21#include <linux/string.h>
22#include <linux/ptrace.h>
23#include <linux/errno.h>
24#include <linux/ioport.h>
25#include <linux/slab.h>
26#include <linux/interrupt.h>
27#include <linux/pci.h>
28#include <linux/init.h>
29#include <linux/delay.h>
30#include <linux/netdevice.h>
31#include <linux/etherdevice.h>
32#include <linux/skbuff.h>
33#include <linux/spinlock.h>
34#include <linux/mii.h>
35#include <linux/ethtool.h>
36#include <linux/bitops.h>
37#include <linux/platform_device.h>
38
39#include <asm/pgtable.h>
40#include <asm/irq.h>
41#include <asm/uaccess.h>
42
43#include "fs_enet.h"
44#include "fec.h"
45
46/* Make MII read/write commands for the FEC.
47*/
48#define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
49#define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | (VAL & 0xffff))
50#define mk_mii_end 0
51
52#define FEC_MII_LOOPS 10000
53
54static int match_has_phy (struct device *dev, void* data)
55{
56 struct platform_device* pdev = container_of(dev, struct platform_device, dev);
57 struct fs_platform_info* fpi;
58 if(strcmp(pdev->name, (char*)data))
59 {
60 return 0;
61 }
62
63 fpi = pdev->dev.platform_data;
64 if((fpi)&&(fpi->has_phy))
65 return 1;
66 return 0;
67}
68
69static int fs_mii_fec_init(struct fec_info* fec, struct fs_mii_fec_platform_info *fmpi)
70{
71 struct resource *r;
72 fec_t *fecp;
73 char* name = "fsl-cpm-fec";
74
75 /* we need fec in order to be useful */
76 struct platform_device *fec_pdev =
77 container_of(bus_find_device(&platform_bus_type, NULL, name, match_has_phy),
78 struct platform_device, dev);
79
80 if(fec_pdev == NULL) {
81 printk(KERN_ERR"Unable to find PHY for %s", name);
82 return -ENODEV;
83 }
84
85 r = platform_get_resource_byname(fec_pdev, IORESOURCE_MEM, "regs");
86
87 fec->fecp = fecp = (fec_t*)ioremap(r->start,sizeof(fec_t));
88 fec->mii_speed = fmpi->mii_speed;
89
90 setbits32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
91 setbits32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
92 out_be32(&fecp->fec_ievent, FEC_ENET_MII);
93 out_be32(&fecp->fec_mii_speed, fec->mii_speed);
94
95 return 0;
96}
97
98static int fs_enet_fec_mii_read(struct mii_bus *bus , int phy_id, int location)
99{
100 struct fec_info* fec = bus->priv;
101 fec_t *fecp = fec->fecp;
102 int i, ret = -1;
103
104 if ((in_be32(&fecp->fec_r_cntrl) & FEC_RCNTRL_MII_MODE) == 0)
105 BUG();
106
107 /* Add PHY address to register command. */
108 out_be32(&fecp->fec_mii_data, (phy_id << 23) | mk_mii_read(location));
109
110 for (i = 0; i < FEC_MII_LOOPS; i++)
111 if ((in_be32(&fecp->fec_ievent) & FEC_ENET_MII) != 0)
112 break;
113
114 if (i < FEC_MII_LOOPS) {
115 out_be32(&fecp->fec_ievent, FEC_ENET_MII);
116 ret = in_be32(&fecp->fec_mii_data) & 0xffff;
117 }
118
119 return ret;
120
121}
122
123static int fs_enet_fec_mii_write(struct mii_bus *bus, int phy_id, int location, u16 val)
124{
125 struct fec_info* fec = bus->priv;
126 fec_t *fecp = fec->fecp;
127 int i;
128
129 /* this must never happen */
130 if ((in_be32(&fecp->fec_r_cntrl) & FEC_RCNTRL_MII_MODE) == 0)
131 BUG();
132
133 /* Add PHY address to register command. */
134 out_be32(&fecp->fec_mii_data, (phy_id << 23) | mk_mii_write(location, val));
135
136 for (i = 0; i < FEC_MII_LOOPS; i++)
137 if ((in_be32(&fecp->fec_ievent) & FEC_ENET_MII) != 0)
138 break;
139
140 if (i < FEC_MII_LOOPS)
141 out_be32(&fecp->fec_ievent, FEC_ENET_MII);
142
143 return 0;
144
145}
146
147static int fs_enet_fec_mii_reset(struct mii_bus *bus)
148{
149 /* nothing here - for now */
150 return 0;
151}
152
153static int __devinit fs_enet_fec_mdio_probe(struct device *dev)
154{
155 struct platform_device *pdev = to_platform_device(dev);
156 struct fs_mii_fec_platform_info *pdata;
157 struct mii_bus *new_bus;
158 struct fec_info *fec;
159 int err = 0;
160 if (NULL == dev)
161 return -EINVAL;
162 new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL);
163
164 if (NULL == new_bus)
165 return -ENOMEM;
166
167 fec = kzalloc(sizeof(struct fec_info), GFP_KERNEL);
168
169 if (NULL == fec)
170 return -ENOMEM;
171
172 new_bus->name = "FEC MII Bus",
173 new_bus->read = &fs_enet_fec_mii_read,
174 new_bus->write = &fs_enet_fec_mii_write,
175 new_bus->reset = &fs_enet_fec_mii_reset,
176 new_bus->id = pdev->id;
177
178 pdata = (struct fs_mii_fec_platform_info *)pdev->dev.platform_data;
179
180 if (NULL == pdata) {
181 printk(KERN_ERR "fs_enet FEC mdio %d: Missing platform data!\n", pdev->id);
182 return -ENODEV;
183 }
184
185 /*set up workspace*/
186
187 fs_mii_fec_init(fec, pdata);
188 new_bus->priv = fec;
189
190 new_bus->irq = pdata->irq;
191
192 new_bus->dev = dev;
193 dev_set_drvdata(dev, new_bus);
194
195 err = mdiobus_register(new_bus);
196
197 if (0 != err) {
198 printk (KERN_ERR "%s: Cannot register as MDIO bus\n",
199 new_bus->name);
200 goto bus_register_fail;
201 }
202
203 return 0;
204
205bus_register_fail:
206 kfree(new_bus);
207
208 return err;
209}
210
211
212static int fs_enet_fec_mdio_remove(struct device *dev)
213{
214 struct mii_bus *bus = dev_get_drvdata(dev);
215
216 mdiobus_unregister(bus);
217
218 dev_set_drvdata(dev, NULL);
219 kfree(bus->priv);
220
221 bus->priv = NULL;
222 kfree(bus);
223
224 return 0;
225}
226
227static struct device_driver fs_enet_fec_mdio_driver = {
228 .name = "fsl-cpm-fec-mdio",
229 .bus = &platform_bus_type,
230 .probe = fs_enet_fec_mdio_probe,
231 .remove = fs_enet_fec_mdio_remove,
232};
233
234int fs_enet_mdio_fec_init(void)
235{
236 return driver_register(&fs_enet_fec_mdio_driver);
237}
238
239void fs_enet_mdio_fec_exit(void)
240{
241 driver_unregister(&fs_enet_fec_mdio_driver);
242}
243
diff --git a/drivers/net/fs_enet/mii-fixed.c b/drivers/net/fs_enet/mii-fixed.c
deleted file mode 100644
index ae4a9c3bb393..000000000000
--- a/drivers/net/fs_enet/mii-fixed.c
+++ /dev/null
@@ -1,91 +0,0 @@
1/*
2 * Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
3 *
4 * Copyright (c) 2003 Intracom S.A.
5 * by Pantelis Antoniou <panto@intracom.gr>
6 *
7 * 2005 (c) MontaVista Software, Inc.
8 * Vitaly Bordug <vbordug@ru.mvista.com>
9 *
10 * This file is licensed under the terms of the GNU General Public License
11 * version 2. This program is licensed "as is" without any warranty of any
12 * kind, whether express or implied.
13 */
14
15
16#include <linux/module.h>
17#include <linux/types.h>
18#include <linux/kernel.h>
19#include <linux/sched.h>
20#include <linux/string.h>
21#include <linux/ptrace.h>
22#include <linux/errno.h>
23#include <linux/ioport.h>
24#include <linux/slab.h>
25#include <linux/interrupt.h>
26#include <linux/pci.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/netdevice.h>
30#include <linux/etherdevice.h>
31#include <linux/skbuff.h>
32#include <linux/spinlock.h>
33#include <linux/mii.h>
34#include <linux/ethtool.h>
35#include <linux/bitops.h>
36
37#include <asm/pgtable.h>
38#include <asm/irq.h>
39#include <asm/uaccess.h>
40
41#include "fs_enet.h"
42
43static const u16 mii_regs[7] = {
44 0x3100,
45 0x786d,
46 0x0fff,
47 0x0fff,
48 0x01e1,
49 0x45e1,
50 0x0003,
51};
52
53static int mii_read(struct fs_enet_mii_bus *bus, int phy_id, int location)
54{
55 int ret = 0;
56
57 if ((unsigned int)location >= ARRAY_SIZE(mii_regs))
58 return -1;
59
60 if (location != 5)
61 ret = mii_regs[location];
62 else
63 ret = bus->fixed.lpa;
64
65 return ret;
66}
67
68static void mii_write(struct fs_enet_mii_bus *bus, int phy_id, int location, int val)
69{
70 /* do nothing */
71}
72
73int fs_mii_fixed_init(struct fs_enet_mii_bus *bus)
74{
75 const struct fs_mii_bus_info *bi = bus->bus_info;
76
77 bus->fixed.lpa = 0x45e1; /* default 100Mb, full duplex */
78
79 /* if speed is fixed at 10Mb, remove 100Mb modes */
80 if (bi->i.fixed.speed == 10)
81 bus->fixed.lpa &= ~LPA_100;
82
83 /* if duplex is half, remove full duplex modes */
84 if (bi->i.fixed.duplex == 0)
85 bus->fixed.lpa &= ~LPA_DUPLEX;
86
87 bus->mii_read = mii_read;
88 bus->mii_write = mii_write;
89
90 return 0;
91}
diff --git a/drivers/net/gt96100eth.c b/drivers/net/gt96100eth.c
index 49dacc6e35aa..2b4db7414475 100644
--- a/drivers/net/gt96100eth.c
+++ b/drivers/net/gt96100eth.c
@@ -699,7 +699,6 @@ static int __init gt96100_probe1(struct pci_dev *pci, int port_num)
699 memset(gp, 0, sizeof(*gp)); // clear it 699 memset(gp, 0, sizeof(*gp)); // clear it
700 700
701 gp->port_num = port_num; 701 gp->port_num = port_num;
702 gp->io_size = GT96100_ETH_IO_SIZE;
703 gp->port_offset = port_num * GT96100_ETH_IO_SIZE; 702 gp->port_offset = port_num * GT96100_ETH_IO_SIZE;
704 gp->phy_addr = phy_addr; 703 gp->phy_addr = phy_addr;
705 gp->chip_rev = chip_rev; 704 gp->chip_rev = chip_rev;
@@ -1531,7 +1530,7 @@ static void gt96100_cleanup_module(void)
1531 + sizeof(gt96100_td_t) * TX_RING_SIZE, 1530 + sizeof(gt96100_td_t) * TX_RING_SIZE,
1532 gp->rx_ring); 1531 gp->rx_ring);
1533 free_netdev(gtif->dev); 1532 free_netdev(gtif->dev);
1534 release_region(gtif->iobase, gp->io_size); 1533 release_region(gtif->iobase, GT96100_ETH_IO_SIZE);
1535 } 1534 }
1536 } 1535 }
1537} 1536}
diff --git a/drivers/net/gt96100eth.h b/drivers/net/gt96100eth.h
index 2a8331938b84..3b62a87c7d7f 100644
--- a/drivers/net/gt96100eth.h
+++ b/drivers/net/gt96100eth.h
@@ -331,7 +331,6 @@ struct gt96100_private {
331 mib_counters_t mib; 331 mib_counters_t mib;
332 struct net_device_stats stats; 332 struct net_device_stats stats;
333 333
334 int io_size;
335 int port_num; // 0 or 1 334 int port_num; // 0 or 1
336 int chip_rev; 335 int chip_rev;
337 u32 port_offset; 336 u32 port_offset;
@@ -340,7 +339,6 @@ struct gt96100_private {
340 u32 last_psr; // last value of the port status register 339 u32 last_psr; // last value of the port status register
341 340
342 int options; /* User-settable misc. driver options. */ 341 int options; /* User-settable misc. driver options. */
343 int drv_flags;
344 struct timer_list timer; 342 struct timer_list timer;
345 spinlock_t lock; /* Serialise access to device */ 343 spinlock_t lock; /* Serialise access to device */
346}; 344};
diff --git a/drivers/net/hamachi.c b/drivers/net/hamachi.c
index 7bcd939c6edd..409c6aab0411 100644
--- a/drivers/net/hamachi.c
+++ b/drivers/net/hamachi.c
@@ -20,22 +20,15 @@
20 20
21 Support and updates available at 21 Support and updates available at
22 http://www.scyld.com/network/hamachi.html 22 http://www.scyld.com/network/hamachi.html
23 [link no longer provides useful info -jgarzik]
23 or 24 or
24 http://www.parl.clemson.edu/~keithu/hamachi.html 25 http://www.parl.clemson.edu/~keithu/hamachi.html
25 26
26
27
28 Linux kernel changelog:
29
30 LK1.0.1:
31 - fix lack of pci_dev<->dev association
32 - ethtool support (jgarzik)
33
34*/ 27*/
35 28
36#define DRV_NAME "hamachi" 29#define DRV_NAME "hamachi"
37#define DRV_VERSION "1.01+LK1.0.1" 30#define DRV_VERSION "2.0"
38#define DRV_RELDATE "5/18/2001" 31#define DRV_RELDATE "June 27, 2006"
39 32
40 33
41/* A few user-configurable values. */ 34/* A few user-configurable values. */
@@ -608,7 +601,8 @@ static int __devinit hamachi_init_one (struct pci_dev *pdev,
608 pci_set_master(pdev); 601 pci_set_master(pdev);
609 602
610 i = pci_request_regions(pdev, DRV_NAME); 603 i = pci_request_regions(pdev, DRV_NAME);
611 if (i) return i; 604 if (i)
605 return i;
612 606
613 irq = pdev->irq; 607 irq = pdev->irq;
614 ioaddr = ioremap(base, 0x400); 608 ioaddr = ioremap(base, 0x400);
diff --git a/drivers/net/hamradio/bpqether.c b/drivers/net/hamradio/bpqether.c
index 0641f54fc638..889f338132fa 100644
--- a/drivers/net/hamradio/bpqether.c
+++ b/drivers/net/hamradio/bpqether.c
@@ -122,6 +122,12 @@ struct bpqdev {
122 122
123static LIST_HEAD(bpq_devices); 123static LIST_HEAD(bpq_devices);
124 124
125/*
126 * bpqether network devices are paired with ethernet devices below them, so
127 * form a special "super class" of normal ethernet devices; split their locks
128 * off into a separate class since they always nest.
129 */
130static struct lock_class_key bpq_netdev_xmit_lock_key;
125 131
126/* ------------------------------------------------------------------------ */ 132/* ------------------------------------------------------------------------ */
127 133
@@ -528,6 +534,7 @@ static int bpq_new_device(struct net_device *edev)
528 err = register_netdevice(ndev); 534 err = register_netdevice(ndev);
529 if (err) 535 if (err)
530 goto error; 536 goto error;
537 lockdep_set_class(&ndev->_xmit_lock, &bpq_netdev_xmit_lock_key);
531 538
532 /* List protected by RTNL */ 539 /* List protected by RTNL */
533 list_add_rcu(&bpq->bpq_list, &bpq_devices); 540 list_add_rcu(&bpq->bpq_list, &bpq_devices);
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index 3a42afab5036..43e3f33ed5e2 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -271,6 +271,7 @@ static int __init ifb_init_module(void)
271 for (i = 0; i < numifbs && !err; i++) 271 for (i = 0; i < numifbs && !err; i++)
272 err = ifb_init_one(i); 272 err = ifb_init_one(i);
273 if (err) { 273 if (err) {
274 i--;
274 while (--i >= 0) 275 while (--i >= 0)
275 ifb_free_one(i); 276 ifb_free_one(i);
276 } 277 }
diff --git a/drivers/net/irda/ali-ircc.c b/drivers/net/irda/ali-ircc.c
index bf1fca5a3fa0..e3c8cd5eca67 100644
--- a/drivers/net/irda/ali-ircc.c
+++ b/drivers/net/irda/ali-ircc.c
@@ -146,7 +146,7 @@ static int __init ali_ircc_init(void)
146{ 146{
147 ali_chip_t *chip; 147 ali_chip_t *chip;
148 chipio_t info; 148 chipio_t info;
149 int ret = -ENODEV; 149 int ret;
150 int cfg, cfg_base; 150 int cfg, cfg_base;
151 int reg, revision; 151 int reg, revision;
152 int i = 0; 152 int i = 0;
@@ -160,6 +160,7 @@ static int __init ali_ircc_init(void)
160 return ret; 160 return ret;
161 } 161 }
162 162
163 ret = -ENODEV;
163 164
164 /* Probe for all the ALi chipsets we know about */ 165 /* Probe for all the ALi chipsets we know about */
165 for (chip= chips; chip->name; chip++, i++) 166 for (chip= chips; chip->name; chip++, i++)
diff --git a/drivers/net/irda/smsc-ircc2.c b/drivers/net/irda/smsc-ircc2.c
index a4674044bd6f..2eff45bedc7c 100644
--- a/drivers/net/irda/smsc-ircc2.c
+++ b/drivers/net/irda/smsc-ircc2.c
@@ -2353,7 +2353,7 @@ static int __init smsc_superio_lpc(unsigned short cfg_base)
2353#ifdef CONFIG_PCI 2353#ifdef CONFIG_PCI
2354#define PCIID_VENDOR_INTEL 0x8086 2354#define PCIID_VENDOR_INTEL 0x8086
2355#define PCIID_VENDOR_ALI 0x10b9 2355#define PCIID_VENDOR_ALI 0x10b9
2356static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __devinitdata = { 2356static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __initdata = {
2357 { 2357 {
2358 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */ 2358 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2359 .device = 0x24cc, 2359 .device = 0x24cc,
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
index b91e082483f6..7bbd447289b5 100644
--- a/drivers/net/ixgb/ixgb_main.c
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -1173,7 +1173,7 @@ ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
1173 uint16_t ipcse, tucse, mss; 1173 uint16_t ipcse, tucse, mss;
1174 int err; 1174 int err;
1175 1175
1176 if(likely(skb_shinfo(skb)->gso_size)) { 1176 if (likely(skb_is_gso(skb))) {
1177 if (skb_header_cloned(skb)) { 1177 if (skb_header_cloned(skb)) {
1178 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); 1178 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1179 if (err) 1179 if (err)
@@ -1281,7 +1281,7 @@ ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1281 1281
1282 while(len) { 1282 while(len) {
1283 buffer_info = &tx_ring->buffer_info[i]; 1283 buffer_info = &tx_ring->buffer_info[i];
1284 size = min(len, IXGB_MAX_JUMBO_FRAME_SIZE); 1284 size = min(len, IXGB_MAX_DATA_PER_TXD);
1285 buffer_info->length = size; 1285 buffer_info->length = size;
1286 buffer_info->dma = 1286 buffer_info->dma =
1287 pci_map_single(adapter->pdev, 1287 pci_map_single(adapter->pdev,
@@ -1306,7 +1306,7 @@ ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1306 1306
1307 while(len) { 1307 while(len) {
1308 buffer_info = &tx_ring->buffer_info[i]; 1308 buffer_info = &tx_ring->buffer_info[i];
1309 size = min(len, IXGB_MAX_JUMBO_FRAME_SIZE); 1309 size = min(len, IXGB_MAX_DATA_PER_TXD);
1310 buffer_info->length = size; 1310 buffer_info->length = size;
1311 buffer_info->dma = 1311 buffer_info->dma =
1312 pci_map_page(adapter->pdev, 1312 pci_map_page(adapter->pdev,
diff --git a/drivers/net/lance.c b/drivers/net/lance.c
index c1c3452c90ca..5b4dbfe5fb77 100644
--- a/drivers/net/lance.c
+++ b/drivers/net/lance.c
@@ -326,7 +326,7 @@ MODULE_PARM_DESC(dma, "LANCE/PCnet ISA DMA channel (ignored for some devices)");
326MODULE_PARM_DESC(irq, "LANCE/PCnet IRQ number (ignored for some devices)"); 326MODULE_PARM_DESC(irq, "LANCE/PCnet IRQ number (ignored for some devices)");
327MODULE_PARM_DESC(lance_debug, "LANCE/PCnet debug level (0-7)"); 327MODULE_PARM_DESC(lance_debug, "LANCE/PCnet debug level (0-7)");
328 328
329int init_module(void) 329int __init init_module(void)
330{ 330{
331 struct net_device *dev; 331 struct net_device *dev;
332 int this_dev, found = 0; 332 int this_dev, found = 0;
diff --git a/drivers/net/lne390.c b/drivers/net/lne390.c
index 646e89fc3562..c0ec7f6abcb2 100644
--- a/drivers/net/lne390.c
+++ b/drivers/net/lne390.c
@@ -406,7 +406,7 @@ MODULE_PARM_DESC(mem, "memory base address(es)");
406MODULE_DESCRIPTION("Mylex LNE390A/B EISA Ethernet driver"); 406MODULE_DESCRIPTION("Mylex LNE390A/B EISA Ethernet driver");
407MODULE_LICENSE("GPL"); 407MODULE_LICENSE("GPL");
408 408
409int init_module(void) 409int __init init_module(void)
410{ 410{
411 struct net_device *dev; 411 struct net_device *dev;
412 int this_dev, found = 0; 412 int this_dev, found = 0;
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index 43fef7de8cb9..997cbce9af6e 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -139,7 +139,7 @@ static int loopback_xmit(struct sk_buff *skb, struct net_device *dev)
139#endif 139#endif
140 140
141#ifdef LOOPBACK_TSO 141#ifdef LOOPBACK_TSO
142 if (skb_shinfo(skb)->gso_size) { 142 if (skb_is_gso(skb)) {
143 BUG_ON(skb->protocol != htons(ETH_P_IP)); 143 BUG_ON(skb->protocol != htons(ETH_P_IP));
144 BUG_ON(skb->nh.iph->protocol != IPPROTO_TCP); 144 BUG_ON(skb->nh.iph->protocol != IPPROTO_TCP);
145 145
diff --git a/drivers/net/mace.c b/drivers/net/mace.c
index f2c0bf89f0c7..29e4b5aa6ead 100644
--- a/drivers/net/mace.c
+++ b/drivers/net/mace.c
@@ -242,12 +242,12 @@ static int __devinit mace_probe(struct macio_dev *mdev, const struct of_device_i
242 } 242 }
243 rc = request_irq(mp->tx_dma_intr, mace_txdma_intr, 0, "MACE-txdma", dev); 243 rc = request_irq(mp->tx_dma_intr, mace_txdma_intr, 0, "MACE-txdma", dev);
244 if (rc) { 244 if (rc) {
245 printk(KERN_ERR "MACE: can't get irq %d\n", mace->intrs[1].line); 245 printk(KERN_ERR "MACE: can't get irq %d\n", mp->tx_dma_intr);
246 goto err_free_irq; 246 goto err_free_irq;
247 } 247 }
248 rc = request_irq(mp->rx_dma_intr, mace_rxdma_intr, 0, "MACE-rxdma", dev); 248 rc = request_irq(mp->rx_dma_intr, mace_rxdma_intr, 0, "MACE-rxdma", dev);
249 if (rc) { 249 if (rc) {
250 printk(KERN_ERR "MACE: can't get irq %d\n", mace->intrs[2].line); 250 printk(KERN_ERR "MACE: can't get irq %d\n", mp->rx_dma_intr);
251 goto err_free_tx_irq; 251 goto err_free_tx_irq;
252 } 252 }
253 253
diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index 760c61b98867..eeab1df5bef3 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -385,6 +385,8 @@ static int mv643xx_eth_receive_queue(struct net_device *dev, int budget)
385 struct pkt_info pkt_info; 385 struct pkt_info pkt_info;
386 386
387 while (budget-- > 0 && eth_port_receive(mp, &pkt_info) == ETH_OK) { 387 while (budget-- > 0 && eth_port_receive(mp, &pkt_info) == ETH_OK) {
388 dma_unmap_single(NULL, pkt_info.buf_ptr, RX_SKB_SIZE,
389 DMA_FROM_DEVICE);
388 mp->rx_desc_count--; 390 mp->rx_desc_count--;
389 received_packets++; 391 received_packets++;
390 392
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index 72aad42db7b4..9bdd43ab3573 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -177,6 +177,7 @@ struct myri10ge_priv {
177 struct work_struct watchdog_work; 177 struct work_struct watchdog_work;
178 struct timer_list watchdog_timer; 178 struct timer_list watchdog_timer;
179 int watchdog_tx_done; 179 int watchdog_tx_done;
180 int watchdog_tx_req;
180 int watchdog_resets; 181 int watchdog_resets;
181 int tx_linearized; 182 int tx_linearized;
182 int pause; 183 int pause;
@@ -188,7 +189,6 @@ struct myri10ge_priv {
188 int vendor_specific_offset; 189 int vendor_specific_offset;
189 u32 devctl; 190 u32 devctl;
190 u16 msi_flags; 191 u16 msi_flags;
191 u32 pm_state[16];
192 u32 read_dma; 192 u32 read_dma;
193 u32 write_dma; 193 u32 write_dma;
194 u32 read_write_dma; 194 u32 read_write_dma;
@@ -449,6 +449,7 @@ static int myri10ge_load_hotplug_firmware(struct myri10ge_priv *mgp, u32 * size)
449 struct mcp_gen_header *hdr; 449 struct mcp_gen_header *hdr;
450 size_t hdr_offset; 450 size_t hdr_offset;
451 int status; 451 int status;
452 unsigned i;
452 453
453 if ((status = request_firmware(&fw, mgp->fw_name, dev)) < 0) { 454 if ((status = request_firmware(&fw, mgp->fw_name, dev)) < 0) {
454 dev_err(dev, "Unable to load %s firmware image via hotplug\n", 455 dev_err(dev, "Unable to load %s firmware image via hotplug\n",
@@ -480,18 +481,12 @@ static int myri10ge_load_hotplug_firmware(struct myri10ge_priv *mgp, u32 * size)
480 goto abort_with_fw; 481 goto abort_with_fw;
481 482
482 crc = crc32(~0, fw->data, fw->size); 483 crc = crc32(~0, fw->data, fw->size);
483 if (mgp->tx.boundary == 2048) { 484 for (i = 0; i < fw->size; i += 256) {
484 /* Avoid PCI burst on chipset with unaligned completions. */ 485 myri10ge_pio_copy(mgp->sram + MYRI10GE_FW_OFFSET + i,
485 int i; 486 fw->data + i,
486 __iomem u32 *ptr = (__iomem u32 *) (mgp->sram + 487 min(256U, (unsigned)(fw->size - i)));
487 MYRI10GE_FW_OFFSET); 488 mb();
488 for (i = 0; i < fw->size / 4; i++) { 489 readb(mgp->sram);
489 __raw_writel(((u32 *) fw->data)[i], ptr + i);
490 wmb();
491 }
492 } else {
493 myri10ge_pio_copy(mgp->sram + MYRI10GE_FW_OFFSET, fw->data,
494 fw->size);
495 } 490 }
496 /* corruption checking is good for parity recovery and buggy chipset */ 491 /* corruption checking is good for parity recovery and buggy chipset */
497 memcpy_fromio(fw->data, mgp->sram + MYRI10GE_FW_OFFSET, fw->size); 492 memcpy_fromio(fw->data, mgp->sram + MYRI10GE_FW_OFFSET, fw->size);
@@ -621,7 +616,7 @@ static int myri10ge_load_firmware(struct myri10ge_priv *mgp)
621 return -ENXIO; 616 return -ENXIO;
622 } 617 }
623 dev_info(&mgp->pdev->dev, "handoff confirmed\n"); 618 dev_info(&mgp->pdev->dev, "handoff confirmed\n");
624 myri10ge_dummy_rdma(mgp, mgp->tx.boundary != 4096); 619 myri10ge_dummy_rdma(mgp, 1);
625 620
626 return 0; 621 return 0;
627} 622}
@@ -1289,6 +1284,7 @@ static const char myri10ge_gstrings_stats[][ETH_GSTRING_LEN] = {
1289 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors", 1284 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
1290 "tx_heartbeat_errors", "tx_window_errors", 1285 "tx_heartbeat_errors", "tx_window_errors",
1291 /* device-specific stats */ 1286 /* device-specific stats */
1287 "tx_boundary", "WC", "irq", "MSI",
1292 "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs", 1288 "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs",
1293 "serial_number", "tx_pkt_start", "tx_pkt_done", 1289 "serial_number", "tx_pkt_start", "tx_pkt_done",
1294 "tx_req", "tx_done", "rx_small_cnt", "rx_big_cnt", 1290 "tx_req", "tx_done", "rx_small_cnt", "rx_big_cnt",
@@ -1327,6 +1323,10 @@ myri10ge_get_ethtool_stats(struct net_device *netdev,
1327 for (i = 0; i < MYRI10GE_NET_STATS_LEN; i++) 1323 for (i = 0; i < MYRI10GE_NET_STATS_LEN; i++)
1328 data[i] = ((unsigned long *)&mgp->stats)[i]; 1324 data[i] = ((unsigned long *)&mgp->stats)[i];
1329 1325
1326 data[i++] = (unsigned int)mgp->tx.boundary;
1327 data[i++] = (unsigned int)(mgp->mtrr >= 0);
1328 data[i++] = (unsigned int)mgp->pdev->irq;
1329 data[i++] = (unsigned int)mgp->msi_enabled;
1330 data[i++] = (unsigned int)mgp->read_dma; 1330 data[i++] = (unsigned int)mgp->read_dma;
1331 data[i++] = (unsigned int)mgp->write_dma; 1331 data[i++] = (unsigned int)mgp->write_dma;
1332 data[i++] = (unsigned int)mgp->read_write_dma; 1332 data[i++] = (unsigned int)mgp->read_write_dma;
@@ -2112,7 +2112,7 @@ abort_linearize:
2112 } 2112 }
2113 idx = (idx + 1) & tx->mask; 2113 idx = (idx + 1) & tx->mask;
2114 } while (idx != last_idx); 2114 } while (idx != last_idx);
2115 if (skb_shinfo(skb)->gso_size) { 2115 if (skb_is_gso(skb)) {
2116 printk(KERN_ERR 2116 printk(KERN_ERR
2117 "myri10ge: %s: TSO but wanted to linearize?!?!?\n", 2117 "myri10ge: %s: TSO but wanted to linearize?!?!?\n",
2118 mgp->dev->name); 2118 mgp->dev->name);
@@ -2197,8 +2197,6 @@ static int myri10ge_change_mtu(struct net_device *dev, int new_mtu)
2197 * any other device, except if forced with myri10ge_ecrc_enable > 1. 2197 * any other device, except if forced with myri10ge_ecrc_enable > 1.
2198 */ 2198 */
2199 2199
2200#define PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_PCIE 0x005d
2201
2202static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp) 2200static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp)
2203{ 2201{
2204 struct pci_dev *bridge = mgp->pdev->bus->self; 2202 struct pci_dev *bridge = mgp->pdev->bus->self;
@@ -2410,18 +2408,24 @@ static int myri10ge_resume(struct pci_dev *pdev)
2410 return -EIO; 2408 return -EIO;
2411 } 2409 }
2412 myri10ge_restore_state(mgp); 2410 myri10ge_restore_state(mgp);
2413 pci_enable_device(pdev); 2411
2412 status = pci_enable_device(pdev);
2413 if (status < 0) {
2414 dev_err(&pdev->dev, "failed to enable device\n");
2415 return -EIO;
2416 }
2417
2414 pci_set_master(pdev); 2418 pci_set_master(pdev);
2415 2419
2416 status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED, 2420 status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED,
2417 netdev->name, mgp); 2421 netdev->name, mgp);
2418 if (status != 0) { 2422 if (status != 0) {
2419 dev_err(&pdev->dev, "failed to allocate IRQ\n"); 2423 dev_err(&pdev->dev, "failed to allocate IRQ\n");
2420 goto abort_with_msi; 2424 goto abort_with_enabled;
2421 } 2425 }
2422 2426
2423 myri10ge_reset(mgp); 2427 myri10ge_reset(mgp);
2424 myri10ge_dummy_rdma(mgp, mgp->tx.boundary != 4096); 2428 myri10ge_dummy_rdma(mgp, 1);
2425 2429
2426 /* Save configuration space to be restored if the 2430 /* Save configuration space to be restored if the
2427 * nic resets due to a parity error */ 2431 * nic resets due to a parity error */
@@ -2436,7 +2440,8 @@ static int myri10ge_resume(struct pci_dev *pdev)
2436 2440
2437 return 0; 2441 return 0;
2438 2442
2439abort_with_msi: 2443abort_with_enabled:
2444 pci_disable_device(pdev);
2440 return -EIO; 2445 return -EIO;
2441 2446
2442} 2447}
@@ -2538,7 +2543,8 @@ static void myri10ge_watchdog_timer(unsigned long arg)
2538 2543
2539 mgp = (struct myri10ge_priv *)arg; 2544 mgp = (struct myri10ge_priv *)arg;
2540 if (mgp->tx.req != mgp->tx.done && 2545 if (mgp->tx.req != mgp->tx.done &&
2541 mgp->tx.done == mgp->watchdog_tx_done) 2546 mgp->tx.done == mgp->watchdog_tx_done &&
2547 mgp->watchdog_tx_req != mgp->watchdog_tx_done)
2542 /* nic seems like it might be stuck.. */ 2548 /* nic seems like it might be stuck.. */
2543 schedule_work(&mgp->watchdog_work); 2549 schedule_work(&mgp->watchdog_work);
2544 else 2550 else
@@ -2547,6 +2553,7 @@ static void myri10ge_watchdog_timer(unsigned long arg)
2547 jiffies + myri10ge_watchdog_timeout * HZ); 2553 jiffies + myri10ge_watchdog_timeout * HZ);
2548 2554
2549 mgp->watchdog_tx_done = mgp->tx.done; 2555 mgp->watchdog_tx_done = mgp->tx.done;
2556 mgp->watchdog_tx_req = mgp->tx.req;
2550} 2557}
2551 2558
2552static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 2559static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
@@ -2737,11 +2744,10 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2737 dev_err(&pdev->dev, "register_netdev failed: %d\n", status); 2744 dev_err(&pdev->dev, "register_netdev failed: %d\n", status);
2738 goto abort_with_irq; 2745 goto abort_with_irq;
2739 } 2746 }
2740 2747 dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n",
2741 printk(KERN_INFO "myri10ge: %s: %s IRQ %d, tx bndry %d, fw %s, WC %s\n", 2748 (mgp->msi_enabled ? "MSI" : "xPIC"),
2742 netdev->name, (mgp->msi_enabled ? "MSI" : "xPIC"), 2749 pdev->irq, mgp->tx.boundary, mgp->fw_name,
2743 pdev->irq, mgp->tx.boundary, mgp->fw_name, 2750 (mgp->mtrr >= 0 ? "Enabled" : "Disabled"));
2744 (mgp->mtrr >= 0 ? "Enabled" : "Disabled"));
2745 2751
2746 return 0; 2752 return 0;
2747 2753
diff --git a/drivers/net/natsemi.c b/drivers/net/natsemi.c
index 9df2628be1e7..db0475a1102f 100644
--- a/drivers/net/natsemi.c
+++ b/drivers/net/natsemi.c
@@ -20,120 +20,9 @@
20 20
21 Support information and updates available at 21 Support information and updates available at
22 http://www.scyld.com/network/netsemi.html 22 http://www.scyld.com/network/netsemi.html
23 [link no longer provides useful info -jgarzik]
23 24
24 25
25 Linux kernel modifications:
26
27 Version 1.0.1:
28 - Spinlock fixes
29 - Bug fixes and better intr performance (Tjeerd)
30 Version 1.0.2:
31 - Now reads correct MAC address from eeprom
32 Version 1.0.3:
33 - Eliminate redundant priv->tx_full flag
34 - Call netif_start_queue from dev->tx_timeout
35 - wmb() in start_tx() to flush data
36 - Update Tx locking
37 - Clean up PCI enable (davej)
38 Version 1.0.4:
39 - Merge Donald Becker's natsemi.c version 1.07
40 Version 1.0.5:
41 - { fill me in }
42 Version 1.0.6:
43 * ethtool support (jgarzik)
44 * Proper initialization of the card (which sometimes
45 fails to occur and leaves the card in a non-functional
46 state). (uzi)
47
48 * Some documented register settings to optimize some
49 of the 100Mbit autodetection circuitry in rev C cards. (uzi)
50
51 * Polling of the PHY intr for stuff like link state
52 change and auto- negotiation to finally work properly. (uzi)
53
54 * One-liner removal of a duplicate declaration of
55 netdev_error(). (uzi)
56
57 Version 1.0.7: (Manfred Spraul)
58 * pci dma
59 * SMP locking update
60 * full reset added into tx_timeout
61 * correct multicast hash generation (both big and little endian)
62 [copied from a natsemi driver version
63 from Myrio Corporation, Greg Smith]
64 * suspend/resume
65
66 version 1.0.8 (Tim Hockin <thockin@sun.com>)
67 * ETHTOOL_* support
68 * Wake on lan support (Erik Gilling)
69 * MXDMA fixes for serverworks
70 * EEPROM reload
71
72 version 1.0.9 (Manfred Spraul)
73 * Main change: fix lack of synchronize
74 netif_close/netif_suspend against a last interrupt
75 or packet.
76 * do not enable superflous interrupts (e.g. the
77 drivers relies on TxDone - TxIntr not needed)
78 * wait that the hardware has really stopped in close
79 and suspend.
80 * workaround for the (at least) gcc-2.95.1 compiler
81 problem. Also simplifies the code a bit.
82 * disable_irq() in tx_timeout - needed to protect
83 against rx interrupts.
84 * stop the nic before switching into silent rx mode
85 for wol (required according to docu).
86
87 version 1.0.10:
88 * use long for ee_addr (various)
89 * print pointers properly (DaveM)
90 * include asm/irq.h (?)
91
92 version 1.0.11:
93 * check and reset if PHY errors appear (Adrian Sun)
94 * WoL cleanup (Tim Hockin)
95 * Magic number cleanup (Tim Hockin)
96 * Don't reload EEPROM on every reset (Tim Hockin)
97 * Save and restore EEPROM state across reset (Tim Hockin)
98 * MDIO Cleanup (Tim Hockin)
99 * Reformat register offsets/bits (jgarzik)
100
101 version 1.0.12:
102 * ETHTOOL_* further support (Tim Hockin)
103
104 version 1.0.13:
105 * ETHTOOL_[G]EEPROM support (Tim Hockin)
106
107 version 1.0.13:
108 * crc cleanup (Matt Domsch <Matt_Domsch@dell.com>)
109
110 version 1.0.14:
111 * Cleanup some messages and autoneg in ethtool (Tim Hockin)
112
113 version 1.0.15:
114 * Get rid of cable_magic flag
115 * use new (National provided) solution for cable magic issue
116
117 version 1.0.16:
118 * call netdev_rx() for RxErrors (Manfred Spraul)
119 * formatting and cleanups
120 * change options and full_duplex arrays to be zero
121 initialized
122 * enable only the WoL and PHY interrupts in wol mode
123
124 version 1.0.17:
125 * only do cable_magic on 83815 and early 83816 (Tim Hockin)
126 * create a function for rx refill (Manfred Spraul)
127 * combine drain_ring and init_ring (Manfred Spraul)
128 * oom handling (Manfred Spraul)
129 * hands_off instead of playing with netif_device_{de,a}ttach
130 (Manfred Spraul)
131 * be sure to write the MAC back to the chip (Manfred Spraul)
132 * lengthen EEPROM timeout, and always warn about timeouts
133 (Manfred Spraul)
134 * comments update (Manfred)
135 * do the right thing on a phy-reset (Manfred and Tim)
136
137 TODO: 26 TODO:
138 * big endian support with CFG:BEM instead of cpu_to_le32 27 * big endian support with CFG:BEM instead of cpu_to_le32
139*/ 28*/
@@ -165,8 +54,8 @@
165#include <asm/uaccess.h> 54#include <asm/uaccess.h>
166 55
167#define DRV_NAME "natsemi" 56#define DRV_NAME "natsemi"
168#define DRV_VERSION "1.07+LK1.0.17" 57#define DRV_VERSION "2.0"
169#define DRV_RELDATE "Sep 27, 2002" 58#define DRV_RELDATE "June 27, 2006"
170 59
171#define RX_OFFSET 2 60#define RX_OFFSET 2
172 61
diff --git a/drivers/net/ne2k-pci.c b/drivers/net/ne2k-pci.c
index fa50eb889408..34bdba9eec79 100644
--- a/drivers/net/ne2k-pci.c
+++ b/drivers/net/ne2k-pci.c
@@ -231,12 +231,12 @@ static int __devinit ne2k_pci_init_one (struct pci_dev *pdev,
231 irq = pdev->irq; 231 irq = pdev->irq;
232 232
233 if (!ioaddr || ((pci_resource_flags (pdev, 0) & IORESOURCE_IO) == 0)) { 233 if (!ioaddr || ((pci_resource_flags (pdev, 0) & IORESOURCE_IO) == 0)) {
234 printk (KERN_ERR PFX "no I/O resource at PCI BAR #0\n"); 234 dev_err(&pdev->dev, "no I/O resource at PCI BAR #0\n");
235 return -ENODEV; 235 return -ENODEV;
236 } 236 }
237 237
238 if (request_region (ioaddr, NE_IO_EXTENT, DRV_NAME) == NULL) { 238 if (request_region (ioaddr, NE_IO_EXTENT, DRV_NAME) == NULL) {
239 printk (KERN_ERR PFX "I/O resource 0x%x @ 0x%lx busy\n", 239 dev_err(&pdev->dev, "I/O resource 0x%x @ 0x%lx busy\n",
240 NE_IO_EXTENT, ioaddr); 240 NE_IO_EXTENT, ioaddr);
241 return -EBUSY; 241 return -EBUSY;
242 } 242 }
@@ -263,7 +263,7 @@ static int __devinit ne2k_pci_init_one (struct pci_dev *pdev,
263 /* Allocate net_device, dev->priv; fill in 8390 specific dev fields. */ 263 /* Allocate net_device, dev->priv; fill in 8390 specific dev fields. */
264 dev = alloc_ei_netdev(); 264 dev = alloc_ei_netdev();
265 if (!dev) { 265 if (!dev) {
266 printk (KERN_ERR PFX "cannot allocate ethernet device\n"); 266 dev_err(&pdev->dev, "cannot allocate ethernet device\n");
267 goto err_out_free_res; 267 goto err_out_free_res;
268 } 268 }
269 SET_MODULE_OWNER(dev); 269 SET_MODULE_OWNER(dev);
@@ -281,7 +281,8 @@ static int __devinit ne2k_pci_init_one (struct pci_dev *pdev,
281 while ((inb(ioaddr + EN0_ISR) & ENISR_RESET) == 0) 281 while ((inb(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
282 /* Limit wait: '2' avoids jiffy roll-over. */ 282 /* Limit wait: '2' avoids jiffy roll-over. */
283 if (jiffies - reset_start_time > 2) { 283 if (jiffies - reset_start_time > 2) {
284 printk(KERN_ERR PFX "Card failure (no reset ack).\n"); 284 dev_err(&pdev->dev,
285 "Card failure (no reset ack).\n");
285 goto err_out_free_netdev; 286 goto err_out_free_netdev;
286 } 287 }
287 288
diff --git a/drivers/net/ni5010.c b/drivers/net/ni5010.c
index a68bf474f6ed..d4be207d321a 100644
--- a/drivers/net/ni5010.c
+++ b/drivers/net/ni5010.c
@@ -1,17 +1,12 @@
1/* ni5010.c: A network driver for the MiCom-Interlan NI5010 ethercard. 1/* ni5010.c: A network driver for the MiCom-Interlan NI5010 ethercard.
2 * 2 *
3 * Copyright 1996,1997 Jan-Pascal van Best and Andreas Mohr. 3 * Copyright 1996,1997,2006 Jan-Pascal van Best and Andreas Mohr.
4 * 4 *
5 * This software may be used and distributed according to the terms 5 * This software may be used and distributed according to the terms
6 * of the GNU General Public License, incorporated herein by reference. 6 * of the GNU General Public License, incorporated herein by reference.
7 * 7 *
8 * The authors may be reached as: 8 * The authors may be reached as:
9 * jvbest@wi.leidenuniv.nl a.mohr@mailto.de 9 * janpascal@vanbest.org andi@lisas.de
10 * or by snail mail as
11 * Jan-Pascal van Best Andreas Mohr
12 * Klikspaanweg 58-4 Stauferstr. 6
13 * 2324 LZ Leiden D-71272 Renningen
14 * The Netherlands Germany
15 * 10 *
16 * Sources: 11 * Sources:
17 * Donald Becker's "skeleton.c" 12 * Donald Becker's "skeleton.c"
@@ -27,8 +22,9 @@
27 * 970503 v0.93: Fixed auto-irq failure on warm reboot (JB) 22 * 970503 v0.93: Fixed auto-irq failure on warm reboot (JB)
28 * 970623 v1.00: First kernel version (AM) 23 * 970623 v1.00: First kernel version (AM)
29 * 970814 v1.01: Added detection of onboard receive buffer size (AM) 24 * 970814 v1.01: Added detection of onboard receive buffer size (AM)
25 * 060611 v1.02: slight cleanup: email addresses, driver modernization.
30 * Bugs: 26 * Bugs:
31 * - None known... 27 * - not SMP-safe (no locking of I/O accesses)
32 * - Note that you have to patch ifconfig for the new /proc/net/dev 28 * - Note that you have to patch ifconfig for the new /proc/net/dev
33 * format. It gives incorrect stats otherwise. 29 * format. It gives incorrect stats otherwise.
34 * 30 *
@@ -39,7 +35,7 @@
39 * Complete merge with Andreas' driver 35 * Complete merge with Andreas' driver
40 * Implement ring buffers (Is this useful? You can't squeeze 36 * Implement ring buffers (Is this useful? You can't squeeze
41 * too many packet in a 2k buffer!) 37 * too many packet in a 2k buffer!)
42 * Implement DMA (Again, is this useful? Some docs says DMA is 38 * Implement DMA (Again, is this useful? Some docs say DMA is
43 * slower than programmed I/O) 39 * slower than programmed I/O)
44 * 40 *
45 * Compile with: 41 * Compile with:
@@ -47,7 +43,7 @@
47 * -DMODULE -c ni5010.c 43 * -DMODULE -c ni5010.c
48 * 44 *
49 * Insert with e.g.: 45 * Insert with e.g.:
50 * insmod ni5010.o io=0x300 irq=5 46 * insmod ni5010.ko io=0x300 irq=5
51 */ 47 */
52 48
53#include <linux/module.h> 49#include <linux/module.h>
@@ -69,15 +65,15 @@
69 65
70#include "ni5010.h" 66#include "ni5010.h"
71 67
72static const char *boardname = "NI5010"; 68static const char boardname[] = "NI5010";
73static char *version = 69static char version[] __initdata =
74 "ni5010.c: v1.00 06/23/97 Jan-Pascal van Best and Andreas Mohr\n"; 70 "ni5010.c: v1.02 20060611 Jan-Pascal van Best and Andreas Mohr\n";
75 71
76/* bufsize_rcv == 0 means autoprobing */ 72/* bufsize_rcv == 0 means autoprobing */
77static unsigned int bufsize_rcv; 73static unsigned int bufsize_rcv;
78 74
79#define jumpered_interrupts /* IRQ line jumpered on board */ 75#define JUMPERED_INTERRUPTS /* IRQ line jumpered on board */
80#undef jumpered_dma /* No DMA used */ 76#undef JUMPERED_DMA /* No DMA used */
81#undef FULL_IODETECT /* Only detect in portlist */ 77#undef FULL_IODETECT /* Only detect in portlist */
82 78
83#ifndef FULL_IODETECT 79#ifndef FULL_IODETECT
@@ -281,7 +277,7 @@ static int __init ni5010_probe1(struct net_device *dev, int ioaddr)
281 277
282 PRINTK2((KERN_DEBUG "%s: I/O #4 passed!\n", dev->name)); 278 PRINTK2((KERN_DEBUG "%s: I/O #4 passed!\n", dev->name));
283 279
284#ifdef jumpered_interrupts 280#ifdef JUMPERED_INTERRUPTS
285 if (dev->irq == 0xff) 281 if (dev->irq == 0xff)
286 ; 282 ;
287 else if (dev->irq < 2) { 283 else if (dev->irq < 2) {
@@ -305,7 +301,7 @@ static int __init ni5010_probe1(struct net_device *dev, int ioaddr)
305 } else if (dev->irq == 2) { 301 } else if (dev->irq == 2) {
306 dev->irq = 9; 302 dev->irq = 9;
307 } 303 }
308#endif /* jumpered_irq */ 304#endif /* JUMPERED_INTERRUPTS */
309 PRINTK2((KERN_DEBUG "%s: I/O #9 passed!\n", dev->name)); 305 PRINTK2((KERN_DEBUG "%s: I/O #9 passed!\n", dev->name));
310 306
311 /* DMA is not supported (yet?), so no use detecting it */ 307 /* DMA is not supported (yet?), so no use detecting it */
@@ -334,7 +330,7 @@ static int __init ni5010_probe1(struct net_device *dev, int ioaddr)
334 outw(0, IE_GP); /* Point GP at start of packet */ 330 outw(0, IE_GP); /* Point GP at start of packet */
335 outb(0, IE_RBUF); /* set buffer byte 0 to 0 again */ 331 outb(0, IE_RBUF); /* set buffer byte 0 to 0 again */
336 } 332 }
337 printk("// bufsize rcv/xmt=%d/%d\n", bufsize_rcv, NI5010_BUFSIZE); 333 printk("-> bufsize rcv/xmt=%d/%d\n", bufsize_rcv, NI5010_BUFSIZE);
338 memset(dev->priv, 0, sizeof(struct ni5010_local)); 334 memset(dev->priv, 0, sizeof(struct ni5010_local));
339 335
340 dev->open = ni5010_open; 336 dev->open = ni5010_open;
@@ -354,11 +350,9 @@ static int __init ni5010_probe1(struct net_device *dev, int ioaddr)
354 outb(0xff, EDLC_XCLR); /* Kill all pending xmt interrupts */ 350 outb(0xff, EDLC_XCLR); /* Kill all pending xmt interrupts */
355 351
356 printk(KERN_INFO "%s: NI5010 found at 0x%x, using IRQ %d", dev->name, ioaddr, dev->irq); 352 printk(KERN_INFO "%s: NI5010 found at 0x%x, using IRQ %d", dev->name, ioaddr, dev->irq);
357 if (dev->dma) printk(" & DMA %d", dev->dma); 353 if (dev->dma)
354 printk(" & DMA %d", dev->dma);
358 printk(".\n"); 355 printk(".\n");
359
360 printk(KERN_INFO "Join the NI5010 driver development team!\n");
361 printk(KERN_INFO "Mail to a.mohr@mailto.de or jvbest@wi.leidenuniv.nl\n");
362 return 0; 356 return 0;
363out: 357out:
364 release_region(dev->base_addr, NI5010_IO_EXTENT); 358 release_region(dev->base_addr, NI5010_IO_EXTENT);
@@ -371,7 +365,7 @@ out:
371 * 365 *
372 * This routine should set everything up anew at each open, even 366 * This routine should set everything up anew at each open, even
373 * registers that "should" only need to be set once at boot, so that 367 * registers that "should" only need to be set once at boot, so that
374 * there is non-reboot way to recover if something goes wrong. 368 * there is a non-reboot way to recover if something goes wrong.
375 */ 369 */
376 370
377static int ni5010_open(struct net_device *dev) 371static int ni5010_open(struct net_device *dev)
@@ -390,13 +384,13 @@ static int ni5010_open(struct net_device *dev)
390 * Always allocate the DMA channel after the IRQ, 384 * Always allocate the DMA channel after the IRQ,
391 * and clean up on failure. 385 * and clean up on failure.
392 */ 386 */
393#ifdef jumpered_dma 387#ifdef JUMPERED_DMA
394 if (request_dma(dev->dma, cardname)) { 388 if (request_dma(dev->dma, cardname)) {
395 printk(KERN_WARNING "%s: Cannot get dma %#2x\n", dev->name, dev->dma); 389 printk(KERN_WARNING "%s: Cannot get dma %#2x\n", dev->name, dev->dma);
396 free_irq(dev->irq, NULL); 390 free_irq(dev->irq, NULL);
397 return -EAGAIN; 391 return -EAGAIN;
398 } 392 }
399#endif /* jumpered_dma */ 393#endif /* JUMPERED_DMA */
400 394
401 PRINTK3((KERN_DEBUG "%s: passed open() #2\n", dev->name)); 395 PRINTK3((KERN_DEBUG "%s: passed open() #2\n", dev->name));
402 /* Reset the hardware here. Don't forget to set the station address. */ 396 /* Reset the hardware here. Don't forget to set the station address. */
@@ -633,7 +627,7 @@ static int ni5010_close(struct net_device *dev)
633 int ioaddr = dev->base_addr; 627 int ioaddr = dev->base_addr;
634 628
635 PRINTK2((KERN_DEBUG "%s: entering ni5010_close\n", dev->name)); 629 PRINTK2((KERN_DEBUG "%s: entering ni5010_close\n", dev->name));
636#ifdef jumpered_interrupts 630#ifdef JUMPERED_INTERRUPTS
637 free_irq(dev->irq, NULL); 631 free_irq(dev->irq, NULL);
638#endif 632#endif
639 /* Put card in held-RESET state */ 633 /* Put card in held-RESET state */
@@ -771,7 +765,7 @@ module_param(irq, int, 0);
771MODULE_PARM_DESC(io, "ni5010 I/O base address"); 765MODULE_PARM_DESC(io, "ni5010 I/O base address");
772MODULE_PARM_DESC(irq, "ni5010 IRQ number"); 766MODULE_PARM_DESC(irq, "ni5010 IRQ number");
773 767
774int init_module(void) 768static int __init ni5010_init_module(void)
775{ 769{
776 PRINTK2((KERN_DEBUG "%s: entering init_module\n", boardname)); 770 PRINTK2((KERN_DEBUG "%s: entering init_module\n", boardname));
777 /* 771 /*
@@ -792,13 +786,15 @@ int init_module(void)
792 return 0; 786 return 0;
793} 787}
794 788
795void cleanup_module(void) 789static void __exit ni5010_cleanup_module(void)
796{ 790{
797 PRINTK2((KERN_DEBUG "%s: entering cleanup_module\n", boardname)); 791 PRINTK2((KERN_DEBUG "%s: entering cleanup_module\n", boardname));
798 unregister_netdev(dev_ni5010); 792 unregister_netdev(dev_ni5010);
799 release_region(dev_ni5010->base_addr, NI5010_IO_EXTENT); 793 release_region(dev_ni5010->base_addr, NI5010_IO_EXTENT);
800 free_netdev(dev_ni5010); 794 free_netdev(dev_ni5010);
801} 795}
796module_init(ni5010_init_module);
797module_exit(ni5010_cleanup_module);
802#endif /* MODULE */ 798#endif /* MODULE */
803MODULE_LICENSE("GPL"); 799MODULE_LICENSE("GPL");
804 800
diff --git a/drivers/net/ni52.c b/drivers/net/ni52.c
index fa854c8fde75..4d52ecf8af56 100644
--- a/drivers/net/ni52.c
+++ b/drivers/net/ni52.c
@@ -1323,7 +1323,7 @@ MODULE_PARM_DESC(irq, "NI5210 IRQ number,required");
1323MODULE_PARM_DESC(memstart, "NI5210 memory base address,required"); 1323MODULE_PARM_DESC(memstart, "NI5210 memory base address,required");
1324MODULE_PARM_DESC(memend, "NI5210 memory end address,required"); 1324MODULE_PARM_DESC(memend, "NI5210 memory end address,required");
1325 1325
1326int init_module(void) 1326int __init init_module(void)
1327{ 1327{
1328 if(io <= 0x0 || !memend || !memstart || irq < 2) { 1328 if(io <= 0x0 || !memend || !memstart || irq < 2) {
1329 printk("ni52: Autoprobing not allowed for modules.\nni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n"); 1329 printk("ni52: Autoprobing not allowed for modules.\nni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
diff --git a/drivers/net/ni65.c b/drivers/net/ni65.c
index bb42ff218484..810cc572f5f7 100644
--- a/drivers/net/ni65.c
+++ b/drivers/net/ni65.c
@@ -1253,7 +1253,7 @@ MODULE_PARM_DESC(irq, "ni6510 IRQ number (ignored for some cards)");
1253MODULE_PARM_DESC(io, "ni6510 I/O base address"); 1253MODULE_PARM_DESC(io, "ni6510 I/O base address");
1254MODULE_PARM_DESC(dma, "ni6510 ISA DMA channel (ignored for some cards)"); 1254MODULE_PARM_DESC(dma, "ni6510 ISA DMA channel (ignored for some cards)");
1255 1255
1256int init_module(void) 1256int __init init_module(void)
1257{ 1257{
1258 dev_ni65 = ni65_probe(-1); 1258 dev_ni65 = ni65_probe(-1);
1259 return IS_ERR(dev_ni65) ? PTR_ERR(dev_ni65) : 0; 1259 return IS_ERR(dev_ni65) ? PTR_ERR(dev_ni65) : 0;
diff --git a/drivers/net/ns83820.c b/drivers/net/ns83820.c
index 70429108c40d..0e76859c90a2 100644
--- a/drivers/net/ns83820.c
+++ b/drivers/net/ns83820.c
@@ -803,7 +803,7 @@ static int ns83820_setup_rx(struct net_device *ndev)
803 803
804 writel(dev->IMR_cache, dev->base + IMR); 804 writel(dev->IMR_cache, dev->base + IMR);
805 writel(1, dev->base + IER); 805 writel(1, dev->base + IER);
806 spin_unlock_irq(&dev->misc_lock); 806 spin_unlock(&dev->misc_lock);
807 807
808 kick_rx(ndev); 808 kick_rx(ndev);
809 809
@@ -1012,8 +1012,6 @@ static void do_tx_done(struct net_device *ndev)
1012 struct ns83820 *dev = PRIV(ndev); 1012 struct ns83820 *dev = PRIV(ndev);
1013 u32 cmdsts, tx_done_idx, *desc; 1013 u32 cmdsts, tx_done_idx, *desc;
1014 1014
1015 spin_lock_irq(&dev->tx_lock);
1016
1017 dprintk("do_tx_done(%p)\n", ndev); 1015 dprintk("do_tx_done(%p)\n", ndev);
1018 tx_done_idx = dev->tx_done_idx; 1016 tx_done_idx = dev->tx_done_idx;
1019 desc = dev->tx_descs + (tx_done_idx * DESC_SIZE); 1017 desc = dev->tx_descs + (tx_done_idx * DESC_SIZE);
@@ -1069,7 +1067,6 @@ static void do_tx_done(struct net_device *ndev)
1069 netif_start_queue(ndev); 1067 netif_start_queue(ndev);
1070 netif_wake_queue(ndev); 1068 netif_wake_queue(ndev);
1071 } 1069 }
1072 spin_unlock_irq(&dev->tx_lock);
1073} 1070}
1074 1071
1075static void ns83820_cleanup_tx(struct ns83820 *dev) 1072static void ns83820_cleanup_tx(struct ns83820 *dev)
@@ -1281,11 +1278,13 @@ static struct ethtool_ops ops = {
1281 .get_link = ns83820_get_link 1278 .get_link = ns83820_get_link
1282}; 1279};
1283 1280
1281/* this function is called in irq context from the ISR */
1284static void ns83820_mib_isr(struct ns83820 *dev) 1282static void ns83820_mib_isr(struct ns83820 *dev)
1285{ 1283{
1286 spin_lock(&dev->misc_lock); 1284 unsigned long flags;
1285 spin_lock_irqsave(&dev->misc_lock, flags);
1287 ns83820_update_stats(dev); 1286 ns83820_update_stats(dev);
1288 spin_unlock(&dev->misc_lock); 1287 spin_unlock_irqrestore(&dev->misc_lock, flags);
1289} 1288}
1290 1289
1291static void ns83820_do_isr(struct net_device *ndev, u32 isr); 1290static void ns83820_do_isr(struct net_device *ndev, u32 isr);
@@ -1307,6 +1306,8 @@ static irqreturn_t ns83820_irq(int foo, void *data, struct pt_regs *regs)
1307static void ns83820_do_isr(struct net_device *ndev, u32 isr) 1306static void ns83820_do_isr(struct net_device *ndev, u32 isr)
1308{ 1307{
1309 struct ns83820 *dev = PRIV(ndev); 1308 struct ns83820 *dev = PRIV(ndev);
1309 unsigned long flags;
1310
1310#ifdef DEBUG 1311#ifdef DEBUG
1311 if (isr & ~(ISR_PHY | ISR_RXDESC | ISR_RXEARLY | ISR_RXOK | ISR_RXERR | ISR_TXIDLE | ISR_TXOK | ISR_TXDESC)) 1312 if (isr & ~(ISR_PHY | ISR_RXDESC | ISR_RXEARLY | ISR_RXOK | ISR_RXERR | ISR_TXIDLE | ISR_TXOK | ISR_TXDESC))
1312 Dprintk("odd isr? 0x%08x\n", isr); 1313 Dprintk("odd isr? 0x%08x\n", isr);
@@ -1321,10 +1322,10 @@ static void ns83820_do_isr(struct net_device *ndev, u32 isr)
1321 if ((ISR_RXDESC | ISR_RXOK) & isr) { 1322 if ((ISR_RXDESC | ISR_RXOK) & isr) {
1322 prefetch(dev->rx_info.next_rx_desc); 1323 prefetch(dev->rx_info.next_rx_desc);
1323 1324
1324 spin_lock_irq(&dev->misc_lock); 1325 spin_lock_irqsave(&dev->misc_lock, flags);
1325 dev->IMR_cache &= ~(ISR_RXDESC | ISR_RXOK); 1326 dev->IMR_cache &= ~(ISR_RXDESC | ISR_RXOK);
1326 writel(dev->IMR_cache, dev->base + IMR); 1327 writel(dev->IMR_cache, dev->base + IMR);
1327 spin_unlock_irq(&dev->misc_lock); 1328 spin_unlock_irqrestore(&dev->misc_lock, flags);
1328 1329
1329 tasklet_schedule(&dev->rx_tasklet); 1330 tasklet_schedule(&dev->rx_tasklet);
1330 //rx_irq(ndev); 1331 //rx_irq(ndev);
@@ -1370,16 +1371,18 @@ static void ns83820_do_isr(struct net_device *ndev, u32 isr)
1370 * work has accumulated 1371 * work has accumulated
1371 */ 1372 */
1372 if ((ISR_TXDESC | ISR_TXIDLE | ISR_TXOK | ISR_TXERR) & isr) { 1373 if ((ISR_TXDESC | ISR_TXIDLE | ISR_TXOK | ISR_TXERR) & isr) {
1374 spin_lock_irqsave(&dev->tx_lock, flags);
1373 do_tx_done(ndev); 1375 do_tx_done(ndev);
1376 spin_unlock_irqrestore(&dev->tx_lock, flags);
1374 1377
1375 /* Disable TxOk if there are no outstanding tx packets. 1378 /* Disable TxOk if there are no outstanding tx packets.
1376 */ 1379 */
1377 if ((dev->tx_done_idx == dev->tx_free_idx) && 1380 if ((dev->tx_done_idx == dev->tx_free_idx) &&
1378 (dev->IMR_cache & ISR_TXOK)) { 1381 (dev->IMR_cache & ISR_TXOK)) {
1379 spin_lock_irq(&dev->misc_lock); 1382 spin_lock_irqsave(&dev->misc_lock, flags);
1380 dev->IMR_cache &= ~ISR_TXOK; 1383 dev->IMR_cache &= ~ISR_TXOK;
1381 writel(dev->IMR_cache, dev->base + IMR); 1384 writel(dev->IMR_cache, dev->base + IMR);
1382 spin_unlock_irq(&dev->misc_lock); 1385 spin_unlock_irqrestore(&dev->misc_lock, flags);
1383 } 1386 }
1384 } 1387 }
1385 1388
@@ -1390,10 +1393,10 @@ static void ns83820_do_isr(struct net_device *ndev, u32 isr)
1390 * nature are expected, we must enable TxOk. 1393 * nature are expected, we must enable TxOk.
1391 */ 1394 */
1392 if ((ISR_TXIDLE & isr) && (dev->tx_done_idx != dev->tx_free_idx)) { 1395 if ((ISR_TXIDLE & isr) && (dev->tx_done_idx != dev->tx_free_idx)) {
1393 spin_lock_irq(&dev->misc_lock); 1396 spin_lock_irqsave(&dev->misc_lock, flags);
1394 dev->IMR_cache |= ISR_TXOK; 1397 dev->IMR_cache |= ISR_TXOK;
1395 writel(dev->IMR_cache, dev->base + IMR); 1398 writel(dev->IMR_cache, dev->base + IMR);
1396 spin_unlock_irq(&dev->misc_lock); 1399 spin_unlock_irqrestore(&dev->misc_lock, flags);
1397 } 1400 }
1398 1401
1399 /* MIB interrupt: one of the statistics counters is about to overflow */ 1402 /* MIB interrupt: one of the statistics counters is about to overflow */
@@ -1455,7 +1458,7 @@ static void ns83820_tx_timeout(struct net_device *ndev)
1455 u32 tx_done_idx, *desc; 1458 u32 tx_done_idx, *desc;
1456 unsigned long flags; 1459 unsigned long flags;
1457 1460
1458 local_irq_save(flags); 1461 spin_lock_irqsave(&dev->tx_lock, flags);
1459 1462
1460 tx_done_idx = dev->tx_done_idx; 1463 tx_done_idx = dev->tx_done_idx;
1461 desc = dev->tx_descs + (tx_done_idx * DESC_SIZE); 1464 desc = dev->tx_descs + (tx_done_idx * DESC_SIZE);
@@ -1482,7 +1485,7 @@ static void ns83820_tx_timeout(struct net_device *ndev)
1482 ndev->name, 1485 ndev->name,
1483 tx_done_idx, dev->tx_free_idx, le32_to_cpu(desc[DESC_CMDSTS])); 1486 tx_done_idx, dev->tx_free_idx, le32_to_cpu(desc[DESC_CMDSTS]));
1484 1487
1485 local_irq_restore(flags); 1488 spin_unlock_irqrestore(&dev->tx_lock, flags);
1486} 1489}
1487 1490
1488static void ns83820_tx_watch(unsigned long data) 1491static void ns83820_tx_watch(unsigned long data)
@@ -1832,7 +1835,7 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
1832 } else if (!pci_set_dma_mask(pci_dev, DMA_32BIT_MASK)) { 1835 } else if (!pci_set_dma_mask(pci_dev, DMA_32BIT_MASK)) {
1833 using_dac = 0; 1836 using_dac = 0;
1834 } else { 1837 } else {
1835 printk(KERN_WARNING "ns83820.c: pci_set_dma_mask failed!\n"); 1838 dev_warn(&pci_dev->dev, "pci_set_dma_mask failed!\n");
1836 return -ENODEV; 1839 return -ENODEV;
1837 } 1840 }
1838 1841
@@ -1855,7 +1858,7 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
1855 1858
1856 err = pci_enable_device(pci_dev); 1859 err = pci_enable_device(pci_dev);
1857 if (err) { 1860 if (err) {
1858 printk(KERN_INFO "ns83820: pci_enable_dev failed: %d\n", err); 1861 dev_info(&pci_dev->dev, "pci_enable_dev failed: %d\n", err);
1859 goto out_free; 1862 goto out_free;
1860 } 1863 }
1861 1864
@@ -1884,8 +1887,8 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
1884 err = request_irq(pci_dev->irq, ns83820_irq, IRQF_SHARED, 1887 err = request_irq(pci_dev->irq, ns83820_irq, IRQF_SHARED,
1885 DRV_NAME, ndev); 1888 DRV_NAME, ndev);
1886 if (err) { 1889 if (err) {
1887 printk(KERN_INFO "ns83820: unable to register irq %d\n", 1890 dev_info(&pci_dev->dev, "unable to register irq %d, err %d\n",
1888 pci_dev->irq); 1891 pci_dev->irq, err);
1889 goto out_disable; 1892 goto out_disable;
1890 } 1893 }
1891 1894
@@ -1899,7 +1902,7 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
1899 rtnl_lock(); 1902 rtnl_lock();
1900 err = dev_alloc_name(ndev, ndev->name); 1903 err = dev_alloc_name(ndev, ndev->name);
1901 if (err < 0) { 1904 if (err < 0) {
1902 printk(KERN_INFO "ns83820: unable to get netdev name: %d\n", err); 1905 dev_info(&pci_dev->dev, "unable to get netdev name: %d\n", err);
1903 goto out_free_irq; 1906 goto out_free_irq;
1904 } 1907 }
1905 1908
diff --git a/drivers/net/pci-skeleton.c b/drivers/net/pci-skeleton.c
index 3388ee1313ea..e0e293964042 100644
--- a/drivers/net/pci-skeleton.c
+++ b/drivers/net/pci-skeleton.c
@@ -601,7 +601,7 @@ static int __devinit netdrv_init_board (struct pci_dev *pdev,
601 /* dev zeroed in alloc_etherdev */ 601 /* dev zeroed in alloc_etherdev */
602 dev = alloc_etherdev (sizeof (*tp)); 602 dev = alloc_etherdev (sizeof (*tp));
603 if (dev == NULL) { 603 if (dev == NULL) {
604 printk (KERN_ERR PFX "unable to alloc new ethernet\n"); 604 dev_err(&pdev->dev, "unable to alloc new ethernet\n");
605 DPRINTK ("EXIT, returning -ENOMEM\n"); 605 DPRINTK ("EXIT, returning -ENOMEM\n");
606 return -ENOMEM; 606 return -ENOMEM;
607 } 607 }
@@ -631,14 +631,14 @@ static int __devinit netdrv_init_board (struct pci_dev *pdev,
631 631
632 /* make sure PCI base addr 0 is PIO */ 632 /* make sure PCI base addr 0 is PIO */
633 if (!(pio_flags & IORESOURCE_IO)) { 633 if (!(pio_flags & IORESOURCE_IO)) {
634 printk (KERN_ERR PFX "region #0 not a PIO resource, aborting\n"); 634 dev_err(&pdev->dev, "region #0 not a PIO resource, aborting\n");
635 rc = -ENODEV; 635 rc = -ENODEV;
636 goto err_out; 636 goto err_out;
637 } 637 }
638 638
639 /* make sure PCI base addr 1 is MMIO */ 639 /* make sure PCI base addr 1 is MMIO */
640 if (!(mmio_flags & IORESOURCE_MEM)) { 640 if (!(mmio_flags & IORESOURCE_MEM)) {
641 printk (KERN_ERR PFX "region #1 not an MMIO resource, aborting\n"); 641 dev_err(&pdev->dev, "region #1 not an MMIO resource, aborting\n");
642 rc = -ENODEV; 642 rc = -ENODEV;
643 goto err_out; 643 goto err_out;
644 } 644 }
@@ -646,12 +646,12 @@ static int __devinit netdrv_init_board (struct pci_dev *pdev,
646 /* check for weird/broken PCI region reporting */ 646 /* check for weird/broken PCI region reporting */
647 if ((pio_len < NETDRV_MIN_IO_SIZE) || 647 if ((pio_len < NETDRV_MIN_IO_SIZE) ||
648 (mmio_len < NETDRV_MIN_IO_SIZE)) { 648 (mmio_len < NETDRV_MIN_IO_SIZE)) {
649 printk (KERN_ERR PFX "Invalid PCI region size(s), aborting\n"); 649 dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n");
650 rc = -ENODEV; 650 rc = -ENODEV;
651 goto err_out; 651 goto err_out;
652 } 652 }
653 653
654 rc = pci_request_regions (pdev, "pci-skeleton"); 654 rc = pci_request_regions (pdev, MODNAME);
655 if (rc) 655 if (rc)
656 goto err_out; 656 goto err_out;
657 657
@@ -663,7 +663,7 @@ static int __devinit netdrv_init_board (struct pci_dev *pdev,
663 /* ioremap MMIO region */ 663 /* ioremap MMIO region */
664 ioaddr = ioremap (mmio_start, mmio_len); 664 ioaddr = ioremap (mmio_start, mmio_len);
665 if (ioaddr == NULL) { 665 if (ioaddr == NULL) {
666 printk (KERN_ERR PFX "cannot remap MMIO, aborting\n"); 666 dev_err(&pdev->dev, "cannot remap MMIO, aborting\n");
667 rc = -EIO; 667 rc = -EIO;
668 goto err_out_free_res; 668 goto err_out_free_res;
669 } 669 }
@@ -699,9 +699,10 @@ static int __devinit netdrv_init_board (struct pci_dev *pdev,
699 } 699 }
700 700
701 /* if unknown chip, assume array element #0, original RTL-8139 in this case */ 701 /* if unknown chip, assume array element #0, original RTL-8139 in this case */
702 printk (KERN_DEBUG PFX "PCI device %s: unknown chip version, assuming RTL-8139\n", 702 dev_printk (KERN_DEBUG, &pdev->dev,
703 pci_name(pdev)); 703 "unknown chip version, assuming RTL-8139\n");
704 printk (KERN_DEBUG PFX "PCI device %s: TxConfig = 0x%lx\n", pci_name(pdev), NETDRV_R32 (TxConfig)); 704 dev_printk (KERN_DEBUG, &pdev->dev, "TxConfig = 0x%lx\n",
705 NETDRV_R32 (TxConfig));
705 tp->chipset = 0; 706 tp->chipset = 0;
706 707
707match: 708match:
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index 9bae77ce1314..4122bb46f5ff 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -345,6 +345,7 @@ typedef struct local_info_t {
345 void __iomem *dingo_ccr; /* only used for CEM56 cards */ 345 void __iomem *dingo_ccr; /* only used for CEM56 cards */
346 unsigned last_ptr_value; /* last packets transmitted value */ 346 unsigned last_ptr_value; /* last packets transmitted value */
347 const char *manf_str; 347 const char *manf_str;
348 struct work_struct tx_timeout_task;
348} local_info_t; 349} local_info_t;
349 350
350/**************** 351/****************
@@ -352,6 +353,7 @@ typedef struct local_info_t {
352 */ 353 */
353static int do_start_xmit(struct sk_buff *skb, struct net_device *dev); 354static int do_start_xmit(struct sk_buff *skb, struct net_device *dev);
354static void do_tx_timeout(struct net_device *dev); 355static void do_tx_timeout(struct net_device *dev);
356static void xirc2ps_tx_timeout_task(void *data);
355static struct net_device_stats *do_get_stats(struct net_device *dev); 357static struct net_device_stats *do_get_stats(struct net_device *dev);
356static void set_addresses(struct net_device *dev); 358static void set_addresses(struct net_device *dev);
357static void set_multicast_list(struct net_device *dev); 359static void set_multicast_list(struct net_device *dev);
@@ -589,6 +591,7 @@ xirc2ps_probe(struct pcmcia_device *link)
589#ifdef HAVE_TX_TIMEOUT 591#ifdef HAVE_TX_TIMEOUT
590 dev->tx_timeout = do_tx_timeout; 592 dev->tx_timeout = do_tx_timeout;
591 dev->watchdog_timeo = TX_TIMEOUT; 593 dev->watchdog_timeo = TX_TIMEOUT;
594 INIT_WORK(&local->tx_timeout_task, xirc2ps_tx_timeout_task, dev);
592#endif 595#endif
593 596
594 return xirc2ps_config(link); 597 return xirc2ps_config(link);
@@ -1341,17 +1344,24 @@ xirc2ps_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1341/*====================================================================*/ 1344/*====================================================================*/
1342 1345
1343static void 1346static void
1344do_tx_timeout(struct net_device *dev) 1347xirc2ps_tx_timeout_task(void *data)
1345{ 1348{
1346 local_info_t *lp = netdev_priv(dev); 1349 struct net_device *dev = data;
1347 printk(KERN_NOTICE "%s: transmit timed out\n", dev->name);
1348 lp->stats.tx_errors++;
1349 /* reset the card */ 1350 /* reset the card */
1350 do_reset(dev,1); 1351 do_reset(dev,1);
1351 dev->trans_start = jiffies; 1352 dev->trans_start = jiffies;
1352 netif_wake_queue(dev); 1353 netif_wake_queue(dev);
1353} 1354}
1354 1355
1356static void
1357do_tx_timeout(struct net_device *dev)
1358{
1359 local_info_t *lp = netdev_priv(dev);
1360 lp->stats.tx_errors++;
1361 printk(KERN_NOTICE "%s: transmit timed out\n", dev->name);
1362 schedule_work(&lp->tx_timeout_task);
1363}
1364
1355static int 1365static int
1356do_start_xmit(struct sk_buff *skb, struct net_device *dev) 1366do_start_xmit(struct sk_buff *skb, struct net_device *dev)
1357{ 1367{
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index d768f3d1ac28..d50bcb89dd28 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -58,18 +58,15 @@ static const char *const version =
58 * PCI device identifiers for "new style" Linux PCI Device Drivers 58 * PCI device identifiers for "new style" Linux PCI Device Drivers
59 */ 59 */
60static struct pci_device_id pcnet32_pci_tbl[] = { 60static struct pci_device_id pcnet32_pci_tbl[] = {
61 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE_HOME, 61 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE_HOME), },
62 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 62 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE), },
63 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE,
64 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
65 63
66 /* 64 /*
67 * Adapters that were sold with IBM's RS/6000 or pSeries hardware have 65 * Adapters that were sold with IBM's RS/6000 or pSeries hardware have
68 * the incorrect vendor id. 66 * the incorrect vendor id.
69 */ 67 */
70 { PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_AMD_LANCE, 68 { PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_AMD_LANCE),
71 PCI_ANY_ID, PCI_ANY_ID, 69 .class = (PCI_CLASS_NETWORK_ETHERNET << 8), .class_mask = 0xffff00, },
72 PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, 0},
73 70
74 { } /* terminate list */ 71 { } /* terminate list */
75}; 72};
@@ -188,6 +185,25 @@ static int homepna[MAX_UNITS];
188 185
189#define PCNET32_TOTAL_SIZE 0x20 186#define PCNET32_TOTAL_SIZE 0x20
190 187
188#define CSR0 0
189#define CSR0_INIT 0x1
190#define CSR0_START 0x2
191#define CSR0_STOP 0x4
192#define CSR0_TXPOLL 0x8
193#define CSR0_INTEN 0x40
194#define CSR0_IDON 0x0100
195#define CSR0_NORMAL (CSR0_START | CSR0_INTEN)
196#define PCNET32_INIT_LOW 1
197#define PCNET32_INIT_HIGH 2
198#define CSR3 3
199#define CSR4 4
200#define CSR5 5
201#define CSR5_SUSPEND 0x0001
202#define CSR15 15
203#define PCNET32_MC_FILTER 8
204
205#define PCNET32_79C970A 0x2621
206
191/* The PCNET32 Rx and Tx ring descriptors. */ 207/* The PCNET32 Rx and Tx ring descriptors. */
192struct pcnet32_rx_head { 208struct pcnet32_rx_head {
193 u32 base; 209 u32 base;
@@ -275,9 +291,9 @@ struct pcnet32_private {
275 291
276 /* each bit indicates an available PHY */ 292 /* each bit indicates an available PHY */
277 u32 phymask; 293 u32 phymask;
294 unsigned short chip_version; /* which variant this is */
278}; 295};
279 296
280static void pcnet32_probe_vlbus(void);
281static int pcnet32_probe_pci(struct pci_dev *, const struct pci_device_id *); 297static int pcnet32_probe_pci(struct pci_dev *, const struct pci_device_id *);
282static int pcnet32_probe1(unsigned long, int, struct pci_dev *); 298static int pcnet32_probe1(unsigned long, int, struct pci_dev *);
283static int pcnet32_open(struct net_device *); 299static int pcnet32_open(struct net_device *);
@@ -419,6 +435,238 @@ static struct pcnet32_access pcnet32_dwio = {
419 .reset = pcnet32_dwio_reset 435 .reset = pcnet32_dwio_reset
420}; 436};
421 437
438static void pcnet32_netif_stop(struct net_device *dev)
439{
440 dev->trans_start = jiffies;
441 netif_poll_disable(dev);
442 netif_tx_disable(dev);
443}
444
445static void pcnet32_netif_start(struct net_device *dev)
446{
447 netif_wake_queue(dev);
448 netif_poll_enable(dev);
449}
450
451/*
452 * Allocate space for the new sized tx ring.
453 * Free old resources
454 * Save new resources.
455 * Any failure keeps old resources.
456 * Must be called with lp->lock held.
457 */
458static void pcnet32_realloc_tx_ring(struct net_device *dev,
459 struct pcnet32_private *lp,
460 unsigned int size)
461{
462 dma_addr_t new_ring_dma_addr;
463 dma_addr_t *new_dma_addr_list;
464 struct pcnet32_tx_head *new_tx_ring;
465 struct sk_buff **new_skb_list;
466
467 pcnet32_purge_tx_ring(dev);
468
469 new_tx_ring = pci_alloc_consistent(lp->pci_dev,
470 sizeof(struct pcnet32_tx_head) *
471 (1 << size),
472 &new_ring_dma_addr);
473 if (new_tx_ring == NULL) {
474 if (netif_msg_drv(lp))
475 printk("\n" KERN_ERR
476 "%s: Consistent memory allocation failed.\n",
477 dev->name);
478 return;
479 }
480 memset(new_tx_ring, 0, sizeof(struct pcnet32_tx_head) * (1 << size));
481
482 new_dma_addr_list = kcalloc((1 << size), sizeof(dma_addr_t),
483 GFP_ATOMIC);
484 if (!new_dma_addr_list) {
485 if (netif_msg_drv(lp))
486 printk("\n" KERN_ERR
487 "%s: Memory allocation failed.\n", dev->name);
488 goto free_new_tx_ring;
489 }
490
491 new_skb_list = kcalloc((1 << size), sizeof(struct sk_buff *),
492 GFP_ATOMIC);
493 if (!new_skb_list) {
494 if (netif_msg_drv(lp))
495 printk("\n" KERN_ERR
496 "%s: Memory allocation failed.\n", dev->name);
497 goto free_new_lists;
498 }
499
500 kfree(lp->tx_skbuff);
501 kfree(lp->tx_dma_addr);
502 pci_free_consistent(lp->pci_dev,
503 sizeof(struct pcnet32_tx_head) *
504 lp->tx_ring_size, lp->tx_ring,
505 lp->tx_ring_dma_addr);
506
507 lp->tx_ring_size = (1 << size);
508 lp->tx_mod_mask = lp->tx_ring_size - 1;
509 lp->tx_len_bits = (size << 12);
510 lp->tx_ring = new_tx_ring;
511 lp->tx_ring_dma_addr = new_ring_dma_addr;
512 lp->tx_dma_addr = new_dma_addr_list;
513 lp->tx_skbuff = new_skb_list;
514 return;
515
516 free_new_lists:
517 kfree(new_dma_addr_list);
518 free_new_tx_ring:
519 pci_free_consistent(lp->pci_dev,
520 sizeof(struct pcnet32_tx_head) *
521 (1 << size),
522 new_tx_ring,
523 new_ring_dma_addr);
524 return;
525}
526
527/*
528 * Allocate space for the new sized rx ring.
529 * Re-use old receive buffers.
530 * alloc extra buffers
531 * free unneeded buffers
532 * free unneeded buffers
533 * Save new resources.
534 * Any failure keeps old resources.
535 * Must be called with lp->lock held.
536 */
537static void pcnet32_realloc_rx_ring(struct net_device *dev,
538 struct pcnet32_private *lp,
539 unsigned int size)
540{
541 dma_addr_t new_ring_dma_addr;
542 dma_addr_t *new_dma_addr_list;
543 struct pcnet32_rx_head *new_rx_ring;
544 struct sk_buff **new_skb_list;
545 int new, overlap;
546
547 new_rx_ring = pci_alloc_consistent(lp->pci_dev,
548 sizeof(struct pcnet32_rx_head) *
549 (1 << size),
550 &new_ring_dma_addr);
551 if (new_rx_ring == NULL) {
552 if (netif_msg_drv(lp))
553 printk("\n" KERN_ERR
554 "%s: Consistent memory allocation failed.\n",
555 dev->name);
556 return;
557 }
558 memset(new_rx_ring, 0, sizeof(struct pcnet32_rx_head) * (1 << size));
559
560 new_dma_addr_list = kcalloc((1 << size), sizeof(dma_addr_t),
561 GFP_ATOMIC);
562 if (!new_dma_addr_list) {
563 if (netif_msg_drv(lp))
564 printk("\n" KERN_ERR
565 "%s: Memory allocation failed.\n", dev->name);
566 goto free_new_rx_ring;
567 }
568
569 new_skb_list = kcalloc((1 << size), sizeof(struct sk_buff *),
570 GFP_ATOMIC);
571 if (!new_skb_list) {
572 if (netif_msg_drv(lp))
573 printk("\n" KERN_ERR
574 "%s: Memory allocation failed.\n", dev->name);
575 goto free_new_lists;
576 }
577
578 /* first copy the current receive buffers */
579 overlap = min(size, lp->rx_ring_size);
580 for (new = 0; new < overlap; new++) {
581 new_rx_ring[new] = lp->rx_ring[new];
582 new_dma_addr_list[new] = lp->rx_dma_addr[new];
583 new_skb_list[new] = lp->rx_skbuff[new];
584 }
585 /* now allocate any new buffers needed */
586 for (; new < size; new++ ) {
587 struct sk_buff *rx_skbuff;
588 new_skb_list[new] = dev_alloc_skb(PKT_BUF_SZ);
589 if (!(rx_skbuff = new_skb_list[new])) {
590 /* keep the original lists and buffers */
591 if (netif_msg_drv(lp))
592 printk(KERN_ERR
593 "%s: pcnet32_realloc_rx_ring dev_alloc_skb failed.\n",
594 dev->name);
595 goto free_all_new;
596 }
597 skb_reserve(rx_skbuff, 2);
598
599 new_dma_addr_list[new] =
600 pci_map_single(lp->pci_dev, rx_skbuff->data,
601 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
602 new_rx_ring[new].base = (u32) le32_to_cpu(new_dma_addr_list[new]);
603 new_rx_ring[new].buf_length = le16_to_cpu(2 - PKT_BUF_SZ);
604 new_rx_ring[new].status = le16_to_cpu(0x8000);
605 }
606 /* and free any unneeded buffers */
607 for (; new < lp->rx_ring_size; new++) {
608 if (lp->rx_skbuff[new]) {
609 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[new],
610 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
611 dev_kfree_skb(lp->rx_skbuff[new]);
612 }
613 }
614
615 kfree(lp->rx_skbuff);
616 kfree(lp->rx_dma_addr);
617 pci_free_consistent(lp->pci_dev,
618 sizeof(struct pcnet32_rx_head) *
619 lp->rx_ring_size, lp->rx_ring,
620 lp->rx_ring_dma_addr);
621
622 lp->rx_ring_size = (1 << size);
623 lp->rx_mod_mask = lp->rx_ring_size - 1;
624 lp->rx_len_bits = (size << 4);
625 lp->rx_ring = new_rx_ring;
626 lp->rx_ring_dma_addr = new_ring_dma_addr;
627 lp->rx_dma_addr = new_dma_addr_list;
628 lp->rx_skbuff = new_skb_list;
629 return;
630
631 free_all_new:
632 for (; --new >= lp->rx_ring_size; ) {
633 if (new_skb_list[new]) {
634 pci_unmap_single(lp->pci_dev, new_dma_addr_list[new],
635 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
636 dev_kfree_skb(new_skb_list[new]);
637 }
638 }
639 kfree(new_skb_list);
640 free_new_lists:
641 kfree(new_dma_addr_list);
642 free_new_rx_ring:
643 pci_free_consistent(lp->pci_dev,
644 sizeof(struct pcnet32_rx_head) *
645 (1 << size),
646 new_rx_ring,
647 new_ring_dma_addr);
648 return;
649}
650
651static void pcnet32_purge_rx_ring(struct net_device *dev)
652{
653 struct pcnet32_private *lp = dev->priv;
654 int i;
655
656 /* free all allocated skbuffs */
657 for (i = 0; i < lp->rx_ring_size; i++) {
658 lp->rx_ring[i].status = 0; /* CPU owns buffer */
659 wmb(); /* Make sure adapter sees owner change */
660 if (lp->rx_skbuff[i]) {
661 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i],
662 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
663 dev_kfree_skb_any(lp->rx_skbuff[i]);
664 }
665 lp->rx_skbuff[i] = NULL;
666 lp->rx_dma_addr[i] = 0;
667 }
668}
669
422#ifdef CONFIG_NET_POLL_CONTROLLER 670#ifdef CONFIG_NET_POLL_CONTROLLER
423static void pcnet32_poll_controller(struct net_device *dev) 671static void pcnet32_poll_controller(struct net_device *dev)
424{ 672{
@@ -479,9 +727,11 @@ static u32 pcnet32_get_link(struct net_device *dev)
479 spin_lock_irqsave(&lp->lock, flags); 727 spin_lock_irqsave(&lp->lock, flags);
480 if (lp->mii) { 728 if (lp->mii) {
481 r = mii_link_ok(&lp->mii_if); 729 r = mii_link_ok(&lp->mii_if);
482 } else { 730 } else if (lp->chip_version >= PCNET32_79C970A) {
483 ulong ioaddr = dev->base_addr; /* card base I/O address */ 731 ulong ioaddr = dev->base_addr; /* card base I/O address */
484 r = (lp->a.read_bcr(ioaddr, 4) != 0xc0); 732 r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
733 } else { /* can not detect link on really old chips */
734 r = 1;
485 } 735 }
486 spin_unlock_irqrestore(&lp->lock, flags); 736 spin_unlock_irqrestore(&lp->lock, flags);
487 737
@@ -519,10 +769,10 @@ static void pcnet32_get_ringparam(struct net_device *dev,
519{ 769{
520 struct pcnet32_private *lp = dev->priv; 770 struct pcnet32_private *lp = dev->priv;
521 771
522 ering->tx_max_pending = TX_MAX_RING_SIZE - 1; 772 ering->tx_max_pending = TX_MAX_RING_SIZE;
523 ering->tx_pending = lp->tx_ring_size - 1; 773 ering->tx_pending = lp->tx_ring_size;
524 ering->rx_max_pending = RX_MAX_RING_SIZE - 1; 774 ering->rx_max_pending = RX_MAX_RING_SIZE;
525 ering->rx_pending = lp->rx_ring_size - 1; 775 ering->rx_pending = lp->rx_ring_size;
526} 776}
527 777
528static int pcnet32_set_ringparam(struct net_device *dev, 778static int pcnet32_set_ringparam(struct net_device *dev,
@@ -530,56 +780,53 @@ static int pcnet32_set_ringparam(struct net_device *dev,
530{ 780{
531 struct pcnet32_private *lp = dev->priv; 781 struct pcnet32_private *lp = dev->priv;
532 unsigned long flags; 782 unsigned long flags;
783 unsigned int size;
784 ulong ioaddr = dev->base_addr;
533 int i; 785 int i;
534 786
535 if (ering->rx_mini_pending || ering->rx_jumbo_pending) 787 if (ering->rx_mini_pending || ering->rx_jumbo_pending)
536 return -EINVAL; 788 return -EINVAL;
537 789
538 if (netif_running(dev)) 790 if (netif_running(dev))
539 pcnet32_close(dev); 791 pcnet32_netif_stop(dev);
540 792
541 spin_lock_irqsave(&lp->lock, flags); 793 spin_lock_irqsave(&lp->lock, flags);
542 pcnet32_free_ring(dev); 794 lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
543 lp->tx_ring_size = 795
544 min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE); 796 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
545 lp->rx_ring_size =
546 min(ering->rx_pending, (unsigned int)RX_MAX_RING_SIZE);
547 797
548 /* set the minimum ring size to 4, to allow the loopback test to work 798 /* set the minimum ring size to 4, to allow the loopback test to work
549 * unchanged. 799 * unchanged.
550 */ 800 */
551 for (i = 2; i <= PCNET32_LOG_MAX_TX_BUFFERS; i++) { 801 for (i = 2; i <= PCNET32_LOG_MAX_TX_BUFFERS; i++) {
552 if (lp->tx_ring_size <= (1 << i)) 802 if (size <= (1 << i))
553 break; 803 break;
554 } 804 }
555 lp->tx_ring_size = (1 << i); 805 if ((1 << i) != lp->tx_ring_size)
556 lp->tx_mod_mask = lp->tx_ring_size - 1; 806 pcnet32_realloc_tx_ring(dev, lp, i);
557 lp->tx_len_bits = (i << 12); 807
558 808 size = min(ering->rx_pending, (unsigned int)RX_MAX_RING_SIZE);
559 for (i = 2; i <= PCNET32_LOG_MAX_RX_BUFFERS; i++) { 809 for (i = 2; i <= PCNET32_LOG_MAX_RX_BUFFERS; i++) {
560 if (lp->rx_ring_size <= (1 << i)) 810 if (size <= (1 << i))
561 break; 811 break;
562 } 812 }
563 lp->rx_ring_size = (1 << i); 813 if ((1 << i) != lp->rx_ring_size)
564 lp->rx_mod_mask = lp->rx_ring_size - 1; 814 pcnet32_realloc_rx_ring(dev, lp, i);
565 lp->rx_len_bits = (i << 4); 815
816 dev->weight = lp->rx_ring_size / 2;
566 817
567 if (pcnet32_alloc_ring(dev, dev->name)) { 818 if (netif_running(dev)) {
568 pcnet32_free_ring(dev); 819 pcnet32_netif_start(dev);
569 spin_unlock_irqrestore(&lp->lock, flags); 820 pcnet32_restart(dev, CSR0_NORMAL);
570 return -ENOMEM;
571 } 821 }
572 822
573 spin_unlock_irqrestore(&lp->lock, flags); 823 spin_unlock_irqrestore(&lp->lock, flags);
574 824
575 if (pcnet32_debug & NETIF_MSG_DRV) 825 if (netif_msg_drv(lp))
576 printk(KERN_INFO PFX 826 printk(KERN_INFO
577 "%s: Ring Param Settings: RX: %d, TX: %d\n", dev->name, 827 "%s: Ring Param Settings: RX: %d, TX: %d\n", dev->name,
578 lp->rx_ring_size, lp->tx_ring_size); 828 lp->rx_ring_size, lp->tx_ring_size);
579 829
580 if (netif_running(dev))
581 pcnet32_open(dev);
582
583 return 0; 830 return 0;
584} 831}
585 832
@@ -633,29 +880,27 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
633 unsigned long flags; 880 unsigned long flags;
634 unsigned long ticks; 881 unsigned long ticks;
635 882
636 *data1 = 1; /* status of test, default to fail */
637 rc = 1; /* default to fail */ 883 rc = 1; /* default to fail */
638 884
639 if (netif_running(dev)) 885 if (netif_running(dev))
640 pcnet32_close(dev); 886 pcnet32_close(dev);
641 887
642 spin_lock_irqsave(&lp->lock, flags); 888 spin_lock_irqsave(&lp->lock, flags);
889 lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
890
891 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
643 892
644 /* Reset the PCNET32 */ 893 /* Reset the PCNET32 */
645 lp->a.reset(ioaddr); 894 lp->a.reset(ioaddr);
895 lp->a.write_csr(ioaddr, CSR4, 0x0915);
646 896
647 /* switch pcnet32 to 32bit mode */ 897 /* switch pcnet32 to 32bit mode */
648 lp->a.write_bcr(ioaddr, 20, 2); 898 lp->a.write_bcr(ioaddr, 20, 2);
649 899
650 lp->init_block.mode =
651 le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
652 lp->init_block.filter[0] = 0;
653 lp->init_block.filter[1] = 0;
654
655 /* purge & init rings but don't actually restart */ 900 /* purge & init rings but don't actually restart */
656 pcnet32_restart(dev, 0x0000); 901 pcnet32_restart(dev, 0x0000);
657 902
658 lp->a.write_csr(ioaddr, 0, 0x0004); /* Set STOP bit */ 903 lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
659 904
660 /* Initialize Transmit buffers. */ 905 /* Initialize Transmit buffers. */
661 size = data_len + 15; 906 size = data_len + 15;
@@ -697,14 +942,15 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
697 } 942 }
698 } 943 }
699 944
700 x = a->read_bcr(ioaddr, 32); /* set internal loopback in BSR32 */ 945 x = a->read_bcr(ioaddr, 32); /* set internal loopback in BCR32 */
701 x = x | 0x0002; 946 a->write_bcr(ioaddr, 32, x | 0x0002);
702 a->write_bcr(ioaddr, 32, x);
703 947
704 lp->a.write_csr(ioaddr, 15, 0x0044); /* set int loopback in CSR15 */ 948 /* set int loopback in CSR15 */
949 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
950 lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
705 951
706 teststatus = le16_to_cpu(0x8000); 952 teststatus = le16_to_cpu(0x8000);
707 lp->a.write_csr(ioaddr, 0, 0x0002); /* Set STRT bit */ 953 lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
708 954
709 /* Check status of descriptors */ 955 /* Check status of descriptors */
710 for (x = 0; x < numbuffs; x++) { 956 for (x = 0; x < numbuffs; x++) {
@@ -712,7 +958,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
712 rmb(); 958 rmb();
713 while ((lp->rx_ring[x].status & teststatus) && (ticks < 200)) { 959 while ((lp->rx_ring[x].status & teststatus) && (ticks < 200)) {
714 spin_unlock_irqrestore(&lp->lock, flags); 960 spin_unlock_irqrestore(&lp->lock, flags);
715 mdelay(1); 961 msleep(1);
716 spin_lock_irqsave(&lp->lock, flags); 962 spin_lock_irqsave(&lp->lock, flags);
717 rmb(); 963 rmb();
718 ticks++; 964 ticks++;
@@ -725,7 +971,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
725 } 971 }
726 } 972 }
727 973
728 lp->a.write_csr(ioaddr, 0, 0x0004); /* Set STOP bit */ 974 lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
729 wmb(); 975 wmb();
730 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) { 976 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
731 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name); 977 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);
@@ -758,25 +1004,24 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
758 } 1004 }
759 x++; 1005 x++;
760 } 1006 }
761 if (!rc) {
762 *data1 = 0;
763 }
764 1007
765 clean_up: 1008 clean_up:
1009 *data1 = rc;
766 pcnet32_purge_tx_ring(dev); 1010 pcnet32_purge_tx_ring(dev);
767 x = a->read_csr(ioaddr, 15) & 0xFFFF;
768 a->write_csr(ioaddr, 15, (x & ~0x0044)); /* reset bits 6 and 2 */
769 1011
770 x = a->read_bcr(ioaddr, 32); /* reset internal loopback */ 1012 x = a->read_csr(ioaddr, CSR15);
771 x = x & ~0x0002; 1013 a->write_csr(ioaddr, CSR15, (x & ~0x0044)); /* reset bits 6 and 2 */
772 a->write_bcr(ioaddr, 32, x);
773 1014
774 spin_unlock_irqrestore(&lp->lock, flags); 1015 x = a->read_bcr(ioaddr, 32); /* reset internal loopback */
1016 a->write_bcr(ioaddr, 32, (x & ~0x0002));
775 1017
776 if (netif_running(dev)) { 1018 if (netif_running(dev)) {
1019 spin_unlock_irqrestore(&lp->lock, flags);
777 pcnet32_open(dev); 1020 pcnet32_open(dev);
778 } else { 1021 } else {
1022 pcnet32_purge_rx_ring(dev);
779 lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */ 1023 lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
1024 spin_unlock_irqrestore(&lp->lock, flags);
780 } 1025 }
781 1026
782 return (rc); 1027 return (rc);
@@ -839,6 +1084,47 @@ static int pcnet32_phys_id(struct net_device *dev, u32 data)
839 return 0; 1084 return 0;
840} 1085}
841 1086
1087/*
1088 * lp->lock must be held.
1089 */
1090static int pcnet32_suspend(struct net_device *dev, unsigned long *flags,
1091 int can_sleep)
1092{
1093 int csr5;
1094 struct pcnet32_private *lp = dev->priv;
1095 struct pcnet32_access *a = &lp->a;
1096 ulong ioaddr = dev->base_addr;
1097 int ticks;
1098
1099 /* really old chips have to be stopped. */
1100 if (lp->chip_version < PCNET32_79C970A)
1101 return 0;
1102
1103 /* set SUSPEND (SPND) - CSR5 bit 0 */
1104 csr5 = a->read_csr(ioaddr, CSR5);
1105 a->write_csr(ioaddr, CSR5, csr5 | CSR5_SUSPEND);
1106
1107 /* poll waiting for bit to be set */
1108 ticks = 0;
1109 while (!(a->read_csr(ioaddr, CSR5) & CSR5_SUSPEND)) {
1110 spin_unlock_irqrestore(&lp->lock, *flags);
1111 if (can_sleep)
1112 msleep(1);
1113 else
1114 mdelay(1);
1115 spin_lock_irqsave(&lp->lock, *flags);
1116 ticks++;
1117 if (ticks > 200) {
1118 if (netif_msg_hw(lp))
1119 printk(KERN_DEBUG
1120 "%s: Error getting into suspend!\n",
1121 dev->name);
1122 return 0;
1123 }
1124 }
1125 return 1;
1126}
1127
842#define PCNET32_REGS_PER_PHY 32 1128#define PCNET32_REGS_PER_PHY 32
843#define PCNET32_MAX_PHYS 32 1129#define PCNET32_MAX_PHYS 32
844static int pcnet32_get_regs_len(struct net_device *dev) 1130static int pcnet32_get_regs_len(struct net_device *dev)
@@ -857,32 +1143,13 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
857 struct pcnet32_private *lp = dev->priv; 1143 struct pcnet32_private *lp = dev->priv;
858 struct pcnet32_access *a = &lp->a; 1144 struct pcnet32_access *a = &lp->a;
859 ulong ioaddr = dev->base_addr; 1145 ulong ioaddr = dev->base_addr;
860 int ticks;
861 unsigned long flags; 1146 unsigned long flags;
862 1147
863 spin_lock_irqsave(&lp->lock, flags); 1148 spin_lock_irqsave(&lp->lock, flags);
864 1149
865 csr0 = a->read_csr(ioaddr, 0); 1150 csr0 = a->read_csr(ioaddr, CSR0);
866 if (!(csr0 & 0x0004)) { /* If not stopped */ 1151 if (!(csr0 & CSR0_STOP)) /* If not stopped */
867 /* set SUSPEND (SPND) - CSR5 bit 0 */ 1152 pcnet32_suspend(dev, &flags, 1);
868 a->write_csr(ioaddr, 5, 0x0001);
869
870 /* poll waiting for bit to be set */
871 ticks = 0;
872 while (!(a->read_csr(ioaddr, 5) & 0x0001)) {
873 spin_unlock_irqrestore(&lp->lock, flags);
874 mdelay(1);
875 spin_lock_irqsave(&lp->lock, flags);
876 ticks++;
877 if (ticks > 200) {
878 if (netif_msg_hw(lp))
879 printk(KERN_DEBUG
880 "%s: Error getting into suspend!\n",
881 dev->name);
882 break;
883 }
884 }
885 }
886 1153
887 /* read address PROM */ 1154 /* read address PROM */
888 for (i = 0; i < 16; i += 2) 1155 for (i = 0; i < 16; i += 2)
@@ -919,9 +1186,12 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
919 } 1186 }
920 } 1187 }
921 1188
922 if (!(csr0 & 0x0004)) { /* If not stopped */ 1189 if (!(csr0 & CSR0_STOP)) { /* If not stopped */
1190 int csr5;
1191
923 /* clear SUSPEND (SPND) - CSR5 bit 0 */ 1192 /* clear SUSPEND (SPND) - CSR5 bit 0 */
924 a->write_csr(ioaddr, 5, 0x0000); 1193 csr5 = a->read_csr(ioaddr, CSR5);
1194 a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
925 } 1195 }
926 1196
927 spin_unlock_irqrestore(&lp->lock, flags); 1197 spin_unlock_irqrestore(&lp->lock, flags);
@@ -952,7 +1222,7 @@ static struct ethtool_ops pcnet32_ethtool_ops = {
952/* only probes for non-PCI devices, the rest are handled by 1222/* only probes for non-PCI devices, the rest are handled by
953 * pci_register_driver via pcnet32_probe_pci */ 1223 * pci_register_driver via pcnet32_probe_pci */
954 1224
955static void __devinit pcnet32_probe_vlbus(void) 1225static void __devinit pcnet32_probe_vlbus(unsigned int *pcnet32_portlist)
956{ 1226{
957 unsigned int *port, ioaddr; 1227 unsigned int *port, ioaddr;
958 1228
@@ -1268,6 +1538,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
1268 lp->mii_if.reg_num_mask = 0x1f; 1538 lp->mii_if.reg_num_mask = 0x1f;
1269 lp->dxsuflo = dxsuflo; 1539 lp->dxsuflo = dxsuflo;
1270 lp->mii = mii; 1540 lp->mii = mii;
1541 lp->chip_version = chip_version;
1271 lp->msg_enable = pcnet32_debug; 1542 lp->msg_enable = pcnet32_debug;
1272 if ((cards_found >= MAX_UNITS) 1543 if ((cards_found >= MAX_UNITS)
1273 || (options[cards_found] > sizeof(options_mapping))) 1544 || (options[cards_found] > sizeof(options_mapping)))
@@ -1436,7 +1707,7 @@ static int pcnet32_alloc_ring(struct net_device *dev, char *name)
1436 lp->tx_ring_size, 1707 lp->tx_ring_size,
1437 &lp->tx_ring_dma_addr); 1708 &lp->tx_ring_dma_addr);
1438 if (lp->tx_ring == NULL) { 1709 if (lp->tx_ring == NULL) {
1439 if (pcnet32_debug & NETIF_MSG_DRV) 1710 if (netif_msg_drv(lp))
1440 printk("\n" KERN_ERR PFX 1711 printk("\n" KERN_ERR PFX
1441 "%s: Consistent memory allocation failed.\n", 1712 "%s: Consistent memory allocation failed.\n",
1442 name); 1713 name);
@@ -1448,52 +1719,48 @@ static int pcnet32_alloc_ring(struct net_device *dev, char *name)
1448 lp->rx_ring_size, 1719 lp->rx_ring_size,
1449 &lp->rx_ring_dma_addr); 1720 &lp->rx_ring_dma_addr);
1450 if (lp->rx_ring == NULL) { 1721 if (lp->rx_ring == NULL) {
1451 if (pcnet32_debug & NETIF_MSG_DRV) 1722 if (netif_msg_drv(lp))
1452 printk("\n" KERN_ERR PFX 1723 printk("\n" KERN_ERR PFX
1453 "%s: Consistent memory allocation failed.\n", 1724 "%s: Consistent memory allocation failed.\n",
1454 name); 1725 name);
1455 return -ENOMEM; 1726 return -ENOMEM;
1456 } 1727 }
1457 1728
1458 lp->tx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->tx_ring_size, 1729 lp->tx_dma_addr = kcalloc(lp->tx_ring_size, sizeof(dma_addr_t),
1459 GFP_ATOMIC); 1730 GFP_ATOMIC);
1460 if (!lp->tx_dma_addr) { 1731 if (!lp->tx_dma_addr) {
1461 if (pcnet32_debug & NETIF_MSG_DRV) 1732 if (netif_msg_drv(lp))
1462 printk("\n" KERN_ERR PFX 1733 printk("\n" KERN_ERR PFX
1463 "%s: Memory allocation failed.\n", name); 1734 "%s: Memory allocation failed.\n", name);
1464 return -ENOMEM; 1735 return -ENOMEM;
1465 } 1736 }
1466 memset(lp->tx_dma_addr, 0, sizeof(dma_addr_t) * lp->tx_ring_size);
1467 1737
1468 lp->rx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->rx_ring_size, 1738 lp->rx_dma_addr = kcalloc(lp->rx_ring_size, sizeof(dma_addr_t),
1469 GFP_ATOMIC); 1739 GFP_ATOMIC);
1470 if (!lp->rx_dma_addr) { 1740 if (!lp->rx_dma_addr) {
1471 if (pcnet32_debug & NETIF_MSG_DRV) 1741 if (netif_msg_drv(lp))
1472 printk("\n" KERN_ERR PFX 1742 printk("\n" KERN_ERR PFX
1473 "%s: Memory allocation failed.\n", name); 1743 "%s: Memory allocation failed.\n", name);
1474 return -ENOMEM; 1744 return -ENOMEM;
1475 } 1745 }
1476 memset(lp->rx_dma_addr, 0, sizeof(dma_addr_t) * lp->rx_ring_size);
1477 1746
1478 lp->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->tx_ring_size, 1747 lp->tx_skbuff = kcalloc(lp->tx_ring_size, sizeof(struct sk_buff *),
1479 GFP_ATOMIC); 1748 GFP_ATOMIC);
1480 if (!lp->tx_skbuff) { 1749 if (!lp->tx_skbuff) {
1481 if (pcnet32_debug & NETIF_MSG_DRV) 1750 if (netif_msg_drv(lp))
1482 printk("\n" KERN_ERR PFX 1751 printk("\n" KERN_ERR PFX
1483 "%s: Memory allocation failed.\n", name); 1752 "%s: Memory allocation failed.\n", name);
1484 return -ENOMEM; 1753 return -ENOMEM;
1485 } 1754 }
1486 memset(lp->tx_skbuff, 0, sizeof(struct sk_buff *) * lp->tx_ring_size);
1487 1755
1488 lp->rx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->rx_ring_size, 1756 lp->rx_skbuff = kcalloc(lp->rx_ring_size, sizeof(struct sk_buff *),
1489 GFP_ATOMIC); 1757 GFP_ATOMIC);
1490 if (!lp->rx_skbuff) { 1758 if (!lp->rx_skbuff) {
1491 if (pcnet32_debug & NETIF_MSG_DRV) 1759 if (netif_msg_drv(lp))
1492 printk("\n" KERN_ERR PFX 1760 printk("\n" KERN_ERR PFX
1493 "%s: Memory allocation failed.\n", name); 1761 "%s: Memory allocation failed.\n", name);
1494 return -ENOMEM; 1762 return -ENOMEM;
1495 } 1763 }
1496 memset(lp->rx_skbuff, 0, sizeof(struct sk_buff *) * lp->rx_ring_size);
1497 1764
1498 return 0; 1765 return 0;
1499} 1766}
@@ -1582,10 +1849,7 @@ static int pcnet32_open(struct net_device *dev)
1582 val |= 2; 1849 val |= 2;
1583 } else if (lp->options & PCNET32_PORT_ASEL) { 1850 } else if (lp->options & PCNET32_PORT_ASEL) {
1584 /* workaround of xSeries250, turn on for 79C975 only */ 1851 /* workaround of xSeries250, turn on for 79C975 only */
1585 i = ((lp->a.read_csr(ioaddr, 88) | 1852 if (lp->chip_version == 0x2627)
1586 (lp->a.
1587 read_csr(ioaddr, 89) << 16)) >> 12) & 0xffff;
1588 if (i == 0x2627)
1589 val |= 3; 1853 val |= 3;
1590 } 1854 }
1591 lp->a.write_bcr(ioaddr, 9, val); 1855 lp->a.write_bcr(ioaddr, 9, val);
@@ -1729,9 +1993,11 @@ static int pcnet32_open(struct net_device *dev)
1729 1993
1730 netif_start_queue(dev); 1994 netif_start_queue(dev);
1731 1995
1732 /* Print the link status and start the watchdog */ 1996 if (lp->chip_version >= PCNET32_79C970A) {
1733 pcnet32_check_media(dev, 1); 1997 /* Print the link status and start the watchdog */
1734 mod_timer(&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT); 1998 pcnet32_check_media(dev, 1);
1999 mod_timer(&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT);
2000 }
1735 2001
1736 i = 0; 2002 i = 0;
1737 while (i++ < 100) 2003 while (i++ < 100)
@@ -1757,16 +2023,7 @@ static int pcnet32_open(struct net_device *dev)
1757 2023
1758 err_free_ring: 2024 err_free_ring:
1759 /* free any allocated skbuffs */ 2025 /* free any allocated skbuffs */
1760 for (i = 0; i < lp->rx_ring_size; i++) { 2026 pcnet32_purge_rx_ring(dev);
1761 lp->rx_ring[i].status = 0;
1762 if (lp->rx_skbuff[i]) {
1763 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i],
1764 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
1765 dev_kfree_skb(lp->rx_skbuff[i]);
1766 }
1767 lp->rx_skbuff[i] = NULL;
1768 lp->rx_dma_addr[i] = 0;
1769 }
1770 2027
1771 /* 2028 /*
1772 * Switch back to 16bit mode to avoid problems with dumb 2029 * Switch back to 16bit mode to avoid problems with dumb
@@ -2348,7 +2605,6 @@ static int pcnet32_close(struct net_device *dev)
2348{ 2605{
2349 unsigned long ioaddr = dev->base_addr; 2606 unsigned long ioaddr = dev->base_addr;
2350 struct pcnet32_private *lp = dev->priv; 2607 struct pcnet32_private *lp = dev->priv;
2351 int i;
2352 unsigned long flags; 2608 unsigned long flags;
2353 2609
2354 del_timer_sync(&lp->watchdog_timer); 2610 del_timer_sync(&lp->watchdog_timer);
@@ -2379,31 +2635,8 @@ static int pcnet32_close(struct net_device *dev)
2379 2635
2380 spin_lock_irqsave(&lp->lock, flags); 2636 spin_lock_irqsave(&lp->lock, flags);
2381 2637
2382 /* free all allocated skbuffs */ 2638 pcnet32_purge_rx_ring(dev);
2383 for (i = 0; i < lp->rx_ring_size; i++) { 2639 pcnet32_purge_tx_ring(dev);
2384 lp->rx_ring[i].status = 0;
2385 wmb(); /* Make sure adapter sees owner change */
2386 if (lp->rx_skbuff[i]) {
2387 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i],
2388 PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
2389 dev_kfree_skb(lp->rx_skbuff[i]);
2390 }
2391 lp->rx_skbuff[i] = NULL;
2392 lp->rx_dma_addr[i] = 0;
2393 }
2394
2395 for (i = 0; i < lp->tx_ring_size; i++) {
2396 lp->tx_ring[i].status = 0; /* CPU owns buffer */
2397 wmb(); /* Make sure adapter sees owner change */
2398 if (lp->tx_skbuff[i]) {
2399 pci_unmap_single(lp->pci_dev, lp->tx_dma_addr[i],
2400 lp->tx_skbuff[i]->len,
2401 PCI_DMA_TODEVICE);
2402 dev_kfree_skb(lp->tx_skbuff[i]);
2403 }
2404 lp->tx_skbuff[i] = NULL;
2405 lp->tx_dma_addr[i] = 0;
2406 }
2407 2640
2408 spin_unlock_irqrestore(&lp->lock, flags); 2641 spin_unlock_irqrestore(&lp->lock, flags);
2409 2642
@@ -2433,6 +2666,7 @@ static void pcnet32_load_multicast(struct net_device *dev)
2433 volatile struct pcnet32_init_block *ib = &lp->init_block; 2666 volatile struct pcnet32_init_block *ib = &lp->init_block;
2434 volatile u16 *mcast_table = (u16 *) & ib->filter; 2667 volatile u16 *mcast_table = (u16 *) & ib->filter;
2435 struct dev_mc_list *dmi = dev->mc_list; 2668 struct dev_mc_list *dmi = dev->mc_list;
2669 unsigned long ioaddr = dev->base_addr;
2436 char *addrs; 2670 char *addrs;
2437 int i; 2671 int i;
2438 u32 crc; 2672 u32 crc;
@@ -2441,6 +2675,10 @@ static void pcnet32_load_multicast(struct net_device *dev)
2441 if (dev->flags & IFF_ALLMULTI) { 2675 if (dev->flags & IFF_ALLMULTI) {
2442 ib->filter[0] = 0xffffffff; 2676 ib->filter[0] = 0xffffffff;
2443 ib->filter[1] = 0xffffffff; 2677 ib->filter[1] = 0xffffffff;
2678 lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
2679 lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
2680 lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
2681 lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
2444 return; 2682 return;
2445 } 2683 }
2446 /* clear the multicast filter */ 2684 /* clear the multicast filter */
@@ -2462,6 +2700,9 @@ static void pcnet32_load_multicast(struct net_device *dev)
2462 le16_to_cpu(le16_to_cpu(mcast_table[crc >> 4]) | 2700 le16_to_cpu(le16_to_cpu(mcast_table[crc >> 4]) |
2463 (1 << (crc & 0xf))); 2701 (1 << (crc & 0xf)));
2464 } 2702 }
2703 for (i = 0; i < 4; i++)
2704 lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
2705 le16_to_cpu(mcast_table[i]));
2465 return; 2706 return;
2466} 2707}
2467 2708
@@ -2472,8 +2713,11 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
2472{ 2713{
2473 unsigned long ioaddr = dev->base_addr, flags; 2714 unsigned long ioaddr = dev->base_addr, flags;
2474 struct pcnet32_private *lp = dev->priv; 2715 struct pcnet32_private *lp = dev->priv;
2716 int csr15, suspended;
2475 2717
2476 spin_lock_irqsave(&lp->lock, flags); 2718 spin_lock_irqsave(&lp->lock, flags);
2719 suspended = pcnet32_suspend(dev, &flags, 0);
2720 csr15 = lp->a.read_csr(ioaddr, CSR15);
2477 if (dev->flags & IFF_PROMISC) { 2721 if (dev->flags & IFF_PROMISC) {
2478 /* Log any net taps. */ 2722 /* Log any net taps. */
2479 if (netif_msg_hw(lp)) 2723 if (netif_msg_hw(lp))
@@ -2482,15 +2726,24 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
2482 lp->init_block.mode = 2726 lp->init_block.mode =
2483 le16_to_cpu(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) << 2727 le16_to_cpu(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
2484 7); 2728 7);
2729 lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
2485 } else { 2730 } else {
2486 lp->init_block.mode = 2731 lp->init_block.mode =
2487 le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7); 2732 le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
2733 lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
2488 pcnet32_load_multicast(dev); 2734 pcnet32_load_multicast(dev);
2489 } 2735 }
2490 2736
2491 lp->a.write_csr(ioaddr, 0, 0x0004); /* Temporarily stop the lance. */ 2737 if (suspended) {
2492 pcnet32_restart(dev, 0x0042); /* Resume normal operation */ 2738 int csr5;
2493 netif_wake_queue(dev); 2739 /* clear SUSPEND (SPND) - CSR5 bit 0 */
2740 csr5 = lp->a.read_csr(ioaddr, CSR5);
2741 lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
2742 } else {
2743 lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
2744 pcnet32_restart(dev, CSR0_NORMAL);
2745 netif_wake_queue(dev);
2746 }
2494 2747
2495 spin_unlock_irqrestore(&lp->lock, flags); 2748 spin_unlock_irqrestore(&lp->lock, flags);
2496} 2749}
@@ -2730,7 +2983,7 @@ static int __init pcnet32_init_module(void)
2730 2983
2731 /* should we find any remaining VLbus devices ? */ 2984 /* should we find any remaining VLbus devices ? */
2732 if (pcnet32vlb) 2985 if (pcnet32vlb)
2733 pcnet32_probe_vlbus(); 2986 pcnet32_probe_vlbus(pcnet32_portlist);
2734 2987
2735 if (cards_found && (pcnet32_debug & NETIF_MSG_PROBE)) 2988 if (cards_found && (pcnet32_debug & NETIF_MSG_PROBE))
2736 printk(KERN_INFO PFX "%d cards_found.\n", cards_found); 2989 printk(KERN_INFO PFX "%d cards_found.\n", cards_found);
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 2ba6d3a40e2e..b79ec0d7480f 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -56,5 +56,22 @@ config SMSC_PHY
56 ---help--- 56 ---help---
57 Currently supports the LAN83C185 PHY 57 Currently supports the LAN83C185 PHY
58 58
59config FIXED_PHY
60 tristate "Drivers for PHY emulation on fixed speed/link"
61 depends on PHYLIB
62 ---help---
63 Adds the driver to PHY layer to cover the boards that do not have any PHY bound,
64 but with the ability to manipulate with speed/link in software. The relavant MII
65 speed/duplex parameters could be effectively handled in user-specified fuction.
66 Currently tested with mpc866ads.
67
68config FIXED_MII_10_FDX
69 bool "Emulation for 10M Fdx fixed PHY behavior"
70 depends on FIXED_PHY
71
72config FIXED_MII_100_FDX
73 bool "Emulation for 100M Fdx fixed PHY behavior"
74 depends on FIXED_PHY
75
59endmenu 76endmenu
60 77
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index a00e61942525..320f8323123f 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -10,3 +10,4 @@ obj-$(CONFIG_LXT_PHY) += lxt.o
10obj-$(CONFIG_QSEMI_PHY) += qsemi.o 10obj-$(CONFIG_QSEMI_PHY) += qsemi.o
11obj-$(CONFIG_SMSC_PHY) += smsc.o 11obj-$(CONFIG_SMSC_PHY) += smsc.o
12obj-$(CONFIG_VITESSE_PHY) += vitesse.o 12obj-$(CONFIG_VITESSE_PHY) += vitesse.o
13obj-$(CONFIG_FIXED_PHY) += fixed.o
diff --git a/drivers/net/phy/cicada.c b/drivers/net/phy/cicada.c
index 3efb715c28dc..ae60e6e4107c 100644
--- a/drivers/net/phy/cicada.c
+++ b/drivers/net/phy/cicada.c
@@ -103,7 +103,22 @@ static int cis820x_config_intr(struct phy_device *phydev)
103 return err; 103 return err;
104} 104}
105 105
106/* Cicada 820x */ 106/* Cicada 8201, a.k.a Vitesse VSC8201 */
107static struct phy_driver cis8201_driver = {
108 .phy_id = 0x000fc410,
109 .name = "Cicada Cis8201",
110 .phy_id_mask = 0x000ffff0,
111 .features = PHY_GBIT_FEATURES,
112 .flags = PHY_HAS_INTERRUPT,
113 .config_init = &cis820x_config_init,
114 .config_aneg = &genphy_config_aneg,
115 .read_status = &genphy_read_status,
116 .ack_interrupt = &cis820x_ack_interrupt,
117 .config_intr = &cis820x_config_intr,
118 .driver = { .owner = THIS_MODULE,},
119};
120
121/* Cicada 8204 */
107static struct phy_driver cis8204_driver = { 122static struct phy_driver cis8204_driver = {
108 .phy_id = 0x000fc440, 123 .phy_id = 0x000fc440,
109 .name = "Cicada Cis8204", 124 .name = "Cicada Cis8204",
@@ -118,15 +133,30 @@ static struct phy_driver cis8204_driver = {
118 .driver = { .owner = THIS_MODULE,}, 133 .driver = { .owner = THIS_MODULE,},
119}; 134};
120 135
121static int __init cis8204_init(void) 136static int __init cicada_init(void)
122{ 137{
123 return phy_driver_register(&cis8204_driver); 138 int ret;
139
140 ret = phy_driver_register(&cis8204_driver);
141 if (ret)
142 goto err1;
143
144 ret = phy_driver_register(&cis8201_driver);
145 if (ret)
146 goto err2;
147 return 0;
148
149err2:
150 phy_driver_unregister(&cis8204_driver);
151err1:
152 return ret;
124} 153}
125 154
126static void __exit cis8204_exit(void) 155static void __exit cicada_exit(void)
127{ 156{
128 phy_driver_unregister(&cis8204_driver); 157 phy_driver_unregister(&cis8204_driver);
158 phy_driver_unregister(&cis8201_driver);
129} 159}
130 160
131module_init(cis8204_init); 161module_init(cicada_init);
132module_exit(cis8204_exit); 162module_exit(cicada_exit);
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c
new file mode 100644
index 000000000000..341036df4710
--- /dev/null
+++ b/drivers/net/phy/fixed.c
@@ -0,0 +1,358 @@
1/*
2 * drivers/net/phy/fixed.c
3 *
4 * Driver for fixed PHYs, when transceiver is able to operate in one fixed mode.
5 *
6 * Author: Vitaly Bordug
7 *
8 * Copyright (c) 2006 MontaVista Software, Inc.
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 as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 *
15 */
16#include <linux/config.h>
17#include <linux/kernel.h>
18#include <linux/sched.h>
19#include <linux/string.h>
20#include <linux/errno.h>
21#include <linux/unistd.h>
22#include <linux/slab.h>
23#include <linux/interrupt.h>
24#include <linux/init.h>
25#include <linux/delay.h>
26#include <linux/netdevice.h>
27#include <linux/etherdevice.h>
28#include <linux/skbuff.h>
29#include <linux/spinlock.h>
30#include <linux/mm.h>
31#include <linux/module.h>
32#include <linux/mii.h>
33#include <linux/ethtool.h>
34#include <linux/phy.h>
35
36#include <asm/io.h>
37#include <asm/irq.h>
38#include <asm/uaccess.h>
39
40#define MII_REGS_NUM 7
41
42/*
43 The idea is to emulate normal phy behavior by responding with
44 pre-defined values to mii BMCR read, so that read_status hook could
45 take all the needed info.
46*/
47
48struct fixed_phy_status {
49 u8 link;
50 u16 speed;
51 u8 duplex;
52};
53
54/*-----------------------------------------------------------------------------
55 * Private information hoder for mii_bus
56 *-----------------------------------------------------------------------------*/
57struct fixed_info {
58 u16 *regs;
59 u8 regs_num;
60 struct fixed_phy_status phy_status;
61 struct phy_device *phydev; /* pointer to the container */
62 /* link & speed cb */
63 int(*link_update)(struct net_device*, struct fixed_phy_status*);
64
65};
66
67/*-----------------------------------------------------------------------------
68 * If something weird is required to be done with link/speed,
69 * network driver is able to assign a function to implement this.
70 * May be useful for PHY's that need to be software-driven.
71 *-----------------------------------------------------------------------------*/
72int fixed_mdio_set_link_update(struct phy_device* phydev,
73 int(*link_update)(struct net_device*, struct fixed_phy_status*))
74{
75 struct fixed_info *fixed;
76
77 if(link_update == NULL)
78 return -EINVAL;
79
80 if(phydev) {
81 if(phydev->bus) {
82 fixed = phydev->bus->priv;
83 fixed->link_update = link_update;
84 return 0;
85 }
86 }
87 return -EINVAL;
88}
89EXPORT_SYMBOL(fixed_mdio_set_link_update);
90
91/*-----------------------------------------------------------------------------
92 * This is used for updating internal mii regs from the status
93 *-----------------------------------------------------------------------------*/
94static int fixed_mdio_update_regs(struct fixed_info *fixed)
95{
96 u16 *regs = fixed->regs;
97 u16 bmsr = 0;
98 u16 bmcr = 0;
99
100 if(!regs) {
101 printk(KERN_ERR "%s: regs not set up", __FUNCTION__);
102 return -EINVAL;
103 }
104
105 if(fixed->phy_status.link)
106 bmsr |= BMSR_LSTATUS;
107
108 if(fixed->phy_status.duplex) {
109 bmcr |= BMCR_FULLDPLX;
110
111 switch ( fixed->phy_status.speed ) {
112 case 100:
113 bmsr |= BMSR_100FULL;
114 bmcr |= BMCR_SPEED100;
115 break;
116
117 case 10:
118 bmsr |= BMSR_10FULL;
119 break;
120 }
121 } else {
122 switch ( fixed->phy_status.speed ) {
123 case 100:
124 bmsr |= BMSR_100HALF;
125 bmcr |= BMCR_SPEED100;
126 break;
127
128 case 10:
129 bmsr |= BMSR_100HALF;
130 break;
131 }
132 }
133
134 regs[MII_BMCR] = bmcr;
135 regs[MII_BMSR] = bmsr | 0x800; /*we are always capable of 10 hdx*/
136
137 return 0;
138}
139
140static int fixed_mii_read(struct mii_bus *bus, int phy_id, int location)
141{
142 struct fixed_info *fixed = bus->priv;
143
144 /* if user has registered link update callback, use it */
145 if(fixed->phydev)
146 if(fixed->phydev->attached_dev) {
147 if(fixed->link_update) {
148 fixed->link_update(fixed->phydev->attached_dev,
149 &fixed->phy_status);
150 fixed_mdio_update_regs(fixed);
151 }
152 }
153
154 if ((unsigned int)location >= fixed->regs_num)
155 return -1;
156 return fixed->regs[location];
157}
158
159static int fixed_mii_write(struct mii_bus *bus, int phy_id, int location, u16 val)
160{
161 /* do nothing for now*/
162 return 0;
163}
164
165static int fixed_mii_reset(struct mii_bus *bus)
166{
167 /*nothing here - no way/need to reset it*/
168 return 0;
169}
170
171static int fixed_config_aneg(struct phy_device *phydev)
172{
173 /* :TODO:03/13/2006 09:45:37 PM::
174 The full autoneg funcionality can be emulated,
175 but no need to have anything here for now
176 */
177 return 0;
178}
179
180/*-----------------------------------------------------------------------------
181 * the manual bind will do the magic - with phy_id_mask == 0
182 * match will never return true...
183 *-----------------------------------------------------------------------------*/
184static struct phy_driver fixed_mdio_driver = {
185 .name = "Fixed PHY",
186 .features = PHY_BASIC_FEATURES,
187 .config_aneg = fixed_config_aneg,
188 .read_status = genphy_read_status,
189 .driver = { .owner = THIS_MODULE,},
190};
191
192/*-----------------------------------------------------------------------------
193 * This func is used to create all the necessary stuff, bind
194 * the fixed phy driver and register all it on the mdio_bus_type.
195 * speed is either 10 or 100, duplex is boolean.
196 * number is used to create multiple fixed PHYs, so that several devices can
197 * utilize them simultaneously.
198 *-----------------------------------------------------------------------------*/
199static int fixed_mdio_register_device(int number, int speed, int duplex)
200{
201 struct mii_bus *new_bus;
202 struct fixed_info *fixed;
203 struct phy_device *phydev;
204 int err = 0;
205
206 struct device* dev = kzalloc(sizeof(struct device), GFP_KERNEL);
207
208 if (NULL == dev)
209 return -ENOMEM;
210
211 new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL);
212
213 if (NULL == new_bus) {
214 kfree(dev);
215 return -ENOMEM;
216 }
217 fixed = kzalloc(sizeof(struct fixed_info), GFP_KERNEL);
218
219 if (NULL == fixed) {
220 kfree(dev);
221 kfree(new_bus);
222 return -ENOMEM;
223 }
224
225 fixed->regs = kzalloc(MII_REGS_NUM*sizeof(int), GFP_KERNEL);
226 fixed->regs_num = MII_REGS_NUM;
227 fixed->phy_status.speed = speed;
228 fixed->phy_status.duplex = duplex;
229 fixed->phy_status.link = 1;
230
231 new_bus->name = "Fixed MII Bus",
232 new_bus->read = &fixed_mii_read,
233 new_bus->write = &fixed_mii_write,
234 new_bus->reset = &fixed_mii_reset,
235
236 /*set up workspace*/
237 fixed_mdio_update_regs(fixed);
238 new_bus->priv = fixed;
239
240 new_bus->dev = dev;
241 dev_set_drvdata(dev, new_bus);
242
243 /* create phy_device and register it on the mdio bus */
244 phydev = phy_device_create(new_bus, 0, 0);
245
246 /*
247 Put the phydev pointer into the fixed pack so that bus read/write code could
248 be able to access for instance attached netdev. Well it doesn't have to do
249 so, only in case of utilizing user-specified link-update...
250 */
251 fixed->phydev = phydev;
252
253 if(NULL == phydev) {
254 err = -ENOMEM;
255 goto device_create_fail;
256 }
257
258 phydev->irq = -1;
259 phydev->dev.bus = &mdio_bus_type;
260
261 if(number)
262 snprintf(phydev->dev.bus_id, BUS_ID_SIZE,
263 "fixed_%d@%d:%d", number, speed, duplex);
264 else
265 snprintf(phydev->dev.bus_id, BUS_ID_SIZE,
266 "fixed@%d:%d", speed, duplex);
267 phydev->bus = new_bus;
268
269 err = device_register(&phydev->dev);
270 if(err) {
271 printk(KERN_ERR "Phy %s failed to register\n",
272 phydev->dev.bus_id);
273 goto bus_register_fail;
274 }
275
276 /*
277 the mdio bus has phy_id match... In order not to do it
278 artificially, we are binding the driver here by hand;
279 it will be the same for all the fixed phys anyway.
280 */
281 down_write(&phydev->dev.bus->subsys.rwsem);
282
283 phydev->dev.driver = &fixed_mdio_driver.driver;
284
285 err = phydev->dev.driver->probe(&phydev->dev);
286 if(err < 0) {
287 printk(KERN_ERR "Phy %s: problems with fixed driver\n",phydev->dev.bus_id);
288 up_write(&phydev->dev.bus->subsys.rwsem);
289 goto probe_fail;
290 }
291
292 device_bind_driver(&phydev->dev);
293 up_write(&phydev->dev.bus->subsys.rwsem);
294
295 return 0;
296
297probe_fail:
298 device_unregister(&phydev->dev);
299bus_register_fail:
300 kfree(phydev);
301device_create_fail:
302 kfree(dev);
303 kfree(new_bus);
304 kfree(fixed);
305
306 return err;
307}
308
309
310MODULE_DESCRIPTION("Fixed PHY device & driver for PAL");
311MODULE_AUTHOR("Vitaly Bordug");
312MODULE_LICENSE("GPL");
313
314static int __init fixed_init(void)
315{
316 int ret;
317 int duplex = 0;
318
319 /* register on the bus... Not expected to be matched with anything there... */
320 phy_driver_register(&fixed_mdio_driver);
321
322 /* So let the fun begin...
323 We will create several mdio devices here, and will bound the upper
324 driver to them.
325
326 Then the external software can lookup the phy bus by searching
327 fixed@speed:duplex, e.g. fixed@100:1, to be connected to the
328 virtual 100M Fdx phy.
329
330 In case several virtual PHYs required, the bus_id will be in form
331 fixed_<num>@<speed>:<duplex>, which make it able even to define
332 driver-specific link control callback, if for instance PHY is completely
333 SW-driven.
334
335 */
336
337#ifdef CONFIG_FIXED_MII_DUPLEX
338 duplex = 1;
339#endif
340
341#ifdef CONFIG_FIXED_MII_100_FDX
342 fixed_mdio_register_device(0, 100, 1);
343#endif
344
345#ifdef CONFIX_FIXED_MII_10_FDX
346 fixed_mdio_register_device(0, 10, 1);
347#endif
348 return 0;
349}
350
351static void __exit fixed_exit(void)
352{
353 phy_driver_unregister(&fixed_mdio_driver);
354 /* :WARNING:02/18/2006 04:32:40 AM:: Cleanup all the created stuff */
355}
356
357module_init(fixed_init);
358module_exit(fixed_exit);
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 1dde390c164d..cf6660c93ffa 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -159,6 +159,7 @@ struct bus_type mdio_bus_type = {
159 .suspend = mdio_bus_suspend, 159 .suspend = mdio_bus_suspend,
160 .resume = mdio_bus_resume, 160 .resume = mdio_bus_resume,
161}; 161};
162EXPORT_SYMBOL(mdio_bus_type);
162 163
163int __init mdio_bus_init(void) 164int __init mdio_bus_init(void)
164{ 165{
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 7d5c2233c252..f5aad77288f9 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -419,9 +419,8 @@ void phy_start_machine(struct phy_device *phydev,
419 419
420/* phy_stop_machine 420/* phy_stop_machine
421 * 421 *
422 * description: Stops the state machine timer, sets the state to 422 * description: Stops the state machine timer, sets the state to UP
423 * UP (unless it wasn't up yet), and then frees the interrupt, 423 * (unless it wasn't up yet). This function must be called BEFORE
424 * if it is in use. This function must be called BEFORE
425 * phy_detach. 424 * phy_detach.
426 */ 425 */
427void phy_stop_machine(struct phy_device *phydev) 426void phy_stop_machine(struct phy_device *phydev)
@@ -433,9 +432,6 @@ void phy_stop_machine(struct phy_device *phydev)
433 phydev->state = PHY_UP; 432 phydev->state = PHY_UP;
434 spin_unlock(&phydev->lock); 433 spin_unlock(&phydev->lock);
435 434
436 if (phydev->irq != PHY_POLL)
437 phy_stop_interrupts(phydev);
438
439 phydev->adjust_state = NULL; 435 phydev->adjust_state = NULL;
440} 436}
441 437
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 1bc1e032c5d6..2d1ecfdc80db 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -45,6 +45,35 @@ static struct phy_driver genphy_driver;
45extern int mdio_bus_init(void); 45extern int mdio_bus_init(void);
46extern void mdio_bus_exit(void); 46extern void mdio_bus_exit(void);
47 47
48struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
49{
50 struct phy_device *dev;
51 /* We allocate the device, and initialize the
52 * default values */
53 dev = kcalloc(1, sizeof(*dev), GFP_KERNEL);
54
55 if (NULL == dev)
56 return (struct phy_device*) PTR_ERR((void*)-ENOMEM);
57
58 dev->speed = 0;
59 dev->duplex = -1;
60 dev->pause = dev->asym_pause = 0;
61 dev->link = 1;
62
63 dev->autoneg = AUTONEG_ENABLE;
64
65 dev->addr = addr;
66 dev->phy_id = phy_id;
67 dev->bus = bus;
68
69 dev->state = PHY_DOWN;
70
71 spin_lock_init(&dev->lock);
72
73 return dev;
74}
75EXPORT_SYMBOL(phy_device_create);
76
48/* get_phy_device 77/* get_phy_device
49 * 78 *
50 * description: Reads the ID registers of the PHY at addr on the 79 * description: Reads the ID registers of the PHY at addr on the
@@ -78,27 +107,7 @@ struct phy_device * get_phy_device(struct mii_bus *bus, int addr)
78 if (0xffffffff == phy_id) 107 if (0xffffffff == phy_id)
79 return NULL; 108 return NULL;
80 109
81 /* Otherwise, we allocate the device, and initialize the 110 dev = phy_device_create(bus, addr, phy_id);
82 * default values */
83 dev = kcalloc(1, sizeof(*dev), GFP_KERNEL);
84
85 if (NULL == dev)
86 return ERR_PTR(-ENOMEM);
87
88 dev->speed = 0;
89 dev->duplex = -1;
90 dev->pause = dev->asym_pause = 0;
91 dev->link = 1;
92
93 dev->autoneg = AUTONEG_ENABLE;
94
95 dev->addr = addr;
96 dev->phy_id = phy_id;
97 dev->bus = bus;
98
99 dev->state = PHY_DOWN;
100
101 spin_lock_init(&dev->lock);
102 111
103 return dev; 112 return dev;
104} 113}
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 0ec6e9d57b94..c872f7c6cce3 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -192,7 +192,7 @@ struct cardmap {
192 void *ptr[CARDMAP_WIDTH]; 192 void *ptr[CARDMAP_WIDTH];
193}; 193};
194static void *cardmap_get(struct cardmap *map, unsigned int nr); 194static void *cardmap_get(struct cardmap *map, unsigned int nr);
195static void cardmap_set(struct cardmap **map, unsigned int nr, void *ptr); 195static int cardmap_set(struct cardmap **map, unsigned int nr, void *ptr);
196static unsigned int cardmap_find_first_free(struct cardmap *map); 196static unsigned int cardmap_find_first_free(struct cardmap *map);
197static void cardmap_destroy(struct cardmap **map); 197static void cardmap_destroy(struct cardmap **map);
198 198
@@ -1995,10 +1995,9 @@ ppp_register_channel(struct ppp_channel *chan)
1995{ 1995{
1996 struct channel *pch; 1996 struct channel *pch;
1997 1997
1998 pch = kmalloc(sizeof(struct channel), GFP_KERNEL); 1998 pch = kzalloc(sizeof(struct channel), GFP_KERNEL);
1999 if (pch == 0) 1999 if (pch == 0)
2000 return -ENOMEM; 2000 return -ENOMEM;
2001 memset(pch, 0, sizeof(struct channel));
2002 pch->ppp = NULL; 2001 pch->ppp = NULL;
2003 pch->chan = chan; 2002 pch->chan = chan;
2004 chan->ppp = pch; 2003 chan->ppp = pch;
@@ -2408,13 +2407,12 @@ ppp_create_interface(int unit, int *retp)
2408 int ret = -ENOMEM; 2407 int ret = -ENOMEM;
2409 int i; 2408 int i;
2410 2409
2411 ppp = kmalloc(sizeof(struct ppp), GFP_KERNEL); 2410 ppp = kzalloc(sizeof(struct ppp), GFP_KERNEL);
2412 if (!ppp) 2411 if (!ppp)
2413 goto out; 2412 goto out;
2414 dev = alloc_netdev(0, "", ppp_setup); 2413 dev = alloc_netdev(0, "", ppp_setup);
2415 if (!dev) 2414 if (!dev)
2416 goto out1; 2415 goto out1;
2417 memset(ppp, 0, sizeof(struct ppp));
2418 2416
2419 ppp->mru = PPP_MRU; 2417 ppp->mru = PPP_MRU;
2420 init_ppp_file(&ppp->file, INTERFACE); 2418 init_ppp_file(&ppp->file, INTERFACE);
@@ -2454,11 +2452,16 @@ ppp_create_interface(int unit, int *retp)
2454 } 2452 }
2455 2453
2456 atomic_inc(&ppp_unit_count); 2454 atomic_inc(&ppp_unit_count);
2457 cardmap_set(&all_ppp_units, unit, ppp); 2455 ret = cardmap_set(&all_ppp_units, unit, ppp);
2456 if (ret != 0)
2457 goto out3;
2458
2458 mutex_unlock(&all_ppp_mutex); 2459 mutex_unlock(&all_ppp_mutex);
2459 *retp = 0; 2460 *retp = 0;
2460 return ppp; 2461 return ppp;
2461 2462
2463out3:
2464 atomic_dec(&ppp_unit_count);
2462out2: 2465out2:
2463 mutex_unlock(&all_ppp_mutex); 2466 mutex_unlock(&all_ppp_mutex);
2464 free_netdev(dev); 2467 free_netdev(dev);
@@ -2695,7 +2698,7 @@ static void *cardmap_get(struct cardmap *map, unsigned int nr)
2695 return NULL; 2698 return NULL;
2696} 2699}
2697 2700
2698static void cardmap_set(struct cardmap **pmap, unsigned int nr, void *ptr) 2701static int cardmap_set(struct cardmap **pmap, unsigned int nr, void *ptr)
2699{ 2702{
2700 struct cardmap *p; 2703 struct cardmap *p;
2701 int i; 2704 int i;
@@ -2704,8 +2707,9 @@ static void cardmap_set(struct cardmap **pmap, unsigned int nr, void *ptr)
2704 if (p == NULL || (nr >> p->shift) >= CARDMAP_WIDTH) { 2707 if (p == NULL || (nr >> p->shift) >= CARDMAP_WIDTH) {
2705 do { 2708 do {
2706 /* need a new top level */ 2709 /* need a new top level */
2707 struct cardmap *np = kmalloc(sizeof(*np), GFP_KERNEL); 2710 struct cardmap *np = kzalloc(sizeof(*np), GFP_KERNEL);
2708 memset(np, 0, sizeof(*np)); 2711 if (!np)
2712 goto enomem;
2709 np->ptr[0] = p; 2713 np->ptr[0] = p;
2710 if (p != NULL) { 2714 if (p != NULL) {
2711 np->shift = p->shift + CARDMAP_ORDER; 2715 np->shift = p->shift + CARDMAP_ORDER;
@@ -2719,8 +2723,9 @@ static void cardmap_set(struct cardmap **pmap, unsigned int nr, void *ptr)
2719 while (p->shift > 0) { 2723 while (p->shift > 0) {
2720 i = (nr >> p->shift) & CARDMAP_MASK; 2724 i = (nr >> p->shift) & CARDMAP_MASK;
2721 if (p->ptr[i] == NULL) { 2725 if (p->ptr[i] == NULL) {
2722 struct cardmap *np = kmalloc(sizeof(*np), GFP_KERNEL); 2726 struct cardmap *np = kzalloc(sizeof(*np), GFP_KERNEL);
2723 memset(np, 0, sizeof(*np)); 2727 if (!np)
2728 goto enomem;
2724 np->shift = p->shift - CARDMAP_ORDER; 2729 np->shift = p->shift - CARDMAP_ORDER;
2725 np->parent = p; 2730 np->parent = p;
2726 p->ptr[i] = np; 2731 p->ptr[i] = np;
@@ -2735,6 +2740,9 @@ static void cardmap_set(struct cardmap **pmap, unsigned int nr, void *ptr)
2735 set_bit(i, &p->inuse); 2740 set_bit(i, &p->inuse);
2736 else 2741 else
2737 clear_bit(i, &p->inuse); 2742 clear_bit(i, &p->inuse);
2743 return 0;
2744 enomem:
2745 return -ENOMEM;
2738} 2746}
2739 2747
2740static unsigned int cardmap_find_first_free(struct cardmap *map) 2748static unsigned int cardmap_find_first_free(struct cardmap *map)
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 16a0ef1b1369..4c2f575faad7 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -1406,7 +1406,7 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out,
1406 dev = alloc_etherdev(sizeof (*tp)); 1406 dev = alloc_etherdev(sizeof (*tp));
1407 if (dev == NULL) { 1407 if (dev == NULL) {
1408 if (netif_msg_drv(&debug)) 1408 if (netif_msg_drv(&debug))
1409 printk(KERN_ERR PFX "unable to alloc new ethernet\n"); 1409 dev_err(&pdev->dev, "unable to alloc new ethernet\n");
1410 goto err_out; 1410 goto err_out;
1411 } 1411 }
1412 1412
@@ -1418,10 +1418,8 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out,
1418 /* enable device (incl. PCI PM wakeup and hotplug setup) */ 1418 /* enable device (incl. PCI PM wakeup and hotplug setup) */
1419 rc = pci_enable_device(pdev); 1419 rc = pci_enable_device(pdev);
1420 if (rc < 0) { 1420 if (rc < 0) {
1421 if (netif_msg_probe(tp)) { 1421 if (netif_msg_probe(tp))
1422 printk(KERN_ERR PFX "%s: enable failure\n", 1422 dev_err(&pdev->dev, "enable failure\n");
1423 pci_name(pdev));
1424 }
1425 goto err_out_free_dev; 1423 goto err_out_free_dev;
1426 } 1424 }
1427 1425
@@ -1437,37 +1435,32 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out,
1437 pci_read_config_word(pdev, pm_cap + PCI_PM_CTRL, &pwr_command); 1435 pci_read_config_word(pdev, pm_cap + PCI_PM_CTRL, &pwr_command);
1438 acpi_idle_state = pwr_command & PCI_PM_CTRL_STATE_MASK; 1436 acpi_idle_state = pwr_command & PCI_PM_CTRL_STATE_MASK;
1439 } else { 1437 } else {
1440 if (netif_msg_probe(tp)) { 1438 if (netif_msg_probe(tp))
1441 printk(KERN_ERR PFX 1439 dev_err(&pdev->dev,
1442 "PowerManagement capability not found.\n"); 1440 "PowerManagement capability not found.\n");
1443 }
1444 } 1441 }
1445 1442
1446 /* make sure PCI base addr 1 is MMIO */ 1443 /* make sure PCI base addr 1 is MMIO */
1447 if (!(pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { 1444 if (!(pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
1448 if (netif_msg_probe(tp)) { 1445 if (netif_msg_probe(tp))
1449 printk(KERN_ERR PFX 1446 dev_err(&pdev->dev,
1450 "region #1 not an MMIO resource, aborting\n"); 1447 "region #1 not an MMIO resource, aborting\n");
1451 }
1452 rc = -ENODEV; 1448 rc = -ENODEV;
1453 goto err_out_mwi; 1449 goto err_out_mwi;
1454 } 1450 }
1455 /* check for weird/broken PCI region reporting */ 1451 /* check for weird/broken PCI region reporting */
1456 if (pci_resource_len(pdev, 1) < R8169_REGS_SIZE) { 1452 if (pci_resource_len(pdev, 1) < R8169_REGS_SIZE) {
1457 if (netif_msg_probe(tp)) { 1453 if (netif_msg_probe(tp))
1458 printk(KERN_ERR PFX 1454 dev_err(&pdev->dev,
1459 "Invalid PCI region size(s), aborting\n"); 1455 "Invalid PCI region size(s), aborting\n");
1460 }
1461 rc = -ENODEV; 1456 rc = -ENODEV;
1462 goto err_out_mwi; 1457 goto err_out_mwi;
1463 } 1458 }
1464 1459
1465 rc = pci_request_regions(pdev, MODULENAME); 1460 rc = pci_request_regions(pdev, MODULENAME);
1466 if (rc < 0) { 1461 if (rc < 0) {
1467 if (netif_msg_probe(tp)) { 1462 if (netif_msg_probe(tp))
1468 printk(KERN_ERR PFX "%s: could not request regions.\n", 1463 dev_err(&pdev->dev, "could not request regions.\n");
1469 pci_name(pdev));
1470 }
1471 goto err_out_mwi; 1464 goto err_out_mwi;
1472 } 1465 }
1473 1466
@@ -1480,10 +1473,9 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out,
1480 } else { 1473 } else {
1481 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 1474 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1482 if (rc < 0) { 1475 if (rc < 0) {
1483 if (netif_msg_probe(tp)) { 1476 if (netif_msg_probe(tp))
1484 printk(KERN_ERR PFX 1477 dev_err(&pdev->dev,
1485 "DMA configuration failed.\n"); 1478 "DMA configuration failed.\n");
1486 }
1487 goto err_out_free_res; 1479 goto err_out_free_res;
1488 } 1480 }
1489 } 1481 }
@@ -1494,7 +1486,7 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out,
1494 ioaddr = ioremap(pci_resource_start(pdev, 1), R8169_REGS_SIZE); 1486 ioaddr = ioremap(pci_resource_start(pdev, 1), R8169_REGS_SIZE);
1495 if (ioaddr == NULL) { 1487 if (ioaddr == NULL) {
1496 if (netif_msg_probe(tp)) 1488 if (netif_msg_probe(tp))
1497 printk(KERN_ERR PFX "cannot remap MMIO, aborting\n"); 1489 dev_err(&pdev->dev, "cannot remap MMIO, aborting\n");
1498 rc = -EIO; 1490 rc = -EIO;
1499 goto err_out_free_res; 1491 goto err_out_free_res;
1500 } 1492 }
@@ -1526,9 +1518,9 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out,
1526 if (i < 0) { 1518 if (i < 0) {
1527 /* Unknown chip: assume array element #0, original RTL-8169 */ 1519 /* Unknown chip: assume array element #0, original RTL-8169 */
1528 if (netif_msg_probe(tp)) { 1520 if (netif_msg_probe(tp)) {
1529 printk(KERN_DEBUG PFX "PCI device %s: " 1521 dev_printk(KERN_DEBUG, &pdev->dev,
1530 "unknown chip version, assuming %s\n", 1522 "unknown chip version, assuming %s\n",
1531 pci_name(pdev), rtl_chip_info[0].name); 1523 rtl_chip_info[0].name);
1532 } 1524 }
1533 i++; 1525 i++;
1534 } 1526 }
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index c6b77acb35ef..e72e0e099060 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -71,12 +71,13 @@
71#include <asm/uaccess.h> 71#include <asm/uaccess.h>
72#include <asm/io.h> 72#include <asm/io.h>
73#include <asm/div64.h> 73#include <asm/div64.h>
74#include <asm/irq.h>
74 75
75/* local include */ 76/* local include */
76#include "s2io.h" 77#include "s2io.h"
77#include "s2io-regs.h" 78#include "s2io-regs.h"
78 79
79#define DRV_VERSION "2.0.14.2" 80#define DRV_VERSION "2.0.15.2"
80 81
81/* S2io Driver name & version. */ 82/* S2io Driver name & version. */
82static char s2io_driver_name[] = "Neterion"; 83static char s2io_driver_name[] = "Neterion";
@@ -370,38 +371,50 @@ static const u64 fix_mac[] = {
370 END_SIGN 371 END_SIGN
371}; 372};
372 373
374MODULE_AUTHOR("Raghavendra Koushik <raghavendra.koushik@neterion.com>");
375MODULE_LICENSE("GPL");
376MODULE_VERSION(DRV_VERSION);
377
378
373/* Module Loadable parameters. */ 379/* Module Loadable parameters. */
374static unsigned int tx_fifo_num = 1; 380S2IO_PARM_INT(tx_fifo_num, 1);
375static unsigned int tx_fifo_len[MAX_TX_FIFOS] = 381S2IO_PARM_INT(rx_ring_num, 1);
376 {DEFAULT_FIFO_0_LEN, [1 ...(MAX_TX_FIFOS - 1)] = DEFAULT_FIFO_1_7_LEN}; 382
377static unsigned int rx_ring_num = 1; 383
378static unsigned int rx_ring_sz[MAX_RX_RINGS] = 384S2IO_PARM_INT(rx_ring_mode, 1);
379 {[0 ...(MAX_RX_RINGS - 1)] = SMALL_BLK_CNT}; 385S2IO_PARM_INT(use_continuous_tx_intrs, 1);
380static unsigned int rts_frm_len[MAX_RX_RINGS] = 386S2IO_PARM_INT(rmac_pause_time, 0x100);
381 {[0 ...(MAX_RX_RINGS - 1)] = 0 }; 387S2IO_PARM_INT(mc_pause_threshold_q0q3, 187);
382static unsigned int rx_ring_mode = 1; 388S2IO_PARM_INT(mc_pause_threshold_q4q7, 187);
383static unsigned int use_continuous_tx_intrs = 1; 389S2IO_PARM_INT(shared_splits, 0);
384static unsigned int rmac_pause_time = 0x100; 390S2IO_PARM_INT(tmac_util_period, 5);
385static unsigned int mc_pause_threshold_q0q3 = 187; 391S2IO_PARM_INT(rmac_util_period, 5);
386static unsigned int mc_pause_threshold_q4q7 = 187; 392S2IO_PARM_INT(bimodal, 0);
387static unsigned int shared_splits; 393S2IO_PARM_INT(l3l4hdr_size, 128);
388static unsigned int tmac_util_period = 5;
389static unsigned int rmac_util_period = 5;
390static unsigned int bimodal = 0;
391static unsigned int l3l4hdr_size = 128;
392#ifndef CONFIG_S2IO_NAPI
393static unsigned int indicate_max_pkts;
394#endif
395/* Frequency of Rx desc syncs expressed as power of 2 */ 394/* Frequency of Rx desc syncs expressed as power of 2 */
396static unsigned int rxsync_frequency = 3; 395S2IO_PARM_INT(rxsync_frequency, 3);
397/* Interrupt type. Values can be 0(INTA), 1(MSI), 2(MSI_X) */ 396/* Interrupt type. Values can be 0(INTA), 1(MSI), 2(MSI_X) */
398static unsigned int intr_type = 0; 397S2IO_PARM_INT(intr_type, 0);
399/* Large receive offload feature */ 398/* Large receive offload feature */
400static unsigned int lro = 0; 399S2IO_PARM_INT(lro, 0);
401/* Max pkts to be aggregated by LRO at one time. If not specified, 400/* Max pkts to be aggregated by LRO at one time. If not specified,
402 * aggregation happens until we hit max IP pkt size(64K) 401 * aggregation happens until we hit max IP pkt size(64K)
403 */ 402 */
404static unsigned int lro_max_pkts = 0xFFFF; 403S2IO_PARM_INT(lro_max_pkts, 0xFFFF);
404#ifndef CONFIG_S2IO_NAPI
405S2IO_PARM_INT(indicate_max_pkts, 0);
406#endif
407
408static unsigned int tx_fifo_len[MAX_TX_FIFOS] =
409 {DEFAULT_FIFO_0_LEN, [1 ...(MAX_TX_FIFOS - 1)] = DEFAULT_FIFO_1_7_LEN};
410static unsigned int rx_ring_sz[MAX_RX_RINGS] =
411 {[0 ...(MAX_RX_RINGS - 1)] = SMALL_BLK_CNT};
412static unsigned int rts_frm_len[MAX_RX_RINGS] =
413 {[0 ...(MAX_RX_RINGS - 1)] = 0 };
414
415module_param_array(tx_fifo_len, uint, NULL, 0);
416module_param_array(rx_ring_sz, uint, NULL, 0);
417module_param_array(rts_frm_len, uint, NULL, 0);
405 418
406/* 419/*
407 * S2IO device table. 420 * S2IO device table.
@@ -464,10 +477,9 @@ static int init_shared_mem(struct s2io_nic *nic)
464 size += config->tx_cfg[i].fifo_len; 477 size += config->tx_cfg[i].fifo_len;
465 } 478 }
466 if (size > MAX_AVAILABLE_TXDS) { 479 if (size > MAX_AVAILABLE_TXDS) {
467 DBG_PRINT(ERR_DBG, "%s: Requested TxDs too high, ", 480 DBG_PRINT(ERR_DBG, "s2io: Requested TxDs too high, ");
468 __FUNCTION__);
469 DBG_PRINT(ERR_DBG, "Requested: %d, max supported: 8192\n", size); 481 DBG_PRINT(ERR_DBG, "Requested: %d, max supported: 8192\n", size);
470 return FAILURE; 482 return -EINVAL;
471 } 483 }
472 484
473 lst_size = (sizeof(TxD_t) * config->max_txds); 485 lst_size = (sizeof(TxD_t) * config->max_txds);
@@ -547,6 +559,7 @@ static int init_shared_mem(struct s2io_nic *nic)
547 nic->ufo_in_band_v = kmalloc((sizeof(u64) * size), GFP_KERNEL); 559 nic->ufo_in_band_v = kmalloc((sizeof(u64) * size), GFP_KERNEL);
548 if (!nic->ufo_in_band_v) 560 if (!nic->ufo_in_band_v)
549 return -ENOMEM; 561 return -ENOMEM;
562 memset(nic->ufo_in_band_v, 0, size);
550 563
551 /* Allocation and initialization of RXDs in Rings */ 564 /* Allocation and initialization of RXDs in Rings */
552 size = 0; 565 size = 0;
@@ -1213,7 +1226,7 @@ static int init_nic(struct s2io_nic *nic)
1213 break; 1226 break;
1214 } 1227 }
1215 1228
1216 /* Enable Tx FIFO partition 0. */ 1229 /* Enable all configured Tx FIFO partitions */
1217 val64 = readq(&bar0->tx_fifo_partition_0); 1230 val64 = readq(&bar0->tx_fifo_partition_0);
1218 val64 |= (TX_FIFO_PARTITION_EN); 1231 val64 |= (TX_FIFO_PARTITION_EN);
1219 writeq(val64, &bar0->tx_fifo_partition_0); 1232 writeq(val64, &bar0->tx_fifo_partition_0);
@@ -1650,7 +1663,7 @@ static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
1650 writeq(temp64, &bar0->general_int_mask); 1663 writeq(temp64, &bar0->general_int_mask);
1651 /* 1664 /*
1652 * If Hercules adapter enable GPIO otherwise 1665 * If Hercules adapter enable GPIO otherwise
1653 * disabled all PCIX, Flash, MDIO, IIC and GPIO 1666 * disable all PCIX, Flash, MDIO, IIC and GPIO
1654 * interrupts for now. 1667 * interrupts for now.
1655 * TODO 1668 * TODO
1656 */ 1669 */
@@ -1976,7 +1989,6 @@ static int start_nic(struct s2io_nic *nic)
1976 XENA_dev_config_t __iomem *bar0 = nic->bar0; 1989 XENA_dev_config_t __iomem *bar0 = nic->bar0;
1977 struct net_device *dev = nic->dev; 1990 struct net_device *dev = nic->dev;
1978 register u64 val64 = 0; 1991 register u64 val64 = 0;
1979 u16 interruptible;
1980 u16 subid, i; 1992 u16 subid, i;
1981 mac_info_t *mac_control; 1993 mac_info_t *mac_control;
1982 struct config_param *config; 1994 struct config_param *config;
@@ -2047,16 +2059,6 @@ static int start_nic(struct s2io_nic *nic)
2047 return FAILURE; 2059 return FAILURE;
2048 } 2060 }
2049 2061
2050 /* Enable select interrupts */
2051 if (nic->intr_type != INTA)
2052 en_dis_able_nic_intrs(nic, ENA_ALL_INTRS, DISABLE_INTRS);
2053 else {
2054 interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
2055 interruptible |= TX_PIC_INTR | RX_PIC_INTR;
2056 interruptible |= TX_MAC_INTR | RX_MAC_INTR;
2057 en_dis_able_nic_intrs(nic, interruptible, ENABLE_INTRS);
2058 }
2059
2060 /* 2062 /*
2061 * With some switches, link might be already up at this point. 2063 * With some switches, link might be already up at this point.
2062 * Because of this weird behavior, when we enable laser, 2064 * Because of this weird behavior, when we enable laser,
@@ -2130,7 +2132,7 @@ static struct sk_buff *s2io_txdl_getskb(fifo_info_t *fifo_data, TxD_t *txdlp, in
2130 frag->size, PCI_DMA_TODEVICE); 2132 frag->size, PCI_DMA_TODEVICE);
2131 } 2133 }
2132 } 2134 }
2133 txdlp->Host_Control = 0; 2135 memset(txdlp,0, (sizeof(TxD_t) * fifo_data->max_txds));
2134 return(skb); 2136 return(skb);
2135} 2137}
2136 2138
@@ -2382,9 +2384,14 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2382 skb->data = (void *) (unsigned long)tmp; 2384 skb->data = (void *) (unsigned long)tmp;
2383 skb->tail = (void *) (unsigned long)tmp; 2385 skb->tail = (void *) (unsigned long)tmp;
2384 2386
2385 ((RxD3_t*)rxdp)->Buffer0_ptr = 2387 if (!(((RxD3_t*)rxdp)->Buffer0_ptr))
2386 pci_map_single(nic->pdev, ba->ba_0, BUF0_LEN, 2388 ((RxD3_t*)rxdp)->Buffer0_ptr =
2389 pci_map_single(nic->pdev, ba->ba_0, BUF0_LEN,
2387 PCI_DMA_FROMDEVICE); 2390 PCI_DMA_FROMDEVICE);
2391 else
2392 pci_dma_sync_single_for_device(nic->pdev,
2393 (dma_addr_t) ((RxD3_t*)rxdp)->Buffer0_ptr,
2394 BUF0_LEN, PCI_DMA_FROMDEVICE);
2388 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN); 2395 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
2389 if (nic->rxd_mode == RXD_MODE_3B) { 2396 if (nic->rxd_mode == RXD_MODE_3B) {
2390 /* Two buffer mode */ 2397 /* Two buffer mode */
@@ -2397,10 +2404,13 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2397 (nic->pdev, skb->data, dev->mtu + 4, 2404 (nic->pdev, skb->data, dev->mtu + 4,
2398 PCI_DMA_FROMDEVICE); 2405 PCI_DMA_FROMDEVICE);
2399 2406
2400 /* Buffer-1 will be dummy buffer not used */ 2407 /* Buffer-1 will be dummy buffer. Not used */
2401 ((RxD3_t*)rxdp)->Buffer1_ptr = 2408 if (!(((RxD3_t*)rxdp)->Buffer1_ptr)) {
2402 pci_map_single(nic->pdev, ba->ba_1, BUF1_LEN, 2409 ((RxD3_t*)rxdp)->Buffer1_ptr =
2403 PCI_DMA_FROMDEVICE); 2410 pci_map_single(nic->pdev,
2411 ba->ba_1, BUF1_LEN,
2412 PCI_DMA_FROMDEVICE);
2413 }
2404 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1); 2414 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
2405 rxdp->Control_2 |= SET_BUFFER2_SIZE_3 2415 rxdp->Control_2 |= SET_BUFFER2_SIZE_3
2406 (dev->mtu + 4); 2416 (dev->mtu + 4);
@@ -2625,23 +2635,23 @@ no_rx:
2625} 2635}
2626#endif 2636#endif
2627 2637
2638#ifdef CONFIG_NET_POLL_CONTROLLER
2628/** 2639/**
2629 * s2io_netpoll - Rx interrupt service handler for netpoll support 2640 * s2io_netpoll - netpoll event handler entry point
2630 * @dev : pointer to the device structure. 2641 * @dev : pointer to the device structure.
2631 * Description: 2642 * Description:
2632 * Polling 'interrupt' - used by things like netconsole to send skbs 2643 * This function will be called by upper layer to check for events on the
2633 * without having to re-enable interrupts. It's not called while 2644 * interface in situations where interrupts are disabled. It is used for
2634 * the interrupt routine is executing. 2645 * specific in-kernel networking tasks, such as remote consoles and kernel
2646 * debugging over the network (example netdump in RedHat).
2635 */ 2647 */
2636
2637#ifdef CONFIG_NET_POLL_CONTROLLER
2638static void s2io_netpoll(struct net_device *dev) 2648static void s2io_netpoll(struct net_device *dev)
2639{ 2649{
2640 nic_t *nic = dev->priv; 2650 nic_t *nic = dev->priv;
2641 mac_info_t *mac_control; 2651 mac_info_t *mac_control;
2642 struct config_param *config; 2652 struct config_param *config;
2643 XENA_dev_config_t __iomem *bar0 = nic->bar0; 2653 XENA_dev_config_t __iomem *bar0 = nic->bar0;
2644 u64 val64; 2654 u64 val64 = 0xFFFFFFFFFFFFFFFFULL;
2645 int i; 2655 int i;
2646 2656
2647 disable_irq(dev->irq); 2657 disable_irq(dev->irq);
@@ -2650,9 +2660,17 @@ static void s2io_netpoll(struct net_device *dev)
2650 mac_control = &nic->mac_control; 2660 mac_control = &nic->mac_control;
2651 config = &nic->config; 2661 config = &nic->config;
2652 2662
2653 val64 = readq(&bar0->rx_traffic_int);
2654 writeq(val64, &bar0->rx_traffic_int); 2663 writeq(val64, &bar0->rx_traffic_int);
2664 writeq(val64, &bar0->tx_traffic_int);
2655 2665
2666 /* we need to free up the transmitted skbufs or else netpoll will
2667 * run out of skbs and will fail and eventually netpoll application such
2668 * as netdump will fail.
2669 */
2670 for (i = 0; i < config->tx_fifo_num; i++)
2671 tx_intr_handler(&mac_control->fifos[i]);
2672
2673 /* check for received packet and indicate up to network */
2656 for (i = 0; i < config->rx_ring_num; i++) 2674 for (i = 0; i < config->rx_ring_num; i++)
2657 rx_intr_handler(&mac_control->rings[i]); 2675 rx_intr_handler(&mac_control->rings[i]);
2658 2676
@@ -2719,7 +2737,7 @@ static void rx_intr_handler(ring_info_t *ring_data)
2719 /* If your are next to put index then it's FIFO full condition */ 2737 /* If your are next to put index then it's FIFO full condition */
2720 if ((get_block == put_block) && 2738 if ((get_block == put_block) &&
2721 (get_info.offset + 1) == put_info.offset) { 2739 (get_info.offset + 1) == put_info.offset) {
2722 DBG_PRINT(ERR_DBG, "%s: Ring Full\n",dev->name); 2740 DBG_PRINT(INTR_DBG, "%s: Ring Full\n",dev->name);
2723 break; 2741 break;
2724 } 2742 }
2725 skb = (struct sk_buff *) ((unsigned long)rxdp->Host_Control); 2743 skb = (struct sk_buff *) ((unsigned long)rxdp->Host_Control);
@@ -2739,18 +2757,15 @@ static void rx_intr_handler(ring_info_t *ring_data)
2739 HEADER_SNAP_SIZE, 2757 HEADER_SNAP_SIZE,
2740 PCI_DMA_FROMDEVICE); 2758 PCI_DMA_FROMDEVICE);
2741 } else if (nic->rxd_mode == RXD_MODE_3B) { 2759 } else if (nic->rxd_mode == RXD_MODE_3B) {
2742 pci_unmap_single(nic->pdev, (dma_addr_t) 2760 pci_dma_sync_single_for_cpu(nic->pdev, (dma_addr_t)
2743 ((RxD3_t*)rxdp)->Buffer0_ptr, 2761 ((RxD3_t*)rxdp)->Buffer0_ptr,
2744 BUF0_LEN, PCI_DMA_FROMDEVICE); 2762 BUF0_LEN, PCI_DMA_FROMDEVICE);
2745 pci_unmap_single(nic->pdev, (dma_addr_t) 2763 pci_unmap_single(nic->pdev, (dma_addr_t)
2746 ((RxD3_t*)rxdp)->Buffer1_ptr,
2747 BUF1_LEN, PCI_DMA_FROMDEVICE);
2748 pci_unmap_single(nic->pdev, (dma_addr_t)
2749 ((RxD3_t*)rxdp)->Buffer2_ptr, 2764 ((RxD3_t*)rxdp)->Buffer2_ptr,
2750 dev->mtu + 4, 2765 dev->mtu + 4,
2751 PCI_DMA_FROMDEVICE); 2766 PCI_DMA_FROMDEVICE);
2752 } else { 2767 } else {
2753 pci_unmap_single(nic->pdev, (dma_addr_t) 2768 pci_dma_sync_single_for_cpu(nic->pdev, (dma_addr_t)
2754 ((RxD3_t*)rxdp)->Buffer0_ptr, BUF0_LEN, 2769 ((RxD3_t*)rxdp)->Buffer0_ptr, BUF0_LEN,
2755 PCI_DMA_FROMDEVICE); 2770 PCI_DMA_FROMDEVICE);
2756 pci_unmap_single(nic->pdev, (dma_addr_t) 2771 pci_unmap_single(nic->pdev, (dma_addr_t)
@@ -3338,7 +3353,7 @@ static void s2io_reset(nic_t * sp)
3338 3353
3339 /* Clear certain PCI/PCI-X fields after reset */ 3354 /* Clear certain PCI/PCI-X fields after reset */
3340 if (sp->device_type == XFRAME_II_DEVICE) { 3355 if (sp->device_type == XFRAME_II_DEVICE) {
3341 /* Clear parity err detect bit */ 3356 /* Clear "detected parity error" bit */
3342 pci_write_config_word(sp->pdev, PCI_STATUS, 0x8000); 3357 pci_write_config_word(sp->pdev, PCI_STATUS, 0x8000);
3343 3358
3344 /* Clearing PCIX Ecc status register */ 3359 /* Clearing PCIX Ecc status register */
@@ -3539,7 +3554,7 @@ static void restore_xmsi_data(nic_t *nic)
3539 u64 val64; 3554 u64 val64;
3540 int i; 3555 int i;
3541 3556
3542 for (i=0; i< nic->avail_msix_vectors; i++) { 3557 for (i=0; i < MAX_REQUESTED_MSI_X; i++) {
3543 writeq(nic->msix_info[i].addr, &bar0->xmsi_address); 3558 writeq(nic->msix_info[i].addr, &bar0->xmsi_address);
3544 writeq(nic->msix_info[i].data, &bar0->xmsi_data); 3559 writeq(nic->msix_info[i].data, &bar0->xmsi_data);
3545 val64 = (BIT(7) | BIT(15) | vBIT(i, 26, 6)); 3560 val64 = (BIT(7) | BIT(15) | vBIT(i, 26, 6));
@@ -3558,7 +3573,7 @@ static void store_xmsi_data(nic_t *nic)
3558 int i; 3573 int i;
3559 3574
3560 /* Store and display */ 3575 /* Store and display */
3561 for (i=0; i< nic->avail_msix_vectors; i++) { 3576 for (i=0; i < MAX_REQUESTED_MSI_X; i++) {
3562 val64 = (BIT(15) | vBIT(i, 26, 6)); 3577 val64 = (BIT(15) | vBIT(i, 26, 6));
3563 writeq(val64, &bar0->xmsi_access); 3578 writeq(val64, &bar0->xmsi_access);
3564 if (wait_for_msix_trans(nic, i)) { 3579 if (wait_for_msix_trans(nic, i)) {
@@ -3749,101 +3764,19 @@ static int s2io_open(struct net_device *dev)
3749 if (err) { 3764 if (err) {
3750 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n", 3765 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
3751 dev->name); 3766 dev->name);
3752 if (err == -ENODEV) 3767 goto hw_init_failed;
3753 goto hw_init_failed;
3754 else
3755 goto hw_enable_failed;
3756 }
3757
3758 /* Store the values of the MSIX table in the nic_t structure */
3759 store_xmsi_data(sp);
3760
3761 /* After proper initialization of H/W, register ISR */
3762 if (sp->intr_type == MSI) {
3763 err = request_irq((int) sp->pdev->irq, s2io_msi_handle,
3764 IRQF_SHARED, sp->name, dev);
3765 if (err) {
3766 DBG_PRINT(ERR_DBG, "%s: MSI registration \
3767failed\n", dev->name);
3768 goto isr_registration_failed;
3769 }
3770 }
3771 if (sp->intr_type == MSI_X) {
3772 int i;
3773
3774 for (i=1; (sp->s2io_entries[i].in_use == MSIX_FLG); i++) {
3775 if (sp->s2io_entries[i].type == MSIX_FIFO_TYPE) {
3776 sprintf(sp->desc1, "%s:MSI-X-%d-TX",
3777 dev->name, i);
3778 err = request_irq(sp->entries[i].vector,
3779 s2io_msix_fifo_handle, 0, sp->desc1,
3780 sp->s2io_entries[i].arg);
3781 DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc1,
3782 (unsigned long long)sp->msix_info[i].addr);
3783 } else {
3784 sprintf(sp->desc2, "%s:MSI-X-%d-RX",
3785 dev->name, i);
3786 err = request_irq(sp->entries[i].vector,
3787 s2io_msix_ring_handle, 0, sp->desc2,
3788 sp->s2io_entries[i].arg);
3789 DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc2,
3790 (unsigned long long)sp->msix_info[i].addr);
3791 }
3792 if (err) {
3793 DBG_PRINT(ERR_DBG, "%s: MSI-X-%d registration \
3794failed\n", dev->name, i);
3795 DBG_PRINT(ERR_DBG, "Returned: %d\n", err);
3796 goto isr_registration_failed;
3797 }
3798 sp->s2io_entries[i].in_use = MSIX_REGISTERED_SUCCESS;
3799 }
3800 }
3801 if (sp->intr_type == INTA) {
3802 err = request_irq((int) sp->pdev->irq, s2io_isr, IRQF_SHARED,
3803 sp->name, dev);
3804 if (err) {
3805 DBG_PRINT(ERR_DBG, "%s: ISR registration failed\n",
3806 dev->name);
3807 goto isr_registration_failed;
3808 }
3809 } 3768 }
3810 3769
3811 if (s2io_set_mac_addr(dev, dev->dev_addr) == FAILURE) { 3770 if (s2io_set_mac_addr(dev, dev->dev_addr) == FAILURE) {
3812 DBG_PRINT(ERR_DBG, "Set Mac Address Failed\n"); 3771 DBG_PRINT(ERR_DBG, "Set Mac Address Failed\n");
3772 s2io_card_down(sp);
3813 err = -ENODEV; 3773 err = -ENODEV;
3814 goto setting_mac_address_failed; 3774 goto hw_init_failed;
3815 } 3775 }
3816 3776
3817 netif_start_queue(dev); 3777 netif_start_queue(dev);
3818 return 0; 3778 return 0;
3819 3779
3820setting_mac_address_failed:
3821 if (sp->intr_type != MSI_X)
3822 free_irq(sp->pdev->irq, dev);
3823isr_registration_failed:
3824 del_timer_sync(&sp->alarm_timer);
3825 if (sp->intr_type == MSI_X) {
3826 int i;
3827 u16 msi_control; /* Temp variable */
3828
3829 for (i=1; (sp->s2io_entries[i].in_use ==
3830 MSIX_REGISTERED_SUCCESS); i++) {
3831 int vector = sp->entries[i].vector;
3832 void *arg = sp->s2io_entries[i].arg;
3833
3834 free_irq(vector, arg);
3835 }
3836 pci_disable_msix(sp->pdev);
3837
3838 /* Temp */
3839 pci_read_config_word(sp->pdev, 0x42, &msi_control);
3840 msi_control &= 0xFFFE; /* Disable MSI */
3841 pci_write_config_word(sp->pdev, 0x42, msi_control);
3842 }
3843 else if (sp->intr_type == MSI)
3844 pci_disable_msi(sp->pdev);
3845hw_enable_failed:
3846 s2io_reset(sp);
3847hw_init_failed: 3780hw_init_failed:
3848 if (sp->intr_type == MSI_X) { 3781 if (sp->intr_type == MSI_X) {
3849 if (sp->entries) 3782 if (sp->entries)
@@ -3874,7 +3807,7 @@ static int s2io_close(struct net_device *dev)
3874 flush_scheduled_work(); 3807 flush_scheduled_work();
3875 netif_stop_queue(dev); 3808 netif_stop_queue(dev);
3876 /* Reset card, kill tasklet and free Tx and Rx buffers. */ 3809 /* Reset card, kill tasklet and free Tx and Rx buffers. */
3877 s2io_card_down(sp, 1); 3810 s2io_card_down(sp);
3878 3811
3879 sp->device_close_flag = TRUE; /* Device is shut down. */ 3812 sp->device_close_flag = TRUE; /* Device is shut down. */
3880 return 0; 3813 return 0;
@@ -3901,13 +3834,11 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
3901 TxD_t *txdp; 3834 TxD_t *txdp;
3902 TxFIFO_element_t __iomem *tx_fifo; 3835 TxFIFO_element_t __iomem *tx_fifo;
3903 unsigned long flags; 3836 unsigned long flags;
3904#ifdef NETIF_F_TSO
3905 int mss;
3906#endif
3907 u16 vlan_tag = 0; 3837 u16 vlan_tag = 0;
3908 int vlan_priority = 0; 3838 int vlan_priority = 0;
3909 mac_info_t *mac_control; 3839 mac_info_t *mac_control;
3910 struct config_param *config; 3840 struct config_param *config;
3841 int offload_type;
3911 3842
3912 mac_control = &sp->mac_control; 3843 mac_control = &sp->mac_control;
3913 config = &sp->config; 3844 config = &sp->config;
@@ -3955,13 +3886,11 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
3955 return 0; 3886 return 0;
3956 } 3887 }
3957 3888
3958 txdp->Control_1 = 0; 3889 offload_type = s2io_offload_type(skb);
3959 txdp->Control_2 = 0;
3960#ifdef NETIF_F_TSO 3890#ifdef NETIF_F_TSO
3961 mss = skb_shinfo(skb)->gso_size; 3891 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
3962 if (skb_shinfo(skb)->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
3963 txdp->Control_1 |= TXD_TCP_LSO_EN; 3892 txdp->Control_1 |= TXD_TCP_LSO_EN;
3964 txdp->Control_1 |= TXD_TCP_LSO_MSS(mss); 3893 txdp->Control_1 |= TXD_TCP_LSO_MSS(s2io_tcp_mss(skb));
3965 } 3894 }
3966#endif 3895#endif
3967 if (skb->ip_summed == CHECKSUM_HW) { 3896 if (skb->ip_summed == CHECKSUM_HW) {
@@ -3979,10 +3908,10 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
3979 } 3908 }
3980 3909
3981 frg_len = skb->len - skb->data_len; 3910 frg_len = skb->len - skb->data_len;
3982 if (skb_shinfo(skb)->gso_type == SKB_GSO_UDP) { 3911 if (offload_type == SKB_GSO_UDP) {
3983 int ufo_size; 3912 int ufo_size;
3984 3913
3985 ufo_size = skb_shinfo(skb)->gso_size; 3914 ufo_size = s2io_udp_mss(skb);
3986 ufo_size &= ~7; 3915 ufo_size &= ~7;
3987 txdp->Control_1 |= TXD_UFO_EN; 3916 txdp->Control_1 |= TXD_UFO_EN;
3988 txdp->Control_1 |= TXD_UFO_MSS(ufo_size); 3917 txdp->Control_1 |= TXD_UFO_MSS(ufo_size);
@@ -3999,16 +3928,13 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
3999 sp->ufo_in_band_v, 3928 sp->ufo_in_band_v,
4000 sizeof(u64), PCI_DMA_TODEVICE); 3929 sizeof(u64), PCI_DMA_TODEVICE);
4001 txdp++; 3930 txdp++;
4002 txdp->Control_1 = 0;
4003 txdp->Control_2 = 0;
4004 } 3931 }
4005 3932
4006 txdp->Buffer_Pointer = pci_map_single 3933 txdp->Buffer_Pointer = pci_map_single
4007 (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE); 3934 (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE);
4008 txdp->Host_Control = (unsigned long) skb; 3935 txdp->Host_Control = (unsigned long) skb;
4009 txdp->Control_1 |= TXD_BUFFER0_SIZE(frg_len); 3936 txdp->Control_1 |= TXD_BUFFER0_SIZE(frg_len);
4010 3937 if (offload_type == SKB_GSO_UDP)
4011 if (skb_shinfo(skb)->gso_type == SKB_GSO_UDP)
4012 txdp->Control_1 |= TXD_UFO_EN; 3938 txdp->Control_1 |= TXD_UFO_EN;
4013 3939
4014 frg_cnt = skb_shinfo(skb)->nr_frags; 3940 frg_cnt = skb_shinfo(skb)->nr_frags;
@@ -4023,12 +3949,12 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
4023 (sp->pdev, frag->page, frag->page_offset, 3949 (sp->pdev, frag->page, frag->page_offset,
4024 frag->size, PCI_DMA_TODEVICE); 3950 frag->size, PCI_DMA_TODEVICE);
4025 txdp->Control_1 = TXD_BUFFER0_SIZE(frag->size); 3951 txdp->Control_1 = TXD_BUFFER0_SIZE(frag->size);
4026 if (skb_shinfo(skb)->gso_type == SKB_GSO_UDP) 3952 if (offload_type == SKB_GSO_UDP)
4027 txdp->Control_1 |= TXD_UFO_EN; 3953 txdp->Control_1 |= TXD_UFO_EN;
4028 } 3954 }
4029 txdp->Control_1 |= TXD_GATHER_CODE_LAST; 3955 txdp->Control_1 |= TXD_GATHER_CODE_LAST;
4030 3956
4031 if (skb_shinfo(skb)->gso_type == SKB_GSO_UDP) 3957 if (offload_type == SKB_GSO_UDP)
4032 frg_cnt++; /* as Txd0 was used for inband header */ 3958 frg_cnt++; /* as Txd0 was used for inband header */
4033 3959
4034 tx_fifo = mac_control->tx_FIFO_start[queue]; 3960 tx_fifo = mac_control->tx_FIFO_start[queue];
@@ -4037,13 +3963,9 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
4037 3963
4038 val64 = (TX_FIFO_LAST_TXD_NUM(frg_cnt) | TX_FIFO_FIRST_LIST | 3964 val64 = (TX_FIFO_LAST_TXD_NUM(frg_cnt) | TX_FIFO_FIRST_LIST |
4039 TX_FIFO_LAST_LIST); 3965 TX_FIFO_LAST_LIST);
4040 3966 if (offload_type)
4041#ifdef NETIF_F_TSO
4042 if (mss)
4043 val64 |= TX_FIFO_SPECIAL_FUNC;
4044#endif
4045 if (skb_shinfo(skb)->gso_type == SKB_GSO_UDP)
4046 val64 |= TX_FIFO_SPECIAL_FUNC; 3967 val64 |= TX_FIFO_SPECIAL_FUNC;
3968
4047 writeq(val64, &tx_fifo->List_Control); 3969 writeq(val64, &tx_fifo->List_Control);
4048 3970
4049 mmiowb(); 3971 mmiowb();
@@ -4077,13 +3999,41 @@ s2io_alarm_handle(unsigned long data)
4077 mod_timer(&sp->alarm_timer, jiffies + HZ / 2); 3999 mod_timer(&sp->alarm_timer, jiffies + HZ / 2);
4078} 4000}
4079 4001
4002static int s2io_chk_rx_buffers(nic_t *sp, int rng_n)
4003{
4004 int rxb_size, level;
4005
4006 if (!sp->lro) {
4007 rxb_size = atomic_read(&sp->rx_bufs_left[rng_n]);
4008 level = rx_buffer_level(sp, rxb_size, rng_n);
4009
4010 if ((level == PANIC) && (!TASKLET_IN_USE)) {
4011 int ret;
4012 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", __FUNCTION__);
4013 DBG_PRINT(INTR_DBG, "PANIC levels\n");
4014 if ((ret = fill_rx_buffers(sp, rng_n)) == -ENOMEM) {
4015 DBG_PRINT(ERR_DBG, "Out of memory in %s",
4016 __FUNCTION__);
4017 clear_bit(0, (&sp->tasklet_status));
4018 return -1;
4019 }
4020 clear_bit(0, (&sp->tasklet_status));
4021 } else if (level == LOW)
4022 tasklet_schedule(&sp->task);
4023
4024 } else if (fill_rx_buffers(sp, rng_n) == -ENOMEM) {
4025 DBG_PRINT(ERR_DBG, "%s:Out of memory", sp->dev->name);
4026 DBG_PRINT(ERR_DBG, " in Rx Intr!!\n");
4027 }
4028 return 0;
4029}
4030
4080static irqreturn_t 4031static irqreturn_t
4081s2io_msi_handle(int irq, void *dev_id, struct pt_regs *regs) 4032s2io_msi_handle(int irq, void *dev_id, struct pt_regs *regs)
4082{ 4033{
4083 struct net_device *dev = (struct net_device *) dev_id; 4034 struct net_device *dev = (struct net_device *) dev_id;
4084 nic_t *sp = dev->priv; 4035 nic_t *sp = dev->priv;
4085 int i; 4036 int i;
4086 int ret;
4087 mac_info_t *mac_control; 4037 mac_info_t *mac_control;
4088 struct config_param *config; 4038 struct config_param *config;
4089 4039
@@ -4105,35 +4055,8 @@ s2io_msi_handle(int irq, void *dev_id, struct pt_regs *regs)
4105 * reallocate the buffers from the interrupt handler itself, 4055 * reallocate the buffers from the interrupt handler itself,
4106 * else schedule a tasklet to reallocate the buffers. 4056 * else schedule a tasklet to reallocate the buffers.
4107 */ 4057 */
4108 for (i = 0; i < config->rx_ring_num; i++) { 4058 for (i = 0; i < config->rx_ring_num; i++)
4109 if (!sp->lro) { 4059 s2io_chk_rx_buffers(sp, i);
4110 int rxb_size = atomic_read(&sp->rx_bufs_left[i]);
4111 int level = rx_buffer_level(sp, rxb_size, i);
4112
4113 if ((level == PANIC) && (!TASKLET_IN_USE)) {
4114 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ",
4115 dev->name);
4116 DBG_PRINT(INTR_DBG, "PANIC levels\n");
4117 if ((ret = fill_rx_buffers(sp, i)) == -ENOMEM) {
4118 DBG_PRINT(ERR_DBG, "%s:Out of memory",
4119 dev->name);
4120 DBG_PRINT(ERR_DBG, " in ISR!!\n");
4121 clear_bit(0, (&sp->tasklet_status));
4122 atomic_dec(&sp->isr_cnt);
4123 return IRQ_HANDLED;
4124 }
4125 clear_bit(0, (&sp->tasklet_status));
4126 } else if (level == LOW) {
4127 tasklet_schedule(&sp->task);
4128 }
4129 }
4130 else if (fill_rx_buffers(sp, i) == -ENOMEM) {
4131 DBG_PRINT(ERR_DBG, "%s:Out of memory",
4132 dev->name);
4133 DBG_PRINT(ERR_DBG, " in Rx Intr!!\n");
4134 break;
4135 }
4136 }
4137 4060
4138 atomic_dec(&sp->isr_cnt); 4061 atomic_dec(&sp->isr_cnt);
4139 return IRQ_HANDLED; 4062 return IRQ_HANDLED;
@@ -4144,39 +4067,13 @@ s2io_msix_ring_handle(int irq, void *dev_id, struct pt_regs *regs)
4144{ 4067{
4145 ring_info_t *ring = (ring_info_t *)dev_id; 4068 ring_info_t *ring = (ring_info_t *)dev_id;
4146 nic_t *sp = ring->nic; 4069 nic_t *sp = ring->nic;
4147 struct net_device *dev = (struct net_device *) dev_id;
4148 int rxb_size, level, rng_n;
4149 4070
4150 atomic_inc(&sp->isr_cnt); 4071 atomic_inc(&sp->isr_cnt);
4151 rx_intr_handler(ring);
4152 4072
4153 rng_n = ring->ring_no; 4073 rx_intr_handler(ring);
4154 if (!sp->lro) { 4074 s2io_chk_rx_buffers(sp, ring->ring_no);
4155 rxb_size = atomic_read(&sp->rx_bufs_left[rng_n]);
4156 level = rx_buffer_level(sp, rxb_size, rng_n);
4157
4158 if ((level == PANIC) && (!TASKLET_IN_USE)) {
4159 int ret;
4160 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", __FUNCTION__);
4161 DBG_PRINT(INTR_DBG, "PANIC levels\n");
4162 if ((ret = fill_rx_buffers(sp, rng_n)) == -ENOMEM) {
4163 DBG_PRINT(ERR_DBG, "Out of memory in %s",
4164 __FUNCTION__);
4165 clear_bit(0, (&sp->tasklet_status));
4166 return IRQ_HANDLED;
4167 }
4168 clear_bit(0, (&sp->tasklet_status));
4169 } else if (level == LOW) {
4170 tasklet_schedule(&sp->task);
4171 }
4172 }
4173 else if (fill_rx_buffers(sp, rng_n) == -ENOMEM) {
4174 DBG_PRINT(ERR_DBG, "%s:Out of memory", dev->name);
4175 DBG_PRINT(ERR_DBG, " in Rx Intr!!\n");
4176 }
4177 4075
4178 atomic_dec(&sp->isr_cnt); 4076 atomic_dec(&sp->isr_cnt);
4179
4180 return IRQ_HANDLED; 4077 return IRQ_HANDLED;
4181} 4078}
4182 4079
@@ -4341,37 +4238,8 @@ static irqreturn_t s2io_isr(int irq, void *dev_id, struct pt_regs *regs)
4341 * else schedule a tasklet to reallocate the buffers. 4238 * else schedule a tasklet to reallocate the buffers.
4342 */ 4239 */
4343#ifndef CONFIG_S2IO_NAPI 4240#ifndef CONFIG_S2IO_NAPI
4344 for (i = 0; i < config->rx_ring_num; i++) { 4241 for (i = 0; i < config->rx_ring_num; i++)
4345 if (!sp->lro) { 4242 s2io_chk_rx_buffers(sp, i);
4346 int ret;
4347 int rxb_size = atomic_read(&sp->rx_bufs_left[i]);
4348 int level = rx_buffer_level(sp, rxb_size, i);
4349
4350 if ((level == PANIC) && (!TASKLET_IN_USE)) {
4351 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ",
4352 dev->name);
4353 DBG_PRINT(INTR_DBG, "PANIC levels\n");
4354 if ((ret = fill_rx_buffers(sp, i)) == -ENOMEM) {
4355 DBG_PRINT(ERR_DBG, "%s:Out of memory",
4356 dev->name);
4357 DBG_PRINT(ERR_DBG, " in ISR!!\n");
4358 clear_bit(0, (&sp->tasklet_status));
4359 atomic_dec(&sp->isr_cnt);
4360 writeq(org_mask, &bar0->general_int_mask);
4361 return IRQ_HANDLED;
4362 }
4363 clear_bit(0, (&sp->tasklet_status));
4364 } else if (level == LOW) {
4365 tasklet_schedule(&sp->task);
4366 }
4367 }
4368 else if (fill_rx_buffers(sp, i) == -ENOMEM) {
4369 DBG_PRINT(ERR_DBG, "%s:Out of memory",
4370 dev->name);
4371 DBG_PRINT(ERR_DBG, " in Rx intr!!\n");
4372 break;
4373 }
4374 }
4375#endif 4243#endif
4376 writeq(org_mask, &bar0->general_int_mask); 4244 writeq(org_mask, &bar0->general_int_mask);
4377 atomic_dec(&sp->isr_cnt); 4245 atomic_dec(&sp->isr_cnt);
@@ -4401,6 +4269,8 @@ static void s2io_updt_stats(nic_t *sp)
4401 if (cnt == 5) 4269 if (cnt == 5)
4402 break; /* Updt failed */ 4270 break; /* Updt failed */
4403 } while(1); 4271 } while(1);
4272 } else {
4273 memset(sp->mac_control.stats_info, 0, sizeof(StatInfo_t));
4404 } 4274 }
4405} 4275}
4406 4276
@@ -5035,7 +4905,8 @@ static int write_eeprom(nic_t * sp, int off, u64 data, int cnt)
5035} 4905}
5036static void s2io_vpd_read(nic_t *nic) 4906static void s2io_vpd_read(nic_t *nic)
5037{ 4907{
5038 u8 vpd_data[256],data; 4908 u8 *vpd_data;
4909 u8 data;
5039 int i=0, cnt, fail = 0; 4910 int i=0, cnt, fail = 0;
5040 int vpd_addr = 0x80; 4911 int vpd_addr = 0x80;
5041 4912
@@ -5048,6 +4919,10 @@ static void s2io_vpd_read(nic_t *nic)
5048 vpd_addr = 0x50; 4919 vpd_addr = 0x50;
5049 } 4920 }
5050 4921
4922 vpd_data = kmalloc(256, GFP_KERNEL);
4923 if (!vpd_data)
4924 return;
4925
5051 for (i = 0; i < 256; i +=4 ) { 4926 for (i = 0; i < 256; i +=4 ) {
5052 pci_write_config_byte(nic->pdev, (vpd_addr + 2), i); 4927 pci_write_config_byte(nic->pdev, (vpd_addr + 2), i);
5053 pci_read_config_byte(nic->pdev, (vpd_addr + 2), &data); 4928 pci_read_config_byte(nic->pdev, (vpd_addr + 2), &data);
@@ -5070,6 +4945,7 @@ static void s2io_vpd_read(nic_t *nic)
5070 memset(nic->product_name, 0, vpd_data[1]); 4945 memset(nic->product_name, 0, vpd_data[1]);
5071 memcpy(nic->product_name, &vpd_data[3], vpd_data[1]); 4946 memcpy(nic->product_name, &vpd_data[3], vpd_data[1]);
5072 } 4947 }
4948 kfree(vpd_data);
5073} 4949}
5074 4950
5075/** 4951/**
@@ -5388,7 +5264,7 @@ static int s2io_link_test(nic_t * sp, uint64_t * data)
5388 else 5264 else
5389 *data = 0; 5265 *data = 0;
5390 5266
5391 return 0; 5267 return *data;
5392} 5268}
5393 5269
5394/** 5270/**
@@ -5846,6 +5722,19 @@ static int s2io_ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
5846 return 0; 5722 return 0;
5847} 5723}
5848 5724
5725static u32 s2io_ethtool_op_get_tso(struct net_device *dev)
5726{
5727 return (dev->features & NETIF_F_TSO) != 0;
5728}
5729static int s2io_ethtool_op_set_tso(struct net_device *dev, u32 data)
5730{
5731 if (data)
5732 dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
5733 else
5734 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
5735
5736 return 0;
5737}
5849 5738
5850static struct ethtool_ops netdev_ethtool_ops = { 5739static struct ethtool_ops netdev_ethtool_ops = {
5851 .get_settings = s2io_ethtool_gset, 5740 .get_settings = s2io_ethtool_gset,
@@ -5866,8 +5755,8 @@ static struct ethtool_ops netdev_ethtool_ops = {
5866 .get_sg = ethtool_op_get_sg, 5755 .get_sg = ethtool_op_get_sg,
5867 .set_sg = ethtool_op_set_sg, 5756 .set_sg = ethtool_op_set_sg,
5868#ifdef NETIF_F_TSO 5757#ifdef NETIF_F_TSO
5869 .get_tso = ethtool_op_get_tso, 5758 .get_tso = s2io_ethtool_op_get_tso,
5870 .set_tso = ethtool_op_set_tso, 5759 .set_tso = s2io_ethtool_op_set_tso,
5871#endif 5760#endif
5872 .get_ufo = ethtool_op_get_ufo, 5761 .get_ufo = ethtool_op_get_ufo,
5873 .set_ufo = ethtool_op_set_ufo, 5762 .set_ufo = ethtool_op_set_ufo,
@@ -5919,7 +5808,7 @@ static int s2io_change_mtu(struct net_device *dev, int new_mtu)
5919 5808
5920 dev->mtu = new_mtu; 5809 dev->mtu = new_mtu;
5921 if (netif_running(dev)) { 5810 if (netif_running(dev)) {
5922 s2io_card_down(sp, 0); 5811 s2io_card_down(sp);
5923 netif_stop_queue(dev); 5812 netif_stop_queue(dev);
5924 if (s2io_card_up(sp)) { 5813 if (s2io_card_up(sp)) {
5925 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n", 5814 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
@@ -6216,43 +6105,106 @@ static int rxd_owner_bit_reset(nic_t *sp)
6216 6105
6217} 6106}
6218 6107
6219static void s2io_card_down(nic_t * sp, int flag) 6108static int s2io_add_isr(nic_t * sp)
6220{ 6109{
6221 int cnt = 0; 6110 int ret = 0;
6222 XENA_dev_config_t __iomem *bar0 = sp->bar0;
6223 unsigned long flags;
6224 register u64 val64 = 0;
6225 struct net_device *dev = sp->dev; 6111 struct net_device *dev = sp->dev;
6112 int err = 0;
6226 6113
6227 del_timer_sync(&sp->alarm_timer); 6114 if (sp->intr_type == MSI)
6228 /* If s2io_set_link task is executing, wait till it completes. */ 6115 ret = s2io_enable_msi(sp);
6229 while (test_and_set_bit(0, &(sp->link_state))) { 6116 else if (sp->intr_type == MSI_X)
6230 msleep(50); 6117 ret = s2io_enable_msi_x(sp);
6118 if (ret) {
6119 DBG_PRINT(ERR_DBG, "%s: Defaulting to INTA\n", dev->name);
6120 sp->intr_type = INTA;
6231 } 6121 }
6232 atomic_set(&sp->card_state, CARD_DOWN);
6233 6122
6234 /* disable Tx and Rx traffic on the NIC */ 6123 /* Store the values of the MSIX table in the nic_t structure */
6235 stop_nic(sp); 6124 store_xmsi_data(sp);
6236 if (flag) {
6237 if (sp->intr_type == MSI_X) {
6238 int i;
6239 u16 msi_control;
6240 6125
6241 for (i=1; (sp->s2io_entries[i].in_use == 6126 /* After proper initialization of H/W, register ISR */
6242 MSIX_REGISTERED_SUCCESS); i++) { 6127 if (sp->intr_type == MSI) {
6243 int vector = sp->entries[i].vector; 6128 err = request_irq((int) sp->pdev->irq, s2io_msi_handle,
6244 void *arg = sp->s2io_entries[i].arg; 6129 IRQF_SHARED, sp->name, dev);
6130 if (err) {
6131 pci_disable_msi(sp->pdev);
6132 DBG_PRINT(ERR_DBG, "%s: MSI registration failed\n",
6133 dev->name);
6134 return -1;
6135 }
6136 }
6137 if (sp->intr_type == MSI_X) {
6138 int i;
6245 6139
6246 free_irq(vector, arg); 6140 for (i=1; (sp->s2io_entries[i].in_use == MSIX_FLG); i++) {
6141 if (sp->s2io_entries[i].type == MSIX_FIFO_TYPE) {
6142 sprintf(sp->desc[i], "%s:MSI-X-%d-TX",
6143 dev->name, i);
6144 err = request_irq(sp->entries[i].vector,
6145 s2io_msix_fifo_handle, 0, sp->desc[i],
6146 sp->s2io_entries[i].arg);
6147 DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc[i],
6148 (unsigned long long)sp->msix_info[i].addr);
6149 } else {
6150 sprintf(sp->desc[i], "%s:MSI-X-%d-RX",
6151 dev->name, i);
6152 err = request_irq(sp->entries[i].vector,
6153 s2io_msix_ring_handle, 0, sp->desc[i],
6154 sp->s2io_entries[i].arg);
6155 DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc[i],
6156 (unsigned long long)sp->msix_info[i].addr);
6247 } 6157 }
6248 pci_read_config_word(sp->pdev, 0x42, &msi_control); 6158 if (err) {
6249 msi_control &= 0xFFFE; /* Disable MSI */ 6159 DBG_PRINT(ERR_DBG,"%s:MSI-X-%d registration "
6250 pci_write_config_word(sp->pdev, 0x42, msi_control); 6160 "failed\n", dev->name, i);
6251 pci_disable_msix(sp->pdev); 6161 DBG_PRINT(ERR_DBG, "Returned: %d\n", err);
6252 } else { 6162 return -1;
6253 free_irq(sp->pdev->irq, dev); 6163 }
6254 if (sp->intr_type == MSI) 6164 sp->s2io_entries[i].in_use = MSIX_REGISTERED_SUCCESS;
6255 pci_disable_msi(sp->pdev); 6165 }
6166 }
6167 if (sp->intr_type == INTA) {
6168 err = request_irq((int) sp->pdev->irq, s2io_isr, IRQF_SHARED,
6169 sp->name, dev);
6170 if (err) {
6171 DBG_PRINT(ERR_DBG, "%s: ISR registration failed\n",
6172 dev->name);
6173 return -1;
6174 }
6175 }
6176 return 0;
6177}
6178static void s2io_rem_isr(nic_t * sp)
6179{
6180 int cnt = 0;
6181 struct net_device *dev = sp->dev;
6182
6183 if (sp->intr_type == MSI_X) {
6184 int i;
6185 u16 msi_control;
6186
6187 for (i=1; (sp->s2io_entries[i].in_use ==
6188 MSIX_REGISTERED_SUCCESS); i++) {
6189 int vector = sp->entries[i].vector;
6190 void *arg = sp->s2io_entries[i].arg;
6191
6192 free_irq(vector, arg);
6193 }
6194 pci_read_config_word(sp->pdev, 0x42, &msi_control);
6195 msi_control &= 0xFFFE; /* Disable MSI */
6196 pci_write_config_word(sp->pdev, 0x42, msi_control);
6197
6198 pci_disable_msix(sp->pdev);
6199 } else {
6200 free_irq(sp->pdev->irq, dev);
6201 if (sp->intr_type == MSI) {
6202 u16 val;
6203
6204 pci_disable_msi(sp->pdev);
6205 pci_read_config_word(sp->pdev, 0x4c, &val);
6206 val ^= 0x1;
6207 pci_write_config_word(sp->pdev, 0x4c, val);
6256 } 6208 }
6257 } 6209 }
6258 /* Waiting till all Interrupt handlers are complete */ 6210 /* Waiting till all Interrupt handlers are complete */
@@ -6263,6 +6215,26 @@ static void s2io_card_down(nic_t * sp, int flag)
6263 break; 6215 break;
6264 cnt++; 6216 cnt++;
6265 } while(cnt < 5); 6217 } while(cnt < 5);
6218}
6219
6220static void s2io_card_down(nic_t * sp)
6221{
6222 int cnt = 0;
6223 XENA_dev_config_t __iomem *bar0 = sp->bar0;
6224 unsigned long flags;
6225 register u64 val64 = 0;
6226
6227 del_timer_sync(&sp->alarm_timer);
6228 /* If s2io_set_link task is executing, wait till it completes. */
6229 while (test_and_set_bit(0, &(sp->link_state))) {
6230 msleep(50);
6231 }
6232 atomic_set(&sp->card_state, CARD_DOWN);
6233
6234 /* disable Tx and Rx traffic on the NIC */
6235 stop_nic(sp);
6236
6237 s2io_rem_isr(sp);
6266 6238
6267 /* Kill tasklet. */ 6239 /* Kill tasklet. */
6268 tasklet_kill(&sp->task); 6240 tasklet_kill(&sp->task);
@@ -6314,23 +6286,16 @@ static int s2io_card_up(nic_t * sp)
6314 mac_info_t *mac_control; 6286 mac_info_t *mac_control;
6315 struct config_param *config; 6287 struct config_param *config;
6316 struct net_device *dev = (struct net_device *) sp->dev; 6288 struct net_device *dev = (struct net_device *) sp->dev;
6289 u16 interruptible;
6317 6290
6318 /* Initialize the H/W I/O registers */ 6291 /* Initialize the H/W I/O registers */
6319 if (init_nic(sp) != 0) { 6292 if (init_nic(sp) != 0) {
6320 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n", 6293 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
6321 dev->name); 6294 dev->name);
6295 s2io_reset(sp);
6322 return -ENODEV; 6296 return -ENODEV;
6323 } 6297 }
6324 6298
6325 if (sp->intr_type == MSI)
6326 ret = s2io_enable_msi(sp);
6327 else if (sp->intr_type == MSI_X)
6328 ret = s2io_enable_msi_x(sp);
6329 if (ret) {
6330 DBG_PRINT(ERR_DBG, "%s: Defaulting to INTA\n", dev->name);
6331 sp->intr_type = INTA;
6332 }
6333
6334 /* 6299 /*
6335 * Initializing the Rx buffers. For now we are considering only 1 6300 * Initializing the Rx buffers. For now we are considering only 1
6336 * Rx ring and initializing buffers into 30 Rx blocks 6301 * Rx ring and initializing buffers into 30 Rx blocks
@@ -6354,28 +6319,46 @@ static int s2io_card_up(nic_t * sp)
6354 s2io_set_multicast(dev); 6319 s2io_set_multicast(dev);
6355 6320
6356 if (sp->lro) { 6321 if (sp->lro) {
6357 /* Initialize max aggregatable pkts based on MTU */ 6322 /* Initialize max aggregatable pkts per session based on MTU */
6358 sp->lro_max_aggr_per_sess = ((1<<16) - 1) / dev->mtu; 6323 sp->lro_max_aggr_per_sess = ((1<<16) - 1) / dev->mtu;
6359 /* Check if we can use(if specified) user provided value */ 6324 /* Check if we can use(if specified) user provided value */
6360 if (lro_max_pkts < sp->lro_max_aggr_per_sess) 6325 if (lro_max_pkts < sp->lro_max_aggr_per_sess)
6361 sp->lro_max_aggr_per_sess = lro_max_pkts; 6326 sp->lro_max_aggr_per_sess = lro_max_pkts;
6362 } 6327 }
6363 6328
6364 /* Enable tasklet for the device */
6365 tasklet_init(&sp->task, s2io_tasklet, (unsigned long) dev);
6366
6367 /* Enable Rx Traffic and interrupts on the NIC */ 6329 /* Enable Rx Traffic and interrupts on the NIC */
6368 if (start_nic(sp)) { 6330 if (start_nic(sp)) {
6369 DBG_PRINT(ERR_DBG, "%s: Starting NIC failed\n", dev->name); 6331 DBG_PRINT(ERR_DBG, "%s: Starting NIC failed\n", dev->name);
6370 tasklet_kill(&sp->task);
6371 s2io_reset(sp); 6332 s2io_reset(sp);
6372 free_irq(dev->irq, dev); 6333 free_rx_buffers(sp);
6334 return -ENODEV;
6335 }
6336
6337 /* Add interrupt service routine */
6338 if (s2io_add_isr(sp) != 0) {
6339 if (sp->intr_type == MSI_X)
6340 s2io_rem_isr(sp);
6341 s2io_reset(sp);
6373 free_rx_buffers(sp); 6342 free_rx_buffers(sp);
6374 return -ENODEV; 6343 return -ENODEV;
6375 } 6344 }
6376 6345
6377 S2IO_TIMER_CONF(sp->alarm_timer, s2io_alarm_handle, sp, (HZ/2)); 6346 S2IO_TIMER_CONF(sp->alarm_timer, s2io_alarm_handle, sp, (HZ/2));
6378 6347
6348 /* Enable tasklet for the device */
6349 tasklet_init(&sp->task, s2io_tasklet, (unsigned long) dev);
6350
6351 /* Enable select interrupts */
6352 if (sp->intr_type != INTA)
6353 en_dis_able_nic_intrs(sp, ENA_ALL_INTRS, DISABLE_INTRS);
6354 else {
6355 interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
6356 interruptible |= TX_PIC_INTR | RX_PIC_INTR;
6357 interruptible |= TX_MAC_INTR | RX_MAC_INTR;
6358 en_dis_able_nic_intrs(sp, interruptible, ENABLE_INTRS);
6359 }
6360
6361
6379 atomic_set(&sp->card_state, CARD_UP); 6362 atomic_set(&sp->card_state, CARD_UP);
6380 return 0; 6363 return 0;
6381} 6364}
@@ -6395,7 +6378,7 @@ static void s2io_restart_nic(unsigned long data)
6395 struct net_device *dev = (struct net_device *) data; 6378 struct net_device *dev = (struct net_device *) data;
6396 nic_t *sp = dev->priv; 6379 nic_t *sp = dev->priv;
6397 6380
6398 s2io_card_down(sp, 0); 6381 s2io_card_down(sp);
6399 if (s2io_card_up(sp)) { 6382 if (s2io_card_up(sp)) {
6400 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n", 6383 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
6401 dev->name); 6384 dev->name);
@@ -6437,7 +6420,7 @@ static void s2io_tx_watchdog(struct net_device *dev)
6437 * @cksum : FCS checksum of the frame. 6420 * @cksum : FCS checksum of the frame.
6438 * @ring_no : the ring from which this RxD was extracted. 6421 * @ring_no : the ring from which this RxD was extracted.
6439 * Description: 6422 * Description:
6440 * This function is called by the Tx interrupt serivce routine to perform 6423 * This function is called by the Rx interrupt serivce routine to perform
6441 * some OS related operations on the SKB before passing it to the upper 6424 * some OS related operations on the SKB before passing it to the upper
6442 * layers. It mainly checks if the checksum is OK, if so adds it to the 6425 * layers. It mainly checks if the checksum is OK, if so adds it to the
6443 * SKBs cksum variable, increments the Rx packet count and passes the SKB 6426 * SKBs cksum variable, increments the Rx packet count and passes the SKB
@@ -6697,33 +6680,6 @@ static void s2io_init_pci(nic_t * sp)
6697 pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd); 6680 pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
6698} 6681}
6699 6682
6700MODULE_AUTHOR("Raghavendra Koushik <raghavendra.koushik@neterion.com>");
6701MODULE_LICENSE("GPL");
6702MODULE_VERSION(DRV_VERSION);
6703
6704module_param(tx_fifo_num, int, 0);
6705module_param(rx_ring_num, int, 0);
6706module_param(rx_ring_mode, int, 0);
6707module_param_array(tx_fifo_len, uint, NULL, 0);
6708module_param_array(rx_ring_sz, uint, NULL, 0);
6709module_param_array(rts_frm_len, uint, NULL, 0);
6710module_param(use_continuous_tx_intrs, int, 1);
6711module_param(rmac_pause_time, int, 0);
6712module_param(mc_pause_threshold_q0q3, int, 0);
6713module_param(mc_pause_threshold_q4q7, int, 0);
6714module_param(shared_splits, int, 0);
6715module_param(tmac_util_period, int, 0);
6716module_param(rmac_util_period, int, 0);
6717module_param(bimodal, bool, 0);
6718module_param(l3l4hdr_size, int , 0);
6719#ifndef CONFIG_S2IO_NAPI
6720module_param(indicate_max_pkts, int, 0);
6721#endif
6722module_param(rxsync_frequency, int, 0);
6723module_param(intr_type, int, 0);
6724module_param(lro, int, 0);
6725module_param(lro_max_pkts, int, 0);
6726
6727static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type) 6683static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type)
6728{ 6684{
6729 if ( tx_fifo_num > 8) { 6685 if ( tx_fifo_num > 8) {
@@ -6831,8 +6787,8 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
6831 } 6787 }
6832 if (dev_intr_type != MSI_X) { 6788 if (dev_intr_type != MSI_X) {
6833 if (pci_request_regions(pdev, s2io_driver_name)) { 6789 if (pci_request_regions(pdev, s2io_driver_name)) {
6834 DBG_PRINT(ERR_DBG, "Request Regions failed\n"), 6790 DBG_PRINT(ERR_DBG, "Request Regions failed\n");
6835 pci_disable_device(pdev); 6791 pci_disable_device(pdev);
6836 return -ENODEV; 6792 return -ENODEV;
6837 } 6793 }
6838 } 6794 }
@@ -6956,7 +6912,7 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
6956 /* initialize the shared memory used by the NIC and the host */ 6912 /* initialize the shared memory used by the NIC and the host */
6957 if (init_shared_mem(sp)) { 6913 if (init_shared_mem(sp)) {
6958 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n", 6914 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n",
6959 __FUNCTION__); 6915 dev->name);
6960 ret = -ENOMEM; 6916 ret = -ENOMEM;
6961 goto mem_alloc_failed; 6917 goto mem_alloc_failed;
6962 } 6918 }
@@ -7093,6 +7049,9 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
7093 dev->addr_len = ETH_ALEN; 7049 dev->addr_len = ETH_ALEN;
7094 memcpy(dev->dev_addr, sp->def_mac_addr, ETH_ALEN); 7050 memcpy(dev->dev_addr, sp->def_mac_addr, ETH_ALEN);
7095 7051
7052 /* reset Nic and bring it to known state */
7053 s2io_reset(sp);
7054
7096 /* 7055 /*
7097 * Initialize the tasklet status and link state flags 7056 * Initialize the tasklet status and link state flags
7098 * and the card state parameter 7057 * and the card state parameter
@@ -7130,11 +7089,11 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
7130 goto register_failed; 7089 goto register_failed;
7131 } 7090 }
7132 s2io_vpd_read(sp); 7091 s2io_vpd_read(sp);
7133 DBG_PRINT(ERR_DBG, "%s: Neterion %s",dev->name, sp->product_name);
7134 DBG_PRINT(ERR_DBG, "(rev %d), Driver version %s\n",
7135 get_xena_rev_id(sp->pdev),
7136 s2io_driver_version);
7137 DBG_PRINT(ERR_DBG, "Copyright(c) 2002-2005 Neterion Inc.\n"); 7092 DBG_PRINT(ERR_DBG, "Copyright(c) 2002-2005 Neterion Inc.\n");
7093 DBG_PRINT(ERR_DBG, "%s: Neterion %s (rev %d)\n",dev->name,
7094 sp->product_name, get_xena_rev_id(sp->pdev));
7095 DBG_PRINT(ERR_DBG, "%s: Driver version %s\n", dev->name,
7096 s2io_driver_version);
7138 DBG_PRINT(ERR_DBG, "%s: MAC ADDR: " 7097 DBG_PRINT(ERR_DBG, "%s: MAC ADDR: "
7139 "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, 7098 "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name,
7140 sp->def_mac_addr[0].mac_addr[0], 7099 sp->def_mac_addr[0].mac_addr[0],
@@ -7435,8 +7394,13 @@ static int verify_l3_l4_lro_capable(lro_t *l_lro, struct iphdr *ip,
7435 if (ip->ihl != 5) /* IP has options */ 7394 if (ip->ihl != 5) /* IP has options */
7436 return -1; 7395 return -1;
7437 7396
7397 /* If we see CE codepoint in IP header, packet is not mergeable */
7398 if (INET_ECN_is_ce(ipv4_get_dsfield(ip)))
7399 return -1;
7400
7401 /* If we see ECE or CWR flags in TCP header, packet is not mergeable */
7438 if (tcp->urg || tcp->psh || tcp->rst || tcp->syn || tcp->fin || 7402 if (tcp->urg || tcp->psh || tcp->rst || tcp->syn || tcp->fin ||
7439 !tcp->ack) { 7403 tcp->ece || tcp->cwr || !tcp->ack) {
7440 /* 7404 /*
7441 * Currently recognize only the ack control word and 7405 * Currently recognize only the ack control word and
7442 * any other control field being set would result in 7406 * any other control field being set would result in
@@ -7590,18 +7554,16 @@ static void queue_rx_frame(struct sk_buff *skb)
7590static void lro_append_pkt(nic_t *sp, lro_t *lro, struct sk_buff *skb, 7554static void lro_append_pkt(nic_t *sp, lro_t *lro, struct sk_buff *skb,
7591 u32 tcp_len) 7555 u32 tcp_len)
7592{ 7556{
7593 struct sk_buff *tmp, *first = lro->parent; 7557 struct sk_buff *first = lro->parent;
7594 7558
7595 first->len += tcp_len; 7559 first->len += tcp_len;
7596 first->data_len = lro->frags_len; 7560 first->data_len = lro->frags_len;
7597 skb_pull(skb, (skb->len - tcp_len)); 7561 skb_pull(skb, (skb->len - tcp_len));
7598 if ((tmp = skb_shinfo(first)->frag_list)) { 7562 if (skb_shinfo(first)->frag_list)
7599 while (tmp->next) 7563 lro->last_frag->next = skb;
7600 tmp = tmp->next;
7601 tmp->next = skb;
7602 }
7603 else 7564 else
7604 skb_shinfo(first)->frag_list = skb; 7565 skb_shinfo(first)->frag_list = skb;
7566 lro->last_frag = skb;
7605 sp->mac_control.stats_info->sw_stat.clubbed_frms_cnt++; 7567 sp->mac_control.stats_info->sw_stat.clubbed_frms_cnt++;
7606 return; 7568 return;
7607} 7569}
diff --git a/drivers/net/s2io.h b/drivers/net/s2io.h
index c43f52179708..5ed49c3be1e9 100644
--- a/drivers/net/s2io.h
+++ b/drivers/net/s2io.h
@@ -719,6 +719,7 @@ struct msix_info_st {
719/* Data structure to represent a LRO session */ 719/* Data structure to represent a LRO session */
720typedef struct lro { 720typedef struct lro {
721 struct sk_buff *parent; 721 struct sk_buff *parent;
722 struct sk_buff *last_frag;
722 u8 *l2h; 723 u8 *l2h;
723 struct iphdr *iph; 724 struct iphdr *iph;
724 struct tcphdr *tcph; 725 struct tcphdr *tcph;
@@ -829,8 +830,7 @@ struct s2io_nic {
829#define MSIX_FLG 0xA5 830#define MSIX_FLG 0xA5
830 struct msix_entry *entries; 831 struct msix_entry *entries;
831 struct s2io_msix_entry *s2io_entries; 832 struct s2io_msix_entry *s2io_entries;
832 char desc1[35]; 833 char desc[MAX_REQUESTED_MSI_X][25];
833 char desc2[35];
834 834
835 int avail_msix_vectors; /* No. of MSI-X vectors granted by system */ 835 int avail_msix_vectors; /* No. of MSI-X vectors granted by system */
836 836
@@ -1002,7 +1002,7 @@ static int verify_xena_quiescence(nic_t *sp, u64 val64, int flag);
1002static struct ethtool_ops netdev_ethtool_ops; 1002static struct ethtool_ops netdev_ethtool_ops;
1003static void s2io_set_link(unsigned long data); 1003static void s2io_set_link(unsigned long data);
1004static int s2io_set_swapper(nic_t * sp); 1004static int s2io_set_swapper(nic_t * sp);
1005static void s2io_card_down(nic_t *nic, int flag); 1005static void s2io_card_down(nic_t *nic);
1006static int s2io_card_up(nic_t *nic); 1006static int s2io_card_up(nic_t *nic);
1007static int get_xena_rev_id(struct pci_dev *pdev); 1007static int get_xena_rev_id(struct pci_dev *pdev);
1008static void restore_xmsi_data(nic_t *nic); 1008static void restore_xmsi_data(nic_t *nic);
@@ -1012,4 +1012,13 @@ static void clear_lro_session(lro_t *lro);
1012static void queue_rx_frame(struct sk_buff *skb); 1012static void queue_rx_frame(struct sk_buff *skb);
1013static void update_L3L4_header(nic_t *sp, lro_t *lro); 1013static void update_L3L4_header(nic_t *sp, lro_t *lro);
1014static void lro_append_pkt(nic_t *sp, lro_t *lro, struct sk_buff *skb, u32 tcp_len); 1014static void lro_append_pkt(nic_t *sp, lro_t *lro, struct sk_buff *skb, u32 tcp_len);
1015
1016#define s2io_tcp_mss(skb) skb_shinfo(skb)->gso_size
1017#define s2io_udp_mss(skb) skb_shinfo(skb)->gso_size
1018#define s2io_offload_type(skb) skb_shinfo(skb)->gso_type
1019
1020#define S2IO_PARM_INT(X, def_val) \
1021 static unsigned int X = def_val;\
1022 module_param(X , uint, 0);
1023
1015#endif /* _S2IO_H */ 1024#endif /* _S2IO_H */
diff --git a/drivers/net/seeq8005.c b/drivers/net/seeq8005.c
index efd0f235020f..01392bca0223 100644
--- a/drivers/net/seeq8005.c
+++ b/drivers/net/seeq8005.c
@@ -742,7 +742,7 @@ module_param(irq, int, 0);
742MODULE_PARM_DESC(io, "SEEQ 8005 I/O base address"); 742MODULE_PARM_DESC(io, "SEEQ 8005 I/O base address");
743MODULE_PARM_DESC(irq, "SEEQ 8005 IRQ number"); 743MODULE_PARM_DESC(irq, "SEEQ 8005 IRQ number");
744 744
745int init_module(void) 745int __init init_module(void)
746{ 746{
747 dev_seeq = seeq8005_probe(-1); 747 dev_seeq = seeq8005_probe(-1);
748 if (IS_ERR(dev_seeq)) 748 if (IS_ERR(dev_seeq))
diff --git a/drivers/net/sk98lin/h/xmac_ii.h b/drivers/net/sk98lin/h/xmac_ii.h
index 2b19f8ad0318..7f8e6d0084c7 100644
--- a/drivers/net/sk98lin/h/xmac_ii.h
+++ b/drivers/net/sk98lin/h/xmac_ii.h
@@ -1473,7 +1473,7 @@ extern "C" {
1473#define GM_TXCR_FORCE_JAM (1<<15) /* Bit 15: Force Jam / Flow-Control */ 1473#define GM_TXCR_FORCE_JAM (1<<15) /* Bit 15: Force Jam / Flow-Control */
1474#define GM_TXCR_CRC_DIS (1<<14) /* Bit 14: Disable insertion of CRC */ 1474#define GM_TXCR_CRC_DIS (1<<14) /* Bit 14: Disable insertion of CRC */
1475#define GM_TXCR_PAD_DIS (1<<13) /* Bit 13: Disable padding of packets */ 1475#define GM_TXCR_PAD_DIS (1<<13) /* Bit 13: Disable padding of packets */
1476#define GM_TXCR_COL_THR_MSK (1<<10) /* Bit 12..10: Collision Threshold */ 1476#define GM_TXCR_COL_THR_MSK (7<<10) /* Bit 12..10: Collision Threshold */
1477 1477
1478#define TX_COL_THR(x) (SHIFT10(x) & GM_TXCR_COL_THR_MSK) 1478#define TX_COL_THR(x) (SHIFT10(x) & GM_TXCR_COL_THR_MSK)
1479 1479
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 82200bfaa8ed..ad878dfddef4 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -516,10 +516,7 @@ static int skge_set_pauseparam(struct net_device *dev,
516/* Chip internal frequency for clock calculations */ 516/* Chip internal frequency for clock calculations */
517static inline u32 hwkhz(const struct skge_hw *hw) 517static inline u32 hwkhz(const struct skge_hw *hw)
518{ 518{
519 if (hw->chip_id == CHIP_ID_GENESIS) 519 return (hw->chip_id == CHIP_ID_GENESIS) ? 53125 : 78125;
520 return 53215; /* or: 53.125 MHz */
521 else
522 return 78215; /* or: 78.125 MHz */
523} 520}
524 521
525/* Chip HZ to microseconds */ 522/* Chip HZ to microseconds */
@@ -2214,6 +2211,7 @@ static int skge_up(struct net_device *dev)
2214 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F); 2211 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F);
2215 skge_led(skge, LED_MODE_ON); 2212 skge_led(skge, LED_MODE_ON);
2216 2213
2214 netif_poll_enable(dev);
2217 return 0; 2215 return 0;
2218 2216
2219 free_rx_ring: 2217 free_rx_ring:
@@ -2282,6 +2280,7 @@ static int skge_down(struct net_device *dev)
2282 2280
2283 skge_led(skge, LED_MODE_OFF); 2281 skge_led(skge, LED_MODE_OFF);
2284 2282
2283 netif_poll_disable(dev);
2285 skge_tx_clean(skge); 2284 skge_tx_clean(skge);
2286 skge_rx_clean(skge); 2285 skge_rx_clean(skge);
2287 2286
diff --git a/drivers/net/skge.h b/drivers/net/skge.h
index ed19ff47ce11..593387b3c0dd 100644
--- a/drivers/net/skge.h
+++ b/drivers/net/skge.h
@@ -1734,11 +1734,11 @@ enum {
1734 GM_TXCR_FORCE_JAM = 1<<15, /* Bit 15: Force Jam / Flow-Control */ 1734 GM_TXCR_FORCE_JAM = 1<<15, /* Bit 15: Force Jam / Flow-Control */
1735 GM_TXCR_CRC_DIS = 1<<14, /* Bit 14: Disable insertion of CRC */ 1735 GM_TXCR_CRC_DIS = 1<<14, /* Bit 14: Disable insertion of CRC */
1736 GM_TXCR_PAD_DIS = 1<<13, /* Bit 13: Disable padding of packets */ 1736 GM_TXCR_PAD_DIS = 1<<13, /* Bit 13: Disable padding of packets */
1737 GM_TXCR_COL_THR_MSK = 1<<10, /* Bit 12..10: Collision Threshold */ 1737 GM_TXCR_COL_THR_MSK = 7<<10, /* Bit 12..10: Collision Threshold */
1738}; 1738};
1739 1739
1740#define TX_COL_THR(x) (((x)<<10) & GM_TXCR_COL_THR_MSK) 1740#define TX_COL_THR(x) (((x)<<10) & GM_TXCR_COL_THR_MSK)
1741#define TX_COL_DEF 0x04 1741#define TX_COL_DEF 0x04 /* late collision after 64 byte */
1742 1742
1743/* GM_RX_CTRL 16 bit r/w Receive Control Register */ 1743/* GM_RX_CTRL 16 bit r/w Receive Control Register */
1744enum { 1744enum {
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index 418f169a6a31..933e87f1cc68 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -50,7 +50,7 @@
50#include "sky2.h" 50#include "sky2.h"
51 51
52#define DRV_NAME "sky2" 52#define DRV_NAME "sky2"
53#define DRV_VERSION "1.4" 53#define DRV_VERSION "1.5"
54#define PFX DRV_NAME " " 54#define PFX DRV_NAME " "
55 55
56/* 56/*
@@ -65,6 +65,7 @@
65#define RX_MAX_PENDING (RX_LE_SIZE/2 - 2) 65#define RX_MAX_PENDING (RX_LE_SIZE/2 - 2)
66#define RX_DEF_PENDING RX_MAX_PENDING 66#define RX_DEF_PENDING RX_MAX_PENDING
67#define RX_SKB_ALIGN 8 67#define RX_SKB_ALIGN 8
68#define RX_BUF_WRITE 16
68 69
69#define TX_RING_SIZE 512 70#define TX_RING_SIZE 512
70#define TX_DEF_PENDING (TX_RING_SIZE - 1) 71#define TX_DEF_PENDING (TX_RING_SIZE - 1)
@@ -232,9 +233,10 @@ static void sky2_set_power_state(struct sky2_hw *hw, pci_power_t state)
232 if (hw->ports > 1) 233 if (hw->ports > 1)
233 reg1 |= PCI_Y2_PHY2_COMA; 234 reg1 |= PCI_Y2_PHY2_COMA;
234 } 235 }
236 sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
237 udelay(100);
235 238
236 if (hw->chip_id == CHIP_ID_YUKON_EC_U) { 239 if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
237 sky2_write16(hw, B0_CTST, Y2_HW_WOL_ON);
238 sky2_pci_write32(hw, PCI_DEV_REG3, 0); 240 sky2_pci_write32(hw, PCI_DEV_REG3, 0);
239 reg1 = sky2_pci_read32(hw, PCI_DEV_REG4); 241 reg1 = sky2_pci_read32(hw, PCI_DEV_REG4);
240 reg1 &= P_ASPM_CONTROL_MSK; 242 reg1 &= P_ASPM_CONTROL_MSK;
@@ -242,8 +244,6 @@ static void sky2_set_power_state(struct sky2_hw *hw, pci_power_t state)
242 sky2_pci_write32(hw, PCI_DEV_REG5, 0); 244 sky2_pci_write32(hw, PCI_DEV_REG5, 0);
243 } 245 }
244 246
245 sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
246
247 break; 247 break;
248 248
249 case PCI_D3hot: 249 case PCI_D3hot:
@@ -255,6 +255,7 @@ static void sky2_set_power_state(struct sky2_hw *hw, pci_power_t state)
255 else 255 else
256 reg1 |= (PCI_Y2_PHY1_POWD | PCI_Y2_PHY2_POWD); 256 reg1 |= (PCI_Y2_PHY1_POWD | PCI_Y2_PHY2_POWD);
257 sky2_pci_write32(hw, PCI_DEV_REG1, reg1); 257 sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
258 udelay(100);
258 259
259 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) 260 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
260 sky2_write8(hw, B2_Y2_CLK_GATE, 0); 261 sky2_write8(hw, B2_Y2_CLK_GATE, 0);
@@ -1159,7 +1160,7 @@ static unsigned tx_le_req(const struct sk_buff *skb)
1159 count = sizeof(dma_addr_t) / sizeof(u32); 1160 count = sizeof(dma_addr_t) / sizeof(u32);
1160 count += skb_shinfo(skb)->nr_frags * count; 1161 count += skb_shinfo(skb)->nr_frags * count;
1161 1162
1162 if (skb_shinfo(skb)->gso_size) 1163 if (skb_is_gso(skb))
1163 ++count; 1164 ++count;
1164 1165
1165 if (skb->ip_summed == CHECKSUM_HW) 1166 if (skb->ip_summed == CHECKSUM_HW)
@@ -1389,7 +1390,7 @@ static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
1389 } 1390 }
1390 1391
1391 sky2->tx_cons = put; 1392 sky2->tx_cons = put;
1392 if (tx_avail(sky2) > MAX_SKB_TX_LE) 1393 if (tx_avail(sky2) > MAX_SKB_TX_LE + 4)
1393 netif_wake_queue(dev); 1394 netif_wake_queue(dev);
1394} 1395}
1395 1396
@@ -1888,9 +1889,6 @@ resubmit:
1888 re->skb->ip_summed = CHECKSUM_NONE; 1889 re->skb->ip_summed = CHECKSUM_NONE;
1889 sky2_rx_add(sky2, re->mapaddr); 1890 sky2_rx_add(sky2, re->mapaddr);
1890 1891
1891 /* Tell receiver about new buffers. */
1892 sky2_put_idx(sky2->hw, rxqaddr[sky2->port], sky2->rx_put);
1893
1894 return skb; 1892 return skb;
1895 1893
1896oversize: 1894oversize:
@@ -1937,7 +1935,9 @@ static inline int sky2_more_work(const struct sky2_hw *hw)
1937/* Process status response ring */ 1935/* Process status response ring */
1938static int sky2_status_intr(struct sky2_hw *hw, int to_do) 1936static int sky2_status_intr(struct sky2_hw *hw, int to_do)
1939{ 1937{
1938 struct sky2_port *sky2;
1940 int work_done = 0; 1939 int work_done = 0;
1940 unsigned buf_write[2] = { 0, 0 };
1941 u16 hwidx = sky2_read16(hw, STAT_PUT_IDX); 1941 u16 hwidx = sky2_read16(hw, STAT_PUT_IDX);
1942 1942
1943 rmb(); 1943 rmb();
@@ -1945,7 +1945,6 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do)
1945 while (hw->st_idx != hwidx) { 1945 while (hw->st_idx != hwidx) {
1946 struct sky2_status_le *le = hw->st_le + hw->st_idx; 1946 struct sky2_status_le *le = hw->st_le + hw->st_idx;
1947 struct net_device *dev; 1947 struct net_device *dev;
1948 struct sky2_port *sky2;
1949 struct sk_buff *skb; 1948 struct sk_buff *skb;
1950 u32 status; 1949 u32 status;
1951 u16 length; 1950 u16 length;
@@ -1978,6 +1977,14 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do)
1978#endif 1977#endif
1979 netif_receive_skb(skb); 1978 netif_receive_skb(skb);
1980 1979
1980 /* Update receiver after 16 frames */
1981 if (++buf_write[le->link] == RX_BUF_WRITE) {
1982 sky2_put_idx(hw, rxqaddr[le->link],
1983 sky2->rx_put);
1984 buf_write[le->link] = 0;
1985 }
1986
1987 /* Stop after net poll weight */
1981 if (++work_done >= to_do) 1988 if (++work_done >= to_do)
1982 goto exit_loop; 1989 goto exit_loop;
1983 break; 1990 break;
@@ -2016,6 +2023,16 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do)
2016 } 2023 }
2017 2024
2018exit_loop: 2025exit_loop:
2026 if (buf_write[0]) {
2027 sky2 = netdev_priv(hw->dev[0]);
2028 sky2_put_idx(hw, Q_R1, sky2->rx_put);
2029 }
2030
2031 if (buf_write[1]) {
2032 sky2 = netdev_priv(hw->dev[1]);
2033 sky2_put_idx(hw, Q_R2, sky2->rx_put);
2034 }
2035
2019 return work_done; 2036 return work_done;
2020} 2037}
2021 2038
@@ -2186,9 +2203,6 @@ static int sky2_poll(struct net_device *dev0, int *budget)
2186 int work_done = 0; 2203 int work_done = 0;
2187 u32 status = sky2_read32(hw, B0_Y2_SP_EISR); 2204 u32 status = sky2_read32(hw, B0_Y2_SP_EISR);
2188 2205
2189 if (!~status)
2190 goto out;
2191
2192 if (status & Y2_IS_HW_ERR) 2206 if (status & Y2_IS_HW_ERR)
2193 sky2_hw_intr(hw); 2207 sky2_hw_intr(hw);
2194 2208
@@ -2225,7 +2239,7 @@ static int sky2_poll(struct net_device *dev0, int *budget)
2225 2239
2226 if (sky2_more_work(hw)) 2240 if (sky2_more_work(hw))
2227 return 1; 2241 return 1;
2228out: 2242
2229 netif_rx_complete(dev0); 2243 netif_rx_complete(dev0);
2230 2244
2231 sky2_read32(hw, B0_Y2_SP_LISR); 2245 sky2_read32(hw, B0_Y2_SP_LISR);
@@ -2286,7 +2300,7 @@ static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk)
2286} 2300}
2287 2301
2288 2302
2289static int __devinit sky2_reset(struct sky2_hw *hw) 2303static int sky2_reset(struct sky2_hw *hw)
2290{ 2304{
2291 u16 status; 2305 u16 status;
2292 u8 t8, pmd_type; 2306 u8 t8, pmd_type;
@@ -3437,17 +3451,14 @@ static int sky2_suspend(struct pci_dev *pdev, pm_message_t state)
3437 return -EINVAL; 3451 return -EINVAL;
3438 3452
3439 del_timer_sync(&hw->idle_timer); 3453 del_timer_sync(&hw->idle_timer);
3454 netif_poll_disable(hw->dev[0]);
3440 3455
3441 for (i = 0; i < hw->ports; i++) { 3456 for (i = 0; i < hw->ports; i++) {
3442 struct net_device *dev = hw->dev[i]; 3457 struct net_device *dev = hw->dev[i];
3443 3458
3444 if (dev) { 3459 if (netif_running(dev)) {
3445 if (!netif_running(dev))
3446 continue;
3447
3448 sky2_down(dev); 3460 sky2_down(dev);
3449 netif_device_detach(dev); 3461 netif_device_detach(dev);
3450 netif_poll_disable(dev);
3451 } 3462 }
3452 } 3463 }
3453 3464
@@ -3474,9 +3485,8 @@ static int sky2_resume(struct pci_dev *pdev)
3474 3485
3475 for (i = 0; i < hw->ports; i++) { 3486 for (i = 0; i < hw->ports; i++) {
3476 struct net_device *dev = hw->dev[i]; 3487 struct net_device *dev = hw->dev[i];
3477 if (dev && netif_running(dev)) { 3488 if (netif_running(dev)) {
3478 netif_device_attach(dev); 3489 netif_device_attach(dev);
3479 netif_poll_enable(dev);
3480 3490
3481 err = sky2_up(dev); 3491 err = sky2_up(dev);
3482 if (err) { 3492 if (err) {
@@ -3488,6 +3498,7 @@ static int sky2_resume(struct pci_dev *pdev)
3488 } 3498 }
3489 } 3499 }
3490 3500
3501 netif_poll_enable(hw->dev[0]);
3491 sky2_idle_start(hw); 3502 sky2_idle_start(hw);
3492out: 3503out:
3493 return err; 3504 return err;
diff --git a/drivers/net/sky2.h b/drivers/net/sky2.h
index 8a0bc5525f0a..2db8d19b22d1 100644
--- a/drivers/net/sky2.h
+++ b/drivers/net/sky2.h
@@ -1480,7 +1480,7 @@ enum {
1480 GM_TXCR_FORCE_JAM = 1<<15, /* Bit 15: Force Jam / Flow-Control */ 1480 GM_TXCR_FORCE_JAM = 1<<15, /* Bit 15: Force Jam / Flow-Control */
1481 GM_TXCR_CRC_DIS = 1<<14, /* Bit 14: Disable insertion of CRC */ 1481 GM_TXCR_CRC_DIS = 1<<14, /* Bit 14: Disable insertion of CRC */
1482 GM_TXCR_PAD_DIS = 1<<13, /* Bit 13: Disable padding of packets */ 1482 GM_TXCR_PAD_DIS = 1<<13, /* Bit 13: Disable padding of packets */
1483 GM_TXCR_COL_THR_MSK = 1<<10, /* Bit 12..10: Collision Threshold */ 1483 GM_TXCR_COL_THR_MSK = 7<<10, /* Bit 12..10: Collision Threshold */
1484}; 1484};
1485 1485
1486#define TX_COL_THR(x) (((x)<<10) & GM_TXCR_COL_THR_MSK) 1486#define TX_COL_THR(x) (((x)<<10) & GM_TXCR_COL_THR_MSK)
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index d37bd860b336..0b15290df278 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -1092,6 +1092,7 @@ static irqreturn_t smc911x_interrupt(int irq, void *dev_id, struct pt_regs *regs
1092 /* Spurious interrupt check */ 1092 /* Spurious interrupt check */
1093 if ((SMC_GET_IRQ_CFG() & (INT_CFG_IRQ_INT_ | INT_CFG_IRQ_EN_)) != 1093 if ((SMC_GET_IRQ_CFG() & (INT_CFG_IRQ_INT_ | INT_CFG_IRQ_EN_)) !=
1094 (INT_CFG_IRQ_INT_ | INT_CFG_IRQ_EN_)) { 1094 (INT_CFG_IRQ_INT_ | INT_CFG_IRQ_EN_)) {
1095 spin_unlock_irqrestore(&lp->lock, flags);
1095 return IRQ_NONE; 1096 return IRQ_NONE;
1096 } 1097 }
1097 1098
diff --git a/drivers/net/smc91x.c b/drivers/net/smc91x.c
index 3d8dcb6c8758..cf62373b808b 100644
--- a/drivers/net/smc91x.c
+++ b/drivers/net/smc91x.c
@@ -321,12 +321,12 @@ static void smc_reset(struct net_device *dev)
321 DBG(2, "%s: %s\n", dev->name, __FUNCTION__); 321 DBG(2, "%s: %s\n", dev->name, __FUNCTION__);
322 322
323 /* Disable all interrupts, block TX tasklet */ 323 /* Disable all interrupts, block TX tasklet */
324 spin_lock(&lp->lock); 324 spin_lock_irq(&lp->lock);
325 SMC_SELECT_BANK(2); 325 SMC_SELECT_BANK(2);
326 SMC_SET_INT_MASK(0); 326 SMC_SET_INT_MASK(0);
327 pending_skb = lp->pending_tx_skb; 327 pending_skb = lp->pending_tx_skb;
328 lp->pending_tx_skb = NULL; 328 lp->pending_tx_skb = NULL;
329 spin_unlock(&lp->lock); 329 spin_unlock_irq(&lp->lock);
330 330
331 /* free any pending tx skb */ 331 /* free any pending tx skb */
332 if (pending_skb) { 332 if (pending_skb) {
@@ -448,12 +448,12 @@ static void smc_shutdown(struct net_device *dev)
448 DBG(2, "%s: %s\n", CARDNAME, __FUNCTION__); 448 DBG(2, "%s: %s\n", CARDNAME, __FUNCTION__);
449 449
450 /* no more interrupts for me */ 450 /* no more interrupts for me */
451 spin_lock(&lp->lock); 451 spin_lock_irq(&lp->lock);
452 SMC_SELECT_BANK(2); 452 SMC_SELECT_BANK(2);
453 SMC_SET_INT_MASK(0); 453 SMC_SET_INT_MASK(0);
454 pending_skb = lp->pending_tx_skb; 454 pending_skb = lp->pending_tx_skb;
455 lp->pending_tx_skb = NULL; 455 lp->pending_tx_skb = NULL;
456 spin_unlock(&lp->lock); 456 spin_unlock_irq(&lp->lock);
457 if (pending_skb) 457 if (pending_skb)
458 dev_kfree_skb(pending_skb); 458 dev_kfree_skb(pending_skb);
459 459
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index b4028049ed76..7aa7fbac8224 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -136,14 +136,9 @@
136#define SMC_CAN_USE_32BIT 0 136#define SMC_CAN_USE_32BIT 0
137#define SMC_IO_SHIFT 0 137#define SMC_IO_SHIFT 0
138#define SMC_NOWAIT 1 138#define SMC_NOWAIT 1
139#define SMC_USE_PXA_DMA 1
140 139
141#define SMC_inb(a, r) readb((a) + (r))
142#define SMC_inw(a, r) readw((a) + (r)) 140#define SMC_inw(a, r) readw((a) + (r))
143#define SMC_inl(a, r) readl((a) + (r))
144#define SMC_outb(v, a, r) writeb(v, (a) + (r))
145#define SMC_outw(v, a, r) writew(v, (a) + (r)) 141#define SMC_outw(v, a, r) writew(v, (a) + (r))
146#define SMC_outl(v, a, r) writel(v, (a) + (r))
147#define SMC_insw(a, r, p, l) readsw((a) + (r), p, l) 142#define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
148#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l) 143#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
149 144
@@ -189,16 +184,10 @@ SMC_outw(u16 val, void __iomem *ioaddr, int reg)
189#define SMC_IO_SHIFT 0 184#define SMC_IO_SHIFT 0
190#define SMC_NOWAIT 1 185#define SMC_NOWAIT 1
191 186
192#define SMC_inb(a, r) readb((a) + (r))
193#define SMC_outb(v, a, r) writeb(v, (a) + (r))
194#define SMC_inw(a, r) readw((a) + (r)) 187#define SMC_inw(a, r) readw((a) + (r))
195#define SMC_outw(v, a, r) writew(v, (a) + (r)) 188#define SMC_outw(v, a, r) writew(v, (a) + (r))
196#define SMC_insw(a, r, p, l) readsw((a) + (r), p, l) 189#define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
197#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l) 190#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
198#define SMC_inl(a, r) readl((a) + (r))
199#define SMC_outl(v, a, r) writel(v, (a) + (r))
200#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
201#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
202 191
203#include <asm/mach-types.h> 192#include <asm/mach-types.h>
204#include <asm/arch/cpu.h> 193#include <asm/arch/cpu.h>
@@ -354,6 +343,42 @@ static inline void LPD7_SMC_outsw (unsigned char* a, int r,
354 343
355#define SMC_IRQ_FLAGS (0) 344#define SMC_IRQ_FLAGS (0)
356 345
346#elif defined(CONFIG_ARCH_VERSATILE)
347
348#define SMC_CAN_USE_8BIT 1
349#define SMC_CAN_USE_16BIT 1
350#define SMC_CAN_USE_32BIT 1
351#define SMC_NOWAIT 1
352
353#define SMC_inb(a, r) readb((a) + (r))
354#define SMC_inw(a, r) readw((a) + (r))
355#define SMC_inl(a, r) readl((a) + (r))
356#define SMC_outb(v, a, r) writeb(v, (a) + (r))
357#define SMC_outw(v, a, r) writew(v, (a) + (r))
358#define SMC_outl(v, a, r) writel(v, (a) + (r))
359#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
360#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
361
362#define SMC_IRQ_FLAGS (0)
363
364#elif defined(CONFIG_ARCH_VERSATILE)
365
366#define SMC_CAN_USE_8BIT 1
367#define SMC_CAN_USE_16BIT 1
368#define SMC_CAN_USE_32BIT 1
369#define SMC_NOWAIT 1
370
371#define SMC_inb(a, r) readb((a) + (r))
372#define SMC_inw(a, r) readw((a) + (r))
373#define SMC_inl(a, r) readl((a) + (r))
374#define SMC_outb(v, a, r) writeb(v, (a) + (r))
375#define SMC_outw(v, a, r) writew(v, (a) + (r))
376#define SMC_outl(v, a, r) writel(v, (a) + (r))
377#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
378#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
379
380#define SMC_IRQ_FLAGS (0)
381
357#else 382#else
358 383
359#define SMC_CAN_USE_8BIT 1 384#define SMC_CAN_USE_8BIT 1
diff --git a/drivers/net/spider_net.c b/drivers/net/spider_net.c
index fb1d5a8a45cf..88907218457a 100644
--- a/drivers/net/spider_net.c
+++ b/drivers/net/spider_net.c
@@ -84,7 +84,7 @@ MODULE_DEVICE_TABLE(pci, spider_net_pci_tbl);
84 * 84 *
85 * returns the content of the specified SMMIO register. 85 * returns the content of the specified SMMIO register.
86 */ 86 */
87static u32 87static inline u32
88spider_net_read_reg(struct spider_net_card *card, u32 reg) 88spider_net_read_reg(struct spider_net_card *card, u32 reg)
89{ 89{
90 u32 value; 90 u32 value;
@@ -101,7 +101,7 @@ spider_net_read_reg(struct spider_net_card *card, u32 reg)
101 * @reg: register to write to 101 * @reg: register to write to
102 * @value: value to write into the specified SMMIO register 102 * @value: value to write into the specified SMMIO register
103 */ 103 */
104static void 104static inline void
105spider_net_write_reg(struct spider_net_card *card, u32 reg, u32 value) 105spider_net_write_reg(struct spider_net_card *card, u32 reg, u32 value)
106{ 106{
107 value = cpu_to_le32(value); 107 value = cpu_to_le32(value);
@@ -259,39 +259,10 @@ spider_net_get_mac_address(struct net_device *netdev)
259 * 259 *
260 * returns the status as in the dmac_cmd_status field of the descriptor 260 * returns the status as in the dmac_cmd_status field of the descriptor
261 */ 261 */
262static enum spider_net_descr_status 262static inline int
263spider_net_get_descr_status(struct spider_net_descr *descr) 263spider_net_get_descr_status(struct spider_net_descr *descr)
264{ 264{
265 u32 cmd_status; 265 return descr->dmac_cmd_status & SPIDER_NET_DESCR_IND_PROC_MASK;
266
267 cmd_status = descr->dmac_cmd_status;
268 cmd_status >>= SPIDER_NET_DESCR_IND_PROC_SHIFT;
269 /* no need to mask out any bits, as cmd_status is 32 bits wide only
270 * (and unsigned) */
271 return cmd_status;
272}
273
274/**
275 * spider_net_set_descr_status -- sets the status of a descriptor
276 * @descr: descriptor to change
277 * @status: status to set in the descriptor
278 *
279 * changes the status to the specified value. Doesn't change other bits
280 * in the status
281 */
282static void
283spider_net_set_descr_status(struct spider_net_descr *descr,
284 enum spider_net_descr_status status)
285{
286 u32 cmd_status;
287 /* read the status */
288 cmd_status = descr->dmac_cmd_status;
289 /* clean the upper 4 bits */
290 cmd_status &= SPIDER_NET_DESCR_IND_PROC_MASKO;
291 /* add the status to it */
292 cmd_status |= ((u32)status)<<SPIDER_NET_DESCR_IND_PROC_SHIFT;
293 /* and write it back */
294 descr->dmac_cmd_status = cmd_status;
295} 266}
296 267
297/** 268/**
@@ -328,24 +299,23 @@ spider_net_free_chain(struct spider_net_card *card,
328static int 299static int
329spider_net_init_chain(struct spider_net_card *card, 300spider_net_init_chain(struct spider_net_card *card,
330 struct spider_net_descr_chain *chain, 301 struct spider_net_descr_chain *chain,
331 struct spider_net_descr *start_descr, int no) 302 struct spider_net_descr *start_descr,
303 int direction, int no)
332{ 304{
333 int i; 305 int i;
334 struct spider_net_descr *descr; 306 struct spider_net_descr *descr;
335 dma_addr_t buf; 307 dma_addr_t buf;
336 308
337 atomic_set(&card->rx_chain_refill,0);
338
339 descr = start_descr; 309 descr = start_descr;
340 memset(descr, 0, sizeof(*descr) * no); 310 memset(descr, 0, sizeof(*descr) * no);
341 311
342 /* set up the hardware pointers in each descriptor */ 312 /* set up the hardware pointers in each descriptor */
343 for (i=0; i<no; i++, descr++) { 313 for (i=0; i<no; i++, descr++) {
344 spider_net_set_descr_status(descr, SPIDER_NET_DESCR_NOT_IN_USE); 314 descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
345 315
346 buf = pci_map_single(card->pdev, descr, 316 buf = pci_map_single(card->pdev, descr,
347 SPIDER_NET_DESCR_SIZE, 317 SPIDER_NET_DESCR_SIZE,
348 PCI_DMA_BIDIRECTIONAL); 318 direction);
349 319
350 if (buf == DMA_ERROR_CODE) 320 if (buf == DMA_ERROR_CODE)
351 goto iommu_error; 321 goto iommu_error;
@@ -360,10 +330,11 @@ spider_net_init_chain(struct spider_net_card *card,
360 start_descr->prev = descr-1; 330 start_descr->prev = descr-1;
361 331
362 descr = start_descr; 332 descr = start_descr;
363 for (i=0; i < no; i++, descr++) { 333 if (direction == PCI_DMA_FROMDEVICE)
364 descr->next_descr_addr = descr->next->bus_addr; 334 for (i=0; i < no; i++, descr++)
365 } 335 descr->next_descr_addr = descr->next->bus_addr;
366 336
337 spin_lock_init(&chain->lock);
367 chain->head = start_descr; 338 chain->head = start_descr;
368 chain->tail = start_descr; 339 chain->tail = start_descr;
369 340
@@ -375,7 +346,7 @@ iommu_error:
375 if (descr->bus_addr) 346 if (descr->bus_addr)
376 pci_unmap_single(card->pdev, descr->bus_addr, 347 pci_unmap_single(card->pdev, descr->bus_addr,
377 SPIDER_NET_DESCR_SIZE, 348 SPIDER_NET_DESCR_SIZE,
378 PCI_DMA_BIDIRECTIONAL); 349 direction);
379 return -ENOMEM; 350 return -ENOMEM;
380} 351}
381 352
@@ -396,7 +367,7 @@ spider_net_free_rx_chain_contents(struct spider_net_card *card)
396 dev_kfree_skb(descr->skb); 367 dev_kfree_skb(descr->skb);
397 pci_unmap_single(card->pdev, descr->buf_addr, 368 pci_unmap_single(card->pdev, descr->buf_addr,
398 SPIDER_NET_MAX_FRAME, 369 SPIDER_NET_MAX_FRAME,
399 PCI_DMA_BIDIRECTIONAL); 370 PCI_DMA_FROMDEVICE);
400 } 371 }
401 descr = descr->next; 372 descr = descr->next;
402 } 373 }
@@ -446,15 +417,16 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
446 skb_reserve(descr->skb, SPIDER_NET_RXBUF_ALIGN - offset); 417 skb_reserve(descr->skb, SPIDER_NET_RXBUF_ALIGN - offset);
447 /* io-mmu-map the skb */ 418 /* io-mmu-map the skb */
448 buf = pci_map_single(card->pdev, descr->skb->data, 419 buf = pci_map_single(card->pdev, descr->skb->data,
449 SPIDER_NET_MAX_FRAME, PCI_DMA_BIDIRECTIONAL); 420 SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
450 descr->buf_addr = buf; 421 descr->buf_addr = buf;
451 if (buf == DMA_ERROR_CODE) { 422 if (buf == DMA_ERROR_CODE) {
452 dev_kfree_skb_any(descr->skb); 423 dev_kfree_skb_any(descr->skb);
453 if (netif_msg_rx_err(card) && net_ratelimit()) 424 if (netif_msg_rx_err(card) && net_ratelimit())
454 pr_err("Could not iommu-map rx buffer\n"); 425 pr_err("Could not iommu-map rx buffer\n");
455 spider_net_set_descr_status(descr, SPIDER_NET_DESCR_NOT_IN_USE); 426 descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
456 } else { 427 } else {
457 descr->dmac_cmd_status = SPIDER_NET_DMAC_RX_CARDOWNED; 428 descr->dmac_cmd_status = SPIDER_NET_DESCR_CARDOWNED |
429 SPIDER_NET_DMAC_NOINTR_COMPLETE;
458 } 430 }
459 431
460 return error; 432 return error;
@@ -468,7 +440,7 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
468 * chip by writing to the appropriate register. DMA is enabled in 440 * chip by writing to the appropriate register. DMA is enabled in
469 * spider_net_enable_rxdmac. 441 * spider_net_enable_rxdmac.
470 */ 442 */
471static void 443static inline void
472spider_net_enable_rxchtails(struct spider_net_card *card) 444spider_net_enable_rxchtails(struct spider_net_card *card)
473{ 445{
474 /* assume chain is aligned correctly */ 446 /* assume chain is aligned correctly */
@@ -483,7 +455,7 @@ spider_net_enable_rxchtails(struct spider_net_card *card)
483 * spider_net_enable_rxdmac enables the DMA controller by setting RX_DMA_EN 455 * spider_net_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
484 * in the GDADMACCNTR register 456 * in the GDADMACCNTR register
485 */ 457 */
486static void 458static inline void
487spider_net_enable_rxdmac(struct spider_net_card *card) 459spider_net_enable_rxdmac(struct spider_net_card *card)
488{ 460{
489 wmb(); 461 wmb();
@@ -500,23 +472,24 @@ spider_net_enable_rxdmac(struct spider_net_card *card)
500static void 472static void
501spider_net_refill_rx_chain(struct spider_net_card *card) 473spider_net_refill_rx_chain(struct spider_net_card *card)
502{ 474{
503 struct spider_net_descr_chain *chain; 475 struct spider_net_descr_chain *chain = &card->rx_chain;
504 476 unsigned long flags;
505 chain = &card->rx_chain;
506 477
507 /* one context doing the refill (and a second context seeing that 478 /* one context doing the refill (and a second context seeing that
508 * and omitting it) is ok. If called by NAPI, we'll be called again 479 * and omitting it) is ok. If called by NAPI, we'll be called again
509 * as spider_net_decode_one_descr is called several times. If some 480 * as spider_net_decode_one_descr is called several times. If some
510 * interrupt calls us, the NAPI is about to clean up anyway. */ 481 * interrupt calls us, the NAPI is about to clean up anyway. */
511 if (atomic_inc_return(&card->rx_chain_refill) == 1) 482 if (!spin_trylock_irqsave(&chain->lock, flags))
512 while (spider_net_get_descr_status(chain->head) == 483 return;
513 SPIDER_NET_DESCR_NOT_IN_USE) { 484
514 if (spider_net_prepare_rx_descr(card, chain->head)) 485 while (spider_net_get_descr_status(chain->head) ==
515 break; 486 SPIDER_NET_DESCR_NOT_IN_USE) {
516 chain->head = chain->head->next; 487 if (spider_net_prepare_rx_descr(card, chain->head))
517 } 488 break;
489 chain->head = chain->head->next;
490 }
518 491
519 atomic_dec(&card->rx_chain_refill); 492 spin_unlock_irqrestore(&chain->lock, flags);
520} 493}
521 494
522/** 495/**
@@ -554,111 +527,6 @@ error:
554} 527}
555 528
556/** 529/**
557 * spider_net_release_tx_descr - processes a used tx descriptor
558 * @card: card structure
559 * @descr: descriptor to release
560 *
561 * releases a used tx descriptor (unmapping, freeing of skb)
562 */
563static void
564spider_net_release_tx_descr(struct spider_net_card *card,
565 struct spider_net_descr *descr)
566{
567 struct sk_buff *skb;
568
569 /* unmap the skb */
570 skb = descr->skb;
571 pci_unmap_single(card->pdev, descr->buf_addr, skb->len,
572 PCI_DMA_BIDIRECTIONAL);
573
574 dev_kfree_skb_any(skb);
575
576 /* set status to not used */
577 spider_net_set_descr_status(descr, SPIDER_NET_DESCR_NOT_IN_USE);
578}
579
580/**
581 * spider_net_release_tx_chain - processes sent tx descriptors
582 * @card: adapter structure
583 * @brutal: if set, don't care about whether descriptor seems to be in use
584 *
585 * returns 0 if the tx ring is empty, otherwise 1.
586 *
587 * spider_net_release_tx_chain releases the tx descriptors that spider has
588 * finished with (if non-brutal) or simply release tx descriptors (if brutal).
589 * If some other context is calling this function, we return 1 so that we're
590 * scheduled again (if we were scheduled) and will not loose initiative.
591 */
592static int
593spider_net_release_tx_chain(struct spider_net_card *card, int brutal)
594{
595 struct spider_net_descr_chain *tx_chain = &card->tx_chain;
596 enum spider_net_descr_status status;
597
598 if (atomic_inc_return(&card->tx_chain_release) != 1) {
599 atomic_dec(&card->tx_chain_release);
600 return 1;
601 }
602
603 for (;;) {
604 status = spider_net_get_descr_status(tx_chain->tail);
605 switch (status) {
606 case SPIDER_NET_DESCR_CARDOWNED:
607 if (!brutal)
608 goto out;
609 /* fallthrough, if we release the descriptors
610 * brutally (then we don't care about
611 * SPIDER_NET_DESCR_CARDOWNED) */
612 case SPIDER_NET_DESCR_RESPONSE_ERROR:
613 case SPIDER_NET_DESCR_PROTECTION_ERROR:
614 case SPIDER_NET_DESCR_FORCE_END:
615 if (netif_msg_tx_err(card))
616 pr_err("%s: forcing end of tx descriptor "
617 "with status x%02x\n",
618 card->netdev->name, status);
619 card->netdev_stats.tx_dropped++;
620 break;
621
622 case SPIDER_NET_DESCR_COMPLETE:
623 card->netdev_stats.tx_packets++;
624 card->netdev_stats.tx_bytes +=
625 tx_chain->tail->skb->len;
626 break;
627
628 default: /* any other value (== SPIDER_NET_DESCR_NOT_IN_USE) */
629 goto out;
630 }
631 spider_net_release_tx_descr(card, tx_chain->tail);
632 tx_chain->tail = tx_chain->tail->next;
633 }
634out:
635 atomic_dec(&card->tx_chain_release);
636
637 netif_wake_queue(card->netdev);
638
639 if (status == SPIDER_NET_DESCR_CARDOWNED)
640 return 1;
641 return 0;
642}
643
644/**
645 * spider_net_cleanup_tx_ring - cleans up the TX ring
646 * @card: card structure
647 *
648 * spider_net_cleanup_tx_ring is called by the tx_timer (as we don't use
649 * interrupts to cleanup our TX ring) and returns sent packets to the stack
650 * by freeing them
651 */
652static void
653spider_net_cleanup_tx_ring(struct spider_net_card *card)
654{
655 if ( (spider_net_release_tx_chain(card, 0)) &&
656 (card->netdev->flags & IFF_UP) ) {
657 mod_timer(&card->tx_timer, jiffies + SPIDER_NET_TX_TIMER);
658 }
659}
660
661/**
662 * spider_net_get_multicast_hash - generates hash for multicast filter table 530 * spider_net_get_multicast_hash - generates hash for multicast filter table
663 * @addr: multicast address 531 * @addr: multicast address
664 * 532 *
@@ -761,97 +629,6 @@ spider_net_disable_rxdmac(struct spider_net_card *card)
761} 629}
762 630
763/** 631/**
764 * spider_net_stop - called upon ifconfig down
765 * @netdev: interface device structure
766 *
767 * always returns 0
768 */
769int
770spider_net_stop(struct net_device *netdev)
771{
772 struct spider_net_card *card = netdev_priv(netdev);
773
774 tasklet_kill(&card->rxram_full_tl);
775 netif_poll_disable(netdev);
776 netif_carrier_off(netdev);
777 netif_stop_queue(netdev);
778 del_timer_sync(&card->tx_timer);
779
780 /* disable/mask all interrupts */
781 spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, 0);
782 spider_net_write_reg(card, SPIDER_NET_GHIINT1MSK, 0);
783 spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK, 0);
784
785 /* free_irq(netdev->irq, netdev);*/
786 free_irq(to_pci_dev(netdev->class_dev.dev)->irq, netdev);
787
788 spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR,
789 SPIDER_NET_DMA_TX_FEND_VALUE);
790
791 /* turn off DMA, force end */
792 spider_net_disable_rxdmac(card);
793
794 /* release chains */
795 spider_net_release_tx_chain(card, 1);
796
797 spider_net_free_chain(card, &card->tx_chain);
798 spider_net_free_chain(card, &card->rx_chain);
799
800 return 0;
801}
802
803/**
804 * spider_net_get_next_tx_descr - returns the next available tx descriptor
805 * @card: device structure to get descriptor from
806 *
807 * returns the address of the next descriptor, or NULL if not available.
808 */
809static struct spider_net_descr *
810spider_net_get_next_tx_descr(struct spider_net_card *card)
811{
812 /* check, if head points to not-in-use descr */
813 if ( spider_net_get_descr_status(card->tx_chain.head) ==
814 SPIDER_NET_DESCR_NOT_IN_USE ) {
815 return card->tx_chain.head;
816 } else {
817 return NULL;
818 }
819}
820
821/**
822 * spider_net_set_txdescr_cmdstat - sets the tx descriptor command field
823 * @descr: descriptor structure to fill out
824 * @skb: packet to consider
825 *
826 * fills out the command and status field of the descriptor structure,
827 * depending on hardware checksum settings.
828 */
829static void
830spider_net_set_txdescr_cmdstat(struct spider_net_descr *descr,
831 struct sk_buff *skb)
832{
833 /* make sure the other fields in the descriptor are written */
834 wmb();
835
836 if (skb->ip_summed != CHECKSUM_HW) {
837 descr->dmac_cmd_status = SPIDER_NET_DMAC_CMDSTAT_NOCS;
838 return;
839 }
840
841 /* is packet ip?
842 * if yes: tcp? udp? */
843 if (skb->protocol == htons(ETH_P_IP)) {
844 if (skb->nh.iph->protocol == IPPROTO_TCP)
845 descr->dmac_cmd_status = SPIDER_NET_DMAC_CMDSTAT_TCPCS;
846 else if (skb->nh.iph->protocol == IPPROTO_UDP)
847 descr->dmac_cmd_status = SPIDER_NET_DMAC_CMDSTAT_UDPCS;
848 else /* the stack should checksum non-tcp and non-udp
849 packets on his own: NETIF_F_IP_CSUM */
850 descr->dmac_cmd_status = SPIDER_NET_DMAC_CMDSTAT_NOCS;
851 }
852}
853
854/**
855 * spider_net_prepare_tx_descr - fill tx descriptor with skb data 632 * spider_net_prepare_tx_descr - fill tx descriptor with skb data
856 * @card: card structure 633 * @card: card structure
857 * @descr: descriptor structure to fill out 634 * @descr: descriptor structure to fill out
@@ -864,13 +641,12 @@ spider_net_set_txdescr_cmdstat(struct spider_net_descr *descr,
864 */ 641 */
865static int 642static int
866spider_net_prepare_tx_descr(struct spider_net_card *card, 643spider_net_prepare_tx_descr(struct spider_net_card *card,
867 struct spider_net_descr *descr,
868 struct sk_buff *skb) 644 struct sk_buff *skb)
869{ 645{
646 struct spider_net_descr *descr = card->tx_chain.head;
870 dma_addr_t buf; 647 dma_addr_t buf;
871 648
872 buf = pci_map_single(card->pdev, skb->data, 649 buf = pci_map_single(card->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
873 skb->len, PCI_DMA_BIDIRECTIONAL);
874 if (buf == DMA_ERROR_CODE) { 650 if (buf == DMA_ERROR_CODE) {
875 if (netif_msg_tx_err(card) && net_ratelimit()) 651 if (netif_msg_tx_err(card) && net_ratelimit())
876 pr_err("could not iommu-map packet (%p, %i). " 652 pr_err("could not iommu-map packet (%p, %i). "
@@ -880,10 +656,101 @@ spider_net_prepare_tx_descr(struct spider_net_card *card,
880 656
881 descr->buf_addr = buf; 657 descr->buf_addr = buf;
882 descr->buf_size = skb->len; 658 descr->buf_size = skb->len;
659 descr->next_descr_addr = 0;
883 descr->skb = skb; 660 descr->skb = skb;
884 descr->data_status = 0; 661 descr->data_status = 0;
885 662
886 spider_net_set_txdescr_cmdstat(descr,skb); 663 descr->dmac_cmd_status =
664 SPIDER_NET_DESCR_CARDOWNED | SPIDER_NET_DMAC_NOCS;
665 if (skb->protocol == htons(ETH_P_IP))
666 switch (skb->nh.iph->protocol) {
667 case IPPROTO_TCP:
668 descr->dmac_cmd_status |= SPIDER_NET_DMAC_TCP;
669 break;
670 case IPPROTO_UDP:
671 descr->dmac_cmd_status |= SPIDER_NET_DMAC_UDP;
672 break;
673 }
674
675 descr->prev->next_descr_addr = descr->bus_addr;
676
677 return 0;
678}
679
680/**
681 * spider_net_release_tx_descr - processes a used tx descriptor
682 * @card: card structure
683 * @descr: descriptor to release
684 *
685 * releases a used tx descriptor (unmapping, freeing of skb)
686 */
687static inline void
688spider_net_release_tx_descr(struct spider_net_card *card)
689{
690 struct spider_net_descr *descr = card->tx_chain.tail;
691 struct sk_buff *skb;
692
693 card->tx_chain.tail = card->tx_chain.tail->next;
694 descr->dmac_cmd_status |= SPIDER_NET_DESCR_NOT_IN_USE;
695
696 /* unmap the skb */
697 skb = descr->skb;
698 pci_unmap_single(card->pdev, descr->buf_addr, skb->len,
699 PCI_DMA_TODEVICE);
700 dev_kfree_skb_any(skb);
701}
702
703/**
704 * spider_net_release_tx_chain - processes sent tx descriptors
705 * @card: adapter structure
706 * @brutal: if set, don't care about whether descriptor seems to be in use
707 *
708 * returns 0 if the tx ring is empty, otherwise 1.
709 *
710 * spider_net_release_tx_chain releases the tx descriptors that spider has
711 * finished with (if non-brutal) or simply release tx descriptors (if brutal).
712 * If some other context is calling this function, we return 1 so that we're
713 * scheduled again (if we were scheduled) and will not loose initiative.
714 */
715static int
716spider_net_release_tx_chain(struct spider_net_card *card, int brutal)
717{
718 struct spider_net_descr_chain *chain = &card->tx_chain;
719 int status;
720
721 spider_net_read_reg(card, SPIDER_NET_GDTDMACCNTR);
722
723 while (chain->tail != chain->head) {
724 status = spider_net_get_descr_status(chain->tail);
725 switch (status) {
726 case SPIDER_NET_DESCR_COMPLETE:
727 card->netdev_stats.tx_packets++;
728 card->netdev_stats.tx_bytes += chain->tail->skb->len;
729 break;
730
731 case SPIDER_NET_DESCR_CARDOWNED:
732 if (!brutal)
733 return 1;
734 /* fallthrough, if we release the descriptors
735 * brutally (then we don't care about
736 * SPIDER_NET_DESCR_CARDOWNED) */
737
738 case SPIDER_NET_DESCR_RESPONSE_ERROR:
739 case SPIDER_NET_DESCR_PROTECTION_ERROR:
740 case SPIDER_NET_DESCR_FORCE_END:
741 if (netif_msg_tx_err(card))
742 pr_err("%s: forcing end of tx descriptor "
743 "with status x%02x\n",
744 card->netdev->name, status);
745 card->netdev_stats.tx_errors++;
746 break;
747
748 default:
749 card->netdev_stats.tx_dropped++;
750 return 1;
751 }
752 spider_net_release_tx_descr(card);
753 }
887 754
888 return 0; 755 return 0;
889} 756}
@@ -896,18 +763,32 @@ spider_net_prepare_tx_descr(struct spider_net_card *card,
896 * spider_net_kick_tx_dma writes the current tx chain head as start address 763 * spider_net_kick_tx_dma writes the current tx chain head as start address
897 * of the tx descriptor chain and enables the transmission DMA engine 764 * of the tx descriptor chain and enables the transmission DMA engine
898 */ 765 */
899static void 766static inline void
900spider_net_kick_tx_dma(struct spider_net_card *card, 767spider_net_kick_tx_dma(struct spider_net_card *card)
901 struct spider_net_descr *descr)
902{ 768{
903 /* this is the only descriptor in the output chain. 769 struct spider_net_descr *descr;
904 * Enable TX DMA */
905 770
906 spider_net_write_reg(card, SPIDER_NET_GDTDCHA, 771 if (spider_net_read_reg(card, SPIDER_NET_GDTDMACCNTR) &
907 descr->bus_addr); 772 SPIDER_NET_TX_DMA_EN)
773 goto out;
908 774
909 spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR, 775 descr = card->tx_chain.tail;
910 SPIDER_NET_DMA_TX_VALUE); 776 for (;;) {
777 if (spider_net_get_descr_status(descr) ==
778 SPIDER_NET_DESCR_CARDOWNED) {
779 spider_net_write_reg(card, SPIDER_NET_GDTDCHA,
780 descr->bus_addr);
781 spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR,
782 SPIDER_NET_DMA_TX_VALUE);
783 break;
784 }
785 if (descr == card->tx_chain.head)
786 break;
787 descr = descr->next;
788 }
789
790out:
791 mod_timer(&card->tx_timer, jiffies + SPIDER_NET_TX_TIMER);
911} 792}
912 793
913/** 794/**
@@ -915,47 +796,69 @@ spider_net_kick_tx_dma(struct spider_net_card *card,
915 * @skb: packet to send out 796 * @skb: packet to send out
916 * @netdev: interface device structure 797 * @netdev: interface device structure
917 * 798 *
918 * returns 0 on success, <0 on failure 799 * returns 0 on success, !0 on failure
919 */ 800 */
920static int 801static int
921spider_net_xmit(struct sk_buff *skb, struct net_device *netdev) 802spider_net_xmit(struct sk_buff *skb, struct net_device *netdev)
922{ 803{
923 struct spider_net_card *card = netdev_priv(netdev); 804 struct spider_net_card *card = netdev_priv(netdev);
924 struct spider_net_descr *descr; 805 struct spider_net_descr_chain *chain = &card->tx_chain;
806 struct spider_net_descr *descr = chain->head;
807 unsigned long flags;
925 int result; 808 int result;
926 809
810 spin_lock_irqsave(&chain->lock, flags);
811
927 spider_net_release_tx_chain(card, 0); 812 spider_net_release_tx_chain(card, 0);
928 813
929 descr = spider_net_get_next_tx_descr(card); 814 if (chain->head->next == chain->tail->prev) {
815 card->netdev_stats.tx_dropped++;
816 result = NETDEV_TX_LOCKED;
817 goto out;
818 }
930 819
931 if (!descr) 820 if (spider_net_get_descr_status(descr) != SPIDER_NET_DESCR_NOT_IN_USE) {
932 goto error; 821 result = NETDEV_TX_LOCKED;
822 goto out;
823 }
933 824
934 result = spider_net_prepare_tx_descr(card, descr, skb); 825 if (spider_net_prepare_tx_descr(card, skb) != 0) {
935 if (result) 826 card->netdev_stats.tx_dropped++;
936 goto error; 827 result = NETDEV_TX_BUSY;
828 goto out;
829 }
937 830
831 result = NETDEV_TX_OK;
832
833 spider_net_kick_tx_dma(card);
938 card->tx_chain.head = card->tx_chain.head->next; 834 card->tx_chain.head = card->tx_chain.head->next;
939 835
940 if (spider_net_get_descr_status(descr->prev) != 836out:
941 SPIDER_NET_DESCR_CARDOWNED) { 837 spin_unlock_irqrestore(&chain->lock, flags);
942 /* make sure the current descriptor is in memory. Then 838 netif_wake_queue(netdev);
943 * kicking it on again makes sense, if the previous is not 839 return result;
944 * card-owned anymore. Check the previous descriptor twice 840}
945 * to omit an mb() in heavy traffic cases */
946 mb();
947 if (spider_net_get_descr_status(descr->prev) !=
948 SPIDER_NET_DESCR_CARDOWNED)
949 spider_net_kick_tx_dma(card, descr);
950 }
951 841
952 mod_timer(&card->tx_timer, jiffies + SPIDER_NET_TX_TIMER); 842/**
843 * spider_net_cleanup_tx_ring - cleans up the TX ring
844 * @card: card structure
845 *
846 * spider_net_cleanup_tx_ring is called by the tx_timer (as we don't use
847 * interrupts to cleanup our TX ring) and returns sent packets to the stack
848 * by freeing them
849 */
850static void
851spider_net_cleanup_tx_ring(struct spider_net_card *card)
852{
853 unsigned long flags;
953 854
954 return NETDEV_TX_OK; 855 spin_lock_irqsave(&card->tx_chain.lock, flags);
955 856
956error: 857 if ((spider_net_release_tx_chain(card, 0) != 0) &&
957 card->netdev_stats.tx_dropped++; 858 (card->netdev->flags & IFF_UP))
958 return NETDEV_TX_BUSY; 859 spider_net_kick_tx_dma(card);
860
861 spin_unlock_irqrestore(&card->tx_chain.lock, flags);
959} 862}
960 863
961/** 864/**
@@ -1002,7 +905,7 @@ spider_net_pass_skb_up(struct spider_net_descr *descr,
1002 905
1003 /* unmap descriptor */ 906 /* unmap descriptor */
1004 pci_unmap_single(card->pdev, descr->buf_addr, SPIDER_NET_MAX_FRAME, 907 pci_unmap_single(card->pdev, descr->buf_addr, SPIDER_NET_MAX_FRAME,
1005 PCI_DMA_BIDIRECTIONAL); 908 PCI_DMA_FROMDEVICE);
1006 909
1007 /* the cases we'll throw away the packet immediately */ 910 /* the cases we'll throw away the packet immediately */
1008 if (data_error & SPIDER_NET_DESTROY_RX_FLAGS) { 911 if (data_error & SPIDER_NET_DESTROY_RX_FLAGS) {
@@ -1067,14 +970,11 @@ spider_net_pass_skb_up(struct spider_net_descr *descr,
1067static int 970static int
1068spider_net_decode_one_descr(struct spider_net_card *card, int napi) 971spider_net_decode_one_descr(struct spider_net_card *card, int napi)
1069{ 972{
1070 enum spider_net_descr_status status; 973 struct spider_net_descr_chain *chain = &card->rx_chain;
1071 struct spider_net_descr *descr; 974 struct spider_net_descr *descr = chain->tail;
1072 struct spider_net_descr_chain *chain; 975 int status;
1073 int result; 976 int result;
1074 977
1075 chain = &card->rx_chain;
1076 descr = chain->tail;
1077
1078 status = spider_net_get_descr_status(descr); 978 status = spider_net_get_descr_status(descr);
1079 979
1080 if (status == SPIDER_NET_DESCR_CARDOWNED) { 980 if (status == SPIDER_NET_DESCR_CARDOWNED) {
@@ -1103,7 +1003,7 @@ spider_net_decode_one_descr(struct spider_net_card *card, int napi)
1103 card->netdev->name, status); 1003 card->netdev->name, status);
1104 card->netdev_stats.rx_dropped++; 1004 card->netdev_stats.rx_dropped++;
1105 pci_unmap_single(card->pdev, descr->buf_addr, 1005 pci_unmap_single(card->pdev, descr->buf_addr,
1106 SPIDER_NET_MAX_FRAME, PCI_DMA_BIDIRECTIONAL); 1006 SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
1107 dev_kfree_skb_irq(descr->skb); 1007 dev_kfree_skb_irq(descr->skb);
1108 goto refill; 1008 goto refill;
1109 } 1009 }
@@ -1119,7 +1019,7 @@ spider_net_decode_one_descr(struct spider_net_card *card, int napi)
1119 /* ok, we've got a packet in descr */ 1019 /* ok, we've got a packet in descr */
1120 result = spider_net_pass_skb_up(descr, card, napi); 1020 result = spider_net_pass_skb_up(descr, card, napi);
1121refill: 1021refill:
1122 spider_net_set_descr_status(descr, SPIDER_NET_DESCR_NOT_IN_USE); 1022 descr->dmac_cmd_status = SPIDER_NET_DESCR_NOT_IN_USE;
1123 /* change the descriptor state: */ 1023 /* change the descriptor state: */
1124 if (!napi) 1024 if (!napi)
1125 spider_net_refill_rx_chain(card); 1025 spider_net_refill_rx_chain(card);
@@ -1291,21 +1191,6 @@ spider_net_set_mac(struct net_device *netdev, void *p)
1291} 1191}
1292 1192
1293/** 1193/**
1294 * spider_net_enable_txdmac - enables a TX DMA controller
1295 * @card: card structure
1296 *
1297 * spider_net_enable_txdmac enables the TX DMA controller by setting the
1298 * descriptor chain tail address
1299 */
1300static void
1301spider_net_enable_txdmac(struct spider_net_card *card)
1302{
1303 /* assume chain is aligned correctly */
1304 spider_net_write_reg(card, SPIDER_NET_GDTDCHA,
1305 card->tx_chain.tail->bus_addr);
1306}
1307
1308/**
1309 * spider_net_handle_rxram_full - cleans up RX ring upon RX RAM full interrupt 1194 * spider_net_handle_rxram_full - cleans up RX ring upon RX RAM full interrupt
1310 * @card: card structure 1195 * @card: card structure
1311 * 1196 *
@@ -1653,7 +1538,6 @@ spider_net_enable_card(struct spider_net_card *card)
1653 { SPIDER_NET_GMRWOLCTRL, 0 }, 1538 { SPIDER_NET_GMRWOLCTRL, 0 },
1654 { SPIDER_NET_GTESTMD, 0x10000000 }, 1539 { SPIDER_NET_GTESTMD, 0x10000000 },
1655 { SPIDER_NET_GTTQMSK, 0x00400040 }, 1540 { SPIDER_NET_GTTQMSK, 0x00400040 },
1656 { SPIDER_NET_GTESTMD, 0 },
1657 1541
1658 { SPIDER_NET_GMACINTEN, 0 }, 1542 { SPIDER_NET_GMACINTEN, 0 },
1659 1543
@@ -1692,9 +1576,6 @@ spider_net_enable_card(struct spider_net_card *card)
1692 1576
1693 spider_net_write_reg(card, SPIDER_NET_GRXDMAEN, SPIDER_NET_WOL_VALUE); 1577 spider_net_write_reg(card, SPIDER_NET_GRXDMAEN, SPIDER_NET_WOL_VALUE);
1694 1578
1695 /* set chain tail adress for TX chain */
1696 spider_net_enable_txdmac(card);
1697
1698 spider_net_write_reg(card, SPIDER_NET_GMACLENLMT, 1579 spider_net_write_reg(card, SPIDER_NET_GMACLENLMT,
1699 SPIDER_NET_LENLMT_VALUE); 1580 SPIDER_NET_LENLMT_VALUE);
1700 spider_net_write_reg(card, SPIDER_NET_GMACMODE, 1581 spider_net_write_reg(card, SPIDER_NET_GMACMODE,
@@ -1709,6 +1590,9 @@ spider_net_enable_card(struct spider_net_card *card)
1709 SPIDER_NET_INT1_MASK_VALUE); 1590 SPIDER_NET_INT1_MASK_VALUE);
1710 spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK, 1591 spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK,
1711 SPIDER_NET_INT2_MASK_VALUE); 1592 SPIDER_NET_INT2_MASK_VALUE);
1593
1594 spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR,
1595 SPIDER_NET_GDTDCEIDIS);
1712} 1596}
1713 1597
1714/** 1598/**
@@ -1727,11 +1611,12 @@ spider_net_open(struct net_device *netdev)
1727 int result; 1611 int result;
1728 1612
1729 result = -ENOMEM; 1613 result = -ENOMEM;
1730 if (spider_net_init_chain(card, &card->tx_chain, 1614 if (spider_net_init_chain(card, &card->tx_chain, card->descr,
1731 card->descr, tx_descriptors)) 1615 PCI_DMA_TODEVICE, card->tx_desc))
1732 goto alloc_tx_failed; 1616 goto alloc_tx_failed;
1733 if (spider_net_init_chain(card, &card->rx_chain, 1617 if (spider_net_init_chain(card, &card->rx_chain,
1734 card->descr + tx_descriptors, rx_descriptors)) 1618 card->descr + card->rx_desc,
1619 PCI_DMA_FROMDEVICE, card->rx_desc))
1735 goto alloc_rx_failed; 1620 goto alloc_rx_failed;
1736 1621
1737 /* allocate rx skbs */ 1622 /* allocate rx skbs */
@@ -1938,7 +1823,7 @@ spider_net_workaround_rxramfull(struct spider_net_card *card)
1938 /* empty sequencer data */ 1823 /* empty sequencer data */
1939 for (sequencer = 0; sequencer < SPIDER_NET_FIRMWARE_SEQS; 1824 for (sequencer = 0; sequencer < SPIDER_NET_FIRMWARE_SEQS;
1940 sequencer++) { 1825 sequencer++) {
1941 spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT + 1826 spider_net_write_reg(card, SPIDER_NET_GSnPRGADR +
1942 sequencer * 8, 0x0); 1827 sequencer * 8, 0x0);
1943 for (i = 0; i < SPIDER_NET_FIRMWARE_SEQWORDS; i++) { 1828 for (i = 0; i < SPIDER_NET_FIRMWARE_SEQWORDS; i++) {
1944 spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT + 1829 spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT +
@@ -1955,6 +1840,49 @@ spider_net_workaround_rxramfull(struct spider_net_card *card)
1955} 1840}
1956 1841
1957/** 1842/**
1843 * spider_net_stop - called upon ifconfig down
1844 * @netdev: interface device structure
1845 *
1846 * always returns 0
1847 */
1848int
1849spider_net_stop(struct net_device *netdev)
1850{
1851 struct spider_net_card *card = netdev_priv(netdev);
1852
1853 tasklet_kill(&card->rxram_full_tl);
1854 netif_poll_disable(netdev);
1855 netif_carrier_off(netdev);
1856 netif_stop_queue(netdev);
1857 del_timer_sync(&card->tx_timer);
1858
1859 /* disable/mask all interrupts */
1860 spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, 0);
1861 spider_net_write_reg(card, SPIDER_NET_GHIINT1MSK, 0);
1862 spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK, 0);
1863
1864 /* free_irq(netdev->irq, netdev);*/
1865 free_irq(to_pci_dev(netdev->class_dev.dev)->irq, netdev);
1866
1867 spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR,
1868 SPIDER_NET_DMA_TX_FEND_VALUE);
1869
1870 /* turn off DMA, force end */
1871 spider_net_disable_rxdmac(card);
1872
1873 /* release chains */
1874 if (spin_trylock(&card->tx_chain.lock)) {
1875 spider_net_release_tx_chain(card, 1);
1876 spin_unlock(&card->tx_chain.lock);
1877 }
1878
1879 spider_net_free_chain(card, &card->tx_chain);
1880 spider_net_free_chain(card, &card->rx_chain);
1881
1882 return 0;
1883}
1884
1885/**
1958 * spider_net_tx_timeout_task - task scheduled by the watchdog timeout 1886 * spider_net_tx_timeout_task - task scheduled by the watchdog timeout
1959 * function (to be called not under interrupt status) 1887 * function (to be called not under interrupt status)
1960 * @data: data, is interface device structure 1888 * @data: data, is interface device structure
@@ -1982,7 +1910,7 @@ spider_net_tx_timeout_task(void *data)
1982 goto out; 1910 goto out;
1983 1911
1984 spider_net_open(netdev); 1912 spider_net_open(netdev);
1985 spider_net_kick_tx_dma(card, card->tx_chain.head); 1913 spider_net_kick_tx_dma(card);
1986 netif_device_attach(netdev); 1914 netif_device_attach(netdev);
1987 1915
1988out: 1916out:
@@ -2065,7 +1993,6 @@ spider_net_setup_netdev(struct spider_net_card *card)
2065 1993
2066 pci_set_drvdata(card->pdev, netdev); 1994 pci_set_drvdata(card->pdev, netdev);
2067 1995
2068 atomic_set(&card->tx_chain_release,0);
2069 card->rxram_full_tl.data = (unsigned long) card; 1996 card->rxram_full_tl.data = (unsigned long) card;
2070 card->rxram_full_tl.func = 1997 card->rxram_full_tl.func =
2071 (void (*)(unsigned long)) spider_net_handle_rxram_full; 1998 (void (*)(unsigned long)) spider_net_handle_rxram_full;
@@ -2077,9 +2004,12 @@ spider_net_setup_netdev(struct spider_net_card *card)
2077 2004
2078 card->options.rx_csum = SPIDER_NET_RX_CSUM_DEFAULT; 2005 card->options.rx_csum = SPIDER_NET_RX_CSUM_DEFAULT;
2079 2006
2007 card->tx_desc = tx_descriptors;
2008 card->rx_desc = rx_descriptors;
2009
2080 spider_net_setup_netdev_ops(netdev); 2010 spider_net_setup_netdev_ops(netdev);
2081 2011
2082 netdev->features = NETIF_F_HW_CSUM; 2012 netdev->features = NETIF_F_HW_CSUM | NETIF_F_LLTX;
2083 /* some time: NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX | 2013 /* some time: NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
2084 * NETIF_F_HW_VLAN_FILTER */ 2014 * NETIF_F_HW_VLAN_FILTER */
2085 2015
diff --git a/drivers/net/spider_net.h b/drivers/net/spider_net.h
index 3b8d951cf73c..30407cdf0892 100644
--- a/drivers/net/spider_net.h
+++ b/drivers/net/spider_net.h
@@ -208,7 +208,10 @@ extern char spider_net_driver_name[];
208#define SPIDER_NET_DMA_RX_VALUE 0x80000000 208#define SPIDER_NET_DMA_RX_VALUE 0x80000000
209#define SPIDER_NET_DMA_RX_FEND_VALUE 0x00030003 209#define SPIDER_NET_DMA_RX_FEND_VALUE 0x00030003
210/* to set TX_DMA_EN */ 210/* to set TX_DMA_EN */
211#define SPIDER_NET_DMA_TX_VALUE 0x80000000 211#define SPIDER_NET_TX_DMA_EN 0x80000000
212#define SPIDER_NET_GDTDCEIDIS 0x00000002
213#define SPIDER_NET_DMA_TX_VALUE SPIDER_NET_TX_DMA_EN | \
214 SPIDER_NET_GDTDCEIDIS
212#define SPIDER_NET_DMA_TX_FEND_VALUE 0x00030003 215#define SPIDER_NET_DMA_TX_FEND_VALUE 0x00030003
213 216
214/* SPIDER_NET_UA_DESCR_VALUE is OR'ed with the unicast address */ 217/* SPIDER_NET_UA_DESCR_VALUE is OR'ed with the unicast address */
@@ -329,55 +332,23 @@ enum spider_net_int2_status {
329 (~SPIDER_NET_TXINT) & \ 332 (~SPIDER_NET_TXINT) & \
330 (~SPIDER_NET_RXINT) ) 333 (~SPIDER_NET_RXINT) )
331 334
332#define SPIDER_NET_GPREXEC 0x80000000 335#define SPIDER_NET_GPREXEC 0x80000000
333#define SPIDER_NET_GPRDAT_MASK 0x0000ffff 336#define SPIDER_NET_GPRDAT_MASK 0x0000ffff
334 337
335/* descriptor bits 338#define SPIDER_NET_DMAC_NOINTR_COMPLETE 0x00800000
336 * 339#define SPIDER_NET_DMAC_NOCS 0x00040000
337 * 1010 descriptor ready 340#define SPIDER_NET_DMAC_TCP 0x00020000
338 * 0 descr in middle of chain 341#define SPIDER_NET_DMAC_UDP 0x00030000
339 * 000 fixed to 0 342#define SPIDER_NET_TXDCEST 0x08000000
340 * 343
341 * 0 no interrupt on completion 344#define SPIDER_NET_DESCR_IND_PROC_MASK 0xF0000000
342 * 000 fixed to 0 345#define SPIDER_NET_DESCR_COMPLETE 0x00000000 /* used in rx and tx */
343 * 1 no ipsec processing 346#define SPIDER_NET_DESCR_RESPONSE_ERROR 0x10000000 /* used in rx and tx */
344 * 1 last descriptor for this frame 347#define SPIDER_NET_DESCR_PROTECTION_ERROR 0x20000000 /* used in rx and tx */
345 * 00 no checksum 348#define SPIDER_NET_DESCR_FRAME_END 0x40000000 /* used in rx */
346 * 10 tcp checksum 349#define SPIDER_NET_DESCR_FORCE_END 0x50000000 /* used in rx and tx */
347 * 11 udp checksum 350#define SPIDER_NET_DESCR_CARDOWNED 0xA0000000 /* used in rx and tx */
348 * 351#define SPIDER_NET_DESCR_NOT_IN_USE 0xF0000000
349 * 00 fixed to 0
350 * 0 fixed to 0
351 * 0 no interrupt on response errors
352 * 0 no interrupt on invalid descr
353 * 0 no interrupt on dma process termination
354 * 0 no interrupt on descr chain end
355 * 0 no interrupt on descr complete
356 *
357 * 000 fixed to 0
358 * 0 response error interrupt status
359 * 0 invalid descr status
360 * 0 dma termination status
361 * 0 descr chain end status
362 * 0 descr complete status */
363#define SPIDER_NET_DMAC_CMDSTAT_NOCS 0xa00c0000
364#define SPIDER_NET_DMAC_CMDSTAT_TCPCS 0xa00e0000
365#define SPIDER_NET_DMAC_CMDSTAT_UDPCS 0xa00f0000
366#define SPIDER_NET_DESCR_IND_PROC_SHIFT 28
367#define SPIDER_NET_DESCR_IND_PROC_MASKO 0x0fffffff
368
369/* descr ready, descr is in middle of chain, get interrupt on completion */
370#define SPIDER_NET_DMAC_RX_CARDOWNED 0xa0800000
371
372enum spider_net_descr_status {
373 SPIDER_NET_DESCR_COMPLETE = 0x00, /* used in rx and tx */
374 SPIDER_NET_DESCR_RESPONSE_ERROR = 0x01, /* used in rx and tx */
375 SPIDER_NET_DESCR_PROTECTION_ERROR = 0x02, /* used in rx and tx */
376 SPIDER_NET_DESCR_FRAME_END = 0x04, /* used in rx */
377 SPIDER_NET_DESCR_FORCE_END = 0x05, /* used in rx and tx */
378 SPIDER_NET_DESCR_CARDOWNED = 0x0a, /* used in rx and tx */
379 SPIDER_NET_DESCR_NOT_IN_USE /* any other value */
380};
381 352
382struct spider_net_descr { 353struct spider_net_descr {
383 /* as defined by the hardware */ 354 /* as defined by the hardware */
@@ -398,7 +369,7 @@ struct spider_net_descr {
398} __attribute__((aligned(32))); 369} __attribute__((aligned(32)));
399 370
400struct spider_net_descr_chain { 371struct spider_net_descr_chain {
401 /* we walk from tail to head */ 372 spinlock_t lock;
402 struct spider_net_descr *head; 373 struct spider_net_descr *head;
403 struct spider_net_descr *tail; 374 struct spider_net_descr *tail;
404}; 375};
@@ -453,8 +424,6 @@ struct spider_net_card {
453 424
454 struct spider_net_descr_chain tx_chain; 425 struct spider_net_descr_chain tx_chain;
455 struct spider_net_descr_chain rx_chain; 426 struct spider_net_descr_chain rx_chain;
456 atomic_t rx_chain_refill;
457 atomic_t tx_chain_release;
458 427
459 struct net_device_stats netdev_stats; 428 struct net_device_stats netdev_stats;
460 429
@@ -471,6 +440,9 @@ struct spider_net_card {
471 /* for ethtool */ 440 /* for ethtool */
472 int msg_enable; 441 int msg_enable;
473 442
443 int rx_desc;
444 int tx_desc;
445
474 struct spider_net_descr descr[0]; 446 struct spider_net_descr descr[0];
475}; 447};
476 448
diff --git a/drivers/net/spider_net_ethtool.c b/drivers/net/spider_net_ethtool.c
index a5bb0b7633af..02209222b8c9 100644
--- a/drivers/net/spider_net_ethtool.c
+++ b/drivers/net/spider_net_ethtool.c
@@ -130,6 +130,18 @@ spider_net_ethtool_set_tx_csum(struct net_device *netdev, uint32_t data)
130 return 0; 130 return 0;
131} 131}
132 132
133static void
134spider_net_ethtool_get_ringparam(struct net_device *netdev,
135 struct ethtool_ringparam *ering)
136{
137 struct spider_net_card *card = netdev->priv;
138
139 ering->tx_max_pending = SPIDER_NET_TX_DESCRIPTORS_MAX;
140 ering->tx_pending = card->tx_desc;
141 ering->rx_max_pending = SPIDER_NET_RX_DESCRIPTORS_MAX;
142 ering->rx_pending = card->rx_desc;
143}
144
133struct ethtool_ops spider_net_ethtool_ops = { 145struct ethtool_ops spider_net_ethtool_ops = {
134 .get_settings = spider_net_ethtool_get_settings, 146 .get_settings = spider_net_ethtool_get_settings,
135 .get_drvinfo = spider_net_ethtool_get_drvinfo, 147 .get_drvinfo = spider_net_ethtool_get_drvinfo,
@@ -141,5 +153,6 @@ struct ethtool_ops spider_net_ethtool_ops = {
141 .set_rx_csum = spider_net_ethtool_set_rx_csum, 153 .set_rx_csum = spider_net_ethtool_set_rx_csum,
142 .get_tx_csum = spider_net_ethtool_get_tx_csum, 154 .get_tx_csum = spider_net_ethtool_get_tx_csum,
143 .set_tx_csum = spider_net_ethtool_set_tx_csum, 155 .set_tx_csum = spider_net_ethtool_set_tx_csum,
156 .get_ringparam = spider_net_ethtool_get_ringparam,
144}; 157};
145 158
diff --git a/drivers/net/starfire.c b/drivers/net/starfire.c
index ed1f59901ff4..c0a62b00ffc8 100644
--- a/drivers/net/starfire.c
+++ b/drivers/net/starfire.c
@@ -22,129 +22,13 @@
22 22
23 Support and updates available at 23 Support and updates available at
24 http://www.scyld.com/network/starfire.html 24 http://www.scyld.com/network/starfire.html
25 [link no longer provides useful info -jgarzik]
25 26
26 -----------------------------------------------------------
27
28 Linux kernel-specific changes:
29
30 LK1.1.1 (jgarzik):
31 - Use PCI driver interface
32 - Fix MOD_xxx races
33 - softnet fixups
34
35 LK1.1.2 (jgarzik):
36 - Merge Becker version 0.15
37
38 LK1.1.3 (Andrew Morton)
39 - Timer cleanups
40
41 LK1.1.4 (jgarzik):
42 - Merge Becker version 1.03
43
44 LK1.2.1 (Ion Badulescu <ionut@cs.columbia.edu>)
45 - Support hardware Rx/Tx checksumming
46 - Use the GFP firmware taken from Adaptec's Netware driver
47
48 LK1.2.2 (Ion Badulescu)
49 - Backported to 2.2.x
50
51 LK1.2.3 (Ion Badulescu)
52 - Fix the flaky mdio interface
53 - More compat clean-ups
54
55 LK1.2.4 (Ion Badulescu)
56 - More 2.2.x initialization fixes
57
58 LK1.2.5 (Ion Badulescu)
59 - Several fixes from Manfred Spraul
60
61 LK1.2.6 (Ion Badulescu)
62 - Fixed ifup/ifdown/ifup problem in 2.4.x
63
64 LK1.2.7 (Ion Badulescu)
65 - Removed unused code
66 - Made more functions static and __init
67
68 LK1.2.8 (Ion Badulescu)
69 - Quell bogus error messages, inform about the Tx threshold
70 - Removed #ifdef CONFIG_PCI, this driver is PCI only
71
72 LK1.2.9 (Ion Badulescu)
73 - Merged Jeff Garzik's changes from 2.4.4-pre5
74 - Added 2.2.x compatibility stuff required by the above changes
75
76 LK1.2.9a (Ion Badulescu)
77 - More updates from Jeff Garzik
78
79 LK1.3.0 (Ion Badulescu)
80 - Merged zerocopy support
81
82 LK1.3.1 (Ion Badulescu)
83 - Added ethtool support
84 - Added GPIO (media change) interrupt support
85
86 LK1.3.2 (Ion Badulescu)
87 - Fixed 2.2.x compatibility issues introduced in 1.3.1
88 - Fixed ethtool ioctl returning uninitialized memory
89
90 LK1.3.3 (Ion Badulescu)
91 - Initialize the TxMode register properly
92 - Don't dereference dev->priv after freeing it
93
94 LK1.3.4 (Ion Badulescu)
95 - Fixed initialization timing problems
96 - Fixed interrupt mask definitions
97
98 LK1.3.5 (jgarzik)
99 - ethtool NWAY_RST, GLINK, [GS]MSGLVL support
100
101 LK1.3.6:
102 - Sparc64 support and fixes (Ion Badulescu)
103 - Better stats and error handling (Ion Badulescu)
104 - Use new pci_set_mwi() PCI API function (jgarzik)
105
106 LK1.3.7 (Ion Badulescu)
107 - minimal implementation of tx_timeout()
108 - correctly shutdown the Rx/Tx engines in netdev_close()
109 - added calls to netif_carrier_on/off
110 (patch from Stefan Rompf <srompf@isg.de>)
111 - VLAN support
112
113 LK1.3.8 (Ion Badulescu)
114 - adjust DMA burst size on sparc64
115 - 64-bit support
116 - reworked zerocopy support for 64-bit buffers
117 - working and usable interrupt mitigation/latency
118 - reduced Tx interrupt frequency for lower interrupt overhead
119
120 LK1.3.9 (Ion Badulescu)
121 - bugfix for mcast filter
122 - enable the right kind of Tx interrupts (TxDMADone, not TxDone)
123
124 LK1.4.0 (Ion Badulescu)
125 - NAPI support
126
127 LK1.4.1 (Ion Badulescu)
128 - flush PCI posting buffers after disabling Rx interrupts
129 - put the chip to a D3 slumber on driver unload
130 - added config option to enable/disable NAPI
131
132 LK1.4.2 (Ion Badulescu)
133 - finally added firmware (GPL'ed by Adaptec)
134 - removed compatibility code for 2.2.x
135
136 LK1.4.2.1 (Ion Badulescu)
137 - fixed 32/64 bit issues on i386 + CONFIG_HIGHMEM
138 - added 32-bit padding to outgoing skb's, removed previous workaround
139
140TODO: - fix forced speed/duplexing code (broken a long time ago, when
141 somebody converted the driver to use the generic MII code)
142 - fix VLAN support
143*/ 27*/
144 28
145#define DRV_NAME "starfire" 29#define DRV_NAME "starfire"
146#define DRV_VERSION "1.03+LK1.4.2.1" 30#define DRV_VERSION "2.0"
147#define DRV_RELDATE "October 3, 2005" 31#define DRV_RELDATE "June 27, 2006"
148 32
149#include <linux/module.h> 33#include <linux/module.h>
150#include <linux/kernel.h> 34#include <linux/kernel.h>
@@ -846,7 +730,6 @@ static int __devinit starfire_init_one(struct pci_dev *pdev,
846 goto err_out_free_netdev; 730 goto err_out_free_netdev;
847 } 731 }
848 732
849 /* ioremap is borken in Linux-2.2.x/sparc64 */
850 base = ioremap(ioaddr, io_size); 733 base = ioremap(ioaddr, io_size);
851 if (!base) { 734 if (!base) {
852 printk(KERN_ERR DRV_NAME " %d: cannot remap %#x @ %#lx, aborting\n", 735 printk(KERN_ERR DRV_NAME " %d: cannot remap %#x @ %#lx, aborting\n",
diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
index 643fceae3db5..698568e751da 100644
--- a/drivers/net/sundance.c
+++ b/drivers/net/sundance.c
@@ -16,91 +16,13 @@
16 16
17 Support and updates available at 17 Support and updates available at
18 http://www.scyld.com/network/sundance.html 18 http://www.scyld.com/network/sundance.html
19 [link no longer provides useful info -jgarzik]
19 20
20
21 Version LK1.01a (jgarzik):
22 - Replace some MII-related magic numbers with constants
23
24 Version LK1.02 (D-Link):
25 - Add new board to PCI ID list
26 - Fix multicast bug
27
28 Version LK1.03 (D-Link):
29 - New Rx scheme, reduce Rx congestion
30 - Option to disable flow control
31
32 Version LK1.04 (D-Link):
33 - Tx timeout recovery
34 - More support for ethtool.
35
36 Version LK1.04a:
37 - Remove unused/constant members from struct pci_id_info
38 (which then allows removal of 'drv_flags' from private struct)
39 (jgarzik)
40 - If no phy is found, fail to load that board (jgarzik)
41 - Always start phy id scan at id 1 to avoid problems (Donald Becker)
42 - Autodetect where mii_preable_required is needed,
43 default to not needed. (Donald Becker)
44
45 Version LK1.04b:
46 - Remove mii_preamble_required module parameter (Donald Becker)
47 - Add per-interface mii_preamble_required (setting is autodetected)
48 (Donald Becker)
49 - Remove unnecessary cast from void pointer (jgarzik)
50 - Re-align comments in private struct (jgarzik)
51
52 Version LK1.04c (jgarzik):
53 - Support bitmapped message levels (NETIF_MSG_xxx), and the
54 two ethtool ioctls that get/set them
55 - Don't hand-code MII ethtool support, use standard API/lib
56
57 Version LK1.04d:
58 - Merge from Donald Becker's sundance.c: (Jason Lunz)
59 * proper support for variably-sized MTUs
60 * default to PIO, to fix chip bugs
61 - Add missing unregister_netdev (Jason Lunz)
62 - Add CONFIG_SUNDANCE_MMIO config option (jgarzik)
63 - Better rx buf size calculation (Donald Becker)
64
65 Version LK1.05 (D-Link):
66 - Fix DFE-580TX packet drop issue (for DL10050C)
67 - Fix reset_tx logic
68
69 Version LK1.06 (D-Link):
70 - Fix crash while unloading driver
71
72 Versin LK1.06b (D-Link):
73 - New tx scheme, adaptive tx_coalesce
74
75 Version LK1.07 (D-Link):
76 - Fix tx bugs in big-endian machines
77 - Remove unused max_interrupt_work module parameter, the new
78 NAPI-like rx scheme doesn't need it.
79 - Remove redundancy get_stats() in intr_handler(), those
80 I/O access could affect performance in ARM-based system
81 - Add Linux software VLAN support
82
83 Version LK1.08 (Philippe De Muyter phdm@macqel.be):
84 - Fix bug of custom mac address
85 (StationAddr register only accept word write)
86
87 Version LK1.09 (D-Link):
88 - Fix the flowctrl bug.
89 - Set Pause bit in MII ANAR if flow control enabled.
90
91 Version LK1.09a (ICPlus):
92 - Add the delay time in reading the contents of EEPROM
93
94 Version LK1.10 (Philippe De Muyter phdm@macqel.be):
95 - Make 'unblock interface after Tx underrun' work
96
97 Version LK1.11 (Pedro Alejandro Lopez-Valencia palopezv at gmail.com):
98 - Add support for IC Plus Corporation IP100A chipset
99*/ 21*/
100 22
101#define DRV_NAME "sundance" 23#define DRV_NAME "sundance"
102#define DRV_VERSION "1.01+LK1.11" 24#define DRV_VERSION "1.1"
103#define DRV_RELDATE "14-Jun-2006" 25#define DRV_RELDATE "27-Jun-2006"
104 26
105 27
106/* The user-configurable values. 28/* The user-configurable values.
@@ -185,7 +107,7 @@ static char *media[MAX_UNITS];
185#endif 107#endif
186 108
187/* These identify the driver base version and may not be removed. */ 109/* These identify the driver base version and may not be removed. */
188static char version[] __devinitdata = 110static char version[] =
189KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " Written by Donald Becker\n" 111KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " Written by Donald Becker\n"
190KERN_INFO " http://www.scyld.com/network/sundance.html\n"; 112KERN_INFO " http://www.scyld.com/network/sundance.html\n";
191 113
@@ -282,15 +204,15 @@ IVc. Errata
282#define USE_IO_OPS 1 204#define USE_IO_OPS 1
283#endif 205#endif
284 206
285static struct pci_device_id sundance_pci_tbl[] = { 207static const struct pci_device_id sundance_pci_tbl[] = {
286 {0x1186, 0x1002, 0x1186, 0x1002, 0, 0, 0}, 208 { 0x1186, 0x1002, 0x1186, 0x1002, 0, 0, 0 },
287 {0x1186, 0x1002, 0x1186, 0x1003, 0, 0, 1}, 209 { 0x1186, 0x1002, 0x1186, 0x1003, 0, 0, 1 },
288 {0x1186, 0x1002, 0x1186, 0x1012, 0, 0, 2}, 210 { 0x1186, 0x1002, 0x1186, 0x1012, 0, 0, 2 },
289 {0x1186, 0x1002, 0x1186, 0x1040, 0, 0, 3}, 211 { 0x1186, 0x1002, 0x1186, 0x1040, 0, 0, 3 },
290 {0x1186, 0x1002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4}, 212 { 0x1186, 0x1002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
291 {0x13F0, 0x0201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5}, 213 { 0x13F0, 0x0201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
292 {0x13F0, 0x0200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6}, 214 { 0x13F0, 0x0200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
293 {0,} 215 { }
294}; 216};
295MODULE_DEVICE_TABLE(pci, sundance_pci_tbl); 217MODULE_DEVICE_TABLE(pci, sundance_pci_tbl);
296 218
@@ -301,7 +223,7 @@ enum {
301struct pci_id_info { 223struct pci_id_info {
302 const char *name; 224 const char *name;
303}; 225};
304static const struct pci_id_info pci_id_tbl[] = { 226static const struct pci_id_info pci_id_tbl[] __devinitdata = {
305 {"D-Link DFE-550TX FAST Ethernet Adapter"}, 227 {"D-Link DFE-550TX FAST Ethernet Adapter"},
306 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"}, 228 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
307 {"D-Link DFE-580TX 4 port Server Adapter"}, 229 {"D-Link DFE-580TX 4 port Server Adapter"},
@@ -309,7 +231,7 @@ static const struct pci_id_info pci_id_tbl[] = {
309 {"D-Link DL10050-based FAST Ethernet Adapter"}, 231 {"D-Link DL10050-based FAST Ethernet Adapter"},
310 {"Sundance Technology Alta"}, 232 {"Sundance Technology Alta"},
311 {"IC Plus Corporation IP100A FAST Ethernet Adapter"}, 233 {"IC Plus Corporation IP100A FAST Ethernet Adapter"},
312 {NULL,}, /* 0 terminated list. */ 234 { } /* terminate list. */
313}; 235};
314 236
315/* This driver was written to use PCI memory space, however x86-oriented 237/* This driver was written to use PCI memory space, however x86-oriented
diff --git a/drivers/net/sunhme.c b/drivers/net/sunhme.c
index 8673fd4c08c7..c6f5bc3c042f 100644
--- a/drivers/net/sunhme.c
+++ b/drivers/net/sunhme.c
@@ -3255,12 +3255,7 @@ static void __devexit happy_meal_pci_remove(struct pci_dev *pdev)
3255} 3255}
3256 3256
3257static struct pci_device_id happymeal_pci_ids[] = { 3257static struct pci_device_id happymeal_pci_ids[] = {
3258 { 3258 { PCI_DEVICE(PCI_VENDOR_ID_SUN, PCI_DEVICE_ID_SUN_HAPPYMEAL) },
3259 .vendor = PCI_VENDOR_ID_SUN,
3260 .device = PCI_DEVICE_ID_SUN_HAPPYMEAL,
3261 .subvendor = PCI_ANY_ID,
3262 .subdevice = PCI_ANY_ID,
3263 },
3264 { } /* Terminating entry */ 3259 { } /* Terminating entry */
3265}; 3260};
3266 3261
@@ -3275,7 +3270,7 @@ static struct pci_driver hme_pci_driver = {
3275 3270
3276static int __init happy_meal_pci_init(void) 3271static int __init happy_meal_pci_init(void)
3277{ 3272{
3278 return pci_module_init(&hme_pci_driver); 3273 return pci_register_driver(&hme_pci_driver);
3279} 3274}
3280 3275
3281static void happy_meal_pci_exit(void) 3276static void happy_meal_pci_exit(void)
diff --git a/drivers/net/sunlance.c b/drivers/net/sunlance.c
index 1ef9fd39a79a..ec0413609f36 100644
--- a/drivers/net/sunlance.c
+++ b/drivers/net/sunlance.c
@@ -1537,7 +1537,7 @@ static int __init sparc_lance_init(void)
1537{ 1537{
1538 if ((idprom->id_machtype == (SM_SUN4|SM_4_330)) || 1538 if ((idprom->id_machtype == (SM_SUN4|SM_4_330)) ||
1539 (idprom->id_machtype == (SM_SUN4|SM_4_470))) { 1539 (idprom->id_machtype == (SM_SUN4|SM_4_470))) {
1540 memset(&sun4_sdev, 0, sizeof(sdev)); 1540 memset(&sun4_sdev, 0, sizeof(struct sbus_dev));
1541 sun4_sdev.reg_addrs[0].phys_addr = sun4_eth_physaddr; 1541 sun4_sdev.reg_addrs[0].phys_addr = sun4_eth_physaddr;
1542 sun4_sdev.irqs[0] = 6; 1542 sun4_sdev.irqs[0] = 6;
1543 return sparc_lance_probe_one(&sun4_sdev, NULL, NULL); 1543 return sparc_lance_probe_one(&sun4_sdev, NULL, NULL);
@@ -1547,16 +1547,16 @@ static int __init sparc_lance_init(void)
1547 1547
1548static int __exit sunlance_sun4_remove(void) 1548static int __exit sunlance_sun4_remove(void)
1549{ 1549{
1550 struct lance_private *lp = dev_get_drvdata(&sun4_sdev->dev); 1550 struct lance_private *lp = dev_get_drvdata(&sun4_sdev.ofdev.dev);
1551 struct net_device *net_dev = lp->dev; 1551 struct net_device *net_dev = lp->dev;
1552 1552
1553 unregister_netdevice(net_dev); 1553 unregister_netdevice(net_dev);
1554 1554
1555 lance_free_hwresources(root_lance_dev); 1555 lance_free_hwresources(lp);
1556 1556
1557 free_netdev(net_dev); 1557 free_netdev(net_dev);
1558 1558
1559 dev_set_drvdata(&sun4_sdev->dev, NULL); 1559 dev_set_drvdata(&sun4_sdev.ofdev.dev, NULL);
1560 1560
1561 return 0; 1561 return 0;
1562} 1562}
@@ -1566,20 +1566,21 @@ static int __exit sunlance_sun4_remove(void)
1566static int __devinit sunlance_sbus_probe(struct of_device *dev, const struct of_device_id *match) 1566static int __devinit sunlance_sbus_probe(struct of_device *dev, const struct of_device_id *match)
1567{ 1567{
1568 struct sbus_dev *sdev = to_sbus_device(&dev->dev); 1568 struct sbus_dev *sdev = to_sbus_device(&dev->dev);
1569 struct device_node *dp = dev->node;
1570 int err; 1569 int err;
1571 1570
1572 if (!strcmp(dp->name, "le")) { 1571 if (sdev->parent) {
1573 err = sparc_lance_probe_one(sdev, NULL, NULL); 1572 struct of_device *parent = &sdev->parent->ofdev;
1574 } else if (!strcmp(dp->name, "ledma")) {
1575 struct sbus_dma *ledma = find_ledma(sdev);
1576 1573
1577 err = sparc_lance_probe_one(sdev->child, ledma, NULL); 1574 if (!strcmp(parent->node->name, "ledma")) {
1578 } else { 1575 struct sbus_dma *ledma = find_ledma(to_sbus_device(&parent->dev));
1579 BUG_ON(strcmp(dp->name, "lebuffer"));
1580 1576
1581 err = sparc_lance_probe_one(sdev->child, NULL, sdev); 1577 err = sparc_lance_probe_one(sdev, ledma, NULL);
1582 } 1578 } else if (!strcmp(parent->node->name, "lebuffer")) {
1579 err = sparc_lance_probe_one(sdev, NULL, to_sbus_device(&parent->dev));
1580 } else
1581 err = sparc_lance_probe_one(sdev, NULL, NULL);
1582 } else
1583 err = sparc_lance_probe_one(sdev, NULL, NULL);
1583 1584
1584 return err; 1585 return err;
1585} 1586}
@@ -1604,12 +1605,6 @@ static struct of_device_id sunlance_sbus_match[] = {
1604 { 1605 {
1605 .name = "le", 1606 .name = "le",
1606 }, 1607 },
1607 {
1608 .name = "ledma",
1609 },
1610 {
1611 .name = "lebuffer",
1612 },
1613 {}, 1608 {},
1614}; 1609};
1615 1610
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index e5e1b2962936..eafabb253f08 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -68,8 +68,8 @@
68 68
69#define DRV_MODULE_NAME "tg3" 69#define DRV_MODULE_NAME "tg3"
70#define PFX DRV_MODULE_NAME ": " 70#define PFX DRV_MODULE_NAME ": "
71#define DRV_MODULE_VERSION "3.61" 71#define DRV_MODULE_VERSION "3.65"
72#define DRV_MODULE_RELDATE "June 29, 2006" 72#define DRV_MODULE_RELDATE "August 07, 2006"
73 73
74#define TG3_DEF_MAC_MODE 0 74#define TG3_DEF_MAC_MODE 0
75#define TG3_DEF_RX_MODE 0 75#define TG3_DEF_RX_MODE 0
@@ -123,9 +123,6 @@
123 TG3_RX_RCB_RING_SIZE(tp)) 123 TG3_RX_RCB_RING_SIZE(tp))
124#define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ 124#define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
125 TG3_TX_RING_SIZE) 125 TG3_TX_RING_SIZE)
126#define TX_BUFFS_AVAIL(TP) \
127 ((TP)->tx_pending - \
128 (((TP)->tx_prod - (TP)->tx_cons) & (TG3_TX_RING_SIZE - 1)))
129#define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) 126#define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
130 127
131#define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64) 128#define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
@@ -2987,6 +2984,13 @@ static void tg3_tx_recover(struct tg3 *tp)
2987 spin_unlock(&tp->lock); 2984 spin_unlock(&tp->lock);
2988} 2985}
2989 2986
2987static inline u32 tg3_tx_avail(struct tg3 *tp)
2988{
2989 smp_mb();
2990 return (tp->tx_pending -
2991 ((tp->tx_prod - tp->tx_cons) & (TG3_TX_RING_SIZE - 1)));
2992}
2993
2990/* Tigon3 never reports partial packet sends. So we do not 2994/* Tigon3 never reports partial packet sends. So we do not
2991 * need special logic to handle SKBs that have not had all 2995 * need special logic to handle SKBs that have not had all
2992 * of their frags sent yet, like SunGEM does. 2996 * of their frags sent yet, like SunGEM does.
@@ -3038,12 +3042,20 @@ static void tg3_tx(struct tg3 *tp)
3038 3042
3039 tp->tx_cons = sw_idx; 3043 tp->tx_cons = sw_idx;
3040 3044
3041 if (unlikely(netif_queue_stopped(tp->dev))) { 3045 /* Need to make the tx_cons update visible to tg3_start_xmit()
3042 spin_lock(&tp->tx_lock); 3046 * before checking for netif_queue_stopped(). Without the
3047 * memory barrier, there is a small possibility that tg3_start_xmit()
3048 * will miss it and cause the queue to be stopped forever.
3049 */
3050 smp_mb();
3051
3052 if (unlikely(netif_queue_stopped(tp->dev) &&
3053 (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH))) {
3054 netif_tx_lock(tp->dev);
3043 if (netif_queue_stopped(tp->dev) && 3055 if (netif_queue_stopped(tp->dev) &&
3044 (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH)) 3056 (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH))
3045 netif_wake_queue(tp->dev); 3057 netif_wake_queue(tp->dev);
3046 spin_unlock(&tp->tx_lock); 3058 netif_tx_unlock(tp->dev);
3047 } 3059 }
3048} 3060}
3049 3061
@@ -3097,11 +3109,10 @@ static int tg3_alloc_rx_skb(struct tg3 *tp, u32 opaque_key,
3097 * Callers depend upon this behavior and assume that 3109 * Callers depend upon this behavior and assume that
3098 * we leave everything unchanged if we fail. 3110 * we leave everything unchanged if we fail.
3099 */ 3111 */
3100 skb = dev_alloc_skb(skb_size); 3112 skb = netdev_alloc_skb(tp->dev, skb_size);
3101 if (skb == NULL) 3113 if (skb == NULL)
3102 return -ENOMEM; 3114 return -ENOMEM;
3103 3115
3104 skb->dev = tp->dev;
3105 skb_reserve(skb, tp->rx_offset); 3116 skb_reserve(skb, tp->rx_offset);
3106 3117
3107 mapping = pci_map_single(tp->pdev, skb->data, 3118 mapping = pci_map_single(tp->pdev, skb->data,
@@ -3270,11 +3281,10 @@ static int tg3_rx(struct tg3 *tp, int budget)
3270 tg3_recycle_rx(tp, opaque_key, 3281 tg3_recycle_rx(tp, opaque_key,
3271 desc_idx, *post_ptr); 3282 desc_idx, *post_ptr);
3272 3283
3273 copy_skb = dev_alloc_skb(len + 2); 3284 copy_skb = netdev_alloc_skb(tp->dev, len + 2);
3274 if (copy_skb == NULL) 3285 if (copy_skb == NULL)
3275 goto drop_it_no_recycle; 3286 goto drop_it_no_recycle;
3276 3287
3277 copy_skb->dev = tp->dev;
3278 skb_reserve(copy_skb, 2); 3288 skb_reserve(copy_skb, 2);
3279 skb_put(copy_skb, len); 3289 skb_put(copy_skb, len);
3280 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); 3290 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE);
@@ -3590,6 +3600,28 @@ static irqreturn_t tg3_test_isr(int irq, void *dev_id,
3590static int tg3_init_hw(struct tg3 *, int); 3600static int tg3_init_hw(struct tg3 *, int);
3591static int tg3_halt(struct tg3 *, int, int); 3601static int tg3_halt(struct tg3 *, int, int);
3592 3602
3603/* Restart hardware after configuration changes, self-test, etc.
3604 * Invoked with tp->lock held.
3605 */
3606static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
3607{
3608 int err;
3609
3610 err = tg3_init_hw(tp, reset_phy);
3611 if (err) {
3612 printk(KERN_ERR PFX "%s: Failed to re-initialize device, "
3613 "aborting.\n", tp->dev->name);
3614 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
3615 tg3_full_unlock(tp);
3616 del_timer_sync(&tp->timer);
3617 tp->irq_sync = 0;
3618 netif_poll_enable(tp->dev);
3619 dev_close(tp->dev);
3620 tg3_full_lock(tp, 0);
3621 }
3622 return err;
3623}
3624
3593#ifdef CONFIG_NET_POLL_CONTROLLER 3625#ifdef CONFIG_NET_POLL_CONTROLLER
3594static void tg3_poll_controller(struct net_device *dev) 3626static void tg3_poll_controller(struct net_device *dev)
3595{ 3627{
@@ -3630,13 +3662,15 @@ static void tg3_reset_task(void *_data)
3630 } 3662 }
3631 3663
3632 tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); 3664 tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
3633 tg3_init_hw(tp, 1); 3665 if (tg3_init_hw(tp, 1))
3666 goto out;
3634 3667
3635 tg3_netif_start(tp); 3668 tg3_netif_start(tp);
3636 3669
3637 if (restart_timer) 3670 if (restart_timer)
3638 mod_timer(&tp->timer, jiffies + 1); 3671 mod_timer(&tp->timer, jiffies + 1);
3639 3672
3673out:
3640 tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK; 3674 tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
3641 3675
3642 tg3_full_unlock(tp); 3676 tg3_full_unlock(tp);
@@ -3773,7 +3807,7 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
3773 * interrupt. Furthermore, IRQ processing runs lockless so we have 3807 * interrupt. Furthermore, IRQ processing runs lockless so we have
3774 * no IRQ context deadlocks to worry about either. Rejoice! 3808 * no IRQ context deadlocks to worry about either. Rejoice!
3775 */ 3809 */
3776 if (unlikely(TX_BUFFS_AVAIL(tp) <= (skb_shinfo(skb)->nr_frags + 1))) { 3810 if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
3777 if (!netif_queue_stopped(dev)) { 3811 if (!netif_queue_stopped(dev)) {
3778 netif_stop_queue(dev); 3812 netif_stop_queue(dev);
3779 3813
@@ -3798,18 +3832,24 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
3798 goto out_unlock; 3832 goto out_unlock;
3799 } 3833 }
3800 3834
3801 tcp_opt_len = ((skb->h.th->doff - 5) * 4); 3835 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
3802 ip_tcp_len = (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr); 3836 mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
3837 else {
3838 tcp_opt_len = ((skb->h.th->doff - 5) * 4);
3839 ip_tcp_len = (skb->nh.iph->ihl * 4) +
3840 sizeof(struct tcphdr);
3841
3842 skb->nh.iph->check = 0;
3843 skb->nh.iph->tot_len = htons(mss + ip_tcp_len +
3844 tcp_opt_len);
3845 mss |= (ip_tcp_len + tcp_opt_len) << 9;
3846 }
3803 3847
3804 base_flags |= (TXD_FLAG_CPU_PRE_DMA | 3848 base_flags |= (TXD_FLAG_CPU_PRE_DMA |
3805 TXD_FLAG_CPU_POST_DMA); 3849 TXD_FLAG_CPU_POST_DMA);
3806 3850
3807 skb->nh.iph->check = 0;
3808 skb->nh.iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
3809
3810 skb->h.th->check = 0; 3851 skb->h.th->check = 0;
3811 3852
3812 mss |= (ip_tcp_len + tcp_opt_len) << 9;
3813 } 3853 }
3814 else if (skb->ip_summed == CHECKSUM_HW) 3854 else if (skb->ip_summed == CHECKSUM_HW)
3815 base_flags |= TXD_FLAG_TCPUDP_CSUM; 3855 base_flags |= TXD_FLAG_TCPUDP_CSUM;
@@ -3863,12 +3903,10 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
3863 tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry); 3903 tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
3864 3904
3865 tp->tx_prod = entry; 3905 tp->tx_prod = entry;
3866 if (unlikely(TX_BUFFS_AVAIL(tp) <= (MAX_SKB_FRAGS + 1))) { 3906 if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
3867 spin_lock(&tp->tx_lock);
3868 netif_stop_queue(dev); 3907 netif_stop_queue(dev);
3869 if (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH) 3908 if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH)
3870 netif_wake_queue(tp->dev); 3909 netif_wake_queue(tp->dev);
3871 spin_unlock(&tp->tx_lock);
3872 } 3910 }
3873 3911
3874out_unlock: 3912out_unlock:
@@ -3890,7 +3928,7 @@ static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb)
3890 struct sk_buff *segs, *nskb; 3928 struct sk_buff *segs, *nskb;
3891 3929
3892 /* Estimate the number of fragments in the worst case */ 3930 /* Estimate the number of fragments in the worst case */
3893 if (unlikely(TX_BUFFS_AVAIL(tp) <= (skb_shinfo(skb)->gso_segs * 3))) { 3931 if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->gso_segs * 3))) {
3894 netif_stop_queue(tp->dev); 3932 netif_stop_queue(tp->dev);
3895 return NETDEV_TX_BUSY; 3933 return NETDEV_TX_BUSY;
3896 } 3934 }
@@ -3930,7 +3968,7 @@ static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
3930 * interrupt. Furthermore, IRQ processing runs lockless so we have 3968 * interrupt. Furthermore, IRQ processing runs lockless so we have
3931 * no IRQ context deadlocks to worry about either. Rejoice! 3969 * no IRQ context deadlocks to worry about either. Rejoice!
3932 */ 3970 */
3933 if (unlikely(TX_BUFFS_AVAIL(tp) <= (skb_shinfo(skb)->nr_frags + 1))) { 3971 if (unlikely(tg3_tx_avail(tp) <= (skb_shinfo(skb)->nr_frags + 1))) {
3934 if (!netif_queue_stopped(dev)) { 3972 if (!netif_queue_stopped(dev)) {
3935 netif_stop_queue(dev); 3973 netif_stop_queue(dev);
3936 3974
@@ -4080,12 +4118,10 @@ static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
4080 tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry); 4118 tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
4081 4119
4082 tp->tx_prod = entry; 4120 tp->tx_prod = entry;
4083 if (unlikely(TX_BUFFS_AVAIL(tp) <= (MAX_SKB_FRAGS + 1))) { 4121 if (unlikely(tg3_tx_avail(tp) <= (MAX_SKB_FRAGS + 1))) {
4084 spin_lock(&tp->tx_lock);
4085 netif_stop_queue(dev); 4122 netif_stop_queue(dev);
4086 if (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH) 4123 if (tg3_tx_avail(tp) > TG3_TX_WAKEUP_THRESH)
4087 netif_wake_queue(tp->dev); 4124 netif_wake_queue(tp->dev);
4088 spin_unlock(&tp->tx_lock);
4089 } 4125 }
4090 4126
4091out_unlock: 4127out_unlock:
@@ -4118,6 +4154,7 @@ static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
4118static int tg3_change_mtu(struct net_device *dev, int new_mtu) 4154static int tg3_change_mtu(struct net_device *dev, int new_mtu)
4119{ 4155{
4120 struct tg3 *tp = netdev_priv(dev); 4156 struct tg3 *tp = netdev_priv(dev);
4157 int err;
4121 4158
4122 if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) 4159 if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp))
4123 return -EINVAL; 4160 return -EINVAL;
@@ -4138,13 +4175,14 @@ static int tg3_change_mtu(struct net_device *dev, int new_mtu)
4138 4175
4139 tg3_set_mtu(dev, tp, new_mtu); 4176 tg3_set_mtu(dev, tp, new_mtu);
4140 4177
4141 tg3_init_hw(tp, 0); 4178 err = tg3_restart_hw(tp, 0);
4142 4179
4143 tg3_netif_start(tp); 4180 if (!err)
4181 tg3_netif_start(tp);
4144 4182
4145 tg3_full_unlock(tp); 4183 tg3_full_unlock(tp);
4146 4184
4147 return 0; 4185 return err;
4148} 4186}
4149 4187
4150/* Free up pending packets in all rx/tx rings. 4188/* Free up pending packets in all rx/tx rings.
@@ -4226,7 +4264,7 @@ static void tg3_free_rings(struct tg3 *tp)
4226 * end up in the driver. tp->{tx,}lock are held and thus 4264 * end up in the driver. tp->{tx,}lock are held and thus
4227 * we may not sleep. 4265 * we may not sleep.
4228 */ 4266 */
4229static void tg3_init_rings(struct tg3 *tp) 4267static int tg3_init_rings(struct tg3 *tp)
4230{ 4268{
4231 u32 i; 4269 u32 i;
4232 4270
@@ -4275,18 +4313,38 @@ static void tg3_init_rings(struct tg3 *tp)
4275 4313
4276 /* Now allocate fresh SKBs for each rx ring. */ 4314 /* Now allocate fresh SKBs for each rx ring. */
4277 for (i = 0; i < tp->rx_pending; i++) { 4315 for (i = 0; i < tp->rx_pending; i++) {
4278 if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, 4316 if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, -1, i) < 0) {
4279 -1, i) < 0) 4317 printk(KERN_WARNING PFX
4318 "%s: Using a smaller RX standard ring, "
4319 "only %d out of %d buffers were allocated "
4320 "successfully.\n",
4321 tp->dev->name, i, tp->rx_pending);
4322 if (i == 0)
4323 return -ENOMEM;
4324 tp->rx_pending = i;
4280 break; 4325 break;
4326 }
4281 } 4327 }
4282 4328
4283 if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) { 4329 if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
4284 for (i = 0; i < tp->rx_jumbo_pending; i++) { 4330 for (i = 0; i < tp->rx_jumbo_pending; i++) {
4285 if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO, 4331 if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
4286 -1, i) < 0) 4332 -1, i) < 0) {
4333 printk(KERN_WARNING PFX
4334 "%s: Using a smaller RX jumbo ring, "
4335 "only %d out of %d buffers were "
4336 "allocated successfully.\n",
4337 tp->dev->name, i, tp->rx_jumbo_pending);
4338 if (i == 0) {
4339 tg3_free_rings(tp);
4340 return -ENOMEM;
4341 }
4342 tp->rx_jumbo_pending = i;
4287 break; 4343 break;
4344 }
4288 } 4345 }
4289 } 4346 }
4347 return 0;
4290} 4348}
4291 4349
4292/* 4350/*
@@ -5809,6 +5867,7 @@ static int tg3_set_mac_addr(struct net_device *dev, void *p)
5809{ 5867{
5810 struct tg3 *tp = netdev_priv(dev); 5868 struct tg3 *tp = netdev_priv(dev);
5811 struct sockaddr *addr = p; 5869 struct sockaddr *addr = p;
5870 int err = 0;
5812 5871
5813 if (!is_valid_ether_addr(addr->sa_data)) 5872 if (!is_valid_ether_addr(addr->sa_data))
5814 return -EINVAL; 5873 return -EINVAL;
@@ -5826,9 +5885,9 @@ static int tg3_set_mac_addr(struct net_device *dev, void *p)
5826 tg3_full_lock(tp, 1); 5885 tg3_full_lock(tp, 1);
5827 5886
5828 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); 5887 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
5829 tg3_init_hw(tp, 0); 5888 err = tg3_restart_hw(tp, 0);
5830 5889 if (!err)
5831 tg3_netif_start(tp); 5890 tg3_netif_start(tp);
5832 tg3_full_unlock(tp); 5891 tg3_full_unlock(tp);
5833 } else { 5892 } else {
5834 spin_lock_bh(&tp->lock); 5893 spin_lock_bh(&tp->lock);
@@ -5836,7 +5895,7 @@ static int tg3_set_mac_addr(struct net_device *dev, void *p)
5836 spin_unlock_bh(&tp->lock); 5895 spin_unlock_bh(&tp->lock);
5837 } 5896 }
5838 5897
5839 return 0; 5898 return err;
5840} 5899}
5841 5900
5842/* tp->lock is held. */ 5901/* tp->lock is held. */
@@ -5936,7 +5995,9 @@ static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
5936 * can only do this after the hardware has been 5995 * can only do this after the hardware has been
5937 * successfully reset. 5996 * successfully reset.
5938 */ 5997 */
5939 tg3_init_rings(tp); 5998 err = tg3_init_rings(tp);
5999 if (err)
6000 return err;
5940 6001
5941 /* This value is determined during the probe time DMA 6002 /* This value is determined during the probe time DMA
5942 * engine test, tg3_test_dma. 6003 * engine test, tg3_test_dma.
@@ -7887,6 +7948,12 @@ static int tg3_set_tso(struct net_device *dev, u32 value)
7887 return -EINVAL; 7948 return -EINVAL;
7888 return 0; 7949 return 0;
7889 } 7950 }
7951 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) {
7952 if (value)
7953 dev->features |= NETIF_F_TSO6;
7954 else
7955 dev->features &= ~NETIF_F_TSO6;
7956 }
7890 return ethtool_op_set_tso(dev, value); 7957 return ethtool_op_set_tso(dev, value);
7891} 7958}
7892#endif 7959#endif
@@ -7944,7 +8011,7 @@ static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *
7944static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) 8011static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
7945{ 8012{
7946 struct tg3 *tp = netdev_priv(dev); 8013 struct tg3 *tp = netdev_priv(dev);
7947 int irq_sync = 0; 8014 int irq_sync = 0, err = 0;
7948 8015
7949 if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) || 8016 if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) ||
7950 (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) || 8017 (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) ||
@@ -7968,13 +8035,14 @@ static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *e
7968 8035
7969 if (netif_running(dev)) { 8036 if (netif_running(dev)) {
7970 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); 8037 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
7971 tg3_init_hw(tp, 1); 8038 err = tg3_restart_hw(tp, 1);
7972 tg3_netif_start(tp); 8039 if (!err)
8040 tg3_netif_start(tp);
7973 } 8041 }
7974 8042
7975 tg3_full_unlock(tp); 8043 tg3_full_unlock(tp);
7976 8044
7977 return 0; 8045 return err;
7978} 8046}
7979 8047
7980static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) 8048static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
@@ -7989,7 +8057,7 @@ static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam
7989static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) 8057static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
7990{ 8058{
7991 struct tg3 *tp = netdev_priv(dev); 8059 struct tg3 *tp = netdev_priv(dev);
7992 int irq_sync = 0; 8060 int irq_sync = 0, err = 0;
7993 8061
7994 if (netif_running(dev)) { 8062 if (netif_running(dev)) {
7995 tg3_netif_stop(tp); 8063 tg3_netif_stop(tp);
@@ -8013,13 +8081,14 @@ static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam
8013 8081
8014 if (netif_running(dev)) { 8082 if (netif_running(dev)) {
8015 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); 8083 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
8016 tg3_init_hw(tp, 1); 8084 err = tg3_restart_hw(tp, 1);
8017 tg3_netif_start(tp); 8085 if (!err)
8086 tg3_netif_start(tp);
8018 } 8087 }
8019 8088
8020 tg3_full_unlock(tp); 8089 tg3_full_unlock(tp);
8021 8090
8022 return 0; 8091 return err;
8023} 8092}
8024 8093
8025static u32 tg3_get_rx_csum(struct net_device *dev) 8094static u32 tg3_get_rx_csum(struct net_device *dev)
@@ -8555,7 +8624,7 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
8555 err = -EIO; 8624 err = -EIO;
8556 8625
8557 tx_len = 1514; 8626 tx_len = 1514;
8558 skb = dev_alloc_skb(tx_len); 8627 skb = netdev_alloc_skb(tp->dev, tx_len);
8559 if (!skb) 8628 if (!skb)
8560 return -ENOMEM; 8629 return -ENOMEM;
8561 8630
@@ -8654,7 +8723,9 @@ static int tg3_test_loopback(struct tg3 *tp)
8654 if (!netif_running(tp->dev)) 8723 if (!netif_running(tp->dev))
8655 return TG3_LOOPBACK_FAILED; 8724 return TG3_LOOPBACK_FAILED;
8656 8725
8657 tg3_reset_hw(tp, 1); 8726 err = tg3_reset_hw(tp, 1);
8727 if (err)
8728 return TG3_LOOPBACK_FAILED;
8658 8729
8659 if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK)) 8730 if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
8660 err |= TG3_MAC_LOOPBACK_FAILED; 8731 err |= TG3_MAC_LOOPBACK_FAILED;
@@ -8728,8 +8799,8 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
8728 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); 8799 tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
8729 if (netif_running(dev)) { 8800 if (netif_running(dev)) {
8730 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; 8801 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
8731 tg3_init_hw(tp, 1); 8802 if (!tg3_restart_hw(tp, 1))
8732 tg3_netif_start(tp); 8803 tg3_netif_start(tp);
8733 } 8804 }
8734 8805
8735 tg3_full_unlock(tp); 8806 tg3_full_unlock(tp);
@@ -10066,6 +10137,8 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10066 static struct pci_device_id write_reorder_chipsets[] = { 10137 static struct pci_device_id write_reorder_chipsets[] = {
10067 { PCI_DEVICE(PCI_VENDOR_ID_AMD, 10138 { PCI_DEVICE(PCI_VENDOR_ID_AMD,
10068 PCI_DEVICE_ID_AMD_FE_GATE_700C) }, 10139 PCI_DEVICE_ID_AMD_FE_GATE_700C) },
10140 { PCI_DEVICE(PCI_VENDOR_ID_AMD,
10141 PCI_DEVICE_ID_AMD_8131_BRIDGE) },
10069 { PCI_DEVICE(PCI_VENDOR_ID_VIA, 10142 { PCI_DEVICE(PCI_VENDOR_ID_VIA,
10070 PCI_DEVICE_ID_VIA_8385_0) }, 10143 PCI_DEVICE_ID_VIA_8385_0) },
10071 { }, 10144 { },
@@ -11407,7 +11480,6 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11407 tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; 11480 tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA;
11408#endif 11481#endif
11409 spin_lock_init(&tp->lock); 11482 spin_lock_init(&tp->lock);
11410 spin_lock_init(&tp->tx_lock);
11411 spin_lock_init(&tp->indirect_lock); 11483 spin_lock_init(&tp->indirect_lock);
11412 INIT_WORK(&tp->reset_task, tg3_reset_task, tp); 11484 INIT_WORK(&tp->reset_task, tg3_reset_task, tp);
11413 11485
@@ -11507,8 +11579,11 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11507 * Firmware TSO on older chips gives lower performance, so it 11579 * Firmware TSO on older chips gives lower performance, so it
11508 * is off by default, but can be enabled using ethtool. 11580 * is off by default, but can be enabled using ethtool.
11509 */ 11581 */
11510 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) 11582 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) {
11511 dev->features |= NETIF_F_TSO; 11583 dev->features |= NETIF_F_TSO;
11584 if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_2)
11585 dev->features |= NETIF_F_TSO6;
11586 }
11512 11587
11513#endif 11588#endif
11514 11589
@@ -11682,7 +11757,8 @@ static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
11682 tg3_full_lock(tp, 0); 11757 tg3_full_lock(tp, 0);
11683 11758
11684 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; 11759 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
11685 tg3_init_hw(tp, 1); 11760 if (tg3_restart_hw(tp, 1))
11761 goto out;
11686 11762
11687 tp->timer.expires = jiffies + tp->timer_offset; 11763 tp->timer.expires = jiffies + tp->timer_offset;
11688 add_timer(&tp->timer); 11764 add_timer(&tp->timer);
@@ -11690,6 +11766,7 @@ static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
11690 netif_device_attach(dev); 11766 netif_device_attach(dev);
11691 tg3_netif_start(tp); 11767 tg3_netif_start(tp);
11692 11768
11769out:
11693 tg3_full_unlock(tp); 11770 tg3_full_unlock(tp);
11694 } 11771 }
11695 11772
@@ -11716,16 +11793,19 @@ static int tg3_resume(struct pci_dev *pdev)
11716 tg3_full_lock(tp, 0); 11793 tg3_full_lock(tp, 0);
11717 11794
11718 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; 11795 tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE;
11719 tg3_init_hw(tp, 1); 11796 err = tg3_restart_hw(tp, 1);
11797 if (err)
11798 goto out;
11720 11799
11721 tp->timer.expires = jiffies + tp->timer_offset; 11800 tp->timer.expires = jiffies + tp->timer_offset;
11722 add_timer(&tp->timer); 11801 add_timer(&tp->timer);
11723 11802
11724 tg3_netif_start(tp); 11803 tg3_netif_start(tp);
11725 11804
11805out:
11726 tg3_full_unlock(tp); 11806 tg3_full_unlock(tp);
11727 11807
11728 return 0; 11808 return err;
11729} 11809}
11730 11810
11731static struct pci_driver tg3_driver = { 11811static struct pci_driver tg3_driver = {
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index ba2c98711c88..3ecf356cfb08 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -2079,9 +2079,9 @@ struct tg3 {
2079 * lock: Held during reset, PHY access, timer, and when 2079 * lock: Held during reset, PHY access, timer, and when
2080 * updating tg3_flags and tg3_flags2. 2080 * updating tg3_flags and tg3_flags2.
2081 * 2081 *
2082 * tx_lock: Held during tg3_start_xmit and tg3_tx only 2082 * netif_tx_lock: Held during tg3_start_xmit. tg3_tx holds
2083 * when calling netif_[start|stop]_queue. 2083 * netif_tx_lock when it needs to call
2084 * tg3_start_xmit is protected by netif_tx_lock. 2084 * netif_wake_queue.
2085 * 2085 *
2086 * Both of these locks are to be held with BH safety. 2086 * Both of these locks are to be held with BH safety.
2087 * 2087 *
@@ -2118,8 +2118,6 @@ struct tg3 {
2118 u32 tx_cons; 2118 u32 tx_cons;
2119 u32 tx_pending; 2119 u32 tx_pending;
2120 2120
2121 spinlock_t tx_lock;
2122
2123 struct tg3_tx_buffer_desc *tx_ring; 2121 struct tg3_tx_buffer_desc *tx_ring;
2124 struct tx_ring_info *tx_buffers; 2122 struct tx_ring_info *tx_buffers;
2125 dma_addr_t tx_desc_mapping; 2123 dma_addr_t tx_desc_mapping;
diff --git a/drivers/net/tokenring/ibmtr.c b/drivers/net/tokenring/ibmtr.c
index 9f491563944e..4470025ff7f8 100644
--- a/drivers/net/tokenring/ibmtr.c
+++ b/drivers/net/tokenring/ibmtr.c
@@ -140,7 +140,7 @@ in the event that chatty debug messages are desired - jjs 12/30/98 */
140 140
141/* version and credits */ 141/* version and credits */
142#ifndef PCMCIA 142#ifndef PCMCIA
143static char version[] __initdata = 143static char version[] __devinitdata =
144 "\nibmtr.c: v1.3.57 8/ 7/94 Peter De Schrijver and Mark Swanson\n" 144 "\nibmtr.c: v1.3.57 8/ 7/94 Peter De Schrijver and Mark Swanson\n"
145 " v2.1.125 10/20/98 Paul Norton <pnorton@ieee.org>\n" 145 " v2.1.125 10/20/98 Paul Norton <pnorton@ieee.org>\n"
146 " v2.2.0 12/30/98 Joel Sloan <jjs@c-me.com>\n" 146 " v2.2.0 12/30/98 Joel Sloan <jjs@c-me.com>\n"
@@ -216,7 +216,7 @@ static int __devinitdata turbo_irq[IBMTR_MAX_ADAPTERS] = {0};
216static int __devinitdata turbo_searched = 0; 216static int __devinitdata turbo_searched = 0;
217 217
218#ifndef PCMCIA 218#ifndef PCMCIA
219static __u32 ibmtr_mem_base __initdata = 0xd0000; 219static __u32 ibmtr_mem_base __devinitdata = 0xd0000;
220#endif 220#endif
221 221
222static void __devinit PrtChanID(char *pcid, short stride) 222static void __devinit PrtChanID(char *pcid, short stride)
diff --git a/drivers/net/tokenring/smctr.c b/drivers/net/tokenring/smctr.c
index cd2e0251e2bc..85a7f797d343 100644
--- a/drivers/net/tokenring/smctr.c
+++ b/drivers/net/tokenring/smctr.c
@@ -5666,7 +5666,7 @@ module_param_array(io, int, NULL, 0);
5666module_param_array(irq, int, NULL, 0); 5666module_param_array(irq, int, NULL, 0);
5667module_param(ringspeed, int, 0); 5667module_param(ringspeed, int, 0);
5668 5668
5669static struct net_device *setup_card(int n) 5669static struct net_device * __init setup_card(int n)
5670{ 5670{
5671 struct net_device *dev = alloc_trdev(sizeof(struct net_local)); 5671 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
5672 int err; 5672 int err;
@@ -5696,9 +5696,8 @@ out:
5696 free_netdev(dev); 5696 free_netdev(dev);
5697 return ERR_PTR(err); 5697 return ERR_PTR(err);
5698} 5698}
5699
5700 5699
5701int init_module(void) 5700int __init init_module(void)
5702{ 5701{
5703 int i, found = 0; 5702 int i, found = 0;
5704 struct net_device *dev; 5703 struct net_device *dev;
diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
index b4c0d101a7d7..eba9083da146 100644
--- a/drivers/net/tulip/winbond-840.c
+++ b/drivers/net/tulip/winbond-840.c
@@ -138,7 +138,7 @@ static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
138#include <asm/irq.h> 138#include <asm/irq.h>
139 139
140/* These identify the driver base version and may not be removed. */ 140/* These identify the driver base version and may not be removed. */
141static char version[] __devinitdata = 141static char version[] =
142KERN_INFO DRV_NAME ".c:v" DRV_VERSION " (2.4 port) " DRV_RELDATE " Donald Becker <becker@scyld.com>\n" 142KERN_INFO DRV_NAME ".c:v" DRV_VERSION " (2.4 port) " DRV_RELDATE " Donald Becker <becker@scyld.com>\n"
143KERN_INFO " http://www.scyld.com/network/drivers.html\n"; 143KERN_INFO " http://www.scyld.com/network/drivers.html\n";
144 144
@@ -224,24 +224,21 @@ static const struct pci_device_id w840_pci_tbl[] = {
224}; 224};
225MODULE_DEVICE_TABLE(pci, w840_pci_tbl); 225MODULE_DEVICE_TABLE(pci, w840_pci_tbl);
226 226
227enum {
228 netdev_res_size = 128, /* size of PCI BAR resource */
229};
230
227struct pci_id_info { 231struct pci_id_info {
228 const char *name; 232 const char *name;
229 struct match_info { 233 int drv_flags; /* Driver use, intended as capability flags. */
230 int pci, pci_mask, subsystem, subsystem_mask;
231 int revision, revision_mask; /* Only 8 bits. */
232 } id;
233 int io_size; /* Needed for I/O region check or ioremap(). */
234 int drv_flags; /* Driver use, intended as capability flags. */
235}; 234};
236static struct pci_id_info pci_id_tbl[] = { 235
237 {"Winbond W89c840", /* Sometime a Level-One switch card. */ 236static const struct pci_id_info pci_id_tbl[] __devinitdata = {
238 { 0x08401050, 0xffffffff, 0x81530000, 0xffff0000 }, 237 { /* Sometime a Level-One switch card. */
239 128, CanHaveMII | HasBrokenTx | FDXOnNoMII}, 238 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
240 {"Winbond W89c840", { 0x08401050, 0xffffffff, }, 239 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
241 128, CanHaveMII | HasBrokenTx}, 240 { "Compex RL100-ATX", CanHaveMII | HasBrokenTx},
242 {"Compex RL100-ATX", { 0x201111F6, 0xffffffff,}, 241 { } /* terminate list. */
243 128, CanHaveMII | HasBrokenTx},
244 {NULL,}, /* 0 terminated list. */
245}; 242};
246 243
247/* This driver was written to use PCI memory space, however some x86 systems 244/* This driver was written to use PCI memory space, however some x86 systems
@@ -399,7 +396,7 @@ static int __devinit w840_probe1 (struct pci_dev *pdev,
399#ifdef USE_IO_OPS 396#ifdef USE_IO_OPS
400 bar = 0; 397 bar = 0;
401#endif 398#endif
402 ioaddr = pci_iomap(pdev, bar, pci_id_tbl[chip_idx].io_size); 399 ioaddr = pci_iomap(pdev, bar, netdev_res_size);
403 if (!ioaddr) 400 if (!ioaddr)
404 goto err_out_free_res; 401 goto err_out_free_res;
405 402
diff --git a/drivers/net/tulip/xircom_cb.c b/drivers/net/tulip/xircom_cb.c
index f874e4f6ccf6..cf43390d2c80 100644
--- a/drivers/net/tulip/xircom_cb.c
+++ b/drivers/net/tulip/xircom_cb.c
@@ -1264,8 +1264,7 @@ static void investigate_write_descriptor(struct net_device *dev, struct xircom_p
1264 1264
1265static int __init xircom_init(void) 1265static int __init xircom_init(void)
1266{ 1266{
1267 pci_register_driver(&xircom_ops); 1267 return pci_register_driver(&xircom_ops);
1268 return 0;
1269} 1268}
1270 1269
1271static void __exit xircom_exit(void) 1270static void __exit xircom_exit(void)
diff --git a/drivers/net/tulip/xircom_tulip_cb.c b/drivers/net/tulip/xircom_tulip_cb.c
index 091ebb7a62f6..17ca7dc42e6f 100644
--- a/drivers/net/tulip/xircom_tulip_cb.c
+++ b/drivers/net/tulip/xircom_tulip_cb.c
@@ -10,26 +10,11 @@
10 410 Severn Ave., Suite 210 10 410 Severn Ave., Suite 210
11 Annapolis MD 21403 11 Annapolis MD 21403
12 12
13 -----------------------------------------------------------
14
15 Linux kernel-specific changes:
16
17 LK1.0 (Ion Badulescu)
18 - Major cleanup
19 - Use 2.4 PCI API
20 - Support ethtool
21 - Rewrite perfect filter/hash code
22 - Use interrupts for media changes
23
24 LK1.1 (Ion Badulescu)
25 - Disallow negotiation of unsupported full-duplex modes
26*/ 13*/
27 14
28#define DRV_NAME "xircom_tulip_cb" 15#define DRV_NAME "xircom_tulip_cb"
29#define DRV_VERSION "0.91+LK1.1" 16#define DRV_VERSION "0.92"
30#define DRV_RELDATE "October 11, 2001" 17#define DRV_RELDATE "June 27, 2006"
31
32#define CARDBUS 1
33 18
34/* A few user-configurable values. */ 19/* A few user-configurable values. */
35 20
@@ -306,10 +291,10 @@ struct xircom_private {
306 struct xircom_tx_desc tx_ring[TX_RING_SIZE]; 291 struct xircom_tx_desc tx_ring[TX_RING_SIZE];
307 /* The saved address of a sent-in-place packet/buffer, for skfree(). */ 292 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
308 struct sk_buff* tx_skbuff[TX_RING_SIZE]; 293 struct sk_buff* tx_skbuff[TX_RING_SIZE];
309#ifdef CARDBUS 294
310 /* The X3201-3 requires 4-byte aligned tx bufs */ 295 /* The X3201-3 requires 4-byte aligned tx bufs */
311 struct sk_buff* tx_aligned_skbuff[TX_RING_SIZE]; 296 struct sk_buff* tx_aligned_skbuff[TX_RING_SIZE];
312#endif 297
313 /* The addresses of receive-in-place skbuffs. */ 298 /* The addresses of receive-in-place skbuffs. */
314 struct sk_buff* rx_skbuff[RX_RING_SIZE]; 299 struct sk_buff* rx_skbuff[RX_RING_SIZE];
315 u16 setup_frame[PKT_SETUP_SZ / sizeof(u16)]; /* Pseudo-Tx frame to init address table. */ 300 u16 setup_frame[PKT_SETUP_SZ / sizeof(u16)]; /* Pseudo-Tx frame to init address table. */
@@ -908,10 +893,8 @@ static void xircom_init_ring(struct net_device *dev)
908 tp->tx_skbuff[i] = NULL; 893 tp->tx_skbuff[i] = NULL;
909 tp->tx_ring[i].status = 0; 894 tp->tx_ring[i].status = 0;
910 tp->tx_ring[i].buffer2 = virt_to_bus(&tp->tx_ring[i+1]); 895 tp->tx_ring[i].buffer2 = virt_to_bus(&tp->tx_ring[i+1]);
911#ifdef CARDBUS
912 if (tp->chip_id == X3201_3) 896 if (tp->chip_id == X3201_3)
913 tp->tx_aligned_skbuff[i] = dev_alloc_skb(PKT_BUF_SZ); 897 tp->tx_aligned_skbuff[i] = dev_alloc_skb(PKT_BUF_SZ);
914#endif /* CARDBUS */
915 } 898 }
916 tp->tx_ring[i-1].buffer2 = virt_to_bus(&tp->tx_ring[0]); 899 tp->tx_ring[i-1].buffer2 = virt_to_bus(&tp->tx_ring[0]);
917} 900}
@@ -931,12 +914,10 @@ xircom_start_xmit(struct sk_buff *skb, struct net_device *dev)
931 entry = tp->cur_tx % TX_RING_SIZE; 914 entry = tp->cur_tx % TX_RING_SIZE;
932 915
933 tp->tx_skbuff[entry] = skb; 916 tp->tx_skbuff[entry] = skb;
934#ifdef CARDBUS
935 if (tp->chip_id == X3201_3) { 917 if (tp->chip_id == X3201_3) {
936 memcpy(tp->tx_aligned_skbuff[entry]->data,skb->data,skb->len); 918 memcpy(tp->tx_aligned_skbuff[entry]->data,skb->data,skb->len);
937 tp->tx_ring[entry].buffer1 = virt_to_bus(tp->tx_aligned_skbuff[entry]->data); 919 tp->tx_ring[entry].buffer1 = virt_to_bus(tp->tx_aligned_skbuff[entry]->data);
938 } else 920 } else
939#endif
940 tp->tx_ring[entry].buffer1 = virt_to_bus(skb->data); 921 tp->tx_ring[entry].buffer1 = virt_to_bus(skb->data);
941 922
942 if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE/2) {/* Typical path */ 923 if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE/2) {/* Typical path */
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index 063816f2b11e..4103c37172f9 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -805,7 +805,7 @@ typhoon_start_tx(struct sk_buff *skb, struct net_device *dev)
805 * If problems develop with TSO, check this first. 805 * If problems develop with TSO, check this first.
806 */ 806 */
807 numDesc = skb_shinfo(skb)->nr_frags + 1; 807 numDesc = skb_shinfo(skb)->nr_frags + 1;
808 if(skb_tso_size(skb)) 808 if (skb_is_gso(skb))
809 numDesc++; 809 numDesc++;
810 810
811 /* When checking for free space in the ring, we need to also 811 /* When checking for free space in the ring, we need to also
@@ -845,7 +845,7 @@ typhoon_start_tx(struct sk_buff *skb, struct net_device *dev)
845 TYPHOON_TX_PF_VLAN_TAG_SHIFT); 845 TYPHOON_TX_PF_VLAN_TAG_SHIFT);
846 } 846 }
847 847
848 if(skb_tso_size(skb)) { 848 if (skb_is_gso(skb)) {
849 first_txd->processFlags |= TYPHOON_TX_PF_TCP_SEGMENT; 849 first_txd->processFlags |= TYPHOON_TX_PF_TCP_SEGMENT;
850 first_txd->numDesc++; 850 first_txd->numDesc++;
851 851
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
new file mode 100644
index 000000000000..47f49ef72bdc
--- /dev/null
+++ b/drivers/net/ucc_geth.c
@@ -0,0 +1,4278 @@
1/*
2 * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved.
3 *
4 * Author: Shlomi Gridish <gridish@freescale.com>
5 *
6 * Description:
7 * QE UCC Gigabit Ethernet Driver
8 *
9 * Changelog:
10 * Jul 6, 2006 Li Yang <LeoLi@freescale.com>
11 * - Rearrange code and style fixes
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 */
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/errno.h>
21#include <linux/slab.h>
22#include <linux/stddef.h>
23#include <linux/interrupt.h>
24#include <linux/netdevice.h>
25#include <linux/etherdevice.h>
26#include <linux/skbuff.h>
27#include <linux/spinlock.h>
28#include <linux/mm.h>
29#include <linux/ethtool.h>
30#include <linux/delay.h>
31#include <linux/dma-mapping.h>
32#include <linux/fsl_devices.h>
33#include <linux/ethtool.h>
34#include <linux/platform_device.h>
35#include <linux/mii.h>
36
37#include <asm/uaccess.h>
38#include <asm/irq.h>
39#include <asm/io.h>
40#include <asm/immap_qe.h>
41#include <asm/qe.h>
42#include <asm/ucc.h>
43#include <asm/ucc_fast.h>
44
45#include "ucc_geth.h"
46#include "ucc_geth_phy.h"
47
48#undef DEBUG
49
50#define DRV_DESC "QE UCC Gigabit Ethernet Controller version:June 20, 2006"
51#define DRV_NAME "ucc_geth"
52
53#define ugeth_printk(level, format, arg...) \
54 printk(level format "\n", ## arg)
55
56#define ugeth_dbg(format, arg...) \
57 ugeth_printk(KERN_DEBUG , format , ## arg)
58#define ugeth_err(format, arg...) \
59 ugeth_printk(KERN_ERR , format , ## arg)
60#define ugeth_info(format, arg...) \
61 ugeth_printk(KERN_INFO , format , ## arg)
62#define ugeth_warn(format, arg...) \
63 ugeth_printk(KERN_WARNING , format , ## arg)
64
65#ifdef UGETH_VERBOSE_DEBUG
66#define ugeth_vdbg ugeth_dbg
67#else
68#define ugeth_vdbg(fmt, args...) do { } while (0)
69#endif /* UGETH_VERBOSE_DEBUG */
70
71static DEFINE_SPINLOCK(ugeth_lock);
72
73static ucc_geth_info_t ugeth_primary_info = {
74 .uf_info = {
75 .bd_mem_part = MEM_PART_SYSTEM,
76 .rtsm = UCC_FAST_SEND_IDLES_BETWEEN_FRAMES,
77 .max_rx_buf_length = 1536,
78/* FIXME: should be changed in run time for 1G and 100M */
79#ifdef CONFIG_UGETH_HAS_GIGA
80 .urfs = UCC_GETH_URFS_GIGA_INIT,
81 .urfet = UCC_GETH_URFET_GIGA_INIT,
82 .urfset = UCC_GETH_URFSET_GIGA_INIT,
83 .utfs = UCC_GETH_UTFS_GIGA_INIT,
84 .utfet = UCC_GETH_UTFET_GIGA_INIT,
85 .utftt = UCC_GETH_UTFTT_GIGA_INIT,
86#else
87 .urfs = UCC_GETH_URFS_INIT,
88 .urfet = UCC_GETH_URFET_INIT,
89 .urfset = UCC_GETH_URFSET_INIT,
90 .utfs = UCC_GETH_UTFS_INIT,
91 .utfet = UCC_GETH_UTFET_INIT,
92 .utftt = UCC_GETH_UTFTT_INIT,
93#endif
94 .ufpt = 256,
95 .mode = UCC_FAST_PROTOCOL_MODE_ETHERNET,
96 .ttx_trx = UCC_FAST_GUMR_TRANSPARENT_TTX_TRX_NORMAL,
97 .tenc = UCC_FAST_TX_ENCODING_NRZ,
98 .renc = UCC_FAST_RX_ENCODING_NRZ,
99 .tcrc = UCC_FAST_16_BIT_CRC,
100 .synl = UCC_FAST_SYNC_LEN_NOT_USED,
101 },
102 .numQueuesTx = 1,
103 .numQueuesRx = 1,
104 .extendedFilteringChainPointer = ((uint32_t) NULL),
105 .typeorlen = 3072 /*1536 */ ,
106 .nonBackToBackIfgPart1 = 0x40,
107 .nonBackToBackIfgPart2 = 0x60,
108 .miminumInterFrameGapEnforcement = 0x50,
109 .backToBackInterFrameGap = 0x60,
110 .mblinterval = 128,
111 .nortsrbytetime = 5,
112 .fracsiz = 1,
113 .strictpriorityq = 0xff,
114 .altBebTruncation = 0xa,
115 .excessDefer = 1,
116 .maxRetransmission = 0xf,
117 .collisionWindow = 0x37,
118 .receiveFlowControl = 1,
119 .maxGroupAddrInHash = 4,
120 .maxIndAddrInHash = 4,
121 .prel = 7,
122 .maxFrameLength = 1518,
123 .minFrameLength = 64,
124 .maxD1Length = 1520,
125 .maxD2Length = 1520,
126 .vlantype = 0x8100,
127 .ecamptr = ((uint32_t) NULL),
128 .eventRegMask = UCCE_OTHER,
129 .pausePeriod = 0xf000,
130 .interruptcoalescingmaxvalue = {1, 1, 1, 1, 1, 1, 1, 1},
131 .bdRingLenTx = {
132 TX_BD_RING_LEN,
133 TX_BD_RING_LEN,
134 TX_BD_RING_LEN,
135 TX_BD_RING_LEN,
136 TX_BD_RING_LEN,
137 TX_BD_RING_LEN,
138 TX_BD_RING_LEN,
139 TX_BD_RING_LEN},
140
141 .bdRingLenRx = {
142 RX_BD_RING_LEN,
143 RX_BD_RING_LEN,
144 RX_BD_RING_LEN,
145 RX_BD_RING_LEN,
146 RX_BD_RING_LEN,
147 RX_BD_RING_LEN,
148 RX_BD_RING_LEN,
149 RX_BD_RING_LEN},
150
151 .numStationAddresses = UCC_GETH_NUM_OF_STATION_ADDRESSES_1,
152 .largestexternallookupkeysize =
153 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE,
154 .statisticsMode = UCC_GETH_STATISTICS_GATHERING_MODE_NONE,
155 .vlanOperationTagged = UCC_GETH_VLAN_OPERATION_TAGGED_NOP,
156 .vlanOperationNonTagged = UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP,
157 .rxQoSMode = UCC_GETH_QOS_MODE_DEFAULT,
158 .aufc = UPSMR_AUTOMATIC_FLOW_CONTROL_MODE_NONE,
159 .padAndCrc = MACCFG2_PAD_AND_CRC_MODE_PAD_AND_CRC,
160 .numThreadsTx = UCC_GETH_NUM_OF_THREADS_4,
161 .numThreadsRx = UCC_GETH_NUM_OF_THREADS_4,
162 .riscTx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
163 .riscRx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
164};
165
166static ucc_geth_info_t ugeth_info[8];
167
168#ifdef DEBUG
169static void mem_disp(u8 *addr, int size)
170{
171 u8 *i;
172 int size16Aling = (size >> 4) << 4;
173 int size4Aling = (size >> 2) << 2;
174 int notAlign = 0;
175 if (size % 16)
176 notAlign = 1;
177
178 for (i = addr; (u32) i < (u32) addr + size16Aling; i += 16)
179 printk("0x%08x: %08x %08x %08x %08x\r\n",
180 (u32) i,
181 *((u32 *) (i)),
182 *((u32 *) (i + 4)),
183 *((u32 *) (i + 8)), *((u32 *) (i + 12)));
184 if (notAlign == 1)
185 printk("0x%08x: ", (u32) i);
186 for (; (u32) i < (u32) addr + size4Aling; i += 4)
187 printk("%08x ", *((u32 *) (i)));
188 for (; (u32) i < (u32) addr + size; i++)
189 printk("%02x", *((u8 *) (i)));
190 if (notAlign == 1)
191 printk("\r\n");
192}
193#endif /* DEBUG */
194
195#ifdef CONFIG_UGETH_FILTERING
196static void enqueue(struct list_head *node, struct list_head *lh)
197{
198 unsigned long flags;
199
200 spin_lock_irqsave(ugeth_lock, flags);
201 list_add_tail(node, lh);
202 spin_unlock_irqrestore(ugeth_lock, flags);
203}
204#endif /* CONFIG_UGETH_FILTERING */
205
206static struct list_head *dequeue(struct list_head *lh)
207{
208 unsigned long flags;
209
210 spin_lock_irqsave(ugeth_lock, flags);
211 if (!list_empty(lh)) {
212 struct list_head *node = lh->next;
213 list_del(node);
214 spin_unlock_irqrestore(ugeth_lock, flags);
215 return node;
216 } else {
217 spin_unlock_irqrestore(ugeth_lock, flags);
218 return NULL;
219 }
220}
221
222static int get_interface_details(enet_interface_e enet_interface,
223 enet_speed_e *speed,
224 int *r10m,
225 int *rmm,
226 int *rpm,
227 int *tbi, int *limited_to_full_duplex)
228{
229 /* Analyze enet_interface according to Interface Mode
230 Configuration table */
231 switch (enet_interface) {
232 case ENET_10_MII:
233 *speed = ENET_SPEED_10BT;
234 break;
235 case ENET_10_RMII:
236 *speed = ENET_SPEED_10BT;
237 *r10m = 1;
238 *rmm = 1;
239 break;
240 case ENET_10_RGMII:
241 *speed = ENET_SPEED_10BT;
242 *rpm = 1;
243 *r10m = 1;
244 *limited_to_full_duplex = 1;
245 break;
246 case ENET_100_MII:
247 *speed = ENET_SPEED_100BT;
248 break;
249 case ENET_100_RMII:
250 *speed = ENET_SPEED_100BT;
251 *rmm = 1;
252 break;
253 case ENET_100_RGMII:
254 *speed = ENET_SPEED_100BT;
255 *rpm = 1;
256 *limited_to_full_duplex = 1;
257 break;
258 case ENET_1000_GMII:
259 *speed = ENET_SPEED_1000BT;
260 *limited_to_full_duplex = 1;
261 break;
262 case ENET_1000_RGMII:
263 *speed = ENET_SPEED_1000BT;
264 *rpm = 1;
265 *limited_to_full_duplex = 1;
266 break;
267 case ENET_1000_TBI:
268 *speed = ENET_SPEED_1000BT;
269 *tbi = 1;
270 *limited_to_full_duplex = 1;
271 break;
272 case ENET_1000_RTBI:
273 *speed = ENET_SPEED_1000BT;
274 *rpm = 1;
275 *tbi = 1;
276 *limited_to_full_duplex = 1;
277 break;
278 default:
279 return -EINVAL;
280 break;
281 }
282
283 return 0;
284}
285
286static struct sk_buff *get_new_skb(ucc_geth_private_t *ugeth, u8 *bd)
287{
288 struct sk_buff *skb = NULL;
289
290 skb = dev_alloc_skb(ugeth->ug_info->uf_info.max_rx_buf_length +
291 UCC_GETH_RX_DATA_BUF_ALIGNMENT);
292
293 if (skb == NULL)
294 return NULL;
295
296 /* We need the data buffer to be aligned properly. We will reserve
297 * as many bytes as needed to align the data properly
298 */
299 skb_reserve(skb,
300 UCC_GETH_RX_DATA_BUF_ALIGNMENT -
301 (((unsigned)skb->data) & (UCC_GETH_RX_DATA_BUF_ALIGNMENT -
302 1)));
303
304 skb->dev = ugeth->dev;
305
306 BD_BUFFER_SET(bd,
307 dma_map_single(NULL,
308 skb->data,
309 ugeth->ug_info->uf_info.max_rx_buf_length +
310 UCC_GETH_RX_DATA_BUF_ALIGNMENT,
311 DMA_FROM_DEVICE));
312
313 BD_STATUS_AND_LENGTH_SET(bd,
314 (R_E | R_I |
315 (BD_STATUS_AND_LENGTH(bd) & R_W)));
316
317 return skb;
318}
319
320static int rx_bd_buffer_set(ucc_geth_private_t *ugeth, u8 rxQ)
321{
322 u8 *bd;
323 u32 bd_status;
324 struct sk_buff *skb;
325 int i;
326
327 bd = ugeth->p_rx_bd_ring[rxQ];
328 i = 0;
329
330 do {
331 bd_status = BD_STATUS_AND_LENGTH(bd);
332 skb = get_new_skb(ugeth, bd);
333
334 if (!skb) /* If can not allocate data buffer,
335 abort. Cleanup will be elsewhere */
336 return -ENOMEM;
337
338 ugeth->rx_skbuff[rxQ][i] = skb;
339
340 /* advance the BD pointer */
341 bd += UCC_GETH_SIZE_OF_BD;
342 i++;
343 } while (!(bd_status & R_W));
344
345 return 0;
346}
347
348static int fill_init_enet_entries(ucc_geth_private_t *ugeth,
349 volatile u32 *p_start,
350 u8 num_entries,
351 u32 thread_size,
352 u32 thread_alignment,
353 qe_risc_allocation_e risc,
354 int skip_page_for_first_entry)
355{
356 u32 init_enet_offset;
357 u8 i;
358 int snum;
359
360 for (i = 0; i < num_entries; i++) {
361 if ((snum = qe_get_snum()) < 0) {
362 ugeth_err("fill_init_enet_entries: Can not get SNUM.");
363 return snum;
364 }
365 if ((i == 0) && skip_page_for_first_entry)
366 /* First entry of Rx does not have page */
367 init_enet_offset = 0;
368 else {
369 init_enet_offset =
370 qe_muram_alloc(thread_size, thread_alignment);
371 if (IS_MURAM_ERR(init_enet_offset)) {
372 ugeth_err
373 ("fill_init_enet_entries: Can not allocate DPRAM memory.");
374 qe_put_snum((u8) snum);
375 return -ENOMEM;
376 }
377 }
378 *(p_start++) =
379 ((u8) snum << ENET_INIT_PARAM_SNUM_SHIFT) | init_enet_offset
380 | risc;
381 }
382
383 return 0;
384}
385
386static int return_init_enet_entries(ucc_geth_private_t *ugeth,
387 volatile u32 *p_start,
388 u8 num_entries,
389 qe_risc_allocation_e risc,
390 int skip_page_for_first_entry)
391{
392 u32 init_enet_offset;
393 u8 i;
394 int snum;
395
396 for (i = 0; i < num_entries; i++) {
397 /* Check that this entry was actually valid --
398 needed in case failed in allocations */
399 if ((*p_start & ENET_INIT_PARAM_RISC_MASK) == risc) {
400 snum =
401 (u32) (*p_start & ENET_INIT_PARAM_SNUM_MASK) >>
402 ENET_INIT_PARAM_SNUM_SHIFT;
403 qe_put_snum((u8) snum);
404 if (!((i == 0) && skip_page_for_first_entry)) {
405 /* First entry of Rx does not have page */
406 init_enet_offset =
407 (in_be32(p_start) &
408 ENET_INIT_PARAM_PTR_MASK);
409 qe_muram_free(init_enet_offset);
410 }
411 *(p_start++) = 0; /* Just for cosmetics */
412 }
413 }
414
415 return 0;
416}
417
418#ifdef DEBUG
419static int dump_init_enet_entries(ucc_geth_private_t *ugeth,
420 volatile u32 *p_start,
421 u8 num_entries,
422 u32 thread_size,
423 qe_risc_allocation_e risc,
424 int skip_page_for_first_entry)
425{
426 u32 init_enet_offset;
427 u8 i;
428 int snum;
429
430 for (i = 0; i < num_entries; i++) {
431 /* Check that this entry was actually valid --
432 needed in case failed in allocations */
433 if ((*p_start & ENET_INIT_PARAM_RISC_MASK) == risc) {
434 snum =
435 (u32) (*p_start & ENET_INIT_PARAM_SNUM_MASK) >>
436 ENET_INIT_PARAM_SNUM_SHIFT;
437 qe_put_snum((u8) snum);
438 if (!((i == 0) && skip_page_for_first_entry)) {
439 /* First entry of Rx does not have page */
440 init_enet_offset =
441 (in_be32(p_start) &
442 ENET_INIT_PARAM_PTR_MASK);
443 ugeth_info("Init enet entry %d:", i);
444 ugeth_info("Base address: 0x%08x",
445 (u32)
446 qe_muram_addr(init_enet_offset));
447 mem_disp(qe_muram_addr(init_enet_offset),
448 thread_size);
449 }
450 p_start++;
451 }
452 }
453
454 return 0;
455}
456#endif
457
458#ifdef CONFIG_UGETH_FILTERING
459static enet_addr_container_t *get_enet_addr_container(void)
460{
461 enet_addr_container_t *enet_addr_cont;
462
463 /* allocate memory */
464 enet_addr_cont = kmalloc(sizeof(enet_addr_container_t), GFP_KERNEL);
465 if (!enet_addr_cont) {
466 ugeth_err("%s: No memory for enet_addr_container_t object.",
467 __FUNCTION__);
468 return NULL;
469 }
470
471 return enet_addr_cont;
472}
473#endif /* CONFIG_UGETH_FILTERING */
474
475static void put_enet_addr_container(enet_addr_container_t *enet_addr_cont)
476{
477 kfree(enet_addr_cont);
478}
479
480#ifdef CONFIG_UGETH_FILTERING
481static int hw_add_addr_in_paddr(ucc_geth_private_t *ugeth,
482 enet_addr_t *p_enet_addr, u8 paddr_num)
483{
484 ucc_geth_82xx_address_filtering_pram_t *p_82xx_addr_filt;
485
486 if (!(paddr_num < NUM_OF_PADDRS)) {
487 ugeth_warn("%s: Illagel paddr_num.", __FUNCTION__);
488 return -EINVAL;
489 }
490
491 p_82xx_addr_filt =
492 (ucc_geth_82xx_address_filtering_pram_t *) ugeth->p_rx_glbl_pram->
493 addressfiltering;
494
495 /* Ethernet frames are defined in Little Endian mode, */
496 /* therefore to insert the address we reverse the bytes. */
497 out_be16(&p_82xx_addr_filt->paddr[paddr_num].h,
498 (u16) (((u16) (((u16) ((*p_enet_addr)[5])) << 8)) |
499 (u16) (*p_enet_addr)[4]));
500 out_be16(&p_82xx_addr_filt->paddr[paddr_num].m,
501 (u16) (((u16) (((u16) ((*p_enet_addr)[3])) << 8)) |
502 (u16) (*p_enet_addr)[2]));
503 out_be16(&p_82xx_addr_filt->paddr[paddr_num].l,
504 (u16) (((u16) (((u16) ((*p_enet_addr)[1])) << 8)) |
505 (u16) (*p_enet_addr)[0]));
506
507 return 0;
508}
509#endif /* CONFIG_UGETH_FILTERING */
510
511static int hw_clear_addr_in_paddr(ucc_geth_private_t *ugeth, u8 paddr_num)
512{
513 ucc_geth_82xx_address_filtering_pram_t *p_82xx_addr_filt;
514
515 if (!(paddr_num < NUM_OF_PADDRS)) {
516 ugeth_warn("%s: Illagel paddr_num.", __FUNCTION__);
517 return -EINVAL;
518 }
519
520 p_82xx_addr_filt =
521 (ucc_geth_82xx_address_filtering_pram_t *) ugeth->p_rx_glbl_pram->
522 addressfiltering;
523
524 /* Writing address ff.ff.ff.ff.ff.ff disables address
525 recognition for this register */
526 out_be16(&p_82xx_addr_filt->paddr[paddr_num].h, 0xffff);
527 out_be16(&p_82xx_addr_filt->paddr[paddr_num].m, 0xffff);
528 out_be16(&p_82xx_addr_filt->paddr[paddr_num].l, 0xffff);
529
530 return 0;
531}
532
533static void hw_add_addr_in_hash(ucc_geth_private_t *ugeth,
534 enet_addr_t *p_enet_addr)
535{
536 ucc_geth_82xx_address_filtering_pram_t *p_82xx_addr_filt;
537 u32 cecr_subblock;
538
539 p_82xx_addr_filt =
540 (ucc_geth_82xx_address_filtering_pram_t *) ugeth->p_rx_glbl_pram->
541 addressfiltering;
542
543 cecr_subblock =
544 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
545
546 /* Ethernet frames are defined in Little Endian mode,
547 therefor to insert */
548 /* the address to the hash (Big Endian mode), we reverse the bytes.*/
549 out_be16(&p_82xx_addr_filt->taddr.h,
550 (u16) (((u16) (((u16) ((*p_enet_addr)[5])) << 8)) |
551 (u16) (*p_enet_addr)[4]));
552 out_be16(&p_82xx_addr_filt->taddr.m,
553 (u16) (((u16) (((u16) ((*p_enet_addr)[3])) << 8)) |
554 (u16) (*p_enet_addr)[2]));
555 out_be16(&p_82xx_addr_filt->taddr.l,
556 (u16) (((u16) (((u16) ((*p_enet_addr)[1])) << 8)) |
557 (u16) (*p_enet_addr)[0]));
558
559 qe_issue_cmd(QE_SET_GROUP_ADDRESS, cecr_subblock,
560 (u8) QE_CR_PROTOCOL_ETHERNET, 0);
561}
562
563#ifdef CONFIG_UGETH_MAGIC_PACKET
564static void magic_packet_detection_enable(ucc_geth_private_t *ugeth)
565{
566 ucc_fast_private_t *uccf;
567 ucc_geth_t *ug_regs;
568 u32 maccfg2, uccm;
569
570 uccf = ugeth->uccf;
571 ug_regs = ugeth->ug_regs;
572
573 /* Enable interrupts for magic packet detection */
574 uccm = in_be32(uccf->p_uccm);
575 uccm |= UCCE_MPD;
576 out_be32(uccf->p_uccm, uccm);
577
578 /* Enable magic packet detection */
579 maccfg2 = in_be32(&ug_regs->maccfg2);
580 maccfg2 |= MACCFG2_MPE;
581 out_be32(&ug_regs->maccfg2, maccfg2);
582}
583
584static void magic_packet_detection_disable(ucc_geth_private_t *ugeth)
585{
586 ucc_fast_private_t *uccf;
587 ucc_geth_t *ug_regs;
588 u32 maccfg2, uccm;
589
590 uccf = ugeth->uccf;
591 ug_regs = ugeth->ug_regs;
592
593 /* Disable interrupts for magic packet detection */
594 uccm = in_be32(uccf->p_uccm);
595 uccm &= ~UCCE_MPD;
596 out_be32(uccf->p_uccm, uccm);
597
598 /* Disable magic packet detection */
599 maccfg2 = in_be32(&ug_regs->maccfg2);
600 maccfg2 &= ~MACCFG2_MPE;
601 out_be32(&ug_regs->maccfg2, maccfg2);
602}
603#endif /* MAGIC_PACKET */
604
605static inline int compare_addr(enet_addr_t *addr1, enet_addr_t *addr2)
606{
607 return memcmp(addr1, addr2, ENET_NUM_OCTETS_PER_ADDRESS);
608}
609
610#ifdef DEBUG
611static void get_statistics(ucc_geth_private_t *ugeth,
612 ucc_geth_tx_firmware_statistics_t *
613 tx_firmware_statistics,
614 ucc_geth_rx_firmware_statistics_t *
615 rx_firmware_statistics,
616 ucc_geth_hardware_statistics_t *hardware_statistics)
617{
618 ucc_fast_t *uf_regs;
619 ucc_geth_t *ug_regs;
620 ucc_geth_tx_firmware_statistics_pram_t *p_tx_fw_statistics_pram;
621 ucc_geth_rx_firmware_statistics_pram_t *p_rx_fw_statistics_pram;
622
623 ug_regs = ugeth->ug_regs;
624 uf_regs = (ucc_fast_t *) ug_regs;
625 p_tx_fw_statistics_pram = ugeth->p_tx_fw_statistics_pram;
626 p_rx_fw_statistics_pram = ugeth->p_rx_fw_statistics_pram;
627
628 /* Tx firmware only if user handed pointer and driver actually
629 gathers Tx firmware statistics */
630 if (tx_firmware_statistics && p_tx_fw_statistics_pram) {
631 tx_firmware_statistics->sicoltx =
632 in_be32(&p_tx_fw_statistics_pram->sicoltx);
633 tx_firmware_statistics->mulcoltx =
634 in_be32(&p_tx_fw_statistics_pram->mulcoltx);
635 tx_firmware_statistics->latecoltxfr =
636 in_be32(&p_tx_fw_statistics_pram->latecoltxfr);
637 tx_firmware_statistics->frabortduecol =
638 in_be32(&p_tx_fw_statistics_pram->frabortduecol);
639 tx_firmware_statistics->frlostinmactxer =
640 in_be32(&p_tx_fw_statistics_pram->frlostinmactxer);
641 tx_firmware_statistics->carriersenseertx =
642 in_be32(&p_tx_fw_statistics_pram->carriersenseertx);
643 tx_firmware_statistics->frtxok =
644 in_be32(&p_tx_fw_statistics_pram->frtxok);
645 tx_firmware_statistics->txfrexcessivedefer =
646 in_be32(&p_tx_fw_statistics_pram->txfrexcessivedefer);
647 tx_firmware_statistics->txpkts256 =
648 in_be32(&p_tx_fw_statistics_pram->txpkts256);
649 tx_firmware_statistics->txpkts512 =
650 in_be32(&p_tx_fw_statistics_pram->txpkts512);
651 tx_firmware_statistics->txpkts1024 =
652 in_be32(&p_tx_fw_statistics_pram->txpkts1024);
653 tx_firmware_statistics->txpktsjumbo =
654 in_be32(&p_tx_fw_statistics_pram->txpktsjumbo);
655 }
656
657 /* Rx firmware only if user handed pointer and driver actually
658 * gathers Rx firmware statistics */
659 if (rx_firmware_statistics && p_rx_fw_statistics_pram) {
660 int i;
661 rx_firmware_statistics->frrxfcser =
662 in_be32(&p_rx_fw_statistics_pram->frrxfcser);
663 rx_firmware_statistics->fraligner =
664 in_be32(&p_rx_fw_statistics_pram->fraligner);
665 rx_firmware_statistics->inrangelenrxer =
666 in_be32(&p_rx_fw_statistics_pram->inrangelenrxer);
667 rx_firmware_statistics->outrangelenrxer =
668 in_be32(&p_rx_fw_statistics_pram->outrangelenrxer);
669 rx_firmware_statistics->frtoolong =
670 in_be32(&p_rx_fw_statistics_pram->frtoolong);
671 rx_firmware_statistics->runt =
672 in_be32(&p_rx_fw_statistics_pram->runt);
673 rx_firmware_statistics->verylongevent =
674 in_be32(&p_rx_fw_statistics_pram->verylongevent);
675 rx_firmware_statistics->symbolerror =
676 in_be32(&p_rx_fw_statistics_pram->symbolerror);
677 rx_firmware_statistics->dropbsy =
678 in_be32(&p_rx_fw_statistics_pram->dropbsy);
679 for (i = 0; i < 0x8; i++)
680 rx_firmware_statistics->res0[i] =
681 p_rx_fw_statistics_pram->res0[i];
682 rx_firmware_statistics->mismatchdrop =
683 in_be32(&p_rx_fw_statistics_pram->mismatchdrop);
684 rx_firmware_statistics->underpkts =
685 in_be32(&p_rx_fw_statistics_pram->underpkts);
686 rx_firmware_statistics->pkts256 =
687 in_be32(&p_rx_fw_statistics_pram->pkts256);
688 rx_firmware_statistics->pkts512 =
689 in_be32(&p_rx_fw_statistics_pram->pkts512);
690 rx_firmware_statistics->pkts1024 =
691 in_be32(&p_rx_fw_statistics_pram->pkts1024);
692 rx_firmware_statistics->pktsjumbo =
693 in_be32(&p_rx_fw_statistics_pram->pktsjumbo);
694 rx_firmware_statistics->frlossinmacer =
695 in_be32(&p_rx_fw_statistics_pram->frlossinmacer);
696 rx_firmware_statistics->pausefr =
697 in_be32(&p_rx_fw_statistics_pram->pausefr);
698 for (i = 0; i < 0x4; i++)
699 rx_firmware_statistics->res1[i] =
700 p_rx_fw_statistics_pram->res1[i];
701 rx_firmware_statistics->removevlan =
702 in_be32(&p_rx_fw_statistics_pram->removevlan);
703 rx_firmware_statistics->replacevlan =
704 in_be32(&p_rx_fw_statistics_pram->replacevlan);
705 rx_firmware_statistics->insertvlan =
706 in_be32(&p_rx_fw_statistics_pram->insertvlan);
707 }
708
709 /* Hardware only if user handed pointer and driver actually
710 gathers hardware statistics */
711 if (hardware_statistics && (in_be32(&uf_regs->upsmr) & UPSMR_HSE)) {
712 hardware_statistics->tx64 = in_be32(&ug_regs->tx64);
713 hardware_statistics->tx127 = in_be32(&ug_regs->tx127);
714 hardware_statistics->tx255 = in_be32(&ug_regs->tx255);
715 hardware_statistics->rx64 = in_be32(&ug_regs->rx64);
716 hardware_statistics->rx127 = in_be32(&ug_regs->rx127);
717 hardware_statistics->rx255 = in_be32(&ug_regs->rx255);
718 hardware_statistics->txok = in_be32(&ug_regs->txok);
719 hardware_statistics->txcf = in_be16(&ug_regs->txcf);
720 hardware_statistics->tmca = in_be32(&ug_regs->tmca);
721 hardware_statistics->tbca = in_be32(&ug_regs->tbca);
722 hardware_statistics->rxfok = in_be32(&ug_regs->rxfok);
723 hardware_statistics->rxbok = in_be32(&ug_regs->rxbok);
724 hardware_statistics->rbyt = in_be32(&ug_regs->rbyt);
725 hardware_statistics->rmca = in_be32(&ug_regs->rmca);
726 hardware_statistics->rbca = in_be32(&ug_regs->rbca);
727 }
728}
729
730static void dump_bds(ucc_geth_private_t *ugeth)
731{
732 int i;
733 int length;
734
735 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
736 if (ugeth->p_tx_bd_ring[i]) {
737 length =
738 (ugeth->ug_info->bdRingLenTx[i] *
739 UCC_GETH_SIZE_OF_BD);
740 ugeth_info("TX BDs[%d]", i);
741 mem_disp(ugeth->p_tx_bd_ring[i], length);
742 }
743 }
744 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
745 if (ugeth->p_rx_bd_ring[i]) {
746 length =
747 (ugeth->ug_info->bdRingLenRx[i] *
748 UCC_GETH_SIZE_OF_BD);
749 ugeth_info("RX BDs[%d]", i);
750 mem_disp(ugeth->p_rx_bd_ring[i], length);
751 }
752 }
753}
754
755static void dump_regs(ucc_geth_private_t *ugeth)
756{
757 int i;
758
759 ugeth_info("UCC%d Geth registers:", ugeth->ug_info->uf_info.ucc_num);
760 ugeth_info("Base address: 0x%08x", (u32) ugeth->ug_regs);
761
762 ugeth_info("maccfg1 : addr - 0x%08x, val - 0x%08x",
763 (u32) & ugeth->ug_regs->maccfg1,
764 in_be32(&ugeth->ug_regs->maccfg1));
765 ugeth_info("maccfg2 : addr - 0x%08x, val - 0x%08x",
766 (u32) & ugeth->ug_regs->maccfg2,
767 in_be32(&ugeth->ug_regs->maccfg2));
768 ugeth_info("ipgifg : addr - 0x%08x, val - 0x%08x",
769 (u32) & ugeth->ug_regs->ipgifg,
770 in_be32(&ugeth->ug_regs->ipgifg));
771 ugeth_info("hafdup : addr - 0x%08x, val - 0x%08x",
772 (u32) & ugeth->ug_regs->hafdup,
773 in_be32(&ugeth->ug_regs->hafdup));
774 ugeth_info("miimcfg : addr - 0x%08x, val - 0x%08x",
775 (u32) & ugeth->ug_regs->miimng.miimcfg,
776 in_be32(&ugeth->ug_regs->miimng.miimcfg));
777 ugeth_info("miimcom : addr - 0x%08x, val - 0x%08x",
778 (u32) & ugeth->ug_regs->miimng.miimcom,
779 in_be32(&ugeth->ug_regs->miimng.miimcom));
780 ugeth_info("miimadd : addr - 0x%08x, val - 0x%08x",
781 (u32) & ugeth->ug_regs->miimng.miimadd,
782 in_be32(&ugeth->ug_regs->miimng.miimadd));
783 ugeth_info("miimcon : addr - 0x%08x, val - 0x%08x",
784 (u32) & ugeth->ug_regs->miimng.miimcon,
785 in_be32(&ugeth->ug_regs->miimng.miimcon));
786 ugeth_info("miimstat : addr - 0x%08x, val - 0x%08x",
787 (u32) & ugeth->ug_regs->miimng.miimstat,
788 in_be32(&ugeth->ug_regs->miimng.miimstat));
789 ugeth_info("miimmind : addr - 0x%08x, val - 0x%08x",
790 (u32) & ugeth->ug_regs->miimng.miimind,
791 in_be32(&ugeth->ug_regs->miimng.miimind));
792 ugeth_info("ifctl : addr - 0x%08x, val - 0x%08x",
793 (u32) & ugeth->ug_regs->ifctl,
794 in_be32(&ugeth->ug_regs->ifctl));
795 ugeth_info("ifstat : addr - 0x%08x, val - 0x%08x",
796 (u32) & ugeth->ug_regs->ifstat,
797 in_be32(&ugeth->ug_regs->ifstat));
798 ugeth_info("macstnaddr1: addr - 0x%08x, val - 0x%08x",
799 (u32) & ugeth->ug_regs->macstnaddr1,
800 in_be32(&ugeth->ug_regs->macstnaddr1));
801 ugeth_info("macstnaddr2: addr - 0x%08x, val - 0x%08x",
802 (u32) & ugeth->ug_regs->macstnaddr2,
803 in_be32(&ugeth->ug_regs->macstnaddr2));
804 ugeth_info("uempr : addr - 0x%08x, val - 0x%08x",
805 (u32) & ugeth->ug_regs->uempr,
806 in_be32(&ugeth->ug_regs->uempr));
807 ugeth_info("utbipar : addr - 0x%08x, val - 0x%08x",
808 (u32) & ugeth->ug_regs->utbipar,
809 in_be32(&ugeth->ug_regs->utbipar));
810 ugeth_info("uescr : addr - 0x%08x, val - 0x%04x",
811 (u32) & ugeth->ug_regs->uescr,
812 in_be16(&ugeth->ug_regs->uescr));
813 ugeth_info("tx64 : addr - 0x%08x, val - 0x%08x",
814 (u32) & ugeth->ug_regs->tx64,
815 in_be32(&ugeth->ug_regs->tx64));
816 ugeth_info("tx127 : addr - 0x%08x, val - 0x%08x",
817 (u32) & ugeth->ug_regs->tx127,
818 in_be32(&ugeth->ug_regs->tx127));
819 ugeth_info("tx255 : addr - 0x%08x, val - 0x%08x",
820 (u32) & ugeth->ug_regs->tx255,
821 in_be32(&ugeth->ug_regs->tx255));
822 ugeth_info("rx64 : addr - 0x%08x, val - 0x%08x",
823 (u32) & ugeth->ug_regs->rx64,
824 in_be32(&ugeth->ug_regs->rx64));
825 ugeth_info("rx127 : addr - 0x%08x, val - 0x%08x",
826 (u32) & ugeth->ug_regs->rx127,
827 in_be32(&ugeth->ug_regs->rx127));
828 ugeth_info("rx255 : addr - 0x%08x, val - 0x%08x",
829 (u32) & ugeth->ug_regs->rx255,
830 in_be32(&ugeth->ug_regs->rx255));
831 ugeth_info("txok : addr - 0x%08x, val - 0x%08x",
832 (u32) & ugeth->ug_regs->txok,
833 in_be32(&ugeth->ug_regs->txok));
834 ugeth_info("txcf : addr - 0x%08x, val - 0x%04x",
835 (u32) & ugeth->ug_regs->txcf,
836 in_be16(&ugeth->ug_regs->txcf));
837 ugeth_info("tmca : addr - 0x%08x, val - 0x%08x",
838 (u32) & ugeth->ug_regs->tmca,
839 in_be32(&ugeth->ug_regs->tmca));
840 ugeth_info("tbca : addr - 0x%08x, val - 0x%08x",
841 (u32) & ugeth->ug_regs->tbca,
842 in_be32(&ugeth->ug_regs->tbca));
843 ugeth_info("rxfok : addr - 0x%08x, val - 0x%08x",
844 (u32) & ugeth->ug_regs->rxfok,
845 in_be32(&ugeth->ug_regs->rxfok));
846 ugeth_info("rxbok : addr - 0x%08x, val - 0x%08x",
847 (u32) & ugeth->ug_regs->rxbok,
848 in_be32(&ugeth->ug_regs->rxbok));
849 ugeth_info("rbyt : addr - 0x%08x, val - 0x%08x",
850 (u32) & ugeth->ug_regs->rbyt,
851 in_be32(&ugeth->ug_regs->rbyt));
852 ugeth_info("rmca : addr - 0x%08x, val - 0x%08x",
853 (u32) & ugeth->ug_regs->rmca,
854 in_be32(&ugeth->ug_regs->rmca));
855 ugeth_info("rbca : addr - 0x%08x, val - 0x%08x",
856 (u32) & ugeth->ug_regs->rbca,
857 in_be32(&ugeth->ug_regs->rbca));
858 ugeth_info("scar : addr - 0x%08x, val - 0x%08x",
859 (u32) & ugeth->ug_regs->scar,
860 in_be32(&ugeth->ug_regs->scar));
861 ugeth_info("scam : addr - 0x%08x, val - 0x%08x",
862 (u32) & ugeth->ug_regs->scam,
863 in_be32(&ugeth->ug_regs->scam));
864
865 if (ugeth->p_thread_data_tx) {
866 int numThreadsTxNumerical;
867 switch (ugeth->ug_info->numThreadsTx) {
868 case UCC_GETH_NUM_OF_THREADS_1:
869 numThreadsTxNumerical = 1;
870 break;
871 case UCC_GETH_NUM_OF_THREADS_2:
872 numThreadsTxNumerical = 2;
873 break;
874 case UCC_GETH_NUM_OF_THREADS_4:
875 numThreadsTxNumerical = 4;
876 break;
877 case UCC_GETH_NUM_OF_THREADS_6:
878 numThreadsTxNumerical = 6;
879 break;
880 case UCC_GETH_NUM_OF_THREADS_8:
881 numThreadsTxNumerical = 8;
882 break;
883 default:
884 numThreadsTxNumerical = 0;
885 break;
886 }
887
888 ugeth_info("Thread data TXs:");
889 ugeth_info("Base address: 0x%08x",
890 (u32) ugeth->p_thread_data_tx);
891 for (i = 0; i < numThreadsTxNumerical; i++) {
892 ugeth_info("Thread data TX[%d]:", i);
893 ugeth_info("Base address: 0x%08x",
894 (u32) & ugeth->p_thread_data_tx[i]);
895 mem_disp((u8 *) & ugeth->p_thread_data_tx[i],
896 sizeof(ucc_geth_thread_data_tx_t));
897 }
898 }
899 if (ugeth->p_thread_data_rx) {
900 int numThreadsRxNumerical;
901 switch (ugeth->ug_info->numThreadsRx) {
902 case UCC_GETH_NUM_OF_THREADS_1:
903 numThreadsRxNumerical = 1;
904 break;
905 case UCC_GETH_NUM_OF_THREADS_2:
906 numThreadsRxNumerical = 2;
907 break;
908 case UCC_GETH_NUM_OF_THREADS_4:
909 numThreadsRxNumerical = 4;
910 break;
911 case UCC_GETH_NUM_OF_THREADS_6:
912 numThreadsRxNumerical = 6;
913 break;
914 case UCC_GETH_NUM_OF_THREADS_8:
915 numThreadsRxNumerical = 8;
916 break;
917 default:
918 numThreadsRxNumerical = 0;
919 break;
920 }
921
922 ugeth_info("Thread data RX:");
923 ugeth_info("Base address: 0x%08x",
924 (u32) ugeth->p_thread_data_rx);
925 for (i = 0; i < numThreadsRxNumerical; i++) {
926 ugeth_info("Thread data RX[%d]:", i);
927 ugeth_info("Base address: 0x%08x",
928 (u32) & ugeth->p_thread_data_rx[i]);
929 mem_disp((u8 *) & ugeth->p_thread_data_rx[i],
930 sizeof(ucc_geth_thread_data_rx_t));
931 }
932 }
933 if (ugeth->p_exf_glbl_param) {
934 ugeth_info("EXF global param:");
935 ugeth_info("Base address: 0x%08x",
936 (u32) ugeth->p_exf_glbl_param);
937 mem_disp((u8 *) ugeth->p_exf_glbl_param,
938 sizeof(*ugeth->p_exf_glbl_param));
939 }
940 if (ugeth->p_tx_glbl_pram) {
941 ugeth_info("TX global param:");
942 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_tx_glbl_pram);
943 ugeth_info("temoder : addr - 0x%08x, val - 0x%04x",
944 (u32) & ugeth->p_tx_glbl_pram->temoder,
945 in_be16(&ugeth->p_tx_glbl_pram->temoder));
946 ugeth_info("sqptr : addr - 0x%08x, val - 0x%08x",
947 (u32) & ugeth->p_tx_glbl_pram->sqptr,
948 in_be32(&ugeth->p_tx_glbl_pram->sqptr));
949 ugeth_info("schedulerbasepointer: addr - 0x%08x, val - 0x%08x",
950 (u32) & ugeth->p_tx_glbl_pram->schedulerbasepointer,
951 in_be32(&ugeth->p_tx_glbl_pram->
952 schedulerbasepointer));
953 ugeth_info("txrmonbaseptr: addr - 0x%08x, val - 0x%08x",
954 (u32) & ugeth->p_tx_glbl_pram->txrmonbaseptr,
955 in_be32(&ugeth->p_tx_glbl_pram->txrmonbaseptr));
956 ugeth_info("tstate : addr - 0x%08x, val - 0x%08x",
957 (u32) & ugeth->p_tx_glbl_pram->tstate,
958 in_be32(&ugeth->p_tx_glbl_pram->tstate));
959 ugeth_info("iphoffset[0] : addr - 0x%08x, val - 0x%02x",
960 (u32) & ugeth->p_tx_glbl_pram->iphoffset[0],
961 ugeth->p_tx_glbl_pram->iphoffset[0]);
962 ugeth_info("iphoffset[1] : addr - 0x%08x, val - 0x%02x",
963 (u32) & ugeth->p_tx_glbl_pram->iphoffset[1],
964 ugeth->p_tx_glbl_pram->iphoffset[1]);
965 ugeth_info("iphoffset[2] : addr - 0x%08x, val - 0x%02x",
966 (u32) & ugeth->p_tx_glbl_pram->iphoffset[2],
967 ugeth->p_tx_glbl_pram->iphoffset[2]);
968 ugeth_info("iphoffset[3] : addr - 0x%08x, val - 0x%02x",
969 (u32) & ugeth->p_tx_glbl_pram->iphoffset[3],
970 ugeth->p_tx_glbl_pram->iphoffset[3]);
971 ugeth_info("iphoffset[4] : addr - 0x%08x, val - 0x%02x",
972 (u32) & ugeth->p_tx_glbl_pram->iphoffset[4],
973 ugeth->p_tx_glbl_pram->iphoffset[4]);
974 ugeth_info("iphoffset[5] : addr - 0x%08x, val - 0x%02x",
975 (u32) & ugeth->p_tx_glbl_pram->iphoffset[5],
976 ugeth->p_tx_glbl_pram->iphoffset[5]);
977 ugeth_info("iphoffset[6] : addr - 0x%08x, val - 0x%02x",
978 (u32) & ugeth->p_tx_glbl_pram->iphoffset[6],
979 ugeth->p_tx_glbl_pram->iphoffset[6]);
980 ugeth_info("iphoffset[7] : addr - 0x%08x, val - 0x%02x",
981 (u32) & ugeth->p_tx_glbl_pram->iphoffset[7],
982 ugeth->p_tx_glbl_pram->iphoffset[7]);
983 ugeth_info("vtagtable[0] : addr - 0x%08x, val - 0x%08x",
984 (u32) & ugeth->p_tx_glbl_pram->vtagtable[0],
985 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[0]));
986 ugeth_info("vtagtable[1] : addr - 0x%08x, val - 0x%08x",
987 (u32) & ugeth->p_tx_glbl_pram->vtagtable[1],
988 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[1]));
989 ugeth_info("vtagtable[2] : addr - 0x%08x, val - 0x%08x",
990 (u32) & ugeth->p_tx_glbl_pram->vtagtable[2],
991 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[2]));
992 ugeth_info("vtagtable[3] : addr - 0x%08x, val - 0x%08x",
993 (u32) & ugeth->p_tx_glbl_pram->vtagtable[3],
994 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[3]));
995 ugeth_info("vtagtable[4] : addr - 0x%08x, val - 0x%08x",
996 (u32) & ugeth->p_tx_glbl_pram->vtagtable[4],
997 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[4]));
998 ugeth_info("vtagtable[5] : addr - 0x%08x, val - 0x%08x",
999 (u32) & ugeth->p_tx_glbl_pram->vtagtable[5],
1000 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[5]));
1001 ugeth_info("vtagtable[6] : addr - 0x%08x, val - 0x%08x",
1002 (u32) & ugeth->p_tx_glbl_pram->vtagtable[6],
1003 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[6]));
1004 ugeth_info("vtagtable[7] : addr - 0x%08x, val - 0x%08x",
1005 (u32) & ugeth->p_tx_glbl_pram->vtagtable[7],
1006 in_be32(&ugeth->p_tx_glbl_pram->vtagtable[7]));
1007 ugeth_info("tqptr : addr - 0x%08x, val - 0x%08x",
1008 (u32) & ugeth->p_tx_glbl_pram->tqptr,
1009 in_be32(&ugeth->p_tx_glbl_pram->tqptr));
1010 }
1011 if (ugeth->p_rx_glbl_pram) {
1012 ugeth_info("RX global param:");
1013 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_glbl_pram);
1014 ugeth_info("remoder : addr - 0x%08x, val - 0x%08x",
1015 (u32) & ugeth->p_rx_glbl_pram->remoder,
1016 in_be32(&ugeth->p_rx_glbl_pram->remoder));
1017 ugeth_info("rqptr : addr - 0x%08x, val - 0x%08x",
1018 (u32) & ugeth->p_rx_glbl_pram->rqptr,
1019 in_be32(&ugeth->p_rx_glbl_pram->rqptr));
1020 ugeth_info("typeorlen : addr - 0x%08x, val - 0x%04x",
1021 (u32) & ugeth->p_rx_glbl_pram->typeorlen,
1022 in_be16(&ugeth->p_rx_glbl_pram->typeorlen));
1023 ugeth_info("rxgstpack : addr - 0x%08x, val - 0x%02x",
1024 (u32) & ugeth->p_rx_glbl_pram->rxgstpack,
1025 ugeth->p_rx_glbl_pram->rxgstpack);
1026 ugeth_info("rxrmonbaseptr : addr - 0x%08x, val - 0x%08x",
1027 (u32) & ugeth->p_rx_glbl_pram->rxrmonbaseptr,
1028 in_be32(&ugeth->p_rx_glbl_pram->rxrmonbaseptr));
1029 ugeth_info("intcoalescingptr: addr - 0x%08x, val - 0x%08x",
1030 (u32) & ugeth->p_rx_glbl_pram->intcoalescingptr,
1031 in_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr));
1032 ugeth_info("rstate : addr - 0x%08x, val - 0x%02x",
1033 (u32) & ugeth->p_rx_glbl_pram->rstate,
1034 ugeth->p_rx_glbl_pram->rstate);
1035 ugeth_info("mrblr : addr - 0x%08x, val - 0x%04x",
1036 (u32) & ugeth->p_rx_glbl_pram->mrblr,
1037 in_be16(&ugeth->p_rx_glbl_pram->mrblr));
1038 ugeth_info("rbdqptr : addr - 0x%08x, val - 0x%08x",
1039 (u32) & ugeth->p_rx_glbl_pram->rbdqptr,
1040 in_be32(&ugeth->p_rx_glbl_pram->rbdqptr));
1041 ugeth_info("mflr : addr - 0x%08x, val - 0x%04x",
1042 (u32) & ugeth->p_rx_glbl_pram->mflr,
1043 in_be16(&ugeth->p_rx_glbl_pram->mflr));
1044 ugeth_info("minflr : addr - 0x%08x, val - 0x%04x",
1045 (u32) & ugeth->p_rx_glbl_pram->minflr,
1046 in_be16(&ugeth->p_rx_glbl_pram->minflr));
1047 ugeth_info("maxd1 : addr - 0x%08x, val - 0x%04x",
1048 (u32) & ugeth->p_rx_glbl_pram->maxd1,
1049 in_be16(&ugeth->p_rx_glbl_pram->maxd1));
1050 ugeth_info("maxd2 : addr - 0x%08x, val - 0x%04x",
1051 (u32) & ugeth->p_rx_glbl_pram->maxd2,
1052 in_be16(&ugeth->p_rx_glbl_pram->maxd2));
1053 ugeth_info("ecamptr : addr - 0x%08x, val - 0x%08x",
1054 (u32) & ugeth->p_rx_glbl_pram->ecamptr,
1055 in_be32(&ugeth->p_rx_glbl_pram->ecamptr));
1056 ugeth_info("l2qt : addr - 0x%08x, val - 0x%08x",
1057 (u32) & ugeth->p_rx_glbl_pram->l2qt,
1058 in_be32(&ugeth->p_rx_glbl_pram->l2qt));
1059 ugeth_info("l3qt[0] : addr - 0x%08x, val - 0x%08x",
1060 (u32) & ugeth->p_rx_glbl_pram->l3qt[0],
1061 in_be32(&ugeth->p_rx_glbl_pram->l3qt[0]));
1062 ugeth_info("l3qt[1] : addr - 0x%08x, val - 0x%08x",
1063 (u32) & ugeth->p_rx_glbl_pram->l3qt[1],
1064 in_be32(&ugeth->p_rx_glbl_pram->l3qt[1]));
1065 ugeth_info("l3qt[2] : addr - 0x%08x, val - 0x%08x",
1066 (u32) & ugeth->p_rx_glbl_pram->l3qt[2],
1067 in_be32(&ugeth->p_rx_glbl_pram->l3qt[2]));
1068 ugeth_info("l3qt[3] : addr - 0x%08x, val - 0x%08x",
1069 (u32) & ugeth->p_rx_glbl_pram->l3qt[3],
1070 in_be32(&ugeth->p_rx_glbl_pram->l3qt[3]));
1071 ugeth_info("l3qt[4] : addr - 0x%08x, val - 0x%08x",
1072 (u32) & ugeth->p_rx_glbl_pram->l3qt[4],
1073 in_be32(&ugeth->p_rx_glbl_pram->l3qt[4]));
1074 ugeth_info("l3qt[5] : addr - 0x%08x, val - 0x%08x",
1075 (u32) & ugeth->p_rx_glbl_pram->l3qt[5],
1076 in_be32(&ugeth->p_rx_glbl_pram->l3qt[5]));
1077 ugeth_info("l3qt[6] : addr - 0x%08x, val - 0x%08x",
1078 (u32) & ugeth->p_rx_glbl_pram->l3qt[6],
1079 in_be32(&ugeth->p_rx_glbl_pram->l3qt[6]));
1080 ugeth_info("l3qt[7] : addr - 0x%08x, val - 0x%08x",
1081 (u32) & ugeth->p_rx_glbl_pram->l3qt[7],
1082 in_be32(&ugeth->p_rx_glbl_pram->l3qt[7]));
1083 ugeth_info("vlantype : addr - 0x%08x, val - 0x%04x",
1084 (u32) & ugeth->p_rx_glbl_pram->vlantype,
1085 in_be16(&ugeth->p_rx_glbl_pram->vlantype));
1086 ugeth_info("vlantci : addr - 0x%08x, val - 0x%04x",
1087 (u32) & ugeth->p_rx_glbl_pram->vlantci,
1088 in_be16(&ugeth->p_rx_glbl_pram->vlantci));
1089 for (i = 0; i < 64; i++)
1090 ugeth_info
1091 ("addressfiltering[%d]: addr - 0x%08x, val - 0x%02x",
1092 i,
1093 (u32) & ugeth->p_rx_glbl_pram->addressfiltering[i],
1094 ugeth->p_rx_glbl_pram->addressfiltering[i]);
1095 ugeth_info("exfGlobalParam : addr - 0x%08x, val - 0x%08x",
1096 (u32) & ugeth->p_rx_glbl_pram->exfGlobalParam,
1097 in_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam));
1098 }
1099 if (ugeth->p_send_q_mem_reg) {
1100 ugeth_info("Send Q memory registers:");
1101 ugeth_info("Base address: 0x%08x",
1102 (u32) ugeth->p_send_q_mem_reg);
1103 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
1104 ugeth_info("SQQD[%d]:", i);
1105 ugeth_info("Base address: 0x%08x",
1106 (u32) & ugeth->p_send_q_mem_reg->sqqd[i]);
1107 mem_disp((u8 *) & ugeth->p_send_q_mem_reg->sqqd[i],
1108 sizeof(ucc_geth_send_queue_qd_t));
1109 }
1110 }
1111 if (ugeth->p_scheduler) {
1112 ugeth_info("Scheduler:");
1113 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_scheduler);
1114 mem_disp((u8 *) ugeth->p_scheduler,
1115 sizeof(*ugeth->p_scheduler));
1116 }
1117 if (ugeth->p_tx_fw_statistics_pram) {
1118 ugeth_info("TX FW statistics pram:");
1119 ugeth_info("Base address: 0x%08x",
1120 (u32) ugeth->p_tx_fw_statistics_pram);
1121 mem_disp((u8 *) ugeth->p_tx_fw_statistics_pram,
1122 sizeof(*ugeth->p_tx_fw_statistics_pram));
1123 }
1124 if (ugeth->p_rx_fw_statistics_pram) {
1125 ugeth_info("RX FW statistics pram:");
1126 ugeth_info("Base address: 0x%08x",
1127 (u32) ugeth->p_rx_fw_statistics_pram);
1128 mem_disp((u8 *) ugeth->p_rx_fw_statistics_pram,
1129 sizeof(*ugeth->p_rx_fw_statistics_pram));
1130 }
1131 if (ugeth->p_rx_irq_coalescing_tbl) {
1132 ugeth_info("RX IRQ coalescing tables:");
1133 ugeth_info("Base address: 0x%08x",
1134 (u32) ugeth->p_rx_irq_coalescing_tbl);
1135 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
1136 ugeth_info("RX IRQ coalescing table entry[%d]:", i);
1137 ugeth_info("Base address: 0x%08x",
1138 (u32) & ugeth->p_rx_irq_coalescing_tbl->
1139 coalescingentry[i]);
1140 ugeth_info
1141 ("interruptcoalescingmaxvalue: addr - 0x%08x, val - 0x%08x",
1142 (u32) & ugeth->p_rx_irq_coalescing_tbl->
1143 coalescingentry[i].interruptcoalescingmaxvalue,
1144 in_be32(&ugeth->p_rx_irq_coalescing_tbl->
1145 coalescingentry[i].
1146 interruptcoalescingmaxvalue));
1147 ugeth_info
1148 ("interruptcoalescingcounter : addr - 0x%08x, val - 0x%08x",
1149 (u32) & ugeth->p_rx_irq_coalescing_tbl->
1150 coalescingentry[i].interruptcoalescingcounter,
1151 in_be32(&ugeth->p_rx_irq_coalescing_tbl->
1152 coalescingentry[i].
1153 interruptcoalescingcounter));
1154 }
1155 }
1156 if (ugeth->p_rx_bd_qs_tbl) {
1157 ugeth_info("RX BD QS tables:");
1158 ugeth_info("Base address: 0x%08x", (u32) ugeth->p_rx_bd_qs_tbl);
1159 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
1160 ugeth_info("RX BD QS table[%d]:", i);
1161 ugeth_info("Base address: 0x%08x",
1162 (u32) & ugeth->p_rx_bd_qs_tbl[i]);
1163 ugeth_info
1164 ("bdbaseptr : addr - 0x%08x, val - 0x%08x",
1165 (u32) & ugeth->p_rx_bd_qs_tbl[i].bdbaseptr,
1166 in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdbaseptr));
1167 ugeth_info
1168 ("bdptr : addr - 0x%08x, val - 0x%08x",
1169 (u32) & ugeth->p_rx_bd_qs_tbl[i].bdptr,
1170 in_be32(&ugeth->p_rx_bd_qs_tbl[i].bdptr));
1171 ugeth_info
1172 ("externalbdbaseptr: addr - 0x%08x, val - 0x%08x",
1173 (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
1174 in_be32(&ugeth->p_rx_bd_qs_tbl[i].
1175 externalbdbaseptr));
1176 ugeth_info
1177 ("externalbdptr : addr - 0x%08x, val - 0x%08x",
1178 (u32) & ugeth->p_rx_bd_qs_tbl[i].externalbdptr,
1179 in_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdptr));
1180 ugeth_info("ucode RX Prefetched BDs:");
1181 ugeth_info("Base address: 0x%08x",
1182 (u32)
1183 qe_muram_addr(in_be32
1184 (&ugeth->p_rx_bd_qs_tbl[i].
1185 bdbaseptr)));
1186 mem_disp((u8 *)
1187 qe_muram_addr(in_be32
1188 (&ugeth->p_rx_bd_qs_tbl[i].
1189 bdbaseptr)),
1190 sizeof(ucc_geth_rx_prefetched_bds_t));
1191 }
1192 }
1193 if (ugeth->p_init_enet_param_shadow) {
1194 int size;
1195 ugeth_info("Init enet param shadow:");
1196 ugeth_info("Base address: 0x%08x",
1197 (u32) ugeth->p_init_enet_param_shadow);
1198 mem_disp((u8 *) ugeth->p_init_enet_param_shadow,
1199 sizeof(*ugeth->p_init_enet_param_shadow));
1200
1201 size = sizeof(ucc_geth_thread_rx_pram_t);
1202 if (ugeth->ug_info->rxExtendedFiltering) {
1203 size +=
1204 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
1205 if (ugeth->ug_info->largestexternallookupkeysize ==
1206 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
1207 size +=
1208 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
1209 if (ugeth->ug_info->largestexternallookupkeysize ==
1210 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
1211 size +=
1212 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
1213 }
1214
1215 dump_init_enet_entries(ugeth,
1216 &(ugeth->p_init_enet_param_shadow->
1217 txthread[0]),
1218 ENET_INIT_PARAM_MAX_ENTRIES_TX,
1219 sizeof(ucc_geth_thread_tx_pram_t),
1220 ugeth->ug_info->riscTx, 0);
1221 dump_init_enet_entries(ugeth,
1222 &(ugeth->p_init_enet_param_shadow->
1223 rxthread[0]),
1224 ENET_INIT_PARAM_MAX_ENTRIES_RX, size,
1225 ugeth->ug_info->riscRx, 1);
1226 }
1227}
1228#endif /* DEBUG */
1229
1230static void init_default_reg_vals(volatile u32 *upsmr_register,
1231 volatile u32 *maccfg1_register,
1232 volatile u32 *maccfg2_register)
1233{
1234 out_be32(upsmr_register, UCC_GETH_UPSMR_INIT);
1235 out_be32(maccfg1_register, UCC_GETH_MACCFG1_INIT);
1236 out_be32(maccfg2_register, UCC_GETH_MACCFG2_INIT);
1237}
1238
1239static int init_half_duplex_params(int alt_beb,
1240 int back_pressure_no_backoff,
1241 int no_backoff,
1242 int excess_defer,
1243 u8 alt_beb_truncation,
1244 u8 max_retransmissions,
1245 u8 collision_window,
1246 volatile u32 *hafdup_register)
1247{
1248 u32 value = 0;
1249
1250 if ((alt_beb_truncation > HALFDUP_ALT_BEB_TRUNCATION_MAX) ||
1251 (max_retransmissions > HALFDUP_MAX_RETRANSMISSION_MAX) ||
1252 (collision_window > HALFDUP_COLLISION_WINDOW_MAX))
1253 return -EINVAL;
1254
1255 value = (u32) (alt_beb_truncation << HALFDUP_ALT_BEB_TRUNCATION_SHIFT);
1256
1257 if (alt_beb)
1258 value |= HALFDUP_ALT_BEB;
1259 if (back_pressure_no_backoff)
1260 value |= HALFDUP_BACK_PRESSURE_NO_BACKOFF;
1261 if (no_backoff)
1262 value |= HALFDUP_NO_BACKOFF;
1263 if (excess_defer)
1264 value |= HALFDUP_EXCESSIVE_DEFER;
1265
1266 value |= (max_retransmissions << HALFDUP_MAX_RETRANSMISSION_SHIFT);
1267
1268 value |= collision_window;
1269
1270 out_be32(hafdup_register, value);
1271 return 0;
1272}
1273
1274static int init_inter_frame_gap_params(u8 non_btb_cs_ipg,
1275 u8 non_btb_ipg,
1276 u8 min_ifg,
1277 u8 btb_ipg,
1278 volatile u32 *ipgifg_register)
1279{
1280 u32 value = 0;
1281
1282 /* Non-Back-to-back IPG part 1 should be <= Non-Back-to-back
1283 IPG part 2 */
1284 if (non_btb_cs_ipg > non_btb_ipg)
1285 return -EINVAL;
1286
1287 if ((non_btb_cs_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART1_MAX) ||
1288 (non_btb_ipg > IPGIFG_NON_BACK_TO_BACK_IFG_PART2_MAX) ||
1289 /*(min_ifg > IPGIFG_MINIMUM_IFG_ENFORCEMENT_MAX) || */
1290 (btb_ipg > IPGIFG_BACK_TO_BACK_IFG_MAX))
1291 return -EINVAL;
1292
1293 value |=
1294 ((non_btb_cs_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART1_SHIFT) &
1295 IPGIFG_NBTB_CS_IPG_MASK);
1296 value |=
1297 ((non_btb_ipg << IPGIFG_NON_BACK_TO_BACK_IFG_PART2_SHIFT) &
1298 IPGIFG_NBTB_IPG_MASK);
1299 value |=
1300 ((min_ifg << IPGIFG_MINIMUM_IFG_ENFORCEMENT_SHIFT) &
1301 IPGIFG_MIN_IFG_MASK);
1302 value |= (btb_ipg & IPGIFG_BTB_IPG_MASK);
1303
1304 out_be32(ipgifg_register, value);
1305 return 0;
1306}
1307
1308static int init_flow_control_params(u32 automatic_flow_control_mode,
1309 int rx_flow_control_enable,
1310 int tx_flow_control_enable,
1311 u16 pause_period,
1312 u16 extension_field,
1313 volatile u32 *upsmr_register,
1314 volatile u32 *uempr_register,
1315 volatile u32 *maccfg1_register)
1316{
1317 u32 value = 0;
1318
1319 /* Set UEMPR register */
1320 value = (u32) pause_period << UEMPR_PAUSE_TIME_VALUE_SHIFT;
1321 value |= (u32) extension_field << UEMPR_EXTENDED_PAUSE_TIME_VALUE_SHIFT;
1322 out_be32(uempr_register, value);
1323
1324 /* Set UPSMR register */
1325 value = in_be32(upsmr_register);
1326 value |= automatic_flow_control_mode;
1327 out_be32(upsmr_register, value);
1328
1329 value = in_be32(maccfg1_register);
1330 if (rx_flow_control_enable)
1331 value |= MACCFG1_FLOW_RX;
1332 if (tx_flow_control_enable)
1333 value |= MACCFG1_FLOW_TX;
1334 out_be32(maccfg1_register, value);
1335
1336 return 0;
1337}
1338
1339static int init_hw_statistics_gathering_mode(int enable_hardware_statistics,
1340 int auto_zero_hardware_statistics,
1341 volatile u32 *upsmr_register,
1342 volatile u16 *uescr_register)
1343{
1344 u32 upsmr_value = 0;
1345 u16 uescr_value = 0;
1346 /* Enable hardware statistics gathering if requested */
1347 if (enable_hardware_statistics) {
1348 upsmr_value = in_be32(upsmr_register);
1349 upsmr_value |= UPSMR_HSE;
1350 out_be32(upsmr_register, upsmr_value);
1351 }
1352
1353 /* Clear hardware statistics counters */
1354 uescr_value = in_be16(uescr_register);
1355 uescr_value |= UESCR_CLRCNT;
1356 /* Automatically zero hardware statistics counters on read,
1357 if requested */
1358 if (auto_zero_hardware_statistics)
1359 uescr_value |= UESCR_AUTOZ;
1360 out_be16(uescr_register, uescr_value);
1361
1362 return 0;
1363}
1364
1365static int init_firmware_statistics_gathering_mode(int
1366 enable_tx_firmware_statistics,
1367 int enable_rx_firmware_statistics,
1368 volatile u32 *tx_rmon_base_ptr,
1369 u32 tx_firmware_statistics_structure_address,
1370 volatile u32 *rx_rmon_base_ptr,
1371 u32 rx_firmware_statistics_structure_address,
1372 volatile u16 *temoder_register,
1373 volatile u32 *remoder_register)
1374{
1375 /* Note: this function does not check if */
1376 /* the parameters it receives are NULL */
1377 u16 temoder_value;
1378 u32 remoder_value;
1379
1380 if (enable_tx_firmware_statistics) {
1381 out_be32(tx_rmon_base_ptr,
1382 tx_firmware_statistics_structure_address);
1383 temoder_value = in_be16(temoder_register);
1384 temoder_value |= TEMODER_TX_RMON_STATISTICS_ENABLE;
1385 out_be16(temoder_register, temoder_value);
1386 }
1387
1388 if (enable_rx_firmware_statistics) {
1389 out_be32(rx_rmon_base_ptr,
1390 rx_firmware_statistics_structure_address);
1391 remoder_value = in_be32(remoder_register);
1392 remoder_value |= REMODER_RX_RMON_STATISTICS_ENABLE;
1393 out_be32(remoder_register, remoder_value);
1394 }
1395
1396 return 0;
1397}
1398
1399static int init_mac_station_addr_regs(u8 address_byte_0,
1400 u8 address_byte_1,
1401 u8 address_byte_2,
1402 u8 address_byte_3,
1403 u8 address_byte_4,
1404 u8 address_byte_5,
1405 volatile u32 *macstnaddr1_register,
1406 volatile u32 *macstnaddr2_register)
1407{
1408 u32 value = 0;
1409
1410 /* Example: for a station address of 0x12345678ABCD, */
1411 /* 0x12 is byte 0, 0x34 is byte 1 and so on and 0xCD is byte 5 */
1412
1413 /* MACSTNADDR1 Register: */
1414
1415 /* 0 7 8 15 */
1416 /* station address byte 5 station address byte 4 */
1417 /* 16 23 24 31 */
1418 /* station address byte 3 station address byte 2 */
1419 value |= (u32) ((address_byte_2 << 0) & 0x000000FF);
1420 value |= (u32) ((address_byte_3 << 8) & 0x0000FF00);
1421 value |= (u32) ((address_byte_4 << 16) & 0x00FF0000);
1422 value |= (u32) ((address_byte_5 << 24) & 0xFF000000);
1423
1424 out_be32(macstnaddr1_register, value);
1425
1426 /* MACSTNADDR2 Register: */
1427
1428 /* 0 7 8 15 */
1429 /* station address byte 1 station address byte 0 */
1430 /* 16 23 24 31 */
1431 /* reserved reserved */
1432 value = 0;
1433 value |= (u32) ((address_byte_0 << 16) & 0x00FF0000);
1434 value |= (u32) ((address_byte_1 << 24) & 0xFF000000);
1435
1436 out_be32(macstnaddr2_register, value);
1437
1438 return 0;
1439}
1440
1441static int init_mac_duplex_mode(int full_duplex,
1442 int limited_to_full_duplex,
1443 volatile u32 *maccfg2_register)
1444{
1445 u32 value = 0;
1446
1447 /* some interfaces must work in full duplex mode */
1448 if ((full_duplex == 0) && (limited_to_full_duplex == 1))
1449 return -EINVAL;
1450
1451 value = in_be32(maccfg2_register);
1452
1453 if (full_duplex)
1454 value |= MACCFG2_FDX;
1455 else
1456 value &= ~MACCFG2_FDX;
1457
1458 out_be32(maccfg2_register, value);
1459 return 0;
1460}
1461
1462static int init_check_frame_length_mode(int length_check,
1463 volatile u32 *maccfg2_register)
1464{
1465 u32 value = 0;
1466
1467 value = in_be32(maccfg2_register);
1468
1469 if (length_check)
1470 value |= MACCFG2_LC;
1471 else
1472 value &= ~MACCFG2_LC;
1473
1474 out_be32(maccfg2_register, value);
1475 return 0;
1476}
1477
1478static int init_preamble_length(u8 preamble_length,
1479 volatile u32 *maccfg2_register)
1480{
1481 u32 value = 0;
1482
1483 if ((preamble_length < 3) || (preamble_length > 7))
1484 return -EINVAL;
1485
1486 value = in_be32(maccfg2_register);
1487 value &= ~MACCFG2_PREL_MASK;
1488 value |= (preamble_length << MACCFG2_PREL_SHIFT);
1489 out_be32(maccfg2_register, value);
1490 return 0;
1491}
1492
1493static int init_mii_management_configuration(int reset_mgmt,
1494 int preamble_supress,
1495 volatile u32 *miimcfg_register,
1496 volatile u32 *miimind_register)
1497{
1498 unsigned int timeout = PHY_INIT_TIMEOUT;
1499 u32 value = 0;
1500
1501 value = in_be32(miimcfg_register);
1502 if (reset_mgmt) {
1503 value |= MIIMCFG_RESET_MANAGEMENT;
1504 out_be32(miimcfg_register, value);
1505 }
1506
1507 value = 0;
1508
1509 if (preamble_supress)
1510 value |= MIIMCFG_NO_PREAMBLE;
1511
1512 value |= UCC_GETH_MIIMCFG_MNGMNT_CLC_DIV_INIT;
1513 out_be32(miimcfg_register, value);
1514
1515 /* Wait until the bus is free */
1516 while ((in_be32(miimind_register) & MIIMIND_BUSY) && timeout--)
1517 cpu_relax();
1518
1519 if (timeout <= 0) {
1520 ugeth_err("%s: The MII Bus is stuck!", __FUNCTION__);
1521 return -ETIMEDOUT;
1522 }
1523
1524 return 0;
1525}
1526
1527static int init_rx_parameters(int reject_broadcast,
1528 int receive_short_frames,
1529 int promiscuous, volatile u32 *upsmr_register)
1530{
1531 u32 value = 0;
1532
1533 value = in_be32(upsmr_register);
1534
1535 if (reject_broadcast)
1536 value |= UPSMR_BRO;
1537 else
1538 value &= ~UPSMR_BRO;
1539
1540 if (receive_short_frames)
1541 value |= UPSMR_RSH;
1542 else
1543 value &= ~UPSMR_RSH;
1544
1545 if (promiscuous)
1546 value |= UPSMR_PRO;
1547 else
1548 value &= ~UPSMR_PRO;
1549
1550 out_be32(upsmr_register, value);
1551
1552 return 0;
1553}
1554
1555static int init_max_rx_buff_len(u16 max_rx_buf_len,
1556 volatile u16 *mrblr_register)
1557{
1558 /* max_rx_buf_len value must be a multiple of 128 */
1559 if ((max_rx_buf_len == 0)
1560 || (max_rx_buf_len % UCC_GETH_MRBLR_ALIGNMENT))
1561 return -EINVAL;
1562
1563 out_be16(mrblr_register, max_rx_buf_len);
1564 return 0;
1565}
1566
1567static int init_min_frame_len(u16 min_frame_length,
1568 volatile u16 *minflr_register,
1569 volatile u16 *mrblr_register)
1570{
1571 u16 mrblr_value = 0;
1572
1573 mrblr_value = in_be16(mrblr_register);
1574 if (min_frame_length >= (mrblr_value - 4))
1575 return -EINVAL;
1576
1577 out_be16(minflr_register, min_frame_length);
1578 return 0;
1579}
1580
1581static int adjust_enet_interface(ucc_geth_private_t *ugeth)
1582{
1583 ucc_geth_info_t *ug_info;
1584 ucc_geth_t *ug_regs;
1585 ucc_fast_t *uf_regs;
1586 enet_speed_e speed;
1587 int ret_val, rpm = 0, tbi = 0, r10m = 0, rmm =
1588 0, limited_to_full_duplex = 0;
1589 u32 upsmr, maccfg2, utbipar, tbiBaseAddress;
1590 u16 value;
1591
1592 ugeth_vdbg("%s: IN", __FUNCTION__);
1593
1594 ug_info = ugeth->ug_info;
1595 ug_regs = ugeth->ug_regs;
1596 uf_regs = ugeth->uccf->uf_regs;
1597
1598 /* Analyze enet_interface according to Interface Mode Configuration
1599 table */
1600 ret_val =
1601 get_interface_details(ug_info->enet_interface, &speed, &r10m, &rmm,
1602 &rpm, &tbi, &limited_to_full_duplex);
1603 if (ret_val != 0) {
1604 ugeth_err
1605 ("%s: half duplex not supported in requested configuration.",
1606 __FUNCTION__);
1607 return ret_val;
1608 }
1609
1610 /* Set MACCFG2 */
1611 maccfg2 = in_be32(&ug_regs->maccfg2);
1612 maccfg2 &= ~MACCFG2_INTERFACE_MODE_MASK;
1613 if ((speed == ENET_SPEED_10BT) || (speed == ENET_SPEED_100BT))
1614 maccfg2 |= MACCFG2_INTERFACE_MODE_NIBBLE;
1615 else if (speed == ENET_SPEED_1000BT)
1616 maccfg2 |= MACCFG2_INTERFACE_MODE_BYTE;
1617 maccfg2 |= ug_info->padAndCrc;
1618 out_be32(&ug_regs->maccfg2, maccfg2);
1619
1620 /* Set UPSMR */
1621 upsmr = in_be32(&uf_regs->upsmr);
1622 upsmr &= ~(UPSMR_RPM | UPSMR_R10M | UPSMR_TBIM | UPSMR_RMM);
1623 if (rpm)
1624 upsmr |= UPSMR_RPM;
1625 if (r10m)
1626 upsmr |= UPSMR_R10M;
1627 if (tbi)
1628 upsmr |= UPSMR_TBIM;
1629 if (rmm)
1630 upsmr |= UPSMR_RMM;
1631 out_be32(&uf_regs->upsmr, upsmr);
1632
1633 /* Set UTBIPAR */
1634 utbipar = in_be32(&ug_regs->utbipar);
1635 utbipar &= ~UTBIPAR_PHY_ADDRESS_MASK;
1636 if (tbi)
1637 utbipar |=
1638 (ug_info->phy_address +
1639 ugeth->ug_info->uf_info.
1640 ucc_num) << UTBIPAR_PHY_ADDRESS_SHIFT;
1641 else
1642 utbipar |=
1643 (0x10 +
1644 ugeth->ug_info->uf_info.
1645 ucc_num) << UTBIPAR_PHY_ADDRESS_SHIFT;
1646 out_be32(&ug_regs->utbipar, utbipar);
1647
1648 /* Disable autonegotiation in tbi mode, because by default it
1649 comes up in autonegotiation mode. */
1650 /* Note that this depends on proper setting in utbipar register. */
1651 if (tbi) {
1652 tbiBaseAddress = in_be32(&ug_regs->utbipar);
1653 tbiBaseAddress &= UTBIPAR_PHY_ADDRESS_MASK;
1654 tbiBaseAddress >>= UTBIPAR_PHY_ADDRESS_SHIFT;
1655 value =
1656 ugeth->mii_info->mdio_read(ugeth->dev, (u8) tbiBaseAddress,
1657 ENET_TBI_MII_CR);
1658 value &= ~0x1000; /* Turn off autonegotiation */
1659 ugeth->mii_info->mdio_write(ugeth->dev, (u8) tbiBaseAddress,
1660 ENET_TBI_MII_CR, value);
1661 }
1662
1663 ret_val = init_mac_duplex_mode(1,
1664 limited_to_full_duplex,
1665 &ug_regs->maccfg2);
1666 if (ret_val != 0) {
1667 ugeth_err
1668 ("%s: half duplex not supported in requested configuration.",
1669 __FUNCTION__);
1670 return ret_val;
1671 }
1672
1673 init_check_frame_length_mode(ug_info->lengthCheckRx, &ug_regs->maccfg2);
1674
1675 ret_val = init_preamble_length(ug_info->prel, &ug_regs->maccfg2);
1676 if (ret_val != 0) {
1677 ugeth_err
1678 ("%s: Preamble length must be between 3 and 7 inclusive.",
1679 __FUNCTION__);
1680 return ret_val;
1681 }
1682
1683 return 0;
1684}
1685
1686/* Called every time the controller might need to be made
1687 * aware of new link state. The PHY code conveys this
1688 * information through variables in the ugeth structure, and this
1689 * function converts those variables into the appropriate
1690 * register values, and can bring down the device if needed.
1691 */
1692static void adjust_link(struct net_device *dev)
1693{
1694 ucc_geth_private_t *ugeth = netdev_priv(dev);
1695 ucc_geth_t *ug_regs;
1696 u32 tempval;
1697 struct ugeth_mii_info *mii_info = ugeth->mii_info;
1698
1699 ug_regs = ugeth->ug_regs;
1700
1701 if (mii_info->link) {
1702 /* Now we make sure that we can be in full duplex mode.
1703 * If not, we operate in half-duplex mode. */
1704 if (mii_info->duplex != ugeth->oldduplex) {
1705 if (!(mii_info->duplex)) {
1706 tempval = in_be32(&ug_regs->maccfg2);
1707 tempval &= ~(MACCFG2_FDX);
1708 out_be32(&ug_regs->maccfg2, tempval);
1709
1710 ugeth_info("%s: Half Duplex", dev->name);
1711 } else {
1712 tempval = in_be32(&ug_regs->maccfg2);
1713 tempval |= MACCFG2_FDX;
1714 out_be32(&ug_regs->maccfg2, tempval);
1715
1716 ugeth_info("%s: Full Duplex", dev->name);
1717 }
1718
1719 ugeth->oldduplex = mii_info->duplex;
1720 }
1721
1722 if (mii_info->speed != ugeth->oldspeed) {
1723 switch (mii_info->speed) {
1724 case 1000:
1725#ifdef CONFIG_MPC836x
1726/* FIXME: This code is for 100Mbs BUG fixing,
1727remove this when it is fixed!!! */
1728 if (ugeth->ug_info->enet_interface ==
1729 ENET_1000_GMII)
1730 /* Run the commands which initialize the PHY */
1731 {
1732 tempval =
1733 (u32) mii_info->mdio_read(ugeth->
1734 dev, mii_info->mii_id, 0x1b);
1735 tempval |= 0x000f;
1736 mii_info->mdio_write(ugeth->dev,
1737 mii_info->mii_id, 0x1b,
1738 (u16) tempval);
1739 tempval =
1740 (u32) mii_info->mdio_read(ugeth->
1741 dev, mii_info->mii_id,
1742 MII_BMCR);
1743 mii_info->mdio_write(ugeth->dev,
1744 mii_info->mii_id, MII_BMCR,
1745 (u16) (tempval | BMCR_RESET));
1746 } else if (ugeth->ug_info->enet_interface ==
1747 ENET_1000_RGMII)
1748 /* Run the commands which initialize the PHY */
1749 {
1750 tempval =
1751 (u32) mii_info->mdio_read(ugeth->
1752 dev, mii_info->mii_id, 0x1b);
1753 tempval = (tempval & ~0x000f) | 0x000b;
1754 mii_info->mdio_write(ugeth->dev,
1755 mii_info->mii_id, 0x1b,
1756 (u16) tempval);
1757 tempval =
1758 (u32) mii_info->mdio_read(ugeth->
1759 dev, mii_info->mii_id,
1760 MII_BMCR);
1761 mii_info->mdio_write(ugeth->dev,
1762 mii_info->mii_id, MII_BMCR,
1763 (u16) (tempval | BMCR_RESET));
1764 }
1765 msleep(4000);
1766#endif /* CONFIG_MPC8360 */
1767 adjust_enet_interface(ugeth);
1768 break;
1769 case 100:
1770 case 10:
1771#ifdef CONFIG_MPC836x
1772/* FIXME: This code is for 100Mbs BUG fixing,
1773remove this lines when it will be fixed!!! */
1774 ugeth->ug_info->enet_interface = ENET_100_RGMII;
1775 tempval =
1776 (u32) mii_info->mdio_read(ugeth->dev,
1777 mii_info->mii_id,
1778 0x1b);
1779 tempval = (tempval & ~0x000f) | 0x000b;
1780 mii_info->mdio_write(ugeth->dev,
1781 mii_info->mii_id, 0x1b,
1782 (u16) tempval);
1783 tempval =
1784 (u32) mii_info->mdio_read(ugeth->dev,
1785 mii_info->mii_id,
1786 MII_BMCR);
1787 mii_info->mdio_write(ugeth->dev,
1788 mii_info->mii_id, MII_BMCR,
1789 (u16) (tempval |
1790 BMCR_RESET));
1791 msleep(4000);
1792#endif /* CONFIG_MPC8360 */
1793 adjust_enet_interface(ugeth);
1794 break;
1795 default:
1796 ugeth_warn
1797 ("%s: Ack! Speed (%d) is not 10/100/1000!",
1798 dev->name, mii_info->speed);
1799 break;
1800 }
1801
1802 ugeth_info("%s: Speed %dBT", dev->name,
1803 mii_info->speed);
1804
1805 ugeth->oldspeed = mii_info->speed;
1806 }
1807
1808 if (!ugeth->oldlink) {
1809 ugeth_info("%s: Link is up", dev->name);
1810 ugeth->oldlink = 1;
1811 netif_carrier_on(dev);
1812 netif_schedule(dev);
1813 }
1814 } else {
1815 if (ugeth->oldlink) {
1816 ugeth_info("%s: Link is down", dev->name);
1817 ugeth->oldlink = 0;
1818 ugeth->oldspeed = 0;
1819 ugeth->oldduplex = -1;
1820 netif_carrier_off(dev);
1821 }
1822 }
1823}
1824
1825/* Configure the PHY for dev.
1826 * returns 0 if success. -1 if failure
1827 */
1828static int init_phy(struct net_device *dev)
1829{
1830 ucc_geth_private_t *ugeth = netdev_priv(dev);
1831 struct phy_info *curphy;
1832 ucc_mii_mng_t *mii_regs;
1833 struct ugeth_mii_info *mii_info;
1834 int err;
1835
1836 mii_regs = &ugeth->ug_regs->miimng;
1837
1838 ugeth->oldlink = 0;
1839 ugeth->oldspeed = 0;
1840 ugeth->oldduplex = -1;
1841
1842 mii_info = kmalloc(sizeof(struct ugeth_mii_info), GFP_KERNEL);
1843
1844 if (NULL == mii_info) {
1845 ugeth_err("%s: Could not allocate mii_info", dev->name);
1846 return -ENOMEM;
1847 }
1848
1849 mii_info->mii_regs = mii_regs;
1850 mii_info->speed = SPEED_1000;
1851 mii_info->duplex = DUPLEX_FULL;
1852 mii_info->pause = 0;
1853 mii_info->link = 0;
1854
1855 mii_info->advertising = (ADVERTISED_10baseT_Half |
1856 ADVERTISED_10baseT_Full |
1857 ADVERTISED_100baseT_Half |
1858 ADVERTISED_100baseT_Full |
1859 ADVERTISED_1000baseT_Full);
1860 mii_info->autoneg = 1;
1861
1862 mii_info->mii_id = ugeth->ug_info->phy_address;
1863
1864 mii_info->dev = dev;
1865
1866 mii_info->mdio_read = &read_phy_reg;
1867 mii_info->mdio_write = &write_phy_reg;
1868
1869 ugeth->mii_info = mii_info;
1870
1871 spin_lock_irq(&ugeth->lock);
1872
1873 /* Set this UCC to be the master of the MII managment */
1874 ucc_set_qe_mux_mii_mng(ugeth->ug_info->uf_info.ucc_num);
1875
1876 if (init_mii_management_configuration(1,
1877 ugeth->ug_info->
1878 miiPreambleSupress,
1879 &mii_regs->miimcfg,
1880 &mii_regs->miimind)) {
1881 ugeth_err("%s: The MII Bus is stuck!", dev->name);
1882 err = -1;
1883 goto bus_fail;
1884 }
1885
1886 spin_unlock_irq(&ugeth->lock);
1887
1888 /* get info for this PHY */
1889 curphy = get_phy_info(ugeth->mii_info);
1890
1891 if (curphy == NULL) {
1892 ugeth_err("%s: No PHY found", dev->name);
1893 err = -1;
1894 goto no_phy;
1895 }
1896
1897 mii_info->phyinfo = curphy;
1898
1899 /* Run the commands which initialize the PHY */
1900 if (curphy->init) {
1901 err = curphy->init(ugeth->mii_info);
1902 if (err)
1903 goto phy_init_fail;
1904 }
1905
1906 return 0;
1907
1908 phy_init_fail:
1909 no_phy:
1910 bus_fail:
1911 kfree(mii_info);
1912
1913 return err;
1914}
1915
1916#ifdef CONFIG_UGETH_TX_ON_DEMOND
1917static int ugeth_transmit_on_demand(ucc_geth_private_t *ugeth)
1918{
1919 ucc_fast_transmit_on_demand(ugeth->uccf);
1920
1921 return 0;
1922}
1923#endif
1924
1925static int ugeth_graceful_stop_tx(ucc_geth_private_t *ugeth)
1926{
1927 ucc_fast_private_t *uccf;
1928 u32 cecr_subblock;
1929 u32 temp;
1930
1931 uccf = ugeth->uccf;
1932
1933 /* Mask GRACEFUL STOP TX interrupt bit and clear it */
1934 temp = in_be32(uccf->p_uccm);
1935 temp &= ~UCCE_GRA;
1936 out_be32(uccf->p_uccm, temp);
1937 out_be32(uccf->p_ucce, UCCE_GRA); /* clear by writing 1 */
1938
1939 /* Issue host command */
1940 cecr_subblock =
1941 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
1942 qe_issue_cmd(QE_GRACEFUL_STOP_TX, cecr_subblock,
1943 (u8) QE_CR_PROTOCOL_ETHERNET, 0);
1944
1945 /* Wait for command to complete */
1946 do {
1947 temp = in_be32(uccf->p_ucce);
1948 } while (!(temp & UCCE_GRA));
1949
1950 uccf->stopped_tx = 1;
1951
1952 return 0;
1953}
1954
1955static int ugeth_graceful_stop_rx(ucc_geth_private_t * ugeth)
1956{
1957 ucc_fast_private_t *uccf;
1958 u32 cecr_subblock;
1959 u8 temp;
1960
1961 uccf = ugeth->uccf;
1962
1963 /* Clear acknowledge bit */
1964 temp = ugeth->p_rx_glbl_pram->rxgstpack;
1965 temp &= ~GRACEFUL_STOP_ACKNOWLEDGE_RX;
1966 ugeth->p_rx_glbl_pram->rxgstpack = temp;
1967
1968 /* Keep issuing command and checking acknowledge bit until
1969 it is asserted, according to spec */
1970 do {
1971 /* Issue host command */
1972 cecr_subblock =
1973 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.
1974 ucc_num);
1975 qe_issue_cmd(QE_GRACEFUL_STOP_RX, cecr_subblock,
1976 (u8) QE_CR_PROTOCOL_ETHERNET, 0);
1977
1978 temp = ugeth->p_rx_glbl_pram->rxgstpack;
1979 } while (!(temp & GRACEFUL_STOP_ACKNOWLEDGE_RX));
1980
1981 uccf->stopped_rx = 1;
1982
1983 return 0;
1984}
1985
1986static int ugeth_restart_tx(ucc_geth_private_t *ugeth)
1987{
1988 ucc_fast_private_t *uccf;
1989 u32 cecr_subblock;
1990
1991 uccf = ugeth->uccf;
1992
1993 cecr_subblock =
1994 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
1995 qe_issue_cmd(QE_RESTART_TX, cecr_subblock, (u8) QE_CR_PROTOCOL_ETHERNET,
1996 0);
1997 uccf->stopped_tx = 0;
1998
1999 return 0;
2000}
2001
2002static int ugeth_restart_rx(ucc_geth_private_t *ugeth)
2003{
2004 ucc_fast_private_t *uccf;
2005 u32 cecr_subblock;
2006
2007 uccf = ugeth->uccf;
2008
2009 cecr_subblock =
2010 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
2011 qe_issue_cmd(QE_RESTART_RX, cecr_subblock, (u8) QE_CR_PROTOCOL_ETHERNET,
2012 0);
2013 uccf->stopped_rx = 0;
2014
2015 return 0;
2016}
2017
2018static int ugeth_enable(ucc_geth_private_t *ugeth, comm_dir_e mode)
2019{
2020 ucc_fast_private_t *uccf;
2021 int enabled_tx, enabled_rx;
2022
2023 uccf = ugeth->uccf;
2024
2025 /* check if the UCC number is in range. */
2026 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
2027 ugeth_err("%s: ucc_num out of range.", __FUNCTION__);
2028 return -EINVAL;
2029 }
2030
2031 enabled_tx = uccf->enabled_tx;
2032 enabled_rx = uccf->enabled_rx;
2033
2034 /* Get Tx and Rx going again, in case this channel was actively
2035 disabled. */
2036 if ((mode & COMM_DIR_TX) && (!enabled_tx) && uccf->stopped_tx)
2037 ugeth_restart_tx(ugeth);
2038 if ((mode & COMM_DIR_RX) && (!enabled_rx) && uccf->stopped_rx)
2039 ugeth_restart_rx(ugeth);
2040
2041 ucc_fast_enable(uccf, mode); /* OK to do even if not disabled */
2042
2043 return 0;
2044
2045}
2046
2047static int ugeth_disable(ucc_geth_private_t * ugeth, comm_dir_e mode)
2048{
2049 ucc_fast_private_t *uccf;
2050
2051 uccf = ugeth->uccf;
2052
2053 /* check if the UCC number is in range. */
2054 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
2055 ugeth_err("%s: ucc_num out of range.", __FUNCTION__);
2056 return -EINVAL;
2057 }
2058
2059 /* Stop any transmissions */
2060 if ((mode & COMM_DIR_TX) && uccf->enabled_tx && !uccf->stopped_tx)
2061 ugeth_graceful_stop_tx(ugeth);
2062
2063 /* Stop any receptions */
2064 if ((mode & COMM_DIR_RX) && uccf->enabled_rx && !uccf->stopped_rx)
2065 ugeth_graceful_stop_rx(ugeth);
2066
2067 ucc_fast_disable(ugeth->uccf, mode); /* OK to do even if not enabled */
2068
2069 return 0;
2070}
2071
2072static void ugeth_dump_regs(ucc_geth_private_t *ugeth)
2073{
2074#ifdef DEBUG
2075 ucc_fast_dump_regs(ugeth->uccf);
2076 dump_regs(ugeth);
2077 dump_bds(ugeth);
2078#endif
2079}
2080
2081#ifdef CONFIG_UGETH_FILTERING
2082static int ugeth_ext_filtering_serialize_tad(ucc_geth_tad_params_t *
2083 p_UccGethTadParams,
2084 qe_fltr_tad_t *qe_fltr_tad)
2085{
2086 u16 temp;
2087
2088 /* Zero serialized TAD */
2089 memset(qe_fltr_tad, 0, QE_FLTR_TAD_SIZE);
2090
2091 qe_fltr_tad->serialized[0] |= UCC_GETH_TAD_V; /* Must have this */
2092 if (p_UccGethTadParams->rx_non_dynamic_extended_features_mode ||
2093 (p_UccGethTadParams->vtag_op != UCC_GETH_VLAN_OPERATION_TAGGED_NOP)
2094 || (p_UccGethTadParams->vnontag_op !=
2095 UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP)
2096 )
2097 qe_fltr_tad->serialized[0] |= UCC_GETH_TAD_EF;
2098 if (p_UccGethTadParams->reject_frame)
2099 qe_fltr_tad->serialized[0] |= UCC_GETH_TAD_REJ;
2100 temp =
2101 (u16) (((u16) p_UccGethTadParams->
2102 vtag_op) << UCC_GETH_TAD_VTAG_OP_SHIFT);
2103 qe_fltr_tad->serialized[0] |= (u8) (temp >> 8); /* upper bits */
2104
2105 qe_fltr_tad->serialized[1] |= (u8) (temp & 0x00ff); /* lower bits */
2106 if (p_UccGethTadParams->vnontag_op ==
2107 UCC_GETH_VLAN_OPERATION_NON_TAGGED_Q_TAG_INSERT)
2108 qe_fltr_tad->serialized[1] |= UCC_GETH_TAD_V_NON_VTAG_OP;
2109 qe_fltr_tad->serialized[1] |=
2110 p_UccGethTadParams->rqos << UCC_GETH_TAD_RQOS_SHIFT;
2111
2112 qe_fltr_tad->serialized[2] |=
2113 p_UccGethTadParams->vpri << UCC_GETH_TAD_V_PRIORITY_SHIFT;
2114 /* upper bits */
2115 qe_fltr_tad->serialized[2] |= (u8) (p_UccGethTadParams->vid >> 8);
2116 /* lower bits */
2117 qe_fltr_tad->serialized[3] |= (u8) (p_UccGethTadParams->vid & 0x00ff);
2118
2119 return 0;
2120}
2121
2122static enet_addr_container_t
2123 *ugeth_82xx_filtering_get_match_addr_in_hash(ucc_geth_private_t *ugeth,
2124 enet_addr_t *p_enet_addr)
2125{
2126 enet_addr_container_t *enet_addr_cont;
2127 struct list_head *p_lh;
2128 u16 i, num;
2129 int32_t j;
2130 u8 *p_counter;
2131
2132 if ((*p_enet_addr)[0] & ENET_GROUP_ADDR) {
2133 p_lh = &ugeth->group_hash_q;
2134 p_counter = &(ugeth->numGroupAddrInHash);
2135 } else {
2136 p_lh = &ugeth->ind_hash_q;
2137 p_counter = &(ugeth->numIndAddrInHash);
2138 }
2139
2140 if (!p_lh)
2141 return NULL;
2142
2143 num = *p_counter;
2144
2145 for (i = 0; i < num; i++) {
2146 enet_addr_cont =
2147 (enet_addr_container_t *)
2148 ENET_ADDR_CONT_ENTRY(dequeue(p_lh));
2149 for (j = ENET_NUM_OCTETS_PER_ADDRESS - 1; j >= 0; j--) {
2150 if ((*p_enet_addr)[j] != (enet_addr_cont->address)[j])
2151 break;
2152 if (j == 0)
2153 return enet_addr_cont; /* Found */
2154 }
2155 enqueue(p_lh, &enet_addr_cont->node); /* Put it back */
2156 }
2157 return NULL;
2158}
2159
2160static int ugeth_82xx_filtering_add_addr_in_hash(ucc_geth_private_t *ugeth,
2161 enet_addr_t *p_enet_addr)
2162{
2163 ucc_geth_enet_address_recognition_location_e location;
2164 enet_addr_container_t *enet_addr_cont;
2165 struct list_head *p_lh;
2166 u8 i;
2167 u32 limit;
2168 u8 *p_counter;
2169
2170 if ((*p_enet_addr)[0] & ENET_GROUP_ADDR) {
2171 p_lh = &ugeth->group_hash_q;
2172 limit = ugeth->ug_info->maxGroupAddrInHash;
2173 location =
2174 UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_GROUP_HASH;
2175 p_counter = &(ugeth->numGroupAddrInHash);
2176 } else {
2177 p_lh = &ugeth->ind_hash_q;
2178 limit = ugeth->ug_info->maxIndAddrInHash;
2179 location =
2180 UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_INDIVIDUAL_HASH;
2181 p_counter = &(ugeth->numIndAddrInHash);
2182 }
2183
2184 if ((enet_addr_cont =
2185 ugeth_82xx_filtering_get_match_addr_in_hash(ugeth, p_enet_addr))) {
2186 list_add(p_lh, &enet_addr_cont->node); /* Put it back */
2187 return 0;
2188 }
2189 if ((!p_lh) || (!(*p_counter < limit)))
2190 return -EBUSY;
2191 if (!(enet_addr_cont = get_enet_addr_container()))
2192 return -ENOMEM;
2193 for (i = 0; i < ENET_NUM_OCTETS_PER_ADDRESS; i++)
2194 (enet_addr_cont->address)[i] = (*p_enet_addr)[i];
2195 enet_addr_cont->location = location;
2196 enqueue(p_lh, &enet_addr_cont->node); /* Put it back */
2197 ++(*p_counter);
2198
2199 hw_add_addr_in_hash(ugeth, &(enet_addr_cont->address));
2200
2201 return 0;
2202}
2203
2204static int ugeth_82xx_filtering_clear_addr_in_hash(ucc_geth_private_t *ugeth,
2205 enet_addr_t *p_enet_addr)
2206{
2207 ucc_geth_82xx_address_filtering_pram_t *p_82xx_addr_filt;
2208 enet_addr_container_t *enet_addr_cont;
2209 ucc_fast_private_t *uccf;
2210 comm_dir_e comm_dir;
2211 u16 i, num;
2212 struct list_head *p_lh;
2213 u32 *addr_h, *addr_l;
2214 u8 *p_counter;
2215
2216 uccf = ugeth->uccf;
2217
2218 p_82xx_addr_filt =
2219 (ucc_geth_82xx_address_filtering_pram_t *) ugeth->p_rx_glbl_pram->
2220 addressfiltering;
2221
2222 if (!
2223 (enet_addr_cont =
2224 ugeth_82xx_filtering_get_match_addr_in_hash(ugeth, p_enet_addr)))
2225 return -ENOENT;
2226
2227 /* It's been found and removed from the CQ. */
2228 /* Now destroy its container */
2229 put_enet_addr_container(enet_addr_cont);
2230
2231 if ((*p_enet_addr)[0] & ENET_GROUP_ADDR) {
2232 addr_h = &(p_82xx_addr_filt->gaddr_h);
2233 addr_l = &(p_82xx_addr_filt->gaddr_l);
2234 p_lh = &ugeth->group_hash_q;
2235 p_counter = &(ugeth->numGroupAddrInHash);
2236 } else {
2237 addr_h = &(p_82xx_addr_filt->iaddr_h);
2238 addr_l = &(p_82xx_addr_filt->iaddr_l);
2239 p_lh = &ugeth->ind_hash_q;
2240 p_counter = &(ugeth->numIndAddrInHash);
2241 }
2242
2243 comm_dir = 0;
2244 if (uccf->enabled_tx)
2245 comm_dir |= COMM_DIR_TX;
2246 if (uccf->enabled_rx)
2247 comm_dir |= COMM_DIR_RX;
2248 if (comm_dir)
2249 ugeth_disable(ugeth, comm_dir);
2250
2251 /* Clear the hash table. */
2252 out_be32(addr_h, 0x00000000);
2253 out_be32(addr_l, 0x00000000);
2254
2255 /* Add all remaining CQ elements back into hash */
2256 num = --(*p_counter);
2257 for (i = 0; i < num; i++) {
2258 enet_addr_cont =
2259 (enet_addr_container_t *)
2260 ENET_ADDR_CONT_ENTRY(dequeue(p_lh));
2261 hw_add_addr_in_hash(ugeth, &(enet_addr_cont->address));
2262 enqueue(p_lh, &enet_addr_cont->node); /* Put it back */
2263 }
2264
2265 if (comm_dir)
2266 ugeth_enable(ugeth, comm_dir);
2267
2268 return 0;
2269}
2270#endif /* CONFIG_UGETH_FILTERING */
2271
2272static int ugeth_82xx_filtering_clear_all_addr_in_hash(ucc_geth_private_t *
2273 ugeth,
2274 enet_addr_type_e
2275 enet_addr_type)
2276{
2277 ucc_geth_82xx_address_filtering_pram_t *p_82xx_addr_filt;
2278 ucc_fast_private_t *uccf;
2279 comm_dir_e comm_dir;
2280 struct list_head *p_lh;
2281 u16 i, num;
2282 u32 *addr_h, *addr_l;
2283 u8 *p_counter;
2284
2285 uccf = ugeth->uccf;
2286
2287 p_82xx_addr_filt =
2288 (ucc_geth_82xx_address_filtering_pram_t *) ugeth->p_rx_glbl_pram->
2289 addressfiltering;
2290
2291 if (enet_addr_type == ENET_ADDR_TYPE_GROUP) {
2292 addr_h = &(p_82xx_addr_filt->gaddr_h);
2293 addr_l = &(p_82xx_addr_filt->gaddr_l);
2294 p_lh = &ugeth->group_hash_q;
2295 p_counter = &(ugeth->numGroupAddrInHash);
2296 } else if (enet_addr_type == ENET_ADDR_TYPE_INDIVIDUAL) {
2297 addr_h = &(p_82xx_addr_filt->iaddr_h);
2298 addr_l = &(p_82xx_addr_filt->iaddr_l);
2299 p_lh = &ugeth->ind_hash_q;
2300 p_counter = &(ugeth->numIndAddrInHash);
2301 } else
2302 return -EINVAL;
2303
2304 comm_dir = 0;
2305 if (uccf->enabled_tx)
2306 comm_dir |= COMM_DIR_TX;
2307 if (uccf->enabled_rx)
2308 comm_dir |= COMM_DIR_RX;
2309 if (comm_dir)
2310 ugeth_disable(ugeth, comm_dir);
2311
2312 /* Clear the hash table. */
2313 out_be32(addr_h, 0x00000000);
2314 out_be32(addr_l, 0x00000000);
2315
2316 if (!p_lh)
2317 return 0;
2318
2319 num = *p_counter;
2320
2321 /* Delete all remaining CQ elements */
2322 for (i = 0; i < num; i++)
2323 put_enet_addr_container(ENET_ADDR_CONT_ENTRY(dequeue(p_lh)));
2324
2325 *p_counter = 0;
2326
2327 if (comm_dir)
2328 ugeth_enable(ugeth, comm_dir);
2329
2330 return 0;
2331}
2332
2333#ifdef CONFIG_UGETH_FILTERING
2334static int ugeth_82xx_filtering_add_addr_in_paddr(ucc_geth_private_t *ugeth,
2335 enet_addr_t *p_enet_addr,
2336 u8 paddr_num)
2337{
2338 int i;
2339
2340 if ((*p_enet_addr)[0] & ENET_GROUP_ADDR)
2341 ugeth_warn
2342 ("%s: multicast address added to paddr will have no "
2343 "effect - is this what you wanted?",
2344 __FUNCTION__);
2345
2346 ugeth->indAddrRegUsed[paddr_num] = 1; /* mark this paddr as used */
2347 /* store address in our database */
2348 for (i = 0; i < ENET_NUM_OCTETS_PER_ADDRESS; i++)
2349 ugeth->paddr[paddr_num][i] = (*p_enet_addr)[i];
2350 /* put in hardware */
2351 return hw_add_addr_in_paddr(ugeth, p_enet_addr, paddr_num);
2352}
2353#endif /* CONFIG_UGETH_FILTERING */
2354
2355static int ugeth_82xx_filtering_clear_addr_in_paddr(ucc_geth_private_t *ugeth,
2356 u8 paddr_num)
2357{
2358 ugeth->indAddrRegUsed[paddr_num] = 0; /* mark this paddr as not used */
2359 return hw_clear_addr_in_paddr(ugeth, paddr_num);/* clear in hardware */
2360}
2361
2362static void ucc_geth_memclean(ucc_geth_private_t *ugeth)
2363{
2364 u16 i, j;
2365 u8 *bd;
2366
2367 if (!ugeth)
2368 return;
2369
2370 if (ugeth->uccf)
2371 ucc_fast_free(ugeth->uccf);
2372
2373 if (ugeth->p_thread_data_tx) {
2374 qe_muram_free(ugeth->thread_dat_tx_offset);
2375 ugeth->p_thread_data_tx = NULL;
2376 }
2377 if (ugeth->p_thread_data_rx) {
2378 qe_muram_free(ugeth->thread_dat_rx_offset);
2379 ugeth->p_thread_data_rx = NULL;
2380 }
2381 if (ugeth->p_exf_glbl_param) {
2382 qe_muram_free(ugeth->exf_glbl_param_offset);
2383 ugeth->p_exf_glbl_param = NULL;
2384 }
2385 if (ugeth->p_rx_glbl_pram) {
2386 qe_muram_free(ugeth->rx_glbl_pram_offset);
2387 ugeth->p_rx_glbl_pram = NULL;
2388 }
2389 if (ugeth->p_tx_glbl_pram) {
2390 qe_muram_free(ugeth->tx_glbl_pram_offset);
2391 ugeth->p_tx_glbl_pram = NULL;
2392 }
2393 if (ugeth->p_send_q_mem_reg) {
2394 qe_muram_free(ugeth->send_q_mem_reg_offset);
2395 ugeth->p_send_q_mem_reg = NULL;
2396 }
2397 if (ugeth->p_scheduler) {
2398 qe_muram_free(ugeth->scheduler_offset);
2399 ugeth->p_scheduler = NULL;
2400 }
2401 if (ugeth->p_tx_fw_statistics_pram) {
2402 qe_muram_free(ugeth->tx_fw_statistics_pram_offset);
2403 ugeth->p_tx_fw_statistics_pram = NULL;
2404 }
2405 if (ugeth->p_rx_fw_statistics_pram) {
2406 qe_muram_free(ugeth->rx_fw_statistics_pram_offset);
2407 ugeth->p_rx_fw_statistics_pram = NULL;
2408 }
2409 if (ugeth->p_rx_irq_coalescing_tbl) {
2410 qe_muram_free(ugeth->rx_irq_coalescing_tbl_offset);
2411 ugeth->p_rx_irq_coalescing_tbl = NULL;
2412 }
2413 if (ugeth->p_rx_bd_qs_tbl) {
2414 qe_muram_free(ugeth->rx_bd_qs_tbl_offset);
2415 ugeth->p_rx_bd_qs_tbl = NULL;
2416 }
2417 if (ugeth->p_init_enet_param_shadow) {
2418 return_init_enet_entries(ugeth,
2419 &(ugeth->p_init_enet_param_shadow->
2420 rxthread[0]),
2421 ENET_INIT_PARAM_MAX_ENTRIES_RX,
2422 ugeth->ug_info->riscRx, 1);
2423 return_init_enet_entries(ugeth,
2424 &(ugeth->p_init_enet_param_shadow->
2425 txthread[0]),
2426 ENET_INIT_PARAM_MAX_ENTRIES_TX,
2427 ugeth->ug_info->riscTx, 0);
2428 kfree(ugeth->p_init_enet_param_shadow);
2429 ugeth->p_init_enet_param_shadow = NULL;
2430 }
2431 for (i = 0; i < ugeth->ug_info->numQueuesTx; i++) {
2432 bd = ugeth->p_tx_bd_ring[i];
2433 for (j = 0; j < ugeth->ug_info->bdRingLenTx[i]; j++) {
2434 if (ugeth->tx_skbuff[i][j]) {
2435 dma_unmap_single(NULL,
2436 BD_BUFFER_ARG(bd),
2437 (BD_STATUS_AND_LENGTH(bd) &
2438 BD_LENGTH_MASK),
2439 DMA_TO_DEVICE);
2440 dev_kfree_skb_any(ugeth->tx_skbuff[i][j]);
2441 ugeth->tx_skbuff[i][j] = NULL;
2442 }
2443 }
2444
2445 kfree(ugeth->tx_skbuff[i]);
2446
2447 if (ugeth->p_tx_bd_ring[i]) {
2448 if (ugeth->ug_info->uf_info.bd_mem_part ==
2449 MEM_PART_SYSTEM)
2450 kfree((void *)ugeth->tx_bd_ring_offset[i]);
2451 else if (ugeth->ug_info->uf_info.bd_mem_part ==
2452 MEM_PART_MURAM)
2453 qe_muram_free(ugeth->tx_bd_ring_offset[i]);
2454 ugeth->p_tx_bd_ring[i] = NULL;
2455 }
2456 }
2457 for (i = 0; i < ugeth->ug_info->numQueuesRx; i++) {
2458 if (ugeth->p_rx_bd_ring[i]) {
2459 /* Return existing data buffers in ring */
2460 bd = ugeth->p_rx_bd_ring[i];
2461 for (j = 0; j < ugeth->ug_info->bdRingLenRx[i]; j++) {
2462 if (ugeth->rx_skbuff[i][j]) {
2463 dma_unmap_single(NULL, BD_BUFFER(bd),
2464 ugeth->ug_info->
2465 uf_info.
2466 max_rx_buf_length +
2467 UCC_GETH_RX_DATA_BUF_ALIGNMENT,
2468 DMA_FROM_DEVICE);
2469
2470 dev_kfree_skb_any(ugeth->
2471 rx_skbuff[i][j]);
2472 ugeth->rx_skbuff[i][j] = NULL;
2473 }
2474 bd += UCC_GETH_SIZE_OF_BD;
2475 }
2476
2477 kfree(ugeth->rx_skbuff[i]);
2478
2479 if (ugeth->ug_info->uf_info.bd_mem_part ==
2480 MEM_PART_SYSTEM)
2481 kfree((void *)ugeth->rx_bd_ring_offset[i]);
2482 else if (ugeth->ug_info->uf_info.bd_mem_part ==
2483 MEM_PART_MURAM)
2484 qe_muram_free(ugeth->rx_bd_ring_offset[i]);
2485 ugeth->p_rx_bd_ring[i] = NULL;
2486 }
2487 }
2488 while (!list_empty(&ugeth->group_hash_q))
2489 put_enet_addr_container(ENET_ADDR_CONT_ENTRY
2490 (dequeue(&ugeth->group_hash_q)));
2491 while (!list_empty(&ugeth->ind_hash_q))
2492 put_enet_addr_container(ENET_ADDR_CONT_ENTRY
2493 (dequeue(&ugeth->ind_hash_q)));
2494
2495}
2496
2497static void ucc_geth_set_multi(struct net_device *dev)
2498{
2499 ucc_geth_private_t *ugeth;
2500 struct dev_mc_list *dmi;
2501 ucc_fast_t *uf_regs;
2502 ucc_geth_82xx_address_filtering_pram_t *p_82xx_addr_filt;
2503 enet_addr_t tempaddr;
2504 u8 *mcptr, *tdptr;
2505 int i, j;
2506
2507 ugeth = netdev_priv(dev);
2508
2509 uf_regs = ugeth->uccf->uf_regs;
2510
2511 if (dev->flags & IFF_PROMISC) {
2512
2513 /* Log any net taps. */
2514 printk("%s: Promiscuous mode enabled.\n", dev->name);
2515 uf_regs->upsmr |= UPSMR_PRO;
2516
2517 } else {
2518
2519 uf_regs->upsmr &= ~UPSMR_PRO;
2520
2521 p_82xx_addr_filt =
2522 (ucc_geth_82xx_address_filtering_pram_t *) ugeth->
2523 p_rx_glbl_pram->addressfiltering;
2524
2525 if (dev->flags & IFF_ALLMULTI) {
2526 /* Catch all multicast addresses, so set the
2527 * filter to all 1's.
2528 */
2529 out_be32(&p_82xx_addr_filt->gaddr_h, 0xffffffff);
2530 out_be32(&p_82xx_addr_filt->gaddr_l, 0xffffffff);
2531 } else {
2532 /* Clear filter and add the addresses in the list.
2533 */
2534 out_be32(&p_82xx_addr_filt->gaddr_h, 0x0);
2535 out_be32(&p_82xx_addr_filt->gaddr_l, 0x0);
2536
2537 dmi = dev->mc_list;
2538
2539 for (i = 0; i < dev->mc_count; i++, dmi = dmi->next) {
2540
2541 /* Only support group multicast for now.
2542 */
2543 if (!(dmi->dmi_addr[0] & 1))
2544 continue;
2545
2546 /* The address in dmi_addr is LSB first,
2547 * and taddr is MSB first. We have to
2548 * copy bytes MSB first from dmi_addr.
2549 */
2550 mcptr = (u8 *) dmi->dmi_addr + 5;
2551 tdptr = (u8 *) & tempaddr;
2552 for (j = 0; j < 6; j++)
2553 *tdptr++ = *mcptr--;
2554
2555 /* Ask CPM to run CRC and set bit in
2556 * filter mask.
2557 */
2558 hw_add_addr_in_hash(ugeth, &tempaddr);
2559
2560 }
2561 }
2562 }
2563}
2564
2565static void ucc_geth_stop(ucc_geth_private_t *ugeth)
2566{
2567 ucc_geth_t *ug_regs = ugeth->ug_regs;
2568 u32 tempval;
2569
2570 ugeth_vdbg("%s: IN", __FUNCTION__);
2571
2572 /* Disable the controller */
2573 ugeth_disable(ugeth, COMM_DIR_RX_AND_TX);
2574
2575 /* Tell the kernel the link is down */
2576 ugeth->mii_info->link = 0;
2577 adjust_link(ugeth->dev);
2578
2579 /* Mask all interrupts */
2580 out_be32(ugeth->uccf->p_ucce, 0x00000000);
2581
2582 /* Clear all interrupts */
2583 out_be32(ugeth->uccf->p_ucce, 0xffffffff);
2584
2585 /* Disable Rx and Tx */
2586 tempval = in_be32(&ug_regs->maccfg1);
2587 tempval &= ~(MACCFG1_ENABLE_RX | MACCFG1_ENABLE_TX);
2588 out_be32(&ug_regs->maccfg1, tempval);
2589
2590 if (ugeth->ug_info->board_flags & FSL_UGETH_BRD_HAS_PHY_INTR) {
2591 /* Clear any pending interrupts */
2592 mii_clear_phy_interrupt(ugeth->mii_info);
2593
2594 /* Disable PHY Interrupts */
2595 mii_configure_phy_interrupt(ugeth->mii_info,
2596 MII_INTERRUPT_DISABLED);
2597 }
2598
2599 free_irq(ugeth->ug_info->uf_info.irq, ugeth->dev);
2600
2601 if (ugeth->ug_info->board_flags & FSL_UGETH_BRD_HAS_PHY_INTR) {
2602 free_irq(ugeth->ug_info->phy_interrupt, ugeth->dev);
2603 } else {
2604 del_timer_sync(&ugeth->phy_info_timer);
2605 }
2606
2607 ucc_geth_memclean(ugeth);
2608}
2609
2610static int ucc_geth_startup(ucc_geth_private_t *ugeth)
2611{
2612 ucc_geth_82xx_address_filtering_pram_t *p_82xx_addr_filt;
2613 ucc_geth_init_pram_t *p_init_enet_pram;
2614 ucc_fast_private_t *uccf;
2615 ucc_geth_info_t *ug_info;
2616 ucc_fast_info_t *uf_info;
2617 ucc_fast_t *uf_regs;
2618 ucc_geth_t *ug_regs;
2619 int ret_val = -EINVAL;
2620 u32 remoder = UCC_GETH_REMODER_INIT;
2621 u32 init_enet_pram_offset, cecr_subblock, command, maccfg1;
2622 u32 ifstat, i, j, size, l2qt, l3qt, length;
2623 u16 temoder = UCC_GETH_TEMODER_INIT;
2624 u16 test;
2625 u8 function_code = 0;
2626 u8 *bd, *endOfRing;
2627 u8 numThreadsRxNumerical, numThreadsTxNumerical;
2628
2629 ugeth_vdbg("%s: IN", __FUNCTION__);
2630
2631 ug_info = ugeth->ug_info;
2632 uf_info = &ug_info->uf_info;
2633
2634 if (!((uf_info->bd_mem_part == MEM_PART_SYSTEM) ||
2635 (uf_info->bd_mem_part == MEM_PART_MURAM))) {
2636 ugeth_err("%s: Bad memory partition value.", __FUNCTION__);
2637 return -EINVAL;
2638 }
2639
2640 /* Rx BD lengths */
2641 for (i = 0; i < ug_info->numQueuesRx; i++) {
2642 if ((ug_info->bdRingLenRx[i] < UCC_GETH_RX_BD_RING_SIZE_MIN) ||
2643 (ug_info->bdRingLenRx[i] %
2644 UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT)) {
2645 ugeth_err
2646 ("%s: Rx BD ring length must be multiple of 4,"
2647 " no smaller than 8.", __FUNCTION__);
2648 return -EINVAL;
2649 }
2650 }
2651
2652 /* Tx BD lengths */
2653 for (i = 0; i < ug_info->numQueuesTx; i++) {
2654 if (ug_info->bdRingLenTx[i] < UCC_GETH_TX_BD_RING_SIZE_MIN) {
2655 ugeth_err
2656 ("%s: Tx BD ring length must be no smaller than 2.",
2657 __FUNCTION__);
2658 return -EINVAL;
2659 }
2660 }
2661
2662 /* mrblr */
2663 if ((uf_info->max_rx_buf_length == 0) ||
2664 (uf_info->max_rx_buf_length % UCC_GETH_MRBLR_ALIGNMENT)) {
2665 ugeth_err
2666 ("%s: max_rx_buf_length must be non-zero multiple of 128.",
2667 __FUNCTION__);
2668 return -EINVAL;
2669 }
2670
2671 /* num Tx queues */
2672 if (ug_info->numQueuesTx > NUM_TX_QUEUES) {
2673 ugeth_err("%s: number of tx queues too large.", __FUNCTION__);
2674 return -EINVAL;
2675 }
2676
2677 /* num Rx queues */
2678 if (ug_info->numQueuesRx > NUM_RX_QUEUES) {
2679 ugeth_err("%s: number of rx queues too large.", __FUNCTION__);
2680 return -EINVAL;
2681 }
2682
2683 /* l2qt */
2684 for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++) {
2685 if (ug_info->l2qt[i] >= ug_info->numQueuesRx) {
2686 ugeth_err
2687 ("%s: VLAN priority table entry must not be"
2688 " larger than number of Rx queues.",
2689 __FUNCTION__);
2690 return -EINVAL;
2691 }
2692 }
2693
2694 /* l3qt */
2695 for (i = 0; i < UCC_GETH_IP_PRIORITY_MAX; i++) {
2696 if (ug_info->l3qt[i] >= ug_info->numQueuesRx) {
2697 ugeth_err
2698 ("%s: IP priority table entry must not be"
2699 " larger than number of Rx queues.",
2700 __FUNCTION__);
2701 return -EINVAL;
2702 }
2703 }
2704
2705 if (ug_info->cam && !ug_info->ecamptr) {
2706 ugeth_err("%s: If cam mode is chosen, must supply cam ptr.",
2707 __FUNCTION__);
2708 return -EINVAL;
2709 }
2710
2711 if ((ug_info->numStationAddresses !=
2712 UCC_GETH_NUM_OF_STATION_ADDRESSES_1)
2713 && ug_info->rxExtendedFiltering) {
2714 ugeth_err("%s: Number of station addresses greater than 1 "
2715 "not allowed in extended parsing mode.",
2716 __FUNCTION__);
2717 return -EINVAL;
2718 }
2719
2720 /* Generate uccm_mask for receive */
2721 uf_info->uccm_mask = ug_info->eventRegMask & UCCE_OTHER;/* Errors */
2722 for (i = 0; i < ug_info->numQueuesRx; i++)
2723 uf_info->uccm_mask |= (UCCE_RXBF_SINGLE_MASK << i);
2724
2725 for (i = 0; i < ug_info->numQueuesTx; i++)
2726 uf_info->uccm_mask |= (UCCE_TXBF_SINGLE_MASK << i);
2727 /* Initialize the general fast UCC block. */
2728 if (ucc_fast_init(uf_info, &uccf)) {
2729 ugeth_err("%s: Failed to init uccf.", __FUNCTION__);
2730 ucc_geth_memclean(ugeth);
2731 return -ENOMEM;
2732 }
2733 ugeth->uccf = uccf;
2734
2735 switch (ug_info->numThreadsRx) {
2736 case UCC_GETH_NUM_OF_THREADS_1:
2737 numThreadsRxNumerical = 1;
2738 break;
2739 case UCC_GETH_NUM_OF_THREADS_2:
2740 numThreadsRxNumerical = 2;
2741 break;
2742 case UCC_GETH_NUM_OF_THREADS_4:
2743 numThreadsRxNumerical = 4;
2744 break;
2745 case UCC_GETH_NUM_OF_THREADS_6:
2746 numThreadsRxNumerical = 6;
2747 break;
2748 case UCC_GETH_NUM_OF_THREADS_8:
2749 numThreadsRxNumerical = 8;
2750 break;
2751 default:
2752 ugeth_err("%s: Bad number of Rx threads value.", __FUNCTION__);
2753 ucc_geth_memclean(ugeth);
2754 return -EINVAL;
2755 break;
2756 }
2757
2758 switch (ug_info->numThreadsTx) {
2759 case UCC_GETH_NUM_OF_THREADS_1:
2760 numThreadsTxNumerical = 1;
2761 break;
2762 case UCC_GETH_NUM_OF_THREADS_2:
2763 numThreadsTxNumerical = 2;
2764 break;
2765 case UCC_GETH_NUM_OF_THREADS_4:
2766 numThreadsTxNumerical = 4;
2767 break;
2768 case UCC_GETH_NUM_OF_THREADS_6:
2769 numThreadsTxNumerical = 6;
2770 break;
2771 case UCC_GETH_NUM_OF_THREADS_8:
2772 numThreadsTxNumerical = 8;
2773 break;
2774 default:
2775 ugeth_err("%s: Bad number of Tx threads value.", __FUNCTION__);
2776 ucc_geth_memclean(ugeth);
2777 return -EINVAL;
2778 break;
2779 }
2780
2781 /* Calculate rx_extended_features */
2782 ugeth->rx_non_dynamic_extended_features = ug_info->ipCheckSumCheck ||
2783 ug_info->ipAddressAlignment ||
2784 (ug_info->numStationAddresses !=
2785 UCC_GETH_NUM_OF_STATION_ADDRESSES_1);
2786
2787 ugeth->rx_extended_features = ugeth->rx_non_dynamic_extended_features ||
2788 (ug_info->vlanOperationTagged != UCC_GETH_VLAN_OPERATION_TAGGED_NOP)
2789 || (ug_info->vlanOperationNonTagged !=
2790 UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP);
2791
2792 uf_regs = uccf->uf_regs;
2793 ug_regs = (ucc_geth_t *) (uccf->uf_regs);
2794 ugeth->ug_regs = ug_regs;
2795
2796 init_default_reg_vals(&uf_regs->upsmr,
2797 &ug_regs->maccfg1, &ug_regs->maccfg2);
2798
2799 /* Set UPSMR */
2800 /* For more details see the hardware spec. */
2801 init_rx_parameters(ug_info->bro,
2802 ug_info->rsh, ug_info->pro, &uf_regs->upsmr);
2803
2804 /* We're going to ignore other registers for now, */
2805 /* except as needed to get up and running */
2806
2807 /* Set MACCFG1 */
2808 /* For more details see the hardware spec. */
2809 init_flow_control_params(ug_info->aufc,
2810 ug_info->receiveFlowControl,
2811 1,
2812 ug_info->pausePeriod,
2813 ug_info->extensionField,
2814 &uf_regs->upsmr,
2815 &ug_regs->uempr, &ug_regs->maccfg1);
2816
2817 maccfg1 = in_be32(&ug_regs->maccfg1);
2818 maccfg1 |= MACCFG1_ENABLE_RX;
2819 maccfg1 |= MACCFG1_ENABLE_TX;
2820 out_be32(&ug_regs->maccfg1, maccfg1);
2821
2822 /* Set IPGIFG */
2823 /* For more details see the hardware spec. */
2824 ret_val = init_inter_frame_gap_params(ug_info->nonBackToBackIfgPart1,
2825 ug_info->nonBackToBackIfgPart2,
2826 ug_info->
2827 miminumInterFrameGapEnforcement,
2828 ug_info->backToBackInterFrameGap,
2829 &ug_regs->ipgifg);
2830 if (ret_val != 0) {
2831 ugeth_err("%s: IPGIFG initialization parameter too large.",
2832 __FUNCTION__);
2833 ucc_geth_memclean(ugeth);
2834 return ret_val;
2835 }
2836
2837 /* Set HAFDUP */
2838 /* For more details see the hardware spec. */
2839 ret_val = init_half_duplex_params(ug_info->altBeb,
2840 ug_info->backPressureNoBackoff,
2841 ug_info->noBackoff,
2842 ug_info->excessDefer,
2843 ug_info->altBebTruncation,
2844 ug_info->maxRetransmission,
2845 ug_info->collisionWindow,
2846 &ug_regs->hafdup);
2847 if (ret_val != 0) {
2848 ugeth_err("%s: Half Duplex initialization parameter too large.",
2849 __FUNCTION__);
2850 ucc_geth_memclean(ugeth);
2851 return ret_val;
2852 }
2853
2854 /* Set IFSTAT */
2855 /* For more details see the hardware spec. */
2856 /* Read only - resets upon read */
2857 ifstat = in_be32(&ug_regs->ifstat);
2858
2859 /* Clear UEMPR */
2860 /* For more details see the hardware spec. */
2861 out_be32(&ug_regs->uempr, 0);
2862
2863 /* Set UESCR */
2864 /* For more details see the hardware spec. */
2865 init_hw_statistics_gathering_mode((ug_info->statisticsMode &
2866 UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE),
2867 0, &uf_regs->upsmr, &ug_regs->uescr);
2868
2869 /* Allocate Tx bds */
2870 for (j = 0; j < ug_info->numQueuesTx; j++) {
2871 /* Allocate in multiple of
2872 UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT,
2873 according to spec */
2874 length = ((ug_info->bdRingLenTx[j] * UCC_GETH_SIZE_OF_BD)
2875 / UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
2876 * UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
2877 if ((ug_info->bdRingLenTx[j] * UCC_GETH_SIZE_OF_BD) %
2878 UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT)
2879 length += UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT;
2880 if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
2881 u32 align = 4;
2882 if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
2883 align = UCC_GETH_TX_BD_RING_ALIGNMENT;
2884 ugeth->tx_bd_ring_offset[j] =
2885 (u32) (kmalloc((u32) (length + align),
2886 GFP_KERNEL));
2887 if (ugeth->tx_bd_ring_offset[j] != 0)
2888 ugeth->p_tx_bd_ring[j] =
2889 (void*)((ugeth->tx_bd_ring_offset[j] +
2890 align) & ~(align - 1));
2891 } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
2892 ugeth->tx_bd_ring_offset[j] =
2893 qe_muram_alloc(length,
2894 UCC_GETH_TX_BD_RING_ALIGNMENT);
2895 if (!IS_MURAM_ERR(ugeth->tx_bd_ring_offset[j]))
2896 ugeth->p_tx_bd_ring[j] =
2897 (u8 *) qe_muram_addr(ugeth->
2898 tx_bd_ring_offset[j]);
2899 }
2900 if (!ugeth->p_tx_bd_ring[j]) {
2901 ugeth_err
2902 ("%s: Can not allocate memory for Tx bd rings.",
2903 __FUNCTION__);
2904 ucc_geth_memclean(ugeth);
2905 return -ENOMEM;
2906 }
2907 /* Zero unused end of bd ring, according to spec */
2908 memset(ugeth->p_tx_bd_ring[j] +
2909 ug_info->bdRingLenTx[j] * UCC_GETH_SIZE_OF_BD, 0,
2910 length - ug_info->bdRingLenTx[j] * UCC_GETH_SIZE_OF_BD);
2911 }
2912
2913 /* Allocate Rx bds */
2914 for (j = 0; j < ug_info->numQueuesRx; j++) {
2915 length = ug_info->bdRingLenRx[j] * UCC_GETH_SIZE_OF_BD;
2916 if (uf_info->bd_mem_part == MEM_PART_SYSTEM) {
2917 u32 align = 4;
2918 if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
2919 align = UCC_GETH_RX_BD_RING_ALIGNMENT;
2920 ugeth->rx_bd_ring_offset[j] =
2921 (u32) (kmalloc((u32) (length + align), GFP_KERNEL));
2922 if (ugeth->rx_bd_ring_offset[j] != 0)
2923 ugeth->p_rx_bd_ring[j] =
2924 (void*)((ugeth->rx_bd_ring_offset[j] +
2925 align) & ~(align - 1));
2926 } else if (uf_info->bd_mem_part == MEM_PART_MURAM) {
2927 ugeth->rx_bd_ring_offset[j] =
2928 qe_muram_alloc(length,
2929 UCC_GETH_RX_BD_RING_ALIGNMENT);
2930 if (!IS_MURAM_ERR(ugeth->rx_bd_ring_offset[j]))
2931 ugeth->p_rx_bd_ring[j] =
2932 (u8 *) qe_muram_addr(ugeth->
2933 rx_bd_ring_offset[j]);
2934 }
2935 if (!ugeth->p_rx_bd_ring[j]) {
2936 ugeth_err
2937 ("%s: Can not allocate memory for Rx bd rings.",
2938 __FUNCTION__);
2939 ucc_geth_memclean(ugeth);
2940 return -ENOMEM;
2941 }
2942 }
2943
2944 /* Init Tx bds */
2945 for (j = 0; j < ug_info->numQueuesTx; j++) {
2946 /* Setup the skbuff rings */
2947 ugeth->tx_skbuff[j] =
2948 (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
2949 ugeth->ug_info->bdRingLenTx[j],
2950 GFP_KERNEL);
2951
2952 if (ugeth->tx_skbuff[j] == NULL) {
2953 ugeth_err("%s: Could not allocate tx_skbuff",
2954 __FUNCTION__);
2955 ucc_geth_memclean(ugeth);
2956 return -ENOMEM;
2957 }
2958
2959 for (i = 0; i < ugeth->ug_info->bdRingLenTx[j]; i++)
2960 ugeth->tx_skbuff[j][i] = NULL;
2961
2962 ugeth->skb_curtx[j] = ugeth->skb_dirtytx[j] = 0;
2963 bd = ugeth->confBd[j] = ugeth->txBd[j] = ugeth->p_tx_bd_ring[j];
2964 for (i = 0; i < ug_info->bdRingLenTx[j]; i++) {
2965 BD_BUFFER_CLEAR(bd);
2966 BD_STATUS_AND_LENGTH_SET(bd, 0);
2967 bd += UCC_GETH_SIZE_OF_BD;
2968 }
2969 bd -= UCC_GETH_SIZE_OF_BD;
2970 BD_STATUS_AND_LENGTH_SET(bd, T_W);/* for last BD set Wrap bit */
2971 }
2972
2973 /* Init Rx bds */
2974 for (j = 0; j < ug_info->numQueuesRx; j++) {
2975 /* Setup the skbuff rings */
2976 ugeth->rx_skbuff[j] =
2977 (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
2978 ugeth->ug_info->bdRingLenRx[j],
2979 GFP_KERNEL);
2980
2981 if (ugeth->rx_skbuff[j] == NULL) {
2982 ugeth_err("%s: Could not allocate rx_skbuff",
2983 __FUNCTION__);
2984 ucc_geth_memclean(ugeth);
2985 return -ENOMEM;
2986 }
2987
2988 for (i = 0; i < ugeth->ug_info->bdRingLenRx[j]; i++)
2989 ugeth->rx_skbuff[j][i] = NULL;
2990
2991 ugeth->skb_currx[j] = 0;
2992 bd = ugeth->rxBd[j] = ugeth->p_rx_bd_ring[j];
2993 for (i = 0; i < ug_info->bdRingLenRx[j]; i++) {
2994 BD_STATUS_AND_LENGTH_SET(bd, R_I);
2995 BD_BUFFER_CLEAR(bd);
2996 bd += UCC_GETH_SIZE_OF_BD;
2997 }
2998 bd -= UCC_GETH_SIZE_OF_BD;
2999 BD_STATUS_AND_LENGTH_SET(bd, R_W);/* for last BD set Wrap bit */
3000 }
3001
3002 /*
3003 * Global PRAM
3004 */
3005 /* Tx global PRAM */
3006 /* Allocate global tx parameter RAM page */
3007 ugeth->tx_glbl_pram_offset =
3008 qe_muram_alloc(sizeof(ucc_geth_tx_global_pram_t),
3009 UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT);
3010 if (IS_MURAM_ERR(ugeth->tx_glbl_pram_offset)) {
3011 ugeth_err
3012 ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.",
3013 __FUNCTION__);
3014 ucc_geth_memclean(ugeth);
3015 return -ENOMEM;
3016 }
3017 ugeth->p_tx_glbl_pram =
3018 (ucc_geth_tx_global_pram_t *) qe_muram_addr(ugeth->
3019 tx_glbl_pram_offset);
3020 /* Zero out p_tx_glbl_pram */
3021 memset(ugeth->p_tx_glbl_pram, 0, sizeof(ucc_geth_tx_global_pram_t));
3022
3023 /* Fill global PRAM */
3024
3025 /* TQPTR */
3026 /* Size varies with number of Tx threads */
3027 ugeth->thread_dat_tx_offset =
3028 qe_muram_alloc(numThreadsTxNumerical *
3029 sizeof(ucc_geth_thread_data_tx_t) +
3030 32 * (numThreadsTxNumerical == 1),
3031 UCC_GETH_THREAD_DATA_ALIGNMENT);
3032 if (IS_MURAM_ERR(ugeth->thread_dat_tx_offset)) {
3033 ugeth_err
3034 ("%s: Can not allocate DPRAM memory for p_thread_data_tx.",
3035 __FUNCTION__);
3036 ucc_geth_memclean(ugeth);
3037 return -ENOMEM;
3038 }
3039
3040 ugeth->p_thread_data_tx =
3041 (ucc_geth_thread_data_tx_t *) qe_muram_addr(ugeth->
3042 thread_dat_tx_offset);
3043 out_be32(&ugeth->p_tx_glbl_pram->tqptr, ugeth->thread_dat_tx_offset);
3044
3045 /* vtagtable */
3046 for (i = 0; i < UCC_GETH_TX_VTAG_TABLE_ENTRY_MAX; i++)
3047 out_be32(&ugeth->p_tx_glbl_pram->vtagtable[i],
3048 ug_info->vtagtable[i]);
3049
3050 /* iphoffset */
3051 for (i = 0; i < TX_IP_OFFSET_ENTRY_MAX; i++)
3052 ugeth->p_tx_glbl_pram->iphoffset[i] = ug_info->iphoffset[i];
3053
3054 /* SQPTR */
3055 /* Size varies with number of Tx queues */
3056 ugeth->send_q_mem_reg_offset =
3057 qe_muram_alloc(ug_info->numQueuesTx *
3058 sizeof(ucc_geth_send_queue_qd_t),
3059 UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT);
3060 if (IS_MURAM_ERR(ugeth->send_q_mem_reg_offset)) {
3061 ugeth_err
3062 ("%s: Can not allocate DPRAM memory for p_send_q_mem_reg.",
3063 __FUNCTION__);
3064 ucc_geth_memclean(ugeth);
3065 return -ENOMEM;
3066 }
3067
3068 ugeth->p_send_q_mem_reg =
3069 (ucc_geth_send_queue_mem_region_t *) qe_muram_addr(ugeth->
3070 send_q_mem_reg_offset);
3071 out_be32(&ugeth->p_tx_glbl_pram->sqptr, ugeth->send_q_mem_reg_offset);
3072
3073 /* Setup the table */
3074 /* Assume BD rings are already established */
3075 for (i = 0; i < ug_info->numQueuesTx; i++) {
3076 endOfRing =
3077 ugeth->p_tx_bd_ring[i] + (ug_info->bdRingLenTx[i] -
3078 1) * UCC_GETH_SIZE_OF_BD;
3079 if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
3080 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
3081 (u32) virt_to_phys(ugeth->p_tx_bd_ring[i]));
3082 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
3083 last_bd_completed_address,
3084 (u32) virt_to_phys(endOfRing));
3085 } else if (ugeth->ug_info->uf_info.bd_mem_part ==
3086 MEM_PART_MURAM) {
3087 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].bd_ring_base,
3088 (u32) immrbar_virt_to_phys(ugeth->
3089 p_tx_bd_ring[i]));
3090 out_be32(&ugeth->p_send_q_mem_reg->sqqd[i].
3091 last_bd_completed_address,
3092 (u32) immrbar_virt_to_phys(endOfRing));
3093 }
3094 }
3095
3096 /* schedulerbasepointer */
3097
3098 if (ug_info->numQueuesTx > 1) {
3099 /* scheduler exists only if more than 1 tx queue */
3100 ugeth->scheduler_offset =
3101 qe_muram_alloc(sizeof(ucc_geth_scheduler_t),
3102 UCC_GETH_SCHEDULER_ALIGNMENT);
3103 if (IS_MURAM_ERR(ugeth->scheduler_offset)) {
3104 ugeth_err
3105 ("%s: Can not allocate DPRAM memory for p_scheduler.",
3106 __FUNCTION__);
3107 ucc_geth_memclean(ugeth);
3108 return -ENOMEM;
3109 }
3110
3111 ugeth->p_scheduler =
3112 (ucc_geth_scheduler_t *) qe_muram_addr(ugeth->
3113 scheduler_offset);
3114 out_be32(&ugeth->p_tx_glbl_pram->schedulerbasepointer,
3115 ugeth->scheduler_offset);
3116 /* Zero out p_scheduler */
3117 memset(ugeth->p_scheduler, 0, sizeof(ucc_geth_scheduler_t));
3118
3119 /* Set values in scheduler */
3120 out_be32(&ugeth->p_scheduler->mblinterval,
3121 ug_info->mblinterval);
3122 out_be16(&ugeth->p_scheduler->nortsrbytetime,
3123 ug_info->nortsrbytetime);
3124 ugeth->p_scheduler->fracsiz = ug_info->fracsiz;
3125 ugeth->p_scheduler->strictpriorityq = ug_info->strictpriorityq;
3126 ugeth->p_scheduler->txasap = ug_info->txasap;
3127 ugeth->p_scheduler->extrabw = ug_info->extrabw;
3128 for (i = 0; i < NUM_TX_QUEUES; i++)
3129 ugeth->p_scheduler->weightfactor[i] =
3130 ug_info->weightfactor[i];
3131
3132 /* Set pointers to cpucount registers in scheduler */
3133 ugeth->p_cpucount[0] = &(ugeth->p_scheduler->cpucount0);
3134 ugeth->p_cpucount[1] = &(ugeth->p_scheduler->cpucount1);
3135 ugeth->p_cpucount[2] = &(ugeth->p_scheduler->cpucount2);
3136 ugeth->p_cpucount[3] = &(ugeth->p_scheduler->cpucount3);
3137 ugeth->p_cpucount[4] = &(ugeth->p_scheduler->cpucount4);
3138 ugeth->p_cpucount[5] = &(ugeth->p_scheduler->cpucount5);
3139 ugeth->p_cpucount[6] = &(ugeth->p_scheduler->cpucount6);
3140 ugeth->p_cpucount[7] = &(ugeth->p_scheduler->cpucount7);
3141 }
3142
3143 /* schedulerbasepointer */
3144 /* TxRMON_PTR (statistics) */
3145 if (ug_info->
3146 statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
3147 ugeth->tx_fw_statistics_pram_offset =
3148 qe_muram_alloc(sizeof
3149 (ucc_geth_tx_firmware_statistics_pram_t),
3150 UCC_GETH_TX_STATISTICS_ALIGNMENT);
3151 if (IS_MURAM_ERR(ugeth->tx_fw_statistics_pram_offset)) {
3152 ugeth_err
3153 ("%s: Can not allocate DPRAM memory for"
3154 " p_tx_fw_statistics_pram.", __FUNCTION__);
3155 ucc_geth_memclean(ugeth);
3156 return -ENOMEM;
3157 }
3158 ugeth->p_tx_fw_statistics_pram =
3159 (ucc_geth_tx_firmware_statistics_pram_t *)
3160 qe_muram_addr(ugeth->tx_fw_statistics_pram_offset);
3161 /* Zero out p_tx_fw_statistics_pram */
3162 memset(ugeth->p_tx_fw_statistics_pram,
3163 0, sizeof(ucc_geth_tx_firmware_statistics_pram_t));
3164 }
3165
3166 /* temoder */
3167 /* Already has speed set */
3168
3169 if (ug_info->numQueuesTx > 1)
3170 temoder |= TEMODER_SCHEDULER_ENABLE;
3171 if (ug_info->ipCheckSumGenerate)
3172 temoder |= TEMODER_IP_CHECKSUM_GENERATE;
3173 temoder |= ((ug_info->numQueuesTx - 1) << TEMODER_NUM_OF_QUEUES_SHIFT);
3174 out_be16(&ugeth->p_tx_glbl_pram->temoder, temoder);
3175
3176 test = in_be16(&ugeth->p_tx_glbl_pram->temoder);
3177
3178 /* Function code register value to be used later */
3179 function_code = QE_BMR_BYTE_ORDER_BO_MOT | UCC_FAST_FUNCTION_CODE_GBL;
3180 /* Required for QE */
3181
3182 /* function code register */
3183 out_be32(&ugeth->p_tx_glbl_pram->tstate, ((u32) function_code) << 24);
3184
3185 /* Rx global PRAM */
3186 /* Allocate global rx parameter RAM page */
3187 ugeth->rx_glbl_pram_offset =
3188 qe_muram_alloc(sizeof(ucc_geth_rx_global_pram_t),
3189 UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT);
3190 if (IS_MURAM_ERR(ugeth->rx_glbl_pram_offset)) {
3191 ugeth_err
3192 ("%s: Can not allocate DPRAM memory for p_rx_glbl_pram.",
3193 __FUNCTION__);
3194 ucc_geth_memclean(ugeth);
3195 return -ENOMEM;
3196 }
3197 ugeth->p_rx_glbl_pram =
3198 (ucc_geth_rx_global_pram_t *) qe_muram_addr(ugeth->
3199 rx_glbl_pram_offset);
3200 /* Zero out p_rx_glbl_pram */
3201 memset(ugeth->p_rx_glbl_pram, 0, sizeof(ucc_geth_rx_global_pram_t));
3202
3203 /* Fill global PRAM */
3204
3205 /* RQPTR */
3206 /* Size varies with number of Rx threads */
3207 ugeth->thread_dat_rx_offset =
3208 qe_muram_alloc(numThreadsRxNumerical *
3209 sizeof(ucc_geth_thread_data_rx_t),
3210 UCC_GETH_THREAD_DATA_ALIGNMENT);
3211 if (IS_MURAM_ERR(ugeth->thread_dat_rx_offset)) {
3212 ugeth_err
3213 ("%s: Can not allocate DPRAM memory for p_thread_data_rx.",
3214 __FUNCTION__);
3215 ucc_geth_memclean(ugeth);
3216 return -ENOMEM;
3217 }
3218
3219 ugeth->p_thread_data_rx =
3220 (ucc_geth_thread_data_rx_t *) qe_muram_addr(ugeth->
3221 thread_dat_rx_offset);
3222 out_be32(&ugeth->p_rx_glbl_pram->rqptr, ugeth->thread_dat_rx_offset);
3223
3224 /* typeorlen */
3225 out_be16(&ugeth->p_rx_glbl_pram->typeorlen, ug_info->typeorlen);
3226
3227 /* rxrmonbaseptr (statistics) */
3228 if (ug_info->
3229 statisticsMode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
3230 ugeth->rx_fw_statistics_pram_offset =
3231 qe_muram_alloc(sizeof
3232 (ucc_geth_rx_firmware_statistics_pram_t),
3233 UCC_GETH_RX_STATISTICS_ALIGNMENT);
3234 if (IS_MURAM_ERR(ugeth->rx_fw_statistics_pram_offset)) {
3235 ugeth_err
3236 ("%s: Can not allocate DPRAM memory for"
3237 " p_rx_fw_statistics_pram.", __FUNCTION__);
3238 ucc_geth_memclean(ugeth);
3239 return -ENOMEM;
3240 }
3241 ugeth->p_rx_fw_statistics_pram =
3242 (ucc_geth_rx_firmware_statistics_pram_t *)
3243 qe_muram_addr(ugeth->rx_fw_statistics_pram_offset);
3244 /* Zero out p_rx_fw_statistics_pram */
3245 memset(ugeth->p_rx_fw_statistics_pram, 0,
3246 sizeof(ucc_geth_rx_firmware_statistics_pram_t));
3247 }
3248
3249 /* intCoalescingPtr */
3250
3251 /* Size varies with number of Rx queues */
3252 ugeth->rx_irq_coalescing_tbl_offset =
3253 qe_muram_alloc(ug_info->numQueuesRx *
3254 sizeof(ucc_geth_rx_interrupt_coalescing_entry_t),
3255 UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT);
3256 if (IS_MURAM_ERR(ugeth->rx_irq_coalescing_tbl_offset)) {
3257 ugeth_err
3258 ("%s: Can not allocate DPRAM memory for"
3259 " p_rx_irq_coalescing_tbl.", __FUNCTION__);
3260 ucc_geth_memclean(ugeth);
3261 return -ENOMEM;
3262 }
3263
3264 ugeth->p_rx_irq_coalescing_tbl =
3265 (ucc_geth_rx_interrupt_coalescing_table_t *)
3266 qe_muram_addr(ugeth->rx_irq_coalescing_tbl_offset);
3267 out_be32(&ugeth->p_rx_glbl_pram->intcoalescingptr,
3268 ugeth->rx_irq_coalescing_tbl_offset);
3269
3270 /* Fill interrupt coalescing table */
3271 for (i = 0; i < ug_info->numQueuesRx; i++) {
3272 out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
3273 interruptcoalescingmaxvalue,
3274 ug_info->interruptcoalescingmaxvalue[i]);
3275 out_be32(&ugeth->p_rx_irq_coalescing_tbl->coalescingentry[i].
3276 interruptcoalescingcounter,
3277 ug_info->interruptcoalescingmaxvalue[i]);
3278 }
3279
3280 /* MRBLR */
3281 init_max_rx_buff_len(uf_info->max_rx_buf_length,
3282 &ugeth->p_rx_glbl_pram->mrblr);
3283 /* MFLR */
3284 out_be16(&ugeth->p_rx_glbl_pram->mflr, ug_info->maxFrameLength);
3285 /* MINFLR */
3286 init_min_frame_len(ug_info->minFrameLength,
3287 &ugeth->p_rx_glbl_pram->minflr,
3288 &ugeth->p_rx_glbl_pram->mrblr);
3289 /* MAXD1 */
3290 out_be16(&ugeth->p_rx_glbl_pram->maxd1, ug_info->maxD1Length);
3291 /* MAXD2 */
3292 out_be16(&ugeth->p_rx_glbl_pram->maxd2, ug_info->maxD2Length);
3293
3294 /* l2qt */
3295 l2qt = 0;
3296 for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++)
3297 l2qt |= (ug_info->l2qt[i] << (28 - 4 * i));
3298 out_be32(&ugeth->p_rx_glbl_pram->l2qt, l2qt);
3299
3300 /* l3qt */
3301 for (j = 0; j < UCC_GETH_IP_PRIORITY_MAX; j += 8) {
3302 l3qt = 0;
3303 for (i = 0; i < 8; i++)
3304 l3qt |= (ug_info->l3qt[j + i] << (28 - 4 * i));
3305 out_be32(&ugeth->p_rx_glbl_pram->l3qt[j], l3qt);
3306 }
3307
3308 /* vlantype */
3309 out_be16(&ugeth->p_rx_glbl_pram->vlantype, ug_info->vlantype);
3310
3311 /* vlantci */
3312 out_be16(&ugeth->p_rx_glbl_pram->vlantci, ug_info->vlantci);
3313
3314 /* ecamptr */
3315 out_be32(&ugeth->p_rx_glbl_pram->ecamptr, ug_info->ecamptr);
3316
3317 /* RBDQPTR */
3318 /* Size varies with number of Rx queues */
3319 ugeth->rx_bd_qs_tbl_offset =
3320 qe_muram_alloc(ug_info->numQueuesRx *
3321 (sizeof(ucc_geth_rx_bd_queues_entry_t) +
3322 sizeof(ucc_geth_rx_prefetched_bds_t)),
3323 UCC_GETH_RX_BD_QUEUES_ALIGNMENT);
3324 if (IS_MURAM_ERR(ugeth->rx_bd_qs_tbl_offset)) {
3325 ugeth_err
3326 ("%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.",
3327 __FUNCTION__);
3328 ucc_geth_memclean(ugeth);
3329 return -ENOMEM;
3330 }
3331
3332 ugeth->p_rx_bd_qs_tbl =
3333 (ucc_geth_rx_bd_queues_entry_t *) qe_muram_addr(ugeth->
3334 rx_bd_qs_tbl_offset);
3335 out_be32(&ugeth->p_rx_glbl_pram->rbdqptr, ugeth->rx_bd_qs_tbl_offset);
3336 /* Zero out p_rx_bd_qs_tbl */
3337 memset(ugeth->p_rx_bd_qs_tbl,
3338 0,
3339 ug_info->numQueuesRx * (sizeof(ucc_geth_rx_bd_queues_entry_t) +
3340 sizeof(ucc_geth_rx_prefetched_bds_t)));
3341
3342 /* Setup the table */
3343 /* Assume BD rings are already established */
3344 for (i = 0; i < ug_info->numQueuesRx; i++) {
3345 if (ugeth->ug_info->uf_info.bd_mem_part == MEM_PART_SYSTEM) {
3346 out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
3347 (u32) virt_to_phys(ugeth->p_rx_bd_ring[i]));
3348 } else if (ugeth->ug_info->uf_info.bd_mem_part ==
3349 MEM_PART_MURAM) {
3350 out_be32(&ugeth->p_rx_bd_qs_tbl[i].externalbdbaseptr,
3351 (u32) immrbar_virt_to_phys(ugeth->
3352 p_rx_bd_ring[i]));
3353 }
3354 /* rest of fields handled by QE */
3355 }
3356
3357 /* remoder */
3358 /* Already has speed set */
3359
3360 if (ugeth->rx_extended_features)
3361 remoder |= REMODER_RX_EXTENDED_FEATURES;
3362 if (ug_info->rxExtendedFiltering)
3363 remoder |= REMODER_RX_EXTENDED_FILTERING;
3364 if (ug_info->dynamicMaxFrameLength)
3365 remoder |= REMODER_DYNAMIC_MAX_FRAME_LENGTH;
3366 if (ug_info->dynamicMinFrameLength)
3367 remoder |= REMODER_DYNAMIC_MIN_FRAME_LENGTH;
3368 remoder |=
3369 ug_info->vlanOperationTagged << REMODER_VLAN_OPERATION_TAGGED_SHIFT;
3370 remoder |=
3371 ug_info->
3372 vlanOperationNonTagged << REMODER_VLAN_OPERATION_NON_TAGGED_SHIFT;
3373 remoder |= ug_info->rxQoSMode << REMODER_RX_QOS_MODE_SHIFT;
3374 remoder |= ((ug_info->numQueuesRx - 1) << REMODER_NUM_OF_QUEUES_SHIFT);
3375 if (ug_info->ipCheckSumCheck)
3376 remoder |= REMODER_IP_CHECKSUM_CHECK;
3377 if (ug_info->ipAddressAlignment)
3378 remoder |= REMODER_IP_ADDRESS_ALIGNMENT;
3379 out_be32(&ugeth->p_rx_glbl_pram->remoder, remoder);
3380
3381 /* Note that this function must be called */
3382 /* ONLY AFTER p_tx_fw_statistics_pram */
3383 /* andp_UccGethRxFirmwareStatisticsPram are allocated ! */
3384 init_firmware_statistics_gathering_mode((ug_info->
3385 statisticsMode &
3386 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX),
3387 (ug_info->statisticsMode &
3388 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX),
3389 &ugeth->p_tx_glbl_pram->txrmonbaseptr,
3390 ugeth->tx_fw_statistics_pram_offset,
3391 &ugeth->p_rx_glbl_pram->rxrmonbaseptr,
3392 ugeth->rx_fw_statistics_pram_offset,
3393 &ugeth->p_tx_glbl_pram->temoder,
3394 &ugeth->p_rx_glbl_pram->remoder);
3395
3396 /* function code register */
3397 ugeth->p_rx_glbl_pram->rstate = function_code;
3398
3399 /* initialize extended filtering */
3400 if (ug_info->rxExtendedFiltering) {
3401 if (!ug_info->extendedFilteringChainPointer) {
3402 ugeth_err("%s: Null Extended Filtering Chain Pointer.",
3403 __FUNCTION__);
3404 ucc_geth_memclean(ugeth);
3405 return -EINVAL;
3406 }
3407
3408 /* Allocate memory for extended filtering Mode Global
3409 Parameters */
3410 ugeth->exf_glbl_param_offset =
3411 qe_muram_alloc(sizeof(ucc_geth_exf_global_pram_t),
3412 UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT);
3413 if (IS_MURAM_ERR(ugeth->exf_glbl_param_offset)) {
3414 ugeth_err
3415 ("%s: Can not allocate DPRAM memory for"
3416 " p_exf_glbl_param.", __FUNCTION__);
3417 ucc_geth_memclean(ugeth);
3418 return -ENOMEM;
3419 }
3420
3421 ugeth->p_exf_glbl_param =
3422 (ucc_geth_exf_global_pram_t *) qe_muram_addr(ugeth->
3423 exf_glbl_param_offset);
3424 out_be32(&ugeth->p_rx_glbl_pram->exfGlobalParam,
3425 ugeth->exf_glbl_param_offset);
3426 out_be32(&ugeth->p_exf_glbl_param->l2pcdptr,
3427 (u32) ug_info->extendedFilteringChainPointer);
3428
3429 } else { /* initialize 82xx style address filtering */
3430
3431 /* Init individual address recognition registers to disabled */
3432
3433 for (j = 0; j < NUM_OF_PADDRS; j++)
3434 ugeth_82xx_filtering_clear_addr_in_paddr(ugeth, (u8) j);
3435
3436 /* Create CQs for hash tables */
3437 if (ug_info->maxGroupAddrInHash > 0) {
3438 INIT_LIST_HEAD(&ugeth->group_hash_q);
3439 }
3440 if (ug_info->maxIndAddrInHash > 0) {
3441 INIT_LIST_HEAD(&ugeth->ind_hash_q);
3442 }
3443 p_82xx_addr_filt =
3444 (ucc_geth_82xx_address_filtering_pram_t *) ugeth->
3445 p_rx_glbl_pram->addressfiltering;
3446
3447 ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
3448 ENET_ADDR_TYPE_GROUP);
3449 ugeth_82xx_filtering_clear_all_addr_in_hash(ugeth,
3450 ENET_ADDR_TYPE_INDIVIDUAL);
3451 }
3452
3453 /*
3454 * Initialize UCC at QE level
3455 */
3456
3457 command = QE_INIT_TX_RX;
3458
3459 /* Allocate shadow InitEnet command parameter structure.
3460 * This is needed because after the InitEnet command is executed,
3461 * the structure in DPRAM is released, because DPRAM is a premium
3462 * resource.
3463 * This shadow structure keeps a copy of what was done so that the
3464 * allocated resources can be released when the channel is freed.
3465 */
3466 if (!(ugeth->p_init_enet_param_shadow =
3467 (ucc_geth_init_pram_t *) kmalloc(sizeof(ucc_geth_init_pram_t),
3468 GFP_KERNEL))) {
3469 ugeth_err
3470 ("%s: Can not allocate memory for"
3471 " p_UccInitEnetParamShadows.", __FUNCTION__);
3472 ucc_geth_memclean(ugeth);
3473 return -ENOMEM;
3474 }
3475 /* Zero out *p_init_enet_param_shadow */
3476 memset((char *)ugeth->p_init_enet_param_shadow,
3477 0, sizeof(ucc_geth_init_pram_t));
3478
3479 /* Fill shadow InitEnet command parameter structure */
3480
3481 ugeth->p_init_enet_param_shadow->resinit1 =
3482 ENET_INIT_PARAM_MAGIC_RES_INIT1;
3483 ugeth->p_init_enet_param_shadow->resinit2 =
3484 ENET_INIT_PARAM_MAGIC_RES_INIT2;
3485 ugeth->p_init_enet_param_shadow->resinit3 =
3486 ENET_INIT_PARAM_MAGIC_RES_INIT3;
3487 ugeth->p_init_enet_param_shadow->resinit4 =
3488 ENET_INIT_PARAM_MAGIC_RES_INIT4;
3489 ugeth->p_init_enet_param_shadow->resinit5 =
3490 ENET_INIT_PARAM_MAGIC_RES_INIT5;
3491 ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
3492 ((u32) ug_info->numThreadsRx) << ENET_INIT_PARAM_RGF_SHIFT;
3493 ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
3494 ((u32) ug_info->numThreadsTx) << ENET_INIT_PARAM_TGF_SHIFT;
3495
3496 ugeth->p_init_enet_param_shadow->rgftgfrxglobal |=
3497 ugeth->rx_glbl_pram_offset | ug_info->riscRx;
3498 if ((ug_info->largestexternallookupkeysize !=
3499 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE)
3500 && (ug_info->largestexternallookupkeysize !=
3501 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
3502 && (ug_info->largestexternallookupkeysize !=
3503 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_16_BYTES)) {
3504 ugeth_err("%s: Invalid largest External Lookup Key Size.",
3505 __FUNCTION__);
3506 ucc_geth_memclean(ugeth);
3507 return -EINVAL;
3508 }
3509 ugeth->p_init_enet_param_shadow->largestexternallookupkeysize =
3510 ug_info->largestexternallookupkeysize;
3511 size = sizeof(ucc_geth_thread_rx_pram_t);
3512 if (ug_info->rxExtendedFiltering) {
3513 size += THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING;
3514 if (ug_info->largestexternallookupkeysize ==
3515 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
3516 size +=
3517 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8;
3518 if (ug_info->largestexternallookupkeysize ==
3519 QE_FLTR_TABLE_LOOKUP_KEY_SIZE_16_BYTES)
3520 size +=
3521 THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16;
3522 }
3523
3524 if ((ret_val = fill_init_enet_entries(ugeth, &(ugeth->
3525 p_init_enet_param_shadow->rxthread[0]),
3526 (u8) (numThreadsRxNumerical + 1)
3527 /* Rx needs one extra for terminator */
3528 , size, UCC_GETH_THREAD_RX_PRAM_ALIGNMENT,
3529 ug_info->riscRx, 1)) != 0) {
3530 ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
3531 __FUNCTION__);
3532 ucc_geth_memclean(ugeth);
3533 return ret_val;
3534 }
3535
3536 ugeth->p_init_enet_param_shadow->txglobal =
3537 ugeth->tx_glbl_pram_offset | ug_info->riscTx;
3538 if ((ret_val =
3539 fill_init_enet_entries(ugeth,
3540 &(ugeth->p_init_enet_param_shadow->
3541 txthread[0]), numThreadsTxNumerical,
3542 sizeof(ucc_geth_thread_tx_pram_t),
3543 UCC_GETH_THREAD_TX_PRAM_ALIGNMENT,
3544 ug_info->riscTx, 0)) != 0) {
3545 ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
3546 __FUNCTION__);
3547 ucc_geth_memclean(ugeth);
3548 return ret_val;
3549 }
3550
3551 /* Load Rx bds with buffers */
3552 for (i = 0; i < ug_info->numQueuesRx; i++) {
3553 if ((ret_val = rx_bd_buffer_set(ugeth, (u8) i)) != 0) {
3554 ugeth_err("%s: Can not fill Rx bds with buffers.",
3555 __FUNCTION__);
3556 ucc_geth_memclean(ugeth);
3557 return ret_val;
3558 }
3559 }
3560
3561 /* Allocate InitEnet command parameter structure */
3562 init_enet_pram_offset = qe_muram_alloc(sizeof(ucc_geth_init_pram_t), 4);
3563 if (IS_MURAM_ERR(init_enet_pram_offset)) {
3564 ugeth_err
3565 ("%s: Can not allocate DPRAM memory for p_init_enet_pram.",
3566 __FUNCTION__);
3567 ucc_geth_memclean(ugeth);
3568 return -ENOMEM;
3569 }
3570 p_init_enet_pram =
3571 (ucc_geth_init_pram_t *) qe_muram_addr(init_enet_pram_offset);
3572
3573 /* Copy shadow InitEnet command parameter structure into PRAM */
3574 p_init_enet_pram->resinit1 = ugeth->p_init_enet_param_shadow->resinit1;
3575 p_init_enet_pram->resinit2 = ugeth->p_init_enet_param_shadow->resinit2;
3576 p_init_enet_pram->resinit3 = ugeth->p_init_enet_param_shadow->resinit3;
3577 p_init_enet_pram->resinit4 = ugeth->p_init_enet_param_shadow->resinit4;
3578 out_be16(&p_init_enet_pram->resinit5,
3579 ugeth->p_init_enet_param_shadow->resinit5);
3580 p_init_enet_pram->largestexternallookupkeysize =
3581 ugeth->p_init_enet_param_shadow->largestexternallookupkeysize;
3582 out_be32(&p_init_enet_pram->rgftgfrxglobal,
3583 ugeth->p_init_enet_param_shadow->rgftgfrxglobal);
3584 for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_RX; i++)
3585 out_be32(&p_init_enet_pram->rxthread[i],
3586 ugeth->p_init_enet_param_shadow->rxthread[i]);
3587 out_be32(&p_init_enet_pram->txglobal,
3588 ugeth->p_init_enet_param_shadow->txglobal);
3589 for (i = 0; i < ENET_INIT_PARAM_MAX_ENTRIES_TX; i++)
3590 out_be32(&p_init_enet_pram->txthread[i],
3591 ugeth->p_init_enet_param_shadow->txthread[i]);
3592
3593 /* Issue QE command */
3594 cecr_subblock =
3595 ucc_fast_get_qe_cr_subblock(ugeth->ug_info->uf_info.ucc_num);
3596 qe_issue_cmd(command, cecr_subblock, (u8) QE_CR_PROTOCOL_ETHERNET,
3597 init_enet_pram_offset);
3598
3599 /* Free InitEnet command parameter */
3600 qe_muram_free(init_enet_pram_offset);
3601
3602 return 0;
3603}
3604
3605/* returns a net_device_stats structure pointer */
3606static struct net_device_stats *ucc_geth_get_stats(struct net_device *dev)
3607{
3608 ucc_geth_private_t *ugeth = netdev_priv(dev);
3609
3610 return &(ugeth->stats);
3611}
3612
3613/* ucc_geth_timeout gets called when a packet has not been
3614 * transmitted after a set amount of time.
3615 * For now, assume that clearing out all the structures, and
3616 * starting over will fix the problem. */
3617static void ucc_geth_timeout(struct net_device *dev)
3618{
3619 ucc_geth_private_t *ugeth = netdev_priv(dev);
3620
3621 ugeth_vdbg("%s: IN", __FUNCTION__);
3622
3623 ugeth->stats.tx_errors++;
3624
3625 ugeth_dump_regs(ugeth);
3626
3627 if (dev->flags & IFF_UP) {
3628 ucc_geth_stop(ugeth);
3629 ucc_geth_startup(ugeth);
3630 }
3631
3632 netif_schedule(dev);
3633}
3634
3635/* This is called by the kernel when a frame is ready for transmission. */
3636/* It is pointed to by the dev->hard_start_xmit function pointer */
3637static int ucc_geth_start_xmit(struct sk_buff *skb, struct net_device *dev)
3638{
3639 ucc_geth_private_t *ugeth = netdev_priv(dev);
3640 u8 *bd; /* BD pointer */
3641 u32 bd_status;
3642 u8 txQ = 0;
3643
3644 ugeth_vdbg("%s: IN", __FUNCTION__);
3645
3646 spin_lock_irq(&ugeth->lock);
3647
3648 ugeth->stats.tx_bytes += skb->len;
3649
3650 /* Start from the next BD that should be filled */
3651 bd = ugeth->txBd[txQ];
3652 bd_status = BD_STATUS_AND_LENGTH(bd);
3653 /* Save the skb pointer so we can free it later */
3654 ugeth->tx_skbuff[txQ][ugeth->skb_curtx[txQ]] = skb;
3655
3656 /* Update the current skb pointer (wrapping if this was the last) */
3657 ugeth->skb_curtx[txQ] =
3658 (ugeth->skb_curtx[txQ] +
3659 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
3660
3661 /* set up the buffer descriptor */
3662 BD_BUFFER_SET(bd,
3663 dma_map_single(NULL, skb->data, skb->len, DMA_TO_DEVICE));
3664
3665 //printk(KERN_DEBUG"skb->data is 0x%x\n",skb->data);
3666
3667 bd_status = (bd_status & T_W) | T_R | T_I | T_L | skb->len;
3668
3669 BD_STATUS_AND_LENGTH_SET(bd, bd_status);
3670
3671 dev->trans_start = jiffies;
3672
3673 /* Move to next BD in the ring */
3674 if (!(bd_status & T_W))
3675 ugeth->txBd[txQ] = bd + UCC_GETH_SIZE_OF_BD;
3676 else
3677 ugeth->txBd[txQ] = ugeth->p_tx_bd_ring[txQ];
3678
3679 /* If the next BD still needs to be cleaned up, then the bds
3680 are full. We need to tell the kernel to stop sending us stuff. */
3681 if (bd == ugeth->confBd[txQ]) {
3682 if (!netif_queue_stopped(dev))
3683 netif_stop_queue(dev);
3684 }
3685
3686 if (ugeth->p_scheduler) {
3687 ugeth->cpucount[txQ]++;
3688 /* Indicate to QE that there are more Tx bds ready for
3689 transmission */
3690 /* This is done by writing a running counter of the bd
3691 count to the scheduler PRAM. */
3692 out_be16(ugeth->p_cpucount[txQ], ugeth->cpucount[txQ]);
3693 }
3694
3695 spin_unlock_irq(&ugeth->lock);
3696
3697 return 0;
3698}
3699
3700static int ucc_geth_rx(ucc_geth_private_t *ugeth, u8 rxQ, int rx_work_limit)
3701{
3702 struct sk_buff *skb;
3703 u8 *bd;
3704 u16 length, howmany = 0;
3705 u32 bd_status;
3706 u8 *bdBuffer;
3707
3708 ugeth_vdbg("%s: IN", __FUNCTION__);
3709
3710 spin_lock(&ugeth->lock);
3711 /* collect received buffers */
3712 bd = ugeth->rxBd[rxQ];
3713
3714 bd_status = BD_STATUS_AND_LENGTH(bd);
3715
3716 /* while there are received buffers and BD is full (~R_E) */
3717 while (!((bd_status & (R_E)) || (--rx_work_limit < 0))) {
3718 bdBuffer = (u8 *) BD_BUFFER(bd);
3719 length = (u16) ((bd_status & BD_LENGTH_MASK) - 4);
3720 skb = ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]];
3721
3722 /* determine whether buffer is first, last, first and last
3723 (single buffer frame) or middle (not first and not last) */
3724 if (!skb ||
3725 (!(bd_status & (R_F | R_L))) ||
3726 (bd_status & R_ERRORS_FATAL)) {
3727 ugeth_vdbg("%s, %d: ERROR!!! skb - 0x%08x",
3728 __FUNCTION__, __LINE__, (u32) skb);
3729 if (skb)
3730 dev_kfree_skb_any(skb);
3731
3732 ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = NULL;
3733 ugeth->stats.rx_dropped++;
3734 } else {
3735 ugeth->stats.rx_packets++;
3736 howmany++;
3737
3738 /* Prep the skb for the packet */
3739 skb_put(skb, length);
3740
3741 /* Tell the skb what kind of packet this is */
3742 skb->protocol = eth_type_trans(skb, ugeth->dev);
3743
3744 ugeth->stats.rx_bytes += length;
3745 /* Send the packet up the stack */
3746#ifdef CONFIG_UGETH_NAPI
3747 netif_receive_skb(skb);
3748#else
3749 netif_rx(skb);
3750#endif /* CONFIG_UGETH_NAPI */
3751 }
3752
3753 ugeth->dev->last_rx = jiffies;
3754
3755 skb = get_new_skb(ugeth, bd);
3756 if (!skb) {
3757 ugeth_warn("%s: No Rx Data Buffer", __FUNCTION__);
3758 spin_unlock(&ugeth->lock);
3759 ugeth->stats.rx_dropped++;
3760 break;
3761 }
3762
3763 ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = skb;
3764
3765 /* update to point at the next skb */
3766 ugeth->skb_currx[rxQ] =
3767 (ugeth->skb_currx[rxQ] +
3768 1) & RX_RING_MOD_MASK(ugeth->ug_info->bdRingLenRx[rxQ]);
3769
3770 if (bd_status & R_W)
3771 bd = ugeth->p_rx_bd_ring[rxQ];
3772 else
3773 bd += UCC_GETH_SIZE_OF_BD;
3774
3775 bd_status = BD_STATUS_AND_LENGTH(bd);
3776 }
3777
3778 ugeth->rxBd[rxQ] = bd;
3779 spin_unlock(&ugeth->lock);
3780 return howmany;
3781}
3782
3783static int ucc_geth_tx(struct net_device *dev, u8 txQ)
3784{
3785 /* Start from the next BD that should be filled */
3786 ucc_geth_private_t *ugeth = netdev_priv(dev);
3787 u8 *bd; /* BD pointer */
3788 u32 bd_status;
3789
3790 bd = ugeth->confBd[txQ];
3791 bd_status = BD_STATUS_AND_LENGTH(bd);
3792
3793 /* Normal processing. */
3794 while ((bd_status & T_R) == 0) {
3795 /* BD contains already transmitted buffer. */
3796 /* Handle the transmitted buffer and release */
3797 /* the BD to be used with the current frame */
3798
3799 if ((bd = ugeth->txBd[txQ]) && (netif_queue_stopped(dev) == 0))
3800 break;
3801
3802 ugeth->stats.tx_packets++;
3803
3804 /* Free the sk buffer associated with this TxBD */
3805 dev_kfree_skb_irq(ugeth->
3806 tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]]);
3807 ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]] = NULL;
3808 ugeth->skb_dirtytx[txQ] =
3809 (ugeth->skb_dirtytx[txQ] +
3810 1) & TX_RING_MOD_MASK(ugeth->ug_info->bdRingLenTx[txQ]);
3811
3812 /* We freed a buffer, so now we can restart transmission */
3813 if (netif_queue_stopped(dev))
3814 netif_wake_queue(dev);
3815
3816 /* Advance the confirmation BD pointer */
3817 if (!(bd_status & T_W))
3818 ugeth->confBd[txQ] += UCC_GETH_SIZE_OF_BD;
3819 else
3820 ugeth->confBd[txQ] = ugeth->p_tx_bd_ring[txQ];
3821 }
3822 return 0;
3823}
3824
3825#ifdef CONFIG_UGETH_NAPI
3826static int ucc_geth_poll(struct net_device *dev, int *budget)
3827{
3828 ucc_geth_private_t *ugeth = netdev_priv(dev);
3829 int howmany;
3830 int rx_work_limit = *budget;
3831 u8 rxQ = 0;
3832
3833 if (rx_work_limit > dev->quota)
3834 rx_work_limit = dev->quota;
3835
3836 howmany = ucc_geth_rx(ugeth, rxQ, rx_work_limit);
3837
3838 dev->quota -= howmany;
3839 rx_work_limit -= howmany;
3840 *budget -= howmany;
3841
3842 if (rx_work_limit >= 0)
3843 netif_rx_complete(dev);
3844
3845 return (rx_work_limit < 0) ? 1 : 0;
3846}
3847#endif /* CONFIG_UGETH_NAPI */
3848
3849static irqreturn_t ucc_geth_irq_handler(int irq, void *info,
3850 struct pt_regs *regs)
3851{
3852 struct net_device *dev = (struct net_device *)info;
3853 ucc_geth_private_t *ugeth = netdev_priv(dev);
3854 ucc_fast_private_t *uccf;
3855 ucc_geth_info_t *ug_info;
3856 register u32 ucce = 0;
3857 register u32 bit_mask = UCCE_RXBF_SINGLE_MASK;
3858 register u32 tx_mask = UCCE_TXBF_SINGLE_MASK;
3859 register u8 i;
3860
3861 ugeth_vdbg("%s: IN", __FUNCTION__);
3862
3863 if (!ugeth)
3864 return IRQ_NONE;
3865
3866 uccf = ugeth->uccf;
3867 ug_info = ugeth->ug_info;
3868
3869 do {
3870 ucce |= (u32) (in_be32(uccf->p_ucce) & in_be32(uccf->p_uccm));
3871
3872 /* clear event bits for next time */
3873 /* Side effect here is to mask ucce variable
3874 for future processing below. */
3875 out_be32(uccf->p_ucce, ucce); /* Clear with ones,
3876 but only bits in UCCM */
3877
3878 /* We ignore Tx interrupts because Tx confirmation is
3879 done inside Tx routine */
3880
3881 for (i = 0; i < ug_info->numQueuesRx; i++) {
3882 if (ucce & bit_mask)
3883 ucc_geth_rx(ugeth, i,
3884 (int)ugeth->ug_info->
3885 bdRingLenRx[i]);
3886 ucce &= ~bit_mask;
3887 bit_mask <<= 1;
3888 }
3889
3890 for (i = 0; i < ug_info->numQueuesTx; i++) {
3891 if (ucce & tx_mask)
3892 ucc_geth_tx(dev, i);
3893 ucce &= ~tx_mask;
3894 tx_mask <<= 1;
3895 }
3896
3897 /* Exceptions */
3898 if (ucce & UCCE_BSY) {
3899 ugeth_vdbg("Got BUSY irq!!!!");
3900 ugeth->stats.rx_errors++;
3901 ucce &= ~UCCE_BSY;
3902 }
3903 if (ucce & UCCE_OTHER) {
3904 ugeth_vdbg("Got frame with error (ucce - 0x%08x)!!!!",
3905 ucce);
3906 ugeth->stats.rx_errors++;
3907 ucce &= ~ucce;
3908 }
3909 }
3910 while (ucce);
3911
3912 return IRQ_HANDLED;
3913}
3914
3915static irqreturn_t phy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3916{
3917 struct net_device *dev = (struct net_device *)dev_id;
3918 ucc_geth_private_t *ugeth = netdev_priv(dev);
3919
3920 ugeth_vdbg("%s: IN", __FUNCTION__);
3921
3922 /* Clear the interrupt */
3923 mii_clear_phy_interrupt(ugeth->mii_info);
3924
3925 /* Disable PHY interrupts */
3926 mii_configure_phy_interrupt(ugeth->mii_info, MII_INTERRUPT_DISABLED);
3927
3928 /* Schedule the phy change */
3929 schedule_work(&ugeth->tq);
3930
3931 return IRQ_HANDLED;
3932}
3933
3934/* Scheduled by the phy_interrupt/timer to handle PHY changes */
3935static void ugeth_phy_change(void *data)
3936{
3937 struct net_device *dev = (struct net_device *)data;
3938 ucc_geth_private_t *ugeth = netdev_priv(dev);
3939 ucc_geth_t *ug_regs;
3940 int result = 0;
3941
3942 ugeth_vdbg("%s: IN", __FUNCTION__);
3943
3944 ug_regs = ugeth->ug_regs;
3945
3946 /* Delay to give the PHY a chance to change the
3947 * register state */
3948 msleep(1);
3949
3950 /* Update the link, speed, duplex */
3951 result = ugeth->mii_info->phyinfo->read_status(ugeth->mii_info);
3952
3953 /* Adjust the known status as long as the link
3954 * isn't still coming up */
3955 if ((0 == result) || (ugeth->mii_info->link == 0))
3956 adjust_link(dev);
3957
3958 /* Reenable interrupts, if needed */
3959 if (ugeth->ug_info->board_flags & FSL_UGETH_BRD_HAS_PHY_INTR)
3960 mii_configure_phy_interrupt(ugeth->mii_info,
3961 MII_INTERRUPT_ENABLED);
3962}
3963
3964/* Called every so often on systems that don't interrupt
3965 * the core for PHY changes */
3966static void ugeth_phy_timer(unsigned long data)
3967{
3968 struct net_device *dev = (struct net_device *)data;
3969 ucc_geth_private_t *ugeth = netdev_priv(dev);
3970
3971 schedule_work(&ugeth->tq);
3972
3973 mod_timer(&ugeth->phy_info_timer, jiffies + PHY_CHANGE_TIME * HZ);
3974}
3975
3976/* Keep trying aneg for some time
3977 * If, after GFAR_AN_TIMEOUT seconds, it has not
3978 * finished, we switch to forced.
3979 * Either way, once the process has completed, we either
3980 * request the interrupt, or switch the timer over to
3981 * using ugeth_phy_timer to check status */
3982static void ugeth_phy_startup_timer(unsigned long data)
3983{
3984 struct ugeth_mii_info *mii_info = (struct ugeth_mii_info *)data;
3985 ucc_geth_private_t *ugeth = netdev_priv(mii_info->dev);
3986 static int secondary = UGETH_AN_TIMEOUT;
3987 int result;
3988
3989 /* Configure the Auto-negotiation */
3990 result = mii_info->phyinfo->config_aneg(mii_info);
3991
3992 /* If autonegotiation failed to start, and
3993 * we haven't timed out, reset the timer, and return */
3994 if (result && secondary--) {
3995 mod_timer(&ugeth->phy_info_timer, jiffies + HZ);
3996 return;
3997 } else if (result) {
3998 /* Couldn't start autonegotiation.
3999 * Try switching to forced */
4000 mii_info->autoneg = 0;
4001 result = mii_info->phyinfo->config_aneg(mii_info);
4002
4003 /* Forcing failed! Give up */
4004 if (result) {
4005 ugeth_err("%s: Forcing failed!", mii_info->dev->name);
4006 return;
4007 }
4008 }
4009
4010 /* Kill the timer so it can be restarted */
4011 del_timer_sync(&ugeth->phy_info_timer);
4012
4013 /* Grab the PHY interrupt, if necessary/possible */
4014 if (ugeth->ug_info->board_flags & FSL_UGETH_BRD_HAS_PHY_INTR) {
4015 if (request_irq(ugeth->ug_info->phy_interrupt,
4016 phy_interrupt,
4017 SA_SHIRQ, "phy_interrupt", mii_info->dev) < 0) {
4018 ugeth_err("%s: Can't get IRQ %d (PHY)",
4019 mii_info->dev->name,
4020 ugeth->ug_info->phy_interrupt);
4021 } else {
4022 mii_configure_phy_interrupt(ugeth->mii_info,
4023 MII_INTERRUPT_ENABLED);
4024 return;
4025 }
4026 }
4027
4028 /* Start the timer again, this time in order to
4029 * handle a change in status */
4030 init_timer(&ugeth->phy_info_timer);
4031 ugeth->phy_info_timer.function = &ugeth_phy_timer;
4032 ugeth->phy_info_timer.data = (unsigned long)mii_info->dev;
4033 mod_timer(&ugeth->phy_info_timer, jiffies + PHY_CHANGE_TIME * HZ);
4034}
4035
4036/* Called when something needs to use the ethernet device */
4037/* Returns 0 for success. */
4038static int ucc_geth_open(struct net_device *dev)
4039{
4040 ucc_geth_private_t *ugeth = netdev_priv(dev);
4041 int err;
4042
4043 ugeth_vdbg("%s: IN", __FUNCTION__);
4044
4045 /* Test station address */
4046 if (dev->dev_addr[0] & ENET_GROUP_ADDR) {
4047 ugeth_err("%s: Multicast address used for station address"
4048 " - is this what you wanted?", __FUNCTION__);
4049 return -EINVAL;
4050 }
4051
4052 err = ucc_geth_startup(ugeth);
4053 if (err) {
4054 ugeth_err("%s: Cannot configure net device, aborting.",
4055 dev->name);
4056 return err;
4057 }
4058
4059 err = adjust_enet_interface(ugeth);
4060 if (err) {
4061 ugeth_err("%s: Cannot configure net device, aborting.",
4062 dev->name);
4063 return err;
4064 }
4065
4066 /* Set MACSTNADDR1, MACSTNADDR2 */
4067 /* For more details see the hardware spec. */
4068 init_mac_station_addr_regs(dev->dev_addr[0],
4069 dev->dev_addr[1],
4070 dev->dev_addr[2],
4071 dev->dev_addr[3],
4072 dev->dev_addr[4],
4073 dev->dev_addr[5],
4074 &ugeth->ug_regs->macstnaddr1,
4075 &ugeth->ug_regs->macstnaddr2);
4076
4077 err = init_phy(dev);
4078 if (err) {
4079 ugeth_err("%s: Cannot initialzie PHY, aborting.", dev->name);
4080 return err;
4081 }
4082#ifndef CONFIG_UGETH_NAPI
4083 err =
4084 request_irq(ugeth->ug_info->uf_info.irq, ucc_geth_irq_handler, 0,
4085 "UCC Geth", dev);
4086 if (err) {
4087 ugeth_err("%s: Cannot get IRQ for net device, aborting.",
4088 dev->name);
4089 ucc_geth_stop(ugeth);
4090 return err;
4091 }
4092#endif /* CONFIG_UGETH_NAPI */
4093
4094 /* Set up the PHY change work queue */
4095 INIT_WORK(&ugeth->tq, ugeth_phy_change, dev);
4096
4097 init_timer(&ugeth->phy_info_timer);
4098 ugeth->phy_info_timer.function = &ugeth_phy_startup_timer;
4099 ugeth->phy_info_timer.data = (unsigned long)ugeth->mii_info;
4100 mod_timer(&ugeth->phy_info_timer, jiffies + HZ);
4101
4102 err = ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
4103 if (err) {
4104 ugeth_err("%s: Cannot enable net device, aborting.", dev->name);
4105 ucc_geth_stop(ugeth);
4106 return err;
4107 }
4108
4109 netif_start_queue(dev);
4110
4111 return err;
4112}
4113
4114/* Stops the kernel queue, and halts the controller */
4115static int ucc_geth_close(struct net_device *dev)
4116{
4117 ucc_geth_private_t *ugeth = netdev_priv(dev);
4118
4119 ugeth_vdbg("%s: IN", __FUNCTION__);
4120
4121 ucc_geth_stop(ugeth);
4122
4123 /* Shutdown the PHY */
4124 if (ugeth->mii_info->phyinfo->close)
4125 ugeth->mii_info->phyinfo->close(ugeth->mii_info);
4126
4127 kfree(ugeth->mii_info);
4128
4129 netif_stop_queue(dev);
4130
4131 return 0;
4132}
4133
4134struct ethtool_ops ucc_geth_ethtool_ops = {
4135 .get_settings = NULL,
4136 .get_drvinfo = NULL,
4137 .get_regs_len = NULL,
4138 .get_regs = NULL,
4139 .get_link = NULL,
4140 .get_coalesce = NULL,
4141 .set_coalesce = NULL,
4142 .get_ringparam = NULL,
4143 .set_ringparam = NULL,
4144 .get_strings = NULL,
4145 .get_stats_count = NULL,
4146 .get_ethtool_stats = NULL,
4147};
4148
4149static int ucc_geth_probe(struct device *device)
4150{
4151 struct platform_device *pdev = to_platform_device(device);
4152 struct ucc_geth_platform_data *ugeth_pdata;
4153 struct net_device *dev = NULL;
4154 struct ucc_geth_private *ugeth = NULL;
4155 struct ucc_geth_info *ug_info;
4156 int err;
4157 static int mii_mng_configured = 0;
4158
4159 ugeth_vdbg("%s: IN", __FUNCTION__);
4160
4161 ugeth_pdata = (struct ucc_geth_platform_data *)pdev->dev.platform_data;
4162
4163 ug_info = &ugeth_info[pdev->id];
4164 ug_info->uf_info.ucc_num = pdev->id;
4165 ug_info->uf_info.rx_clock = ugeth_pdata->rx_clock;
4166 ug_info->uf_info.tx_clock = ugeth_pdata->tx_clock;
4167 ug_info->uf_info.regs = ugeth_pdata->phy_reg_addr;
4168 ug_info->uf_info.irq = platform_get_irq(pdev, 0);
4169 ug_info->phy_address = ugeth_pdata->phy_id;
4170 ug_info->enet_interface = ugeth_pdata->phy_interface;
4171 ug_info->board_flags = ugeth_pdata->board_flags;
4172 ug_info->phy_interrupt = ugeth_pdata->phy_interrupt;
4173
4174 printk(KERN_INFO "ucc_geth: UCC%1d at 0x%8x (irq = %d) \n",
4175 ug_info->uf_info.ucc_num + 1, ug_info->uf_info.regs,
4176 ug_info->uf_info.irq);
4177
4178 if (ug_info == NULL) {
4179 ugeth_err("%s: [%d] Missing additional data!", __FUNCTION__,
4180 pdev->id);
4181 return -ENODEV;
4182 }
4183
4184 if (!mii_mng_configured) {
4185 ucc_set_qe_mux_mii_mng(ug_info->uf_info.ucc_num);
4186 mii_mng_configured = 1;
4187 }
4188
4189 /* Create an ethernet device instance */
4190 dev = alloc_etherdev(sizeof(*ugeth));
4191
4192 if (dev == NULL)
4193 return -ENOMEM;
4194
4195 ugeth = netdev_priv(dev);
4196 spin_lock_init(&ugeth->lock);
4197
4198 dev_set_drvdata(device, dev);
4199
4200 /* Set the dev->base_addr to the gfar reg region */
4201 dev->base_addr = (unsigned long)(ug_info->uf_info.regs);
4202
4203 SET_MODULE_OWNER(dev);
4204 SET_NETDEV_DEV(dev, device);
4205
4206 /* Fill in the dev structure */
4207 dev->open = ucc_geth_open;
4208 dev->hard_start_xmit = ucc_geth_start_xmit;
4209 dev->tx_timeout = ucc_geth_timeout;
4210 dev->watchdog_timeo = TX_TIMEOUT;
4211#ifdef CONFIG_UGETH_NAPI
4212 dev->poll = ucc_geth_poll;
4213 dev->weight = UCC_GETH_DEV_WEIGHT;
4214#endif /* CONFIG_UGETH_NAPI */
4215 dev->stop = ucc_geth_close;
4216 dev->get_stats = ucc_geth_get_stats;
4217// dev->change_mtu = ucc_geth_change_mtu;
4218 dev->mtu = 1500;
4219 dev->set_multicast_list = ucc_geth_set_multi;
4220 dev->ethtool_ops = &ucc_geth_ethtool_ops;
4221
4222 err = register_netdev(dev);
4223 if (err) {
4224 ugeth_err("%s: Cannot register net device, aborting.",
4225 dev->name);
4226 free_netdev(dev);
4227 return err;
4228 }
4229
4230 ugeth->ug_info = ug_info;
4231 ugeth->dev = dev;
4232 memcpy(dev->dev_addr, ugeth_pdata->mac_addr, 6);
4233
4234 return 0;
4235}
4236
4237static int ucc_geth_remove(struct device *device)
4238{
4239 struct net_device *dev = dev_get_drvdata(device);
4240 struct ucc_geth_private *ugeth = netdev_priv(dev);
4241
4242 dev_set_drvdata(device, NULL);
4243 ucc_geth_memclean(ugeth);
4244 free_netdev(dev);
4245
4246 return 0;
4247}
4248
4249/* Structure for a device driver */
4250static struct device_driver ucc_geth_driver = {
4251 .name = DRV_NAME,
4252 .bus = &platform_bus_type,
4253 .probe = ucc_geth_probe,
4254 .remove = ucc_geth_remove,
4255};
4256
4257static int __init ucc_geth_init(void)
4258{
4259 int i;
4260 printk(KERN_INFO "ucc_geth: " DRV_DESC "\n");
4261 for (i = 0; i < 8; i++)
4262 memcpy(&(ugeth_info[i]), &ugeth_primary_info,
4263 sizeof(ugeth_primary_info));
4264
4265 return driver_register(&ucc_geth_driver);
4266}
4267
4268static void __exit ucc_geth_exit(void)
4269{
4270 driver_unregister(&ucc_geth_driver);
4271}
4272
4273module_init(ucc_geth_init);
4274module_exit(ucc_geth_exit);
4275
4276MODULE_AUTHOR("Freescale Semiconductor, Inc");
4277MODULE_DESCRIPTION(DRV_DESC);
4278MODULE_LICENSE("GPL");
diff --git a/drivers/net/ucc_geth.h b/drivers/net/ucc_geth.h
new file mode 100644
index 000000000000..005965f5dd9b
--- /dev/null
+++ b/drivers/net/ucc_geth.h
@@ -0,0 +1,1339 @@
1/*
2 * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved.
3 *
4 * Author: Shlomi Gridish <gridish@freescale.com>
5 *
6 * Description:
7 * Internal header file for UCC Gigabit Ethernet unit routines.
8 *
9 * Changelog:
10 * Jun 28, 2006 Li Yang <LeoLi@freescale.com>
11 * - Rearrange code and style fixes
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 */
18#ifndef __UCC_GETH_H__
19#define __UCC_GETH_H__
20
21#include <linux/kernel.h>
22#include <linux/list.h>
23#include <linux/fsl_devices.h>
24
25#include <asm/immap_qe.h>
26#include <asm/qe.h>
27
28#include <asm/ucc.h>
29#include <asm/ucc_fast.h>
30
31#define NUM_TX_QUEUES 8
32#define NUM_RX_QUEUES 8
33#define NUM_BDS_IN_PREFETCHED_BDS 4
34#define TX_IP_OFFSET_ENTRY_MAX 8
35#define NUM_OF_PADDRS 4
36#define ENET_INIT_PARAM_MAX_ENTRIES_RX 9
37#define ENET_INIT_PARAM_MAX_ENTRIES_TX 8
38
39typedef struct ucc_mii_mng {
40 u32 miimcfg; /* MII management configuration reg */
41 u32 miimcom; /* MII management command reg */
42 u32 miimadd; /* MII management address reg */
43 u32 miimcon; /* MII management control reg */
44 u32 miimstat; /* MII management status reg */
45 u32 miimind; /* MII management indication reg */
46} __attribute__ ((packed)) ucc_mii_mng_t;
47
48typedef struct ucc_geth {
49 ucc_fast_t uccf;
50
51 u32 maccfg1; /* mac configuration reg. 1 */
52 u32 maccfg2; /* mac configuration reg. 2 */
53 u32 ipgifg; /* interframe gap reg. */
54 u32 hafdup; /* half-duplex reg. */
55 u8 res1[0x10];
56 ucc_mii_mng_t miimng; /* MII management structure */
57 u32 ifctl; /* interface control reg */
58 u32 ifstat; /* interface statux reg */
59 u32 macstnaddr1; /* mac station address part 1 reg */
60 u32 macstnaddr2; /* mac station address part 2 reg */
61 u8 res2[0x8];
62 u32 uempr; /* UCC Ethernet Mac parameter reg */
63 u32 utbipar; /* UCC tbi address reg */
64 u16 uescr; /* UCC Ethernet statistics control reg */
65 u8 res3[0x180 - 0x15A];
66 u32 tx64; /* Total number of frames (including bad
67 frames) transmitted that were exactly of the
68 minimal length (64 for un tagged, 68 for
69 tagged, or with length exactly equal to the
70 parameter MINLength */
71 u32 tx127; /* Total number of frames (including bad
72 frames) transmitted that were between
73 MINLength (Including FCS length==4) and 127
74 octets */
75 u32 tx255; /* Total number of frames (including bad
76 frames) transmitted that were between 128
77 (Including FCS length==4) and 255 octets */
78 u32 rx64; /* Total number of frames received including
79 bad frames that were exactly of the mninimal
80 length (64 bytes) */
81 u32 rx127; /* Total number of frames (including bad
82 frames) received that were between MINLength
83 (Including FCS length==4) and 127 octets */
84 u32 rx255; /* Total number of frames (including bad
85 frames) received that were between 128
86 (Including FCS length==4) and 255 octets */
87 u32 txok; /* Total number of octets residing in frames
88 that where involved in succesfull
89 transmission */
90 u16 txcf; /* Total number of PAUSE control frames
91 transmitted by this MAC */
92 u8 res4[0x2];
93 u32 tmca; /* Total number of frames that were transmitted
94 succesfully with the group address bit set
95 that are not broadcast frames */
96 u32 tbca; /* Total number of frames transmitted
97 succesfully that had destination address
98 field equal to the broadcast address */
99 u32 rxfok; /* Total number of frames received OK */
100 u32 rxbok; /* Total number of octets received OK */
101 u32 rbyt; /* Total number of octets received including
102 octets in bad frames. Must be implemented in
103 HW because it includes octets in frames that
104 never even reach the UCC */
105 u32 rmca; /* Total number of frames that were received
106 succesfully with the group address bit set
107 that are not broadcast frames */
108 u32 rbca; /* Total number of frames received succesfully
109 that had destination address equal to the
110 broadcast address */
111 u32 scar; /* Statistics carry register */
112 u32 scam; /* Statistics caryy mask register */
113 u8 res5[0x200 - 0x1c4];
114} __attribute__ ((packed)) ucc_geth_t;
115
116/* UCC GETH TEMODR Register */
117#define TEMODER_TX_RMON_STATISTICS_ENABLE 0x0100 /* enable Tx statistics
118 */
119#define TEMODER_SCHEDULER_ENABLE 0x2000 /* enable scheduler */
120#define TEMODER_IP_CHECKSUM_GENERATE 0x0400 /* generate IPv4
121 checksums */
122#define TEMODER_PERFORMANCE_OPTIMIZATION_MODE1 0x0200 /* enable performance
123 optimization
124 enhancement (mode1) */
125#define TEMODER_RMON_STATISTICS 0x0100 /* enable tx statistics
126 */
127#define TEMODER_NUM_OF_QUEUES_SHIFT (15-15) /* Number of queues <<
128 shift */
129
130/* UCC GETH TEMODR Register */
131#define REMODER_RX_RMON_STATISTICS_ENABLE 0x00001000 /* enable Rx
132 statistics */
133#define REMODER_RX_EXTENDED_FEATURES 0x80000000 /* enable
134 extended
135 features */
136#define REMODER_VLAN_OPERATION_TAGGED_SHIFT (31-9 ) /* vlan operation
137 tagged << shift */
138#define REMODER_VLAN_OPERATION_NON_TAGGED_SHIFT (31-10) /* vlan operation non
139 tagged << shift */
140#define REMODER_RX_QOS_MODE_SHIFT (31-15) /* rx QoS mode << shift
141 */
142#define REMODER_RMON_STATISTICS 0x00001000 /* enable rx
143 statistics */
144#define REMODER_RX_EXTENDED_FILTERING 0x00000800 /* extended
145 filtering
146 vs.
147 mpc82xx-like
148 filtering */
149#define REMODER_NUM_OF_QUEUES_SHIFT (31-23) /* Number of queues <<
150 shift */
151#define REMODER_DYNAMIC_MAX_FRAME_LENGTH 0x00000008 /* enable
152 dynamic max
153 frame length
154 */
155#define REMODER_DYNAMIC_MIN_FRAME_LENGTH 0x00000004 /* enable
156 dynamic min
157 frame length
158 */
159#define REMODER_IP_CHECKSUM_CHECK 0x00000002 /* check IPv4
160 checksums */
161#define REMODER_IP_ADDRESS_ALIGNMENT 0x00000001 /* align ip
162 address to
163 4-byte
164 boundary */
165
166/* UCC GETH Event Register */
167#define UCCE_MPD 0x80000000 /* Magic packet
168 detection */
169#define UCCE_SCAR 0x40000000
170#define UCCE_GRA 0x20000000 /* Tx graceful
171 stop
172 complete */
173#define UCCE_CBPR 0x10000000
174#define UCCE_BSY 0x08000000
175#define UCCE_RXC 0x04000000
176#define UCCE_TXC 0x02000000
177#define UCCE_TXE 0x01000000
178#define UCCE_TXB7 0x00800000
179#define UCCE_TXB6 0x00400000
180#define UCCE_TXB5 0x00200000
181#define UCCE_TXB4 0x00100000
182#define UCCE_TXB3 0x00080000
183#define UCCE_TXB2 0x00040000
184#define UCCE_TXB1 0x00020000
185#define UCCE_TXB0 0x00010000
186#define UCCE_RXB7 0x00008000
187#define UCCE_RXB6 0x00004000
188#define UCCE_RXB5 0x00002000
189#define UCCE_RXB4 0x00001000
190#define UCCE_RXB3 0x00000800
191#define UCCE_RXB2 0x00000400
192#define UCCE_RXB1 0x00000200
193#define UCCE_RXB0 0x00000100
194#define UCCE_RXF7 0x00000080
195#define UCCE_RXF6 0x00000040
196#define UCCE_RXF5 0x00000020
197#define UCCE_RXF4 0x00000010
198#define UCCE_RXF3 0x00000008
199#define UCCE_RXF2 0x00000004
200#define UCCE_RXF1 0x00000002
201#define UCCE_RXF0 0x00000001
202
203#define UCCE_RXBF_SINGLE_MASK (UCCE_RXF0)
204#define UCCE_TXBF_SINGLE_MASK (UCCE_TXB0)
205
206#define UCCE_TXB (UCCE_TXB7 | UCCE_TXB6 | UCCE_TXB5 | UCCE_TXB4 |\
207 UCCE_TXB3 | UCCE_TXB2 | UCCE_TXB1 | UCCE_TXB0)
208#define UCCE_RXB (UCCE_RXB7 | UCCE_RXB6 | UCCE_RXB5 | UCCE_RXB4 |\
209 UCCE_RXB3 | UCCE_RXB2 | UCCE_RXB1 | UCCE_RXB0)
210#define UCCE_RXF (UCCE_RXF7 | UCCE_RXF6 | UCCE_RXF5 | UCCE_RXF4 |\
211 UCCE_RXF3 | UCCE_RXF2 | UCCE_RXF1 | UCCE_RXF0)
212#define UCCE_OTHER (UCCE_SCAR | UCCE_GRA | UCCE_CBPR | UCCE_BSY |\
213 UCCE_RXC | UCCE_TXC | UCCE_TXE)
214
215/* UCC GETH UPSMR (Protocol Specific Mode Register) */
216#define UPSMR_ECM 0x04000000 /* Enable CAM
217 Miss or
218 Enable
219 Filtering
220 Miss */
221#define UPSMR_HSE 0x02000000 /* Hardware
222 Statistics
223 Enable */
224#define UPSMR_PRO 0x00400000 /* Promiscuous*/
225#define UPSMR_CAP 0x00200000 /* CAM polarity
226 */
227#define UPSMR_RSH 0x00100000 /* Receive
228 Short Frames
229 */
230#define UPSMR_RPM 0x00080000 /* Reduced Pin
231 Mode
232 interfaces */
233#define UPSMR_R10M 0x00040000 /* RGMII/RMII
234 10 Mode */
235#define UPSMR_RLPB 0x00020000 /* RMII
236 Loopback
237 Mode */
238#define UPSMR_TBIM 0x00010000 /* Ten-bit
239 Interface
240 Mode */
241#define UPSMR_RMM 0x00001000 /* RMII/RGMII
242 Mode */
243#define UPSMR_CAM 0x00000400 /* CAM Address
244 Matching */
245#define UPSMR_BRO 0x00000200 /* Broadcast
246 Address */
247#define UPSMR_RES1 0x00002000 /* Reserved
248 feild - must
249 be 1 */
250
251/* UCC GETH MACCFG1 (MAC Configuration 1 Register) */
252#define MACCFG1_FLOW_RX 0x00000020 /* Flow Control
253 Rx */
254#define MACCFG1_FLOW_TX 0x00000010 /* Flow Control
255 Tx */
256#define MACCFG1_ENABLE_SYNCHED_RX 0x00000008 /* Rx Enable
257 synchronized
258 to Rx stream
259 */
260#define MACCFG1_ENABLE_RX 0x00000004 /* Enable Rx */
261#define MACCFG1_ENABLE_SYNCHED_TX 0x00000002 /* Tx Enable
262 synchronized
263 to Tx stream
264 */
265#define MACCFG1_ENABLE_TX 0x00000001 /* Enable Tx */
266
267/* UCC GETH MACCFG2 (MAC Configuration 2 Register) */
268#define MACCFG2_PREL_SHIFT (31 - 19) /* Preamble
269 Length <<
270 shift */
271#define MACCFG2_PREL_MASK 0x0000f000 /* Preamble
272 Length mask */
273#define MACCFG2_SRP 0x00000080 /* Soft Receive
274 Preamble */
275#define MACCFG2_STP 0x00000040 /* Soft
276 Transmit
277 Preamble */
278#define MACCFG2_RESERVED_1 0x00000020 /* Reserved -
279 must be set
280 to 1 */
281#define MACCFG2_LC 0x00000010 /* Length Check
282 */
283#define MACCFG2_MPE 0x00000008 /* Magic packet
284 detect */
285#define MACCFG2_FDX 0x00000001 /* Full Duplex */
286#define MACCFG2_FDX_MASK 0x00000001 /* Full Duplex
287 mask */
288#define MACCFG2_PAD_CRC 0x00000004
289#define MACCFG2_CRC_EN 0x00000002
290#define MACCFG2_PAD_AND_CRC_MODE_NONE 0x00000000 /* Neither
291 Padding
292 short frames
293 nor CRC */
294#define MACCFG2_PAD_AND_CRC_MODE_CRC_ONLY 0x00000002 /* Append CRC
295 only */
296#define MACCFG2_PAD_AND_CRC_MODE_PAD_AND_CRC 0x00000004
297#define MACCFG2_INTERFACE_MODE_NIBBLE 0x00000100 /* nibble mode
298 (MII/RMII/RGMII
299 10/100bps) */
300#define MACCFG2_INTERFACE_MODE_BYTE 0x00000200 /* byte mode
301 (GMII/TBI/RTB/RGMII
302 1000bps ) */
303#define MACCFG2_INTERFACE_MODE_MASK 0x00000300 /* mask
304 covering all
305 relevant
306 bits */
307
308/* UCC GETH IPGIFG (Inter-frame Gap / Inter-Frame Gap Register) */
309#define IPGIFG_NON_BACK_TO_BACK_IFG_PART1_SHIFT (31 - 7) /* Non
310 back-to-back
311 inter frame
312 gap part 1.
313 << shift */
314#define IPGIFG_NON_BACK_TO_BACK_IFG_PART2_SHIFT (31 - 15) /* Non
315 back-to-back
316 inter frame
317 gap part 2.
318 << shift */
319#define IPGIFG_MINIMUM_IFG_ENFORCEMENT_SHIFT (31 - 23) /* Mimimum IFG
320 Enforcement
321 << shift */
322#define IPGIFG_BACK_TO_BACK_IFG_SHIFT (31 - 31) /* back-to-back
323 inter frame
324 gap << shift
325 */
326#define IPGIFG_NON_BACK_TO_BACK_IFG_PART1_MAX 127 /* Non back-to-back
327 inter frame gap part
328 1. max val */
329#define IPGIFG_NON_BACK_TO_BACK_IFG_PART2_MAX 127 /* Non back-to-back
330 inter frame gap part
331 2. max val */
332#define IPGIFG_MINIMUM_IFG_ENFORCEMENT_MAX 255 /* Mimimum IFG
333 Enforcement max val */
334#define IPGIFG_BACK_TO_BACK_IFG_MAX 127 /* back-to-back inter
335 frame gap max val */
336#define IPGIFG_NBTB_CS_IPG_MASK 0x7F000000
337#define IPGIFG_NBTB_IPG_MASK 0x007F0000
338#define IPGIFG_MIN_IFG_MASK 0x0000FF00
339#define IPGIFG_BTB_IPG_MASK 0x0000007F
340
341/* UCC GETH HAFDUP (Half Duplex Register) */
342#define HALFDUP_ALT_BEB_TRUNCATION_SHIFT (31 - 11) /* Alternate
343 Binary
344 Exponential
345 Backoff
346 Truncation
347 << shift */
348#define HALFDUP_ALT_BEB_TRUNCATION_MAX 0xf /* Alternate Binary
349 Exponential Backoff
350 Truncation max val */
351#define HALFDUP_ALT_BEB 0x00080000 /* Alternate
352 Binary
353 Exponential
354 Backoff */
355#define HALFDUP_BACK_PRESSURE_NO_BACKOFF 0x00040000 /* Back
356 pressure no
357 backoff */
358#define HALFDUP_NO_BACKOFF 0x00020000 /* No Backoff */
359#define HALFDUP_EXCESSIVE_DEFER 0x00010000 /* Excessive
360 Defer */
361#define HALFDUP_MAX_RETRANSMISSION_SHIFT (31 - 19) /* Maximum
362 Retransmission
363 << shift */
364#define HALFDUP_MAX_RETRANSMISSION_MAX 0xf /* Maximum
365 Retransmission max
366 val */
367#define HALFDUP_COLLISION_WINDOW_SHIFT (31 - 31) /* Collision
368 Window <<
369 shift */
370#define HALFDUP_COLLISION_WINDOW_MAX 0x3f /* Collision Window max
371 val */
372#define HALFDUP_ALT_BEB_TR_MASK 0x00F00000
373#define HALFDUP_RETRANS_MASK 0x0000F000
374#define HALFDUP_COL_WINDOW_MASK 0x0000003F
375
376/* UCC GETH UCCS (Ethernet Status Register) */
377#define UCCS_BPR 0x02 /* Back pressure (in
378 half duplex mode) */
379#define UCCS_PAU 0x02 /* Pause state (in full
380 duplex mode) */
381#define UCCS_MPD 0x01 /* Magic Packet
382 Detected */
383
384/* UCC GETH MIIMCFG (MII Management Configuration Register) */
385#define MIIMCFG_RESET_MANAGEMENT 0x80000000 /* Reset
386 management */
387#define MIIMCFG_NO_PREAMBLE 0x00000010 /* Preamble
388 suppress */
389#define MIIMCFG_CLOCK_DIVIDE_SHIFT (31 - 31) /* clock divide
390 << shift */
391#define MIIMCFG_CLOCK_DIVIDE_MAX 0xf /* clock divide max val
392 */
393#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_2 0x00000000 /* divide by 2 */
394#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_4 0x00000001 /* divide by 4 */
395#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_6 0x00000002 /* divide by 6 */
396#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_8 0x00000003 /* divide by 8 */
397#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_10 0x00000004 /* divide by 10
398 */
399#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_14 0x00000005 /* divide by 14
400 */
401#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_16 0x00000008 /* divide by 16
402 */
403#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_20 0x00000006 /* divide by 20
404 */
405#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_28 0x00000007 /* divide by 28
406 */
407#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_32 0x00000009 /* divide by 32
408 */
409#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_48 0x0000000a /* divide by 48
410 */
411#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_64 0x0000000b /* divide by 64
412 */
413#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_80 0x0000000c /* divide by 80
414 */
415#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_112 0x0000000d /* divide by
416 112 */
417#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_160 0x0000000e /* divide by
418 160 */
419#define MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_224 0x0000000f /* divide by
420 224 */
421
422/* UCC GETH MIIMCOM (MII Management Command Register) */
423#define MIIMCOM_SCAN_CYCLE 0x00000002 /* Scan cycle */
424#define MIIMCOM_READ_CYCLE 0x00000001 /* Read cycle */
425
426/* UCC GETH MIIMADD (MII Management Address Register) */
427#define MIIMADD_PHY_ADDRESS_SHIFT (31 - 23) /* PHY Address
428 << shift */
429#define MIIMADD_PHY_REGISTER_SHIFT (31 - 31) /* PHY Register
430 << shift */
431
432/* UCC GETH MIIMCON (MII Management Control Register) */
433#define MIIMCON_PHY_CONTROL_SHIFT (31 - 31) /* PHY Control
434 << shift */
435#define MIIMCON_PHY_STATUS_SHIFT (31 - 31) /* PHY Status
436 << shift */
437
438/* UCC GETH MIIMIND (MII Management Indicator Register) */
439#define MIIMIND_NOT_VALID 0x00000004 /* Not valid */
440#define MIIMIND_SCAN 0x00000002 /* Scan in
441 progress */
442#define MIIMIND_BUSY 0x00000001
443
444/* UCC GETH IFSTAT (Interface Status Register) */
445#define IFSTAT_EXCESS_DEFER 0x00000200 /* Excessive
446 transmission
447 defer */
448
449/* UCC GETH MACSTNADDR1 (Station Address Part 1 Register) */
450#define MACSTNADDR1_OCTET_6_SHIFT (31 - 7) /* Station
451 address 6th
452 octet <<
453 shift */
454#define MACSTNADDR1_OCTET_5_SHIFT (31 - 15) /* Station
455 address 5th
456 octet <<
457 shift */
458#define MACSTNADDR1_OCTET_4_SHIFT (31 - 23) /* Station
459 address 4th
460 octet <<
461 shift */
462#define MACSTNADDR1_OCTET_3_SHIFT (31 - 31) /* Station
463 address 3rd
464 octet <<
465 shift */
466
467/* UCC GETH MACSTNADDR2 (Station Address Part 2 Register) */
468#define MACSTNADDR2_OCTET_2_SHIFT (31 - 7) /* Station
469 address 2nd
470 octet <<
471 shift */
472#define MACSTNADDR2_OCTET_1_SHIFT (31 - 15) /* Station
473 address 1st
474 octet <<
475 shift */
476
477/* UCC GETH UEMPR (Ethernet Mac Parameter Register) */
478#define UEMPR_PAUSE_TIME_VALUE_SHIFT (31 - 15) /* Pause time
479 value <<
480 shift */
481#define UEMPR_EXTENDED_PAUSE_TIME_VALUE_SHIFT (31 - 31) /* Extended
482 pause time
483 value <<
484 shift */
485
486/* UCC GETH UTBIPAR (Ten Bit Interface Physical Address Register) */
487#define UTBIPAR_PHY_ADDRESS_SHIFT (31 - 31) /* Phy address
488 << shift */
489#define UTBIPAR_PHY_ADDRESS_MASK 0x0000001f /* Phy address
490 mask */
491
492/* UCC GETH UESCR (Ethernet Statistics Control Register) */
493#define UESCR_AUTOZ 0x8000 /* Automatically zero
494 addressed
495 statistical counter
496 values */
497#define UESCR_CLRCNT 0x4000 /* Clear all statistics
498 counters */
499#define UESCR_MAXCOV_SHIFT (15 - 7) /* Max
500 Coalescing
501 Value <<
502 shift */
503#define UESCR_SCOV_SHIFT (15 - 15) /* Status
504 Coalescing
505 Value <<
506 shift */
507
508/* UCC GETH UDSR (Data Synchronization Register) */
509#define UDSR_MAGIC 0x067E
510
511typedef struct ucc_geth_thread_data_tx {
512 u8 res0[104];
513} __attribute__ ((packed)) ucc_geth_thread_data_tx_t;
514
515typedef struct ucc_geth_thread_data_rx {
516 u8 res0[40];
517} __attribute__ ((packed)) ucc_geth_thread_data_rx_t;
518
519/* Send Queue Queue-Descriptor */
520typedef struct ucc_geth_send_queue_qd {
521 u32 bd_ring_base; /* pointer to BD ring base address */
522 u8 res0[0x8];
523 u32 last_bd_completed_address;/* initialize to last entry in BD ring */
524 u8 res1[0x30];
525} __attribute__ ((packed)) ucc_geth_send_queue_qd_t;
526
527typedef struct ucc_geth_send_queue_mem_region {
528 ucc_geth_send_queue_qd_t sqqd[NUM_TX_QUEUES];
529} __attribute__ ((packed)) ucc_geth_send_queue_mem_region_t;
530
531typedef struct ucc_geth_thread_tx_pram {
532 u8 res0[64];
533} __attribute__ ((packed)) ucc_geth_thread_tx_pram_t;
534
535typedef struct ucc_geth_thread_rx_pram {
536 u8 res0[128];
537} __attribute__ ((packed)) ucc_geth_thread_rx_pram_t;
538
539#define THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING 64
540#define THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_8 64
541#define THREAD_RX_PRAM_ADDITIONAL_FOR_EXTENDED_FILTERING_16 96
542
543typedef struct ucc_geth_scheduler {
544 u16 cpucount0; /* CPU packet counter */
545 u16 cpucount1; /* CPU packet counter */
546 u16 cecount0; /* QE packet counter */
547 u16 cecount1; /* QE packet counter */
548 u16 cpucount2; /* CPU packet counter */
549 u16 cpucount3; /* CPU packet counter */
550 u16 cecount2; /* QE packet counter */
551 u16 cecount3; /* QE packet counter */
552 u16 cpucount4; /* CPU packet counter */
553 u16 cpucount5; /* CPU packet counter */
554 u16 cecount4; /* QE packet counter */
555 u16 cecount5; /* QE packet counter */
556 u16 cpucount6; /* CPU packet counter */
557 u16 cpucount7; /* CPU packet counter */
558 u16 cecount6; /* QE packet counter */
559 u16 cecount7; /* QE packet counter */
560 u32 weightstatus[NUM_TX_QUEUES]; /* accumulated weight factor */
561 u32 rtsrshadow; /* temporary variable handled by QE */
562 u32 time; /* temporary variable handled by QE */
563 u32 ttl; /* temporary variable handled by QE */
564 u32 mblinterval; /* max burst length interval */
565 u16 nortsrbytetime; /* normalized value of byte time in tsr units */
566 u8 fracsiz; /* radix 2 log value of denom. of
567 NorTSRByteTime */
568 u8 res0[1];
569 u8 strictpriorityq; /* Strict Priority Mask register */
570 u8 txasap; /* Transmit ASAP register */
571 u8 extrabw; /* Extra BandWidth register */
572 u8 oldwfqmask; /* temporary variable handled by QE */
573 u8 weightfactor[NUM_TX_QUEUES];
574 /**< weight factor for queues */
575 u32 minw; /* temporary variable handled by QE */
576 u8 res1[0x70 - 0x64];
577} __attribute__ ((packed)) ucc_geth_scheduler_t;
578
579typedef struct ucc_geth_tx_firmware_statistics_pram {
580 u32 sicoltx; /* single collision */
581 u32 mulcoltx; /* multiple collision */
582 u32 latecoltxfr; /* late collision */
583 u32 frabortduecol; /* frames aborted due to transmit collision */
584 u32 frlostinmactxer; /* frames lost due to internal MAC error
585 transmission that are not counted on any
586 other counter */
587 u32 carriersenseertx; /* carrier sense error */
588 u32 frtxok; /* frames transmitted OK */
589 u32 txfrexcessivedefer; /* frames with defferal time greater than
590 specified threshold */
591 u32 txpkts256; /* total packets (including bad) between 256
592 and 511 octets */
593 u32 txpkts512; /* total packets (including bad) between 512
594 and 1023 octets */
595 u32 txpkts1024; /* total packets (including bad) between 1024
596 and 1518 octets */
597 u32 txpktsjumbo; /* total packets (including bad) between 1024
598 and MAXLength octets */
599} __attribute__ ((packed)) ucc_geth_tx_firmware_statistics_pram_t;
600
601typedef struct ucc_geth_rx_firmware_statistics_pram {
602 u32 frrxfcser; /* frames with crc error */
603 u32 fraligner; /* frames with alignment error */
604 u32 inrangelenrxer; /* in range length error */
605 u32 outrangelenrxer; /* out of range length error */
606 u32 frtoolong; /* frame too long */
607 u32 runt; /* runt */
608 u32 verylongevent; /* very long event */
609 u32 symbolerror; /* symbol error */
610 u32 dropbsy; /* drop because of BD not ready */
611 u8 res0[0x8];
612 u32 mismatchdrop; /* drop because of MAC filtering (e.g. address
613 or type mismatch) */
614 u32 underpkts; /* total frames less than 64 octets */
615 u32 pkts256; /* total frames (including bad) between 256 and
616 511 octets */
617 u32 pkts512; /* total frames (including bad) between 512 and
618 1023 octets */
619 u32 pkts1024; /* total frames (including bad) between 1024
620 and 1518 octets */
621 u32 pktsjumbo; /* total frames (including bad) between 1024
622 and MAXLength octets */
623 u32 frlossinmacer; /* frames lost because of internal MAC error
624 that is not counted in any other counter */
625 u32 pausefr; /* pause frames */
626 u8 res1[0x4];
627 u32 removevlan; /* total frames that had their VLAN tag removed
628 */
629 u32 replacevlan; /* total frames that had their VLAN tag
630 replaced */
631 u32 insertvlan; /* total frames that had their VLAN tag
632 inserted */
633} __attribute__ ((packed)) ucc_geth_rx_firmware_statistics_pram_t;
634
635typedef struct ucc_geth_rx_interrupt_coalescing_entry {
636 u32 interruptcoalescingmaxvalue; /* interrupt coalescing max
637 value */
638 u32 interruptcoalescingcounter; /* interrupt coalescing counter,
639 initialize to
640 interruptcoalescingmaxvalue */
641} __attribute__ ((packed)) ucc_geth_rx_interrupt_coalescing_entry_t;
642
643typedef struct ucc_geth_rx_interrupt_coalescing_table {
644 ucc_geth_rx_interrupt_coalescing_entry_t coalescingentry[NUM_RX_QUEUES];
645 /**< interrupt coalescing entry */
646} __attribute__ ((packed)) ucc_geth_rx_interrupt_coalescing_table_t;
647
648typedef struct ucc_geth_rx_prefetched_bds {
649 qe_bd_t bd[NUM_BDS_IN_PREFETCHED_BDS]; /* prefetched bd */
650} __attribute__ ((packed)) ucc_geth_rx_prefetched_bds_t;
651
652typedef struct ucc_geth_rx_bd_queues_entry {
653 u32 bdbaseptr; /* BD base pointer */
654 u32 bdptr; /* BD pointer */
655 u32 externalbdbaseptr; /* external BD base pointer */
656 u32 externalbdptr; /* external BD pointer */
657} __attribute__ ((packed)) ucc_geth_rx_bd_queues_entry_t;
658
659typedef struct ucc_geth_tx_global_pram {
660 u16 temoder;
661 u8 res0[0x38 - 0x02];
662 u32 sqptr; /* a base pointer to send queue memory region */
663 u32 schedulerbasepointer; /* a base pointer to scheduler memory
664 region */
665 u32 txrmonbaseptr; /* base pointer to Tx RMON statistics counter */
666 u32 tstate; /* tx internal state. High byte contains
667 function code */
668 u8 iphoffset[TX_IP_OFFSET_ENTRY_MAX];
669 u32 vtagtable[0x8]; /* 8 4-byte VLAN tags */
670 u32 tqptr; /* a base pointer to the Tx Queues Memory
671 Region */
672 u8 res2[0x80 - 0x74];
673} __attribute__ ((packed)) ucc_geth_tx_global_pram_t;
674
675/* structure representing Extended Filtering Global Parameters in PRAM */
676typedef struct ucc_geth_exf_global_pram {
677 u32 l2pcdptr; /* individual address filter, high */
678 u8 res0[0x10 - 0x04];
679} __attribute__ ((packed)) ucc_geth_exf_global_pram_t;
680
681typedef struct ucc_geth_rx_global_pram {
682 u32 remoder; /* ethernet mode reg. */
683 u32 rqptr; /* base pointer to the Rx Queues Memory Region*/
684 u32 res0[0x1];
685 u8 res1[0x20 - 0xC];
686 u16 typeorlen; /* cutoff point less than which, type/len field
687 is considered length */
688 u8 res2[0x1];
689 u8 rxgstpack; /* acknowledgement on GRACEFUL STOP RX command*/
690 u32 rxrmonbaseptr; /* base pointer to Rx RMON statistics counter */
691 u8 res3[0x30 - 0x28];
692 u32 intcoalescingptr; /* Interrupt coalescing table pointer */
693 u8 res4[0x36 - 0x34];
694 u8 rstate; /* rx internal state. High byte contains
695 function code */
696 u8 res5[0x46 - 0x37];
697 u16 mrblr; /* max receive buffer length reg. */
698 u32 rbdqptr; /* base pointer to RxBD parameter table
699 description */
700 u16 mflr; /* max frame length reg. */
701 u16 minflr; /* min frame length reg. */
702 u16 maxd1; /* max dma1 length reg. */
703 u16 maxd2; /* max dma2 length reg. */
704 u32 ecamptr; /* external CAM address */
705 u32 l2qt; /* VLAN priority mapping table. */
706 u32 l3qt[0x8]; /* IP priority mapping table. */
707 u16 vlantype; /* vlan type */
708 u16 vlantci; /* default vlan tci */
709 u8 addressfiltering[64]; /* address filtering data structure */
710 u32 exfGlobalParam; /* base address for extended filtering global
711 parameters */
712 u8 res6[0x100 - 0xC4]; /* Initialize to zero */
713} __attribute__ ((packed)) ucc_geth_rx_global_pram_t;
714
715#define GRACEFUL_STOP_ACKNOWLEDGE_RX 0x01
716
717/* structure representing InitEnet command */
718typedef struct ucc_geth_init_pram {
719 u8 resinit1;
720 u8 resinit2;
721 u8 resinit3;
722 u8 resinit4;
723 u16 resinit5;
724 u8 res1[0x1];
725 u8 largestexternallookupkeysize;
726 u32 rgftgfrxglobal;
727 u32 rxthread[ENET_INIT_PARAM_MAX_ENTRIES_RX]; /* rx threads */
728 u8 res2[0x38 - 0x30];
729 u32 txglobal; /* tx global */
730 u32 txthread[ENET_INIT_PARAM_MAX_ENTRIES_TX]; /* tx threads */
731 u8 res3[0x1];
732} __attribute__ ((packed)) ucc_geth_init_pram_t;
733
734#define ENET_INIT_PARAM_RGF_SHIFT (32 - 4)
735#define ENET_INIT_PARAM_TGF_SHIFT (32 - 8)
736
737#define ENET_INIT_PARAM_RISC_MASK 0x0000003f
738#define ENET_INIT_PARAM_PTR_MASK 0x00ffffc0
739#define ENET_INIT_PARAM_SNUM_MASK 0xff000000
740#define ENET_INIT_PARAM_SNUM_SHIFT 24
741
742#define ENET_INIT_PARAM_MAGIC_RES_INIT1 0x06
743#define ENET_INIT_PARAM_MAGIC_RES_INIT2 0x30
744#define ENET_INIT_PARAM_MAGIC_RES_INIT3 0xff
745#define ENET_INIT_PARAM_MAGIC_RES_INIT4 0x00
746#define ENET_INIT_PARAM_MAGIC_RES_INIT5 0x0400
747
748/* structure representing 82xx Address Filtering Enet Address in PRAM */
749typedef struct ucc_geth_82xx_enet_address {
750 u8 res1[0x2];
751 u16 h; /* address (MSB) */
752 u16 m; /* address */
753 u16 l; /* address (LSB) */
754} __attribute__ ((packed)) ucc_geth_82xx_enet_address_t;
755
756/* structure representing 82xx Address Filtering PRAM */
757typedef struct ucc_geth_82xx_address_filtering_pram {
758 u32 iaddr_h; /* individual address filter, high */
759 u32 iaddr_l; /* individual address filter, low */
760 u32 gaddr_h; /* group address filter, high */
761 u32 gaddr_l; /* group address filter, low */
762 ucc_geth_82xx_enet_address_t taddr;
763 ucc_geth_82xx_enet_address_t paddr[NUM_OF_PADDRS];
764 u8 res0[0x40 - 0x38];
765} __attribute__ ((packed)) ucc_geth_82xx_address_filtering_pram_t;
766
767/* GETH Tx firmware statistics structure, used when calling
768 UCC_GETH_GetStatistics. */
769typedef struct ucc_geth_tx_firmware_statistics {
770 u32 sicoltx; /* single collision */
771 u32 mulcoltx; /* multiple collision */
772 u32 latecoltxfr; /* late collision */
773 u32 frabortduecol; /* frames aborted due to transmit collision */
774 u32 frlostinmactxer; /* frames lost due to internal MAC error
775 transmission that are not counted on any
776 other counter */
777 u32 carriersenseertx; /* carrier sense error */
778 u32 frtxok; /* frames transmitted OK */
779 u32 txfrexcessivedefer; /* frames with defferal time greater than
780 specified threshold */
781 u32 txpkts256; /* total packets (including bad) between 256
782 and 511 octets */
783 u32 txpkts512; /* total packets (including bad) between 512
784 and 1023 octets */
785 u32 txpkts1024; /* total packets (including bad) between 1024
786 and 1518 octets */
787 u32 txpktsjumbo; /* total packets (including bad) between 1024
788 and MAXLength octets */
789} __attribute__ ((packed)) ucc_geth_tx_firmware_statistics_t;
790
791/* GETH Rx firmware statistics structure, used when calling
792 UCC_GETH_GetStatistics. */
793typedef struct ucc_geth_rx_firmware_statistics {
794 u32 frrxfcser; /* frames with crc error */
795 u32 fraligner; /* frames with alignment error */
796 u32 inrangelenrxer; /* in range length error */
797 u32 outrangelenrxer; /* out of range length error */
798 u32 frtoolong; /* frame too long */
799 u32 runt; /* runt */
800 u32 verylongevent; /* very long event */
801 u32 symbolerror; /* symbol error */
802 u32 dropbsy; /* drop because of BD not ready */
803 u8 res0[0x8];
804 u32 mismatchdrop; /* drop because of MAC filtering (e.g. address
805 or type mismatch) */
806 u32 underpkts; /* total frames less than 64 octets */
807 u32 pkts256; /* total frames (including bad) between 256 and
808 511 octets */
809 u32 pkts512; /* total frames (including bad) between 512 and
810 1023 octets */
811 u32 pkts1024; /* total frames (including bad) between 1024
812 and 1518 octets */
813 u32 pktsjumbo; /* total frames (including bad) between 1024
814 and MAXLength octets */
815 u32 frlossinmacer; /* frames lost because of internal MAC error
816 that is not counted in any other counter */
817 u32 pausefr; /* pause frames */
818 u8 res1[0x4];
819 u32 removevlan; /* total frames that had their VLAN tag removed
820 */
821 u32 replacevlan; /* total frames that had their VLAN tag
822 replaced */
823 u32 insertvlan; /* total frames that had their VLAN tag
824 inserted */
825} __attribute__ ((packed)) ucc_geth_rx_firmware_statistics_t;
826
827/* GETH hardware statistics structure, used when calling
828 UCC_GETH_GetStatistics. */
829typedef struct ucc_geth_hardware_statistics {
830 u32 tx64; /* Total number of frames (including bad
831 frames) transmitted that were exactly of the
832 minimal length (64 for un tagged, 68 for
833 tagged, or with length exactly equal to the
834 parameter MINLength */
835 u32 tx127; /* Total number of frames (including bad
836 frames) transmitted that were between
837 MINLength (Including FCS length==4) and 127
838 octets */
839 u32 tx255; /* Total number of frames (including bad
840 frames) transmitted that were between 128
841 (Including FCS length==4) and 255 octets */
842 u32 rx64; /* Total number of frames received including
843 bad frames that were exactly of the mninimal
844 length (64 bytes) */
845 u32 rx127; /* Total number of frames (including bad
846 frames) received that were between MINLength
847 (Including FCS length==4) and 127 octets */
848 u32 rx255; /* Total number of frames (including bad
849 frames) received that were between 128
850 (Including FCS length==4) and 255 octets */
851 u32 txok; /* Total number of octets residing in frames
852 that where involved in succesfull
853 transmission */
854 u16 txcf; /* Total number of PAUSE control frames
855 transmitted by this MAC */
856 u32 tmca; /* Total number of frames that were transmitted
857 succesfully with the group address bit set
858 that are not broadcast frames */
859 u32 tbca; /* Total number of frames transmitted
860 succesfully that had destination address
861 field equal to the broadcast address */
862 u32 rxfok; /* Total number of frames received OK */
863 u32 rxbok; /* Total number of octets received OK */
864 u32 rbyt; /* Total number of octets received including
865 octets in bad frames. Must be implemented in
866 HW because it includes octets in frames that
867 never even reach the UCC */
868 u32 rmca; /* Total number of frames that were received
869 succesfully with the group address bit set
870 that are not broadcast frames */
871 u32 rbca; /* Total number of frames received succesfully
872 that had destination address equal to the
873 broadcast address */
874} __attribute__ ((packed)) ucc_geth_hardware_statistics_t;
875
876/* UCC GETH Tx errors returned via TxConf callback */
877#define TX_ERRORS_DEF 0x0200
878#define TX_ERRORS_EXDEF 0x0100
879#define TX_ERRORS_LC 0x0080
880#define TX_ERRORS_RL 0x0040
881#define TX_ERRORS_RC_MASK 0x003C
882#define TX_ERRORS_RC_SHIFT 2
883#define TX_ERRORS_UN 0x0002
884#define TX_ERRORS_CSL 0x0001
885
886/* UCC GETH Rx errors returned via RxStore callback */
887#define RX_ERRORS_CMR 0x0200
888#define RX_ERRORS_M 0x0100
889#define RX_ERRORS_BC 0x0080
890#define RX_ERRORS_MC 0x0040
891
892/* Transmit BD. These are in addition to values defined in uccf. */
893#define T_VID 0x003c0000 /* insert VLAN id index mask. */
894#define T_DEF (((u32) TX_ERRORS_DEF ) << 16)
895#define T_EXDEF (((u32) TX_ERRORS_EXDEF ) << 16)
896#define T_LC (((u32) TX_ERRORS_LC ) << 16)
897#define T_RL (((u32) TX_ERRORS_RL ) << 16)
898#define T_RC_MASK (((u32) TX_ERRORS_RC_MASK ) << 16)
899#define T_UN (((u32) TX_ERRORS_UN ) << 16)
900#define T_CSL (((u32) TX_ERRORS_CSL ) << 16)
901#define T_ERRORS_REPORT (T_DEF | T_EXDEF | T_LC | T_RL | T_RC_MASK \
902 | T_UN | T_CSL) /* transmit errors to report */
903
904/* Receive BD. These are in addition to values defined in uccf. */
905#define R_LG 0x00200000 /* Frame length violation. */
906#define R_NO 0x00100000 /* Non-octet aligned frame. */
907#define R_SH 0x00080000 /* Short frame. */
908#define R_CR 0x00040000 /* CRC error. */
909#define R_OV 0x00020000 /* Overrun. */
910#define R_IPCH 0x00010000 /* IP checksum check failed. */
911#define R_CMR (((u32) RX_ERRORS_CMR ) << 16)
912#define R_M (((u32) RX_ERRORS_M ) << 16)
913#define R_BC (((u32) RX_ERRORS_BC ) << 16)
914#define R_MC (((u32) RX_ERRORS_MC ) << 16)
915#define R_ERRORS_REPORT (R_CMR | R_M | R_BC | R_MC) /* receive errors to
916 report */
917#define R_ERRORS_FATAL (R_LG | R_NO | R_SH | R_CR | \
918 R_OV | R_IPCH) /* receive errors to discard */
919
920/* Alignments */
921#define UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT 256
922#define UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT 128
923#define UCC_GETH_THREAD_RX_PRAM_ALIGNMENT 128
924#define UCC_GETH_THREAD_TX_PRAM_ALIGNMENT 64
925#define UCC_GETH_THREAD_DATA_ALIGNMENT 256 /* spec gives values
926 based on num of
927 threads, but always
928 using the maximum is
929 easier */
930#define UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT 32
931#define UCC_GETH_SCHEDULER_ALIGNMENT 4 /* This is a guess */
932#define UCC_GETH_TX_STATISTICS_ALIGNMENT 4 /* This is a guess */
933#define UCC_GETH_RX_STATISTICS_ALIGNMENT 4 /* This is a guess */
934#define UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT 4 /* This is a
935 guess */
936#define UCC_GETH_RX_BD_QUEUES_ALIGNMENT 8 /* This is a guess */
937#define UCC_GETH_RX_PREFETCHED_BDS_ALIGNMENT 128 /* This is a guess */
938#define UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT 4 /* This
939 is a
940 guess
941 */
942#define UCC_GETH_RX_BD_RING_ALIGNMENT 32
943#define UCC_GETH_TX_BD_RING_ALIGNMENT 32
944#define UCC_GETH_MRBLR_ALIGNMENT 128
945#define UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT 4
946#define UCC_GETH_TX_BD_RING_SIZE_MEMORY_ALIGNMENT 32
947#define UCC_GETH_RX_DATA_BUF_ALIGNMENT 64
948
949#define UCC_GETH_TAD_EF 0x80
950#define UCC_GETH_TAD_V 0x40
951#define UCC_GETH_TAD_REJ 0x20
952#define UCC_GETH_TAD_VTAG_OP_RIGHT_SHIFT 2
953#define UCC_GETH_TAD_VTAG_OP_SHIFT 6
954#define UCC_GETH_TAD_V_NON_VTAG_OP 0x20
955#define UCC_GETH_TAD_RQOS_SHIFT 0
956#define UCC_GETH_TAD_V_PRIORITY_SHIFT 5
957#define UCC_GETH_TAD_CFI 0x10
958
959#define UCC_GETH_VLAN_PRIORITY_MAX 8
960#define UCC_GETH_IP_PRIORITY_MAX 64
961#define UCC_GETH_TX_VTAG_TABLE_ENTRY_MAX 8
962#define UCC_GETH_RX_BD_RING_SIZE_MIN 8
963#define UCC_GETH_TX_BD_RING_SIZE_MIN 2
964
965#define UCC_GETH_SIZE_OF_BD QE_SIZEOF_BD
966
967/* Driver definitions */
968#define TX_BD_RING_LEN 0x10
969#define RX_BD_RING_LEN 0x10
970#define UCC_GETH_DEV_WEIGHT TX_BD_RING_LEN
971
972#define TX_RING_MOD_MASK(size) (size-1)
973#define RX_RING_MOD_MASK(size) (size-1)
974
975#define ENET_NUM_OCTETS_PER_ADDRESS 6
976#define ENET_GROUP_ADDR 0x01 /* Group address mask
977 for ethernet
978 addresses */
979
980#define TX_TIMEOUT (1*HZ)
981#define SKB_ALLOC_TIMEOUT 100000
982#define PHY_INIT_TIMEOUT 100000
983#define PHY_CHANGE_TIME 2
984
985/* Fast Ethernet (10/100 Mbps) */
986#define UCC_GETH_URFS_INIT 512 /* Rx virtual FIFO size
987 */
988#define UCC_GETH_URFET_INIT 256 /* 1/2 urfs */
989#define UCC_GETH_URFSET_INIT 384 /* 3/4 urfs */
990#define UCC_GETH_UTFS_INIT 512 /* Tx virtual FIFO size
991 */
992#define UCC_GETH_UTFET_INIT 256 /* 1/2 utfs */
993#define UCC_GETH_UTFTT_INIT 128
994/* Gigabit Ethernet (1000 Mbps) */
995#define UCC_GETH_URFS_GIGA_INIT 4096/*2048*/ /* Rx virtual
996 FIFO size */
997#define UCC_GETH_URFET_GIGA_INIT 2048/*1024*/ /* 1/2 urfs */
998#define UCC_GETH_URFSET_GIGA_INIT 3072/*1536*/ /* 3/4 urfs */
999#define UCC_GETH_UTFS_GIGA_INIT 8192/*2048*/ /* Tx virtual
1000 FIFO size */
1001#define UCC_GETH_UTFET_GIGA_INIT 4096/*1024*/ /* 1/2 utfs */
1002#define UCC_GETH_UTFTT_GIGA_INIT 0x400/*0x40*/ /* */
1003
1004#define UCC_GETH_REMODER_INIT 0 /* bits that must be
1005 set */
1006#define UCC_GETH_TEMODER_INIT 0xC000 /* bits that must */
1007#define UCC_GETH_UPSMR_INIT (UPSMR_RES1) /* Start value
1008 for this
1009 register */
1010#define UCC_GETH_MACCFG1_INIT 0
1011#define UCC_GETH_MACCFG2_INIT (MACCFG2_RESERVED_1)
1012#define UCC_GETH_MIIMCFG_MNGMNT_CLC_DIV_INIT \
1013 (MIIMCFG_MANAGEMENT_CLOCK_DIVIDE_BY_112)
1014
1015/* Ethernet speed */
1016typedef enum enet_speed {
1017 ENET_SPEED_10BT, /* 10 Base T */
1018 ENET_SPEED_100BT, /* 100 Base T */
1019 ENET_SPEED_1000BT /* 1000 Base T */
1020} enet_speed_e;
1021
1022/* Ethernet Address Type. */
1023typedef enum enet_addr_type {
1024 ENET_ADDR_TYPE_INDIVIDUAL,
1025 ENET_ADDR_TYPE_GROUP,
1026 ENET_ADDR_TYPE_BROADCAST
1027} enet_addr_type_e;
1028
1029/* TBI / MII Set Register */
1030typedef enum enet_tbi_mii_reg {
1031 ENET_TBI_MII_CR = 0x00, /* Control (CR ) */
1032 ENET_TBI_MII_SR = 0x01, /* Status (SR ) */
1033 ENET_TBI_MII_ANA = 0x04, /* AN advertisement (ANA ) */
1034 ENET_TBI_MII_ANLPBPA = 0x05, /* AN link partner base page ability
1035 (ANLPBPA) */
1036 ENET_TBI_MII_ANEX = 0x06, /* AN expansion (ANEX ) */
1037 ENET_TBI_MII_ANNPT = 0x07, /* AN next page transmit (ANNPT ) */
1038 ENET_TBI_MII_ANLPANP = 0x08, /* AN link partner ability next page
1039 (ANLPANP) */
1040 ENET_TBI_MII_EXST = 0x0F, /* Extended status (EXST ) */
1041 ENET_TBI_MII_JD = 0x10, /* Jitter diagnostics (JD ) */
1042 ENET_TBI_MII_TBICON = 0x11 /* TBI control (TBICON ) */
1043} enet_tbi_mii_reg_e;
1044
1045/* UCC GETH 82xx Ethernet Address Recognition Location */
1046typedef enum ucc_geth_enet_address_recognition_location {
1047 UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_STATION_ADDRESS,/* station
1048 address */
1049 UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_PADDR_FIRST, /* additional
1050 station
1051 address
1052 paddr1 */
1053 UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_PADDR2, /* additional
1054 station
1055 address
1056 paddr2 */
1057 UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_PADDR3, /* additional
1058 station
1059 address
1060 paddr3 */
1061 UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_PADDR_LAST, /* additional
1062 station
1063 address
1064 paddr4 */
1065 UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_GROUP_HASH, /* group hash */
1066 UCC_GETH_ENET_ADDRESS_RECOGNITION_LOCATION_INDIVIDUAL_HASH /* individual
1067 hash */
1068} ucc_geth_enet_address_recognition_location_e;
1069
1070/* UCC GETH vlan operation tagged */
1071typedef enum ucc_geth_vlan_operation_tagged {
1072 UCC_GETH_VLAN_OPERATION_TAGGED_NOP = 0x0, /* Tagged - nop */
1073 UCC_GETH_VLAN_OPERATION_TAGGED_REPLACE_VID_PORTION_OF_Q_TAG
1074 = 0x1, /* Tagged - replace vid portion of q tag */
1075 UCC_GETH_VLAN_OPERATION_TAGGED_IF_VID0_REPLACE_VID_WITH_DEFAULT_VALUE
1076 = 0x2, /* Tagged - if vid0 replace vid with default value */
1077 UCC_GETH_VLAN_OPERATION_TAGGED_EXTRACT_Q_TAG_FROM_FRAME
1078 = 0x3 /* Tagged - extract q tag from frame */
1079} ucc_geth_vlan_operation_tagged_e;
1080
1081/* UCC GETH vlan operation non-tagged */
1082typedef enum ucc_geth_vlan_operation_non_tagged {
1083 UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP = 0x0, /* Non tagged - nop */
1084 UCC_GETH_VLAN_OPERATION_NON_TAGGED_Q_TAG_INSERT = 0x1 /* Non tagged -
1085 q tag insert
1086 */
1087} ucc_geth_vlan_operation_non_tagged_e;
1088
1089/* UCC GETH Rx Quality of Service Mode */
1090typedef enum ucc_geth_qos_mode {
1091 UCC_GETH_QOS_MODE_DEFAULT = 0x0, /* default queue */
1092 UCC_GETH_QOS_MODE_QUEUE_NUM_FROM_L2_CRITERIA = 0x1, /* queue
1093 determined
1094 by L2
1095 criteria */
1096 UCC_GETH_QOS_MODE_QUEUE_NUM_FROM_L3_CRITERIA = 0x2 /* queue
1097 determined
1098 by L3
1099 criteria */
1100} ucc_geth_qos_mode_e;
1101
1102/* UCC GETH Statistics Gathering Mode - These are bit flags, 'or' them together
1103 for combined functionality */
1104typedef enum ucc_geth_statistics_gathering_mode {
1105 UCC_GETH_STATISTICS_GATHERING_MODE_NONE = 0x00000000, /* No
1106 statistics
1107 gathering */
1108 UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE = 0x00000001,/* Enable
1109 hardware
1110 statistics
1111 gathering
1112 */
1113 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX = 0x00000004,/*Enable
1114 firmware
1115 tx
1116 statistics
1117 gathering
1118 */
1119 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX = 0x00000008/* Enable
1120 firmware
1121 rx
1122 statistics
1123 gathering
1124 */
1125} ucc_geth_statistics_gathering_mode_e;
1126
1127/* UCC GETH Pad and CRC Mode - Note, Padding without CRC is not possible */
1128typedef enum ucc_geth_maccfg2_pad_and_crc_mode {
1129 UCC_GETH_PAD_AND_CRC_MODE_NONE
1130 = MACCFG2_PAD_AND_CRC_MODE_NONE, /* Neither Padding
1131 short frames
1132 nor CRC */
1133 UCC_GETH_PAD_AND_CRC_MODE_CRC_ONLY
1134 = MACCFG2_PAD_AND_CRC_MODE_CRC_ONLY, /* Append
1135 CRC only */
1136 UCC_GETH_PAD_AND_CRC_MODE_PAD_AND_CRC =
1137 MACCFG2_PAD_AND_CRC_MODE_PAD_AND_CRC
1138} ucc_geth_maccfg2_pad_and_crc_mode_e;
1139
1140/* UCC GETH upsmr Flow Control Mode */
1141typedef enum ucc_geth_flow_control_mode {
1142 UPSMR_AUTOMATIC_FLOW_CONTROL_MODE_NONE = 0x00000000, /* No automatic
1143 flow control
1144 */
1145 UPSMR_AUTOMATIC_FLOW_CONTROL_MODE_PAUSE_WHEN_EMERGENCY
1146 = 0x00004000 /* Send pause frame when RxFIFO reaches its
1147 emergency threshold */
1148} ucc_geth_flow_control_mode_e;
1149
1150/* UCC GETH number of threads */
1151typedef enum ucc_geth_num_of_threads {
1152 UCC_GETH_NUM_OF_THREADS_1 = 0x1, /* 1 */
1153 UCC_GETH_NUM_OF_THREADS_2 = 0x2, /* 2 */
1154 UCC_GETH_NUM_OF_THREADS_4 = 0x0, /* 4 */
1155 UCC_GETH_NUM_OF_THREADS_6 = 0x3, /* 6 */
1156 UCC_GETH_NUM_OF_THREADS_8 = 0x4 /* 8 */
1157} ucc_geth_num_of_threads_e;
1158
1159/* UCC GETH number of station addresses */
1160typedef enum ucc_geth_num_of_station_addresses {
1161 UCC_GETH_NUM_OF_STATION_ADDRESSES_1, /* 1 */
1162 UCC_GETH_NUM_OF_STATION_ADDRESSES_5 /* 5 */
1163} ucc_geth_num_of_station_addresses_e;
1164
1165typedef u8 enet_addr_t[ENET_NUM_OCTETS_PER_ADDRESS];
1166
1167/* UCC GETH 82xx Ethernet Address Container */
1168typedef struct enet_addr_container {
1169 enet_addr_t address; /* ethernet address */
1170 ucc_geth_enet_address_recognition_location_e location; /* location in
1171 82xx address
1172 recognition
1173 hardware */
1174 struct list_head node;
1175} enet_addr_container_t;
1176
1177#define ENET_ADDR_CONT_ENTRY(ptr) list_entry(ptr, enet_addr_container_t, node)
1178
1179/* UCC GETH Termination Action Descriptor (TAD) structure. */
1180typedef struct ucc_geth_tad_params {
1181 int rx_non_dynamic_extended_features_mode;
1182 int reject_frame;
1183 ucc_geth_vlan_operation_tagged_e vtag_op;
1184 ucc_geth_vlan_operation_non_tagged_e vnontag_op;
1185 ucc_geth_qos_mode_e rqos;
1186 u8 vpri;
1187 u16 vid;
1188} ucc_geth_tad_params_t;
1189
1190/* GETH protocol initialization structure */
1191typedef struct ucc_geth_info {
1192 ucc_fast_info_t uf_info;
1193 u8 numQueuesTx;
1194 u8 numQueuesRx;
1195 int ipCheckSumCheck;
1196 int ipCheckSumGenerate;
1197 int rxExtendedFiltering;
1198 u32 extendedFilteringChainPointer;
1199 u16 typeorlen;
1200 int dynamicMaxFrameLength;
1201 int dynamicMinFrameLength;
1202 u8 nonBackToBackIfgPart1;
1203 u8 nonBackToBackIfgPart2;
1204 u8 miminumInterFrameGapEnforcement;
1205 u8 backToBackInterFrameGap;
1206 int ipAddressAlignment;
1207 int lengthCheckRx;
1208 u32 mblinterval;
1209 u16 nortsrbytetime;
1210 u8 fracsiz;
1211 u8 strictpriorityq;
1212 u8 txasap;
1213 u8 extrabw;
1214 int miiPreambleSupress;
1215 u8 altBebTruncation;
1216 int altBeb;
1217 int backPressureNoBackoff;
1218 int noBackoff;
1219 int excessDefer;
1220 u8 maxRetransmission;
1221 u8 collisionWindow;
1222 int pro;
1223 int cap;
1224 int rsh;
1225 int rlpb;
1226 int cam;
1227 int bro;
1228 int ecm;
1229 int receiveFlowControl;
1230 u8 maxGroupAddrInHash;
1231 u8 maxIndAddrInHash;
1232 u8 prel;
1233 u16 maxFrameLength;
1234 u16 minFrameLength;
1235 u16 maxD1Length;
1236 u16 maxD2Length;
1237 u16 vlantype;
1238 u16 vlantci;
1239 u32 ecamptr;
1240 u32 eventRegMask;
1241 u16 pausePeriod;
1242 u16 extensionField;
1243 u8 phy_address;
1244 u32 board_flags;
1245 u32 phy_interrupt;
1246 u8 weightfactor[NUM_TX_QUEUES];
1247 u8 interruptcoalescingmaxvalue[NUM_RX_QUEUES];
1248 u8 l2qt[UCC_GETH_VLAN_PRIORITY_MAX];
1249 u8 l3qt[UCC_GETH_IP_PRIORITY_MAX];
1250 u32 vtagtable[UCC_GETH_TX_VTAG_TABLE_ENTRY_MAX];
1251 u8 iphoffset[TX_IP_OFFSET_ENTRY_MAX];
1252 u16 bdRingLenTx[NUM_TX_QUEUES];
1253 u16 bdRingLenRx[NUM_RX_QUEUES];
1254 enet_interface_e enet_interface;
1255 ucc_geth_num_of_station_addresses_e numStationAddresses;
1256 qe_fltr_largest_external_tbl_lookup_key_size_e
1257 largestexternallookupkeysize;
1258 ucc_geth_statistics_gathering_mode_e statisticsMode;
1259 ucc_geth_vlan_operation_tagged_e vlanOperationTagged;
1260 ucc_geth_vlan_operation_non_tagged_e vlanOperationNonTagged;
1261 ucc_geth_qos_mode_e rxQoSMode;
1262 ucc_geth_flow_control_mode_e aufc;
1263 ucc_geth_maccfg2_pad_and_crc_mode_e padAndCrc;
1264 ucc_geth_num_of_threads_e numThreadsTx;
1265 ucc_geth_num_of_threads_e numThreadsRx;
1266 qe_risc_allocation_e riscTx;
1267 qe_risc_allocation_e riscRx;
1268} ucc_geth_info_t;
1269
1270/* structure representing UCC GETH */
1271typedef struct ucc_geth_private {
1272 ucc_geth_info_t *ug_info;
1273 ucc_fast_private_t *uccf;
1274 struct net_device *dev;
1275 struct net_device_stats stats; /* linux network statistics */
1276 ucc_geth_t *ug_regs;
1277 ucc_geth_init_pram_t *p_init_enet_param_shadow;
1278 ucc_geth_exf_global_pram_t *p_exf_glbl_param;
1279 u32 exf_glbl_param_offset;
1280 ucc_geth_rx_global_pram_t *p_rx_glbl_pram;
1281 u32 rx_glbl_pram_offset;
1282 ucc_geth_tx_global_pram_t *p_tx_glbl_pram;
1283 u32 tx_glbl_pram_offset;
1284 ucc_geth_send_queue_mem_region_t *p_send_q_mem_reg;
1285 u32 send_q_mem_reg_offset;
1286 ucc_geth_thread_data_tx_t *p_thread_data_tx;
1287 u32 thread_dat_tx_offset;
1288 ucc_geth_thread_data_rx_t *p_thread_data_rx;
1289 u32 thread_dat_rx_offset;
1290 ucc_geth_scheduler_t *p_scheduler;
1291 u32 scheduler_offset;
1292 ucc_geth_tx_firmware_statistics_pram_t *p_tx_fw_statistics_pram;
1293 u32 tx_fw_statistics_pram_offset;
1294 ucc_geth_rx_firmware_statistics_pram_t *p_rx_fw_statistics_pram;
1295 u32 rx_fw_statistics_pram_offset;
1296 ucc_geth_rx_interrupt_coalescing_table_t *p_rx_irq_coalescing_tbl;
1297 u32 rx_irq_coalescing_tbl_offset;
1298 ucc_geth_rx_bd_queues_entry_t *p_rx_bd_qs_tbl;
1299 u32 rx_bd_qs_tbl_offset;
1300 u8 *p_tx_bd_ring[NUM_TX_QUEUES];
1301 u32 tx_bd_ring_offset[NUM_TX_QUEUES];
1302 u8 *p_rx_bd_ring[NUM_RX_QUEUES];
1303 u32 rx_bd_ring_offset[NUM_RX_QUEUES];
1304 u8 *confBd[NUM_TX_QUEUES];
1305 u8 *txBd[NUM_TX_QUEUES];
1306 u8 *rxBd[NUM_RX_QUEUES];
1307 int badFrame[NUM_RX_QUEUES];
1308 u16 cpucount[NUM_TX_QUEUES];
1309 volatile u16 *p_cpucount[NUM_TX_QUEUES];
1310 int indAddrRegUsed[NUM_OF_PADDRS];
1311 enet_addr_t paddr[NUM_OF_PADDRS];
1312 u8 numGroupAddrInHash;
1313 u8 numIndAddrInHash;
1314 u8 numIndAddrInReg;
1315 int rx_extended_features;
1316 int rx_non_dynamic_extended_features;
1317 struct list_head conf_skbs;
1318 struct list_head group_hash_q;
1319 struct list_head ind_hash_q;
1320 u32 saved_uccm;
1321 spinlock_t lock;
1322 /* pointers to arrays of skbuffs for tx and rx */
1323 struct sk_buff **tx_skbuff[NUM_TX_QUEUES];
1324 struct sk_buff **rx_skbuff[NUM_RX_QUEUES];
1325 /* indices pointing to the next free sbk in skb arrays */
1326 u16 skb_curtx[NUM_TX_QUEUES];
1327 u16 skb_currx[NUM_RX_QUEUES];
1328 /* index of the first skb which hasn't been transmitted yet. */
1329 u16 skb_dirtytx[NUM_TX_QUEUES];
1330
1331 struct work_struct tq;
1332 struct timer_list phy_info_timer;
1333 struct ugeth_mii_info *mii_info;
1334 int oldspeed;
1335 int oldduplex;
1336 int oldlink;
1337} ucc_geth_private_t;
1338
1339#endif /* __UCC_GETH_H__ */
diff --git a/drivers/net/ucc_geth_phy.c b/drivers/net/ucc_geth_phy.c
new file mode 100644
index 000000000000..f91028c5386d
--- /dev/null
+++ b/drivers/net/ucc_geth_phy.c
@@ -0,0 +1,801 @@
1/*
2 * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved.
3 *
4 * Author: Shlomi Gridish <gridish@freescale.com>
5 *
6 * Description:
7 * UCC GETH Driver -- PHY handling
8 *
9 * Changelog:
10 * Jun 28, 2006 Li Yang <LeoLi@freescale.com>
11 * - Rearrange code and style fixes
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 */
19
20#include <linux/config.h>
21#include <linux/kernel.h>
22#include <linux/sched.h>
23#include <linux/string.h>
24#include <linux/errno.h>
25#include <linux/slab.h>
26#include <linux/interrupt.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/netdevice.h>
30#include <linux/etherdevice.h>
31#include <linux/skbuff.h>
32#include <linux/spinlock.h>
33#include <linux/mm.h>
34#include <linux/module.h>
35#include <linux/version.h>
36#include <linux/crc32.h>
37#include <linux/mii.h>
38#include <linux/ethtool.h>
39
40#include <asm/io.h>
41#include <asm/irq.h>
42#include <asm/uaccess.h>
43
44#include "ucc_geth.h"
45#include "ucc_geth_phy.h"
46#include <platforms/83xx/mpc8360e_pb.h>
47
48#define ugphy_printk(level, format, arg...) \
49 printk(level format "\n", ## arg)
50
51#define ugphy_dbg(format, arg...) \
52 ugphy_printk(KERN_DEBUG, format , ## arg)
53#define ugphy_err(format, arg...) \
54 ugphy_printk(KERN_ERR, format , ## arg)
55#define ugphy_info(format, arg...) \
56 ugphy_printk(KERN_INFO, format , ## arg)
57#define ugphy_warn(format, arg...) \
58 ugphy_printk(KERN_WARNING, format , ## arg)
59
60#ifdef UGETH_VERBOSE_DEBUG
61#define ugphy_vdbg ugphy_dbg
62#else
63#define ugphy_vdbg(fmt, args...) do { } while (0)
64#endif /* UGETH_VERBOSE_DEBUG */
65
66static void config_genmii_advert(struct ugeth_mii_info *mii_info);
67static void genmii_setup_forced(struct ugeth_mii_info *mii_info);
68static void genmii_restart_aneg(struct ugeth_mii_info *mii_info);
69static int gbit_config_aneg(struct ugeth_mii_info *mii_info);
70static int genmii_config_aneg(struct ugeth_mii_info *mii_info);
71static int genmii_update_link(struct ugeth_mii_info *mii_info);
72static int genmii_read_status(struct ugeth_mii_info *mii_info);
73u16 phy_read(struct ugeth_mii_info *mii_info, u16 regnum);
74void phy_write(struct ugeth_mii_info *mii_info, u16 regnum, u16 val);
75
76static u8 *bcsr_regs = NULL;
77
78/* Write value to the PHY for this device to the register at regnum, */
79/* waiting until the write is done before it returns. All PHY */
80/* configuration has to be done through the TSEC1 MIIM regs */
81void write_phy_reg(struct net_device *dev, int mii_id, int regnum, int value)
82{
83 ucc_geth_private_t *ugeth = netdev_priv(dev);
84 ucc_mii_mng_t *mii_regs;
85 enet_tbi_mii_reg_e mii_reg = (enet_tbi_mii_reg_e) regnum;
86 u32 tmp_reg;
87
88 ugphy_vdbg("%s: IN", __FUNCTION__);
89
90 spin_lock_irq(&ugeth->lock);
91
92 mii_regs = ugeth->mii_info->mii_regs;
93
94 /* Set this UCC to be the master of the MII managment */
95 ucc_set_qe_mux_mii_mng(ugeth->ug_info->uf_info.ucc_num);
96
97 /* Stop the MII management read cycle */
98 out_be32(&mii_regs->miimcom, 0);
99 /* Setting up the MII Mangement Address Register */
100 tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg;
101 out_be32(&mii_regs->miimadd, tmp_reg);
102
103 /* Setting up the MII Mangement Control Register with the value */
104 out_be32(&mii_regs->miimcon, (u32) value);
105
106 /* Wait till MII management write is complete */
107 while ((in_be32(&mii_regs->miimind)) & MIIMIND_BUSY)
108 cpu_relax();
109
110 spin_unlock_irq(&ugeth->lock);
111
112 udelay(10000);
113}
114
115/* Reads from register regnum in the PHY for device dev, */
116/* returning the value. Clears miimcom first. All PHY */
117/* configuration has to be done through the TSEC1 MIIM regs */
118int read_phy_reg(struct net_device *dev, int mii_id, int regnum)
119{
120 ucc_geth_private_t *ugeth = netdev_priv(dev);
121 ucc_mii_mng_t *mii_regs;
122 enet_tbi_mii_reg_e mii_reg = (enet_tbi_mii_reg_e) regnum;
123 u32 tmp_reg;
124 u16 value;
125
126 ugphy_vdbg("%s: IN", __FUNCTION__);
127
128 spin_lock_irq(&ugeth->lock);
129
130 mii_regs = ugeth->mii_info->mii_regs;
131
132 /* Setting up the MII Mangement Address Register */
133 tmp_reg = ((u32) mii_id << MIIMADD_PHY_ADDRESS_SHIFT) | mii_reg;
134 out_be32(&mii_regs->miimadd, tmp_reg);
135
136 /* Perform an MII management read cycle */
137 out_be32(&mii_regs->miimcom, MIIMCOM_READ_CYCLE);
138
139 /* Wait till MII management write is complete */
140 while ((in_be32(&mii_regs->miimind)) & MIIMIND_BUSY)
141 cpu_relax();
142
143 udelay(10000);
144
145 /* Read MII management status */
146 value = (u16) in_be32(&mii_regs->miimstat);
147 out_be32(&mii_regs->miimcom, 0);
148 if (value == 0xffff)
149 ugphy_warn("read wrong value : mii_id %d,mii_reg %d, base %08x",
150 mii_id, mii_reg, (u32) & (mii_regs->miimcfg));
151
152 spin_unlock_irq(&ugeth->lock);
153
154 return (value);
155}
156
157void mii_clear_phy_interrupt(struct ugeth_mii_info *mii_info)
158{
159 ugphy_vdbg("%s: IN", __FUNCTION__);
160
161 if (mii_info->phyinfo->ack_interrupt)
162 mii_info->phyinfo->ack_interrupt(mii_info);
163}
164
165void mii_configure_phy_interrupt(struct ugeth_mii_info *mii_info,
166 u32 interrupts)
167{
168 ugphy_vdbg("%s: IN", __FUNCTION__);
169
170 mii_info->interrupts = interrupts;
171 if (mii_info->phyinfo->config_intr)
172 mii_info->phyinfo->config_intr(mii_info);
173}
174
175/* Writes MII_ADVERTISE with the appropriate values, after
176 * sanitizing advertise to make sure only supported features
177 * are advertised
178 */
179static void config_genmii_advert(struct ugeth_mii_info *mii_info)
180{
181 u32 advertise;
182 u16 adv;
183
184 ugphy_vdbg("%s: IN", __FUNCTION__);
185
186 /* Only allow advertising what this PHY supports */
187 mii_info->advertising &= mii_info->phyinfo->features;
188 advertise = mii_info->advertising;
189
190 /* Setup standard advertisement */
191 adv = phy_read(mii_info, MII_ADVERTISE);
192 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
193 if (advertise & ADVERTISED_10baseT_Half)
194 adv |= ADVERTISE_10HALF;
195 if (advertise & ADVERTISED_10baseT_Full)
196 adv |= ADVERTISE_10FULL;
197 if (advertise & ADVERTISED_100baseT_Half)
198 adv |= ADVERTISE_100HALF;
199 if (advertise & ADVERTISED_100baseT_Full)
200 adv |= ADVERTISE_100FULL;
201 phy_write(mii_info, MII_ADVERTISE, adv);
202}
203
204static void genmii_setup_forced(struct ugeth_mii_info *mii_info)
205{
206 u16 ctrl;
207 u32 features = mii_info->phyinfo->features;
208
209 ugphy_vdbg("%s: IN", __FUNCTION__);
210
211 ctrl = phy_read(mii_info, MII_BMCR);
212
213 ctrl &=
214 ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_SPEED1000 | BMCR_ANENABLE);
215 ctrl |= BMCR_RESET;
216
217 switch (mii_info->speed) {
218 case SPEED_1000:
219 if (features & (SUPPORTED_1000baseT_Half
220 | SUPPORTED_1000baseT_Full)) {
221 ctrl |= BMCR_SPEED1000;
222 break;
223 }
224 mii_info->speed = SPEED_100;
225 case SPEED_100:
226 if (features & (SUPPORTED_100baseT_Half
227 | SUPPORTED_100baseT_Full)) {
228 ctrl |= BMCR_SPEED100;
229 break;
230 }
231 mii_info->speed = SPEED_10;
232 case SPEED_10:
233 if (features & (SUPPORTED_10baseT_Half
234 | SUPPORTED_10baseT_Full))
235 break;
236 default: /* Unsupported speed! */
237 ugphy_err("%s: Bad speed!", mii_info->dev->name);
238 break;
239 }
240
241 phy_write(mii_info, MII_BMCR, ctrl);
242}
243
244/* Enable and Restart Autonegotiation */
245static void genmii_restart_aneg(struct ugeth_mii_info *mii_info)
246{
247 u16 ctl;
248
249 ugphy_vdbg("%s: IN", __FUNCTION__);
250
251 ctl = phy_read(mii_info, MII_BMCR);
252 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
253 phy_write(mii_info, MII_BMCR, ctl);
254}
255
256static int gbit_config_aneg(struct ugeth_mii_info *mii_info)
257{
258 u16 adv;
259 u32 advertise;
260
261 ugphy_vdbg("%s: IN", __FUNCTION__);
262
263 if (mii_info->autoneg) {
264 /* Configure the ADVERTISE register */
265 config_genmii_advert(mii_info);
266 advertise = mii_info->advertising;
267
268 adv = phy_read(mii_info, MII_1000BASETCONTROL);
269 adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP |
270 MII_1000BASETCONTROL_HALFDUPLEXCAP);
271 if (advertise & SUPPORTED_1000baseT_Half)
272 adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP;
273 if (advertise & SUPPORTED_1000baseT_Full)
274 adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP;
275 phy_write(mii_info, MII_1000BASETCONTROL, adv);
276
277 /* Start/Restart aneg */
278 genmii_restart_aneg(mii_info);
279 } else
280 genmii_setup_forced(mii_info);
281
282 return 0;
283}
284
285static int genmii_config_aneg(struct ugeth_mii_info *mii_info)
286{
287 ugphy_vdbg("%s: IN", __FUNCTION__);
288
289 if (mii_info->autoneg) {
290 config_genmii_advert(mii_info);
291 genmii_restart_aneg(mii_info);
292 } else
293 genmii_setup_forced(mii_info);
294
295 return 0;
296}
297
298static int genmii_update_link(struct ugeth_mii_info *mii_info)
299{
300 u16 status;
301
302 ugphy_vdbg("%s: IN", __FUNCTION__);
303
304 /* Do a fake read */
305 phy_read(mii_info, MII_BMSR);
306
307 /* Read link and autonegotiation status */
308 status = phy_read(mii_info, MII_BMSR);
309 if ((status & BMSR_LSTATUS) == 0)
310 mii_info->link = 0;
311 else
312 mii_info->link = 1;
313
314 /* If we are autonegotiating, and not done,
315 * return an error */
316 if (mii_info->autoneg && !(status & BMSR_ANEGCOMPLETE))
317 return -EAGAIN;
318
319 return 0;
320}
321
322static int genmii_read_status(struct ugeth_mii_info *mii_info)
323{
324 u16 status;
325 int err;
326
327 ugphy_vdbg("%s: IN", __FUNCTION__);
328
329 /* Update the link, but return if there
330 * was an error */
331 err = genmii_update_link(mii_info);
332 if (err)
333 return err;
334
335 if (mii_info->autoneg) {
336 status = phy_read(mii_info, MII_LPA);
337
338 if (status & (LPA_10FULL | LPA_100FULL))
339 mii_info->duplex = DUPLEX_FULL;
340 else
341 mii_info->duplex = DUPLEX_HALF;
342 if (status & (LPA_100FULL | LPA_100HALF))
343 mii_info->speed = SPEED_100;
344 else
345 mii_info->speed = SPEED_10;
346 mii_info->pause = 0;
347 }
348 /* On non-aneg, we assume what we put in BMCR is the speed,
349 * though magic-aneg shouldn't prevent this case from occurring
350 */
351
352 return 0;
353}
354
355static int marvell_init(struct ugeth_mii_info *mii_info)
356{
357 ugphy_vdbg("%s: IN", __FUNCTION__);
358
359 phy_write(mii_info, 0x14, 0x0cd2);
360 phy_write(mii_info, MII_BMCR,
361 phy_read(mii_info, MII_BMCR) | BMCR_RESET);
362 msleep(4000);
363
364 return 0;
365}
366
367static int marvell_config_aneg(struct ugeth_mii_info *mii_info)
368{
369 ugphy_vdbg("%s: IN", __FUNCTION__);
370
371 /* The Marvell PHY has an errata which requires
372 * that certain registers get written in order
373 * to restart autonegotiation */
374 phy_write(mii_info, MII_BMCR, BMCR_RESET);
375
376 phy_write(mii_info, 0x1d, 0x1f);
377 phy_write(mii_info, 0x1e, 0x200c);
378 phy_write(mii_info, 0x1d, 0x5);
379 phy_write(mii_info, 0x1e, 0);
380 phy_write(mii_info, 0x1e, 0x100);
381
382 gbit_config_aneg(mii_info);
383
384 return 0;
385}
386
387static int marvell_read_status(struct ugeth_mii_info *mii_info)
388{
389 u16 status;
390 int err;
391
392 ugphy_vdbg("%s: IN", __FUNCTION__);
393
394 /* Update the link, but return if there
395 * was an error */
396 err = genmii_update_link(mii_info);
397 if (err)
398 return err;
399
400 /* If the link is up, read the speed and duplex */
401 /* If we aren't autonegotiating, assume speeds
402 * are as set */
403 if (mii_info->autoneg && mii_info->link) {
404 int speed;
405 status = phy_read(mii_info, MII_M1011_PHY_SPEC_STATUS);
406
407 /* Get the duplexity */
408 if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX)
409 mii_info->duplex = DUPLEX_FULL;
410 else
411 mii_info->duplex = DUPLEX_HALF;
412
413 /* Get the speed */
414 speed = status & MII_M1011_PHY_SPEC_STATUS_SPD_MASK;
415 switch (speed) {
416 case MII_M1011_PHY_SPEC_STATUS_1000:
417 mii_info->speed = SPEED_1000;
418 break;
419 case MII_M1011_PHY_SPEC_STATUS_100:
420 mii_info->speed = SPEED_100;
421 break;
422 default:
423 mii_info->speed = SPEED_10;
424 break;
425 }
426 mii_info->pause = 0;
427 }
428
429 return 0;
430}
431
432static int marvell_ack_interrupt(struct ugeth_mii_info *mii_info)
433{
434 ugphy_vdbg("%s: IN", __FUNCTION__);
435
436 /* Clear the interrupts by reading the reg */
437 phy_read(mii_info, MII_M1011_IEVENT);
438
439 return 0;
440}
441
442static int marvell_config_intr(struct ugeth_mii_info *mii_info)
443{
444 ugphy_vdbg("%s: IN", __FUNCTION__);
445
446 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
447 phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
448 else
449 phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
450
451 return 0;
452}
453
454static int cis820x_init(struct ugeth_mii_info *mii_info)
455{
456 ugphy_vdbg("%s: IN", __FUNCTION__);
457
458 phy_write(mii_info, MII_CIS8201_AUX_CONSTAT,
459 MII_CIS8201_AUXCONSTAT_INIT);
460 phy_write(mii_info, MII_CIS8201_EXT_CON1, MII_CIS8201_EXTCON1_INIT);
461
462 return 0;
463}
464
465static int cis820x_read_status(struct ugeth_mii_info *mii_info)
466{
467 u16 status;
468 int err;
469
470 ugphy_vdbg("%s: IN", __FUNCTION__);
471
472 /* Update the link, but return if there
473 * was an error */
474 err = genmii_update_link(mii_info);
475 if (err)
476 return err;
477
478 /* If the link is up, read the speed and duplex */
479 /* If we aren't autonegotiating, assume speeds
480 * are as set */
481 if (mii_info->autoneg && mii_info->link) {
482 int speed;
483
484 status = phy_read(mii_info, MII_CIS8201_AUX_CONSTAT);
485 if (status & MII_CIS8201_AUXCONSTAT_DUPLEX)
486 mii_info->duplex = DUPLEX_FULL;
487 else
488 mii_info->duplex = DUPLEX_HALF;
489
490 speed = status & MII_CIS8201_AUXCONSTAT_SPEED;
491
492 switch (speed) {
493 case MII_CIS8201_AUXCONSTAT_GBIT:
494 mii_info->speed = SPEED_1000;
495 break;
496 case MII_CIS8201_AUXCONSTAT_100:
497 mii_info->speed = SPEED_100;
498 break;
499 default:
500 mii_info->speed = SPEED_10;
501 break;
502 }
503 }
504
505 return 0;
506}
507
508static int cis820x_ack_interrupt(struct ugeth_mii_info *mii_info)
509{
510 ugphy_vdbg("%s: IN", __FUNCTION__);
511
512 phy_read(mii_info, MII_CIS8201_ISTAT);
513
514 return 0;
515}
516
517static int cis820x_config_intr(struct ugeth_mii_info *mii_info)
518{
519 ugphy_vdbg("%s: IN", __FUNCTION__);
520
521 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
522 phy_write(mii_info, MII_CIS8201_IMASK, MII_CIS8201_IMASK_MASK);
523 else
524 phy_write(mii_info, MII_CIS8201_IMASK, 0);
525
526 return 0;
527}
528
529#define DM9161_DELAY 10
530
531static int dm9161_read_status(struct ugeth_mii_info *mii_info)
532{
533 u16 status;
534 int err;
535
536 ugphy_vdbg("%s: IN", __FUNCTION__);
537
538 /* Update the link, but return if there
539 * was an error */
540 err = genmii_update_link(mii_info);
541 if (err)
542 return err;
543
544 /* If the link is up, read the speed and duplex */
545 /* If we aren't autonegotiating, assume speeds
546 * are as set */
547 if (mii_info->autoneg && mii_info->link) {
548 status = phy_read(mii_info, MII_DM9161_SCSR);
549 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H))
550 mii_info->speed = SPEED_100;
551 else
552 mii_info->speed = SPEED_10;
553
554 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_10F))
555 mii_info->duplex = DUPLEX_FULL;
556 else
557 mii_info->duplex = DUPLEX_HALF;
558 }
559
560 return 0;
561}
562
563static int dm9161_config_aneg(struct ugeth_mii_info *mii_info)
564{
565 struct dm9161_private *priv = mii_info->priv;
566
567 ugphy_vdbg("%s: IN", __FUNCTION__);
568
569 if (0 == priv->resetdone)
570 return -EAGAIN;
571
572 return 0;
573}
574
575static void dm9161_timer(unsigned long data)
576{
577 struct ugeth_mii_info *mii_info = (struct ugeth_mii_info *)data;
578 struct dm9161_private *priv = mii_info->priv;
579 u16 status = phy_read(mii_info, MII_BMSR);
580
581 ugphy_vdbg("%s: IN", __FUNCTION__);
582
583 if (status & BMSR_ANEGCOMPLETE) {
584 priv->resetdone = 1;
585 } else
586 mod_timer(&priv->timer, jiffies + DM9161_DELAY * HZ);
587}
588
589static int dm9161_init(struct ugeth_mii_info *mii_info)
590{
591 struct dm9161_private *priv;
592
593 ugphy_vdbg("%s: IN", __FUNCTION__);
594
595 /* Allocate the private data structure */
596 priv = kmalloc(sizeof(struct dm9161_private), GFP_KERNEL);
597
598 if (NULL == priv)
599 return -ENOMEM;
600
601 mii_info->priv = priv;
602
603 /* Reset is not done yet */
604 priv->resetdone = 0;
605
606 phy_write(mii_info, MII_BMCR,
607 phy_read(mii_info, MII_BMCR) | BMCR_RESET);
608
609 phy_write(mii_info, MII_BMCR,
610 phy_read(mii_info, MII_BMCR) & ~BMCR_ISOLATE);
611
612 config_genmii_advert(mii_info);
613 /* Start/Restart aneg */
614 genmii_config_aneg(mii_info);
615
616 /* Start a timer for DM9161_DELAY seconds to wait
617 * for the PHY to be ready */
618 init_timer(&priv->timer);
619 priv->timer.function = &dm9161_timer;
620 priv->timer.data = (unsigned long)mii_info;
621 mod_timer(&priv->timer, jiffies + DM9161_DELAY * HZ);
622
623 return 0;
624}
625
626static void dm9161_close(struct ugeth_mii_info *mii_info)
627{
628 struct dm9161_private *priv = mii_info->priv;
629
630 ugphy_vdbg("%s: IN", __FUNCTION__);
631
632 del_timer_sync(&priv->timer);
633 kfree(priv);
634}
635
636static int dm9161_ack_interrupt(struct ugeth_mii_info *mii_info)
637{
638/* FIXME: This lines are for BUG fixing in the mpc8325.
639Remove this from here when it's fixed */
640 if (bcsr_regs == NULL)
641 bcsr_regs = (u8 *) ioremap(BCSR_PHYS_ADDR, BCSR_SIZE);
642 bcsr_regs[14] |= 0x40;
643 ugphy_vdbg("%s: IN", __FUNCTION__);
644
645 /* Clear the interrupts by reading the reg */
646 phy_read(mii_info, MII_DM9161_INTR);
647
648
649 return 0;
650}
651
652static int dm9161_config_intr(struct ugeth_mii_info *mii_info)
653{
654/* FIXME: This lines are for BUG fixing in the mpc8325.
655Remove this from here when it's fixed */
656 if (bcsr_regs == NULL) {
657 bcsr_regs = (u8 *) ioremap(BCSR_PHYS_ADDR, BCSR_SIZE);
658 bcsr_regs[14] &= ~0x40;
659 }
660 ugphy_vdbg("%s: IN", __FUNCTION__);
661
662 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
663 phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_INIT);
664 else
665 phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_STOP);
666
667 return 0;
668}
669
670/* Cicada 820x */
671static struct phy_info phy_info_cis820x = {
672 .phy_id = 0x000fc440,
673 .name = "Cicada Cis8204",
674 .phy_id_mask = 0x000fffc0,
675 .features = MII_GBIT_FEATURES,
676 .init = &cis820x_init,
677 .config_aneg = &gbit_config_aneg,
678 .read_status = &cis820x_read_status,
679 .ack_interrupt = &cis820x_ack_interrupt,
680 .config_intr = &cis820x_config_intr,
681};
682
683static struct phy_info phy_info_dm9161 = {
684 .phy_id = 0x0181b880,
685 .phy_id_mask = 0x0ffffff0,
686 .name = "Davicom DM9161E",
687 .init = dm9161_init,
688 .config_aneg = dm9161_config_aneg,
689 .read_status = dm9161_read_status,
690 .close = dm9161_close,
691};
692
693static struct phy_info phy_info_dm9161a = {
694 .phy_id = 0x0181b8a0,
695 .phy_id_mask = 0x0ffffff0,
696 .name = "Davicom DM9161A",
697 .features = MII_BASIC_FEATURES,
698 .init = dm9161_init,
699 .config_aneg = dm9161_config_aneg,
700 .read_status = dm9161_read_status,
701 .ack_interrupt = dm9161_ack_interrupt,
702 .config_intr = dm9161_config_intr,
703 .close = dm9161_close,
704};
705
706static struct phy_info phy_info_marvell = {
707 .phy_id = 0x01410c00,
708 .phy_id_mask = 0xffffff00,
709 .name = "Marvell 88E11x1",
710 .features = MII_GBIT_FEATURES,
711 .init = &marvell_init,
712 .config_aneg = &marvell_config_aneg,
713 .read_status = &marvell_read_status,
714 .ack_interrupt = &marvell_ack_interrupt,
715 .config_intr = &marvell_config_intr,
716};
717
718static struct phy_info phy_info_genmii = {
719 .phy_id = 0x00000000,
720 .phy_id_mask = 0x00000000,
721 .name = "Generic MII",
722 .features = MII_BASIC_FEATURES,
723 .config_aneg = genmii_config_aneg,
724 .read_status = genmii_read_status,
725};
726
727static struct phy_info *phy_info[] = {
728 &phy_info_cis820x,
729 &phy_info_marvell,
730 &phy_info_dm9161,
731 &phy_info_dm9161a,
732 &phy_info_genmii,
733 NULL
734};
735
736u16 phy_read(struct ugeth_mii_info *mii_info, u16 regnum)
737{
738 u16 retval;
739 unsigned long flags;
740
741 ugphy_vdbg("%s: IN", __FUNCTION__);
742
743 spin_lock_irqsave(&mii_info->mdio_lock, flags);
744 retval = mii_info->mdio_read(mii_info->dev, mii_info->mii_id, regnum);
745 spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
746
747 return retval;
748}
749
750void phy_write(struct ugeth_mii_info *mii_info, u16 regnum, u16 val)
751{
752 unsigned long flags;
753
754 ugphy_vdbg("%s: IN", __FUNCTION__);
755
756 spin_lock_irqsave(&mii_info->mdio_lock, flags);
757 mii_info->mdio_write(mii_info->dev, mii_info->mii_id, regnum, val);
758 spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
759}
760
761/* Use the PHY ID registers to determine what type of PHY is attached
762 * to device dev. return a struct phy_info structure describing that PHY
763 */
764struct phy_info *get_phy_info(struct ugeth_mii_info *mii_info)
765{
766 u16 phy_reg;
767 u32 phy_ID;
768 int i;
769 struct phy_info *theInfo = NULL;
770 struct net_device *dev = mii_info->dev;
771
772 ugphy_vdbg("%s: IN", __FUNCTION__);
773
774 /* Grab the bits from PHYIR1, and put them in the upper half */
775 phy_reg = phy_read(mii_info, MII_PHYSID1);
776 phy_ID = (phy_reg & 0xffff) << 16;
777
778 /* Grab the bits from PHYIR2, and put them in the lower half */
779 phy_reg = phy_read(mii_info, MII_PHYSID2);
780 phy_ID |= (phy_reg & 0xffff);
781
782 /* loop through all the known PHY types, and find one that */
783 /* matches the ID we read from the PHY. */
784 for (i = 0; phy_info[i]; i++)
785 if (phy_info[i]->phy_id == (phy_ID & phy_info[i]->phy_id_mask)){
786 theInfo = phy_info[i];
787 break;
788 }
789
790 /* This shouldn't happen, as we have generic PHY support */
791 if (theInfo == NULL) {
792 ugphy_info("%s: PHY id %x is not supported!", dev->name,
793 phy_ID);
794 return NULL;
795 } else {
796 ugphy_info("%s: PHY is %s (%x)", dev->name, theInfo->name,
797 phy_ID);
798 }
799
800 return theInfo;
801}
diff --git a/drivers/net/ucc_geth_phy.h b/drivers/net/ucc_geth_phy.h
new file mode 100644
index 000000000000..2f98b8f1bb0a
--- /dev/null
+++ b/drivers/net/ucc_geth_phy.h
@@ -0,0 +1,217 @@
1/*
2 * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved.
3 *
4 * Author: Shlomi Gridish <gridish@freescale.com>
5 *
6 * Description:
7 * UCC GETH Driver -- PHY handling
8 *
9 * Changelog:
10 * Jun 28, 2006 Li Yang <LeoLi@freescale.com>
11 * - Rearrange code and style fixes
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 */
19#ifndef __UCC_GETH_PHY_H__
20#define __UCC_GETH_PHY_H__
21
22#define MII_end ((u32)-2)
23#define MII_read ((u32)-1)
24
25#define MIIMIND_BUSY 0x00000001
26#define MIIMIND_NOTVALID 0x00000004
27
28#define UGETH_AN_TIMEOUT 2000
29
30/* 1000BT control (Marvell & BCM54xx at least) */
31#define MII_1000BASETCONTROL 0x09
32#define MII_1000BASETCONTROL_FULLDUPLEXCAP 0x0200
33#define MII_1000BASETCONTROL_HALFDUPLEXCAP 0x0100
34
35/* Cicada Extended Control Register 1 */
36#define MII_CIS8201_EXT_CON1 0x17
37#define MII_CIS8201_EXTCON1_INIT 0x0000
38
39/* Cicada Interrupt Mask Register */
40#define MII_CIS8201_IMASK 0x19
41#define MII_CIS8201_IMASK_IEN 0x8000
42#define MII_CIS8201_IMASK_SPEED 0x4000
43#define MII_CIS8201_IMASK_LINK 0x2000
44#define MII_CIS8201_IMASK_DUPLEX 0x1000
45#define MII_CIS8201_IMASK_MASK 0xf000
46
47/* Cicada Interrupt Status Register */
48#define MII_CIS8201_ISTAT 0x1a
49#define MII_CIS8201_ISTAT_STATUS 0x8000
50#define MII_CIS8201_ISTAT_SPEED 0x4000
51#define MII_CIS8201_ISTAT_LINK 0x2000
52#define MII_CIS8201_ISTAT_DUPLEX 0x1000
53
54/* Cicada Auxiliary Control/Status Register */
55#define MII_CIS8201_AUX_CONSTAT 0x1c
56#define MII_CIS8201_AUXCONSTAT_INIT 0x0004
57#define MII_CIS8201_AUXCONSTAT_DUPLEX 0x0020
58#define MII_CIS8201_AUXCONSTAT_SPEED 0x0018
59#define MII_CIS8201_AUXCONSTAT_GBIT 0x0010
60#define MII_CIS8201_AUXCONSTAT_100 0x0008
61
62/* 88E1011 PHY Status Register */
63#define MII_M1011_PHY_SPEC_STATUS 0x11
64#define MII_M1011_PHY_SPEC_STATUS_1000 0x8000
65#define MII_M1011_PHY_SPEC_STATUS_100 0x4000
66#define MII_M1011_PHY_SPEC_STATUS_SPD_MASK 0xc000
67#define MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX 0x2000
68#define MII_M1011_PHY_SPEC_STATUS_RESOLVED 0x0800
69#define MII_M1011_PHY_SPEC_STATUS_LINK 0x0400
70
71#define MII_M1011_IEVENT 0x13
72#define MII_M1011_IEVENT_CLEAR 0x0000
73
74#define MII_M1011_IMASK 0x12
75#define MII_M1011_IMASK_INIT 0x6400
76#define MII_M1011_IMASK_CLEAR 0x0000
77
78#define MII_DM9161_SCR 0x10
79#define MII_DM9161_SCR_INIT 0x0610
80
81/* DM9161 Specified Configuration and Status Register */
82#define MII_DM9161_SCSR 0x11
83#define MII_DM9161_SCSR_100F 0x8000
84#define MII_DM9161_SCSR_100H 0x4000
85#define MII_DM9161_SCSR_10F 0x2000
86#define MII_DM9161_SCSR_10H 0x1000
87
88/* DM9161 Interrupt Register */
89#define MII_DM9161_INTR 0x15
90#define MII_DM9161_INTR_PEND 0x8000
91#define MII_DM9161_INTR_DPLX_MASK 0x0800
92#define MII_DM9161_INTR_SPD_MASK 0x0400
93#define MII_DM9161_INTR_LINK_MASK 0x0200
94#define MII_DM9161_INTR_MASK 0x0100
95#define MII_DM9161_INTR_DPLX_CHANGE 0x0010
96#define MII_DM9161_INTR_SPD_CHANGE 0x0008
97#define MII_DM9161_INTR_LINK_CHANGE 0x0004
98#define MII_DM9161_INTR_INIT 0x0000
99#define MII_DM9161_INTR_STOP \
100(MII_DM9161_INTR_DPLX_MASK | MII_DM9161_INTR_SPD_MASK \
101 | MII_DM9161_INTR_LINK_MASK | MII_DM9161_INTR_MASK)
102
103/* DM9161 10BT Configuration/Status */
104#define MII_DM9161_10BTCSR 0x12
105#define MII_DM9161_10BTCSR_INIT 0x7800
106
107#define MII_BASIC_FEATURES (SUPPORTED_10baseT_Half | \
108 SUPPORTED_10baseT_Full | \
109 SUPPORTED_100baseT_Half | \
110 SUPPORTED_100baseT_Full | \
111 SUPPORTED_Autoneg | \
112 SUPPORTED_TP | \
113 SUPPORTED_MII)
114
115#define MII_GBIT_FEATURES (MII_BASIC_FEATURES | \
116 SUPPORTED_1000baseT_Half | \
117 SUPPORTED_1000baseT_Full)
118
119#define MII_READ_COMMAND 0x00000001
120
121#define MII_INTERRUPT_DISABLED 0x0
122#define MII_INTERRUPT_ENABLED 0x1
123/* Taken from mii_if_info and sungem_phy.h */
124struct ugeth_mii_info {
125 /* Information about the PHY type */
126 /* And management functions */
127 struct phy_info *phyinfo;
128
129 ucc_mii_mng_t *mii_regs;
130
131 /* forced speed & duplex (no autoneg)
132 * partner speed & duplex & pause (autoneg)
133 */
134 int speed;
135 int duplex;
136 int pause;
137
138 /* The most recently read link state */
139 int link;
140
141 /* Enabled Interrupts */
142 u32 interrupts;
143
144 u32 advertising;
145 int autoneg;
146 int mii_id;
147
148 /* private data pointer */
149 /* For use by PHYs to maintain extra state */
150 void *priv;
151
152 /* Provided by host chip */
153 struct net_device *dev;
154
155 /* A lock to ensure that only one thing can read/write
156 * the MDIO bus at a time */
157 spinlock_t mdio_lock;
158
159 /* Provided by ethernet driver */
160 int (*mdio_read) (struct net_device * dev, int mii_id, int reg);
161 void (*mdio_write) (struct net_device * dev, int mii_id, int reg,
162 int val);
163};
164
165/* struct phy_info: a structure which defines attributes for a PHY
166 *
167 * id will contain a number which represents the PHY. During
168 * startup, the driver will poll the PHY to find out what its
169 * UID--as defined by registers 2 and 3--is. The 32-bit result
170 * gotten from the PHY will be ANDed with phy_id_mask to
171 * discard any bits which may change based on revision numbers
172 * unimportant to functionality
173 *
174 * There are 6 commands which take a ugeth_mii_info structure.
175 * Each PHY must declare config_aneg, and read_status.
176 */
177struct phy_info {
178 u32 phy_id;
179 char *name;
180 unsigned int phy_id_mask;
181 u32 features;
182
183 /* Called to initialize the PHY */
184 int (*init) (struct ugeth_mii_info * mii_info);
185
186 /* Called to suspend the PHY for power */
187 int (*suspend) (struct ugeth_mii_info * mii_info);
188
189 /* Reconfigures autonegotiation (or disables it) */
190 int (*config_aneg) (struct ugeth_mii_info * mii_info);
191
192 /* Determines the negotiated speed and duplex */
193 int (*read_status) (struct ugeth_mii_info * mii_info);
194
195 /* Clears any pending interrupts */
196 int (*ack_interrupt) (struct ugeth_mii_info * mii_info);
197
198 /* Enables or disables interrupts */
199 int (*config_intr) (struct ugeth_mii_info * mii_info);
200
201 /* Clears up any memory if needed */
202 void (*close) (struct ugeth_mii_info * mii_info);
203};
204
205struct phy_info *get_phy_info(struct ugeth_mii_info *mii_info);
206void write_phy_reg(struct net_device *dev, int mii_id, int regnum, int value);
207int read_phy_reg(struct net_device *dev, int mii_id, int regnum);
208void mii_clear_phy_interrupt(struct ugeth_mii_info *mii_info);
209void mii_configure_phy_interrupt(struct ugeth_mii_info *mii_info,
210 u32 interrupts);
211
212struct dm9161_private {
213 struct timer_list timer;
214 int resetdone;
215};
216
217#endif /* __UCC_GETH_PHY_H__ */
diff --git a/drivers/net/via-rhine.c b/drivers/net/via-rhine.c
index 98b6f3207d3d..ae971080e2e4 100644
--- a/drivers/net/via-rhine.c
+++ b/drivers/net/via-rhine.c
@@ -25,117 +25,13 @@
25 version. He may or may not be interested in bug reports on this 25 version. He may or may not be interested in bug reports on this
26 code. You can find his versions at: 26 code. You can find his versions at:
27 http://www.scyld.com/network/via-rhine.html 27 http://www.scyld.com/network/via-rhine.html
28 28 [link no longer provides useful info -jgarzik]
29
30 Linux kernel version history:
31
32 LK1.1.0:
33 - Jeff Garzik: softnet 'n stuff
34
35 LK1.1.1:
36 - Justin Guyett: softnet and locking fixes
37 - Jeff Garzik: use PCI interface
38
39 LK1.1.2:
40 - Urban Widmark: minor cleanups, merges from Becker 1.03a/1.04 versions
41
42 LK1.1.3:
43 - Urban Widmark: use PCI DMA interface (with thanks to the eepro100.c
44 code) update "Theory of Operation" with
45 softnet/locking changes
46 - Dave Miller: PCI DMA and endian fixups
47 - Jeff Garzik: MOD_xxx race fixes, updated PCI resource allocation
48
49 LK1.1.4:
50 - Urban Widmark: fix gcc 2.95.2 problem and
51 remove writel's to fixed address 0x7c
52
53 LK1.1.5:
54 - Urban Widmark: mdio locking, bounce buffer changes
55 merges from Beckers 1.05 version
56 added netif_running_on/off support
57
58 LK1.1.6:
59 - Urban Widmark: merges from Beckers 1.08b version (VT6102 + mdio)
60 set netif_running_on/off on startup, del_timer_sync
61
62 LK1.1.7:
63 - Manfred Spraul: added reset into tx_timeout
64
65 LK1.1.9:
66 - Urban Widmark: merges from Beckers 1.10 version
67 (media selection + eeprom reload)
68 - David Vrabel: merges from D-Link "1.11" version
69 (disable WOL and PME on startup)
70
71 LK1.1.10:
72 - Manfred Spraul: use "singlecopy" for unaligned buffers
73 don't allocate bounce buffers for !ReqTxAlign cards
74
75 LK1.1.11:
76 - David Woodhouse: Set dev->base_addr before the first time we call
77 wait_for_reset(). It's a lot happier that way.
78 Free np->tx_bufs only if we actually allocated it.
79
80 LK1.1.12:
81 - Martin Eriksson: Allow Memory-Mapped IO to be enabled.
82
83 LK1.1.13 (jgarzik):
84 - Add ethtool support
85 - Replace some MII-related magic numbers with constants
86
87 LK1.1.14 (Ivan G.):
88 - fixes comments for Rhine-III
89 - removes W_MAX_TIMEOUT (unused)
90 - adds HasDavicomPhy for Rhine-I (basis: linuxfet driver; my card
91 is R-I and has Davicom chip, flag is referenced in kernel driver)
92 - sends chip_id as a parameter to wait_for_reset since np is not
93 initialized on first call
94 - changes mmio "else if (chip_id==VT6102)" to "else" so it will work
95 for Rhine-III's (documentation says same bit is correct)
96 - transmit frame queue message is off by one - fixed
97 - adds IntrNormalSummary to "Something Wicked" exclusion list
98 so normal interrupts will not trigger the message (src: Donald Becker)
99 (Roger Luethi)
100 - show confused chip where to continue after Tx error
101 - location of collision counter is chip specific
102 - allow selecting backoff algorithm (module parameter)
103
104 LK1.1.15 (jgarzik):
105 - Use new MII lib helper generic_mii_ioctl
106
107 LK1.1.16 (Roger Luethi)
108 - Etherleak fix
109 - Handle Tx buffer underrun
110 - Fix bugs in full duplex handling
111 - New reset code uses "force reset" cmd on Rhine-II
112 - Various clean ups
113
114 LK1.1.17 (Roger Luethi)
115 - Fix race in via_rhine_start_tx()
116 - On errors, wait for Tx engine to turn off before scavenging
117 - Handle Tx descriptor write-back race on Rhine-II
118 - Force flushing for PCI posted writes
119 - More reset code changes
120
121 LK1.1.18 (Roger Luethi)
122 - No filtering multicast in promisc mode (Edward Peng)
123 - Fix for Rhine-I Tx timeouts
124
125 LK1.1.19 (Roger Luethi)
126 - Increase Tx threshold for unspecified errors
127
128 LK1.2.0-2.6 (Roger Luethi)
129 - Massive clean-up
130 - Rewrite PHY, media handling (remove options, full_duplex, backoff)
131 - Fix Tx engine race for good
132 - Craig Brind: Zero padded aligned buffers for short packets.
133 29
134*/ 30*/
135 31
136#define DRV_NAME "via-rhine" 32#define DRV_NAME "via-rhine"
137#define DRV_VERSION "1.2.0-2.6" 33#define DRV_VERSION "1.4.1"
138#define DRV_RELDATE "June-10-2004" 34#define DRV_RELDATE "July-24-2006"
139 35
140 36
141/* A few user-configurable values. 37/* A few user-configurable values.
@@ -148,6 +44,10 @@ static int max_interrupt_work = 20;
148 Setting to > 1518 effectively disables this feature. */ 44 Setting to > 1518 effectively disables this feature. */
149static int rx_copybreak; 45static int rx_copybreak;
150 46
47/* Work-around for broken BIOSes: they are unable to get the chip back out of
48 power state D3 so PXE booting fails. bootparam(7): via-rhine.avoid_D3=1 */
49static int avoid_D3;
50
151/* 51/*
152 * In case you are looking for 'options[]' or 'full_duplex[]', they 52 * In case you are looking for 'options[]' or 'full_duplex[]', they
153 * are gone. Use ethtool(8) instead. 53 * are gone. Use ethtool(8) instead.
@@ -167,7 +67,11 @@ static const int multicast_filter_limit = 32;
167 There are no ill effects from too-large receive rings. */ 67 There are no ill effects from too-large receive rings. */
168#define TX_RING_SIZE 16 68#define TX_RING_SIZE 16
169#define TX_QUEUE_LEN 10 /* Limit ring entries actually used. */ 69#define TX_QUEUE_LEN 10 /* Limit ring entries actually used. */
70#ifdef CONFIG_VIA_RHINE_NAPI
71#define RX_RING_SIZE 64
72#else
170#define RX_RING_SIZE 16 73#define RX_RING_SIZE 16
74#endif
171 75
172 76
173/* Operational parameters that usually are not changed. */ 77/* Operational parameters that usually are not changed. */
@@ -220,9 +124,11 @@ MODULE_LICENSE("GPL");
220module_param(max_interrupt_work, int, 0); 124module_param(max_interrupt_work, int, 0);
221module_param(debug, int, 0); 125module_param(debug, int, 0);
222module_param(rx_copybreak, int, 0); 126module_param(rx_copybreak, int, 0);
127module_param(avoid_D3, bool, 0);
223MODULE_PARM_DESC(max_interrupt_work, "VIA Rhine maximum events handled per interrupt"); 128MODULE_PARM_DESC(max_interrupt_work, "VIA Rhine maximum events handled per interrupt");
224MODULE_PARM_DESC(debug, "VIA Rhine debug level (0-7)"); 129MODULE_PARM_DESC(debug, "VIA Rhine debug level (0-7)");
225MODULE_PARM_DESC(rx_copybreak, "VIA Rhine copy breakpoint for copy-only-tiny-frames"); 130MODULE_PARM_DESC(rx_copybreak, "VIA Rhine copy breakpoint for copy-only-tiny-frames");
131MODULE_PARM_DESC(avoid_D3, "Avoid power state D3 (work-around for broken BIOSes)");
226 132
227/* 133/*
228 Theory of Operation 134 Theory of Operation
@@ -356,12 +262,11 @@ enum rhine_quirks {
356/* Beware of PCI posted writes */ 262/* Beware of PCI posted writes */
357#define IOSYNC do { ioread8(ioaddr + StationAddr); } while (0) 263#define IOSYNC do { ioread8(ioaddr + StationAddr); } while (0)
358 264
359static struct pci_device_id rhine_pci_tbl[] = 265static const struct pci_device_id rhine_pci_tbl[] = {
360{ 266 { 0x1106, 0x3043, PCI_ANY_ID, PCI_ANY_ID, }, /* VT86C100A */
361 {0x1106, 0x3043, PCI_ANY_ID, PCI_ANY_ID, 0, 0, }, /* VT86C100A */ 267 { 0x1106, 0x3065, PCI_ANY_ID, PCI_ANY_ID, }, /* VT6102 */
362 {0x1106, 0x3065, PCI_ANY_ID, PCI_ANY_ID, 0, 0, }, /* VT6102 */ 268 { 0x1106, 0x3106, PCI_ANY_ID, PCI_ANY_ID, }, /* 6105{,L,LOM} */
363 {0x1106, 0x3106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, }, /* 6105{,L,LOM} */ 269 { 0x1106, 0x3053, PCI_ANY_ID, PCI_ANY_ID, }, /* VT6105M */
364 {0x1106, 0x3053, PCI_ANY_ID, PCI_ANY_ID, 0, 0, }, /* VT6105M */
365 { } /* terminate list */ 270 { } /* terminate list */
366}; 271};
367MODULE_DEVICE_TABLE(pci, rhine_pci_tbl); 272MODULE_DEVICE_TABLE(pci, rhine_pci_tbl);
@@ -501,7 +406,7 @@ static void rhine_tx_timeout(struct net_device *dev);
501static int rhine_start_tx(struct sk_buff *skb, struct net_device *dev); 406static int rhine_start_tx(struct sk_buff *skb, struct net_device *dev);
502static irqreturn_t rhine_interrupt(int irq, void *dev_instance, struct pt_regs *regs); 407static irqreturn_t rhine_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
503static void rhine_tx(struct net_device *dev); 408static void rhine_tx(struct net_device *dev);
504static void rhine_rx(struct net_device *dev); 409static int rhine_rx(struct net_device *dev, int limit);
505static void rhine_error(struct net_device *dev, int intr_status); 410static void rhine_error(struct net_device *dev, int intr_status);
506static void rhine_set_rx_mode(struct net_device *dev); 411static void rhine_set_rx_mode(struct net_device *dev);
507static struct net_device_stats *rhine_get_stats(struct net_device *dev); 412static struct net_device_stats *rhine_get_stats(struct net_device *dev);
@@ -669,6 +574,32 @@ static void rhine_poll(struct net_device *dev)
669} 574}
670#endif 575#endif
671 576
577#ifdef CONFIG_VIA_RHINE_NAPI
578static int rhine_napipoll(struct net_device *dev, int *budget)
579{
580 struct rhine_private *rp = netdev_priv(dev);
581 void __iomem *ioaddr = rp->base;
582 int done, limit = min(dev->quota, *budget);
583
584 done = rhine_rx(dev, limit);
585 *budget -= done;
586 dev->quota -= done;
587
588 if (done < limit) {
589 netif_rx_complete(dev);
590
591 iowrite16(IntrRxDone | IntrRxErr | IntrRxEmpty| IntrRxOverflow |
592 IntrRxDropped | IntrRxNoBuf | IntrTxAborted |
593 IntrTxDone | IntrTxError | IntrTxUnderrun |
594 IntrPCIErr | IntrStatsMax | IntrLinkChange,
595 ioaddr + IntrEnable);
596 return 0;
597 }
598 else
599 return 1;
600}
601#endif
602
672static void rhine_hw_init(struct net_device *dev, long pioaddr) 603static void rhine_hw_init(struct net_device *dev, long pioaddr)
673{ 604{
674 struct rhine_private *rp = netdev_priv(dev); 605 struct rhine_private *rp = netdev_priv(dev);
@@ -849,6 +780,10 @@ static int __devinit rhine_init_one(struct pci_dev *pdev,
849#ifdef CONFIG_NET_POLL_CONTROLLER 780#ifdef CONFIG_NET_POLL_CONTROLLER
850 dev->poll_controller = rhine_poll; 781 dev->poll_controller = rhine_poll;
851#endif 782#endif
783#ifdef CONFIG_VIA_RHINE_NAPI
784 dev->poll = rhine_napipoll;
785 dev->weight = 64;
786#endif
852 if (rp->quirks & rqRhineI) 787 if (rp->quirks & rqRhineI)
853 dev->features |= NETIF_F_SG|NETIF_F_HW_CSUM; 788 dev->features |= NETIF_F_SG|NETIF_F_HW_CSUM;
854 789
@@ -894,6 +829,9 @@ static int __devinit rhine_init_one(struct pci_dev *pdev,
894 } 829 }
895 } 830 }
896 rp->mii_if.phy_id = phy_id; 831 rp->mii_if.phy_id = phy_id;
832 if (debug > 1 && avoid_D3)
833 printk(KERN_INFO "%s: No D3 power state at shutdown.\n",
834 dev->name);
897 835
898 return 0; 836 return 0;
899 837
@@ -1119,6 +1057,8 @@ static void init_registers(struct net_device *dev)
1119 1057
1120 rhine_set_rx_mode(dev); 1058 rhine_set_rx_mode(dev);
1121 1059
1060 netif_poll_enable(dev);
1061
1122 /* Enable interrupts by setting the interrupt mask. */ 1062 /* Enable interrupts by setting the interrupt mask. */
1123 iowrite16(IntrRxDone | IntrRxErr | IntrRxEmpty| IntrRxOverflow | 1063 iowrite16(IntrRxDone | IntrRxErr | IntrRxEmpty| IntrRxOverflow |
1124 IntrRxDropped | IntrRxNoBuf | IntrTxAborted | 1064 IntrRxDropped | IntrRxNoBuf | IntrTxAborted |
@@ -1373,8 +1313,18 @@ static irqreturn_t rhine_interrupt(int irq, void *dev_instance, struct pt_regs *
1373 dev->name, intr_status); 1313 dev->name, intr_status);
1374 1314
1375 if (intr_status & (IntrRxDone | IntrRxErr | IntrRxDropped | 1315 if (intr_status & (IntrRxDone | IntrRxErr | IntrRxDropped |
1376 IntrRxWakeUp | IntrRxEmpty | IntrRxNoBuf)) 1316 IntrRxWakeUp | IntrRxEmpty | IntrRxNoBuf)) {
1377 rhine_rx(dev); 1317#ifdef CONFIG_VIA_RHINE_NAPI
1318 iowrite16(IntrTxAborted |
1319 IntrTxDone | IntrTxError | IntrTxUnderrun |
1320 IntrPCIErr | IntrStatsMax | IntrLinkChange,
1321 ioaddr + IntrEnable);
1322
1323 netif_rx_schedule(dev);
1324#else
1325 rhine_rx(dev, RX_RING_SIZE);
1326#endif
1327 }
1378 1328
1379 if (intr_status & (IntrTxErrSummary | IntrTxDone)) { 1329 if (intr_status & (IntrTxErrSummary | IntrTxDone)) {
1380 if (intr_status & IntrTxErrSummary) { 1330 if (intr_status & IntrTxErrSummary) {
@@ -1472,13 +1422,12 @@ static void rhine_tx(struct net_device *dev)
1472 spin_unlock(&rp->lock); 1422 spin_unlock(&rp->lock);
1473} 1423}
1474 1424
1475/* This routine is logically part of the interrupt handler, but isolated 1425/* Process up to limit frames from receive ring */
1476 for clarity and better register allocation. */ 1426static int rhine_rx(struct net_device *dev, int limit)
1477static void rhine_rx(struct net_device *dev)
1478{ 1427{
1479 struct rhine_private *rp = netdev_priv(dev); 1428 struct rhine_private *rp = netdev_priv(dev);
1429 int count;
1480 int entry = rp->cur_rx % RX_RING_SIZE; 1430 int entry = rp->cur_rx % RX_RING_SIZE;
1481 int boguscnt = rp->dirty_rx + RX_RING_SIZE - rp->cur_rx;
1482 1431
1483 if (debug > 4) { 1432 if (debug > 4) {
1484 printk(KERN_DEBUG "%s: rhine_rx(), entry %d status %8.8x.\n", 1433 printk(KERN_DEBUG "%s: rhine_rx(), entry %d status %8.8x.\n",
@@ -1487,16 +1436,18 @@ static void rhine_rx(struct net_device *dev)
1487 } 1436 }
1488 1437
1489 /* If EOP is set on the next entry, it's a new packet. Send it up. */ 1438 /* If EOP is set on the next entry, it's a new packet. Send it up. */
1490 while (!(rp->rx_head_desc->rx_status & cpu_to_le32(DescOwn))) { 1439 for (count = 0; count < limit; ++count) {
1491 struct rx_desc *desc = rp->rx_head_desc; 1440 struct rx_desc *desc = rp->rx_head_desc;
1492 u32 desc_status = le32_to_cpu(desc->rx_status); 1441 u32 desc_status = le32_to_cpu(desc->rx_status);
1493 int data_size = desc_status >> 16; 1442 int data_size = desc_status >> 16;
1494 1443
1444 if (desc_status & DescOwn)
1445 break;
1446
1495 if (debug > 4) 1447 if (debug > 4)
1496 printk(KERN_DEBUG "rhine_rx() status is %8.8x.\n", 1448 printk(KERN_DEBUG "rhine_rx() status is %8.8x.\n",
1497 desc_status); 1449 desc_status);
1498 if (--boguscnt < 0) 1450
1499 break;
1500 if ((desc_status & (RxWholePkt | RxErr)) != RxWholePkt) { 1451 if ((desc_status & (RxWholePkt | RxErr)) != RxWholePkt) {
1501 if ((desc_status & RxWholePkt) != RxWholePkt) { 1452 if ((desc_status & RxWholePkt) != RxWholePkt) {
1502 printk(KERN_WARNING "%s: Oversized Ethernet " 1453 printk(KERN_WARNING "%s: Oversized Ethernet "
@@ -1565,7 +1516,11 @@ static void rhine_rx(struct net_device *dev)
1565 PCI_DMA_FROMDEVICE); 1516 PCI_DMA_FROMDEVICE);
1566 } 1517 }
1567 skb->protocol = eth_type_trans(skb, dev); 1518 skb->protocol = eth_type_trans(skb, dev);
1519#ifdef CONFIG_VIA_RHINE_NAPI
1520 netif_receive_skb(skb);
1521#else
1568 netif_rx(skb); 1522 netif_rx(skb);
1523#endif
1569 dev->last_rx = jiffies; 1524 dev->last_rx = jiffies;
1570 rp->stats.rx_bytes += pkt_len; 1525 rp->stats.rx_bytes += pkt_len;
1571 rp->stats.rx_packets++; 1526 rp->stats.rx_packets++;
@@ -1592,6 +1547,8 @@ static void rhine_rx(struct net_device *dev)
1592 } 1547 }
1593 rp->rx_ring[entry].rx_status = cpu_to_le32(DescOwn); 1548 rp->rx_ring[entry].rx_status = cpu_to_le32(DescOwn);
1594 } 1549 }
1550
1551 return count;
1595} 1552}
1596 1553
1597/* 1554/*
@@ -1881,6 +1838,7 @@ static int rhine_close(struct net_device *dev)
1881 spin_lock_irq(&rp->lock); 1838 spin_lock_irq(&rp->lock);
1882 1839
1883 netif_stop_queue(dev); 1840 netif_stop_queue(dev);
1841 netif_poll_disable(dev);
1884 1842
1885 if (debug > 1) 1843 if (debug > 1)
1886 printk(KERN_DEBUG "%s: Shutting down ethercard, " 1844 printk(KERN_DEBUG "%s: Shutting down ethercard, "
@@ -1962,7 +1920,8 @@ static void rhine_shutdown (struct pci_dev *pdev)
1962 } 1920 }
1963 1921
1964 /* Hit power state D3 (sleep) */ 1922 /* Hit power state D3 (sleep) */
1965 iowrite8(ioread8(ioaddr + StickyHW) | 0x03, ioaddr + StickyHW); 1923 if (!avoid_D3)
1924 iowrite8(ioread8(ioaddr + StickyHW) | 0x03, ioaddr + StickyHW);
1966 1925
1967 /* TODO: Check use of pci_enable_wake() */ 1926 /* TODO: Check use of pci_enable_wake() */
1968 1927
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index ba2972ba3757..aa9cd92f46b2 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -229,7 +229,8 @@ static int rx_copybreak = 200;
229module_param(rx_copybreak, int, 0644); 229module_param(rx_copybreak, int, 0644);
230MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames"); 230MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames");
231 231
232static void velocity_init_info(struct pci_dev *pdev, struct velocity_info *vptr, struct velocity_info_tbl *info); 232static void velocity_init_info(struct pci_dev *pdev, struct velocity_info *vptr,
233 const struct velocity_info_tbl *info);
233static int velocity_get_pci_info(struct velocity_info *, struct pci_dev *pdev); 234static int velocity_get_pci_info(struct velocity_info *, struct pci_dev *pdev);
234static void velocity_print_info(struct velocity_info *vptr); 235static void velocity_print_info(struct velocity_info *vptr);
235static int velocity_open(struct net_device *dev); 236static int velocity_open(struct net_device *dev);
@@ -294,9 +295,9 @@ static void velocity_unregister_notifier(void)
294 * Internal board variants. At the moment we have only one 295 * Internal board variants. At the moment we have only one
295 */ 296 */
296 297
297static struct velocity_info_tbl chip_info_table[] = { 298static const struct velocity_info_tbl chip_info_table[] __devinitdata = {
298 {CHIP_TYPE_VT6110, "VIA Networking Velocity Family Gigabit Ethernet Adapter", 256, 1, 0x00FFFFFFUL}, 299 {CHIP_TYPE_VT6110, "VIA Networking Velocity Family Gigabit Ethernet Adapter", 1, 0x00FFFFFFUL},
299 {0, NULL} 300 { }
300}; 301};
301 302
302/* 303/*
@@ -304,10 +305,9 @@ static struct velocity_info_tbl chip_info_table[] = {
304 * device driver. Used for hotplug autoloading. 305 * device driver. Used for hotplug autoloading.
305 */ 306 */
306 307
307static struct pci_device_id velocity_id_table[] __devinitdata = { 308static const struct pci_device_id velocity_id_table[] __devinitdata = {
308 {PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_612X, 309 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_612X) },
309 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) chip_info_table}, 310 { }
310 {0, }
311}; 311};
312 312
313MODULE_DEVICE_TABLE(pci, velocity_id_table); 313MODULE_DEVICE_TABLE(pci, velocity_id_table);
@@ -341,7 +341,7 @@ static char __devinit *get_chip_name(enum chip_type chip_id)
341static void __devexit velocity_remove1(struct pci_dev *pdev) 341static void __devexit velocity_remove1(struct pci_dev *pdev)
342{ 342{
343 struct net_device *dev = pci_get_drvdata(pdev); 343 struct net_device *dev = pci_get_drvdata(pdev);
344 struct velocity_info *vptr = dev->priv; 344 struct velocity_info *vptr = netdev_priv(dev);
345 345
346#ifdef CONFIG_PM 346#ifdef CONFIG_PM
347 unsigned long flags; 347 unsigned long flags;
@@ -686,21 +686,23 @@ static int __devinit velocity_found1(struct pci_dev *pdev, const struct pci_devi
686 static int first = 1; 686 static int first = 1;
687 struct net_device *dev; 687 struct net_device *dev;
688 int i; 688 int i;
689 struct velocity_info_tbl *info = (struct velocity_info_tbl *) ent->driver_data; 689 const struct velocity_info_tbl *info = &chip_info_table[ent->driver_data];
690 struct velocity_info *vptr; 690 struct velocity_info *vptr;
691 struct mac_regs __iomem * regs; 691 struct mac_regs __iomem * regs;
692 int ret = -ENOMEM; 692 int ret = -ENOMEM;
693 693
694 /* FIXME: this driver, like almost all other ethernet drivers,
695 * can support more than MAX_UNITS.
696 */
694 if (velocity_nics >= MAX_UNITS) { 697 if (velocity_nics >= MAX_UNITS) {
695 printk(KERN_NOTICE VELOCITY_NAME ": already found %d NICs.\n", 698 dev_notice(&pdev->dev, "already found %d NICs.\n",
696 velocity_nics); 699 velocity_nics);
697 return -ENODEV; 700 return -ENODEV;
698 } 701 }
699 702
700 dev = alloc_etherdev(sizeof(struct velocity_info)); 703 dev = alloc_etherdev(sizeof(struct velocity_info));
701 704 if (!dev) {
702 if (dev == NULL) { 705 dev_err(&pdev->dev, "allocate net device failed.\n");
703 printk(KERN_ERR VELOCITY_NAME ": allocate net device failed.\n");
704 goto out; 706 goto out;
705 } 707 }
706 708
@@ -708,7 +710,7 @@ static int __devinit velocity_found1(struct pci_dev *pdev, const struct pci_devi
708 710
709 SET_MODULE_OWNER(dev); 711 SET_MODULE_OWNER(dev);
710 SET_NETDEV_DEV(dev, &pdev->dev); 712 SET_NETDEV_DEV(dev, &pdev->dev);
711 vptr = dev->priv; 713 vptr = netdev_priv(dev);
712 714
713 715
714 if (first) { 716 if (first) {
@@ -731,17 +733,17 @@ static int __devinit velocity_found1(struct pci_dev *pdev, const struct pci_devi
731 733
732 ret = velocity_get_pci_info(vptr, pdev); 734 ret = velocity_get_pci_info(vptr, pdev);
733 if (ret < 0) { 735 if (ret < 0) {
734 printk(KERN_ERR VELOCITY_NAME ": Failed to find PCI device.\n"); 736 /* error message already printed */
735 goto err_disable; 737 goto err_disable;
736 } 738 }
737 739
738 ret = pci_request_regions(pdev, VELOCITY_NAME); 740 ret = pci_request_regions(pdev, VELOCITY_NAME);
739 if (ret < 0) { 741 if (ret < 0) {
740 printk(KERN_ERR VELOCITY_NAME ": Failed to find PCI device.\n"); 742 dev_err(&pdev->dev, "No PCI resources.\n");
741 goto err_disable; 743 goto err_disable;
742 } 744 }
743 745
744 regs = ioremap(vptr->memaddr, vptr->io_size); 746 regs = ioremap(vptr->memaddr, VELOCITY_IO_SIZE);
745 if (regs == NULL) { 747 if (regs == NULL) {
746 ret = -EIO; 748 ret = -EIO;
747 goto err_release_res; 749 goto err_release_res;
@@ -859,13 +861,14 @@ static void __devinit velocity_print_info(struct velocity_info *vptr)
859 * discovered. 861 * discovered.
860 */ 862 */
861 863
862static void __devinit velocity_init_info(struct pci_dev *pdev, struct velocity_info *vptr, struct velocity_info_tbl *info) 864static void __devinit velocity_init_info(struct pci_dev *pdev,
865 struct velocity_info *vptr,
866 const struct velocity_info_tbl *info)
863{ 867{
864 memset(vptr, 0, sizeof(struct velocity_info)); 868 memset(vptr, 0, sizeof(struct velocity_info));
865 869
866 vptr->pdev = pdev; 870 vptr->pdev = pdev;
867 vptr->chip_id = info->chip_id; 871 vptr->chip_id = info->chip_id;
868 vptr->io_size = info->io_size;
869 vptr->num_txq = info->txqueue; 872 vptr->num_txq = info->txqueue;
870 vptr->multicast_limit = MCAM_SIZE; 873 vptr->multicast_limit = MCAM_SIZE;
871 spin_lock_init(&vptr->lock); 874 spin_lock_init(&vptr->lock);
@@ -883,8 +886,7 @@ static void __devinit velocity_init_info(struct pci_dev *pdev, struct velocity_i
883 886
884static int __devinit velocity_get_pci_info(struct velocity_info *vptr, struct pci_dev *pdev) 887static int __devinit velocity_get_pci_info(struct velocity_info *vptr, struct pci_dev *pdev)
885{ 888{
886 889 if (pci_read_config_byte(pdev, PCI_REVISION_ID, &vptr->rev_id) < 0)
887 if(pci_read_config_byte(pdev, PCI_REVISION_ID, &vptr->rev_id) < 0)
888 return -EIO; 890 return -EIO;
889 891
890 pci_set_master(pdev); 892 pci_set_master(pdev);
@@ -892,24 +894,20 @@ static int __devinit velocity_get_pci_info(struct velocity_info *vptr, struct pc
892 vptr->ioaddr = pci_resource_start(pdev, 0); 894 vptr->ioaddr = pci_resource_start(pdev, 0);
893 vptr->memaddr = pci_resource_start(pdev, 1); 895 vptr->memaddr = pci_resource_start(pdev, 1);
894 896
895 if(!(pci_resource_flags(pdev, 0) & IORESOURCE_IO)) 897 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_IO)) {
896 { 898 dev_err(&pdev->dev,
897 printk(KERN_ERR "%s: region #0 is not an I/O resource, aborting.\n", 899 "region #0 is not an I/O resource, aborting.\n");
898 pci_name(pdev));
899 return -EINVAL; 900 return -EINVAL;
900 } 901 }
901 902
902 if((pci_resource_flags(pdev, 1) & IORESOURCE_IO)) 903 if ((pci_resource_flags(pdev, 1) & IORESOURCE_IO)) {
903 { 904 dev_err(&pdev->dev,
904 printk(KERN_ERR "%s: region #1 is an I/O resource, aborting.\n", 905 "region #1 is an I/O resource, aborting.\n");
905 pci_name(pdev));
906 return -EINVAL; 906 return -EINVAL;
907 } 907 }
908 908
909 if(pci_resource_len(pdev, 1) < 256) 909 if (pci_resource_len(pdev, 1) < VELOCITY_IO_SIZE) {
910 { 910 dev_err(&pdev->dev, "region #1 is too small.\n");
911 printk(KERN_ERR "%s: region #1 is too small.\n",
912 pci_name(pdev));
913 return -EINVAL; 911 return -EINVAL;
914 } 912 }
915 vptr->pdev = pdev; 913 vptr->pdev = pdev;
@@ -1728,7 +1726,7 @@ static void velocity_free_tx_buf(struct velocity_info *vptr, struct velocity_td_
1728 1726
1729static int velocity_open(struct net_device *dev) 1727static int velocity_open(struct net_device *dev)
1730{ 1728{
1731 struct velocity_info *vptr = dev->priv; 1729 struct velocity_info *vptr = netdev_priv(dev);
1732 int ret; 1730 int ret;
1733 1731
1734 vptr->rx_buf_sz = (dev->mtu <= 1504 ? PKT_BUF_SZ : dev->mtu + 32); 1732 vptr->rx_buf_sz = (dev->mtu <= 1504 ? PKT_BUF_SZ : dev->mtu + 32);
@@ -1785,7 +1783,7 @@ err_free_desc_rings:
1785 1783
1786static int velocity_change_mtu(struct net_device *dev, int new_mtu) 1784static int velocity_change_mtu(struct net_device *dev, int new_mtu)
1787{ 1785{
1788 struct velocity_info *vptr = dev->priv; 1786 struct velocity_info *vptr = netdev_priv(dev);
1789 unsigned long flags; 1787 unsigned long flags;
1790 int oldmtu = dev->mtu; 1788 int oldmtu = dev->mtu;
1791 int ret = 0; 1789 int ret = 0;
@@ -1861,7 +1859,7 @@ static void velocity_shutdown(struct velocity_info *vptr)
1861 1859
1862static int velocity_close(struct net_device *dev) 1860static int velocity_close(struct net_device *dev)
1863{ 1861{
1864 struct velocity_info *vptr = dev->priv; 1862 struct velocity_info *vptr = netdev_priv(dev);
1865 1863
1866 netif_stop_queue(dev); 1864 netif_stop_queue(dev);
1867 velocity_shutdown(vptr); 1865 velocity_shutdown(vptr);
@@ -1894,7 +1892,7 @@ static int velocity_close(struct net_device *dev)
1894 1892
1895static int velocity_xmit(struct sk_buff *skb, struct net_device *dev) 1893static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
1896{ 1894{
1897 struct velocity_info *vptr = dev->priv; 1895 struct velocity_info *vptr = netdev_priv(dev);
1898 int qnum = 0; 1896 int qnum = 0;
1899 struct tx_desc *td_ptr; 1897 struct tx_desc *td_ptr;
1900 struct velocity_td_info *tdinfo; 1898 struct velocity_td_info *tdinfo;
@@ -2049,7 +2047,7 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
2049static int velocity_intr(int irq, void *dev_instance, struct pt_regs *regs) 2047static int velocity_intr(int irq, void *dev_instance, struct pt_regs *regs)
2050{ 2048{
2051 struct net_device *dev = dev_instance; 2049 struct net_device *dev = dev_instance;
2052 struct velocity_info *vptr = dev->priv; 2050 struct velocity_info *vptr = netdev_priv(dev);
2053 u32 isr_status; 2051 u32 isr_status;
2054 int max_count = 0; 2052 int max_count = 0;
2055 2053
@@ -2104,7 +2102,7 @@ static int velocity_intr(int irq, void *dev_instance, struct pt_regs *regs)
2104 2102
2105static void velocity_set_multi(struct net_device *dev) 2103static void velocity_set_multi(struct net_device *dev)
2106{ 2104{
2107 struct velocity_info *vptr = dev->priv; 2105 struct velocity_info *vptr = netdev_priv(dev);
2108 struct mac_regs __iomem * regs = vptr->mac_regs; 2106 struct mac_regs __iomem * regs = vptr->mac_regs;
2109 u8 rx_mode; 2107 u8 rx_mode;
2110 int i; 2108 int i;
@@ -2153,7 +2151,7 @@ static void velocity_set_multi(struct net_device *dev)
2153 2151
2154static struct net_device_stats *velocity_get_stats(struct net_device *dev) 2152static struct net_device_stats *velocity_get_stats(struct net_device *dev)
2155{ 2153{
2156 struct velocity_info *vptr = dev->priv; 2154 struct velocity_info *vptr = netdev_priv(dev);
2157 2155
2158 /* If the hardware is down, don't touch MII */ 2156 /* If the hardware is down, don't touch MII */
2159 if(!netif_running(dev)) 2157 if(!netif_running(dev))
@@ -2196,7 +2194,7 @@ static struct net_device_stats *velocity_get_stats(struct net_device *dev)
2196 2194
2197static int velocity_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 2195static int velocity_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2198{ 2196{
2199 struct velocity_info *vptr = dev->priv; 2197 struct velocity_info *vptr = netdev_priv(dev);
2200 int ret; 2198 int ret;
2201 2199
2202 /* If we are asked for information and the device is power 2200 /* If we are asked for information and the device is power
@@ -2744,7 +2742,7 @@ static u32 check_connection_type(struct mac_regs __iomem * regs)
2744 2742
2745 if (PHYSR0 & PHYSR0_SPDG) 2743 if (PHYSR0 & PHYSR0_SPDG)
2746 status |= VELOCITY_SPEED_1000; 2744 status |= VELOCITY_SPEED_1000;
2747 if (PHYSR0 & PHYSR0_SPD10) 2745 else if (PHYSR0 & PHYSR0_SPD10)
2748 status |= VELOCITY_SPEED_10; 2746 status |= VELOCITY_SPEED_10;
2749 else 2747 else
2750 status |= VELOCITY_SPEED_100; 2748 status |= VELOCITY_SPEED_100;
@@ -2825,7 +2823,7 @@ static void enable_flow_control_ability(struct velocity_info *vptr)
2825 2823
2826static int velocity_ethtool_up(struct net_device *dev) 2824static int velocity_ethtool_up(struct net_device *dev)
2827{ 2825{
2828 struct velocity_info *vptr = dev->priv; 2826 struct velocity_info *vptr = netdev_priv(dev);
2829 if (!netif_running(dev)) 2827 if (!netif_running(dev))
2830 pci_set_power_state(vptr->pdev, PCI_D0); 2828 pci_set_power_state(vptr->pdev, PCI_D0);
2831 return 0; 2829 return 0;
@@ -2841,20 +2839,29 @@ static int velocity_ethtool_up(struct net_device *dev)
2841 2839
2842static void velocity_ethtool_down(struct net_device *dev) 2840static void velocity_ethtool_down(struct net_device *dev)
2843{ 2841{
2844 struct velocity_info *vptr = dev->priv; 2842 struct velocity_info *vptr = netdev_priv(dev);
2845 if (!netif_running(dev)) 2843 if (!netif_running(dev))
2846 pci_set_power_state(vptr->pdev, PCI_D3hot); 2844 pci_set_power_state(vptr->pdev, PCI_D3hot);
2847} 2845}
2848 2846
2849static int velocity_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 2847static int velocity_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2850{ 2848{
2851 struct velocity_info *vptr = dev->priv; 2849 struct velocity_info *vptr = netdev_priv(dev);
2852 struct mac_regs __iomem * regs = vptr->mac_regs; 2850 struct mac_regs __iomem * regs = vptr->mac_regs;
2853 u32 status; 2851 u32 status;
2854 status = check_connection_type(vptr->mac_regs); 2852 status = check_connection_type(vptr->mac_regs);
2855 2853
2856 cmd->supported = SUPPORTED_TP | SUPPORTED_Autoneg | SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full; 2854 cmd->supported = SUPPORTED_TP |
2857 if (status & VELOCITY_SPEED_100) 2855 SUPPORTED_Autoneg |
2856 SUPPORTED_10baseT_Half |
2857 SUPPORTED_10baseT_Full |
2858 SUPPORTED_100baseT_Half |
2859 SUPPORTED_100baseT_Full |
2860 SUPPORTED_1000baseT_Half |
2861 SUPPORTED_1000baseT_Full;
2862 if (status & VELOCITY_SPEED_1000)
2863 cmd->speed = SPEED_1000;
2864 else if (status & VELOCITY_SPEED_100)
2858 cmd->speed = SPEED_100; 2865 cmd->speed = SPEED_100;
2859 else 2866 else
2860 cmd->speed = SPEED_10; 2867 cmd->speed = SPEED_10;
@@ -2873,7 +2880,7 @@ static int velocity_get_settings(struct net_device *dev, struct ethtool_cmd *cmd
2873 2880
2874static int velocity_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 2881static int velocity_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2875{ 2882{
2876 struct velocity_info *vptr = dev->priv; 2883 struct velocity_info *vptr = netdev_priv(dev);
2877 u32 curr_status; 2884 u32 curr_status;
2878 u32 new_status = 0; 2885 u32 new_status = 0;
2879 int ret = 0; 2886 int ret = 0;
@@ -2896,14 +2903,14 @@ static int velocity_set_settings(struct net_device *dev, struct ethtool_cmd *cmd
2896 2903
2897static u32 velocity_get_link(struct net_device *dev) 2904static u32 velocity_get_link(struct net_device *dev)
2898{ 2905{
2899 struct velocity_info *vptr = dev->priv; 2906 struct velocity_info *vptr = netdev_priv(dev);
2900 struct mac_regs __iomem * regs = vptr->mac_regs; 2907 struct mac_regs __iomem * regs = vptr->mac_regs;
2901 return BYTE_REG_BITS_IS_ON(PHYSR0_LINKGD, &regs->PHYSR0) ? 0 : 1; 2908 return BYTE_REG_BITS_IS_ON(PHYSR0_LINKGD, &regs->PHYSR0) ? 1 : 0;
2902} 2909}
2903 2910
2904static void velocity_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) 2911static void velocity_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2905{ 2912{
2906 struct velocity_info *vptr = dev->priv; 2913 struct velocity_info *vptr = netdev_priv(dev);
2907 strcpy(info->driver, VELOCITY_NAME); 2914 strcpy(info->driver, VELOCITY_NAME);
2908 strcpy(info->version, VELOCITY_VERSION); 2915 strcpy(info->version, VELOCITY_VERSION);
2909 strcpy(info->bus_info, pci_name(vptr->pdev)); 2916 strcpy(info->bus_info, pci_name(vptr->pdev));
@@ -2911,7 +2918,7 @@ static void velocity_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo
2911 2918
2912static void velocity_ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 2919static void velocity_ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
2913{ 2920{
2914 struct velocity_info *vptr = dev->priv; 2921 struct velocity_info *vptr = netdev_priv(dev);
2915 wol->supported = WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_ARP; 2922 wol->supported = WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_ARP;
2916 wol->wolopts |= WAKE_MAGIC; 2923 wol->wolopts |= WAKE_MAGIC;
2917 /* 2924 /*
@@ -2927,7 +2934,7 @@ static void velocity_ethtool_get_wol(struct net_device *dev, struct ethtool_woli
2927 2934
2928static int velocity_ethtool_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 2935static int velocity_ethtool_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
2929{ 2936{
2930 struct velocity_info *vptr = dev->priv; 2937 struct velocity_info *vptr = netdev_priv(dev);
2931 2938
2932 if (!(wol->wolopts & (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_ARP))) 2939 if (!(wol->wolopts & (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_ARP)))
2933 return -EFAULT; 2940 return -EFAULT;
@@ -2992,7 +2999,7 @@ static struct ethtool_ops velocity_ethtool_ops = {
2992 2999
2993static int velocity_mii_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 3000static int velocity_mii_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2994{ 3001{
2995 struct velocity_info *vptr = dev->priv; 3002 struct velocity_info *vptr = netdev_priv(dev);
2996 struct mac_regs __iomem * regs = vptr->mac_regs; 3003 struct mac_regs __iomem * regs = vptr->mac_regs;
2997 unsigned long flags; 3004 unsigned long flags;
2998 struct mii_ioctl_data *miidata = if_mii(ifr); 3005 struct mii_ioctl_data *miidata = if_mii(ifr);
diff --git a/drivers/net/via-velocity.h b/drivers/net/via-velocity.h
index f1b2640ebdc6..496c3d597444 100644
--- a/drivers/net/via-velocity.h
+++ b/drivers/net/via-velocity.h
@@ -31,6 +31,8 @@
31#define VELOCITY_FULL_DRV_NAM "VIA Networking Velocity Family Gigabit Ethernet Adapter Driver" 31#define VELOCITY_FULL_DRV_NAM "VIA Networking Velocity Family Gigabit Ethernet Adapter Driver"
32#define VELOCITY_VERSION "1.13" 32#define VELOCITY_VERSION "1.13"
33 33
34#define VELOCITY_IO_SIZE 256
35
34#define PKT_BUF_SZ 1540 36#define PKT_BUF_SZ 1540
35 37
36#define MAX_UNITS 8 38#define MAX_UNITS 8
@@ -1191,7 +1193,6 @@ enum chip_type {
1191struct velocity_info_tbl { 1193struct velocity_info_tbl {
1192 enum chip_type chip_id; 1194 enum chip_type chip_id;
1193 char *name; 1195 char *name;
1194 int io_size;
1195 int txqueue; 1196 int txqueue;
1196 u32 flags; 1197 u32 flags;
1197}; 1198};
@@ -1751,7 +1752,6 @@ struct velocity_info {
1751 struct mac_regs __iomem * mac_regs; 1752 struct mac_regs __iomem * mac_regs;
1752 unsigned long memaddr; 1753 unsigned long memaddr;
1753 unsigned long ioaddr; 1754 unsigned long ioaddr;
1754 u32 io_size;
1755 1755
1756 u8 rev_id; 1756 u8 rev_id;
1757 1757
diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
index b5328b0ff927..54b8e492ef97 100644
--- a/drivers/net/wan/Kconfig
+++ b/drivers/net/wan/Kconfig
@@ -134,18 +134,6 @@ config SEALEVEL_4021
134 The driver will be compiled as a module: the 134 The driver will be compiled as a module: the
135 module will be called sealevel. 135 module will be called sealevel.
136 136
137config SYNCLINK_SYNCPPP
138 tristate "SyncLink HDLC/SYNCPPP support"
139 depends on WAN
140 help
141 Enables HDLC/SYNCPPP support for the SyncLink WAN driver.
142
143 Normally the SyncLink WAN driver works with the main PPP driver
144 <file:drivers/net/ppp_generic.c> and pppd program.
145 HDLC/SYNCPPP support allows use of the Cisco HDLC/PPP driver
146 <file:drivers/net/wan/syncppp.c>. The SyncLink WAN driver (in
147 character devices) must also be enabled.
148
149# Generic HDLC 137# Generic HDLC
150config HDLC 138config HDLC
151 tristate "Generic HDLC layer" 139 tristate "Generic HDLC layer"
diff --git a/drivers/net/wan/Makefile b/drivers/net/wan/Makefile
index 823c6d5ab90d..316ca6869d5e 100644
--- a/drivers/net/wan/Makefile
+++ b/drivers/net/wan/Makefile
@@ -28,7 +28,6 @@ obj-$(CONFIG_COSA) += syncppp.o cosa.o
28obj-$(CONFIG_FARSYNC) += syncppp.o farsync.o 28obj-$(CONFIG_FARSYNC) += syncppp.o farsync.o
29obj-$(CONFIG_DSCC4) += dscc4.o 29obj-$(CONFIG_DSCC4) += dscc4.o
30obj-$(CONFIG_LANMEDIA) += syncppp.o 30obj-$(CONFIG_LANMEDIA) += syncppp.o
31obj-$(CONFIG_SYNCLINK_SYNCPPP) += syncppp.o
32obj-$(CONFIG_X25_ASY) += x25_asy.o 31obj-$(CONFIG_X25_ASY) += x25_asy.o
33 32
34obj-$(CONFIG_LANMEDIA) += lmc/ 33obj-$(CONFIG_LANMEDIA) += lmc/
diff --git a/drivers/net/wan/c101.c b/drivers/net/wan/c101.c
index c92ac9fde083..6b63b350cd52 100644
--- a/drivers/net/wan/c101.c
+++ b/drivers/net/wan/c101.c
@@ -116,27 +116,34 @@ static inline void openwin(card_t *card, u8 page)
116#include "hd6457x.c" 116#include "hd6457x.c"
117 117
118 118
119static inline void set_carrier(port_t *port)
120{
121 if (!(sca_in(MSCI1_OFFSET + ST3, port) & ST3_DCD))
122 netif_carrier_on(port_to_dev(port));
123 else
124 netif_carrier_off(port_to_dev(port));
125}
126
127
119static void sca_msci_intr(port_t *port) 128static void sca_msci_intr(port_t *port)
120{ 129{
121 struct net_device *dev = port_to_dev(port); 130 u8 stat = sca_in(MSCI0_OFFSET + ST1, port); /* read MSCI ST1 status */
122 card_t* card = port_to_card(port);
123 u8 stat = sca_in(MSCI1_OFFSET + ST1, card); /* read MSCI ST1 status */
124 131
125 /* Reset MSCI TX underrun status bit */ 132 /* Reset MSCI TX underrun and CDCD (ignored) status bit */
126 sca_out(stat & ST1_UDRN, MSCI0_OFFSET + ST1, card); 133 sca_out(stat & (ST1_UDRN | ST1_CDCD), MSCI0_OFFSET + ST1, port);
127 134
128 if (stat & ST1_UDRN) { 135 if (stat & ST1_UDRN) {
129 struct net_device_stats *stats = hdlc_stats(dev); 136 struct net_device_stats *stats = hdlc_stats(port_to_dev(port));
130 stats->tx_errors++; /* TX Underrun error detected */ 137 stats->tx_errors++; /* TX Underrun error detected */
131 stats->tx_fifo_errors++; 138 stats->tx_fifo_errors++;
132 } 139 }
133 140
141 stat = sca_in(MSCI1_OFFSET + ST1, port); /* read MSCI1 ST1 status */
134 /* Reset MSCI CDCD status bit - uses ch#2 DCD input */ 142 /* Reset MSCI CDCD status bit - uses ch#2 DCD input */
135 sca_out(stat & ST1_CDCD, MSCI1_OFFSET + ST1, card); 143 sca_out(stat & ST1_CDCD, MSCI1_OFFSET + ST1, port);
136 144
137 if (stat & ST1_CDCD) 145 if (stat & ST1_CDCD)
138 hdlc_set_carrier(!(sca_in(MSCI1_OFFSET + ST3, card) & ST3_DCD), 146 set_carrier(port);
139 dev);
140} 147}
141 148
142 149
@@ -190,8 +197,7 @@ static int c101_open(struct net_device *dev)
190 sca_out(IE1_UDRN, MSCI0_OFFSET + IE1, port); 197 sca_out(IE1_UDRN, MSCI0_OFFSET + IE1, port);
191 sca_out(IE0_TXINT, MSCI0_OFFSET + IE0, port); 198 sca_out(IE0_TXINT, MSCI0_OFFSET + IE0, port);
192 199
193 hdlc_set_carrier(!(sca_in(MSCI1_OFFSET + ST3, port) & ST3_DCD), dev); 200 set_carrier(port);
194 printk(KERN_DEBUG "0x%X\n", sca_in(MSCI1_OFFSET + ST3, port));
195 201
196 /* enable MSCI1 CDCD interrupt */ 202 /* enable MSCI1 CDCD interrupt */
197 sca_out(IE1_CDCD, MSCI1_OFFSET + IE1, port); 203 sca_out(IE1_CDCD, MSCI1_OFFSET + IE1, port);
@@ -378,7 +384,7 @@ static int __init c101_run(unsigned long irq, unsigned long winbase)
378 } 384 }
379 385
380 sca_init_sync_port(card); /* Set up C101 memory */ 386 sca_init_sync_port(card); /* Set up C101 memory */
381 hdlc_set_carrier(!(sca_in(MSCI1_OFFSET + ST3, card) & ST3_DCD), dev); 387 set_carrier(card);
382 388
383 printk(KERN_INFO "%s: Moxa C101 on IRQ%u," 389 printk(KERN_INFO "%s: Moxa C101 on IRQ%u,"
384 " using %u TX + %u RX packets rings\n", 390 " using %u TX + %u RX packets rings\n",
@@ -443,4 +449,5 @@ module_exit(c101_cleanup);
443MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>"); 449MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
444MODULE_DESCRIPTION("Moxa C101 serial port driver"); 450MODULE_DESCRIPTION("Moxa C101 serial port driver");
445MODULE_LICENSE("GPL v2"); 451MODULE_LICENSE("GPL v2");
446module_param(hw, charp, 0444); /* hw=irq,ram:irq,... */ 452module_param(hw, charp, 0444);
453MODULE_PARM_DESC(hw, "irq,ram:irq,...");
diff --git a/drivers/net/wan/hd6457x.c b/drivers/net/wan/hd6457x.c
index d3743321a977..dce2bb317b82 100644
--- a/drivers/net/wan/hd6457x.c
+++ b/drivers/net/wan/hd6457x.c
@@ -168,6 +168,23 @@ static inline u32 buffer_offset(port_t *port, u16 desc, int transmit)
168} 168}
169 169
170 170
171static inline void sca_set_carrier(port_t *port)
172{
173 if (!(sca_in(get_msci(port) + ST3, port_to_card(port)) & ST3_DCD)) {
174#ifdef DEBUG_LINK
175 printk(KERN_DEBUG "%s: sca_set_carrier on\n",
176 port_to_dev(port)->name);
177#endif
178 netif_carrier_on(port_to_dev(port));
179 } else {
180#ifdef DEBUG_LINK
181 printk(KERN_DEBUG "%s: sca_set_carrier off\n",
182 port_to_dev(port)->name);
183#endif
184 netif_carrier_off(port_to_dev(port));
185 }
186}
187
171 188
172static void sca_init_sync_port(port_t *port) 189static void sca_init_sync_port(port_t *port)
173{ 190{
@@ -237,9 +254,7 @@ static void sca_init_sync_port(port_t *port)
237 sca_out(DIR_BOFE, DIR_TX(phy_node(port)), card); 254 sca_out(DIR_BOFE, DIR_TX(phy_node(port)), card);
238 } 255 }
239 } 256 }
240 257 sca_set_carrier(port);
241 hdlc_set_carrier(!(sca_in(get_msci(port) + ST3, card) & ST3_DCD),
242 port_to_dev(port));
243} 258}
244 259
245 260
@@ -262,8 +277,7 @@ static inline void sca_msci_intr(port_t *port)
262 } 277 }
263 278
264 if (stat & ST1_CDCD) 279 if (stat & ST1_CDCD)
265 hdlc_set_carrier(!(sca_in(msci + ST3, card) & ST3_DCD), 280 sca_set_carrier(port);
266 port_to_dev(port));
267} 281}
268#endif 282#endif
269 283
@@ -566,7 +580,7 @@ static void sca_open(struct net_device *dev)
566 - all DMA interrupts 580 - all DMA interrupts
567*/ 581*/
568 582
569 hdlc_set_carrier(!(sca_in(msci + ST3, card) & ST3_DCD), dev); 583 sca_set_carrier(port);
570 584
571#ifdef __HD64570_H 585#ifdef __HD64570_H
572 /* MSCI TX INT and RX INT A IRQ enable */ 586 /* MSCI TX INT and RX INT A IRQ enable */
diff --git a/drivers/net/wan/hdlc_cisco.c b/drivers/net/wan/hdlc_cisco.c
index 1fd04662c4fc..f289daba0c7b 100644
--- a/drivers/net/wan/hdlc_cisco.c
+++ b/drivers/net/wan/hdlc_cisco.c
@@ -192,9 +192,7 @@ static int cisco_rx(struct sk_buff *skb)
192 "uptime %ud%uh%um%us)\n", 192 "uptime %ud%uh%um%us)\n",
193 dev->name, days, hrs, 193 dev->name, days, hrs,
194 min, sec); 194 min, sec);
195#if 0 195 netif_dormant_off(dev);
196 netif_carrier_on(dev);
197#endif
198 hdlc->state.cisco.up = 1; 196 hdlc->state.cisco.up = 1;
199 } 197 }
200 } 198 }
@@ -227,9 +225,7 @@ static void cisco_timer(unsigned long arg)
227 hdlc->state.cisco.settings.timeout * HZ)) { 225 hdlc->state.cisco.settings.timeout * HZ)) {
228 hdlc->state.cisco.up = 0; 226 hdlc->state.cisco.up = 0;
229 printk(KERN_INFO "%s: Link down\n", dev->name); 227 printk(KERN_INFO "%s: Link down\n", dev->name);
230#if 0 228 netif_dormant_on(dev);
231 netif_carrier_off(dev);
232#endif
233 } 229 }
234 230
235 cisco_keepalive_send(dev, CISCO_KEEPALIVE_REQ, 231 cisco_keepalive_send(dev, CISCO_KEEPALIVE_REQ,
@@ -265,10 +261,7 @@ static void cisco_stop(struct net_device *dev)
265{ 261{
266 hdlc_device *hdlc = dev_to_hdlc(dev); 262 hdlc_device *hdlc = dev_to_hdlc(dev);
267 del_timer_sync(&hdlc->state.cisco.timer); 263 del_timer_sync(&hdlc->state.cisco.timer);
268#if 0 264 netif_dormant_on(dev);
269 if (netif_carrier_ok(dev))
270 netif_carrier_off(dev);
271#endif
272 hdlc->state.cisco.up = 0; 265 hdlc->state.cisco.up = 0;
273 hdlc->state.cisco.request_sent = 0; 266 hdlc->state.cisco.request_sent = 0;
274} 267}
@@ -328,6 +321,7 @@ int hdlc_cisco_ioctl(struct net_device *dev, struct ifreq *ifr)
328 dev->type = ARPHRD_CISCO; 321 dev->type = ARPHRD_CISCO;
329 dev->flags = IFF_POINTOPOINT | IFF_NOARP; 322 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
330 dev->addr_len = 0; 323 dev->addr_len = 0;
324 netif_dormant_on(dev);
331 return 0; 325 return 0;
332 } 326 }
333 327
diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c
index 523afe17564e..7bb737bbdeb9 100644
--- a/drivers/net/wan/hdlc_fr.c
+++ b/drivers/net/wan/hdlc_fr.c
@@ -301,7 +301,7 @@ static int pvc_open(struct net_device *dev)
301 if (pvc->open_count++ == 0) { 301 if (pvc->open_count++ == 0) {
302 hdlc_device *hdlc = dev_to_hdlc(pvc->master); 302 hdlc_device *hdlc = dev_to_hdlc(pvc->master);
303 if (hdlc->state.fr.settings.lmi == LMI_NONE) 303 if (hdlc->state.fr.settings.lmi == LMI_NONE)
304 pvc->state.active = hdlc->carrier; 304 pvc->state.active = netif_carrier_ok(pvc->master);
305 305
306 pvc_carrier(pvc->state.active, pvc); 306 pvc_carrier(pvc->state.active, pvc);
307 hdlc->state.fr.dce_changed = 1; 307 hdlc->state.fr.dce_changed = 1;
@@ -545,11 +545,7 @@ static void fr_set_link_state(int reliable, struct net_device *dev)
545 545
546 hdlc->state.fr.reliable = reliable; 546 hdlc->state.fr.reliable = reliable;
547 if (reliable) { 547 if (reliable) {
548#if 0 548 netif_dormant_off(dev);
549 if (!netif_carrier_ok(dev))
550 netif_carrier_on(dev);
551#endif
552
553 hdlc->state.fr.n391cnt = 0; /* Request full status */ 549 hdlc->state.fr.n391cnt = 0; /* Request full status */
554 hdlc->state.fr.dce_changed = 1; 550 hdlc->state.fr.dce_changed = 1;
555 551
@@ -562,11 +558,7 @@ static void fr_set_link_state(int reliable, struct net_device *dev)
562 } 558 }
563 } 559 }
564 } else { 560 } else {
565#if 0 561 netif_dormant_on(dev);
566 if (netif_carrier_ok(dev))
567 netif_carrier_off(dev);
568#endif
569
570 while (pvc) { /* Deactivate all PVCs */ 562 while (pvc) { /* Deactivate all PVCs */
571 pvc_carrier(0, pvc); 563 pvc_carrier(0, pvc);
572 pvc->state.exist = pvc->state.active = 0; 564 pvc->state.exist = pvc->state.active = 0;
diff --git a/drivers/net/wan/hdlc_generic.c b/drivers/net/wan/hdlc_generic.c
index b7da55140fbd..04ca1f7b6424 100644
--- a/drivers/net/wan/hdlc_generic.c
+++ b/drivers/net/wan/hdlc_generic.c
@@ -34,10 +34,11 @@
34#include <linux/inetdevice.h> 34#include <linux/inetdevice.h>
35#include <linux/lapb.h> 35#include <linux/lapb.h>
36#include <linux/rtnetlink.h> 36#include <linux/rtnetlink.h>
37#include <linux/notifier.h>
37#include <linux/hdlc.h> 38#include <linux/hdlc.h>
38 39
39 40
40static const char* version = "HDLC support module revision 1.18"; 41static const char* version = "HDLC support module revision 1.19";
41 42
42#undef DEBUG_LINK 43#undef DEBUG_LINK
43 44
@@ -73,57 +74,51 @@ static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev,
73 74
74 75
75 76
76static void __hdlc_set_carrier_on(struct net_device *dev) 77static inline void hdlc_proto_start(struct net_device *dev)
77{ 78{
78 hdlc_device *hdlc = dev_to_hdlc(dev); 79 hdlc_device *hdlc = dev_to_hdlc(dev);
79 if (hdlc->proto.start) 80 if (hdlc->proto.start)
80 return hdlc->proto.start(dev); 81 return hdlc->proto.start(dev);
81#if 0
82#ifdef DEBUG_LINK
83 if (netif_carrier_ok(dev))
84 printk(KERN_ERR "hdlc_set_carrier_on(): already on\n");
85#endif
86 netif_carrier_on(dev);
87#endif
88} 82}
89 83
90 84
91 85
92static void __hdlc_set_carrier_off(struct net_device *dev) 86static inline void hdlc_proto_stop(struct net_device *dev)
93{ 87{
94 hdlc_device *hdlc = dev_to_hdlc(dev); 88 hdlc_device *hdlc = dev_to_hdlc(dev);
95 if (hdlc->proto.stop) 89 if (hdlc->proto.stop)
96 return hdlc->proto.stop(dev); 90 return hdlc->proto.stop(dev);
97
98#if 0
99#ifdef DEBUG_LINK
100 if (!netif_carrier_ok(dev))
101 printk(KERN_ERR "hdlc_set_carrier_off(): already off\n");
102#endif
103 netif_carrier_off(dev);
104#endif
105} 91}
106 92
107 93
108 94
109void hdlc_set_carrier(int on, struct net_device *dev) 95static int hdlc_device_event(struct notifier_block *this, unsigned long event,
96 void *ptr)
110{ 97{
111 hdlc_device *hdlc = dev_to_hdlc(dev); 98 struct net_device *dev = ptr;
99 hdlc_device *hdlc;
112 unsigned long flags; 100 unsigned long flags;
113 on = on ? 1 : 0; 101 int on;
102
103 if (dev->get_stats != hdlc_get_stats)
104 return NOTIFY_DONE; /* not an HDLC device */
105
106 if (event != NETDEV_CHANGE)
107 return NOTIFY_DONE; /* Only interrested in carrier changes */
108
109 on = netif_carrier_ok(dev);
114 110
115#ifdef DEBUG_LINK 111#ifdef DEBUG_LINK
116 printk(KERN_DEBUG "hdlc_set_carrier %i\n", on); 112 printk(KERN_DEBUG "%s: hdlc_device_event NETDEV_CHANGE, carrier %i\n",
113 dev->name, on);
117#endif 114#endif
118 115
116 hdlc = dev_to_hdlc(dev);
119 spin_lock_irqsave(&hdlc->state_lock, flags); 117 spin_lock_irqsave(&hdlc->state_lock, flags);
120 118
121 if (hdlc->carrier == on) 119 if (hdlc->carrier == on)
122 goto carrier_exit; /* no change in DCD line level */ 120 goto carrier_exit; /* no change in DCD line level */
123 121
124#ifdef DEBUG_LINK
125 printk(KERN_INFO "%s: carrier %s\n", dev->name, on ? "ON" : "off");
126#endif
127 hdlc->carrier = on; 122 hdlc->carrier = on;
128 123
129 if (!hdlc->open) 124 if (!hdlc->open)
@@ -131,14 +126,15 @@ void hdlc_set_carrier(int on, struct net_device *dev)
131 126
132 if (hdlc->carrier) { 127 if (hdlc->carrier) {
133 printk(KERN_INFO "%s: Carrier detected\n", dev->name); 128 printk(KERN_INFO "%s: Carrier detected\n", dev->name);
134 __hdlc_set_carrier_on(dev); 129 hdlc_proto_start(dev);
135 } else { 130 } else {
136 printk(KERN_INFO "%s: Carrier lost\n", dev->name); 131 printk(KERN_INFO "%s: Carrier lost\n", dev->name);
137 __hdlc_set_carrier_off(dev); 132 hdlc_proto_stop(dev);
138 } 133 }
139 134
140carrier_exit: 135carrier_exit:
141 spin_unlock_irqrestore(&hdlc->state_lock, flags); 136 spin_unlock_irqrestore(&hdlc->state_lock, flags);
137 return NOTIFY_DONE;
142} 138}
143 139
144 140
@@ -165,7 +161,7 @@ int hdlc_open(struct net_device *dev)
165 161
166 if (hdlc->carrier) { 162 if (hdlc->carrier) {
167 printk(KERN_INFO "%s: Carrier detected\n", dev->name); 163 printk(KERN_INFO "%s: Carrier detected\n", dev->name);
168 __hdlc_set_carrier_on(dev); 164 hdlc_proto_start(dev);
169 } else 165 } else
170 printk(KERN_INFO "%s: No carrier\n", dev->name); 166 printk(KERN_INFO "%s: No carrier\n", dev->name);
171 167
@@ -190,7 +186,7 @@ void hdlc_close(struct net_device *dev)
190 186
191 hdlc->open = 0; 187 hdlc->open = 0;
192 if (hdlc->carrier) 188 if (hdlc->carrier)
193 __hdlc_set_carrier_off(dev); 189 hdlc_proto_stop(dev);
194 190
195 spin_unlock_irq(&hdlc->state_lock); 191 spin_unlock_irq(&hdlc->state_lock);
196 192
@@ -303,7 +299,6 @@ MODULE_LICENSE("GPL v2");
303 299
304EXPORT_SYMBOL(hdlc_open); 300EXPORT_SYMBOL(hdlc_open);
305EXPORT_SYMBOL(hdlc_close); 301EXPORT_SYMBOL(hdlc_close);
306EXPORT_SYMBOL(hdlc_set_carrier);
307EXPORT_SYMBOL(hdlc_ioctl); 302EXPORT_SYMBOL(hdlc_ioctl);
308EXPORT_SYMBOL(hdlc_setup); 303EXPORT_SYMBOL(hdlc_setup);
309EXPORT_SYMBOL(alloc_hdlcdev); 304EXPORT_SYMBOL(alloc_hdlcdev);
@@ -315,9 +310,18 @@ static struct packet_type hdlc_packet_type = {
315}; 310};
316 311
317 312
313static struct notifier_block hdlc_notifier = {
314 .notifier_call = hdlc_device_event,
315};
316
317
318static int __init hdlc_module_init(void) 318static int __init hdlc_module_init(void)
319{ 319{
320 int result;
321
320 printk(KERN_INFO "%s\n", version); 322 printk(KERN_INFO "%s\n", version);
323 if ((result = register_netdevice_notifier(&hdlc_notifier)) != 0)
324 return result;
321 dev_add_pack(&hdlc_packet_type); 325 dev_add_pack(&hdlc_packet_type);
322 return 0; 326 return 0;
323} 327}
@@ -327,6 +331,7 @@ static int __init hdlc_module_init(void)
327static void __exit hdlc_module_exit(void) 331static void __exit hdlc_module_exit(void)
328{ 332{
329 dev_remove_pack(&hdlc_packet_type); 333 dev_remove_pack(&hdlc_packet_type);
334 unregister_netdevice_notifier(&hdlc_notifier);
330} 335}
331 336
332 337
diff --git a/drivers/net/wan/hdlc_ppp.c b/drivers/net/wan/hdlc_ppp.c
index b81263eaede0..fbaab5bf71eb 100644
--- a/drivers/net/wan/hdlc_ppp.c
+++ b/drivers/net/wan/hdlc_ppp.c
@@ -107,6 +107,7 @@ int hdlc_ppp_ioctl(struct net_device *dev, struct ifreq *ifr)
107 dev->hard_header = NULL; 107 dev->hard_header = NULL;
108 dev->type = ARPHRD_PPP; 108 dev->type = ARPHRD_PPP;
109 dev->addr_len = 0; 109 dev->addr_len = 0;
110 netif_dormant_off(dev);
110 return 0; 111 return 0;
111 } 112 }
112 113
diff --git a/drivers/net/wan/hdlc_raw.c b/drivers/net/wan/hdlc_raw.c
index 9456d31cb1c1..f15aa6ba77f1 100644
--- a/drivers/net/wan/hdlc_raw.c
+++ b/drivers/net/wan/hdlc_raw.c
@@ -82,6 +82,7 @@ int hdlc_raw_ioctl(struct net_device *dev, struct ifreq *ifr)
82 dev->type = ARPHRD_RAWHDLC; 82 dev->type = ARPHRD_RAWHDLC;
83 dev->flags = IFF_POINTOPOINT | IFF_NOARP; 83 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
84 dev->addr_len = 0; 84 dev->addr_len = 0;
85 netif_dormant_off(dev);
85 return 0; 86 return 0;
86 } 87 }
87 88
diff --git a/drivers/net/wan/hdlc_raw_eth.c b/drivers/net/wan/hdlc_raw_eth.c
index b1285cc8fee6..d1884987f94e 100644
--- a/drivers/net/wan/hdlc_raw_eth.c
+++ b/drivers/net/wan/hdlc_raw_eth.c
@@ -100,6 +100,7 @@ int hdlc_raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr)
100 dev->tx_queue_len = old_qlen; 100 dev->tx_queue_len = old_qlen;
101 memcpy(dev->dev_addr, "\x00\x01", 2); 101 memcpy(dev->dev_addr, "\x00\x01", 2);
102 get_random_bytes(dev->dev_addr + 2, ETH_ALEN - 2); 102 get_random_bytes(dev->dev_addr + 2, ETH_ALEN - 2);
103 netif_dormant_off(dev);
103 return 0; 104 return 0;
104 } 105 }
105 106
diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c
index 07e5eef1fe0f..a867fb411f89 100644
--- a/drivers/net/wan/hdlc_x25.c
+++ b/drivers/net/wan/hdlc_x25.c
@@ -212,6 +212,7 @@ int hdlc_x25_ioctl(struct net_device *dev, struct ifreq *ifr)
212 dev->hard_header = NULL; 212 dev->hard_header = NULL;
213 dev->type = ARPHRD_X25; 213 dev->type = ARPHRD_X25;
214 dev->addr_len = 0; 214 dev->addr_len = 0;
215 netif_dormant_off(dev);
215 return 0; 216 return 0;
216 } 217 }
217 218
diff --git a/drivers/net/wan/n2.c b/drivers/net/wan/n2.c
index e013b817cab8..dcf46add3adf 100644
--- a/drivers/net/wan/n2.c
+++ b/drivers/net/wan/n2.c
@@ -564,4 +564,5 @@ module_exit(n2_cleanup);
564MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>"); 564MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
565MODULE_DESCRIPTION("RISCom/N2 serial port driver"); 565MODULE_DESCRIPTION("RISCom/N2 serial port driver");
566MODULE_LICENSE("GPL v2"); 566MODULE_LICENSE("GPL v2");
567module_param(hw, charp, 0444); /* hw=io,irq,ram,ports:io,irq,... */ 567module_param(hw, charp, 0444);
568MODULE_PARM_DESC(hw, "io,irq,ram,ports:io,irq,...");
diff --git a/drivers/net/wan/wanxl.c b/drivers/net/wan/wanxl.c
index d564224cdca9..b2031dfc4bb1 100644
--- a/drivers/net/wan/wanxl.c
+++ b/drivers/net/wan/wanxl.c
@@ -149,7 +149,10 @@ static inline void wanxl_cable_intr(port_t *port)
149 printk(KERN_INFO "%s: %s%s module, %s cable%s%s\n", 149 printk(KERN_INFO "%s: %s%s module, %s cable%s%s\n",
150 port->dev->name, pm, dte, cable, dsr, dcd); 150 port->dev->name, pm, dte, cable, dsr, dcd);
151 151
152 hdlc_set_carrier(value & STATUS_CABLE_DCD, port->dev); 152 if (value & STATUS_CABLE_DCD)
153 netif_carrier_on(port->dev);
154 else
155 netif_carrier_off(port->dev);
153} 156}
154 157
155 158
diff --git a/drivers/net/wd.c b/drivers/net/wd.c
index 7caa8dc88a58..b1ba1872f315 100644
--- a/drivers/net/wd.c
+++ b/drivers/net/wd.c
@@ -500,8 +500,8 @@ MODULE_LICENSE("GPL");
500 500
501/* This is set up so that only a single autoprobe takes place per call. 501/* This is set up so that only a single autoprobe takes place per call.
502ISA device autoprobes on a running machine are not recommended. */ 502ISA device autoprobes on a running machine are not recommended. */
503int 503
504init_module(void) 504int __init init_module(void)
505{ 505{
506 struct net_device *dev; 506 struct net_device *dev;
507 int this_dev, found = 0; 507 int this_dev, found = 0;
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 30ec235e6935..2e8ac995d56f 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -447,6 +447,7 @@ config AIRO_CS
447 tristate "Cisco/Aironet 34X/35X/4500/4800 PCMCIA cards" 447 tristate "Cisco/Aironet 34X/35X/4500/4800 PCMCIA cards"
448 depends on NET_RADIO && PCMCIA && (BROKEN || !M32R) 448 depends on NET_RADIO && PCMCIA && (BROKEN || !M32R)
449 select CRYPTO 449 select CRYPTO
450 select CRYPTO_AES
450 ---help--- 451 ---help---
451 This is the standard Linux driver to support Cisco/Aironet PCMCIA 452 This is the standard Linux driver to support Cisco/Aironet PCMCIA
452 802.11 wireless cards. This driver is the same as the Aironet 453 802.11 wireless cards. This driver is the same as the Aironet
@@ -550,6 +551,7 @@ config USB_ZD1201
550 551
551source "drivers/net/wireless/hostap/Kconfig" 552source "drivers/net/wireless/hostap/Kconfig"
552source "drivers/net/wireless/bcm43xx/Kconfig" 553source "drivers/net/wireless/bcm43xx/Kconfig"
554source "drivers/net/wireless/zd1211rw/Kconfig"
553 555
554# yes, this works even when no drivers are selected 556# yes, this works even when no drivers are selected
555config NET_WIRELESS 557config NET_WIRELESS
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 512603de309a..c613af17a159 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_PRISM54) += prism54/
36 36
37obj-$(CONFIG_HOSTAP) += hostap/ 37obj-$(CONFIG_HOSTAP) += hostap/
38obj-$(CONFIG_BCM43XX) += bcm43xx/ 38obj-$(CONFIG_BCM43XX) += bcm43xx/
39obj-$(CONFIG_ZD1211RW) += zd1211rw/
39 40
40# 16-bit wireless PCMCIA client drivers 41# 16-bit wireless PCMCIA client drivers
41obj-$(CONFIG_PCMCIA_RAYCS) += ray_cs.o 42obj-$(CONFIG_PCMCIA_RAYCS) += ray_cs.o
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_ethtool.c b/drivers/net/wireless/bcm43xx/bcm43xx_ethtool.c
index b3ffcf501311..e386dcc32e8c 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_ethtool.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_ethtool.c
@@ -32,7 +32,7 @@
32#include <linux/netdevice.h> 32#include <linux/netdevice.h>
33#include <linux/pci.h> 33#include <linux/pci.h>
34#include <linux/string.h> 34#include <linux/string.h>
35#include <linux/version.h> 35#include <linux/utsrelease.h>
36 36
37 37
38static void bcm43xx_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) 38static void bcm43xx_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.c b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
index d8f5600578b4..df317c1e12a8 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
@@ -1547,7 +1547,7 @@ static void handle_irq_noise(struct bcm43xx_private *bcm)
1547 goto generate_new; 1547 goto generate_new;
1548 1548
1549 /* Get the noise samples. */ 1549 /* Get the noise samples. */
1550 assert(bcm->noisecalc.nr_samples <= 8); 1550 assert(bcm->noisecalc.nr_samples < 8);
1551 i = bcm->noisecalc.nr_samples; 1551 i = bcm->noisecalc.nr_samples;
1552 noise[0] = limit_value(noise[0], 0, ARRAY_SIZE(radio->nrssi_lt) - 1); 1552 noise[0] = limit_value(noise[0], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
1553 noise[1] = limit_value(noise[1], 0, ARRAY_SIZE(radio->nrssi_lt) - 1); 1553 noise[1] = limit_value(noise[1], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
@@ -1885,6 +1885,15 @@ static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_re
1885 1885
1886 spin_lock(&bcm->irq_lock); 1886 spin_lock(&bcm->irq_lock);
1887 1887
1888 /* Only accept IRQs, if we are initialized properly.
1889 * This avoids an RX race while initializing.
1890 * We should probably not enable IRQs before we are initialized
1891 * completely, but some careful work is needed to fix this. I think it
1892 * is best to stay with this cheap workaround for now... .
1893 */
1894 if (unlikely(bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED))
1895 goto out;
1896
1888 reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); 1897 reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
1889 if (reason == 0xffffffff) { 1898 if (reason == 0xffffffff) {
1890 /* irq not for us (shared irq) */ 1899 /* irq not for us (shared irq) */
@@ -1906,19 +1915,11 @@ static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_re
1906 1915
1907 bcm43xx_interrupt_ack(bcm, reason); 1916 bcm43xx_interrupt_ack(bcm, reason);
1908 1917
1909 /* Only accept IRQs, if we are initialized properly. 1918 /* disable all IRQs. They are enabled again in the bottom half. */
1910 * This avoids an RX race while initializing. 1919 bcm->irq_savedstate = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
1911 * We should probably not enable IRQs before we are initialized 1920 /* save the reason code and call our bottom half. */
1912 * completely, but some careful work is needed to fix this. I think it 1921 bcm->irq_reason = reason;
1913 * is best to stay with this cheap workaround for now... . 1922 tasklet_schedule(&bcm->isr_tasklet);
1914 */
1915 if (likely(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)) {
1916 /* disable all IRQs. They are enabled again in the bottom half. */
1917 bcm->irq_savedstate = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
1918 /* save the reason code and call our bottom half. */
1919 bcm->irq_reason = reason;
1920 tasklet_schedule(&bcm->isr_tasklet);
1921 }
1922 1923
1923out: 1924out:
1924 mmiowb(); 1925 mmiowb();
@@ -3698,6 +3699,10 @@ static void bcm43xx_ieee80211_set_security(struct net_device *net_dev,
3698 secinfo->encrypt = sec->encrypt; 3699 secinfo->encrypt = sec->encrypt;
3699 dprintk(", .encrypt = %d", sec->encrypt); 3700 dprintk(", .encrypt = %d", sec->encrypt);
3700 } 3701 }
3702 if (sec->flags & SEC_AUTH_MODE) {
3703 secinfo->auth_mode = sec->auth_mode;
3704 dprintk(", .auth_mode = %d", sec->auth_mode);
3705 }
3701 dprintk("\n"); 3706 dprintk("\n");
3702 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED && 3707 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED &&
3703 !bcm->ieee->host_encrypt) { 3708 !bcm->ieee->host_encrypt) {
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.h b/drivers/net/wireless/bcm43xx/bcm43xx_main.h
index 30a202b258b5..116493671f88 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_main.h
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.h
@@ -112,30 +112,6 @@ int bcm43xx_channel_to_freq(struct bcm43xx_private *bcm,
112 return bcm43xx_channel_to_freq_bg(channel); 112 return bcm43xx_channel_to_freq_bg(channel);
113} 113}
114 114
115/* Lightweight function to check if a channel number is valid.
116 * Note that this does _NOT_ check for geographical restrictions!
117 */
118static inline
119int bcm43xx_is_valid_channel_a(u8 channel)
120{
121 return (channel >= IEEE80211_52GHZ_MIN_CHANNEL
122 && channel <= IEEE80211_52GHZ_MAX_CHANNEL);
123}
124static inline
125int bcm43xx_is_valid_channel_bg(u8 channel)
126{
127 return (channel >= IEEE80211_24GHZ_MIN_CHANNEL
128 && channel <= IEEE80211_24GHZ_MAX_CHANNEL);
129}
130static inline
131int bcm43xx_is_valid_channel(struct bcm43xx_private *bcm,
132 u8 channel)
133{
134 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
135 return bcm43xx_is_valid_channel_a(channel);
136 return bcm43xx_is_valid_channel_bg(channel);
137}
138
139void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf); 115void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf);
140void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf); 116void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf);
141 117
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_radio.c b/drivers/net/wireless/bcm43xx/bcm43xx_radio.c
index af5c0bff1696..bb9c484d7e19 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_radio.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_radio.c
@@ -1594,11 +1594,11 @@ int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm,
1594 u16 r8, tmp; 1594 u16 r8, tmp;
1595 u16 freq; 1595 u16 freq;
1596 1596
1597 if (!ieee80211_is_valid_channel(bcm->ieee, channel))
1598 return -EINVAL;
1597 if ((radio->manufact == 0x17F) && 1599 if ((radio->manufact == 0x17F) &&
1598 (radio->version == 0x2060) && 1600 (radio->version == 0x2060) &&
1599 (radio->revision == 1)) { 1601 (radio->revision == 1)) {
1600 if (channel > 200)
1601 return -EINVAL;
1602 freq = channel2freq_a(channel); 1602 freq = channel2freq_a(channel);
1603 1603
1604 r8 = bcm43xx_radio_read16(bcm, 0x0008); 1604 r8 = bcm43xx_radio_read16(bcm, 0x0008);
@@ -1651,9 +1651,6 @@ int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm,
1651 TODO(); //TODO: TSSI2dbm workaround 1651 TODO(); //TODO: TSSI2dbm workaround
1652 bcm43xx_phy_xmitpower(bcm);//FIXME correct? 1652 bcm43xx_phy_xmitpower(bcm);//FIXME correct?
1653 } else { 1653 } else {
1654 if ((channel < 1) || (channel > 14))
1655 return -EINVAL;
1656
1657 if (synthetic_pu_workaround) 1654 if (synthetic_pu_workaround)
1658 bcm43xx_synth_pu_workaround(bcm, channel); 1655 bcm43xx_synth_pu_workaround(bcm, channel);
1659 1656
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_wx.c b/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
index c35cb3a0777e..5c36e29efff7 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
@@ -119,7 +119,7 @@ static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev,
119 channel = bcm43xx_freq_to_channel(bcm, data->freq.m); 119 channel = bcm43xx_freq_to_channel(bcm, data->freq.m);
120 freq = data->freq.m; 120 freq = data->freq.m;
121 } 121 }
122 if (!bcm43xx_is_valid_channel(bcm, channel)) 122 if (!ieee80211_is_valid_channel(bcm->ieee, channel))
123 goto out_unlock; 123 goto out_unlock;
124 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) { 124 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
125 //ieee80211softmac_disassoc(softmac, $REASON); 125 //ieee80211softmac_disassoc(softmac, $REASON);
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c b/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c
index d8ece28c079f..6dbd855b3647 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c
@@ -296,11 +296,14 @@ void bcm43xx_generate_txhdr(struct bcm43xx_private *bcm,
296 u16 control = 0; 296 u16 control = 0;
297 u16 wsec_rate = 0; 297 u16 wsec_rate = 0;
298 u16 encrypt_frame; 298 u16 encrypt_frame;
299 const u16 ftype = WLAN_FC_GET_TYPE(le16_to_cpu(wireless_header->frame_ctl));
300 const int is_mgt = (ftype == IEEE80211_FTYPE_MGMT);
299 301
300 /* Now construct the TX header. */ 302 /* Now construct the TX header. */
301 memset(txhdr, 0, sizeof(*txhdr)); 303 memset(txhdr, 0, sizeof(*txhdr));
302 304
303 bitrate = bcm->softmac->txrates.default_rate; 305 bitrate = ieee80211softmac_suggest_txrate(bcm->softmac,
306 is_multicast_ether_addr(wireless_header->addr1), is_mgt);
304 ofdm_modulation = !(ieee80211_is_cck_rate(bitrate)); 307 ofdm_modulation = !(ieee80211_is_cck_rate(bitrate));
305 fallback_bitrate = bcm43xx_calc_fallback_rate(bitrate); 308 fallback_bitrate = bcm43xx_calc_fallback_rate(bitrate);
306 fallback_ofdm_modulation = !(ieee80211_is_cck_rate(fallback_bitrate)); 309 fallback_ofdm_modulation = !(ieee80211_is_cck_rate(fallback_bitrate));
diff --git a/drivers/net/wireless/hostap/hostap_hw.c b/drivers/net/wireless/hostap/hostap_hw.c
index b764cfda6e84..d500012fdc7a 100644
--- a/drivers/net/wireless/hostap/hostap_hw.c
+++ b/drivers/net/wireless/hostap/hostap_hw.c
@@ -1042,6 +1042,9 @@ static int prism2_reset_port(struct net_device *dev)
1042 dev->name, local->fragm_threshold); 1042 dev->name, local->fragm_threshold);
1043 } 1043 }
1044 1044
1045 /* Some firmwares lose antenna selection settings on reset */
1046 (void) hostap_set_antsel(local);
1047
1045 return res; 1048 return res;
1046} 1049}
1047 1050
@@ -3095,6 +3098,14 @@ static void prism2_clear_set_tim_queue(local_info_t *local)
3095} 3098}
3096 3099
3097 3100
3101/*
3102 * HostAP uses two layers of net devices, where the inner
3103 * layer gets called all the time from the outer layer.
3104 * This is a natural nesting, which needs a split lock type.
3105 */
3106static struct lock_class_key hostap_netdev_xmit_lock_key;
3107
3108
3098static struct net_device * 3109static struct net_device *
3099prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx, 3110prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx,
3100 struct device *sdev) 3111 struct device *sdev)
@@ -3259,6 +3270,8 @@ while (0)
3259 SET_NETDEV_DEV(dev, sdev); 3270 SET_NETDEV_DEV(dev, sdev);
3260 if (ret >= 0) 3271 if (ret >= 0)
3261 ret = register_netdevice(dev); 3272 ret = register_netdevice(dev);
3273
3274 lockdep_set_class(&dev->_xmit_lock, &hostap_netdev_xmit_lock_key);
3262 rtnl_unlock(); 3275 rtnl_unlock();
3263 if (ret < 0) { 3276 if (ret < 0) {
3264 printk(KERN_WARNING "%s: register netdevice failed!\n", 3277 printk(KERN_WARNING "%s: register netdevice failed!\n",
diff --git a/drivers/net/wireless/hostap/hostap_plx.c b/drivers/net/wireless/hostap/hostap_plx.c
index 49860fa61c30..6dfa041be66d 100644
--- a/drivers/net/wireless/hostap/hostap_plx.c
+++ b/drivers/net/wireless/hostap/hostap_plx.c
@@ -66,10 +66,12 @@ static struct pci_device_id prism2_plx_id_table[] __devinitdata = {
66 PLXDEV(0x10b7, 0x7770, "3Com AirConnect PCI 777A"), 66 PLXDEV(0x10b7, 0x7770, "3Com AirConnect PCI 777A"),
67 PLXDEV(0x111a, 0x1023, "Siemens SpeedStream SS1023"), 67 PLXDEV(0x111a, 0x1023, "Siemens SpeedStream SS1023"),
68 PLXDEV(0x126c, 0x8030, "Nortel emobility"), 68 PLXDEV(0x126c, 0x8030, "Nortel emobility"),
69 PLXDEV(0x1562, 0x0001, "Symbol LA-4123"),
69 PLXDEV(0x1385, 0x4100, "Netgear MA301"), 70 PLXDEV(0x1385, 0x4100, "Netgear MA301"),
70 PLXDEV(0x15e8, 0x0130, "National Datacomm NCP130 (PLX9052)"), 71 PLXDEV(0x15e8, 0x0130, "National Datacomm NCP130 (PLX9052)"),
71 PLXDEV(0x15e8, 0x0131, "National Datacomm NCP130 (TMD7160)"), 72 PLXDEV(0x15e8, 0x0131, "National Datacomm NCP130 (TMD7160)"),
72 PLXDEV(0x1638, 0x1100, "Eumitcom WL11000"), 73 PLXDEV(0x1638, 0x1100, "Eumitcom WL11000"),
74 PLXDEV(0x16ab, 0x1100, "Global Sun Tech GL24110P"),
73 PLXDEV(0x16ab, 0x1101, "Global Sun Tech GL24110P (?)"), 75 PLXDEV(0x16ab, 0x1101, "Global Sun Tech GL24110P (?)"),
74 PLXDEV(0x16ab, 0x1102, "Linksys WPC11 with WDT11"), 76 PLXDEV(0x16ab, 0x1102, "Linksys WPC11 with WDT11"),
75 PLXDEV(0x16ab, 0x1103, "Longshine 8031"), 77 PLXDEV(0x16ab, 0x1103, "Longshine 8031"),
diff --git a/drivers/net/wireless/orinoco.c b/drivers/net/wireless/orinoco.c
index d6ed5781b93a..317ace7f9aae 100644
--- a/drivers/net/wireless/orinoco.c
+++ b/drivers/net/wireless/orinoco.c
@@ -2875,7 +2875,7 @@ static int orinoco_ioctl_setiwencode(struct net_device *dev,
2875 if (orinoco_lock(priv, &flags) != 0) 2875 if (orinoco_lock(priv, &flags) != 0)
2876 return -EBUSY; 2876 return -EBUSY;
2877 2877
2878 if (erq->pointer) { 2878 if (erq->length > 0) {
2879 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) 2879 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2880 index = priv->tx_key; 2880 index = priv->tx_key;
2881 2881
@@ -2918,7 +2918,7 @@ static int orinoco_ioctl_setiwencode(struct net_device *dev,
2918 if (erq->flags & IW_ENCODE_RESTRICTED) 2918 if (erq->flags & IW_ENCODE_RESTRICTED)
2919 restricted = 1; 2919 restricted = 1;
2920 2920
2921 if (erq->pointer) { 2921 if (erq->pointer && erq->length > 0) {
2922 priv->keys[index].len = cpu_to_le16(xlen); 2922 priv->keys[index].len = cpu_to_le16(xlen);
2923 memset(priv->keys[index].data, 0, 2923 memset(priv->keys[index].data, 0,
2924 sizeof(priv->keys[index].data)); 2924 sizeof(priv->keys[index].data));
diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c
index 15465278c789..bcc7038130f6 100644
--- a/drivers/net/wireless/spectrum_cs.c
+++ b/drivers/net/wireless/spectrum_cs.c
@@ -34,8 +34,6 @@
34 34
35#include "orinoco.h" 35#include "orinoco.h"
36 36
37static unsigned char *primsym;
38static unsigned char *secsym;
39static const char primary_fw_name[] = "symbol_sp24t_prim_fw"; 37static const char primary_fw_name[] = "symbol_sp24t_prim_fw";
40static const char secondary_fw_name[] = "symbol_sp24t_sec_fw"; 38static const char secondary_fw_name[] = "symbol_sp24t_sec_fw";
41 39
@@ -244,7 +242,7 @@ spectrum_reset(struct pcmcia_device *link, int idle)
244 u_int save_cor; 242 u_int save_cor;
245 243
246 /* Doing it if hardware is gone is guaranteed crash */ 244 /* Doing it if hardware is gone is guaranteed crash */
247 if (pcmcia_dev_present(link)) 245 if (!pcmcia_dev_present(link))
248 return -ENODEV; 246 return -ENODEV;
249 247
250 /* Save original COR value */ 248 /* Save original COR value */
@@ -440,7 +438,7 @@ spectrum_load_blocks(hermes_t *hw, const struct dblock *first_block)
440 */ 438 */
441static int 439static int
442spectrum_dl_image(hermes_t *hw, struct pcmcia_device *link, 440spectrum_dl_image(hermes_t *hw, struct pcmcia_device *link,
443 const unsigned char *image) 441 const unsigned char *image, int secondary)
444{ 442{
445 int ret; 443 int ret;
446 const unsigned char *ptr; 444 const unsigned char *ptr;
@@ -455,7 +453,7 @@ spectrum_dl_image(hermes_t *hw, struct pcmcia_device *link,
455 first_block = (const struct dblock *) ptr; 453 first_block = (const struct dblock *) ptr;
456 454
457 /* Read the PDA */ 455 /* Read the PDA */
458 if (image != primsym) { 456 if (secondary) {
459 ret = spectrum_read_pda(hw, pda, sizeof(pda)); 457 ret = spectrum_read_pda(hw, pda, sizeof(pda));
460 if (ret) 458 if (ret)
461 return ret; 459 return ret;
@@ -472,7 +470,7 @@ spectrum_dl_image(hermes_t *hw, struct pcmcia_device *link,
472 return ret; 470 return ret;
473 471
474 /* Write the PDA to the adapter */ 472 /* Write the PDA to the adapter */
475 if (image != primsym) { 473 if (secondary) {
476 ret = spectrum_apply_pda(hw, first_block, pda); 474 ret = spectrum_apply_pda(hw, first_block, pda);
477 if (ret) 475 if (ret)
478 return ret; 476 return ret;
@@ -487,7 +485,7 @@ spectrum_dl_image(hermes_t *hw, struct pcmcia_device *link,
487 ret = hermes_init(hw); 485 ret = hermes_init(hw);
488 486
489 /* hermes_reset() should return 0 with the secondary firmware */ 487 /* hermes_reset() should return 0 with the secondary firmware */
490 if (image != primsym && ret != 0) 488 if (secondary && ret != 0)
491 return -ENODEV; 489 return -ENODEV;
492 490
493 /* And this should work with any firmware */ 491 /* And this should work with any firmware */
@@ -509,33 +507,30 @@ spectrum_dl_firmware(hermes_t *hw, struct pcmcia_device *link)
509 const struct firmware *fw_entry; 507 const struct firmware *fw_entry;
510 508
511 if (request_firmware(&fw_entry, primary_fw_name, 509 if (request_firmware(&fw_entry, primary_fw_name,
512 &handle_to_dev(link)) == 0) { 510 &handle_to_dev(link)) != 0) {
513 primsym = fw_entry->data;
514 } else {
515 printk(KERN_ERR PFX "Cannot find firmware: %s\n", 511 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
516 primary_fw_name); 512 primary_fw_name);
517 return -ENOENT; 513 return -ENOENT;
518 } 514 }
519 515
520 if (request_firmware(&fw_entry, secondary_fw_name,
521 &handle_to_dev(link)) == 0) {
522 secsym = fw_entry->data;
523 } else {
524 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
525 secondary_fw_name);
526 return -ENOENT;
527 }
528
529 /* Load primary firmware */ 516 /* Load primary firmware */
530 ret = spectrum_dl_image(hw, link, primsym); 517 ret = spectrum_dl_image(hw, link, fw_entry->data, 0);
518 release_firmware(fw_entry);
531 if (ret) { 519 if (ret) {
532 printk(KERN_ERR PFX "Primary firmware download failed\n"); 520 printk(KERN_ERR PFX "Primary firmware download failed\n");
533 return ret; 521 return ret;
534 } 522 }
535 523
536 /* Load secondary firmware */ 524 if (request_firmware(&fw_entry, secondary_fw_name,
537 ret = spectrum_dl_image(hw, link, secsym); 525 &handle_to_dev(link)) != 0) {
526 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
527 secondary_fw_name);
528 return -ENOENT;
529 }
538 530
531 /* Load secondary firmware */
532 ret = spectrum_dl_image(hw, link, fw_entry->data, 1);
533 release_firmware(fw_entry);
539 if (ret) { 534 if (ret) {
540 printk(KERN_ERR PFX "Secondary firmware download failed\n"); 535 printk(KERN_ERR PFX "Secondary firmware download failed\n");
541 } 536 }
diff --git a/drivers/net/wireless/strip.c b/drivers/net/wireless/strip.c
index fd31885c6844..ccaf28e8db0a 100644
--- a/drivers/net/wireless/strip.c
+++ b/drivers/net/wireless/strip.c
@@ -467,6 +467,7 @@ static int arp_query(unsigned char *haddr, u32 paddr,
467 struct net_device *dev) 467 struct net_device *dev)
468{ 468{
469 struct neighbour *neighbor_entry; 469 struct neighbour *neighbor_entry;
470 int ret = 0;
470 471
471 neighbor_entry = neigh_lookup(&arp_tbl, &paddr, dev); 472 neighbor_entry = neigh_lookup(&arp_tbl, &paddr, dev);
472 473
@@ -474,10 +475,11 @@ static int arp_query(unsigned char *haddr, u32 paddr,
474 neighbor_entry->used = jiffies; 475 neighbor_entry->used = jiffies;
475 if (neighbor_entry->nud_state & NUD_VALID) { 476 if (neighbor_entry->nud_state & NUD_VALID) {
476 memcpy(haddr, neighbor_entry->ha, dev->addr_len); 477 memcpy(haddr, neighbor_entry->ha, dev->addr_len);
477 return 1; 478 ret = 1;
478 } 479 }
480 neigh_release(neighbor_entry);
479 } 481 }
480 return 0; 482 return ret;
481} 483}
482 484
483static void DumpData(char *msg, struct strip *strip_info, __u8 * ptr, 485static void DumpData(char *msg, struct strip *strip_info, __u8 * ptr,
diff --git a/drivers/net/wireless/zd1201.c b/drivers/net/wireless/zd1201.c
index 662ecc8a33ff..c52e9bcf8d02 100644
--- a/drivers/net/wireless/zd1201.c
+++ b/drivers/net/wireless/zd1201.c
@@ -1820,6 +1820,8 @@ static int zd1201_probe(struct usb_interface *interface,
1820 zd->dev->name); 1820 zd->dev->name);
1821 1821
1822 usb_set_intfdata(interface, zd); 1822 usb_set_intfdata(interface, zd);
1823 zd1201_enable(zd); /* zd1201 likes to startup enabled, */
1824 zd1201_disable(zd); /* interfering with all the wifis in range */
1823 return 0; 1825 return 0;
1824 1826
1825err_net: 1827err_net:
diff --git a/drivers/net/wireless/zd1211rw/Kconfig b/drivers/net/wireless/zd1211rw/Kconfig
new file mode 100644
index 000000000000..66ed55bc5460
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/Kconfig
@@ -0,0 +1,19 @@
1config ZD1211RW
2 tristate "ZyDAS ZD1211/ZD1211B USB-wireless support"
3 depends on USB && IEEE80211 && IEEE80211_SOFTMAC && NET_RADIO && EXPERIMENTAL
4 select FW_LOADER
5 ---help---
6 This is an experimental driver for the ZyDAS ZD1211/ZD1211B wireless
7 chip, present in many USB-wireless adapters.
8
9 Device firmware is required alongside this driver. You can download the
10 firmware distribution from http://zd1211.ath.cx/get-firmware
11
12config ZD1211RW_DEBUG
13 bool "ZyDAS ZD1211 debugging"
14 depends on ZD1211RW
15 ---help---
16 ZD1211 debugging messages. Choosing Y will result in additional debug
17 messages being saved to your kernel logs, which may help debug any
18 problems.
19
diff --git a/drivers/net/wireless/zd1211rw/Makefile b/drivers/net/wireless/zd1211rw/Makefile
new file mode 100644
index 000000000000..500314fc74d2
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/Makefile
@@ -0,0 +1,11 @@
1obj-$(CONFIG_ZD1211RW) += zd1211rw.o
2
3zd1211rw-objs := zd_chip.o zd_ieee80211.o \
4 zd_mac.o zd_netdev.o \
5 zd_rf_al2230.o zd_rf_rf2959.o \
6 zd_rf.o zd_usb.o zd_util.o
7
8ifeq ($(CONFIG_ZD1211RW_DEBUG),y)
9EXTRA_CFLAGS += -DDEBUG
10endif
11
diff --git a/drivers/net/wireless/zd1211rw/zd_chip.c b/drivers/net/wireless/zd1211rw/zd_chip.c
new file mode 100644
index 000000000000..aa792821854e
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_chip.c
@@ -0,0 +1,1646 @@
1/* zd_chip.c
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18/* This file implements all the hardware specific functions for the ZD1211
19 * and ZD1211B chips. Support for the ZD1211B was possible after Timothy
20 * Legge sent me a ZD1211B device. Thank you Tim. -- Uli
21 */
22
23#include <linux/kernel.h>
24#include <linux/errno.h>
25
26#include "zd_def.h"
27#include "zd_chip.h"
28#include "zd_ieee80211.h"
29#include "zd_mac.h"
30#include "zd_rf.h"
31#include "zd_util.h"
32
33void zd_chip_init(struct zd_chip *chip,
34 struct net_device *netdev,
35 struct usb_interface *intf)
36{
37 memset(chip, 0, sizeof(*chip));
38 mutex_init(&chip->mutex);
39 zd_usb_init(&chip->usb, netdev, intf);
40 zd_rf_init(&chip->rf);
41}
42
43void zd_chip_clear(struct zd_chip *chip)
44{
45 mutex_lock(&chip->mutex);
46 zd_usb_clear(&chip->usb);
47 zd_rf_clear(&chip->rf);
48 mutex_unlock(&chip->mutex);
49 mutex_destroy(&chip->mutex);
50 memset(chip, 0, sizeof(*chip));
51}
52
53static int scnprint_mac_oui(const u8 *addr, char *buffer, size_t size)
54{
55 return scnprintf(buffer, size, "%02x-%02x-%02x",
56 addr[0], addr[1], addr[2]);
57}
58
59/* Prints an identifier line, which will support debugging. */
60static int scnprint_id(struct zd_chip *chip, char *buffer, size_t size)
61{
62 int i = 0;
63
64 i = scnprintf(buffer, size, "zd1211%s chip ",
65 chip->is_zd1211b ? "b" : "");
66 i += zd_usb_scnprint_id(&chip->usb, buffer+i, size-i);
67 i += scnprintf(buffer+i, size-i, " ");
68 i += scnprint_mac_oui(chip->e2p_mac, buffer+i, size-i);
69 i += scnprintf(buffer+i, size-i, " ");
70 i += zd_rf_scnprint_id(&chip->rf, buffer+i, size-i);
71 i += scnprintf(buffer+i, size-i, " pa%1x %c%c%c", chip->pa_type,
72 chip->patch_cck_gain ? 'g' : '-',
73 chip->patch_cr157 ? '7' : '-',
74 chip->patch_6m_band_edge ? '6' : '-');
75 return i;
76}
77
78static void print_id(struct zd_chip *chip)
79{
80 char buffer[80];
81
82 scnprint_id(chip, buffer, sizeof(buffer));
83 buffer[sizeof(buffer)-1] = 0;
84 dev_info(zd_chip_dev(chip), "%s\n", buffer);
85}
86
87/* Read a variable number of 32-bit values. Parameter count is not allowed to
88 * exceed USB_MAX_IOREAD32_COUNT.
89 */
90int zd_ioread32v_locked(struct zd_chip *chip, u32 *values, const zd_addr_t *addr,
91 unsigned int count)
92{
93 int r;
94 int i;
95 zd_addr_t *a16 = (zd_addr_t *)NULL;
96 u16 *v16;
97 unsigned int count16;
98
99 if (count > USB_MAX_IOREAD32_COUNT)
100 return -EINVAL;
101
102 /* Allocate a single memory block for values and addresses. */
103 count16 = 2*count;
104 a16 = (zd_addr_t *)kmalloc(count16 * (sizeof(zd_addr_t) + sizeof(u16)),
105 GFP_NOFS);
106 if (!a16) {
107 dev_dbg_f(zd_chip_dev(chip),
108 "error ENOMEM in allocation of a16\n");
109 r = -ENOMEM;
110 goto out;
111 }
112 v16 = (u16 *)(a16 + count16);
113
114 for (i = 0; i < count; i++) {
115 int j = 2*i;
116 /* We read the high word always first. */
117 a16[j] = zd_inc_word(addr[i]);
118 a16[j+1] = addr[i];
119 }
120
121 r = zd_ioread16v_locked(chip, v16, a16, count16);
122 if (r) {
123 dev_dbg_f(zd_chip_dev(chip),
124 "error: zd_ioread16v_locked. Error number %d\n", r);
125 goto out;
126 }
127
128 for (i = 0; i < count; i++) {
129 int j = 2*i;
130 values[i] = (v16[j] << 16) | v16[j+1];
131 }
132
133out:
134 kfree((void *)a16);
135 return r;
136}
137
138int _zd_iowrite32v_locked(struct zd_chip *chip, const struct zd_ioreq32 *ioreqs,
139 unsigned int count)
140{
141 int i, j, r;
142 struct zd_ioreq16 *ioreqs16;
143 unsigned int count16;
144
145 ZD_ASSERT(mutex_is_locked(&chip->mutex));
146
147 if (count == 0)
148 return 0;
149 if (count > USB_MAX_IOWRITE32_COUNT)
150 return -EINVAL;
151
152 /* Allocate a single memory block for values and addresses. */
153 count16 = 2*count;
154 ioreqs16 = kmalloc(count16 * sizeof(struct zd_ioreq16), GFP_NOFS);
155 if (!ioreqs16) {
156 r = -ENOMEM;
157 dev_dbg_f(zd_chip_dev(chip),
158 "error %d in ioreqs16 allocation\n", r);
159 goto out;
160 }
161
162 for (i = 0; i < count; i++) {
163 j = 2*i;
164 /* We write the high word always first. */
165 ioreqs16[j].value = ioreqs[i].value >> 16;
166 ioreqs16[j].addr = zd_inc_word(ioreqs[i].addr);
167 ioreqs16[j+1].value = ioreqs[i].value;
168 ioreqs16[j+1].addr = ioreqs[i].addr;
169 }
170
171 r = zd_usb_iowrite16v(&chip->usb, ioreqs16, count16);
172#ifdef DEBUG
173 if (r) {
174 dev_dbg_f(zd_chip_dev(chip),
175 "error %d in zd_usb_write16v\n", r);
176 }
177#endif /* DEBUG */
178out:
179 kfree(ioreqs16);
180 return r;
181}
182
183int zd_iowrite16a_locked(struct zd_chip *chip,
184 const struct zd_ioreq16 *ioreqs, unsigned int count)
185{
186 int r;
187 unsigned int i, j, t, max;
188
189 ZD_ASSERT(mutex_is_locked(&chip->mutex));
190 for (i = 0; i < count; i += j + t) {
191 t = 0;
192 max = count-i;
193 if (max > USB_MAX_IOWRITE16_COUNT)
194 max = USB_MAX_IOWRITE16_COUNT;
195 for (j = 0; j < max; j++) {
196 if (!ioreqs[i+j].addr) {
197 t = 1;
198 break;
199 }
200 }
201
202 r = zd_usb_iowrite16v(&chip->usb, &ioreqs[i], j);
203 if (r) {
204 dev_dbg_f(zd_chip_dev(chip),
205 "error zd_usb_iowrite16v. Error number %d\n",
206 r);
207 return r;
208 }
209 }
210
211 return 0;
212}
213
214/* Writes a variable number of 32 bit registers. The functions will split
215 * that in several USB requests. A split can be forced by inserting an IO
216 * request with an zero address field.
217 */
218int zd_iowrite32a_locked(struct zd_chip *chip,
219 const struct zd_ioreq32 *ioreqs, unsigned int count)
220{
221 int r;
222 unsigned int i, j, t, max;
223
224 for (i = 0; i < count; i += j + t) {
225 t = 0;
226 max = count-i;
227 if (max > USB_MAX_IOWRITE32_COUNT)
228 max = USB_MAX_IOWRITE32_COUNT;
229 for (j = 0; j < max; j++) {
230 if (!ioreqs[i+j].addr) {
231 t = 1;
232 break;
233 }
234 }
235
236 r = _zd_iowrite32v_locked(chip, &ioreqs[i], j);
237 if (r) {
238 dev_dbg_f(zd_chip_dev(chip),
239 "error _zd_iowrite32v_locked."
240 " Error number %d\n", r);
241 return r;
242 }
243 }
244
245 return 0;
246}
247
248int zd_ioread16(struct zd_chip *chip, zd_addr_t addr, u16 *value)
249{
250 int r;
251
252 ZD_ASSERT(!mutex_is_locked(&chip->mutex));
253 mutex_lock(&chip->mutex);
254 r = zd_ioread16_locked(chip, value, addr);
255 mutex_unlock(&chip->mutex);
256 return r;
257}
258
259int zd_ioread32(struct zd_chip *chip, zd_addr_t addr, u32 *value)
260{
261 int r;
262
263 ZD_ASSERT(!mutex_is_locked(&chip->mutex));
264 mutex_lock(&chip->mutex);
265 r = zd_ioread32_locked(chip, value, addr);
266 mutex_unlock(&chip->mutex);
267 return r;
268}
269
270int zd_iowrite16(struct zd_chip *chip, zd_addr_t addr, u16 value)
271{
272 int r;
273
274 ZD_ASSERT(!mutex_is_locked(&chip->mutex));
275 mutex_lock(&chip->mutex);
276 r = zd_iowrite16_locked(chip, value, addr);
277 mutex_unlock(&chip->mutex);
278 return r;
279}
280
281int zd_iowrite32(struct zd_chip *chip, zd_addr_t addr, u32 value)
282{
283 int r;
284
285 ZD_ASSERT(!mutex_is_locked(&chip->mutex));
286 mutex_lock(&chip->mutex);
287 r = zd_iowrite32_locked(chip, value, addr);
288 mutex_unlock(&chip->mutex);
289 return r;
290}
291
292int zd_ioread32v(struct zd_chip *chip, const zd_addr_t *addresses,
293 u32 *values, unsigned int count)
294{
295 int r;
296
297 ZD_ASSERT(!mutex_is_locked(&chip->mutex));
298 mutex_lock(&chip->mutex);
299 r = zd_ioread32v_locked(chip, values, addresses, count);
300 mutex_unlock(&chip->mutex);
301 return r;
302}
303
304int zd_iowrite32a(struct zd_chip *chip, const struct zd_ioreq32 *ioreqs,
305 unsigned int count)
306{
307 int r;
308
309 ZD_ASSERT(!mutex_is_locked(&chip->mutex));
310 mutex_lock(&chip->mutex);
311 r = zd_iowrite32a_locked(chip, ioreqs, count);
312 mutex_unlock(&chip->mutex);
313 return r;
314}
315
316static int read_pod(struct zd_chip *chip, u8 *rf_type)
317{
318 int r;
319 u32 value;
320
321 ZD_ASSERT(mutex_is_locked(&chip->mutex));
322 r = zd_ioread32_locked(chip, &value, E2P_POD);
323 if (r)
324 goto error;
325 dev_dbg_f(zd_chip_dev(chip), "E2P_POD %#010x\n", value);
326
327 /* FIXME: AL2230 handling (Bit 7 in POD) */
328 *rf_type = value & 0x0f;
329 chip->pa_type = (value >> 16) & 0x0f;
330 chip->patch_cck_gain = (value >> 8) & 0x1;
331 chip->patch_cr157 = (value >> 13) & 0x1;
332 chip->patch_6m_band_edge = (value >> 21) & 0x1;
333
334 dev_dbg_f(zd_chip_dev(chip),
335 "RF %s %#01x PA type %#01x patch CCK %d patch CR157 %d "
336 "patch 6M %d\n",
337 zd_rf_name(*rf_type), *rf_type,
338 chip->pa_type, chip->patch_cck_gain,
339 chip->patch_cr157, chip->patch_6m_band_edge);
340 return 0;
341error:
342 *rf_type = 0;
343 chip->pa_type = 0;
344 chip->patch_cck_gain = 0;
345 chip->patch_cr157 = 0;
346 chip->patch_6m_band_edge = 0;
347 return r;
348}
349
350static int _read_mac_addr(struct zd_chip *chip, u8 *mac_addr,
351 const zd_addr_t *addr)
352{
353 int r;
354 u32 parts[2];
355
356 r = zd_ioread32v_locked(chip, parts, (const zd_addr_t *)addr, 2);
357 if (r) {
358 dev_dbg_f(zd_chip_dev(chip),
359 "error: couldn't read e2p macs. Error number %d\n", r);
360 return r;
361 }
362
363 mac_addr[0] = parts[0];
364 mac_addr[1] = parts[0] >> 8;
365 mac_addr[2] = parts[0] >> 16;
366 mac_addr[3] = parts[0] >> 24;
367 mac_addr[4] = parts[1];
368 mac_addr[5] = parts[1] >> 8;
369
370 return 0;
371}
372
373static int read_e2p_mac_addr(struct zd_chip *chip)
374{
375 static const zd_addr_t addr[2] = { E2P_MAC_ADDR_P1, E2P_MAC_ADDR_P2 };
376
377 ZD_ASSERT(mutex_is_locked(&chip->mutex));
378 return _read_mac_addr(chip, chip->e2p_mac, (const zd_addr_t *)addr);
379}
380
381/* MAC address: if custom mac addresses are to to be used CR_MAC_ADDR_P1 and
382 * CR_MAC_ADDR_P2 must be overwritten
383 */
384void zd_get_e2p_mac_addr(struct zd_chip *chip, u8 *mac_addr)
385{
386 mutex_lock(&chip->mutex);
387 memcpy(mac_addr, chip->e2p_mac, ETH_ALEN);
388 mutex_unlock(&chip->mutex);
389}
390
391static int read_mac_addr(struct zd_chip *chip, u8 *mac_addr)
392{
393 static const zd_addr_t addr[2] = { CR_MAC_ADDR_P1, CR_MAC_ADDR_P2 };
394 return _read_mac_addr(chip, mac_addr, (const zd_addr_t *)addr);
395}
396
397int zd_read_mac_addr(struct zd_chip *chip, u8 *mac_addr)
398{
399 int r;
400
401 dev_dbg_f(zd_chip_dev(chip), "\n");
402 mutex_lock(&chip->mutex);
403 r = read_mac_addr(chip, mac_addr);
404 mutex_unlock(&chip->mutex);
405 return r;
406}
407
408int zd_write_mac_addr(struct zd_chip *chip, const u8 *mac_addr)
409{
410 int r;
411 struct zd_ioreq32 reqs[2] = {
412 [0] = { .addr = CR_MAC_ADDR_P1 },
413 [1] = { .addr = CR_MAC_ADDR_P2 },
414 };
415
416 reqs[0].value = (mac_addr[3] << 24)
417 | (mac_addr[2] << 16)
418 | (mac_addr[1] << 8)
419 | mac_addr[0];
420 reqs[1].value = (mac_addr[5] << 8)
421 | mac_addr[4];
422
423 dev_dbg_f(zd_chip_dev(chip),
424 "mac addr " MAC_FMT "\n", MAC_ARG(mac_addr));
425
426 mutex_lock(&chip->mutex);
427 r = zd_iowrite32a_locked(chip, reqs, ARRAY_SIZE(reqs));
428#ifdef DEBUG
429 {
430 u8 tmp[ETH_ALEN];
431 read_mac_addr(chip, tmp);
432 }
433#endif /* DEBUG */
434 mutex_unlock(&chip->mutex);
435 return r;
436}
437
438int zd_read_regdomain(struct zd_chip *chip, u8 *regdomain)
439{
440 int r;
441 u32 value;
442
443 mutex_lock(&chip->mutex);
444 r = zd_ioread32_locked(chip, &value, E2P_SUBID);
445 mutex_unlock(&chip->mutex);
446 if (r)
447 return r;
448
449 *regdomain = value >> 16;
450 dev_dbg_f(zd_chip_dev(chip), "regdomain: %#04x\n", *regdomain);
451
452 return 0;
453}
454
455static int read_values(struct zd_chip *chip, u8 *values, size_t count,
456 zd_addr_t e2p_addr, u32 guard)
457{
458 int r;
459 int i;
460 u32 v;
461
462 ZD_ASSERT(mutex_is_locked(&chip->mutex));
463 for (i = 0;;) {
464 r = zd_ioread32_locked(chip, &v, e2p_addr+i/2);
465 if (r)
466 return r;
467 v -= guard;
468 if (i+4 < count) {
469 values[i++] = v;
470 values[i++] = v >> 8;
471 values[i++] = v >> 16;
472 values[i++] = v >> 24;
473 continue;
474 }
475 for (;i < count; i++)
476 values[i] = v >> (8*(i%3));
477 return 0;
478 }
479}
480
481static int read_pwr_cal_values(struct zd_chip *chip)
482{
483 return read_values(chip, chip->pwr_cal_values,
484 E2P_CHANNEL_COUNT, E2P_PWR_CAL_VALUE1,
485 0);
486}
487
488static int read_pwr_int_values(struct zd_chip *chip)
489{
490 return read_values(chip, chip->pwr_int_values,
491 E2P_CHANNEL_COUNT, E2P_PWR_INT_VALUE1,
492 E2P_PWR_INT_GUARD);
493}
494
495static int read_ofdm_cal_values(struct zd_chip *chip)
496{
497 int r;
498 int i;
499 static const zd_addr_t addresses[] = {
500 E2P_36M_CAL_VALUE1,
501 E2P_48M_CAL_VALUE1,
502 E2P_54M_CAL_VALUE1,
503 };
504
505 for (i = 0; i < 3; i++) {
506 r = read_values(chip, chip->ofdm_cal_values[i],
507 E2P_CHANNEL_COUNT, addresses[i], 0);
508 if (r)
509 return r;
510 }
511 return 0;
512}
513
514static int read_cal_int_tables(struct zd_chip *chip)
515{
516 int r;
517
518 r = read_pwr_cal_values(chip);
519 if (r)
520 return r;
521 r = read_pwr_int_values(chip);
522 if (r)
523 return r;
524 r = read_ofdm_cal_values(chip);
525 if (r)
526 return r;
527 return 0;
528}
529
530/* phy means physical registers */
531int zd_chip_lock_phy_regs(struct zd_chip *chip)
532{
533 int r;
534 u32 tmp;
535
536 ZD_ASSERT(mutex_is_locked(&chip->mutex));
537 r = zd_ioread32_locked(chip, &tmp, CR_REG1);
538 if (r) {
539 dev_err(zd_chip_dev(chip), "error ioread32(CR_REG1): %d\n", r);
540 return r;
541 }
542
543 dev_dbg_f(zd_chip_dev(chip),
544 "CR_REG1: 0x%02x -> 0x%02x\n", tmp, tmp & ~UNLOCK_PHY_REGS);
545 tmp &= ~UNLOCK_PHY_REGS;
546
547 r = zd_iowrite32_locked(chip, tmp, CR_REG1);
548 if (r)
549 dev_err(zd_chip_dev(chip), "error iowrite32(CR_REG1): %d\n", r);
550 return r;
551}
552
553int zd_chip_unlock_phy_regs(struct zd_chip *chip)
554{
555 int r;
556 u32 tmp;
557
558 ZD_ASSERT(mutex_is_locked(&chip->mutex));
559 r = zd_ioread32_locked(chip, &tmp, CR_REG1);
560 if (r) {
561 dev_err(zd_chip_dev(chip),
562 "error ioread32(CR_REG1): %d\n", r);
563 return r;
564 }
565
566 dev_dbg_f(zd_chip_dev(chip),
567 "CR_REG1: 0x%02x -> 0x%02x\n", tmp, tmp | UNLOCK_PHY_REGS);
568 tmp |= UNLOCK_PHY_REGS;
569
570 r = zd_iowrite32_locked(chip, tmp, CR_REG1);
571 if (r)
572 dev_err(zd_chip_dev(chip), "error iowrite32(CR_REG1): %d\n", r);
573 return r;
574}
575
576/* CR157 can be optionally patched by the EEPROM */
577static int patch_cr157(struct zd_chip *chip)
578{
579 int r;
580 u32 value;
581
582 if (!chip->patch_cr157)
583 return 0;
584
585 r = zd_ioread32_locked(chip, &value, E2P_PHY_REG);
586 if (r)
587 return r;
588
589 dev_dbg_f(zd_chip_dev(chip), "patching value %x\n", value >> 8);
590 return zd_iowrite32_locked(chip, value >> 8, CR157);
591}
592
593/*
594 * 6M band edge can be optionally overwritten for certain RF's
595 * Vendor driver says: for FCC regulation, enabled per HWFeature 6M band edge
596 * bit (for AL2230, AL2230S)
597 */
598static int patch_6m_band_edge(struct zd_chip *chip, int channel)
599{
600 struct zd_ioreq16 ioreqs[] = {
601 { CR128, 0x14 }, { CR129, 0x12 }, { CR130, 0x10 },
602 { CR47, 0x1e },
603 };
604
605 if (!chip->patch_6m_band_edge || !chip->rf.patch_6m_band_edge)
606 return 0;
607
608 /* FIXME: Channel 11 is not the edge for all regulatory domains. */
609 if (channel == 1 || channel == 11)
610 ioreqs[0].value = 0x12;
611
612 dev_dbg_f(zd_chip_dev(chip), "patching for channel %d\n", channel);
613 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
614}
615
616static int zd1211_hw_reset_phy(struct zd_chip *chip)
617{
618 static const struct zd_ioreq16 ioreqs[] = {
619 { CR0, 0x0a }, { CR1, 0x06 }, { CR2, 0x26 },
620 { CR3, 0x38 }, { CR4, 0x80 }, { CR9, 0xa0 },
621 { CR10, 0x81 }, { CR11, 0x00 }, { CR12, 0x7f },
622 { CR13, 0x8c }, { CR14, 0x80 }, { CR15, 0x3d },
623 { CR16, 0x20 }, { CR17, 0x1e }, { CR18, 0x0a },
624 { CR19, 0x48 }, { CR20, 0x0c }, { CR21, 0x0c },
625 { CR22, 0x23 }, { CR23, 0x90 }, { CR24, 0x14 },
626 { CR25, 0x40 }, { CR26, 0x10 }, { CR27, 0x19 },
627 { CR28, 0x7f }, { CR29, 0x80 }, { CR30, 0x4b },
628 { CR31, 0x60 }, { CR32, 0x43 }, { CR33, 0x08 },
629 { CR34, 0x06 }, { CR35, 0x0a }, { CR36, 0x00 },
630 { CR37, 0x00 }, { CR38, 0x38 }, { CR39, 0x0c },
631 { CR40, 0x84 }, { CR41, 0x2a }, { CR42, 0x80 },
632 { CR43, 0x10 }, { CR44, 0x12 }, { CR46, 0xff },
633 { CR47, 0x1E }, { CR48, 0x26 }, { CR49, 0x5b },
634 { CR64, 0xd0 }, { CR65, 0x04 }, { CR66, 0x58 },
635 { CR67, 0xc9 }, { CR68, 0x88 }, { CR69, 0x41 },
636 { CR70, 0x23 }, { CR71, 0x10 }, { CR72, 0xff },
637 { CR73, 0x32 }, { CR74, 0x30 }, { CR75, 0x65 },
638 { CR76, 0x41 }, { CR77, 0x1b }, { CR78, 0x30 },
639 { CR79, 0x68 }, { CR80, 0x64 }, { CR81, 0x64 },
640 { CR82, 0x00 }, { CR83, 0x00 }, { CR84, 0x00 },
641 { CR85, 0x02 }, { CR86, 0x00 }, { CR87, 0x00 },
642 { CR88, 0xff }, { CR89, 0xfc }, { CR90, 0x00 },
643 { CR91, 0x00 }, { CR92, 0x00 }, { CR93, 0x08 },
644 { CR94, 0x00 }, { CR95, 0x00 }, { CR96, 0xff },
645 { CR97, 0xe7 }, { CR98, 0x00 }, { CR99, 0x00 },
646 { CR100, 0x00 }, { CR101, 0xae }, { CR102, 0x02 },
647 { CR103, 0x00 }, { CR104, 0x03 }, { CR105, 0x65 },
648 { CR106, 0x04 }, { CR107, 0x00 }, { CR108, 0x0a },
649 { CR109, 0xaa }, { CR110, 0xaa }, { CR111, 0x25 },
650 { CR112, 0x25 }, { CR113, 0x00 }, { CR119, 0x1e },
651 { CR125, 0x90 }, { CR126, 0x00 }, { CR127, 0x00 },
652 { },
653 { CR5, 0x00 }, { CR6, 0x00 }, { CR7, 0x00 },
654 { CR8, 0x00 }, { CR9, 0x20 }, { CR12, 0xf0 },
655 { CR20, 0x0e }, { CR21, 0x0e }, { CR27, 0x10 },
656 { CR44, 0x33 }, { CR47, 0x1E }, { CR83, 0x24 },
657 { CR84, 0x04 }, { CR85, 0x00 }, { CR86, 0x0C },
658 { CR87, 0x12 }, { CR88, 0x0C }, { CR89, 0x00 },
659 { CR90, 0x10 }, { CR91, 0x08 }, { CR93, 0x00 },
660 { CR94, 0x01 }, { CR95, 0x00 }, { CR96, 0x50 },
661 { CR97, 0x37 }, { CR98, 0x35 }, { CR101, 0x13 },
662 { CR102, 0x27 }, { CR103, 0x27 }, { CR104, 0x18 },
663 { CR105, 0x12 }, { CR109, 0x27 }, { CR110, 0x27 },
664 { CR111, 0x27 }, { CR112, 0x27 }, { CR113, 0x27 },
665 { CR114, 0x27 }, { CR115, 0x26 }, { CR116, 0x24 },
666 { CR117, 0xfc }, { CR118, 0xfa }, { CR120, 0x4f },
667 { CR123, 0x27 }, { CR125, 0xaa }, { CR127, 0x03 },
668 { CR128, 0x14 }, { CR129, 0x12 }, { CR130, 0x10 },
669 { CR131, 0x0C }, { CR136, 0xdf }, { CR137, 0x40 },
670 { CR138, 0xa0 }, { CR139, 0xb0 }, { CR140, 0x99 },
671 { CR141, 0x82 }, { CR142, 0x54 }, { CR143, 0x1c },
672 { CR144, 0x6c }, { CR147, 0x07 }, { CR148, 0x4c },
673 { CR149, 0x50 }, { CR150, 0x0e }, { CR151, 0x18 },
674 { CR160, 0xfe }, { CR161, 0xee }, { CR162, 0xaa },
675 { CR163, 0xfa }, { CR164, 0xfa }, { CR165, 0xea },
676 { CR166, 0xbe }, { CR167, 0xbe }, { CR168, 0x6a },
677 { CR169, 0xba }, { CR170, 0xba }, { CR171, 0xba },
678 /* Note: CR204 must lead the CR203 */
679 { CR204, 0x7d },
680 { },
681 { CR203, 0x30 },
682 };
683
684 int r, t;
685
686 dev_dbg_f(zd_chip_dev(chip), "\n");
687
688 r = zd_chip_lock_phy_regs(chip);
689 if (r)
690 goto out;
691
692 r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
693 if (r)
694 goto unlock;
695
696 r = patch_cr157(chip);
697unlock:
698 t = zd_chip_unlock_phy_regs(chip);
699 if (t && !r)
700 r = t;
701out:
702 return r;
703}
704
705static int zd1211b_hw_reset_phy(struct zd_chip *chip)
706{
707 static const struct zd_ioreq16 ioreqs[] = {
708 { CR0, 0x14 }, { CR1, 0x06 }, { CR2, 0x26 },
709 { CR3, 0x38 }, { CR4, 0x80 }, { CR9, 0xe0 },
710 { CR10, 0x81 },
711 /* power control { { CR11, 1 << 6 }, */
712 { CR11, 0x00 },
713 { CR12, 0xf0 }, { CR13, 0x8c }, { CR14, 0x80 },
714 { CR15, 0x3d }, { CR16, 0x20 }, { CR17, 0x1e },
715 { CR18, 0x0a }, { CR19, 0x48 },
716 { CR20, 0x10 }, /* Org:0x0E, ComTrend:RalLink AP */
717 { CR21, 0x0e }, { CR22, 0x23 }, { CR23, 0x90 },
718 { CR24, 0x14 }, { CR25, 0x40 }, { CR26, 0x10 },
719 { CR27, 0x10 }, { CR28, 0x7f }, { CR29, 0x80 },
720 { CR30, 0x49 }, /* jointly decoder, no ASIC */
721 { CR31, 0x60 }, { CR32, 0x43 }, { CR33, 0x08 },
722 { CR34, 0x06 }, { CR35, 0x0a }, { CR36, 0x00 },
723 { CR37, 0x00 }, { CR38, 0x38 }, { CR39, 0x0c },
724 { CR40, 0x84 }, { CR41, 0x2a }, { CR42, 0x80 },
725 { CR43, 0x10 }, { CR44, 0x33 }, { CR46, 0xff },
726 { CR47, 0x1E }, { CR48, 0x26 }, { CR49, 0x5b },
727 { CR64, 0xd0 }, { CR65, 0x04 }, { CR66, 0x58 },
728 { CR67, 0xc9 }, { CR68, 0x88 }, { CR69, 0x41 },
729 { CR70, 0x23 }, { CR71, 0x10 }, { CR72, 0xff },
730 { CR73, 0x32 }, { CR74, 0x30 }, { CR75, 0x65 },
731 { CR76, 0x41 }, { CR77, 0x1b }, { CR78, 0x30 },
732 { CR79, 0xf0 }, { CR80, 0x64 }, { CR81, 0x64 },
733 { CR82, 0x00 }, { CR83, 0x24 }, { CR84, 0x04 },
734 { CR85, 0x00 }, { CR86, 0x0c }, { CR87, 0x12 },
735 { CR88, 0x0c }, { CR89, 0x00 }, { CR90, 0x58 },
736 { CR91, 0x04 }, { CR92, 0x00 }, { CR93, 0x00 },
737 { CR94, 0x01 },
738 { CR95, 0x20 }, /* ZD1211B */
739 { CR96, 0x50 }, { CR97, 0x37 }, { CR98, 0x35 },
740 { CR99, 0x00 }, { CR100, 0x01 }, { CR101, 0x13 },
741 { CR102, 0x27 }, { CR103, 0x27 }, { CR104, 0x18 },
742 { CR105, 0x12 }, { CR106, 0x04 }, { CR107, 0x00 },
743 { CR108, 0x0a }, { CR109, 0x27 }, { CR110, 0x27 },
744 { CR111, 0x27 }, { CR112, 0x27 }, { CR113, 0x27 },
745 { CR114, 0x27 }, { CR115, 0x26 }, { CR116, 0x24 },
746 { CR117, 0xfc }, { CR118, 0xfa }, { CR119, 0x1e },
747 { CR125, 0x90 }, { CR126, 0x00 }, { CR127, 0x00 },
748 { CR128, 0x14 }, { CR129, 0x12 }, { CR130, 0x10 },
749 { CR131, 0x0c }, { CR136, 0xdf }, { CR137, 0xa0 },
750 { CR138, 0xa8 }, { CR139, 0xb4 }, { CR140, 0x98 },
751 { CR141, 0x82 }, { CR142, 0x53 }, { CR143, 0x1c },
752 { CR144, 0x6c }, { CR147, 0x07 }, { CR148, 0x40 },
753 { CR149, 0x40 }, /* Org:0x50 ComTrend:RalLink AP */
754 { CR150, 0x14 }, /* Org:0x0E ComTrend:RalLink AP */
755 { CR151, 0x18 }, { CR159, 0x70 }, { CR160, 0xfe },
756 { CR161, 0xee }, { CR162, 0xaa }, { CR163, 0xfa },
757 { CR164, 0xfa }, { CR165, 0xea }, { CR166, 0xbe },
758 { CR167, 0xbe }, { CR168, 0x6a }, { CR169, 0xba },
759 { CR170, 0xba }, { CR171, 0xba },
760 /* Note: CR204 must lead the CR203 */
761 { CR204, 0x7d },
762 {},
763 { CR203, 0x30 },
764 };
765
766 int r, t;
767
768 dev_dbg_f(zd_chip_dev(chip), "\n");
769
770 r = zd_chip_lock_phy_regs(chip);
771 if (r)
772 goto out;
773
774 r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
775 if (r)
776 goto unlock;
777
778 r = patch_cr157(chip);
779unlock:
780 t = zd_chip_unlock_phy_regs(chip);
781 if (t && !r)
782 r = t;
783out:
784 return r;
785}
786
787static int hw_reset_phy(struct zd_chip *chip)
788{
789 return chip->is_zd1211b ? zd1211b_hw_reset_phy(chip) :
790 zd1211_hw_reset_phy(chip);
791}
792
793static int zd1211_hw_init_hmac(struct zd_chip *chip)
794{
795 static const struct zd_ioreq32 ioreqs[] = {
796 { CR_ACK_TIMEOUT_EXT, 0x20 },
797 { CR_ADDA_MBIAS_WARMTIME, 0x30000808 },
798 { CR_ZD1211_RETRY_MAX, 0x2 },
799 { CR_SNIFFER_ON, 0 },
800 { CR_RX_FILTER, STA_RX_FILTER },
801 { CR_GROUP_HASH_P1, 0x00 },
802 { CR_GROUP_HASH_P2, 0x80000000 },
803 { CR_REG1, 0xa4 },
804 { CR_ADDA_PWR_DWN, 0x7f },
805 { CR_BCN_PLCP_CFG, 0x00f00401 },
806 { CR_PHY_DELAY, 0x00 },
807 { CR_ACK_TIMEOUT_EXT, 0x80 },
808 { CR_ADDA_PWR_DWN, 0x00 },
809 { CR_ACK_TIME_80211, 0x100 },
810 { CR_IFS_VALUE, 0x547c032 },
811 { CR_RX_PE_DELAY, 0x70 },
812 { CR_PS_CTRL, 0x10000000 },
813 { CR_RTS_CTS_RATE, 0x02030203 },
814 { CR_RX_THRESHOLD, 0x000c0640 },
815 { CR_AFTER_PNP, 0x1 },
816 { CR_WEP_PROTECT, 0x114 },
817 };
818
819 int r;
820
821 dev_dbg_f(zd_chip_dev(chip), "\n");
822 ZD_ASSERT(mutex_is_locked(&chip->mutex));
823 r = zd_iowrite32a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
824#ifdef DEBUG
825 if (r) {
826 dev_err(zd_chip_dev(chip),
827 "error in zd_iowrite32a_locked. Error number %d\n", r);
828 }
829#endif /* DEBUG */
830 return r;
831}
832
833static int zd1211b_hw_init_hmac(struct zd_chip *chip)
834{
835 static const struct zd_ioreq32 ioreqs[] = {
836 { CR_ACK_TIMEOUT_EXT, 0x20 },
837 { CR_ADDA_MBIAS_WARMTIME, 0x30000808 },
838 { CR_ZD1211B_RETRY_MAX, 0x02020202 },
839 { CR_ZD1211B_TX_PWR_CTL4, 0x007f003f },
840 { CR_ZD1211B_TX_PWR_CTL3, 0x007f003f },
841 { CR_ZD1211B_TX_PWR_CTL2, 0x003f001f },
842 { CR_ZD1211B_TX_PWR_CTL1, 0x001f000f },
843 { CR_ZD1211B_AIFS_CTL1, 0x00280028 },
844 { CR_ZD1211B_AIFS_CTL2, 0x008C003C },
845 { CR_ZD1211B_TXOP, 0x01800824 },
846 { CR_SNIFFER_ON, 0 },
847 { CR_RX_FILTER, STA_RX_FILTER },
848 { CR_GROUP_HASH_P1, 0x00 },
849 { CR_GROUP_HASH_P2, 0x80000000 },
850 { CR_REG1, 0xa4 },
851 { CR_ADDA_PWR_DWN, 0x7f },
852 { CR_BCN_PLCP_CFG, 0x00f00401 },
853 { CR_PHY_DELAY, 0x00 },
854 { CR_ACK_TIMEOUT_EXT, 0x80 },
855 { CR_ADDA_PWR_DWN, 0x00 },
856 { CR_ACK_TIME_80211, 0x100 },
857 { CR_IFS_VALUE, 0x547c032 },
858 { CR_RX_PE_DELAY, 0x70 },
859 { CR_PS_CTRL, 0x10000000 },
860 { CR_RTS_CTS_RATE, 0x02030203 },
861 { CR_RX_THRESHOLD, 0x000c0640 },
862 { CR_AFTER_PNP, 0x1 },
863 { CR_WEP_PROTECT, 0x114 },
864 };
865
866 int r;
867
868 dev_dbg_f(zd_chip_dev(chip), "\n");
869 ZD_ASSERT(mutex_is_locked(&chip->mutex));
870 r = zd_iowrite32a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
871 if (r) {
872 dev_dbg_f(zd_chip_dev(chip),
873 "error in zd_iowrite32a_locked. Error number %d\n", r);
874 }
875 return r;
876}
877
878static int hw_init_hmac(struct zd_chip *chip)
879{
880 return chip->is_zd1211b ?
881 zd1211b_hw_init_hmac(chip) : zd1211_hw_init_hmac(chip);
882}
883
884struct aw_pt_bi {
885 u32 atim_wnd_period;
886 u32 pre_tbtt;
887 u32 beacon_interval;
888};
889
890static int get_aw_pt_bi(struct zd_chip *chip, struct aw_pt_bi *s)
891{
892 int r;
893 static const zd_addr_t aw_pt_bi_addr[] =
894 { CR_ATIM_WND_PERIOD, CR_PRE_TBTT, CR_BCN_INTERVAL };
895 u32 values[3];
896
897 r = zd_ioread32v_locked(chip, values, (const zd_addr_t *)aw_pt_bi_addr,
898 ARRAY_SIZE(aw_pt_bi_addr));
899 if (r) {
900 memset(s, 0, sizeof(*s));
901 return r;
902 }
903
904 s->atim_wnd_period = values[0];
905 s->pre_tbtt = values[1];
906 s->beacon_interval = values[2];
907 dev_dbg_f(zd_chip_dev(chip), "aw %u pt %u bi %u\n",
908 s->atim_wnd_period, s->pre_tbtt, s->beacon_interval);
909 return 0;
910}
911
912static int set_aw_pt_bi(struct zd_chip *chip, struct aw_pt_bi *s)
913{
914 struct zd_ioreq32 reqs[3];
915
916 if (s->beacon_interval <= 5)
917 s->beacon_interval = 5;
918 if (s->pre_tbtt < 4 || s->pre_tbtt >= s->beacon_interval)
919 s->pre_tbtt = s->beacon_interval - 1;
920 if (s->atim_wnd_period >= s->pre_tbtt)
921 s->atim_wnd_period = s->pre_tbtt - 1;
922
923 reqs[0].addr = CR_ATIM_WND_PERIOD;
924 reqs[0].value = s->atim_wnd_period;
925 reqs[1].addr = CR_PRE_TBTT;
926 reqs[1].value = s->pre_tbtt;
927 reqs[2].addr = CR_BCN_INTERVAL;
928 reqs[2].value = s->beacon_interval;
929
930 dev_dbg_f(zd_chip_dev(chip),
931 "aw %u pt %u bi %u\n", s->atim_wnd_period, s->pre_tbtt,
932 s->beacon_interval);
933 return zd_iowrite32a_locked(chip, reqs, ARRAY_SIZE(reqs));
934}
935
936
937static int set_beacon_interval(struct zd_chip *chip, u32 interval)
938{
939 int r;
940 struct aw_pt_bi s;
941
942 ZD_ASSERT(mutex_is_locked(&chip->mutex));
943 r = get_aw_pt_bi(chip, &s);
944 if (r)
945 return r;
946 s.beacon_interval = interval;
947 return set_aw_pt_bi(chip, &s);
948}
949
950int zd_set_beacon_interval(struct zd_chip *chip, u32 interval)
951{
952 int r;
953
954 mutex_lock(&chip->mutex);
955 r = set_beacon_interval(chip, interval);
956 mutex_unlock(&chip->mutex);
957 return r;
958}
959
960static int hw_init(struct zd_chip *chip)
961{
962 int r;
963
964 dev_dbg_f(zd_chip_dev(chip), "\n");
965 ZD_ASSERT(mutex_is_locked(&chip->mutex));
966 r = hw_reset_phy(chip);
967 if (r)
968 return r;
969
970 r = hw_init_hmac(chip);
971 if (r)
972 return r;
973 r = set_beacon_interval(chip, 100);
974 if (r)
975 return r;
976 return 0;
977}
978
979#ifdef DEBUG
980static int dump_cr(struct zd_chip *chip, const zd_addr_t addr,
981 const char *addr_string)
982{
983 int r;
984 u32 value;
985
986 r = zd_ioread32_locked(chip, &value, addr);
987 if (r) {
988 dev_dbg_f(zd_chip_dev(chip),
989 "error reading %s. Error number %d\n", addr_string, r);
990 return r;
991 }
992
993 dev_dbg_f(zd_chip_dev(chip), "%s %#010x\n",
994 addr_string, (unsigned int)value);
995 return 0;
996}
997
998static int test_init(struct zd_chip *chip)
999{
1000 int r;
1001
1002 r = dump_cr(chip, CR_AFTER_PNP, "CR_AFTER_PNP");
1003 if (r)
1004 return r;
1005 r = dump_cr(chip, CR_GPI_EN, "CR_GPI_EN");
1006 if (r)
1007 return r;
1008 return dump_cr(chip, CR_INTERRUPT, "CR_INTERRUPT");
1009}
1010
1011static void dump_fw_registers(struct zd_chip *chip)
1012{
1013 static const zd_addr_t addr[4] = {
1014 FW_FIRMWARE_VER, FW_USB_SPEED, FW_FIX_TX_RATE,
1015 FW_LINK_STATUS
1016 };
1017
1018 int r;
1019 u16 values[4];
1020
1021 r = zd_ioread16v_locked(chip, values, (const zd_addr_t*)addr,
1022 ARRAY_SIZE(addr));
1023 if (r) {
1024 dev_dbg_f(zd_chip_dev(chip), "error %d zd_ioread16v_locked\n",
1025 r);
1026 return;
1027 }
1028
1029 dev_dbg_f(zd_chip_dev(chip), "FW_FIRMWARE_VER %#06hx\n", values[0]);
1030 dev_dbg_f(zd_chip_dev(chip), "FW_USB_SPEED %#06hx\n", values[1]);
1031 dev_dbg_f(zd_chip_dev(chip), "FW_FIX_TX_RATE %#06hx\n", values[2]);
1032 dev_dbg_f(zd_chip_dev(chip), "FW_LINK_STATUS %#06hx\n", values[3]);
1033}
1034#endif /* DEBUG */
1035
1036static int print_fw_version(struct zd_chip *chip)
1037{
1038 int r;
1039 u16 version;
1040
1041 r = zd_ioread16_locked(chip, &version, FW_FIRMWARE_VER);
1042 if (r)
1043 return r;
1044
1045 dev_info(zd_chip_dev(chip),"firmware version %04hx\n", version);
1046 return 0;
1047}
1048
1049static int set_mandatory_rates(struct zd_chip *chip, enum ieee80211_std std)
1050{
1051 u32 rates;
1052 ZD_ASSERT(mutex_is_locked(&chip->mutex));
1053 /* This sets the mandatory rates, which only depend from the standard
1054 * that the device is supporting. Until further notice we should try
1055 * to support 802.11g also for full speed USB.
1056 */
1057 switch (std) {
1058 case IEEE80211B:
1059 rates = CR_RATE_1M|CR_RATE_2M|CR_RATE_5_5M|CR_RATE_11M;
1060 break;
1061 case IEEE80211G:
1062 rates = CR_RATE_1M|CR_RATE_2M|CR_RATE_5_5M|CR_RATE_11M|
1063 CR_RATE_6M|CR_RATE_12M|CR_RATE_24M;
1064 break;
1065 default:
1066 return -EINVAL;
1067 }
1068 return zd_iowrite32_locked(chip, rates, CR_MANDATORY_RATE_TBL);
1069}
1070
1071int zd_chip_enable_hwint(struct zd_chip *chip)
1072{
1073 int r;
1074
1075 mutex_lock(&chip->mutex);
1076 r = zd_iowrite32_locked(chip, HWINT_ENABLED, CR_INTERRUPT);
1077 mutex_unlock(&chip->mutex);
1078 return r;
1079}
1080
1081static int disable_hwint(struct zd_chip *chip)
1082{
1083 return zd_iowrite32_locked(chip, HWINT_DISABLED, CR_INTERRUPT);
1084}
1085
1086int zd_chip_disable_hwint(struct zd_chip *chip)
1087{
1088 int r;
1089
1090 mutex_lock(&chip->mutex);
1091 r = disable_hwint(chip);
1092 mutex_unlock(&chip->mutex);
1093 return r;
1094}
1095
1096int zd_chip_init_hw(struct zd_chip *chip, u8 device_type)
1097{
1098 int r;
1099 u8 rf_type;
1100
1101 dev_dbg_f(zd_chip_dev(chip), "\n");
1102
1103 mutex_lock(&chip->mutex);
1104 chip->is_zd1211b = (device_type == DEVICE_ZD1211B) != 0;
1105
1106#ifdef DEBUG
1107 r = test_init(chip);
1108 if (r)
1109 goto out;
1110#endif
1111 r = zd_iowrite32_locked(chip, 1, CR_AFTER_PNP);
1112 if (r)
1113 goto out;
1114
1115 r = zd_usb_init_hw(&chip->usb);
1116 if (r)
1117 goto out;
1118
1119 /* GPI is always disabled, also in the other driver.
1120 */
1121 r = zd_iowrite32_locked(chip, 0, CR_GPI_EN);
1122 if (r)
1123 goto out;
1124 r = zd_iowrite32_locked(chip, CWIN_SIZE, CR_CWMIN_CWMAX);
1125 if (r)
1126 goto out;
1127 /* Currently we support IEEE 802.11g for full and high speed USB.
1128 * It might be discussed, whether we should suppport pure b mode for
1129 * full speed USB.
1130 */
1131 r = set_mandatory_rates(chip, IEEE80211G);
1132 if (r)
1133 goto out;
1134 /* Disabling interrupts is certainly a smart thing here.
1135 */
1136 r = disable_hwint(chip);
1137 if (r)
1138 goto out;
1139 r = read_pod(chip, &rf_type);
1140 if (r)
1141 goto out;
1142 r = hw_init(chip);
1143 if (r)
1144 goto out;
1145 r = zd_rf_init_hw(&chip->rf, rf_type);
1146 if (r)
1147 goto out;
1148
1149 r = print_fw_version(chip);
1150 if (r)
1151 goto out;
1152
1153#ifdef DEBUG
1154 dump_fw_registers(chip);
1155 r = test_init(chip);
1156 if (r)
1157 goto out;
1158#endif /* DEBUG */
1159
1160 r = read_e2p_mac_addr(chip);
1161 if (r)
1162 goto out;
1163
1164 r = read_cal_int_tables(chip);
1165 if (r)
1166 goto out;
1167
1168 print_id(chip);
1169out:
1170 mutex_unlock(&chip->mutex);
1171 return r;
1172}
1173
1174static int update_pwr_int(struct zd_chip *chip, u8 channel)
1175{
1176 u8 value = chip->pwr_int_values[channel - 1];
1177 dev_dbg_f(zd_chip_dev(chip), "channel %d pwr_int %#04x\n",
1178 channel, value);
1179 return zd_iowrite32_locked(chip, value, CR31);
1180}
1181
1182static int update_pwr_cal(struct zd_chip *chip, u8 channel)
1183{
1184 u8 value = chip->pwr_cal_values[channel-1];
1185 dev_dbg_f(zd_chip_dev(chip), "channel %d pwr_cal %#04x\n",
1186 channel, value);
1187 return zd_iowrite32_locked(chip, value, CR68);
1188}
1189
1190static int update_ofdm_cal(struct zd_chip *chip, u8 channel)
1191{
1192 struct zd_ioreq32 ioreqs[3];
1193
1194 ioreqs[0].addr = CR67;
1195 ioreqs[0].value = chip->ofdm_cal_values[OFDM_36M_INDEX][channel-1];
1196 ioreqs[1].addr = CR66;
1197 ioreqs[1].value = chip->ofdm_cal_values[OFDM_48M_INDEX][channel-1];
1198 ioreqs[2].addr = CR65;
1199 ioreqs[2].value = chip->ofdm_cal_values[OFDM_54M_INDEX][channel-1];
1200
1201 dev_dbg_f(zd_chip_dev(chip),
1202 "channel %d ofdm_cal 36M %#04x 48M %#04x 54M %#04x\n",
1203 channel, ioreqs[0].value, ioreqs[1].value, ioreqs[2].value);
1204 return zd_iowrite32a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
1205}
1206
1207static int update_channel_integration_and_calibration(struct zd_chip *chip,
1208 u8 channel)
1209{
1210 int r;
1211
1212 r = update_pwr_int(chip, channel);
1213 if (r)
1214 return r;
1215 if (chip->is_zd1211b) {
1216 static const struct zd_ioreq32 ioreqs[] = {
1217 { CR69, 0x28 },
1218 {},
1219 { CR69, 0x2a },
1220 };
1221
1222 r = update_ofdm_cal(chip, channel);
1223 if (r)
1224 return r;
1225 r = update_pwr_cal(chip, channel);
1226 if (r)
1227 return r;
1228 r = zd_iowrite32a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
1229 if (r)
1230 return r;
1231 }
1232
1233 return 0;
1234}
1235
1236/* The CCK baseband gain can be optionally patched by the EEPROM */
1237static int patch_cck_gain(struct zd_chip *chip)
1238{
1239 int r;
1240 u32 value;
1241
1242 if (!chip->patch_cck_gain)
1243 return 0;
1244
1245 ZD_ASSERT(mutex_is_locked(&chip->mutex));
1246 r = zd_ioread32_locked(chip, &value, E2P_PHY_REG);
1247 if (r)
1248 return r;
1249 dev_dbg_f(zd_chip_dev(chip), "patching value %x\n", value & 0xff);
1250 return zd_iowrite32_locked(chip, value & 0xff, CR47);
1251}
1252
1253int zd_chip_set_channel(struct zd_chip *chip, u8 channel)
1254{
1255 int r, t;
1256
1257 mutex_lock(&chip->mutex);
1258 r = zd_chip_lock_phy_regs(chip);
1259 if (r)
1260 goto out;
1261 r = zd_rf_set_channel(&chip->rf, channel);
1262 if (r)
1263 goto unlock;
1264 r = update_channel_integration_and_calibration(chip, channel);
1265 if (r)
1266 goto unlock;
1267 r = patch_cck_gain(chip);
1268 if (r)
1269 goto unlock;
1270 r = patch_6m_band_edge(chip, channel);
1271 if (r)
1272 goto unlock;
1273 r = zd_iowrite32_locked(chip, 0, CR_CONFIG_PHILIPS);
1274unlock:
1275 t = zd_chip_unlock_phy_regs(chip);
1276 if (t && !r)
1277 r = t;
1278out:
1279 mutex_unlock(&chip->mutex);
1280 return r;
1281}
1282
1283u8 zd_chip_get_channel(struct zd_chip *chip)
1284{
1285 u8 channel;
1286
1287 mutex_lock(&chip->mutex);
1288 channel = chip->rf.channel;
1289 mutex_unlock(&chip->mutex);
1290 return channel;
1291}
1292
1293static u16 led_mask(int led)
1294{
1295 switch (led) {
1296 case 1:
1297 return LED1;
1298 case 2:
1299 return LED2;
1300 default:
1301 return 0;
1302 }
1303}
1304
1305static int read_led_reg(struct zd_chip *chip, u16 *status)
1306{
1307 ZD_ASSERT(mutex_is_locked(&chip->mutex));
1308 return zd_ioread16_locked(chip, status, CR_LED);
1309}
1310
1311static int write_led_reg(struct zd_chip *chip, u16 status)
1312{
1313 ZD_ASSERT(mutex_is_locked(&chip->mutex));
1314 return zd_iowrite16_locked(chip, status, CR_LED);
1315}
1316
1317int zd_chip_led_status(struct zd_chip *chip, int led, enum led_status status)
1318{
1319 int r, ret;
1320 u16 mask = led_mask(led);
1321 u16 reg;
1322
1323 if (!mask)
1324 return -EINVAL;
1325 mutex_lock(&chip->mutex);
1326 r = read_led_reg(chip, &reg);
1327 if (r)
1328 return r;
1329 switch (status) {
1330 case LED_STATUS:
1331 return (reg & mask) ? LED_ON : LED_OFF;
1332 case LED_OFF:
1333 reg &= ~mask;
1334 ret = LED_OFF;
1335 break;
1336 case LED_FLIP:
1337 reg ^= mask;
1338 ret = (reg&mask) ? LED_ON : LED_OFF;
1339 break;
1340 case LED_ON:
1341 reg |= mask;
1342 ret = LED_ON;
1343 break;
1344 default:
1345 return -EINVAL;
1346 }
1347 r = write_led_reg(chip, reg);
1348 if (r) {
1349 ret = r;
1350 goto out;
1351 }
1352out:
1353 mutex_unlock(&chip->mutex);
1354 return r;
1355}
1356
1357int zd_chip_led_flip(struct zd_chip *chip, int led,
1358 const unsigned int *phases_msecs, unsigned int count)
1359{
1360 int i, r;
1361 enum led_status status;
1362
1363 r = zd_chip_led_status(chip, led, LED_STATUS);
1364 if (r)
1365 return r;
1366 status = r;
1367 for (i = 0; i < count; i++) {
1368 r = zd_chip_led_status(chip, led, LED_FLIP);
1369 if (r < 0)
1370 goto out;
1371 msleep(phases_msecs[i]);
1372 }
1373
1374out:
1375 zd_chip_led_status(chip, led, status);
1376 return r;
1377}
1378
1379int zd_chip_set_basic_rates(struct zd_chip *chip, u16 cr_rates)
1380{
1381 int r;
1382
1383 if (cr_rates & ~(CR_RATES_80211B|CR_RATES_80211G))
1384 return -EINVAL;
1385
1386 mutex_lock(&chip->mutex);
1387 r = zd_iowrite32_locked(chip, cr_rates, CR_BASIC_RATE_TBL);
1388 mutex_unlock(&chip->mutex);
1389 return r;
1390}
1391
1392static int ofdm_qual_db(u8 status_quality, u8 rate, unsigned int size)
1393{
1394 static const u16 constants[] = {
1395 715, 655, 585, 540, 470, 410, 360, 315,
1396 270, 235, 205, 175, 150, 125, 105, 85,
1397 65, 50, 40, 25, 15
1398 };
1399
1400 int i;
1401 u32 x;
1402
1403 /* It seems that their quality parameter is somehow per signal
1404 * and is now transferred per bit.
1405 */
1406 switch (rate) {
1407 case ZD_OFDM_RATE_6M:
1408 case ZD_OFDM_RATE_12M:
1409 case ZD_OFDM_RATE_24M:
1410 size *= 2;
1411 break;
1412 case ZD_OFDM_RATE_9M:
1413 case ZD_OFDM_RATE_18M:
1414 case ZD_OFDM_RATE_36M:
1415 case ZD_OFDM_RATE_54M:
1416 size *= 4;
1417 size /= 3;
1418 break;
1419 case ZD_OFDM_RATE_48M:
1420 size *= 3;
1421 size /= 2;
1422 break;
1423 default:
1424 return -EINVAL;
1425 }
1426
1427 x = (10000 * status_quality)/size;
1428 for (i = 0; i < ARRAY_SIZE(constants); i++) {
1429 if (x > constants[i])
1430 break;
1431 }
1432
1433 switch (rate) {
1434 case ZD_OFDM_RATE_6M:
1435 case ZD_OFDM_RATE_9M:
1436 i += 3;
1437 break;
1438 case ZD_OFDM_RATE_12M:
1439 case ZD_OFDM_RATE_18M:
1440 i += 5;
1441 break;
1442 case ZD_OFDM_RATE_24M:
1443 case ZD_OFDM_RATE_36M:
1444 i += 9;
1445 break;
1446 case ZD_OFDM_RATE_48M:
1447 case ZD_OFDM_RATE_54M:
1448 i += 15;
1449 break;
1450 default:
1451 return -EINVAL;
1452 }
1453
1454 return i;
1455}
1456
1457static int ofdm_qual_percent(u8 status_quality, u8 rate, unsigned int size)
1458{
1459 int r;
1460
1461 r = ofdm_qual_db(status_quality, rate, size);
1462 ZD_ASSERT(r >= 0);
1463 if (r < 0)
1464 r = 0;
1465
1466 r = (r * 100)/29;
1467 return r <= 100 ? r : 100;
1468}
1469
1470static unsigned int log10times100(unsigned int x)
1471{
1472 static const u8 log10[] = {
1473 0,
1474 0, 30, 47, 60, 69, 77, 84, 90, 95, 100,
1475 104, 107, 111, 114, 117, 120, 123, 125, 127, 130,
1476 132, 134, 136, 138, 139, 141, 143, 144, 146, 147,
1477 149, 150, 151, 153, 154, 155, 156, 157, 159, 160,
1478 161, 162, 163, 164, 165, 166, 167, 168, 169, 169,
1479 170, 171, 172, 173, 174, 174, 175, 176, 177, 177,
1480 178, 179, 179, 180, 181, 181, 182, 183, 183, 184,
1481 185, 185, 186, 186, 187, 188, 188, 189, 189, 190,
1482 190, 191, 191, 192, 192, 193, 193, 194, 194, 195,
1483 195, 196, 196, 197, 197, 198, 198, 199, 199, 200,
1484 200, 200, 201, 201, 202, 202, 202, 203, 203, 204,
1485 204, 204, 205, 205, 206, 206, 206, 207, 207, 207,
1486 208, 208, 208, 209, 209, 210, 210, 210, 211, 211,
1487 211, 212, 212, 212, 213, 213, 213, 213, 214, 214,
1488 214, 215, 215, 215, 216, 216, 216, 217, 217, 217,
1489 217, 218, 218, 218, 219, 219, 219, 219, 220, 220,
1490 220, 220, 221, 221, 221, 222, 222, 222, 222, 223,
1491 223, 223, 223, 224, 224, 224, 224,
1492 };
1493
1494 return x < ARRAY_SIZE(log10) ? log10[x] : 225;
1495}
1496
1497enum {
1498 MAX_CCK_EVM_DB = 45,
1499};
1500
1501static int cck_evm_db(u8 status_quality)
1502{
1503 return (20 * log10times100(status_quality)) / 100;
1504}
1505
1506static int cck_snr_db(u8 status_quality)
1507{
1508 int r = MAX_CCK_EVM_DB - cck_evm_db(status_quality);
1509 ZD_ASSERT(r >= 0);
1510 return r;
1511}
1512
1513static int cck_qual_percent(u8 status_quality)
1514{
1515 int r;
1516
1517 r = cck_snr_db(status_quality);
1518 r = (100*r)/17;
1519 return r <= 100 ? r : 100;
1520}
1521
1522u8 zd_rx_qual_percent(const void *rx_frame, unsigned int size,
1523 const struct rx_status *status)
1524{
1525 return (status->frame_status&ZD_RX_OFDM) ?
1526 ofdm_qual_percent(status->signal_quality_ofdm,
1527 zd_ofdm_plcp_header_rate(rx_frame),
1528 size) :
1529 cck_qual_percent(status->signal_quality_cck);
1530}
1531
1532u8 zd_rx_strength_percent(u8 rssi)
1533{
1534 int r = (rssi*100) / 41;
1535 if (r > 100)
1536 r = 100;
1537 return (u8) r;
1538}
1539
1540u16 zd_rx_rate(const void *rx_frame, const struct rx_status *status)
1541{
1542 static const u16 ofdm_rates[] = {
1543 [ZD_OFDM_RATE_6M] = 60,
1544 [ZD_OFDM_RATE_9M] = 90,
1545 [ZD_OFDM_RATE_12M] = 120,
1546 [ZD_OFDM_RATE_18M] = 180,
1547 [ZD_OFDM_RATE_24M] = 240,
1548 [ZD_OFDM_RATE_36M] = 360,
1549 [ZD_OFDM_RATE_48M] = 480,
1550 [ZD_OFDM_RATE_54M] = 540,
1551 };
1552 u16 rate;
1553 if (status->frame_status & ZD_RX_OFDM) {
1554 u8 ofdm_rate = zd_ofdm_plcp_header_rate(rx_frame);
1555 rate = ofdm_rates[ofdm_rate & 0xf];
1556 } else {
1557 u8 cck_rate = zd_cck_plcp_header_rate(rx_frame);
1558 switch (cck_rate) {
1559 case ZD_CCK_SIGNAL_1M:
1560 rate = 10;
1561 break;
1562 case ZD_CCK_SIGNAL_2M:
1563 rate = 20;
1564 break;
1565 case ZD_CCK_SIGNAL_5M5:
1566 rate = 55;
1567 break;
1568 case ZD_CCK_SIGNAL_11M:
1569 rate = 110;
1570 break;
1571 default:
1572 rate = 0;
1573 }
1574 }
1575
1576 return rate;
1577}
1578
1579int zd_chip_switch_radio_on(struct zd_chip *chip)
1580{
1581 int r;
1582
1583 mutex_lock(&chip->mutex);
1584 r = zd_switch_radio_on(&chip->rf);
1585 mutex_unlock(&chip->mutex);
1586 return r;
1587}
1588
1589int zd_chip_switch_radio_off(struct zd_chip *chip)
1590{
1591 int r;
1592
1593 mutex_lock(&chip->mutex);
1594 r = zd_switch_radio_off(&chip->rf);
1595 mutex_unlock(&chip->mutex);
1596 return r;
1597}
1598
1599int zd_chip_enable_int(struct zd_chip *chip)
1600{
1601 int r;
1602
1603 mutex_lock(&chip->mutex);
1604 r = zd_usb_enable_int(&chip->usb);
1605 mutex_unlock(&chip->mutex);
1606 return r;
1607}
1608
1609void zd_chip_disable_int(struct zd_chip *chip)
1610{
1611 mutex_lock(&chip->mutex);
1612 zd_usb_disable_int(&chip->usb);
1613 mutex_unlock(&chip->mutex);
1614}
1615
1616int zd_chip_enable_rx(struct zd_chip *chip)
1617{
1618 int r;
1619
1620 mutex_lock(&chip->mutex);
1621 r = zd_usb_enable_rx(&chip->usb);
1622 mutex_unlock(&chip->mutex);
1623 return r;
1624}
1625
1626void zd_chip_disable_rx(struct zd_chip *chip)
1627{
1628 mutex_lock(&chip->mutex);
1629 zd_usb_disable_rx(&chip->usb);
1630 mutex_unlock(&chip->mutex);
1631}
1632
1633int zd_rfwritev_locked(struct zd_chip *chip,
1634 const u32* values, unsigned int count, u8 bits)
1635{
1636 int r;
1637 unsigned int i;
1638
1639 for (i = 0; i < count; i++) {
1640 r = zd_rfwrite_locked(chip, values[i], bits);
1641 if (r)
1642 return r;
1643 }
1644
1645 return 0;
1646}
diff --git a/drivers/net/wireless/zd1211rw/zd_chip.h b/drivers/net/wireless/zd1211rw/zd_chip.h
new file mode 100644
index 000000000000..069d2b467339
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_chip.h
@@ -0,0 +1,827 @@
1/* zd_chip.h
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#ifndef _ZD_CHIP_H
19#define _ZD_CHIP_H
20
21#include "zd_types.h"
22#include "zd_rf.h"
23#include "zd_usb.h"
24
25/* Header for the Media Access Controller (MAC) and the Baseband Processor
26 * (BBP). It appears that the ZD1211 wraps the old ZD1205 with USB glue and
27 * adds a processor for handling the USB protocol.
28 */
29
30/* 8-bit hardware registers */
31#define CR0 CTL_REG(0x0000)
32#define CR1 CTL_REG(0x0004)
33#define CR2 CTL_REG(0x0008)
34#define CR3 CTL_REG(0x000C)
35
36#define CR5 CTL_REG(0x0010)
37/* bit 5: if set short preamble used
38 * bit 6: filter band - Japan channel 14 on, else off
39 */
40#define CR6 CTL_REG(0x0014)
41#define CR7 CTL_REG(0x0018)
42#define CR8 CTL_REG(0x001C)
43
44#define CR4 CTL_REG(0x0020)
45
46#define CR9 CTL_REG(0x0024)
47/* bit 2: antenna switch (together with CR10) */
48#define CR10 CTL_REG(0x0028)
49/* bit 1: antenna switch (together with CR9)
50 * RF2959 controls with CR11 radion on and off
51 */
52#define CR11 CTL_REG(0x002C)
53/* bit 6: TX power control for OFDM
54 * RF2959 controls with CR10 radio on and off
55 */
56#define CR12 CTL_REG(0x0030)
57#define CR13 CTL_REG(0x0034)
58#define CR14 CTL_REG(0x0038)
59#define CR15 CTL_REG(0x003C)
60#define CR16 CTL_REG(0x0040)
61#define CR17 CTL_REG(0x0044)
62#define CR18 CTL_REG(0x0048)
63#define CR19 CTL_REG(0x004C)
64#define CR20 CTL_REG(0x0050)
65#define CR21 CTL_REG(0x0054)
66#define CR22 CTL_REG(0x0058)
67#define CR23 CTL_REG(0x005C)
68#define CR24 CTL_REG(0x0060) /* CCA threshold */
69#define CR25 CTL_REG(0x0064)
70#define CR26 CTL_REG(0x0068)
71#define CR27 CTL_REG(0x006C)
72#define CR28 CTL_REG(0x0070)
73#define CR29 CTL_REG(0x0074)
74#define CR30 CTL_REG(0x0078)
75#define CR31 CTL_REG(0x007C) /* TX power control for RF in CCK mode */
76#define CR32 CTL_REG(0x0080)
77#define CR33 CTL_REG(0x0084)
78#define CR34 CTL_REG(0x0088)
79#define CR35 CTL_REG(0x008C)
80#define CR36 CTL_REG(0x0090)
81#define CR37 CTL_REG(0x0094)
82#define CR38 CTL_REG(0x0098)
83#define CR39 CTL_REG(0x009C)
84#define CR40 CTL_REG(0x00A0)
85#define CR41 CTL_REG(0x00A4)
86#define CR42 CTL_REG(0x00A8)
87#define CR43 CTL_REG(0x00AC)
88#define CR44 CTL_REG(0x00B0)
89#define CR45 CTL_REG(0x00B4)
90#define CR46 CTL_REG(0x00B8)
91#define CR47 CTL_REG(0x00BC) /* CCK baseband gain
92 * (patch value might be in EEPROM)
93 */
94#define CR48 CTL_REG(0x00C0)
95#define CR49 CTL_REG(0x00C4)
96#define CR50 CTL_REG(0x00C8)
97#define CR51 CTL_REG(0x00CC) /* TX power control for RF in 6-36M modes */
98#define CR52 CTL_REG(0x00D0) /* TX power control for RF in 48M mode */
99#define CR53 CTL_REG(0x00D4) /* TX power control for RF in 54M mode */
100#define CR54 CTL_REG(0x00D8)
101#define CR55 CTL_REG(0x00DC)
102#define CR56 CTL_REG(0x00E0)
103#define CR57 CTL_REG(0x00E4)
104#define CR58 CTL_REG(0x00E8)
105#define CR59 CTL_REG(0x00EC)
106#define CR60 CTL_REG(0x00F0)
107#define CR61 CTL_REG(0x00F4)
108#define CR62 CTL_REG(0x00F8)
109#define CR63 CTL_REG(0x00FC)
110#define CR64 CTL_REG(0x0100)
111#define CR65 CTL_REG(0x0104) /* OFDM 54M calibration */
112#define CR66 CTL_REG(0x0108) /* OFDM 48M calibration */
113#define CR67 CTL_REG(0x010C) /* OFDM 36M calibration */
114#define CR68 CTL_REG(0x0110) /* CCK calibration */
115#define CR69 CTL_REG(0x0114)
116#define CR70 CTL_REG(0x0118)
117#define CR71 CTL_REG(0x011C)
118#define CR72 CTL_REG(0x0120)
119#define CR73 CTL_REG(0x0124)
120#define CR74 CTL_REG(0x0128)
121#define CR75 CTL_REG(0x012C)
122#define CR76 CTL_REG(0x0130)
123#define CR77 CTL_REG(0x0134)
124#define CR78 CTL_REG(0x0138)
125#define CR79 CTL_REG(0x013C)
126#define CR80 CTL_REG(0x0140)
127#define CR81 CTL_REG(0x0144)
128#define CR82 CTL_REG(0x0148)
129#define CR83 CTL_REG(0x014C)
130#define CR84 CTL_REG(0x0150)
131#define CR85 CTL_REG(0x0154)
132#define CR86 CTL_REG(0x0158)
133#define CR87 CTL_REG(0x015C)
134#define CR88 CTL_REG(0x0160)
135#define CR89 CTL_REG(0x0164)
136#define CR90 CTL_REG(0x0168)
137#define CR91 CTL_REG(0x016C)
138#define CR92 CTL_REG(0x0170)
139#define CR93 CTL_REG(0x0174)
140#define CR94 CTL_REG(0x0178)
141#define CR95 CTL_REG(0x017C)
142#define CR96 CTL_REG(0x0180)
143#define CR97 CTL_REG(0x0184)
144#define CR98 CTL_REG(0x0188)
145#define CR99 CTL_REG(0x018C)
146#define CR100 CTL_REG(0x0190)
147#define CR101 CTL_REG(0x0194)
148#define CR102 CTL_REG(0x0198)
149#define CR103 CTL_REG(0x019C)
150#define CR104 CTL_REG(0x01A0)
151#define CR105 CTL_REG(0x01A4)
152#define CR106 CTL_REG(0x01A8)
153#define CR107 CTL_REG(0x01AC)
154#define CR108 CTL_REG(0x01B0)
155#define CR109 CTL_REG(0x01B4)
156#define CR110 CTL_REG(0x01B8)
157#define CR111 CTL_REG(0x01BC)
158#define CR112 CTL_REG(0x01C0)
159#define CR113 CTL_REG(0x01C4)
160#define CR114 CTL_REG(0x01C8)
161#define CR115 CTL_REG(0x01CC)
162#define CR116 CTL_REG(0x01D0)
163#define CR117 CTL_REG(0x01D4)
164#define CR118 CTL_REG(0x01D8)
165#define CR119 CTL_REG(0x01DC)
166#define CR120 CTL_REG(0x01E0)
167#define CR121 CTL_REG(0x01E4)
168#define CR122 CTL_REG(0x01E8)
169#define CR123 CTL_REG(0x01EC)
170#define CR124 CTL_REG(0x01F0)
171#define CR125 CTL_REG(0x01F4)
172#define CR126 CTL_REG(0x01F8)
173#define CR127 CTL_REG(0x01FC)
174#define CR128 CTL_REG(0x0200)
175#define CR129 CTL_REG(0x0204)
176#define CR130 CTL_REG(0x0208)
177#define CR131 CTL_REG(0x020C)
178#define CR132 CTL_REG(0x0210)
179#define CR133 CTL_REG(0x0214)
180#define CR134 CTL_REG(0x0218)
181#define CR135 CTL_REG(0x021C)
182#define CR136 CTL_REG(0x0220)
183#define CR137 CTL_REG(0x0224)
184#define CR138 CTL_REG(0x0228)
185#define CR139 CTL_REG(0x022C)
186#define CR140 CTL_REG(0x0230)
187#define CR141 CTL_REG(0x0234)
188#define CR142 CTL_REG(0x0238)
189#define CR143 CTL_REG(0x023C)
190#define CR144 CTL_REG(0x0240)
191#define CR145 CTL_REG(0x0244)
192#define CR146 CTL_REG(0x0248)
193#define CR147 CTL_REG(0x024C)
194#define CR148 CTL_REG(0x0250)
195#define CR149 CTL_REG(0x0254)
196#define CR150 CTL_REG(0x0258)
197#define CR151 CTL_REG(0x025C)
198#define CR152 CTL_REG(0x0260)
199#define CR153 CTL_REG(0x0264)
200#define CR154 CTL_REG(0x0268)
201#define CR155 CTL_REG(0x026C)
202#define CR156 CTL_REG(0x0270)
203#define CR157 CTL_REG(0x0274)
204#define CR158 CTL_REG(0x0278)
205#define CR159 CTL_REG(0x027C)
206#define CR160 CTL_REG(0x0280)
207#define CR161 CTL_REG(0x0284)
208#define CR162 CTL_REG(0x0288)
209#define CR163 CTL_REG(0x028C)
210#define CR164 CTL_REG(0x0290)
211#define CR165 CTL_REG(0x0294)
212#define CR166 CTL_REG(0x0298)
213#define CR167 CTL_REG(0x029C)
214#define CR168 CTL_REG(0x02A0)
215#define CR169 CTL_REG(0x02A4)
216#define CR170 CTL_REG(0x02A8)
217#define CR171 CTL_REG(0x02AC)
218#define CR172 CTL_REG(0x02B0)
219#define CR173 CTL_REG(0x02B4)
220#define CR174 CTL_REG(0x02B8)
221#define CR175 CTL_REG(0x02BC)
222#define CR176 CTL_REG(0x02C0)
223#define CR177 CTL_REG(0x02C4)
224#define CR178 CTL_REG(0x02C8)
225#define CR179 CTL_REG(0x02CC)
226#define CR180 CTL_REG(0x02D0)
227#define CR181 CTL_REG(0x02D4)
228#define CR182 CTL_REG(0x02D8)
229#define CR183 CTL_REG(0x02DC)
230#define CR184 CTL_REG(0x02E0)
231#define CR185 CTL_REG(0x02E4)
232#define CR186 CTL_REG(0x02E8)
233#define CR187 CTL_REG(0x02EC)
234#define CR188 CTL_REG(0x02F0)
235#define CR189 CTL_REG(0x02F4)
236#define CR190 CTL_REG(0x02F8)
237#define CR191 CTL_REG(0x02FC)
238#define CR192 CTL_REG(0x0300)
239#define CR193 CTL_REG(0x0304)
240#define CR194 CTL_REG(0x0308)
241#define CR195 CTL_REG(0x030C)
242#define CR196 CTL_REG(0x0310)
243#define CR197 CTL_REG(0x0314)
244#define CR198 CTL_REG(0x0318)
245#define CR199 CTL_REG(0x031C)
246#define CR200 CTL_REG(0x0320)
247#define CR201 CTL_REG(0x0324)
248#define CR202 CTL_REG(0x0328)
249#define CR203 CTL_REG(0x032C) /* I2C bus template value & flash control */
250#define CR204 CTL_REG(0x0330)
251#define CR205 CTL_REG(0x0334)
252#define CR206 CTL_REG(0x0338)
253#define CR207 CTL_REG(0x033C)
254#define CR208 CTL_REG(0x0340)
255#define CR209 CTL_REG(0x0344)
256#define CR210 CTL_REG(0x0348)
257#define CR211 CTL_REG(0x034C)
258#define CR212 CTL_REG(0x0350)
259#define CR213 CTL_REG(0x0354)
260#define CR214 CTL_REG(0x0358)
261#define CR215 CTL_REG(0x035C)
262#define CR216 CTL_REG(0x0360)
263#define CR217 CTL_REG(0x0364)
264#define CR218 CTL_REG(0x0368)
265#define CR219 CTL_REG(0x036C)
266#define CR220 CTL_REG(0x0370)
267#define CR221 CTL_REG(0x0374)
268#define CR222 CTL_REG(0x0378)
269#define CR223 CTL_REG(0x037C)
270#define CR224 CTL_REG(0x0380)
271#define CR225 CTL_REG(0x0384)
272#define CR226 CTL_REG(0x0388)
273#define CR227 CTL_REG(0x038C)
274#define CR228 CTL_REG(0x0390)
275#define CR229 CTL_REG(0x0394)
276#define CR230 CTL_REG(0x0398)
277#define CR231 CTL_REG(0x039C)
278#define CR232 CTL_REG(0x03A0)
279#define CR233 CTL_REG(0x03A4)
280#define CR234 CTL_REG(0x03A8)
281#define CR235 CTL_REG(0x03AC)
282#define CR236 CTL_REG(0x03B0)
283
284#define CR240 CTL_REG(0x03C0)
285/* bit 7: host-controlled RF register writes
286 * CR241-CR245: for hardware controlled writing of RF bits, not needed for
287 * USB
288 */
289#define CR241 CTL_REG(0x03C4)
290#define CR242 CTL_REG(0x03C8)
291#define CR243 CTL_REG(0x03CC)
292#define CR244 CTL_REG(0x03D0)
293#define CR245 CTL_REG(0x03D4)
294
295#define CR251 CTL_REG(0x03EC) /* only used for activation and deactivation of
296 * Airoha RFs AL2230 and AL7230B
297 */
298#define CR252 CTL_REG(0x03F0)
299#define CR253 CTL_REG(0x03F4)
300#define CR254 CTL_REG(0x03F8)
301#define CR255 CTL_REG(0x03FC)
302
303#define CR_MAX_PHY_REG 255
304
305/* Taken from the ZYDAS driver, not all of them are relevant for the ZSD1211
306 * driver.
307 */
308
309#define CR_RF_IF_CLK CTL_REG(0x0400)
310#define CR_RF_IF_DATA CTL_REG(0x0404)
311#define CR_PE1_PE2 CTL_REG(0x0408)
312#define CR_PE2_DLY CTL_REG(0x040C)
313#define CR_LE1 CTL_REG(0x0410)
314#define CR_LE2 CTL_REG(0x0414)
315/* Seems to enable/disable GPI (General Purpose IO?) */
316#define CR_GPI_EN CTL_REG(0x0418)
317#define CR_RADIO_PD CTL_REG(0x042C)
318#define CR_RF2948_PD CTL_REG(0x042C)
319#define CR_ENABLE_PS_MANUAL_AGC CTL_REG(0x043C)
320#define CR_CONFIG_PHILIPS CTL_REG(0x0440)
321#define CR_SA2400_SER_AP CTL_REG(0x0444)
322#define CR_I2C_WRITE CTL_REG(0x0444)
323#define CR_SA2400_SER_RP CTL_REG(0x0448)
324#define CR_RADIO_PE CTL_REG(0x0458)
325#define CR_RST_BUS_MASTER CTL_REG(0x045C)
326#define CR_RFCFG CTL_REG(0x0464)
327#define CR_HSTSCHG CTL_REG(0x046C)
328#define CR_PHY_ON CTL_REG(0x0474)
329#define CR_RX_DELAY CTL_REG(0x0478)
330#define CR_RX_PE_DELAY CTL_REG(0x047C)
331#define CR_GPIO_1 CTL_REG(0x0490)
332#define CR_GPIO_2 CTL_REG(0x0494)
333#define CR_EncryBufMux CTL_REG(0x04A8)
334#define CR_PS_CTRL CTL_REG(0x0500)
335#define CR_ADDA_PWR_DWN CTL_REG(0x0504)
336#define CR_ADDA_MBIAS_WARMTIME CTL_REG(0x0508)
337#define CR_MAC_PS_STATE CTL_REG(0x050C)
338
339#define CR_INTERRUPT CTL_REG(0x0510)
340#define INT_TX_COMPLETE 0x00000001
341#define INT_RX_COMPLETE 0x00000002
342#define INT_RETRY_FAIL 0x00000004
343#define INT_WAKEUP 0x00000008
344#define INT_DTIM_NOTIFY 0x00000020
345#define INT_CFG_NEXT_BCN 0x00000040
346#define INT_BUS_ABORT 0x00000080
347#define INT_TX_FIFO_READY 0x00000100
348#define INT_UART 0x00000200
349#define INT_TX_COMPLETE_EN 0x00010000
350#define INT_RX_COMPLETE_EN 0x00020000
351#define INT_RETRY_FAIL_EN 0x00040000
352#define INT_WAKEUP_EN 0x00080000
353#define INT_DTIM_NOTIFY_EN 0x00200000
354#define INT_CFG_NEXT_BCN_EN 0x00400000
355#define INT_BUS_ABORT_EN 0x00800000
356#define INT_TX_FIFO_READY_EN 0x01000000
357#define INT_UART_EN 0x02000000
358
359#define CR_TSF_LOW_PART CTL_REG(0x0514)
360#define CR_TSF_HIGH_PART CTL_REG(0x0518)
361
362/* Following three values are in time units (1024us)
363 * Following condition must be met:
364 * atim < tbtt < bcn
365 */
366#define CR_ATIM_WND_PERIOD CTL_REG(0x051C)
367#define CR_BCN_INTERVAL CTL_REG(0x0520)
368#define CR_PRE_TBTT CTL_REG(0x0524)
369/* in units of TU(1024us) */
370
371/* for UART support */
372#define CR_UART_RBR_THR_DLL CTL_REG(0x0540)
373#define CR_UART_DLM_IER CTL_REG(0x0544)
374#define CR_UART_IIR_FCR CTL_REG(0x0548)
375#define CR_UART_LCR CTL_REG(0x054c)
376#define CR_UART_MCR CTL_REG(0x0550)
377#define CR_UART_LSR CTL_REG(0x0554)
378#define CR_UART_MSR CTL_REG(0x0558)
379#define CR_UART_ECR CTL_REG(0x055c)
380#define CR_UART_STATUS CTL_REG(0x0560)
381
382#define CR_PCI_TX_ADDR_P1 CTL_REG(0x0600)
383#define CR_PCI_TX_AddR_P2 CTL_REG(0x0604)
384#define CR_PCI_RX_AddR_P1 CTL_REG(0x0608)
385#define CR_PCI_RX_AddR_P2 CTL_REG(0x060C)
386
387/* must be overwritten if custom MAC address will be used */
388#define CR_MAC_ADDR_P1 CTL_REG(0x0610)
389#define CR_MAC_ADDR_P2 CTL_REG(0x0614)
390#define CR_BSSID_P1 CTL_REG(0x0618)
391#define CR_BSSID_P2 CTL_REG(0x061C)
392#define CR_BCN_PLCP_CFG CTL_REG(0x0620)
393#define CR_GROUP_HASH_P1 CTL_REG(0x0624)
394#define CR_GROUP_HASH_P2 CTL_REG(0x0628)
395#define CR_RX_TIMEOUT CTL_REG(0x062C)
396
397/* Basic rates supported by the BSS. When producing ACK or CTS messages, the
398 * device will use a rate in this table that is less than or equal to the rate
399 * of the incoming frame which prompted the response */
400#define CR_BASIC_RATE_TBL CTL_REG(0x0630)
401#define CR_RATE_1M 0x0001 /* 802.11b */
402#define CR_RATE_2M 0x0002 /* 802.11b */
403#define CR_RATE_5_5M 0x0004 /* 802.11b */
404#define CR_RATE_11M 0x0008 /* 802.11b */
405#define CR_RATE_6M 0x0100 /* 802.11g */
406#define CR_RATE_9M 0x0200 /* 802.11g */
407#define CR_RATE_12M 0x0400 /* 802.11g */
408#define CR_RATE_18M 0x0800 /* 802.11g */
409#define CR_RATE_24M 0x1000 /* 802.11g */
410#define CR_RATE_36M 0x2000 /* 802.11g */
411#define CR_RATE_48M 0x4000 /* 802.11g */
412#define CR_RATE_54M 0x8000 /* 802.11g */
413#define CR_RATES_80211G 0xff00
414#define CR_RATES_80211B 0x000f
415
416/* Mandatory rates required in the BSS. When producing ACK or CTS messages, if
417 * the device could not find an appropriate rate in CR_BASIC_RATE_TBL, it will
418 * look for a rate in this table that is less than or equal to the rate of
419 * the incoming frame. */
420#define CR_MANDATORY_RATE_TBL CTL_REG(0x0634)
421#define CR_RTS_CTS_RATE CTL_REG(0x0638)
422
423#define CR_WEP_PROTECT CTL_REG(0x063C)
424#define CR_RX_THRESHOLD CTL_REG(0x0640)
425
426/* register for controlling the LEDS */
427#define CR_LED CTL_REG(0x0644)
428/* masks for controlling LEDs */
429#define LED1 0x0100
430#define LED2 0x0200
431
432/* Seems to indicate that the configuration is over.
433 */
434#define CR_AFTER_PNP CTL_REG(0x0648)
435#define CR_ACK_TIME_80211 CTL_REG(0x0658)
436
437#define CR_RX_OFFSET CTL_REG(0x065c)
438
439#define CR_PHY_DELAY CTL_REG(0x066C)
440#define CR_BCN_FIFO CTL_REG(0x0670)
441#define CR_SNIFFER_ON CTL_REG(0x0674)
442
443#define CR_ENCRYPTION_TYPE CTL_REG(0x0678)
444#define NO_WEP 0
445#define WEP64 1
446#define WEP128 5
447#define WEP256 6
448#define ENC_SNIFFER 8
449
450#define CR_ZD1211_RETRY_MAX CTL_REG(0x067C)
451
452#define CR_REG1 CTL_REG(0x0680)
453/* Setting the bit UNLOCK_PHY_REGS disallows the write access to physical
454 * registers, so one could argue it is a LOCK bit. But calling it
455 * LOCK_PHY_REGS makes it confusing.
456 */
457#define UNLOCK_PHY_REGS 0x0080
458
459#define CR_DEVICE_STATE CTL_REG(0x0684)
460#define CR_UNDERRUN_CNT CTL_REG(0x0688)
461
462#define CR_RX_FILTER CTL_REG(0x068c)
463#define RX_FILTER_ASSOC_RESPONSE 0x0002
464#define RX_FILTER_REASSOC_RESPONSE 0x0008
465#define RX_FILTER_PROBE_RESPONSE 0x0020
466#define RX_FILTER_BEACON 0x0100
467#define RX_FILTER_DISASSOC 0x0400
468#define RX_FILTER_AUTH 0x0800
469#define AP_RX_FILTER 0x0400feff
470#define STA_RX_FILTER 0x0000ffff
471
472/* Monitor mode sets filter to 0xfffff */
473
474#define CR_ACK_TIMEOUT_EXT CTL_REG(0x0690)
475#define CR_BCN_FIFO_SEMAPHORE CTL_REG(0x0694)
476#define CR_IFS_VALUE CTL_REG(0x0698)
477#define CR_RX_TIME_OUT CTL_REG(0x069C)
478#define CR_TOTAL_RX_FRM CTL_REG(0x06A0)
479#define CR_CRC32_CNT CTL_REG(0x06A4)
480#define CR_CRC16_CNT CTL_REG(0x06A8)
481#define CR_DECRYPTION_ERR_UNI CTL_REG(0x06AC)
482#define CR_RX_FIFO_OVERRUN CTL_REG(0x06B0)
483
484#define CR_DECRYPTION_ERR_MUL CTL_REG(0x06BC)
485
486#define CR_NAV_CNT CTL_REG(0x06C4)
487#define CR_NAV_CCA CTL_REG(0x06C8)
488#define CR_RETRY_CNT CTL_REG(0x06CC)
489
490#define CR_READ_TCB_ADDR CTL_REG(0x06E8)
491#define CR_READ_RFD_ADDR CTL_REG(0x06EC)
492#define CR_CWMIN_CWMAX CTL_REG(0x06F0)
493#define CR_TOTAL_TX_FRM CTL_REG(0x06F4)
494
495/* CAM: Continuous Access Mode (power management) */
496#define CR_CAM_MODE CTL_REG(0x0700)
497#define CR_CAM_ROLL_TB_LOW CTL_REG(0x0704)
498#define CR_CAM_ROLL_TB_HIGH CTL_REG(0x0708)
499#define CR_CAM_ADDRESS CTL_REG(0x070C)
500#define CR_CAM_DATA CTL_REG(0x0710)
501
502#define CR_ROMDIR CTL_REG(0x0714)
503
504#define CR_DECRY_ERR_FLG_LOW CTL_REG(0x0714)
505#define CR_DECRY_ERR_FLG_HIGH CTL_REG(0x0718)
506
507#define CR_WEPKEY0 CTL_REG(0x0720)
508#define CR_WEPKEY1 CTL_REG(0x0724)
509#define CR_WEPKEY2 CTL_REG(0x0728)
510#define CR_WEPKEY3 CTL_REG(0x072C)
511#define CR_WEPKEY4 CTL_REG(0x0730)
512#define CR_WEPKEY5 CTL_REG(0x0734)
513#define CR_WEPKEY6 CTL_REG(0x0738)
514#define CR_WEPKEY7 CTL_REG(0x073C)
515#define CR_WEPKEY8 CTL_REG(0x0740)
516#define CR_WEPKEY9 CTL_REG(0x0744)
517#define CR_WEPKEY10 CTL_REG(0x0748)
518#define CR_WEPKEY11 CTL_REG(0x074C)
519#define CR_WEPKEY12 CTL_REG(0x0750)
520#define CR_WEPKEY13 CTL_REG(0x0754)
521#define CR_WEPKEY14 CTL_REG(0x0758)
522#define CR_WEPKEY15 CTL_REG(0x075c)
523#define CR_TKIP_MODE CTL_REG(0x0760)
524
525#define CR_EEPROM_PROTECT0 CTL_REG(0x0758)
526#define CR_EEPROM_PROTECT1 CTL_REG(0x075C)
527
528#define CR_DBG_FIFO_RD CTL_REG(0x0800)
529#define CR_DBG_SELECT CTL_REG(0x0804)
530#define CR_FIFO_Length CTL_REG(0x0808)
531
532
533#define CR_RSSI_MGC CTL_REG(0x0810)
534
535#define CR_PON CTL_REG(0x0818)
536#define CR_RX_ON CTL_REG(0x081C)
537#define CR_TX_ON CTL_REG(0x0820)
538#define CR_CHIP_EN CTL_REG(0x0824)
539#define CR_LO_SW CTL_REG(0x0828)
540#define CR_TXRX_SW CTL_REG(0x082C)
541#define CR_S_MD CTL_REG(0x0830)
542
543#define CR_USB_DEBUG_PORT CTL_REG(0x0888)
544
545#define CR_ZD1211B_TX_PWR_CTL1 CTL_REG(0x0b00)
546#define CR_ZD1211B_TX_PWR_CTL2 CTL_REG(0x0b04)
547#define CR_ZD1211B_TX_PWR_CTL3 CTL_REG(0x0b08)
548#define CR_ZD1211B_TX_PWR_CTL4 CTL_REG(0x0b0c)
549#define CR_ZD1211B_AIFS_CTL1 CTL_REG(0x0b10)
550#define CR_ZD1211B_AIFS_CTL2 CTL_REG(0x0b14)
551#define CR_ZD1211B_TXOP CTL_REG(0x0b20)
552#define CR_ZD1211B_RETRY_MAX CTL_REG(0x0b28)
553
554#define CWIN_SIZE 0x007f043f
555
556
557#define HWINT_ENABLED 0x004f0000
558#define HWINT_DISABLED 0
559
560#define E2P_PWR_INT_GUARD 8
561#define E2P_CHANNEL_COUNT 14
562
563/* If you compare this addresses with the ZYDAS orignal driver, please notify
564 * that we use word mapping for the EEPROM.
565 */
566
567/*
568 * Upper 16 bit contains the regulatory domain.
569 */
570#define E2P_SUBID E2P_REG(0x00)
571#define E2P_POD E2P_REG(0x02)
572#define E2P_MAC_ADDR_P1 E2P_REG(0x04)
573#define E2P_MAC_ADDR_P2 E2P_REG(0x06)
574#define E2P_PWR_CAL_VALUE1 E2P_REG(0x08)
575#define E2P_PWR_CAL_VALUE2 E2P_REG(0x0a)
576#define E2P_PWR_CAL_VALUE3 E2P_REG(0x0c)
577#define E2P_PWR_CAL_VALUE4 E2P_REG(0x0e)
578#define E2P_PWR_INT_VALUE1 E2P_REG(0x10)
579#define E2P_PWR_INT_VALUE2 E2P_REG(0x12)
580#define E2P_PWR_INT_VALUE3 E2P_REG(0x14)
581#define E2P_PWR_INT_VALUE4 E2P_REG(0x16)
582
583/* Contains a bit for each allowed channel. It gives for Europe (ETSI 0x30)
584 * also only 11 channels. */
585#define E2P_ALLOWED_CHANNEL E2P_REG(0x18)
586
587#define E2P_PHY_REG E2P_REG(0x1a)
588#define E2P_DEVICE_VER E2P_REG(0x20)
589#define E2P_36M_CAL_VALUE1 E2P_REG(0x28)
590#define E2P_36M_CAL_VALUE2 E2P_REG(0x2a)
591#define E2P_36M_CAL_VALUE3 E2P_REG(0x2c)
592#define E2P_36M_CAL_VALUE4 E2P_REG(0x2e)
593#define E2P_11A_INT_VALUE1 E2P_REG(0x30)
594#define E2P_11A_INT_VALUE2 E2P_REG(0x32)
595#define E2P_11A_INT_VALUE3 E2P_REG(0x34)
596#define E2P_11A_INT_VALUE4 E2P_REG(0x36)
597#define E2P_48M_CAL_VALUE1 E2P_REG(0x38)
598#define E2P_48M_CAL_VALUE2 E2P_REG(0x3a)
599#define E2P_48M_CAL_VALUE3 E2P_REG(0x3c)
600#define E2P_48M_CAL_VALUE4 E2P_REG(0x3e)
601#define E2P_48M_INT_VALUE1 E2P_REG(0x40)
602#define E2P_48M_INT_VALUE2 E2P_REG(0x42)
603#define E2P_48M_INT_VALUE3 E2P_REG(0x44)
604#define E2P_48M_INT_VALUE4 E2P_REG(0x46)
605#define E2P_54M_CAL_VALUE1 E2P_REG(0x48) /* ??? */
606#define E2P_54M_CAL_VALUE2 E2P_REG(0x4a)
607#define E2P_54M_CAL_VALUE3 E2P_REG(0x4c)
608#define E2P_54M_CAL_VALUE4 E2P_REG(0x4e)
609#define E2P_54M_INT_VALUE1 E2P_REG(0x50)
610#define E2P_54M_INT_VALUE2 E2P_REG(0x52)
611#define E2P_54M_INT_VALUE3 E2P_REG(0x54)
612#define E2P_54M_INT_VALUE4 E2P_REG(0x56)
613
614/* All 16 bit values */
615#define FW_FIRMWARE_VER FW_REG(0)
616/* non-zero if USB high speed connection */
617#define FW_USB_SPEED FW_REG(1)
618#define FW_FIX_TX_RATE FW_REG(2)
619/* Seems to be able to control LEDs over the firmware */
620#define FW_LINK_STATUS FW_REG(3)
621#define FW_SOFT_RESET FW_REG(4)
622#define FW_FLASH_CHK FW_REG(5)
623
624enum {
625 CR_BASE_OFFSET = 0x9000,
626 FW_START_OFFSET = 0xee00,
627 FW_BASE_ADDR_OFFSET = FW_START_OFFSET + 0x1d,
628 EEPROM_START_OFFSET = 0xf800,
629 EEPROM_SIZE = 0x800, /* words */
630 LOAD_CODE_SIZE = 0xe, /* words */
631 LOAD_VECT_SIZE = 0x10000 - 0xfff7, /* words */
632 EEPROM_REGS_OFFSET = LOAD_CODE_SIZE + LOAD_VECT_SIZE,
633 E2P_BASE_OFFSET = EEPROM_START_OFFSET +
634 EEPROM_REGS_OFFSET,
635};
636
637#define FW_REG_TABLE_ADDR USB_ADDR(FW_START_OFFSET + 0x1d)
638
639enum {
640 /* indices for ofdm_cal_values */
641 OFDM_36M_INDEX = 0,
642 OFDM_48M_INDEX = 1,
643 OFDM_54M_INDEX = 2,
644};
645
646struct zd_chip {
647 struct zd_usb usb;
648 struct zd_rf rf;
649 struct mutex mutex;
650 u8 e2p_mac[ETH_ALEN];
651 /* EepSetPoint in the vendor driver */
652 u8 pwr_cal_values[E2P_CHANNEL_COUNT];
653 /* integration values in the vendor driver */
654 u8 pwr_int_values[E2P_CHANNEL_COUNT];
655 /* SetPointOFDM in the vendor driver */
656 u8 ofdm_cal_values[3][E2P_CHANNEL_COUNT];
657 u8 pa_type:4, patch_cck_gain:1, patch_cr157:1, patch_6m_band_edge:1,
658 is_zd1211b:1;
659};
660
661static inline struct zd_chip *zd_usb_to_chip(struct zd_usb *usb)
662{
663 return container_of(usb, struct zd_chip, usb);
664}
665
666static inline struct zd_chip *zd_rf_to_chip(struct zd_rf *rf)
667{
668 return container_of(rf, struct zd_chip, rf);
669}
670
671#define zd_chip_dev(chip) (&(chip)->usb.intf->dev)
672
673void zd_chip_init(struct zd_chip *chip,
674 struct net_device *netdev,
675 struct usb_interface *intf);
676void zd_chip_clear(struct zd_chip *chip);
677int zd_chip_init_hw(struct zd_chip *chip, u8 device_type);
678int zd_chip_reset(struct zd_chip *chip);
679
680static inline int zd_ioread16v_locked(struct zd_chip *chip, u16 *values,
681 const zd_addr_t *addresses,
682 unsigned int count)
683{
684 ZD_ASSERT(mutex_is_locked(&chip->mutex));
685 return zd_usb_ioread16v(&chip->usb, values, addresses, count);
686}
687
688static inline int zd_ioread16_locked(struct zd_chip *chip, u16 *value,
689 const zd_addr_t addr)
690{
691 ZD_ASSERT(mutex_is_locked(&chip->mutex));
692 return zd_usb_ioread16(&chip->usb, value, addr);
693}
694
695int zd_ioread32v_locked(struct zd_chip *chip, u32 *values,
696 const zd_addr_t *addresses, unsigned int count);
697
698static inline int zd_ioread32_locked(struct zd_chip *chip, u32 *value,
699 const zd_addr_t addr)
700{
701 return zd_ioread32v_locked(chip, value, (const zd_addr_t *)&addr, 1);
702}
703
704static inline int zd_iowrite16_locked(struct zd_chip *chip, u16 value,
705 zd_addr_t addr)
706{
707 struct zd_ioreq16 ioreq;
708
709 ZD_ASSERT(mutex_is_locked(&chip->mutex));
710 ioreq.addr = addr;
711 ioreq.value = value;
712
713 return zd_usb_iowrite16v(&chip->usb, &ioreq, 1);
714}
715
716int zd_iowrite16a_locked(struct zd_chip *chip,
717 const struct zd_ioreq16 *ioreqs, unsigned int count);
718
719int _zd_iowrite32v_locked(struct zd_chip *chip, const struct zd_ioreq32 *ioreqs,
720 unsigned int count);
721
722static inline int zd_iowrite32_locked(struct zd_chip *chip, u32 value,
723 zd_addr_t addr)
724{
725 struct zd_ioreq32 ioreq;
726
727 ioreq.addr = addr;
728 ioreq.value = value;
729
730 return _zd_iowrite32v_locked(chip, &ioreq, 1);
731}
732
733int zd_iowrite32a_locked(struct zd_chip *chip,
734 const struct zd_ioreq32 *ioreqs, unsigned int count);
735
736static inline int zd_rfwrite_locked(struct zd_chip *chip, u32 value, u8 bits)
737{
738 ZD_ASSERT(mutex_is_locked(&chip->mutex));
739 return zd_usb_rfwrite(&chip->usb, value, bits);
740}
741
742int zd_rfwritev_locked(struct zd_chip *chip,
743 const u32* values, unsigned int count, u8 bits);
744
745/* Locking functions for reading and writing registers.
746 * The different parameters are intentional.
747 */
748int zd_ioread16(struct zd_chip *chip, zd_addr_t addr, u16 *value);
749int zd_iowrite16(struct zd_chip *chip, zd_addr_t addr, u16 value);
750int zd_ioread32(struct zd_chip *chip, zd_addr_t addr, u32 *value);
751int zd_iowrite32(struct zd_chip *chip, zd_addr_t addr, u32 value);
752int zd_ioread32v(struct zd_chip *chip, const zd_addr_t *addresses,
753 u32 *values, unsigned int count);
754int zd_iowrite32a(struct zd_chip *chip, const struct zd_ioreq32 *ioreqs,
755 unsigned int count);
756
757int zd_chip_set_channel(struct zd_chip *chip, u8 channel);
758static inline u8 _zd_chip_get_channel(struct zd_chip *chip)
759{
760 return chip->rf.channel;
761}
762u8 zd_chip_get_channel(struct zd_chip *chip);
763int zd_read_regdomain(struct zd_chip *chip, u8 *regdomain);
764void zd_get_e2p_mac_addr(struct zd_chip *chip, u8 *mac_addr);
765int zd_read_mac_addr(struct zd_chip *chip, u8 *mac_addr);
766int zd_write_mac_addr(struct zd_chip *chip, const u8 *mac_addr);
767int zd_chip_switch_radio_on(struct zd_chip *chip);
768int zd_chip_switch_radio_off(struct zd_chip *chip);
769int zd_chip_enable_int(struct zd_chip *chip);
770void zd_chip_disable_int(struct zd_chip *chip);
771int zd_chip_enable_rx(struct zd_chip *chip);
772void zd_chip_disable_rx(struct zd_chip *chip);
773int zd_chip_enable_hwint(struct zd_chip *chip);
774int zd_chip_disable_hwint(struct zd_chip *chip);
775
776static inline int zd_get_encryption_type(struct zd_chip *chip, u32 *type)
777{
778 return zd_ioread32(chip, CR_ENCRYPTION_TYPE, type);
779}
780
781static inline int zd_set_encryption_type(struct zd_chip *chip, u32 type)
782{
783 return zd_iowrite32(chip, CR_ENCRYPTION_TYPE, type);
784}
785
786static inline int zd_chip_get_basic_rates(struct zd_chip *chip, u16 *cr_rates)
787{
788 return zd_ioread16(chip, CR_BASIC_RATE_TBL, cr_rates);
789}
790
791int zd_chip_set_basic_rates(struct zd_chip *chip, u16 cr_rates);
792
793static inline int zd_chip_set_rx_filter(struct zd_chip *chip, u32 filter)
794{
795 return zd_iowrite32(chip, CR_RX_FILTER, filter);
796}
797
798int zd_chip_lock_phy_regs(struct zd_chip *chip);
799int zd_chip_unlock_phy_regs(struct zd_chip *chip);
800
801enum led_status {
802 LED_OFF = 0,
803 LED_ON = 1,
804 LED_FLIP = 2,
805 LED_STATUS = 3,
806};
807
808int zd_chip_led_status(struct zd_chip *chip, int led, enum led_status status);
809int zd_chip_led_flip(struct zd_chip *chip, int led,
810 const unsigned int *phases_msecs, unsigned int count);
811
812int zd_set_beacon_interval(struct zd_chip *chip, u32 interval);
813
814static inline int zd_get_beacon_interval(struct zd_chip *chip, u32 *interval)
815{
816 return zd_ioread32(chip, CR_BCN_INTERVAL, interval);
817}
818
819struct rx_status;
820
821u8 zd_rx_qual_percent(const void *rx_frame, unsigned int size,
822 const struct rx_status *status);
823u8 zd_rx_strength_percent(u8 rssi);
824
825u16 zd_rx_rate(const void *rx_frame, const struct rx_status *status);
826
827#endif /* _ZD_CHIP_H */
diff --git a/drivers/net/wireless/zd1211rw/zd_def.h b/drivers/net/wireless/zd1211rw/zd_def.h
new file mode 100644
index 000000000000..465906812fc4
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_def.h
@@ -0,0 +1,48 @@
1/* zd_def.h
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#ifndef _ZD_DEF_H
19#define _ZD_DEF_H
20
21#include <linux/kernel.h>
22#include <linux/stringify.h>
23#include <linux/device.h>
24#include <linux/kernel.h>
25
26#define dev_printk_f(level, dev, fmt, args...) \
27 dev_printk(level, dev, "%s() " fmt, __func__, ##args)
28
29#ifdef DEBUG
30# define dev_dbg_f(dev, fmt, args...) \
31 dev_printk_f(KERN_DEBUG, dev, fmt, ## args)
32#else
33# define dev_dbg_f(dev, fmt, args...) do { (void)(dev); } while (0)
34#endif /* DEBUG */
35
36#ifdef DEBUG
37# define ZD_ASSERT(x) \
38do { \
39 if (!(x)) { \
40 pr_debug("%s:%d ASSERT %s VIOLATED!\n", \
41 __FILE__, __LINE__, __stringify(x)); \
42 } \
43} while (0)
44#else
45# define ZD_ASSERT(x) do { } while (0)
46#endif
47
48#endif /* _ZD_DEF_H */
diff --git a/drivers/net/wireless/zd1211rw/zd_ieee80211.c b/drivers/net/wireless/zd1211rw/zd_ieee80211.c
new file mode 100644
index 000000000000..66905f7b61ff
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_ieee80211.c
@@ -0,0 +1,191 @@
1/* zd_ieee80211.c
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18/*
19 * A lot of this code is generic and should be moved into the upper layers
20 * at some point.
21 */
22
23#include <linux/errno.h>
24#include <linux/wireless.h>
25#include <linux/kernel.h>
26#include <net/ieee80211.h>
27
28#include "zd_def.h"
29#include "zd_ieee80211.h"
30#include "zd_mac.h"
31
32static const struct channel_range channel_ranges[] = {
33 [0] = { 0, 0},
34 [ZD_REGDOMAIN_FCC] = { 1, 12},
35 [ZD_REGDOMAIN_IC] = { 1, 12},
36 [ZD_REGDOMAIN_ETSI] = { 1, 14},
37 [ZD_REGDOMAIN_JAPAN] = { 1, 14},
38 [ZD_REGDOMAIN_SPAIN] = { 1, 14},
39 [ZD_REGDOMAIN_FRANCE] = { 1, 14},
40 [ZD_REGDOMAIN_JAPAN_ADD] = {14, 15},
41};
42
43const struct channel_range *zd_channel_range(u8 regdomain)
44{
45 if (regdomain >= ARRAY_SIZE(channel_ranges))
46 regdomain = 0;
47 return &channel_ranges[regdomain];
48}
49
50int zd_regdomain_supports_channel(u8 regdomain, u8 channel)
51{
52 const struct channel_range *range = zd_channel_range(regdomain);
53 return range->start <= channel && channel < range->end;
54}
55
56int zd_regdomain_supported(u8 regdomain)
57{
58 const struct channel_range *range = zd_channel_range(regdomain);
59 return range->start != 0;
60}
61
62/* Stores channel frequencies in MHz. */
63static const u16 channel_frequencies[] = {
64 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447,
65 2452, 2457, 2462, 2467, 2472, 2484,
66};
67
68#define NUM_CHANNELS ARRAY_SIZE(channel_frequencies)
69
70static int compute_freq(struct iw_freq *freq, u32 mhz, u32 hz)
71{
72 u32 factor;
73
74 freq->e = 0;
75 if (mhz >= 1000000000U) {
76 pr_debug("zd1211 mhz %u to large\n", mhz);
77 freq->m = 0;
78 return -EINVAL;
79 }
80
81 factor = 1000;
82 while (mhz >= factor) {
83
84 freq->e += 1;
85 factor *= 10;
86 }
87
88 factor /= 1000U;
89 freq->m = mhz * (1000000U/factor) + hz/factor;
90
91 return 0;
92}
93
94int zd_channel_to_freq(struct iw_freq *freq, u8 channel)
95{
96 if (channel > NUM_CHANNELS) {
97 freq->m = 0;
98 freq->e = 0;
99 return -EINVAL;
100 }
101 if (!channel) {
102 freq->m = 0;
103 freq->e = 0;
104 return -EINVAL;
105 }
106 return compute_freq(freq, channel_frequencies[channel-1], 0);
107}
108
109static int freq_to_mhz(const struct iw_freq *freq)
110{
111 u32 factor;
112 int e;
113
114 /* Such high frequencies are not supported. */
115 if (freq->e > 6)
116 return -EINVAL;
117
118 factor = 1;
119 for (e = freq->e; e > 0; --e) {
120 factor *= 10;
121 }
122 factor = 1000000U / factor;
123
124 if (freq->m % factor) {
125 return -EINVAL;
126 }
127
128 return freq->m / factor;
129}
130
131int zd_find_channel(u8 *channel, const struct iw_freq *freq)
132{
133 int i, r;
134 u32 mhz;
135
136 if (!(freq->flags & IW_FREQ_FIXED))
137 return 0;
138
139 if (freq->m < 1000) {
140 if (freq->m > NUM_CHANNELS || freq->m == 0)
141 return -EINVAL;
142 *channel = freq->m;
143 return 1;
144 }
145
146 r = freq_to_mhz(freq);
147 if (r < 0)
148 return r;
149 mhz = r;
150
151 for (i = 0; i < NUM_CHANNELS; i++) {
152 if (mhz == channel_frequencies[i]) {
153 *channel = i+1;
154 return 1;
155 }
156 }
157
158 return -EINVAL;
159}
160
161int zd_geo_init(struct ieee80211_device *ieee, u8 regdomain)
162{
163 struct ieee80211_geo geo;
164 const struct channel_range *range;
165 int i;
166 u8 channel;
167
168 dev_dbg(zd_mac_dev(zd_netdev_mac(ieee->dev)),
169 "regdomain %#04x\n", regdomain);
170
171 range = zd_channel_range(regdomain);
172 if (range->start == 0) {
173 dev_err(zd_mac_dev(zd_netdev_mac(ieee->dev)),
174 "zd1211 regdomain %#04x not supported\n",
175 regdomain);
176 return -EINVAL;
177 }
178
179 memset(&geo, 0, sizeof(geo));
180
181 for (i = 0, channel = range->start; channel < range->end; channel++) {
182 struct ieee80211_channel *chan = &geo.bg[i++];
183 chan->freq = channel_frequencies[channel - 1];
184 chan->channel = channel;
185 }
186
187 geo.bg_channels = i;
188 memcpy(geo.name, "XX ", 4);
189 ieee80211_set_geo(ieee, &geo);
190 return 0;
191}
diff --git a/drivers/net/wireless/zd1211rw/zd_ieee80211.h b/drivers/net/wireless/zd1211rw/zd_ieee80211.h
new file mode 100644
index 000000000000..36329890dfec
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_ieee80211.h
@@ -0,0 +1,85 @@
1#ifndef _ZD_IEEE80211_H
2#define _ZD_IEEE80211_H
3
4#include <net/ieee80211.h>
5#include "zd_types.h"
6
7/* Additional definitions from the standards.
8 */
9
10#define ZD_REGDOMAIN_FCC 0x10
11#define ZD_REGDOMAIN_IC 0x20
12#define ZD_REGDOMAIN_ETSI 0x30
13#define ZD_REGDOMAIN_SPAIN 0x31
14#define ZD_REGDOMAIN_FRANCE 0x32
15#define ZD_REGDOMAIN_JAPAN_ADD 0x40
16#define ZD_REGDOMAIN_JAPAN 0x41
17
18enum {
19 MIN_CHANNEL24 = 1,
20 MAX_CHANNEL24 = 14,
21};
22
23struct channel_range {
24 u8 start;
25 u8 end; /* exclusive (channel must be less than end) */
26};
27
28struct iw_freq;
29
30int zd_geo_init(struct ieee80211_device *ieee, u8 regdomain);
31
32const struct channel_range *zd_channel_range(u8 regdomain);
33int zd_regdomain_supports_channel(u8 regdomain, u8 channel);
34int zd_regdomain_supported(u8 regdomain);
35
36/* for 2.4 GHz band */
37int zd_channel_to_freq(struct iw_freq *freq, u8 channel);
38int zd_find_channel(u8 *channel, const struct iw_freq *freq);
39
40#define ZD_PLCP_SERVICE_LENGTH_EXTENSION 0x80
41
42struct ofdm_plcp_header {
43 u8 prefix[3];
44 __le16 service;
45} __attribute__((packed));
46
47static inline u8 zd_ofdm_plcp_header_rate(
48 const struct ofdm_plcp_header *header)
49{
50 return header->prefix[0] & 0xf;
51}
52
53#define ZD_OFDM_RATE_6M 0xb
54#define ZD_OFDM_RATE_9M 0xf
55#define ZD_OFDM_RATE_12M 0xa
56#define ZD_OFDM_RATE_18M 0xe
57#define ZD_OFDM_RATE_24M 0x9
58#define ZD_OFDM_RATE_36M 0xd
59#define ZD_OFDM_RATE_48M 0x8
60#define ZD_OFDM_RATE_54M 0xc
61
62struct cck_plcp_header {
63 u8 signal;
64 u8 service;
65 __le16 length;
66 __le16 crc16;
67} __attribute__((packed));
68
69static inline u8 zd_cck_plcp_header_rate(const struct cck_plcp_header *header)
70{
71 return header->signal;
72}
73
74#define ZD_CCK_SIGNAL_1M 0x0a
75#define ZD_CCK_SIGNAL_2M 0x14
76#define ZD_CCK_SIGNAL_5M5 0x37
77#define ZD_CCK_SIGNAL_11M 0x6e
78
79enum ieee80211_std {
80 IEEE80211B = 0x01,
81 IEEE80211A = 0x02,
82 IEEE80211G = 0x04,
83};
84
85#endif /* _ZD_IEEE80211_H */
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
new file mode 100644
index 000000000000..a9bd80a08613
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -0,0 +1,1084 @@
1/* zd_mac.c
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#include <linux/netdevice.h>
19#include <linux/etherdevice.h>
20#include <linux/wireless.h>
21#include <linux/usb.h>
22#include <linux/jiffies.h>
23#include <net/ieee80211_radiotap.h>
24
25#include "zd_def.h"
26#include "zd_chip.h"
27#include "zd_mac.h"
28#include "zd_ieee80211.h"
29#include "zd_netdev.h"
30#include "zd_rf.h"
31#include "zd_util.h"
32
33static void ieee_init(struct ieee80211_device *ieee);
34static void softmac_init(struct ieee80211softmac_device *sm);
35
36int zd_mac_init(struct zd_mac *mac,
37 struct net_device *netdev,
38 struct usb_interface *intf)
39{
40 struct ieee80211_device *ieee = zd_netdev_ieee80211(netdev);
41
42 memset(mac, 0, sizeof(*mac));
43 spin_lock_init(&mac->lock);
44 mac->netdev = netdev;
45
46 ieee_init(ieee);
47 softmac_init(ieee80211_priv(netdev));
48 zd_chip_init(&mac->chip, netdev, intf);
49 return 0;
50}
51
52static int reset_channel(struct zd_mac *mac)
53{
54 int r;
55 unsigned long flags;
56 const struct channel_range *range;
57
58 spin_lock_irqsave(&mac->lock, flags);
59 range = zd_channel_range(mac->regdomain);
60 if (!range->start) {
61 r = -EINVAL;
62 goto out;
63 }
64 mac->requested_channel = range->start;
65 r = 0;
66out:
67 spin_unlock_irqrestore(&mac->lock, flags);
68 return r;
69}
70
71int zd_mac_init_hw(struct zd_mac *mac, u8 device_type)
72{
73 int r;
74 struct zd_chip *chip = &mac->chip;
75 u8 addr[ETH_ALEN];
76 u8 default_regdomain;
77
78 r = zd_chip_enable_int(chip);
79 if (r)
80 goto out;
81 r = zd_chip_init_hw(chip, device_type);
82 if (r)
83 goto disable_int;
84
85 zd_get_e2p_mac_addr(chip, addr);
86 r = zd_write_mac_addr(chip, addr);
87 if (r)
88 goto disable_int;
89 ZD_ASSERT(!irqs_disabled());
90 spin_lock_irq(&mac->lock);
91 memcpy(mac->netdev->dev_addr, addr, ETH_ALEN);
92 spin_unlock_irq(&mac->lock);
93
94 r = zd_read_regdomain(chip, &default_regdomain);
95 if (r)
96 goto disable_int;
97 if (!zd_regdomain_supported(default_regdomain)) {
98 dev_dbg_f(zd_mac_dev(mac),
99 "Regulatory Domain %#04x is not supported.\n",
100 default_regdomain);
101 r = -EINVAL;
102 goto disable_int;
103 }
104 spin_lock_irq(&mac->lock);
105 mac->regdomain = mac->default_regdomain = default_regdomain;
106 spin_unlock_irq(&mac->lock);
107 r = reset_channel(mac);
108 if (r)
109 goto disable_int;
110
111 /* We must inform the device that we are doing encryption/decryption in
112 * software at the moment. */
113 r = zd_set_encryption_type(chip, ENC_SNIFFER);
114 if (r)
115 goto disable_int;
116
117 r = zd_geo_init(zd_mac_to_ieee80211(mac), mac->regdomain);
118 if (r)
119 goto disable_int;
120
121 r = 0;
122disable_int:
123 zd_chip_disable_int(chip);
124out:
125 return r;
126}
127
128void zd_mac_clear(struct zd_mac *mac)
129{
130 /* Aquire the lock. */
131 spin_lock(&mac->lock);
132 spin_unlock(&mac->lock);
133 zd_chip_clear(&mac->chip);
134 memset(mac, 0, sizeof(*mac));
135}
136
137static int reset_mode(struct zd_mac *mac)
138{
139 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
140 struct zd_ioreq32 ioreqs[3] = {
141 { CR_RX_FILTER, STA_RX_FILTER },
142 { CR_SNIFFER_ON, 0U },
143 };
144
145 if (ieee->iw_mode == IW_MODE_MONITOR) {
146 ioreqs[0].value = 0xffffffff;
147 ioreqs[1].value = 0x1;
148 ioreqs[2].value = ENC_SNIFFER;
149 }
150
151 return zd_iowrite32a(&mac->chip, ioreqs, 3);
152}
153
154int zd_mac_open(struct net_device *netdev)
155{
156 struct zd_mac *mac = zd_netdev_mac(netdev);
157 struct zd_chip *chip = &mac->chip;
158 int r;
159
160 r = zd_chip_enable_int(chip);
161 if (r < 0)
162 goto out;
163
164 r = zd_chip_set_basic_rates(chip, CR_RATES_80211B | CR_RATES_80211G);
165 if (r < 0)
166 goto disable_int;
167 r = reset_mode(mac);
168 if (r)
169 goto disable_int;
170 r = zd_chip_switch_radio_on(chip);
171 if (r < 0)
172 goto disable_int;
173 r = zd_chip_set_channel(chip, mac->requested_channel);
174 if (r < 0)
175 goto disable_radio;
176 r = zd_chip_enable_rx(chip);
177 if (r < 0)
178 goto disable_radio;
179 r = zd_chip_enable_hwint(chip);
180 if (r < 0)
181 goto disable_rx;
182
183 ieee80211softmac_start(netdev);
184 return 0;
185disable_rx:
186 zd_chip_disable_rx(chip);
187disable_radio:
188 zd_chip_switch_radio_off(chip);
189disable_int:
190 zd_chip_disable_int(chip);
191out:
192 return r;
193}
194
195int zd_mac_stop(struct net_device *netdev)
196{
197 struct zd_mac *mac = zd_netdev_mac(netdev);
198 struct zd_chip *chip = &mac->chip;
199
200 netif_stop_queue(netdev);
201
202 /*
203 * The order here deliberately is a little different from the open()
204 * method, since we need to make sure there is no opportunity for RX
205 * frames to be processed by softmac after we have stopped it.
206 */
207
208 zd_chip_disable_rx(chip);
209 ieee80211softmac_stop(netdev);
210
211 zd_chip_disable_hwint(chip);
212 zd_chip_switch_radio_off(chip);
213 zd_chip_disable_int(chip);
214
215 return 0;
216}
217
218int zd_mac_set_mac_address(struct net_device *netdev, void *p)
219{
220 int r;
221 unsigned long flags;
222 struct sockaddr *addr = p;
223 struct zd_mac *mac = zd_netdev_mac(netdev);
224 struct zd_chip *chip = &mac->chip;
225
226 if (!is_valid_ether_addr(addr->sa_data))
227 return -EADDRNOTAVAIL;
228
229 dev_dbg_f(zd_mac_dev(mac),
230 "Setting MAC to " MAC_FMT "\n", MAC_ARG(addr->sa_data));
231
232 r = zd_write_mac_addr(chip, addr->sa_data);
233 if (r)
234 return r;
235
236 spin_lock_irqsave(&mac->lock, flags);
237 memcpy(netdev->dev_addr, addr->sa_data, ETH_ALEN);
238 spin_unlock_irqrestore(&mac->lock, flags);
239
240 return 0;
241}
242
243int zd_mac_set_regdomain(struct zd_mac *mac, u8 regdomain)
244{
245 int r;
246 u8 channel;
247
248 ZD_ASSERT(!irqs_disabled());
249 spin_lock_irq(&mac->lock);
250 if (regdomain == 0) {
251 regdomain = mac->default_regdomain;
252 }
253 if (!zd_regdomain_supported(regdomain)) {
254 spin_unlock_irq(&mac->lock);
255 return -EINVAL;
256 }
257 mac->regdomain = regdomain;
258 channel = mac->requested_channel;
259 spin_unlock_irq(&mac->lock);
260
261 r = zd_geo_init(zd_mac_to_ieee80211(mac), regdomain);
262 if (r)
263 return r;
264 if (!zd_regdomain_supports_channel(regdomain, channel)) {
265 r = reset_channel(mac);
266 if (r)
267 return r;
268 }
269
270 return 0;
271}
272
273u8 zd_mac_get_regdomain(struct zd_mac *mac)
274{
275 unsigned long flags;
276 u8 regdomain;
277
278 spin_lock_irqsave(&mac->lock, flags);
279 regdomain = mac->regdomain;
280 spin_unlock_irqrestore(&mac->lock, flags);
281 return regdomain;
282}
283
284static void set_channel(struct net_device *netdev, u8 channel)
285{
286 struct zd_mac *mac = zd_netdev_mac(netdev);
287
288 dev_dbg_f(zd_mac_dev(mac), "channel %d\n", channel);
289
290 zd_chip_set_channel(&mac->chip, channel);
291}
292
293/* TODO: Should not work in Managed mode. */
294int zd_mac_request_channel(struct zd_mac *mac, u8 channel)
295{
296 unsigned long lock_flags;
297 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
298
299 if (ieee->iw_mode == IW_MODE_INFRA)
300 return -EPERM;
301
302 spin_lock_irqsave(&mac->lock, lock_flags);
303 if (!zd_regdomain_supports_channel(mac->regdomain, channel)) {
304 spin_unlock_irqrestore(&mac->lock, lock_flags);
305 return -EINVAL;
306 }
307 mac->requested_channel = channel;
308 spin_unlock_irqrestore(&mac->lock, lock_flags);
309 if (netif_running(mac->netdev))
310 return zd_chip_set_channel(&mac->chip, channel);
311 else
312 return 0;
313}
314
315int zd_mac_get_channel(struct zd_mac *mac, u8 *channel, u8 *flags)
316{
317 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
318
319 *channel = zd_chip_get_channel(&mac->chip);
320 if (ieee->iw_mode != IW_MODE_INFRA) {
321 spin_lock_irq(&mac->lock);
322 *flags = *channel == mac->requested_channel ?
323 MAC_FIXED_CHANNEL : 0;
324 spin_unlock(&mac->lock);
325 } else {
326 *flags = 0;
327 }
328 dev_dbg_f(zd_mac_dev(mac), "channel %u flags %u\n", *channel, *flags);
329 return 0;
330}
331
332/* If wrong rate is given, we are falling back to the slowest rate: 1MBit/s */
333static u8 cs_typed_rate(u8 cs_rate)
334{
335 static const u8 typed_rates[16] = {
336 [ZD_CS_CCK_RATE_1M] = ZD_CS_CCK|ZD_CS_CCK_RATE_1M,
337 [ZD_CS_CCK_RATE_2M] = ZD_CS_CCK|ZD_CS_CCK_RATE_2M,
338 [ZD_CS_CCK_RATE_5_5M] = ZD_CS_CCK|ZD_CS_CCK_RATE_5_5M,
339 [ZD_CS_CCK_RATE_11M] = ZD_CS_CCK|ZD_CS_CCK_RATE_11M,
340 [ZD_OFDM_RATE_6M] = ZD_CS_OFDM|ZD_OFDM_RATE_6M,
341 [ZD_OFDM_RATE_9M] = ZD_CS_OFDM|ZD_OFDM_RATE_9M,
342 [ZD_OFDM_RATE_12M] = ZD_CS_OFDM|ZD_OFDM_RATE_12M,
343 [ZD_OFDM_RATE_18M] = ZD_CS_OFDM|ZD_OFDM_RATE_18M,
344 [ZD_OFDM_RATE_24M] = ZD_CS_OFDM|ZD_OFDM_RATE_24M,
345 [ZD_OFDM_RATE_36M] = ZD_CS_OFDM|ZD_OFDM_RATE_36M,
346 [ZD_OFDM_RATE_48M] = ZD_CS_OFDM|ZD_OFDM_RATE_48M,
347 [ZD_OFDM_RATE_54M] = ZD_CS_OFDM|ZD_OFDM_RATE_54M,
348 };
349
350 ZD_ASSERT(ZD_CS_RATE_MASK == 0x0f);
351 return typed_rates[cs_rate & ZD_CS_RATE_MASK];
352}
353
354/* Fallback to lowest rate, if rate is unknown. */
355static u8 rate_to_cs_rate(u8 rate)
356{
357 switch (rate) {
358 case IEEE80211_CCK_RATE_2MB:
359 return ZD_CS_CCK_RATE_2M;
360 case IEEE80211_CCK_RATE_5MB:
361 return ZD_CS_CCK_RATE_5_5M;
362 case IEEE80211_CCK_RATE_11MB:
363 return ZD_CS_CCK_RATE_11M;
364 case IEEE80211_OFDM_RATE_6MB:
365 return ZD_OFDM_RATE_6M;
366 case IEEE80211_OFDM_RATE_9MB:
367 return ZD_OFDM_RATE_9M;
368 case IEEE80211_OFDM_RATE_12MB:
369 return ZD_OFDM_RATE_12M;
370 case IEEE80211_OFDM_RATE_18MB:
371 return ZD_OFDM_RATE_18M;
372 case IEEE80211_OFDM_RATE_24MB:
373 return ZD_OFDM_RATE_24M;
374 case IEEE80211_OFDM_RATE_36MB:
375 return ZD_OFDM_RATE_36M;
376 case IEEE80211_OFDM_RATE_48MB:
377 return ZD_OFDM_RATE_48M;
378 case IEEE80211_OFDM_RATE_54MB:
379 return ZD_OFDM_RATE_54M;
380 }
381 return ZD_CS_CCK_RATE_1M;
382}
383
384int zd_mac_set_mode(struct zd_mac *mac, u32 mode)
385{
386 struct ieee80211_device *ieee;
387
388 switch (mode) {
389 case IW_MODE_AUTO:
390 case IW_MODE_ADHOC:
391 case IW_MODE_INFRA:
392 mac->netdev->type = ARPHRD_ETHER;
393 break;
394 case IW_MODE_MONITOR:
395 mac->netdev->type = ARPHRD_IEEE80211_RADIOTAP;
396 break;
397 default:
398 dev_dbg_f(zd_mac_dev(mac), "wrong mode %u\n", mode);
399 return -EINVAL;
400 }
401
402 ieee = zd_mac_to_ieee80211(mac);
403 ZD_ASSERT(!irqs_disabled());
404 spin_lock_irq(&ieee->lock);
405 ieee->iw_mode = mode;
406 spin_unlock_irq(&ieee->lock);
407
408 if (netif_running(mac->netdev))
409 return reset_mode(mac);
410
411 return 0;
412}
413
414int zd_mac_get_mode(struct zd_mac *mac, u32 *mode)
415{
416 unsigned long flags;
417 struct ieee80211_device *ieee;
418
419 ieee = zd_mac_to_ieee80211(mac);
420 spin_lock_irqsave(&ieee->lock, flags);
421 *mode = ieee->iw_mode;
422 spin_unlock_irqrestore(&ieee->lock, flags);
423 return 0;
424}
425
426int zd_mac_get_range(struct zd_mac *mac, struct iw_range *range)
427{
428 int i;
429 const struct channel_range *channel_range;
430 u8 regdomain;
431
432 memset(range, 0, sizeof(*range));
433
434 /* FIXME: Not so important and depends on the mode. For 802.11g
435 * usually this value is used. It seems to be that Bit/s number is
436 * given here.
437 */
438 range->throughput = 27 * 1000 * 1000;
439
440 range->max_qual.qual = 100;
441 range->max_qual.level = 100;
442
443 /* FIXME: Needs still to be tuned. */
444 range->avg_qual.qual = 71;
445 range->avg_qual.level = 80;
446
447 /* FIXME: depends on standard? */
448 range->min_rts = 256;
449 range->max_rts = 2346;
450
451 range->min_frag = MIN_FRAG_THRESHOLD;
452 range->max_frag = MAX_FRAG_THRESHOLD;
453
454 range->max_encoding_tokens = WEP_KEYS;
455 range->num_encoding_sizes = 2;
456 range->encoding_size[0] = 5;
457 range->encoding_size[1] = WEP_KEY_LEN;
458
459 range->we_version_compiled = WIRELESS_EXT;
460 range->we_version_source = 20;
461
462 ZD_ASSERT(!irqs_disabled());
463 spin_lock_irq(&mac->lock);
464 regdomain = mac->regdomain;
465 spin_unlock_irq(&mac->lock);
466 channel_range = zd_channel_range(regdomain);
467
468 range->num_channels = channel_range->end - channel_range->start;
469 range->old_num_channels = range->num_channels;
470 range->num_frequency = range->num_channels;
471 range->old_num_frequency = range->num_frequency;
472
473 for (i = 0; i < range->num_frequency; i++) {
474 struct iw_freq *freq = &range->freq[i];
475 freq->i = channel_range->start + i;
476 zd_channel_to_freq(freq, freq->i);
477 }
478
479 return 0;
480}
481
482static int zd_calc_tx_length_us(u8 *service, u8 cs_rate, u16 tx_length)
483{
484 static const u8 rate_divisor[] = {
485 [ZD_CS_CCK_RATE_1M] = 1,
486 [ZD_CS_CCK_RATE_2M] = 2,
487 [ZD_CS_CCK_RATE_5_5M] = 11, /* bits must be doubled */
488 [ZD_CS_CCK_RATE_11M] = 11,
489 [ZD_OFDM_RATE_6M] = 6,
490 [ZD_OFDM_RATE_9M] = 9,
491 [ZD_OFDM_RATE_12M] = 12,
492 [ZD_OFDM_RATE_18M] = 18,
493 [ZD_OFDM_RATE_24M] = 24,
494 [ZD_OFDM_RATE_36M] = 36,
495 [ZD_OFDM_RATE_48M] = 48,
496 [ZD_OFDM_RATE_54M] = 54,
497 };
498
499 u32 bits = (u32)tx_length * 8;
500 u32 divisor;
501
502 divisor = rate_divisor[cs_rate];
503 if (divisor == 0)
504 return -EINVAL;
505
506 switch (cs_rate) {
507 case ZD_CS_CCK_RATE_5_5M:
508 bits = (2*bits) + 10; /* round up to the next integer */
509 break;
510 case ZD_CS_CCK_RATE_11M:
511 if (service) {
512 u32 t = bits % 11;
513 *service &= ~ZD_PLCP_SERVICE_LENGTH_EXTENSION;
514 if (0 < t && t <= 3) {
515 *service |= ZD_PLCP_SERVICE_LENGTH_EXTENSION;
516 }
517 }
518 bits += 10; /* round up to the next integer */
519 break;
520 }
521
522 return bits/divisor;
523}
524
525enum {
526 R2M_SHORT_PREAMBLE = 0x01,
527 R2M_11A = 0x02,
528};
529
530static u8 cs_rate_to_modulation(u8 cs_rate, int flags)
531{
532 u8 modulation;
533
534 modulation = cs_typed_rate(cs_rate);
535 if (flags & R2M_SHORT_PREAMBLE) {
536 switch (ZD_CS_RATE(modulation)) {
537 case ZD_CS_CCK_RATE_2M:
538 case ZD_CS_CCK_RATE_5_5M:
539 case ZD_CS_CCK_RATE_11M:
540 modulation |= ZD_CS_CCK_PREA_SHORT;
541 return modulation;
542 }
543 }
544 if (flags & R2M_11A) {
545 if (ZD_CS_TYPE(modulation) == ZD_CS_OFDM)
546 modulation |= ZD_CS_OFDM_MODE_11A;
547 }
548 return modulation;
549}
550
551static void cs_set_modulation(struct zd_mac *mac, struct zd_ctrlset *cs,
552 struct ieee80211_hdr_4addr *hdr)
553{
554 struct ieee80211softmac_device *softmac = ieee80211_priv(mac->netdev);
555 u16 ftype = WLAN_FC_GET_TYPE(le16_to_cpu(hdr->frame_ctl));
556 u8 rate, cs_rate;
557 int is_mgt = (ftype == IEEE80211_FTYPE_MGMT) != 0;
558
559 /* FIXME: 802.11a? short preamble? */
560 rate = ieee80211softmac_suggest_txrate(softmac,
561 is_multicast_ether_addr(hdr->addr1), is_mgt);
562
563 cs_rate = rate_to_cs_rate(rate);
564 cs->modulation = cs_rate_to_modulation(cs_rate, 0);
565}
566
567static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs,
568 struct ieee80211_hdr_4addr *header)
569{
570 unsigned int tx_length = le16_to_cpu(cs->tx_length);
571 u16 fctl = le16_to_cpu(header->frame_ctl);
572 u16 ftype = WLAN_FC_GET_TYPE(fctl);
573 u16 stype = WLAN_FC_GET_STYPE(fctl);
574
575 /*
576 * CONTROL:
577 * - start at 0x00
578 * - if fragment 0, enable bit 0
579 * - if backoff needed, enable bit 0
580 * - if burst (backoff not needed) disable bit 0
581 * - if multicast, enable bit 1
582 * - if PS-POLL frame, enable bit 2
583 * - if in INDEPENDENT_BSS mode and zd1205_DestPowerSave, then enable
584 * bit 4 (FIXME: wtf)
585 * - if frag_len > RTS threshold, set bit 5 as long if it isnt
586 * multicast or mgt
587 * - if bit 5 is set, and we are in OFDM mode, unset bit 5 and set bit
588 * 7
589 */
590
591 cs->control = 0;
592
593 /* First fragment */
594 if (WLAN_GET_SEQ_FRAG(le16_to_cpu(header->seq_ctl)) == 0)
595 cs->control |= ZD_CS_NEED_RANDOM_BACKOFF;
596
597 /* Multicast */
598 if (is_multicast_ether_addr(header->addr1))
599 cs->control |= ZD_CS_MULTICAST;
600
601 /* PS-POLL */
602 if (stype == IEEE80211_STYPE_PSPOLL)
603 cs->control |= ZD_CS_PS_POLL_FRAME;
604
605 if (!is_multicast_ether_addr(header->addr1) &&
606 ftype != IEEE80211_FTYPE_MGMT &&
607 tx_length > zd_netdev_ieee80211(mac->netdev)->rts)
608 {
609 /* FIXME: check the logic */
610 if (ZD_CS_TYPE(cs->modulation) == ZD_CS_OFDM) {
611 /* 802.11g */
612 cs->control |= ZD_CS_SELF_CTS;
613 } else { /* 802.11b */
614 cs->control |= ZD_CS_RTS;
615 }
616 }
617
618 /* FIXME: Management frame? */
619}
620
621static int fill_ctrlset(struct zd_mac *mac,
622 struct ieee80211_txb *txb,
623 int frag_num)
624{
625 int r;
626 struct sk_buff *skb = txb->fragments[frag_num];
627 struct ieee80211_hdr_4addr *hdr =
628 (struct ieee80211_hdr_4addr *) skb->data;
629 unsigned int frag_len = skb->len + IEEE80211_FCS_LEN;
630 unsigned int next_frag_len;
631 unsigned int packet_length;
632 struct zd_ctrlset *cs = (struct zd_ctrlset *)
633 skb_push(skb, sizeof(struct zd_ctrlset));
634
635 if (frag_num+1 < txb->nr_frags) {
636 next_frag_len = txb->fragments[frag_num+1]->len +
637 IEEE80211_FCS_LEN;
638 } else {
639 next_frag_len = 0;
640 }
641 ZD_ASSERT(frag_len <= 0xffff);
642 ZD_ASSERT(next_frag_len <= 0xffff);
643
644 cs_set_modulation(mac, cs, hdr);
645
646 cs->tx_length = cpu_to_le16(frag_len);
647
648 cs_set_control(mac, cs, hdr);
649
650 packet_length = frag_len + sizeof(struct zd_ctrlset) + 10;
651 ZD_ASSERT(packet_length <= 0xffff);
652 /* ZD1211B: Computing the length difference this way, gives us
653 * flexibility to compute the packet length.
654 */
655 cs->packet_length = cpu_to_le16(mac->chip.is_zd1211b ?
656 packet_length - frag_len : packet_length);
657
658 /*
659 * CURRENT LENGTH:
660 * - transmit frame length in microseconds
661 * - seems to be derived from frame length
662 * - see Cal_Us_Service() in zdinlinef.h
663 * - if macp->bTxBurstEnable is enabled, then multiply by 4
664 * - bTxBurstEnable is never set in the vendor driver
665 *
666 * SERVICE:
667 * - "for PLCP configuration"
668 * - always 0 except in some situations at 802.11b 11M
669 * - see line 53 of zdinlinef.h
670 */
671 cs->service = 0;
672 r = zd_calc_tx_length_us(&cs->service, ZD_CS_RATE(cs->modulation),
673 le16_to_cpu(cs->tx_length));
674 if (r < 0)
675 return r;
676 cs->current_length = cpu_to_le16(r);
677
678 if (next_frag_len == 0) {
679 cs->next_frame_length = 0;
680 } else {
681 r = zd_calc_tx_length_us(NULL, ZD_CS_RATE(cs->modulation),
682 next_frag_len);
683 if (r < 0)
684 return r;
685 cs->next_frame_length = cpu_to_le16(r);
686 }
687
688 return 0;
689}
690
691static int zd_mac_tx(struct zd_mac *mac, struct ieee80211_txb *txb, int pri)
692{
693 int i, r;
694
695 for (i = 0; i < txb->nr_frags; i++) {
696 struct sk_buff *skb = txb->fragments[i];
697
698 r = fill_ctrlset(mac, txb, i);
699 if (r)
700 return r;
701 r = zd_usb_tx(&mac->chip.usb, skb->data, skb->len);
702 if (r)
703 return r;
704 }
705
706 /* FIXME: shouldn't this be handled by the upper layers? */
707 mac->netdev->trans_start = jiffies;
708
709 ieee80211_txb_free(txb);
710 return 0;
711}
712
713struct zd_rt_hdr {
714 struct ieee80211_radiotap_header rt_hdr;
715 u8 rt_flags;
716 u8 rt_rate;
717 u16 rt_channel;
718 u16 rt_chbitmask;
719} __attribute__((packed));
720
721static void fill_rt_header(void *buffer, struct zd_mac *mac,
722 const struct ieee80211_rx_stats *stats,
723 const struct rx_status *status)
724{
725 struct zd_rt_hdr *hdr = buffer;
726
727 hdr->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
728 hdr->rt_hdr.it_pad = 0;
729 hdr->rt_hdr.it_len = cpu_to_le16(sizeof(struct zd_rt_hdr));
730 hdr->rt_hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
731 (1 << IEEE80211_RADIOTAP_CHANNEL) |
732 (1 << IEEE80211_RADIOTAP_RATE));
733
734 hdr->rt_flags = 0;
735 if (status->decryption_type & (ZD_RX_WEP64|ZD_RX_WEP128|ZD_RX_WEP256))
736 hdr->rt_flags |= IEEE80211_RADIOTAP_F_WEP;
737
738 hdr->rt_rate = stats->rate / 5;
739
740 /* FIXME: 802.11a */
741 hdr->rt_channel = cpu_to_le16(ieee80211chan2mhz(
742 _zd_chip_get_channel(&mac->chip)));
743 hdr->rt_chbitmask = cpu_to_le16(IEEE80211_CHAN_2GHZ |
744 ((status->frame_status & ZD_RX_FRAME_MODULATION_MASK) ==
745 ZD_RX_OFDM ? IEEE80211_CHAN_OFDM : IEEE80211_CHAN_CCK));
746}
747
748/* Returns 1 if the data packet is for us and 0 otherwise. */
749static int is_data_packet_for_us(struct ieee80211_device *ieee,
750 struct ieee80211_hdr_4addr *hdr)
751{
752 struct net_device *netdev = ieee->dev;
753 u16 fc = le16_to_cpu(hdr->frame_ctl);
754
755 ZD_ASSERT(WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA);
756
757 switch (ieee->iw_mode) {
758 case IW_MODE_ADHOC:
759 if ((fc & (IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS)) != 0 ||
760 memcmp(hdr->addr3, ieee->bssid, ETH_ALEN) != 0)
761 return 0;
762 break;
763 case IW_MODE_AUTO:
764 case IW_MODE_INFRA:
765 if ((fc & (IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS)) !=
766 IEEE80211_FCTL_FROMDS ||
767 memcmp(hdr->addr2, ieee->bssid, ETH_ALEN) != 0)
768 return 0;
769 break;
770 default:
771 ZD_ASSERT(ieee->iw_mode != IW_MODE_MONITOR);
772 return 0;
773 }
774
775 return memcmp(hdr->addr1, netdev->dev_addr, ETH_ALEN) == 0 ||
776 is_multicast_ether_addr(hdr->addr1) ||
777 (netdev->flags & IFF_PROMISC);
778}
779
780/* Filters receiving packets. If it returns 1 send it to ieee80211_rx, if 0
781 * return. If an error is detected -EINVAL is returned. ieee80211_rx_mgt() is
782 * called here.
783 *
784 * It has been based on ieee80211_rx_any.
785 */
786static int filter_rx(struct ieee80211_device *ieee,
787 const u8 *buffer, unsigned int length,
788 struct ieee80211_rx_stats *stats)
789{
790 struct ieee80211_hdr_4addr *hdr;
791 u16 fc;
792
793 if (ieee->iw_mode == IW_MODE_MONITOR)
794 return 1;
795
796 hdr = (struct ieee80211_hdr_4addr *)buffer;
797 fc = le16_to_cpu(hdr->frame_ctl);
798 if ((fc & IEEE80211_FCTL_VERS) != 0)
799 return -EINVAL;
800
801 switch (WLAN_FC_GET_TYPE(fc)) {
802 case IEEE80211_FTYPE_MGMT:
803 if (length < sizeof(struct ieee80211_hdr_3addr))
804 return -EINVAL;
805 ieee80211_rx_mgt(ieee, hdr, stats);
806 return 0;
807 case IEEE80211_FTYPE_CTL:
808 /* Ignore invalid short buffers */
809 return 0;
810 case IEEE80211_FTYPE_DATA:
811 if (length < sizeof(struct ieee80211_hdr_3addr))
812 return -EINVAL;
813 return is_data_packet_for_us(ieee, hdr);
814 }
815
816 return -EINVAL;
817}
818
819static void update_qual_rssi(struct zd_mac *mac,
820 const u8 *buffer, unsigned int length,
821 u8 qual_percent, u8 rssi_percent)
822{
823 unsigned long flags;
824 struct ieee80211_hdr_3addr *hdr;
825 int i;
826
827 hdr = (struct ieee80211_hdr_3addr *)buffer;
828 if (length < offsetof(struct ieee80211_hdr_3addr, addr3))
829 return;
830 if (memcmp(hdr->addr2, zd_mac_to_ieee80211(mac)->bssid, ETH_ALEN) != 0)
831 return;
832
833 spin_lock_irqsave(&mac->lock, flags);
834 i = mac->stats_count % ZD_MAC_STATS_BUFFER_SIZE;
835 mac->qual_buffer[i] = qual_percent;
836 mac->rssi_buffer[i] = rssi_percent;
837 mac->stats_count++;
838 spin_unlock_irqrestore(&mac->lock, flags);
839}
840
841static int fill_rx_stats(struct ieee80211_rx_stats *stats,
842 const struct rx_status **pstatus,
843 struct zd_mac *mac,
844 const u8 *buffer, unsigned int length)
845{
846 const struct rx_status *status;
847
848 *pstatus = status = zd_tail(buffer, length, sizeof(struct rx_status));
849 if (status->frame_status & ZD_RX_ERROR) {
850 /* FIXME: update? */
851 return -EINVAL;
852 }
853 memset(stats, 0, sizeof(struct ieee80211_rx_stats));
854 stats->len = length - (ZD_PLCP_HEADER_SIZE + IEEE80211_FCS_LEN +
855 + sizeof(struct rx_status));
856 /* FIXME: 802.11a */
857 stats->freq = IEEE80211_24GHZ_BAND;
858 stats->received_channel = _zd_chip_get_channel(&mac->chip);
859 stats->rssi = zd_rx_strength_percent(status->signal_strength);
860 stats->signal = zd_rx_qual_percent(buffer,
861 length - sizeof(struct rx_status),
862 status);
863 stats->mask = IEEE80211_STATMASK_RSSI | IEEE80211_STATMASK_SIGNAL;
864 stats->rate = zd_rx_rate(buffer, status);
865 if (stats->rate)
866 stats->mask |= IEEE80211_STATMASK_RATE;
867
868 return 0;
869}
870
871int zd_mac_rx(struct zd_mac *mac, const u8 *buffer, unsigned int length)
872{
873 int r;
874 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
875 struct ieee80211_rx_stats stats;
876 const struct rx_status *status;
877 struct sk_buff *skb;
878
879 if (length < ZD_PLCP_HEADER_SIZE + IEEE80211_1ADDR_LEN +
880 IEEE80211_FCS_LEN + sizeof(struct rx_status))
881 return -EINVAL;
882
883 r = fill_rx_stats(&stats, &status, mac, buffer, length);
884 if (r)
885 return r;
886
887 length -= ZD_PLCP_HEADER_SIZE+IEEE80211_FCS_LEN+
888 sizeof(struct rx_status);
889 buffer += ZD_PLCP_HEADER_SIZE;
890
891 update_qual_rssi(mac, buffer, length, stats.signal, stats.rssi);
892
893 r = filter_rx(ieee, buffer, length, &stats);
894 if (r <= 0)
895 return r;
896
897 skb = dev_alloc_skb(sizeof(struct zd_rt_hdr) + length);
898 if (!skb)
899 return -ENOMEM;
900 if (ieee->iw_mode == IW_MODE_MONITOR)
901 fill_rt_header(skb_put(skb, sizeof(struct zd_rt_hdr)), mac,
902 &stats, status);
903 memcpy(skb_put(skb, length), buffer, length);
904
905 r = ieee80211_rx(ieee, skb, &stats);
906 if (!r) {
907 ZD_ASSERT(in_irq());
908 dev_kfree_skb_irq(skb);
909 }
910 return 0;
911}
912
913static int netdev_tx(struct ieee80211_txb *txb, struct net_device *netdev,
914 int pri)
915{
916 return zd_mac_tx(zd_netdev_mac(netdev), txb, pri);
917}
918
919static void set_security(struct net_device *netdev,
920 struct ieee80211_security *sec)
921{
922 struct ieee80211_device *ieee = zd_netdev_ieee80211(netdev);
923 struct ieee80211_security *secinfo = &ieee->sec;
924 int keyidx;
925
926 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), "\n");
927
928 for (keyidx = 0; keyidx<WEP_KEYS; keyidx++)
929 if (sec->flags & (1<<keyidx)) {
930 secinfo->encode_alg[keyidx] = sec->encode_alg[keyidx];
931 secinfo->key_sizes[keyidx] = sec->key_sizes[keyidx];
932 memcpy(secinfo->keys[keyidx], sec->keys[keyidx],
933 SCM_KEY_LEN);
934 }
935
936 if (sec->flags & SEC_ACTIVE_KEY) {
937 secinfo->active_key = sec->active_key;
938 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
939 " .active_key = %d\n", sec->active_key);
940 }
941 if (sec->flags & SEC_UNICAST_GROUP) {
942 secinfo->unicast_uses_group = sec->unicast_uses_group;
943 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
944 " .unicast_uses_group = %d\n",
945 sec->unicast_uses_group);
946 }
947 if (sec->flags & SEC_LEVEL) {
948 secinfo->level = sec->level;
949 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
950 " .level = %d\n", sec->level);
951 }
952 if (sec->flags & SEC_ENABLED) {
953 secinfo->enabled = sec->enabled;
954 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
955 " .enabled = %d\n", sec->enabled);
956 }
957 if (sec->flags & SEC_ENCRYPT) {
958 secinfo->encrypt = sec->encrypt;
959 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
960 " .encrypt = %d\n", sec->encrypt);
961 }
962 if (sec->flags & SEC_AUTH_MODE) {
963 secinfo->auth_mode = sec->auth_mode;
964 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)),
965 " .auth_mode = %d\n", sec->auth_mode);
966 }
967}
968
969static void ieee_init(struct ieee80211_device *ieee)
970{
971 ieee->mode = IEEE_B | IEEE_G;
972 ieee->freq_band = IEEE80211_24GHZ_BAND;
973 ieee->modulation = IEEE80211_OFDM_MODULATION | IEEE80211_CCK_MODULATION;
974 ieee->tx_headroom = sizeof(struct zd_ctrlset);
975 ieee->set_security = set_security;
976 ieee->hard_start_xmit = netdev_tx;
977
978 /* Software encryption/decryption for now */
979 ieee->host_build_iv = 0;
980 ieee->host_encrypt = 1;
981 ieee->host_decrypt = 1;
982
983 /* FIXME: default to managed mode, until ieee80211 and zd1211rw can
984 * correctly support AUTO */
985 ieee->iw_mode = IW_MODE_INFRA;
986}
987
988static void softmac_init(struct ieee80211softmac_device *sm)
989{
990 sm->set_channel = set_channel;
991}
992
993struct iw_statistics *zd_mac_get_wireless_stats(struct net_device *ndev)
994{
995 struct zd_mac *mac = zd_netdev_mac(ndev);
996 struct iw_statistics *iw_stats = &mac->iw_stats;
997 unsigned int i, count, qual_total, rssi_total;
998
999 memset(iw_stats, 0, sizeof(struct iw_statistics));
1000 /* We are not setting the status, because ieee->state is not updated
1001 * at all and this driver doesn't track authentication state.
1002 */
1003 spin_lock_irq(&mac->lock);
1004 count = mac->stats_count < ZD_MAC_STATS_BUFFER_SIZE ?
1005 mac->stats_count : ZD_MAC_STATS_BUFFER_SIZE;
1006 qual_total = rssi_total = 0;
1007 for (i = 0; i < count; i++) {
1008 qual_total += mac->qual_buffer[i];
1009 rssi_total += mac->rssi_buffer[i];
1010 }
1011 spin_unlock_irq(&mac->lock);
1012 iw_stats->qual.updated = IW_QUAL_NOISE_INVALID;
1013 if (count > 0) {
1014 iw_stats->qual.qual = qual_total / count;
1015 iw_stats->qual.level = rssi_total / count;
1016 iw_stats->qual.updated |=
1017 IW_QUAL_QUAL_UPDATED|IW_QUAL_LEVEL_UPDATED;
1018 } else {
1019 iw_stats->qual.updated |=
1020 IW_QUAL_QUAL_INVALID|IW_QUAL_LEVEL_INVALID;
1021 }
1022 /* TODO: update counter */
1023 return iw_stats;
1024}
1025
1026#ifdef DEBUG
1027static const char* decryption_types[] = {
1028 [ZD_RX_NO_WEP] = "none",
1029 [ZD_RX_WEP64] = "WEP64",
1030 [ZD_RX_TKIP] = "TKIP",
1031 [ZD_RX_AES] = "AES",
1032 [ZD_RX_WEP128] = "WEP128",
1033 [ZD_RX_WEP256] = "WEP256",
1034};
1035
1036static const char *decryption_type_string(u8 type)
1037{
1038 const char *s;
1039
1040 if (type < ARRAY_SIZE(decryption_types)) {
1041 s = decryption_types[type];
1042 } else {
1043 s = NULL;
1044 }
1045 return s ? s : "unknown";
1046}
1047
1048static int is_ofdm(u8 frame_status)
1049{
1050 return (frame_status & ZD_RX_OFDM);
1051}
1052
1053void zd_dump_rx_status(const struct rx_status *status)
1054{
1055 const char* modulation;
1056 u8 quality;
1057
1058 if (is_ofdm(status->frame_status)) {
1059 modulation = "ofdm";
1060 quality = status->signal_quality_ofdm;
1061 } else {
1062 modulation = "cck";
1063 quality = status->signal_quality_cck;
1064 }
1065 pr_debug("rx status %s strength %#04x qual %#04x decryption %s\n",
1066 modulation, status->signal_strength, quality,
1067 decryption_type_string(status->decryption_type));
1068 if (status->frame_status & ZD_RX_ERROR) {
1069 pr_debug("rx error %s%s%s%s%s%s\n",
1070 (status->frame_status & ZD_RX_TIMEOUT_ERROR) ?
1071 "timeout " : "",
1072 (status->frame_status & ZD_RX_FIFO_OVERRUN_ERROR) ?
1073 "fifo " : "",
1074 (status->frame_status & ZD_RX_DECRYPTION_ERROR) ?
1075 "decryption " : "",
1076 (status->frame_status & ZD_RX_CRC32_ERROR) ?
1077 "crc32 " : "",
1078 (status->frame_status & ZD_RX_NO_ADDR1_MATCH_ERROR) ?
1079 "addr1 " : "",
1080 (status->frame_status & ZD_RX_CRC16_ERROR) ?
1081 "crc16" : "");
1082 }
1083}
1084#endif /* DEBUG */
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.h b/drivers/net/wireless/zd1211rw/zd_mac.h
new file mode 100644
index 000000000000..b3ba49b84634
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_mac.h
@@ -0,0 +1,193 @@
1/* zd_mac.h
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#ifndef _ZD_MAC_H
19#define _ZD_MAC_H
20
21#include <linux/wireless.h>
22#include <linux/kernel.h>
23#include <net/ieee80211.h>
24#include <net/ieee80211softmac.h>
25
26#include "zd_chip.h"
27#include "zd_netdev.h"
28
29struct zd_ctrlset {
30 u8 modulation;
31 __le16 tx_length;
32 u8 control;
33 /* stores only the difference to tx_length on ZD1211B */
34 __le16 packet_length;
35 __le16 current_length;
36 u8 service;
37 __le16 next_frame_length;
38} __attribute__((packed));
39
40#define ZD_CS_RESERVED_SIZE 25
41
42/* zd_crtlset field modulation */
43#define ZD_CS_RATE_MASK 0x0f
44#define ZD_CS_TYPE_MASK 0x10
45#define ZD_CS_RATE(modulation) ((modulation) & ZD_CS_RATE_MASK)
46#define ZD_CS_TYPE(modulation) ((modulation) & ZD_CS_TYPE_MASK)
47
48#define ZD_CS_CCK 0x00
49#define ZD_CS_OFDM 0x10
50
51#define ZD_CS_CCK_RATE_1M 0x00
52#define ZD_CS_CCK_RATE_2M 0x01
53#define ZD_CS_CCK_RATE_5_5M 0x02
54#define ZD_CS_CCK_RATE_11M 0x03
55/* The rates for OFDM are encoded as in the PLCP header. Use ZD_OFDM_RATE_*.
56 */
57
58/* bit 5 is preamble (when in CCK mode), or a/g selection (when in OFDM mode) */
59#define ZD_CS_CCK_PREA_LONG 0x00
60#define ZD_CS_CCK_PREA_SHORT 0x20
61#define ZD_CS_OFDM_MODE_11G 0x00
62#define ZD_CS_OFDM_MODE_11A 0x20
63
64/* zd_ctrlset control field */
65#define ZD_CS_NEED_RANDOM_BACKOFF 0x01
66#define ZD_CS_MULTICAST 0x02
67
68#define ZD_CS_FRAME_TYPE_MASK 0x0c
69#define ZD_CS_DATA_FRAME 0x00
70#define ZD_CS_PS_POLL_FRAME 0x04
71#define ZD_CS_MANAGEMENT_FRAME 0x08
72#define ZD_CS_NO_SEQUENCE_CTL_FRAME 0x0c
73
74#define ZD_CS_WAKE_DESTINATION 0x10
75#define ZD_CS_RTS 0x20
76#define ZD_CS_ENCRYPT 0x40
77#define ZD_CS_SELF_CTS 0x80
78
79/* Incoming frames are prepended by a PLCP header */
80#define ZD_PLCP_HEADER_SIZE 5
81
82struct rx_length_info {
83 __le16 length[3];
84 __le16 tag;
85} __attribute__((packed));
86
87#define RX_LENGTH_INFO_TAG 0x697e
88
89struct rx_status {
90 u8 signal_quality_cck;
91 /* rssi */
92 u8 signal_strength;
93 u8 signal_quality_ofdm;
94 u8 decryption_type;
95 u8 frame_status;
96} __attribute__((packed));
97
98/* rx_status field decryption_type */
99#define ZD_RX_NO_WEP 0
100#define ZD_RX_WEP64 1
101#define ZD_RX_TKIP 2
102#define ZD_RX_AES 4
103#define ZD_RX_WEP128 5
104#define ZD_RX_WEP256 6
105
106/* rx_status field frame_status */
107#define ZD_RX_FRAME_MODULATION_MASK 0x01
108#define ZD_RX_CCK 0x00
109#define ZD_RX_OFDM 0x01
110
111#define ZD_RX_TIMEOUT_ERROR 0x02
112#define ZD_RX_FIFO_OVERRUN_ERROR 0x04
113#define ZD_RX_DECRYPTION_ERROR 0x08
114#define ZD_RX_CRC32_ERROR 0x10
115#define ZD_RX_NO_ADDR1_MATCH_ERROR 0x20
116#define ZD_RX_CRC16_ERROR 0x40
117#define ZD_RX_ERROR 0x80
118
119enum mac_flags {
120 MAC_FIXED_CHANNEL = 0x01,
121};
122
123#define ZD_MAC_STATS_BUFFER_SIZE 16
124
125struct zd_mac {
126 struct net_device *netdev;
127 struct zd_chip chip;
128 spinlock_t lock;
129 /* Unlocked reading possible */
130 struct iw_statistics iw_stats;
131 unsigned int stats_count;
132 u8 qual_buffer[ZD_MAC_STATS_BUFFER_SIZE];
133 u8 rssi_buffer[ZD_MAC_STATS_BUFFER_SIZE];
134 u8 regdomain;
135 u8 default_regdomain;
136 u8 requested_channel;
137};
138
139static inline struct ieee80211_device *zd_mac_to_ieee80211(struct zd_mac *mac)
140{
141 return zd_netdev_ieee80211(mac->netdev);
142}
143
144static inline struct zd_mac *zd_netdev_mac(struct net_device *netdev)
145{
146 return ieee80211softmac_priv(netdev);
147}
148
149static inline struct zd_mac *zd_chip_to_mac(struct zd_chip *chip)
150{
151 return container_of(chip, struct zd_mac, chip);
152}
153
154static inline struct zd_mac *zd_usb_to_mac(struct zd_usb *usb)
155{
156 return zd_chip_to_mac(zd_usb_to_chip(usb));
157}
158
159#define zd_mac_dev(mac) (zd_chip_dev(&(mac)->chip))
160
161int zd_mac_init(struct zd_mac *mac,
162 struct net_device *netdev,
163 struct usb_interface *intf);
164void zd_mac_clear(struct zd_mac *mac);
165
166int zd_mac_init_hw(struct zd_mac *mac, u8 device_type);
167
168int zd_mac_open(struct net_device *netdev);
169int zd_mac_stop(struct net_device *netdev);
170int zd_mac_set_mac_address(struct net_device *dev, void *p);
171
172int zd_mac_rx(struct zd_mac *mac, const u8 *buffer, unsigned int length);
173
174int zd_mac_set_regdomain(struct zd_mac *zd_mac, u8 regdomain);
175u8 zd_mac_get_regdomain(struct zd_mac *zd_mac);
176
177int zd_mac_request_channel(struct zd_mac *mac, u8 channel);
178int zd_mac_get_channel(struct zd_mac *mac, u8 *channel, u8 *flags);
179
180int zd_mac_set_mode(struct zd_mac *mac, u32 mode);
181int zd_mac_get_mode(struct zd_mac *mac, u32 *mode);
182
183int zd_mac_get_range(struct zd_mac *mac, struct iw_range *range);
184
185struct iw_statistics *zd_mac_get_wireless_stats(struct net_device *ndev);
186
187#ifdef DEBUG
188void zd_dump_rx_status(const struct rx_status *status);
189#else
190#define zd_dump_rx_status(status)
191#endif /* DEBUG */
192
193#endif /* _ZD_MAC_H */
diff --git a/drivers/net/wireless/zd1211rw/zd_netdev.c b/drivers/net/wireless/zd1211rw/zd_netdev.c
new file mode 100644
index 000000000000..9df232c2c863
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_netdev.c
@@ -0,0 +1,267 @@
1/* zd_netdev.c
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#include <linux/netdevice.h>
19#include <linux/etherdevice.h>
20#include <linux/skbuff.h>
21#include <net/ieee80211.h>
22#include <net/ieee80211softmac.h>
23#include <net/ieee80211softmac_wx.h>
24#include <net/iw_handler.h>
25
26#include "zd_def.h"
27#include "zd_netdev.h"
28#include "zd_mac.h"
29#include "zd_ieee80211.h"
30
31/* Region 0 means reset regdomain to default. */
32static int zd_set_regdomain(struct net_device *netdev,
33 struct iw_request_info *info,
34 union iwreq_data *req, char *extra)
35{
36 const u8 *regdomain = (u8 *)req;
37 return zd_mac_set_regdomain(zd_netdev_mac(netdev), *regdomain);
38}
39
40static int zd_get_regdomain(struct net_device *netdev,
41 struct iw_request_info *info,
42 union iwreq_data *req, char *extra)
43{
44 u8 *regdomain = (u8 *)req;
45 if (!regdomain)
46 return -EINVAL;
47 *regdomain = zd_mac_get_regdomain(zd_netdev_mac(netdev));
48 return 0;
49}
50
51static const struct iw_priv_args zd_priv_args[] = {
52 {
53 .cmd = ZD_PRIV_SET_REGDOMAIN,
54 .set_args = IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
55 .name = "set_regdomain",
56 },
57 {
58 .cmd = ZD_PRIV_GET_REGDOMAIN,
59 .get_args = IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
60 .name = "get_regdomain",
61 },
62};
63
64#define PRIV_OFFSET(x) [(x)-SIOCIWFIRSTPRIV]
65
66static const iw_handler zd_priv_handler[] = {
67 PRIV_OFFSET(ZD_PRIV_SET_REGDOMAIN) = zd_set_regdomain,
68 PRIV_OFFSET(ZD_PRIV_GET_REGDOMAIN) = zd_get_regdomain,
69};
70
71static int iw_get_name(struct net_device *netdev,
72 struct iw_request_info *info,
73 union iwreq_data *req, char *extra)
74{
75 /* FIXME: check whether 802.11a will also supported, add also
76 * zd1211B, if we support it.
77 */
78 strlcpy(req->name, "802.11g zd1211", IFNAMSIZ);
79 return 0;
80}
81
82static int iw_set_freq(struct net_device *netdev,
83 struct iw_request_info *info,
84 union iwreq_data *req, char *extra)
85{
86 int r;
87 struct zd_mac *mac = zd_netdev_mac(netdev);
88 struct iw_freq *freq = &req->freq;
89 u8 channel;
90
91 r = zd_find_channel(&channel, freq);
92 if (r < 0)
93 return r;
94 r = zd_mac_request_channel(mac, channel);
95 return r;
96}
97
98static int iw_get_freq(struct net_device *netdev,
99 struct iw_request_info *info,
100 union iwreq_data *req, char *extra)
101{
102 int r;
103 struct zd_mac *mac = zd_netdev_mac(netdev);
104 struct iw_freq *freq = &req->freq;
105 u8 channel;
106 u8 flags;
107
108 r = zd_mac_get_channel(mac, &channel, &flags);
109 if (r)
110 return r;
111
112 freq->flags = (flags & MAC_FIXED_CHANNEL) ?
113 IW_FREQ_FIXED : IW_FREQ_AUTO;
114 dev_dbg_f(zd_mac_dev(mac), "channel %s\n",
115 (flags & MAC_FIXED_CHANNEL) ? "fixed" : "auto");
116 return zd_channel_to_freq(freq, channel);
117}
118
119static int iw_set_mode(struct net_device *netdev,
120 struct iw_request_info *info,
121 union iwreq_data *req, char *extra)
122{
123 return zd_mac_set_mode(zd_netdev_mac(netdev), req->mode);
124}
125
126static int iw_get_mode(struct net_device *netdev,
127 struct iw_request_info *info,
128 union iwreq_data *req, char *extra)
129{
130 return zd_mac_get_mode(zd_netdev_mac(netdev), &req->mode);
131}
132
133static int iw_get_range(struct net_device *netdev,
134 struct iw_request_info *info,
135 union iwreq_data *req, char *extra)
136{
137 struct iw_range *range = (struct iw_range *)extra;
138
139 dev_dbg_f(zd_mac_dev(zd_netdev_mac(netdev)), "\n");
140 req->data.length = sizeof(*range);
141 return zd_mac_get_range(zd_netdev_mac(netdev), range);
142}
143
144static int iw_set_encode(struct net_device *netdev,
145 struct iw_request_info *info,
146 union iwreq_data *data,
147 char *extra)
148{
149 return ieee80211_wx_set_encode(zd_netdev_ieee80211(netdev), info,
150 data, extra);
151}
152
153static int iw_get_encode(struct net_device *netdev,
154 struct iw_request_info *info,
155 union iwreq_data *data,
156 char *extra)
157{
158 return ieee80211_wx_get_encode(zd_netdev_ieee80211(netdev), info,
159 data, extra);
160}
161
162static int iw_set_encodeext(struct net_device *netdev,
163 struct iw_request_info *info,
164 union iwreq_data *data,
165 char *extra)
166{
167 return ieee80211_wx_set_encodeext(zd_netdev_ieee80211(netdev), info,
168 data, extra);
169}
170
171static int iw_get_encodeext(struct net_device *netdev,
172 struct iw_request_info *info,
173 union iwreq_data *data,
174 char *extra)
175{
176 return ieee80211_wx_get_encodeext(zd_netdev_ieee80211(netdev), info,
177 data, extra);
178}
179
180#define WX(x) [(x)-SIOCIWFIRST]
181
182static const iw_handler zd_standard_iw_handlers[] = {
183 WX(SIOCGIWNAME) = iw_get_name,
184 WX(SIOCSIWFREQ) = iw_set_freq,
185 WX(SIOCGIWFREQ) = iw_get_freq,
186 WX(SIOCSIWMODE) = iw_set_mode,
187 WX(SIOCGIWMODE) = iw_get_mode,
188 WX(SIOCGIWRANGE) = iw_get_range,
189 WX(SIOCSIWENCODE) = iw_set_encode,
190 WX(SIOCGIWENCODE) = iw_get_encode,
191 WX(SIOCSIWENCODEEXT) = iw_set_encodeext,
192 WX(SIOCGIWENCODEEXT) = iw_get_encodeext,
193 WX(SIOCSIWAUTH) = ieee80211_wx_set_auth,
194 WX(SIOCGIWAUTH) = ieee80211_wx_get_auth,
195 WX(SIOCSIWSCAN) = ieee80211softmac_wx_trigger_scan,
196 WX(SIOCGIWSCAN) = ieee80211softmac_wx_get_scan_results,
197 WX(SIOCSIWESSID) = ieee80211softmac_wx_set_essid,
198 WX(SIOCGIWESSID) = ieee80211softmac_wx_get_essid,
199 WX(SIOCSIWAP) = ieee80211softmac_wx_set_wap,
200 WX(SIOCGIWAP) = ieee80211softmac_wx_get_wap,
201 WX(SIOCSIWRATE) = ieee80211softmac_wx_set_rate,
202 WX(SIOCGIWRATE) = ieee80211softmac_wx_get_rate,
203 WX(SIOCSIWGENIE) = ieee80211softmac_wx_set_genie,
204 WX(SIOCGIWGENIE) = ieee80211softmac_wx_get_genie,
205 WX(SIOCSIWMLME) = ieee80211softmac_wx_set_mlme,
206};
207
208static const struct iw_handler_def iw_handler_def = {
209 .standard = zd_standard_iw_handlers,
210 .num_standard = ARRAY_SIZE(zd_standard_iw_handlers),
211 .private = zd_priv_handler,
212 .num_private = ARRAY_SIZE(zd_priv_handler),
213 .private_args = zd_priv_args,
214 .num_private_args = ARRAY_SIZE(zd_priv_args),
215 .get_wireless_stats = zd_mac_get_wireless_stats,
216};
217
218struct net_device *zd_netdev_alloc(struct usb_interface *intf)
219{
220 int r;
221 struct net_device *netdev;
222 struct zd_mac *mac;
223
224 netdev = alloc_ieee80211softmac(sizeof(struct zd_mac));
225 if (!netdev) {
226 dev_dbg_f(&intf->dev, "out of memory\n");
227 return NULL;
228 }
229
230 mac = zd_netdev_mac(netdev);
231 r = zd_mac_init(mac, netdev, intf);
232 if (r) {
233 usb_set_intfdata(intf, NULL);
234 free_ieee80211(netdev);
235 return NULL;
236 }
237
238 SET_MODULE_OWNER(netdev);
239 SET_NETDEV_DEV(netdev, &intf->dev);
240
241 dev_dbg_f(&intf->dev, "netdev->flags %#06hx\n", netdev->flags);
242 dev_dbg_f(&intf->dev, "netdev->features %#010lx\n", netdev->features);
243
244 netdev->open = zd_mac_open;
245 netdev->stop = zd_mac_stop;
246 /* netdev->get_stats = */
247 /* netdev->set_multicast_list = */
248 netdev->set_mac_address = zd_mac_set_mac_address;
249 netdev->wireless_handlers = &iw_handler_def;
250 /* netdev->ethtool_ops = */
251
252 return netdev;
253}
254
255void zd_netdev_free(struct net_device *netdev)
256{
257 if (!netdev)
258 return;
259
260 zd_mac_clear(zd_netdev_mac(netdev));
261 free_ieee80211(netdev);
262}
263
264void zd_netdev_disconnect(struct net_device *netdev)
265{
266 unregister_netdev(netdev);
267}
diff --git a/drivers/net/wireless/zd1211rw/zd_netdev.h b/drivers/net/wireless/zd1211rw/zd_netdev.h
new file mode 100644
index 000000000000..374a957073c1
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_netdev.h
@@ -0,0 +1,45 @@
1/* zd_netdev.h: Header for net device related functions.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#ifndef _ZD_NETDEV_H
19#define _ZD_NETDEV_H
20
21#include <linux/usb.h>
22#include <linux/netdevice.h>
23#include <net/ieee80211.h>
24
25#define ZD_PRIV_SET_REGDOMAIN (SIOCIWFIRSTPRIV)
26#define ZD_PRIV_GET_REGDOMAIN (SIOCIWFIRSTPRIV+1)
27
28static inline struct ieee80211_device *zd_netdev_ieee80211(
29 struct net_device *ndev)
30{
31 return netdev_priv(ndev);
32}
33
34static inline struct net_device *zd_ieee80211_to_netdev(
35 struct ieee80211_device *ieee)
36{
37 return ieee->dev;
38}
39
40struct net_device *zd_netdev_alloc(struct usb_interface *intf);
41void zd_netdev_free(struct net_device *netdev);
42
43void zd_netdev_disconnect(struct net_device *netdev);
44
45#endif /* _ZD_NETDEV_H */
diff --git a/drivers/net/wireless/zd1211rw/zd_rf.c b/drivers/net/wireless/zd1211rw/zd_rf.c
new file mode 100644
index 000000000000..d3770d2c61bc
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_rf.c
@@ -0,0 +1,151 @@
1/* zd_rf.c
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#include <linux/errno.h>
19#include <linux/string.h>
20
21#include "zd_def.h"
22#include "zd_rf.h"
23#include "zd_ieee80211.h"
24#include "zd_chip.h"
25
26static const char *rfs[] = {
27 [0] = "unknown RF0",
28 [1] = "unknown RF1",
29 [UW2451_RF] = "UW2451_RF",
30 [UCHIP_RF] = "UCHIP_RF",
31 [AL2230_RF] = "AL2230_RF",
32 [AL7230B_RF] = "AL7230B_RF",
33 [THETA_RF] = "THETA_RF",
34 [AL2210_RF] = "AL2210_RF",
35 [MAXIM_NEW_RF] = "MAXIM_NEW_RF",
36 [UW2453_RF] = "UW2453_RF",
37 [AL2230S_RF] = "AL2230S_RF",
38 [RALINK_RF] = "RALINK_RF",
39 [INTERSIL_RF] = "INTERSIL_RF",
40 [RF2959_RF] = "RF2959_RF",
41 [MAXIM_NEW2_RF] = "MAXIM_NEW2_RF",
42 [PHILIPS_RF] = "PHILIPS_RF",
43};
44
45const char *zd_rf_name(u8 type)
46{
47 if (type & 0xf0)
48 type = 0;
49 return rfs[type];
50}
51
52void zd_rf_init(struct zd_rf *rf)
53{
54 memset(rf, 0, sizeof(*rf));
55}
56
57void zd_rf_clear(struct zd_rf *rf)
58{
59 memset(rf, 0, sizeof(*rf));
60}
61
62int zd_rf_init_hw(struct zd_rf *rf, u8 type)
63{
64 int r, t;
65 struct zd_chip *chip = zd_rf_to_chip(rf);
66
67 ZD_ASSERT(mutex_is_locked(&chip->mutex));
68 switch (type) {
69 case RF2959_RF:
70 r = zd_rf_init_rf2959(rf);
71 if (r)
72 return r;
73 break;
74 case AL2230_RF:
75 r = zd_rf_init_al2230(rf);
76 if (r)
77 return r;
78 break;
79 default:
80 dev_err(zd_chip_dev(chip),
81 "RF %s %#x is not supported\n", zd_rf_name(type), type);
82 rf->type = 0;
83 return -ENODEV;
84 }
85
86 rf->type = type;
87
88 r = zd_chip_lock_phy_regs(chip);
89 if (r)
90 return r;
91 t = rf->init_hw(rf);
92 r = zd_chip_unlock_phy_regs(chip);
93 if (t)
94 r = t;
95 return r;
96}
97
98int zd_rf_scnprint_id(struct zd_rf *rf, char *buffer, size_t size)
99{
100 return scnprintf(buffer, size, "%s", zd_rf_name(rf->type));
101}
102
103int zd_rf_set_channel(struct zd_rf *rf, u8 channel)
104{
105 int r;
106
107 ZD_ASSERT(mutex_is_locked(&zd_rf_to_chip(rf)->mutex));
108 if (channel < MIN_CHANNEL24)
109 return -EINVAL;
110 if (channel > MAX_CHANNEL24)
111 return -EINVAL;
112 dev_dbg_f(zd_chip_dev(zd_rf_to_chip(rf)), "channel: %d\n", channel);
113
114 r = rf->set_channel(rf, channel);
115 if (r >= 0)
116 rf->channel = channel;
117 return r;
118}
119
120int zd_switch_radio_on(struct zd_rf *rf)
121{
122 int r, t;
123 struct zd_chip *chip = zd_rf_to_chip(rf);
124
125 ZD_ASSERT(mutex_is_locked(&chip->mutex));
126 r = zd_chip_lock_phy_regs(chip);
127 if (r)
128 return r;
129 t = rf->switch_radio_on(rf);
130 r = zd_chip_unlock_phy_regs(chip);
131 if (t)
132 r = t;
133 return r;
134}
135
136int zd_switch_radio_off(struct zd_rf *rf)
137{
138 int r, t;
139 struct zd_chip *chip = zd_rf_to_chip(rf);
140
141 /* TODO: move phy regs handling to zd_chip */
142 ZD_ASSERT(mutex_is_locked(&chip->mutex));
143 r = zd_chip_lock_phy_regs(chip);
144 if (r)
145 return r;
146 t = rf->switch_radio_off(rf);
147 r = zd_chip_unlock_phy_regs(chip);
148 if (t)
149 r = t;
150 return r;
151}
diff --git a/drivers/net/wireless/zd1211rw/zd_rf.h b/drivers/net/wireless/zd1211rw/zd_rf.h
new file mode 100644
index 000000000000..ea30f693fcc8
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_rf.h
@@ -0,0 +1,82 @@
1/* zd_rf.h
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#ifndef _ZD_RF_H
19#define _ZD_RF_H
20
21#include "zd_types.h"
22
23#define UW2451_RF 0x2
24#define UCHIP_RF 0x3
25#define AL2230_RF 0x4
26#define AL7230B_RF 0x5 /* a,b,g */
27#define THETA_RF 0x6
28#define AL2210_RF 0x7
29#define MAXIM_NEW_RF 0x8
30#define UW2453_RF 0x9
31#define AL2230S_RF 0xa
32#define RALINK_RF 0xb
33#define INTERSIL_RF 0xc
34#define RF2959_RF 0xd
35#define MAXIM_NEW2_RF 0xe
36#define PHILIPS_RF 0xf
37
38#define RF_CHANNEL(ch) [(ch)-1]
39
40/* Provides functions of the RF transceiver. */
41
42enum {
43 RF_REG_BITS = 6,
44 RF_VALUE_BITS = 18,
45 RF_RV_BITS = RF_REG_BITS + RF_VALUE_BITS,
46};
47
48struct zd_rf {
49 u8 type;
50
51 u8 channel;
52 /*
53 * Whether this RF should patch the 6M band edge
54 * (assuming E2P_POD agrees)
55 */
56 u8 patch_6m_band_edge:1;
57
58 /* RF-specific functions */
59 int (*init_hw)(struct zd_rf *rf);
60 int (*set_channel)(struct zd_rf *rf, u8 channel);
61 int (*switch_radio_on)(struct zd_rf *rf);
62 int (*switch_radio_off)(struct zd_rf *rf);
63};
64
65const char *zd_rf_name(u8 type);
66void zd_rf_init(struct zd_rf *rf);
67void zd_rf_clear(struct zd_rf *rf);
68int zd_rf_init_hw(struct zd_rf *rf, u8 type);
69
70int zd_rf_scnprint_id(struct zd_rf *rf, char *buffer, size_t size);
71
72int zd_rf_set_channel(struct zd_rf *rf, u8 channel);
73
74int zd_switch_radio_on(struct zd_rf *rf);
75int zd_switch_radio_off(struct zd_rf *rf);
76
77/* Functions for individual RF chips */
78
79int zd_rf_init_rf2959(struct zd_rf *rf);
80int zd_rf_init_al2230(struct zd_rf *rf);
81
82#endif /* _ZD_RF_H */
diff --git a/drivers/net/wireless/zd1211rw/zd_rf_al2230.c b/drivers/net/wireless/zd1211rw/zd_rf_al2230.c
new file mode 100644
index 000000000000..0948b25f660d
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_rf_al2230.c
@@ -0,0 +1,308 @@
1/* zd_rf_al2230.c: Functions for the AL2230 RF controller
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#include <linux/kernel.h>
19
20#include "zd_rf.h"
21#include "zd_usb.h"
22#include "zd_chip.h"
23
24static const u32 al2230_table[][3] = {
25 RF_CHANNEL( 1) = { 0x03f790, 0x033331, 0x00000d, },
26 RF_CHANNEL( 2) = { 0x03f790, 0x0b3331, 0x00000d, },
27 RF_CHANNEL( 3) = { 0x03e790, 0x033331, 0x00000d, },
28 RF_CHANNEL( 4) = { 0x03e790, 0x0b3331, 0x00000d, },
29 RF_CHANNEL( 5) = { 0x03f7a0, 0x033331, 0x00000d, },
30 RF_CHANNEL( 6) = { 0x03f7a0, 0x0b3331, 0x00000d, },
31 RF_CHANNEL( 7) = { 0x03e7a0, 0x033331, 0x00000d, },
32 RF_CHANNEL( 8) = { 0x03e7a0, 0x0b3331, 0x00000d, },
33 RF_CHANNEL( 9) = { 0x03f7b0, 0x033331, 0x00000d, },
34 RF_CHANNEL(10) = { 0x03f7b0, 0x0b3331, 0x00000d, },
35 RF_CHANNEL(11) = { 0x03e7b0, 0x033331, 0x00000d, },
36 RF_CHANNEL(12) = { 0x03e7b0, 0x0b3331, 0x00000d, },
37 RF_CHANNEL(13) = { 0x03f7c0, 0x033331, 0x00000d, },
38 RF_CHANNEL(14) = { 0x03e7c0, 0x066661, 0x00000d, },
39};
40
41static int zd1211_al2230_init_hw(struct zd_rf *rf)
42{
43 int r;
44 struct zd_chip *chip = zd_rf_to_chip(rf);
45
46 static const struct zd_ioreq16 ioreqs[] = {
47 { CR15, 0x20 }, { CR23, 0x40 }, { CR24, 0x20 },
48 { CR26, 0x11 }, { CR28, 0x3e }, { CR29, 0x00 },
49 { CR44, 0x33 }, { CR106, 0x2a }, { CR107, 0x1a },
50 { CR109, 0x09 }, { CR110, 0x27 }, { CR111, 0x2b },
51 { CR112, 0x2b }, { CR119, 0x0a }, { CR10, 0x89 },
52 /* for newest (3rd cut) AL2300 */
53 { CR17, 0x28 },
54 { CR26, 0x93 }, { CR34, 0x30 },
55 /* for newest (3rd cut) AL2300 */
56 { CR35, 0x3e },
57 { CR41, 0x24 }, { CR44, 0x32 },
58 /* for newest (3rd cut) AL2300 */
59 { CR46, 0x96 },
60 { CR47, 0x1e }, { CR79, 0x58 }, { CR80, 0x30 },
61 { CR81, 0x30 }, { CR87, 0x0a }, { CR89, 0x04 },
62 { CR92, 0x0a }, { CR99, 0x28 }, { CR100, 0x00 },
63 { CR101, 0x13 }, { CR102, 0x27 }, { CR106, 0x24 },
64 { CR107, 0x2a }, { CR109, 0x09 }, { CR110, 0x13 },
65 { CR111, 0x1f }, { CR112, 0x1f }, { CR113, 0x27 },
66 { CR114, 0x27 },
67 /* for newest (3rd cut) AL2300 */
68 { CR115, 0x24 },
69 { CR116, 0x24 }, { CR117, 0xf4 }, { CR118, 0xfc },
70 { CR119, 0x10 }, { CR120, 0x4f }, { CR121, 0x77 },
71 { CR122, 0xe0 }, { CR137, 0x88 }, { CR252, 0xff },
72 { CR253, 0xff },
73
74 /* These following happen separately in the vendor driver */
75 { },
76
77 /* shdnb(PLL_ON)=0 */
78 { CR251, 0x2f },
79 /* shdnb(PLL_ON)=1 */
80 { CR251, 0x3f },
81 { CR138, 0x28 }, { CR203, 0x06 },
82 };
83
84 static const u32 rv[] = {
85 /* Channel 1 */
86 0x03f790,
87 0x033331,
88 0x00000d,
89
90 0x0b3331,
91 0x03b812,
92 0x00fff3,
93 0x000da4,
94 0x0f4dc5, /* fix freq shift, 0x04edc5 */
95 0x0805b6,
96 0x011687,
97 0x000688,
98 0x0403b9, /* external control TX power (CR31) */
99 0x00dbba,
100 0x00099b,
101 0x0bdffc,
102 0x00000d,
103 0x00500f,
104
105 /* These writes happen separately in the vendor driver */
106 0x00d00f,
107 0x004c0f,
108 0x00540f,
109 0x00700f,
110 0x00500f,
111 };
112
113 r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
114 if (r)
115 return r;
116
117 r = zd_rfwritev_locked(chip, rv, ARRAY_SIZE(rv), RF_RV_BITS);
118 if (r)
119 return r;
120
121 return 0;
122}
123
124static int zd1211b_al2230_init_hw(struct zd_rf *rf)
125{
126 int r;
127 struct zd_chip *chip = zd_rf_to_chip(rf);
128
129 static const struct zd_ioreq16 ioreqs1[] = {
130 { CR10, 0x89 }, { CR15, 0x20 },
131 { CR17, 0x2B }, /* for newest(3rd cut) AL2230 */
132 { CR23, 0x40 }, { CR24, 0x20 }, { CR26, 0x93 },
133 { CR28, 0x3e }, { CR29, 0x00 },
134 { CR33, 0x28 }, /* 5621 */
135 { CR34, 0x30 },
136 { CR35, 0x3e }, /* for newest(3rd cut) AL2230 */
137 { CR41, 0x24 }, { CR44, 0x32 },
138 { CR46, 0x99 }, /* for newest(3rd cut) AL2230 */
139 { CR47, 0x1e },
140
141 /* ZD1211B 05.06.10 */
142 { CR48, 0x00 }, { CR49, 0x00 }, { CR51, 0x01 },
143 { CR52, 0x80 }, { CR53, 0x7e }, { CR65, 0x00 },
144 { CR66, 0x00 }, { CR67, 0x00 }, { CR68, 0x00 },
145 { CR69, 0x28 },
146
147 { CR79, 0x58 }, { CR80, 0x30 }, { CR81, 0x30 },
148 { CR87, 0x0a }, { CR89, 0x04 },
149 { CR91, 0x00 }, /* 5621 */
150 { CR92, 0x0a },
151 { CR98, 0x8d }, /* 4804, for 1212 new algorithm */
152 { CR99, 0x00 }, /* 5621 */
153 { CR101, 0x13 }, { CR102, 0x27 },
154 { CR106, 0x24 }, /* for newest(3rd cut) AL2230 */
155 { CR107, 0x2a },
156 { CR109, 0x13 }, /* 4804, for 1212 new algorithm */
157 { CR110, 0x1f }, /* 4804, for 1212 new algorithm */
158 { CR111, 0x1f }, { CR112, 0x1f }, { CR113, 0x27 },
159 { CR114, 0x27 },
160 { CR115, 0x26 }, /* 24->26 at 4902 for newest(3rd cut) AL2230 */
161 { CR116, 0x24 },
162 { CR117, 0xfa }, /* for 1211b */
163 { CR118, 0xfa }, /* for 1211b */
164 { CR119, 0x10 },
165 { CR120, 0x4f },
166 { CR121, 0x6c }, /* for 1211b */
167 { CR122, 0xfc }, /* E0->FC at 4902 */
168 { CR123, 0x57 }, /* 5623 */
169 { CR125, 0xad }, /* 4804, for 1212 new algorithm */
170 { CR126, 0x6c }, /* 5614 */
171 { CR127, 0x03 }, /* 4804, for 1212 new algorithm */
172 { CR137, 0x50 }, /* 5614 */
173 { CR138, 0xa8 },
174 { CR144, 0xac }, /* 5621 */
175 { CR150, 0x0d }, { CR252, 0x00 }, { CR253, 0x00 },
176 };
177
178 static const u32 rv1[] = {
179 /* channel 1 */
180 0x03f790,
181 0x033331,
182 0x00000d,
183
184 0x0b3331,
185 0x03b812,
186 0x00fff3,
187 0x0005a4,
188 0x0f4dc5, /* fix freq shift 0x044dc5 */
189 0x0805b6,
190 0x0146c7,
191 0x000688,
192 0x0403b9, /* External control TX power (CR31) */
193 0x00dbba,
194 0x00099b,
195 0x0bdffc,
196 0x00000d,
197 0x00580f,
198 };
199
200 static const struct zd_ioreq16 ioreqs2[] = {
201 { CR47, 0x1e }, { CR_RFCFG, 0x03 },
202 };
203
204 static const u32 rv2[] = {
205 0x00880f,
206 0x00080f,
207 };
208
209 static const struct zd_ioreq16 ioreqs3[] = {
210 { CR_RFCFG, 0x00 }, { CR47, 0x1e }, { CR251, 0x7f },
211 };
212
213 static const u32 rv3[] = {
214 0x00d80f,
215 0x00780f,
216 0x00580f,
217 };
218
219 static const struct zd_ioreq16 ioreqs4[] = {
220 { CR138, 0x28 }, { CR203, 0x06 },
221 };
222
223 r = zd_iowrite16a_locked(chip, ioreqs1, ARRAY_SIZE(ioreqs1));
224 if (r)
225 return r;
226 r = zd_rfwritev_locked(chip, rv1, ARRAY_SIZE(rv1), RF_RV_BITS);
227 if (r)
228 return r;
229 r = zd_iowrite16a_locked(chip, ioreqs2, ARRAY_SIZE(ioreqs2));
230 if (r)
231 return r;
232 r = zd_rfwritev_locked(chip, rv2, ARRAY_SIZE(rv2), RF_RV_BITS);
233 if (r)
234 return r;
235 r = zd_iowrite16a_locked(chip, ioreqs3, ARRAY_SIZE(ioreqs3));
236 if (r)
237 return r;
238 r = zd_rfwritev_locked(chip, rv3, ARRAY_SIZE(rv3), RF_RV_BITS);
239 if (r)
240 return r;
241 return zd_iowrite16a_locked(chip, ioreqs4, ARRAY_SIZE(ioreqs4));
242}
243
244static int al2230_set_channel(struct zd_rf *rf, u8 channel)
245{
246 int r;
247 const u32 *rv = al2230_table[channel-1];
248 struct zd_chip *chip = zd_rf_to_chip(rf);
249 static const struct zd_ioreq16 ioreqs[] = {
250 { CR138, 0x28 },
251 { CR203, 0x06 },
252 };
253
254 r = zd_rfwritev_locked(chip, rv, 3, RF_RV_BITS);
255 if (r)
256 return r;
257 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
258}
259
260static int zd1211_al2230_switch_radio_on(struct zd_rf *rf)
261{
262 struct zd_chip *chip = zd_rf_to_chip(rf);
263 static const struct zd_ioreq16 ioreqs[] = {
264 { CR11, 0x00 },
265 { CR251, 0x3f },
266 };
267
268 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
269}
270
271static int zd1211b_al2230_switch_radio_on(struct zd_rf *rf)
272{
273 struct zd_chip *chip = zd_rf_to_chip(rf);
274 static const struct zd_ioreq16 ioreqs[] = {
275 { CR11, 0x00 },
276 { CR251, 0x7f },
277 };
278
279 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
280}
281
282static int al2230_switch_radio_off(struct zd_rf *rf)
283{
284 struct zd_chip *chip = zd_rf_to_chip(rf);
285 static const struct zd_ioreq16 ioreqs[] = {
286 { CR11, 0x04 },
287 { CR251, 0x2f },
288 };
289
290 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
291}
292
293int zd_rf_init_al2230(struct zd_rf *rf)
294{
295 struct zd_chip *chip = zd_rf_to_chip(rf);
296
297 rf->set_channel = al2230_set_channel;
298 rf->switch_radio_off = al2230_switch_radio_off;
299 if (chip->is_zd1211b) {
300 rf->init_hw = zd1211b_al2230_init_hw;
301 rf->switch_radio_on = zd1211b_al2230_switch_radio_on;
302 } else {
303 rf->init_hw = zd1211_al2230_init_hw;
304 rf->switch_radio_on = zd1211_al2230_switch_radio_on;
305 }
306 rf->patch_6m_band_edge = 1;
307 return 0;
308}
diff --git a/drivers/net/wireless/zd1211rw/zd_rf_rf2959.c b/drivers/net/wireless/zd1211rw/zd_rf_rf2959.c
new file mode 100644
index 000000000000..58247271cc24
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_rf_rf2959.c
@@ -0,0 +1,279 @@
1/* zd_rf_rfmd.c: Functions for the RFMD RF controller
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#include <linux/kernel.h>
19
20#include "zd_rf.h"
21#include "zd_usb.h"
22#include "zd_chip.h"
23
24static u32 rf2959_table[][2] = {
25 RF_CHANNEL( 1) = { 0x181979, 0x1e6666 },
26 RF_CHANNEL( 2) = { 0x181989, 0x1e6666 },
27 RF_CHANNEL( 3) = { 0x181999, 0x1e6666 },
28 RF_CHANNEL( 4) = { 0x1819a9, 0x1e6666 },
29 RF_CHANNEL( 5) = { 0x1819b9, 0x1e6666 },
30 RF_CHANNEL( 6) = { 0x1819c9, 0x1e6666 },
31 RF_CHANNEL( 7) = { 0x1819d9, 0x1e6666 },
32 RF_CHANNEL( 8) = { 0x1819e9, 0x1e6666 },
33 RF_CHANNEL( 9) = { 0x1819f9, 0x1e6666 },
34 RF_CHANNEL(10) = { 0x181a09, 0x1e6666 },
35 RF_CHANNEL(11) = { 0x181a19, 0x1e6666 },
36 RF_CHANNEL(12) = { 0x181a29, 0x1e6666 },
37 RF_CHANNEL(13) = { 0x181a39, 0x1e6666 },
38 RF_CHANNEL(14) = { 0x181a60, 0x1c0000 },
39};
40
41#if 0
42static int bits(u32 rw, int from, int to)
43{
44 rw &= ~(0xffffffffU << (to+1));
45 rw >>= from;
46 return rw;
47}
48
49static int bit(u32 rw, int bit)
50{
51 return bits(rw, bit, bit);
52}
53
54static void dump_regwrite(u32 rw)
55{
56 int reg = bits(rw, 18, 22);
57 int rw_flag = bits(rw, 23, 23);
58 PDEBUG("rf2959 %#010x reg %d rw %d", rw, reg, rw_flag);
59
60 switch (reg) {
61 case 0:
62 PDEBUG("reg0 CFG1 ref_sel %d hybernate %d rf_vco_reg_en %d"
63 " if_vco_reg_en %d if_vga_en %d",
64 bits(rw, 14, 15), bit(rw, 3), bit(rw, 2), bit(rw, 1),
65 bit(rw, 0));
66 break;
67 case 1:
68 PDEBUG("reg1 IFPLL1 pll_en1 %d kv_en1 %d vtc_en1 %d lpf1 %d"
69 " cpl1 %d pdp1 %d autocal_en1 %d ld_en1 %d ifloopr %d"
70 " ifloopc %d dac1 %d",
71 bit(rw, 17), bit(rw, 16), bit(rw, 15), bit(rw, 14),
72 bit(rw, 13), bit(rw, 12), bit(rw, 11), bit(rw, 10),
73 bits(rw, 7, 9), bits(rw, 4, 6), bits(rw, 0, 3));
74 break;
75 case 2:
76 PDEBUG("reg2 IFPLL2 n1 %d num1 %d",
77 bits(rw, 6, 17), bits(rw, 0, 5));
78 break;
79 case 3:
80 PDEBUG("reg3 IFPLL3 num %d", bits(rw, 0, 17));
81 break;
82 case 4:
83 PDEBUG("reg4 IFPLL4 dn1 %#04x ct_def1 %d kv_def1 %d",
84 bits(rw, 8, 16), bits(rw, 4, 7), bits(rw, 0, 3));
85 break;
86 case 5:
87 PDEBUG("reg5 RFPLL1 pll_en %d kv_en %d vtc_en %d lpf %d cpl %d"
88 " pdp %d autocal_en %d ld_en %d rfloopr %d rfloopc %d"
89 " dac %d",
90 bit(rw, 17), bit(rw, 16), bit(rw, 15), bit(rw, 14),
91 bit(rw, 13), bit(rw, 12), bit(rw, 11), bit(rw, 10),
92 bits(rw, 7, 9), bits(rw, 4, 6), bits(rw, 0,3));
93 break;
94 case 6:
95 PDEBUG("reg6 RFPLL2 n %d num %d",
96 bits(rw, 6, 17), bits(rw, 0, 5));
97 break;
98 case 7:
99 PDEBUG("reg7 RFPLL3 num2 %d", bits(rw, 0, 17));
100 break;
101 case 8:
102 PDEBUG("reg8 RFPLL4 dn %#06x ct_def %d kv_def %d",
103 bits(rw, 8, 16), bits(rw, 4, 7), bits(rw, 0, 3));
104 break;
105 case 9:
106 PDEBUG("reg9 CAL1 tvco %d tlock %d m_ct_value %d ld_window %d",
107 bits(rw, 13, 17), bits(rw, 8, 12), bits(rw, 3, 7),
108 bits(rw, 0, 2));
109 break;
110 case 10:
111 PDEBUG("reg10 TXRX1 rxdcfbbyps %d pcontrol %d txvgc %d"
112 " rxlpfbw %d txlpfbw %d txdiffmode %d txenmode %d"
113 " intbiasen %d tybypass %d",
114 bit(rw, 17), bits(rw, 15, 16), bits(rw, 10, 14),
115 bits(rw, 7, 9), bits(rw, 4, 6), bit(rw, 3), bit(rw, 2),
116 bit(rw, 1), bit(rw, 0));
117 break;
118 case 11:
119 PDEBUG("reg11 PCNT1 mid_bias %d p_desired %d pc_offset %d"
120 " tx_delay %d",
121 bits(rw, 15, 17), bits(rw, 9, 14), bits(rw, 3, 8),
122 bits(rw, 0, 2));
123 break;
124 case 12:
125 PDEBUG("reg12 PCNT2 max_power %d mid_power %d min_power %d",
126 bits(rw, 12, 17), bits(rw, 6, 11), bits(rw, 0, 5));
127 break;
128 case 13:
129 PDEBUG("reg13 VCOT1 rfpll vco comp %d ifpll vco comp %d"
130 " lobias %d if_biasbuf %d if_biasvco %d rf_biasbuf %d"
131 " rf_biasvco %d",
132 bit(rw, 17), bit(rw, 16), bit(rw, 15),
133 bits(rw, 8, 9), bits(rw, 5, 7), bits(rw, 3, 4),
134 bits(rw, 0, 2));
135 break;
136 case 14:
137 PDEBUG("reg14 IQCAL rx_acal %d rx_pcal %d"
138 " tx_acal %d tx_pcal %d",
139 bits(rw, 13, 17), bits(rw, 9, 12), bits(rw, 4, 8),
140 bits(rw, 0, 3));
141 break;
142 }
143}
144#endif /* 0 */
145
146static int rf2959_init_hw(struct zd_rf *rf)
147{
148 int r;
149 struct zd_chip *chip = zd_rf_to_chip(rf);
150
151 static const struct zd_ioreq16 ioreqs[] = {
152 { CR2, 0x1E }, { CR9, 0x20 }, { CR10, 0x89 },
153 { CR11, 0x00 }, { CR15, 0xD0 }, { CR17, 0x68 },
154 { CR19, 0x4a }, { CR20, 0x0c }, { CR21, 0x0E },
155 { CR23, 0x48 },
156 /* normal size for cca threshold */
157 { CR24, 0x14 },
158 /* { CR24, 0x20 }, */
159 { CR26, 0x90 }, { CR27, 0x30 }, { CR29, 0x20 },
160 { CR31, 0xb2 }, { CR32, 0x43 }, { CR33, 0x28 },
161 { CR38, 0x30 }, { CR34, 0x0f }, { CR35, 0xF0 },
162 { CR41, 0x2a }, { CR46, 0x7F }, { CR47, 0x1E },
163 { CR51, 0xc5 }, { CR52, 0xc5 }, { CR53, 0xc5 },
164 { CR79, 0x58 }, { CR80, 0x30 }, { CR81, 0x30 },
165 { CR82, 0x00 }, { CR83, 0x24 }, { CR84, 0x04 },
166 { CR85, 0x00 }, { CR86, 0x10 }, { CR87, 0x2A },
167 { CR88, 0x10 }, { CR89, 0x24 }, { CR90, 0x18 },
168 /* { CR91, 0x18 }, */
169 /* should solve continous CTS frame problems */
170 { CR91, 0x00 },
171 { CR92, 0x0a }, { CR93, 0x00 }, { CR94, 0x01 },
172 { CR95, 0x00 }, { CR96, 0x40 }, { CR97, 0x37 },
173 { CR98, 0x05 }, { CR99, 0x28 }, { CR100, 0x00 },
174 { CR101, 0x13 }, { CR102, 0x27 }, { CR103, 0x27 },
175 { CR104, 0x18 }, { CR105, 0x12 },
176 /* normal size */
177 { CR106, 0x1a },
178 /* { CR106, 0x22 }, */
179 { CR107, 0x24 }, { CR108, 0x0a }, { CR109, 0x13 },
180 { CR110, 0x2F }, { CR111, 0x27 }, { CR112, 0x27 },
181 { CR113, 0x27 }, { CR114, 0x27 }, { CR115, 0x40 },
182 { CR116, 0x40 }, { CR117, 0xF0 }, { CR118, 0xF0 },
183 { CR119, 0x16 },
184 /* no TX continuation */
185 { CR122, 0x00 },
186 /* { CR122, 0xff }, */
187 { CR127, 0x03 }, { CR131, 0x08 }, { CR138, 0x28 },
188 { CR148, 0x44 }, { CR150, 0x10 }, { CR169, 0xBB },
189 { CR170, 0xBB },
190 };
191
192 static const u32 rv[] = {
193 0x000007, /* REG0(CFG1) */
194 0x07dd43, /* REG1(IFPLL1) */
195 0x080959, /* REG2(IFPLL2) */
196 0x0e6666,
197 0x116a57, /* REG4 */
198 0x17dd43, /* REG5 */
199 0x1819f9, /* REG6 */
200 0x1e6666,
201 0x214554,
202 0x25e7fa,
203 0x27fffa,
204 /* The Zydas driver somehow forgets to set this value. It's
205 * only set for Japan. We are using internal power control
206 * for now.
207 */
208 0x294128, /* internal power */
209 /* 0x28252c, */ /* External control TX power */
210 /* CR31_CCK, CR51_6-36M, CR52_48M, CR53_54M */
211 0x2c0000,
212 0x300000,
213 0x340000, /* REG13(0xD) */
214 0x381e0f, /* REG14(0xE) */
215 /* Bogus, RF2959's data sheet doesn't know register 27, which is
216 * actually referenced here. The commented 0x11 is 17.
217 */
218 0x6c180f, /* REG27(0x11) */
219 };
220
221 r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
222 if (r)
223 return r;
224
225 return zd_rfwritev_locked(chip, rv, ARRAY_SIZE(rv), RF_RV_BITS);
226}
227
228static int rf2959_set_channel(struct zd_rf *rf, u8 channel)
229{
230 int i, r;
231 u32 *rv = rf2959_table[channel-1];
232 struct zd_chip *chip = zd_rf_to_chip(rf);
233
234 for (i = 0; i < 2; i++) {
235 r = zd_rfwrite_locked(chip, rv[i], RF_RV_BITS);
236 if (r)
237 return r;
238 }
239 return 0;
240}
241
242static int rf2959_switch_radio_on(struct zd_rf *rf)
243{
244 static const struct zd_ioreq16 ioreqs[] = {
245 { CR10, 0x89 },
246 { CR11, 0x00 },
247 };
248 struct zd_chip *chip = zd_rf_to_chip(rf);
249
250 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
251}
252
253static int rf2959_switch_radio_off(struct zd_rf *rf)
254{
255 static const struct zd_ioreq16 ioreqs[] = {
256 { CR10, 0x15 },
257 { CR11, 0x81 },
258 };
259 struct zd_chip *chip = zd_rf_to_chip(rf);
260
261 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
262}
263
264int zd_rf_init_rf2959(struct zd_rf *rf)
265{
266 struct zd_chip *chip = zd_rf_to_chip(rf);
267
268 if (chip->is_zd1211b) {
269 dev_err(zd_chip_dev(chip),
270 "RF2959 is currently not supported for ZD1211B"
271 " devices\n");
272 return -ENODEV;
273 }
274 rf->init_hw = rf2959_init_hw;
275 rf->set_channel = rf2959_set_channel;
276 rf->switch_radio_on = rf2959_switch_radio_on;
277 rf->switch_radio_off = rf2959_switch_radio_off;
278 return 0;
279}
diff --git a/drivers/net/wireless/zd1211rw/zd_types.h b/drivers/net/wireless/zd1211rw/zd_types.h
new file mode 100644
index 000000000000..0155a1584ed3
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_types.h
@@ -0,0 +1,71 @@
1/* zd_types.h
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#ifndef _ZD_TYPES_H
19#define _ZD_TYPES_H
20
21#include <linux/types.h>
22
23/* We have three register spaces mapped into the overall USB address space of
24 * 64K words (16-bit values). There is the control register space of
25 * double-word registers, the eeprom register space and the firmware register
26 * space. The control register space is byte mapped, the others are word
27 * mapped.
28 *
29 * For that reason, we are using byte offsets for control registers and word
30 * offsets for everything else.
31 */
32
33typedef u32 __nocast zd_addr_t;
34
35enum {
36 ADDR_BASE_MASK = 0xff000000,
37 ADDR_OFFSET_MASK = 0x0000ffff,
38 ADDR_ZERO_MASK = 0x00ff0000,
39 NULL_BASE = 0x00000000,
40 USB_BASE = 0x01000000,
41 CR_BASE = 0x02000000,
42 CR_MAX_OFFSET = 0x0b30,
43 E2P_BASE = 0x03000000,
44 E2P_MAX_OFFSET = 0x007e,
45 FW_BASE = 0x04000000,
46 FW_MAX_OFFSET = 0x0005,
47};
48
49#define ZD_ADDR_BASE(addr) ((u32)(addr) & ADDR_BASE_MASK)
50#define ZD_OFFSET(addr) ((u32)(addr) & ADDR_OFFSET_MASK)
51
52#define ZD_ADDR(base, offset) \
53 ((zd_addr_t)(((base) & ADDR_BASE_MASK) | ((offset) & ADDR_OFFSET_MASK)))
54
55#define ZD_NULL_ADDR ((zd_addr_t)0)
56#define USB_REG(offset) ZD_ADDR(USB_BASE, offset) /* word addressing */
57#define CTL_REG(offset) ZD_ADDR(CR_BASE, offset) /* byte addressing */
58#define E2P_REG(offset) ZD_ADDR(E2P_BASE, offset) /* word addressing */
59#define FW_REG(offset) ZD_ADDR(FW_BASE, offset) /* word addressing */
60
61static inline zd_addr_t zd_inc_word(zd_addr_t addr)
62{
63 u32 base = ZD_ADDR_BASE(addr);
64 u32 offset = ZD_OFFSET(addr);
65
66 offset += base == CR_BASE ? 2 : 1;
67
68 return base | offset;
69}
70
71#endif /* _ZD_TYPES_H */
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
new file mode 100644
index 000000000000..6320984126c7
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
@@ -0,0 +1,1309 @@
1/* zd_usb.c
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#include <asm/unaligned.h>
19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/firmware.h>
22#include <linux/device.h>
23#include <linux/errno.h>
24#include <linux/skbuff.h>
25#include <linux/usb.h>
26#include <net/ieee80211.h>
27
28#include "zd_def.h"
29#include "zd_netdev.h"
30#include "zd_mac.h"
31#include "zd_usb.h"
32#include "zd_util.h"
33
34static struct usb_device_id usb_ids[] = {
35 /* ZD1211 */
36 { USB_DEVICE(0x0ace, 0x1211), .driver_info = DEVICE_ZD1211 },
37 { USB_DEVICE(0x07b8, 0x6001), .driver_info = DEVICE_ZD1211 },
38 { USB_DEVICE(0x126f, 0xa006), .driver_info = DEVICE_ZD1211 },
39 { USB_DEVICE(0x6891, 0xa727), .driver_info = DEVICE_ZD1211 },
40 { USB_DEVICE(0x0df6, 0x9071), .driver_info = DEVICE_ZD1211 },
41 { USB_DEVICE(0x157e, 0x300b), .driver_info = DEVICE_ZD1211 },
42 /* ZD1211B */
43 { USB_DEVICE(0x0ace, 0x1215), .driver_info = DEVICE_ZD1211B },
44 { USB_DEVICE(0x157e, 0x300d), .driver_info = DEVICE_ZD1211B },
45 {}
46};
47
48MODULE_LICENSE("GPL");
49MODULE_DESCRIPTION("USB driver for devices with the ZD1211 chip.");
50MODULE_AUTHOR("Ulrich Kunitz");
51MODULE_AUTHOR("Daniel Drake");
52MODULE_VERSION("1.0");
53MODULE_DEVICE_TABLE(usb, usb_ids);
54
55#define FW_ZD1211_PREFIX "zd1211/zd1211_"
56#define FW_ZD1211B_PREFIX "zd1211/zd1211b_"
57
58/* register address handling */
59
60#ifdef DEBUG
61static int check_addr(struct zd_usb *usb, zd_addr_t addr)
62{
63 u32 base = ZD_ADDR_BASE(addr);
64 u32 offset = ZD_OFFSET(addr);
65
66 if ((u32)addr & ADDR_ZERO_MASK)
67 goto invalid_address;
68 switch (base) {
69 case USB_BASE:
70 break;
71 case CR_BASE:
72 if (offset > CR_MAX_OFFSET) {
73 dev_dbg(zd_usb_dev(usb),
74 "CR offset %#010x larger than"
75 " CR_MAX_OFFSET %#10x\n",
76 offset, CR_MAX_OFFSET);
77 goto invalid_address;
78 }
79 if (offset & 1) {
80 dev_dbg(zd_usb_dev(usb),
81 "CR offset %#010x is not a multiple of 2\n",
82 offset);
83 goto invalid_address;
84 }
85 break;
86 case E2P_BASE:
87 if (offset > E2P_MAX_OFFSET) {
88 dev_dbg(zd_usb_dev(usb),
89 "E2P offset %#010x larger than"
90 " E2P_MAX_OFFSET %#010x\n",
91 offset, E2P_MAX_OFFSET);
92 goto invalid_address;
93 }
94 break;
95 case FW_BASE:
96 if (!usb->fw_base_offset) {
97 dev_dbg(zd_usb_dev(usb),
98 "ERROR: fw base offset has not been set\n");
99 return -EAGAIN;
100 }
101 if (offset > FW_MAX_OFFSET) {
102 dev_dbg(zd_usb_dev(usb),
103 "FW offset %#10x is larger than"
104 " FW_MAX_OFFSET %#010x\n",
105 offset, FW_MAX_OFFSET);
106 goto invalid_address;
107 }
108 break;
109 default:
110 dev_dbg(zd_usb_dev(usb),
111 "address has unsupported base %#010x\n", addr);
112 goto invalid_address;
113 }
114
115 return 0;
116invalid_address:
117 dev_dbg(zd_usb_dev(usb),
118 "ERROR: invalid address: %#010x\n", addr);
119 return -EINVAL;
120}
121#endif /* DEBUG */
122
123static u16 usb_addr(struct zd_usb *usb, zd_addr_t addr)
124{
125 u32 base;
126 u16 offset;
127
128 base = ZD_ADDR_BASE(addr);
129 offset = ZD_OFFSET(addr);
130
131 ZD_ASSERT(check_addr(usb, addr) == 0);
132
133 switch (base) {
134 case CR_BASE:
135 offset += CR_BASE_OFFSET;
136 break;
137 case E2P_BASE:
138 offset += E2P_BASE_OFFSET;
139 break;
140 case FW_BASE:
141 offset += usb->fw_base_offset;
142 break;
143 }
144
145 return offset;
146}
147
148/* USB device initialization */
149
150static int request_fw_file(
151 const struct firmware **fw, const char *name, struct device *device)
152{
153 int r;
154
155 dev_dbg_f(device, "fw name %s\n", name);
156
157 r = request_firmware(fw, name, device);
158 if (r)
159 dev_err(device,
160 "Could not load firmware file %s. Error number %d\n",
161 name, r);
162 return r;
163}
164
165static inline u16 get_bcdDevice(const struct usb_device *udev)
166{
167 return le16_to_cpu(udev->descriptor.bcdDevice);
168}
169
170enum upload_code_flags {
171 REBOOT = 1,
172};
173
174/* Ensures that MAX_TRANSFER_SIZE is even. */
175#define MAX_TRANSFER_SIZE (USB_MAX_TRANSFER_SIZE & ~1)
176
177static int upload_code(struct usb_device *udev,
178 const u8 *data, size_t size, u16 code_offset, int flags)
179{
180 u8 *p;
181 int r;
182
183 /* USB request blocks need "kmalloced" buffers.
184 */
185 p = kmalloc(MAX_TRANSFER_SIZE, GFP_KERNEL);
186 if (!p) {
187 dev_err(&udev->dev, "out of memory\n");
188 r = -ENOMEM;
189 goto error;
190 }
191
192 size &= ~1;
193 while (size > 0) {
194 size_t transfer_size = size <= MAX_TRANSFER_SIZE ?
195 size : MAX_TRANSFER_SIZE;
196
197 dev_dbg_f(&udev->dev, "transfer size %zu\n", transfer_size);
198
199 memcpy(p, data, transfer_size);
200 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
201 USB_REQ_FIRMWARE_DOWNLOAD,
202 USB_DIR_OUT | USB_TYPE_VENDOR,
203 code_offset, 0, p, transfer_size, 1000 /* ms */);
204 if (r < 0) {
205 dev_err(&udev->dev,
206 "USB control request for firmware upload"
207 " failed. Error number %d\n", r);
208 goto error;
209 }
210 transfer_size = r & ~1;
211
212 size -= transfer_size;
213 data += transfer_size;
214 code_offset += transfer_size/sizeof(u16);
215 }
216
217 if (flags & REBOOT) {
218 u8 ret;
219
220 r = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
221 USB_REQ_FIRMWARE_CONFIRM,
222 USB_DIR_IN | USB_TYPE_VENDOR,
223 0, 0, &ret, sizeof(ret), 5000 /* ms */);
224 if (r != sizeof(ret)) {
225 dev_err(&udev->dev,
226 "control request firmeware confirmation failed."
227 " Return value %d\n", r);
228 if (r >= 0)
229 r = -ENODEV;
230 goto error;
231 }
232 if (ret & 0x80) {
233 dev_err(&udev->dev,
234 "Internal error while downloading."
235 " Firmware confirm return value %#04x\n",
236 (unsigned int)ret);
237 r = -ENODEV;
238 goto error;
239 }
240 dev_dbg_f(&udev->dev, "firmware confirm return value %#04x\n",
241 (unsigned int)ret);
242 }
243
244 r = 0;
245error:
246 kfree(p);
247 return r;
248}
249
250static u16 get_word(const void *data, u16 offset)
251{
252 const __le16 *p = data;
253 return le16_to_cpu(p[offset]);
254}
255
256static char *get_fw_name(char *buffer, size_t size, u8 device_type,
257 const char* postfix)
258{
259 scnprintf(buffer, size, "%s%s",
260 device_type == DEVICE_ZD1211B ?
261 FW_ZD1211B_PREFIX : FW_ZD1211_PREFIX,
262 postfix);
263 return buffer;
264}
265
266static int upload_firmware(struct usb_device *udev, u8 device_type)
267{
268 int r;
269 u16 fw_bcdDevice;
270 u16 bcdDevice;
271 const struct firmware *ub_fw = NULL;
272 const struct firmware *uph_fw = NULL;
273 char fw_name[128];
274
275 bcdDevice = get_bcdDevice(udev);
276
277 r = request_fw_file(&ub_fw,
278 get_fw_name(fw_name, sizeof(fw_name), device_type, "ub"),
279 &udev->dev);
280 if (r)
281 goto error;
282
283 fw_bcdDevice = get_word(ub_fw->data, EEPROM_REGS_OFFSET);
284
285 /* FIXME: do we have any reason to perform the kludge that the vendor
286 * driver does when there is a version mismatch? (their driver uploads
287 * different firmwares and stuff)
288 */
289 if (fw_bcdDevice != bcdDevice) {
290 dev_info(&udev->dev,
291 "firmware device id %#06x and actual device id "
292 "%#06x differ, continuing anyway\n",
293 fw_bcdDevice, bcdDevice);
294 } else {
295 dev_dbg_f(&udev->dev,
296 "firmware device id %#06x is equal to the "
297 "actual device id\n", fw_bcdDevice);
298 }
299
300
301 r = request_fw_file(&uph_fw,
302 get_fw_name(fw_name, sizeof(fw_name), device_type, "uphr"),
303 &udev->dev);
304 if (r)
305 goto error;
306
307 r = upload_code(udev, uph_fw->data, uph_fw->size, FW_START_OFFSET,
308 REBOOT);
309 if (r) {
310 dev_err(&udev->dev,
311 "Could not upload firmware code uph. Error number %d\n",
312 r);
313 }
314
315 /* FALL-THROUGH */
316error:
317 release_firmware(ub_fw);
318 release_firmware(uph_fw);
319 return r;
320}
321
322static void disable_read_regs_int(struct zd_usb *usb)
323{
324 struct zd_usb_interrupt *intr = &usb->intr;
325
326 spin_lock(&intr->lock);
327 intr->read_regs_enabled = 0;
328 spin_unlock(&intr->lock);
329}
330
331#define urb_dev(urb) (&(urb)->dev->dev)
332
333static inline void handle_regs_int(struct urb *urb)
334{
335 struct zd_usb *usb = urb->context;
336 struct zd_usb_interrupt *intr = &usb->intr;
337 int len;
338
339 ZD_ASSERT(in_interrupt());
340 spin_lock(&intr->lock);
341
342 if (intr->read_regs_enabled) {
343 intr->read_regs.length = len = urb->actual_length;
344
345 if (len > sizeof(intr->read_regs.buffer))
346 len = sizeof(intr->read_regs.buffer);
347 memcpy(intr->read_regs.buffer, urb->transfer_buffer, len);
348 intr->read_regs_enabled = 0;
349 complete(&intr->read_regs.completion);
350 goto out;
351 }
352
353 dev_dbg_f(urb_dev(urb), "regs interrupt ignored\n");
354out:
355 spin_unlock(&intr->lock);
356}
357
358static inline void handle_retry_failed_int(struct urb *urb)
359{
360 dev_dbg_f(urb_dev(urb), "retry failed interrupt\n");
361}
362
363
364static void int_urb_complete(struct urb *urb, struct pt_regs *pt_regs)
365{
366 int r;
367 struct usb_int_header *hdr;
368
369 switch (urb->status) {
370 case 0:
371 break;
372 case -ESHUTDOWN:
373 case -EINVAL:
374 case -ENODEV:
375 case -ENOENT:
376 case -ECONNRESET:
377 case -EPIPE:
378 goto kfree;
379 default:
380 goto resubmit;
381 }
382
383 if (urb->actual_length < sizeof(hdr)) {
384 dev_dbg_f(urb_dev(urb), "error: urb %p to small\n", urb);
385 goto resubmit;
386 }
387
388 hdr = urb->transfer_buffer;
389 if (hdr->type != USB_INT_TYPE) {
390 dev_dbg_f(urb_dev(urb), "error: urb %p wrong type\n", urb);
391 goto resubmit;
392 }
393
394 switch (hdr->id) {
395 case USB_INT_ID_REGS:
396 handle_regs_int(urb);
397 break;
398 case USB_INT_ID_RETRY_FAILED:
399 handle_retry_failed_int(urb);
400 break;
401 default:
402 dev_dbg_f(urb_dev(urb), "error: urb %p unknown id %x\n", urb,
403 (unsigned int)hdr->id);
404 goto resubmit;
405 }
406
407resubmit:
408 r = usb_submit_urb(urb, GFP_ATOMIC);
409 if (r) {
410 dev_dbg_f(urb_dev(urb), "resubmit urb %p\n", urb);
411 goto kfree;
412 }
413 return;
414kfree:
415 kfree(urb->transfer_buffer);
416}
417
418static inline int int_urb_interval(struct usb_device *udev)
419{
420 switch (udev->speed) {
421 case USB_SPEED_HIGH:
422 return 4;
423 case USB_SPEED_LOW:
424 return 10;
425 case USB_SPEED_FULL:
426 default:
427 return 1;
428 }
429}
430
431static inline int usb_int_enabled(struct zd_usb *usb)
432{
433 unsigned long flags;
434 struct zd_usb_interrupt *intr = &usb->intr;
435 struct urb *urb;
436
437 spin_lock_irqsave(&intr->lock, flags);
438 urb = intr->urb;
439 spin_unlock_irqrestore(&intr->lock, flags);
440 return urb != NULL;
441}
442
443int zd_usb_enable_int(struct zd_usb *usb)
444{
445 int r;
446 struct usb_device *udev;
447 struct zd_usb_interrupt *intr = &usb->intr;
448 void *transfer_buffer = NULL;
449 struct urb *urb;
450
451 dev_dbg_f(zd_usb_dev(usb), "\n");
452
453 urb = usb_alloc_urb(0, GFP_NOFS);
454 if (!urb) {
455 r = -ENOMEM;
456 goto out;
457 }
458
459 ZD_ASSERT(!irqs_disabled());
460 spin_lock_irq(&intr->lock);
461 if (intr->urb) {
462 spin_unlock_irq(&intr->lock);
463 r = 0;
464 goto error_free_urb;
465 }
466 intr->urb = urb;
467 spin_unlock_irq(&intr->lock);
468
469 /* TODO: make it a DMA buffer */
470 r = -ENOMEM;
471 transfer_buffer = kmalloc(USB_MAX_EP_INT_BUFFER, GFP_NOFS);
472 if (!transfer_buffer) {
473 dev_dbg_f(zd_usb_dev(usb),
474 "couldn't allocate transfer_buffer\n");
475 goto error_set_urb_null;
476 }
477
478 udev = zd_usb_to_usbdev(usb);
479 usb_fill_int_urb(urb, udev, usb_rcvintpipe(udev, EP_INT_IN),
480 transfer_buffer, USB_MAX_EP_INT_BUFFER,
481 int_urb_complete, usb,
482 intr->interval);
483
484 dev_dbg_f(zd_usb_dev(usb), "submit urb %p\n", intr->urb);
485 r = usb_submit_urb(urb, GFP_NOFS);
486 if (r) {
487 dev_dbg_f(zd_usb_dev(usb),
488 "Couldn't submit urb. Error number %d\n", r);
489 goto error;
490 }
491
492 return 0;
493error:
494 kfree(transfer_buffer);
495error_set_urb_null:
496 spin_lock_irq(&intr->lock);
497 intr->urb = NULL;
498 spin_unlock_irq(&intr->lock);
499error_free_urb:
500 usb_free_urb(urb);
501out:
502 return r;
503}
504
505void zd_usb_disable_int(struct zd_usb *usb)
506{
507 unsigned long flags;
508 struct zd_usb_interrupt *intr = &usb->intr;
509 struct urb *urb;
510
511 spin_lock_irqsave(&intr->lock, flags);
512 urb = intr->urb;
513 if (!urb) {
514 spin_unlock_irqrestore(&intr->lock, flags);
515 return;
516 }
517 intr->urb = NULL;
518 spin_unlock_irqrestore(&intr->lock, flags);
519
520 usb_kill_urb(urb);
521 dev_dbg_f(zd_usb_dev(usb), "urb %p killed\n", urb);
522 usb_free_urb(urb);
523}
524
525static void handle_rx_packet(struct zd_usb *usb, const u8 *buffer,
526 unsigned int length)
527{
528 int i;
529 struct zd_mac *mac = zd_usb_to_mac(usb);
530 const struct rx_length_info *length_info;
531
532 if (length < sizeof(struct rx_length_info)) {
533 /* It's not a complete packet anyhow. */
534 return;
535 }
536 length_info = (struct rx_length_info *)
537 (buffer + length - sizeof(struct rx_length_info));
538
539 /* It might be that three frames are merged into a single URB
540 * transaction. We have to check for the length info tag.
541 *
542 * While testing we discovered that length_info might be unaligned,
543 * because if USB transactions are merged, the last packet will not
544 * be padded. Unaligned access might also happen if the length_info
545 * structure is not present.
546 */
547 if (get_unaligned(&length_info->tag) == cpu_to_le16(RX_LENGTH_INFO_TAG))
548 {
549 unsigned int l, k, n;
550 for (i = 0, l = 0;; i++) {
551 k = le16_to_cpu(get_unaligned(&length_info->length[i]));
552 n = l+k;
553 if (n > length)
554 return;
555 zd_mac_rx(mac, buffer+l, k);
556 if (i >= 2)
557 return;
558 l = (n+3) & ~3;
559 }
560 } else {
561 zd_mac_rx(mac, buffer, length);
562 }
563}
564
565static void rx_urb_complete(struct urb *urb, struct pt_regs *pt_regs)
566{
567 struct zd_usb *usb;
568 struct zd_usb_rx *rx;
569 const u8 *buffer;
570 unsigned int length;
571
572 switch (urb->status) {
573 case 0:
574 break;
575 case -ESHUTDOWN:
576 case -EINVAL:
577 case -ENODEV:
578 case -ENOENT:
579 case -ECONNRESET:
580 case -EPIPE:
581 return;
582 default:
583 dev_dbg_f(urb_dev(urb), "urb %p error %d\n", urb, urb->status);
584 goto resubmit;
585 }
586
587 buffer = urb->transfer_buffer;
588 length = urb->actual_length;
589 usb = urb->context;
590 rx = &usb->rx;
591
592 if (length%rx->usb_packet_size > rx->usb_packet_size-4) {
593 /* If there is an old first fragment, we don't care. */
594 dev_dbg_f(urb_dev(urb), "*** first fragment ***\n");
595 ZD_ASSERT(length <= ARRAY_SIZE(rx->fragment));
596 spin_lock(&rx->lock);
597 memcpy(rx->fragment, buffer, length);
598 rx->fragment_length = length;
599 spin_unlock(&rx->lock);
600 goto resubmit;
601 }
602
603 spin_lock(&rx->lock);
604 if (rx->fragment_length > 0) {
605 /* We are on a second fragment, we believe */
606 ZD_ASSERT(length + rx->fragment_length <=
607 ARRAY_SIZE(rx->fragment));
608 dev_dbg_f(urb_dev(urb), "*** second fragment ***\n");
609 memcpy(rx->fragment+rx->fragment_length, buffer, length);
610 handle_rx_packet(usb, rx->fragment,
611 rx->fragment_length + length);
612 rx->fragment_length = 0;
613 spin_unlock(&rx->lock);
614 } else {
615 spin_unlock(&rx->lock);
616 handle_rx_packet(usb, buffer, length);
617 }
618
619resubmit:
620 usb_submit_urb(urb, GFP_ATOMIC);
621}
622
623struct urb *alloc_urb(struct zd_usb *usb)
624{
625 struct usb_device *udev = zd_usb_to_usbdev(usb);
626 struct urb *urb;
627 void *buffer;
628
629 urb = usb_alloc_urb(0, GFP_NOFS);
630 if (!urb)
631 return NULL;
632 buffer = usb_buffer_alloc(udev, USB_MAX_RX_SIZE, GFP_NOFS,
633 &urb->transfer_dma);
634 if (!buffer) {
635 usb_free_urb(urb);
636 return NULL;
637 }
638
639 usb_fill_bulk_urb(urb, udev, usb_rcvbulkpipe(udev, EP_DATA_IN),
640 buffer, USB_MAX_RX_SIZE,
641 rx_urb_complete, usb);
642 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
643
644 return urb;
645}
646
647void free_urb(struct urb *urb)
648{
649 if (!urb)
650 return;
651 usb_buffer_free(urb->dev, urb->transfer_buffer_length,
652 urb->transfer_buffer, urb->transfer_dma);
653 usb_free_urb(urb);
654}
655
656int zd_usb_enable_rx(struct zd_usb *usb)
657{
658 int i, r;
659 struct zd_usb_rx *rx = &usb->rx;
660 struct urb **urbs;
661
662 dev_dbg_f(zd_usb_dev(usb), "\n");
663
664 r = -ENOMEM;
665 urbs = kcalloc(URBS_COUNT, sizeof(struct urb *), GFP_NOFS);
666 if (!urbs)
667 goto error;
668 for (i = 0; i < URBS_COUNT; i++) {
669 urbs[i] = alloc_urb(usb);
670 if (!urbs[i])
671 goto error;
672 }
673
674 ZD_ASSERT(!irqs_disabled());
675 spin_lock_irq(&rx->lock);
676 if (rx->urbs) {
677 spin_unlock_irq(&rx->lock);
678 r = 0;
679 goto error;
680 }
681 rx->urbs = urbs;
682 rx->urbs_count = URBS_COUNT;
683 spin_unlock_irq(&rx->lock);
684
685 for (i = 0; i < URBS_COUNT; i++) {
686 r = usb_submit_urb(urbs[i], GFP_NOFS);
687 if (r)
688 goto error_submit;
689 }
690
691 return 0;
692error_submit:
693 for (i = 0; i < URBS_COUNT; i++) {
694 usb_kill_urb(urbs[i]);
695 }
696 spin_lock_irq(&rx->lock);
697 rx->urbs = NULL;
698 rx->urbs_count = 0;
699 spin_unlock_irq(&rx->lock);
700error:
701 if (urbs) {
702 for (i = 0; i < URBS_COUNT; i++)
703 free_urb(urbs[i]);
704 }
705 return r;
706}
707
708void zd_usb_disable_rx(struct zd_usb *usb)
709{
710 int i;
711 unsigned long flags;
712 struct urb **urbs;
713 unsigned int count;
714 struct zd_usb_rx *rx = &usb->rx;
715
716 spin_lock_irqsave(&rx->lock, flags);
717 urbs = rx->urbs;
718 count = rx->urbs_count;
719 spin_unlock_irqrestore(&rx->lock, flags);
720 if (!urbs)
721 return;
722
723 for (i = 0; i < count; i++) {
724 usb_kill_urb(urbs[i]);
725 free_urb(urbs[i]);
726 }
727 kfree(urbs);
728
729 spin_lock_irqsave(&rx->lock, flags);
730 rx->urbs = NULL;
731 rx->urbs_count = 0;
732 spin_unlock_irqrestore(&rx->lock, flags);
733}
734
735static void tx_urb_complete(struct urb *urb, struct pt_regs *pt_regs)
736{
737 int r;
738
739 switch (urb->status) {
740 case 0:
741 break;
742 case -ESHUTDOWN:
743 case -EINVAL:
744 case -ENODEV:
745 case -ENOENT:
746 case -ECONNRESET:
747 case -EPIPE:
748 dev_dbg_f(urb_dev(urb), "urb %p error %d\n", urb, urb->status);
749 break;
750 default:
751 dev_dbg_f(urb_dev(urb), "urb %p error %d\n", urb, urb->status);
752 goto resubmit;
753 }
754free_urb:
755 usb_buffer_free(urb->dev, urb->transfer_buffer_length,
756 urb->transfer_buffer, urb->transfer_dma);
757 usb_free_urb(urb);
758 return;
759resubmit:
760 r = usb_submit_urb(urb, GFP_ATOMIC);
761 if (r) {
762 dev_dbg_f(urb_dev(urb), "error resubmit urb %p %d\n", urb, r);
763 goto free_urb;
764 }
765}
766
767/* Puts the frame on the USB endpoint. It doesn't wait for
768 * completion. The frame must contain the control set.
769 */
770int zd_usb_tx(struct zd_usb *usb, const u8 *frame, unsigned int length)
771{
772 int r;
773 struct usb_device *udev = zd_usb_to_usbdev(usb);
774 struct urb *urb;
775 void *buffer;
776
777 urb = usb_alloc_urb(0, GFP_ATOMIC);
778 if (!urb) {
779 r = -ENOMEM;
780 goto out;
781 }
782
783 buffer = usb_buffer_alloc(zd_usb_to_usbdev(usb), length, GFP_ATOMIC,
784 &urb->transfer_dma);
785 if (!buffer) {
786 r = -ENOMEM;
787 goto error_free_urb;
788 }
789 memcpy(buffer, frame, length);
790
791 usb_fill_bulk_urb(urb, udev, usb_sndbulkpipe(udev, EP_DATA_OUT),
792 buffer, length, tx_urb_complete, NULL);
793 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
794
795 r = usb_submit_urb(urb, GFP_ATOMIC);
796 if (r)
797 goto error;
798 return 0;
799error:
800 usb_buffer_free(zd_usb_to_usbdev(usb), length, buffer,
801 urb->transfer_dma);
802error_free_urb:
803 usb_free_urb(urb);
804out:
805 return r;
806}
807
808static inline void init_usb_interrupt(struct zd_usb *usb)
809{
810 struct zd_usb_interrupt *intr = &usb->intr;
811
812 spin_lock_init(&intr->lock);
813 intr->interval = int_urb_interval(zd_usb_to_usbdev(usb));
814 init_completion(&intr->read_regs.completion);
815 intr->read_regs.cr_int_addr = cpu_to_le16(usb_addr(usb, CR_INTERRUPT));
816}
817
818static inline void init_usb_rx(struct zd_usb *usb)
819{
820 struct zd_usb_rx *rx = &usb->rx;
821 spin_lock_init(&rx->lock);
822 if (interface_to_usbdev(usb->intf)->speed == USB_SPEED_HIGH) {
823 rx->usb_packet_size = 512;
824 } else {
825 rx->usb_packet_size = 64;
826 }
827 ZD_ASSERT(rx->fragment_length == 0);
828}
829
830static inline void init_usb_tx(struct zd_usb *usb)
831{
832 /* FIXME: at this point we will allocate a fixed number of urb's for
833 * use in a cyclic scheme */
834}
835
836void zd_usb_init(struct zd_usb *usb, struct net_device *netdev,
837 struct usb_interface *intf)
838{
839 memset(usb, 0, sizeof(*usb));
840 usb->intf = usb_get_intf(intf);
841 usb_set_intfdata(usb->intf, netdev);
842 init_usb_interrupt(usb);
843 init_usb_tx(usb);
844 init_usb_rx(usb);
845}
846
847int zd_usb_init_hw(struct zd_usb *usb)
848{
849 int r;
850 struct zd_chip *chip = zd_usb_to_chip(usb);
851
852 ZD_ASSERT(mutex_is_locked(&chip->mutex));
853 r = zd_ioread16_locked(chip, &usb->fw_base_offset,
854 USB_REG((u16)FW_BASE_ADDR_OFFSET));
855 if (r)
856 return r;
857 dev_dbg_f(zd_usb_dev(usb), "fw_base_offset: %#06hx\n",
858 usb->fw_base_offset);
859
860 return 0;
861}
862
863void zd_usb_clear(struct zd_usb *usb)
864{
865 usb_set_intfdata(usb->intf, NULL);
866 usb_put_intf(usb->intf);
867 memset(usb, 0, sizeof(*usb));
868 /* FIXME: usb_interrupt, usb_tx, usb_rx? */
869}
870
871static const char *speed(enum usb_device_speed speed)
872{
873 switch (speed) {
874 case USB_SPEED_LOW:
875 return "low";
876 case USB_SPEED_FULL:
877 return "full";
878 case USB_SPEED_HIGH:
879 return "high";
880 default:
881 return "unknown speed";
882 }
883}
884
885static int scnprint_id(struct usb_device *udev, char *buffer, size_t size)
886{
887 return scnprintf(buffer, size, "%04hx:%04hx v%04hx %s",
888 le16_to_cpu(udev->descriptor.idVendor),
889 le16_to_cpu(udev->descriptor.idProduct),
890 get_bcdDevice(udev),
891 speed(udev->speed));
892}
893
894int zd_usb_scnprint_id(struct zd_usb *usb, char *buffer, size_t size)
895{
896 struct usb_device *udev = interface_to_usbdev(usb->intf);
897 return scnprint_id(udev, buffer, size);
898}
899
900#ifdef DEBUG
901static void print_id(struct usb_device *udev)
902{
903 char buffer[40];
904
905 scnprint_id(udev, buffer, sizeof(buffer));
906 buffer[sizeof(buffer)-1] = 0;
907 dev_dbg_f(&udev->dev, "%s\n", buffer);
908}
909#else
910#define print_id(udev) do { } while (0)
911#endif
912
913static int probe(struct usb_interface *intf, const struct usb_device_id *id)
914{
915 int r;
916 struct usb_device *udev = interface_to_usbdev(intf);
917 struct net_device *netdev = NULL;
918
919 print_id(udev);
920
921 switch (udev->speed) {
922 case USB_SPEED_LOW:
923 case USB_SPEED_FULL:
924 case USB_SPEED_HIGH:
925 break;
926 default:
927 dev_dbg_f(&intf->dev, "Unknown USB speed\n");
928 r = -ENODEV;
929 goto error;
930 }
931
932 netdev = zd_netdev_alloc(intf);
933 if (netdev == NULL) {
934 r = -ENOMEM;
935 goto error;
936 }
937
938 r = upload_firmware(udev, id->driver_info);
939 if (r) {
940 dev_err(&intf->dev,
941 "couldn't load firmware. Error number %d\n", r);
942 goto error;
943 }
944
945 r = usb_reset_configuration(udev);
946 if (r) {
947 dev_dbg_f(&intf->dev,
948 "couldn't reset configuration. Error number %d\n", r);
949 goto error;
950 }
951
952 /* At this point the interrupt endpoint is not generally enabled. We
953 * save the USB bandwidth until the network device is opened. But
954 * notify that the initialization of the MAC will require the
955 * interrupts to be temporary enabled.
956 */
957 r = zd_mac_init_hw(zd_netdev_mac(netdev), id->driver_info);
958 if (r) {
959 dev_dbg_f(&intf->dev,
960 "couldn't initialize mac. Error number %d\n", r);
961 goto error;
962 }
963
964 r = register_netdev(netdev);
965 if (r) {
966 dev_dbg_f(&intf->dev,
967 "couldn't register netdev. Error number %d\n", r);
968 goto error;
969 }
970
971 dev_dbg_f(&intf->dev, "successful\n");
972 dev_info(&intf->dev,"%s\n", netdev->name);
973 return 0;
974error:
975 usb_reset_device(interface_to_usbdev(intf));
976 zd_netdev_free(netdev);
977 return r;
978}
979
980static void disconnect(struct usb_interface *intf)
981{
982 struct net_device *netdev = zd_intf_to_netdev(intf);
983 struct zd_mac *mac = zd_netdev_mac(netdev);
984 struct zd_usb *usb = &mac->chip.usb;
985
986 dev_dbg_f(zd_usb_dev(usb), "\n");
987
988 zd_netdev_disconnect(netdev);
989
990 /* Just in case something has gone wrong! */
991 zd_usb_disable_rx(usb);
992 zd_usb_disable_int(usb);
993
994 /* If the disconnect has been caused by a removal of the
995 * driver module, the reset allows reloading of the driver. If the
996 * reset will not be executed here, the upload of the firmware in the
997 * probe function caused by the reloading of the driver will fail.
998 */
999 usb_reset_device(interface_to_usbdev(intf));
1000
1001 /* If somebody still waits on this lock now, this is an error. */
1002 zd_netdev_free(netdev);
1003 dev_dbg(&intf->dev, "disconnected\n");
1004}
1005
1006static struct usb_driver driver = {
1007 .name = "zd1211rw",
1008 .id_table = usb_ids,
1009 .probe = probe,
1010 .disconnect = disconnect,
1011};
1012
1013static int __init usb_init(void)
1014{
1015 int r;
1016
1017 pr_debug("usb_init()\n");
1018
1019 r = usb_register(&driver);
1020 if (r) {
1021 printk(KERN_ERR "usb_register() failed. Error number %d\n", r);
1022 return r;
1023 }
1024
1025 pr_debug("zd1211rw initialized\n");
1026 return 0;
1027}
1028
1029static void __exit usb_exit(void)
1030{
1031 pr_debug("usb_exit()\n");
1032 usb_deregister(&driver);
1033}
1034
1035module_init(usb_init);
1036module_exit(usb_exit);
1037
1038static int usb_int_regs_length(unsigned int count)
1039{
1040 return sizeof(struct usb_int_regs) + count * sizeof(struct reg_data);
1041}
1042
1043static void prepare_read_regs_int(struct zd_usb *usb)
1044{
1045 struct zd_usb_interrupt *intr = &usb->intr;
1046
1047 spin_lock(&intr->lock);
1048 intr->read_regs_enabled = 1;
1049 INIT_COMPLETION(intr->read_regs.completion);
1050 spin_unlock(&intr->lock);
1051}
1052
1053static int get_results(struct zd_usb *usb, u16 *values,
1054 struct usb_req_read_regs *req, unsigned int count)
1055{
1056 int r;
1057 int i;
1058 struct zd_usb_interrupt *intr = &usb->intr;
1059 struct read_regs_int *rr = &intr->read_regs;
1060 struct usb_int_regs *regs = (struct usb_int_regs *)rr->buffer;
1061
1062 spin_lock(&intr->lock);
1063
1064 r = -EIO;
1065 /* The created block size seems to be larger than expected.
1066 * However results appear to be correct.
1067 */
1068 if (rr->length < usb_int_regs_length(count)) {
1069 dev_dbg_f(zd_usb_dev(usb),
1070 "error: actual length %d less than expected %d\n",
1071 rr->length, usb_int_regs_length(count));
1072 goto error_unlock;
1073 }
1074 if (rr->length > sizeof(rr->buffer)) {
1075 dev_dbg_f(zd_usb_dev(usb),
1076 "error: actual length %d exceeds buffer size %zu\n",
1077 rr->length, sizeof(rr->buffer));
1078 goto error_unlock;
1079 }
1080
1081 for (i = 0; i < count; i++) {
1082 struct reg_data *rd = &regs->regs[i];
1083 if (rd->addr != req->addr[i]) {
1084 dev_dbg_f(zd_usb_dev(usb),
1085 "rd[%d] addr %#06hx expected %#06hx\n", i,
1086 le16_to_cpu(rd->addr),
1087 le16_to_cpu(req->addr[i]));
1088 goto error_unlock;
1089 }
1090 values[i] = le16_to_cpu(rd->value);
1091 }
1092
1093 r = 0;
1094error_unlock:
1095 spin_unlock(&intr->lock);
1096 return r;
1097}
1098
1099int zd_usb_ioread16v(struct zd_usb *usb, u16 *values,
1100 const zd_addr_t *addresses, unsigned int count)
1101{
1102 int r;
1103 int i, req_len, actual_req_len;
1104 struct usb_device *udev;
1105 struct usb_req_read_regs *req = NULL;
1106 unsigned long timeout;
1107
1108 if (count < 1) {
1109 dev_dbg_f(zd_usb_dev(usb), "error: count is zero\n");
1110 return -EINVAL;
1111 }
1112 if (count > USB_MAX_IOREAD16_COUNT) {
1113 dev_dbg_f(zd_usb_dev(usb),
1114 "error: count %u exceeds possible max %u\n",
1115 count, USB_MAX_IOREAD16_COUNT);
1116 return -EINVAL;
1117 }
1118 if (in_atomic()) {
1119 dev_dbg_f(zd_usb_dev(usb),
1120 "error: io in atomic context not supported\n");
1121 return -EWOULDBLOCK;
1122 }
1123 if (!usb_int_enabled(usb)) {
1124 dev_dbg_f(zd_usb_dev(usb),
1125 "error: usb interrupt not enabled\n");
1126 return -EWOULDBLOCK;
1127 }
1128
1129 req_len = sizeof(struct usb_req_read_regs) + count * sizeof(__le16);
1130 req = kmalloc(req_len, GFP_NOFS);
1131 if (!req)
1132 return -ENOMEM;
1133 req->id = cpu_to_le16(USB_REQ_READ_REGS);
1134 for (i = 0; i < count; i++)
1135 req->addr[i] = cpu_to_le16(usb_addr(usb, addresses[i]));
1136
1137 udev = zd_usb_to_usbdev(usb);
1138 prepare_read_regs_int(usb);
1139 r = usb_bulk_msg(udev, usb_sndbulkpipe(udev, EP_REGS_OUT),
1140 req, req_len, &actual_req_len, 1000 /* ms */);
1141 if (r) {
1142 dev_dbg_f(zd_usb_dev(usb),
1143 "error in usb_bulk_msg(). Error number %d\n", r);
1144 goto error;
1145 }
1146 if (req_len != actual_req_len) {
1147 dev_dbg_f(zd_usb_dev(usb), "error in usb_bulk_msg()\n"
1148 " req_len %d != actual_req_len %d\n",
1149 req_len, actual_req_len);
1150 r = -EIO;
1151 goto error;
1152 }
1153
1154 timeout = wait_for_completion_timeout(&usb->intr.read_regs.completion,
1155 msecs_to_jiffies(1000));
1156 if (!timeout) {
1157 disable_read_regs_int(usb);
1158 dev_dbg_f(zd_usb_dev(usb), "read timed out\n");
1159 r = -ETIMEDOUT;
1160 goto error;
1161 }
1162
1163 r = get_results(usb, values, req, count);
1164error:
1165 kfree(req);
1166 return r;
1167}
1168
1169int zd_usb_iowrite16v(struct zd_usb *usb, const struct zd_ioreq16 *ioreqs,
1170 unsigned int count)
1171{
1172 int r;
1173 struct usb_device *udev;
1174 struct usb_req_write_regs *req = NULL;
1175 int i, req_len, actual_req_len;
1176
1177 if (count == 0)
1178 return 0;
1179 if (count > USB_MAX_IOWRITE16_COUNT) {
1180 dev_dbg_f(zd_usb_dev(usb),
1181 "error: count %u exceeds possible max %u\n",
1182 count, USB_MAX_IOWRITE16_COUNT);
1183 return -EINVAL;
1184 }
1185 if (in_atomic()) {
1186 dev_dbg_f(zd_usb_dev(usb),
1187 "error: io in atomic context not supported\n");
1188 return -EWOULDBLOCK;
1189 }
1190
1191 req_len = sizeof(struct usb_req_write_regs) +
1192 count * sizeof(struct reg_data);
1193 req = kmalloc(req_len, GFP_NOFS);
1194 if (!req)
1195 return -ENOMEM;
1196
1197 req->id = cpu_to_le16(USB_REQ_WRITE_REGS);
1198 for (i = 0; i < count; i++) {
1199 struct reg_data *rw = &req->reg_writes[i];
1200 rw->addr = cpu_to_le16(usb_addr(usb, ioreqs[i].addr));
1201 rw->value = cpu_to_le16(ioreqs[i].value);
1202 }
1203
1204 udev = zd_usb_to_usbdev(usb);
1205 r = usb_bulk_msg(udev, usb_sndbulkpipe(udev, EP_REGS_OUT),
1206 req, req_len, &actual_req_len, 1000 /* ms */);
1207 if (r) {
1208 dev_dbg_f(zd_usb_dev(usb),
1209 "error in usb_bulk_msg(). Error number %d\n", r);
1210 goto error;
1211 }
1212 if (req_len != actual_req_len) {
1213 dev_dbg_f(zd_usb_dev(usb),
1214 "error in usb_bulk_msg()"
1215 " req_len %d != actual_req_len %d\n",
1216 req_len, actual_req_len);
1217 r = -EIO;
1218 goto error;
1219 }
1220
1221 /* FALL-THROUGH with r == 0 */
1222error:
1223 kfree(req);
1224 return r;
1225}
1226
1227int zd_usb_rfwrite(struct zd_usb *usb, u32 value, u8 bits)
1228{
1229 int r;
1230 struct usb_device *udev;
1231 struct usb_req_rfwrite *req = NULL;
1232 int i, req_len, actual_req_len;
1233 u16 bit_value_template;
1234
1235 if (in_atomic()) {
1236 dev_dbg_f(zd_usb_dev(usb),
1237 "error: io in atomic context not supported\n");
1238 return -EWOULDBLOCK;
1239 }
1240 if (bits < USB_MIN_RFWRITE_BIT_COUNT) {
1241 dev_dbg_f(zd_usb_dev(usb),
1242 "error: bits %d are smaller than"
1243 " USB_MIN_RFWRITE_BIT_COUNT %d\n",
1244 bits, USB_MIN_RFWRITE_BIT_COUNT);
1245 return -EINVAL;
1246 }
1247 if (bits > USB_MAX_RFWRITE_BIT_COUNT) {
1248 dev_dbg_f(zd_usb_dev(usb),
1249 "error: bits %d exceed USB_MAX_RFWRITE_BIT_COUNT %d\n",
1250 bits, USB_MAX_RFWRITE_BIT_COUNT);
1251 return -EINVAL;
1252 }
1253#ifdef DEBUG
1254 if (value & (~0UL << bits)) {
1255 dev_dbg_f(zd_usb_dev(usb),
1256 "error: value %#09x has bits >= %d set\n",
1257 value, bits);
1258 return -EINVAL;
1259 }
1260#endif /* DEBUG */
1261
1262 dev_dbg_f(zd_usb_dev(usb), "value %#09x bits %d\n", value, bits);
1263
1264 r = zd_usb_ioread16(usb, &bit_value_template, CR203);
1265 if (r) {
1266 dev_dbg_f(zd_usb_dev(usb),
1267 "error %d: Couldn't read CR203\n", r);
1268 goto out;
1269 }
1270 bit_value_template &= ~(RF_IF_LE|RF_CLK|RF_DATA);
1271
1272 req_len = sizeof(struct usb_req_rfwrite) + bits * sizeof(__le16);
1273 req = kmalloc(req_len, GFP_NOFS);
1274 if (!req)
1275 return -ENOMEM;
1276
1277 req->id = cpu_to_le16(USB_REQ_WRITE_RF);
1278 /* 1: 3683a, but not used in ZYDAS driver */
1279 req->value = cpu_to_le16(2);
1280 req->bits = cpu_to_le16(bits);
1281
1282 for (i = 0; i < bits; i++) {
1283 u16 bv = bit_value_template;
1284 if (value & (1 << (bits-1-i)))
1285 bv |= RF_DATA;
1286 req->bit_values[i] = cpu_to_le16(bv);
1287 }
1288
1289 udev = zd_usb_to_usbdev(usb);
1290 r = usb_bulk_msg(udev, usb_sndbulkpipe(udev, EP_REGS_OUT),
1291 req, req_len, &actual_req_len, 1000 /* ms */);
1292 if (r) {
1293 dev_dbg_f(zd_usb_dev(usb),
1294 "error in usb_bulk_msg(). Error number %d\n", r);
1295 goto out;
1296 }
1297 if (req_len != actual_req_len) {
1298 dev_dbg_f(zd_usb_dev(usb), "error in usb_bulk_msg()"
1299 " req_len %d != actual_req_len %d\n",
1300 req_len, actual_req_len);
1301 r = -EIO;
1302 goto out;
1303 }
1304
1305 /* FALL-THROUGH with r == 0 */
1306out:
1307 kfree(req);
1308 return r;
1309}
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.h b/drivers/net/wireless/zd1211rw/zd_usb.h
new file mode 100644
index 000000000000..d6420283bd5a
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_usb.h
@@ -0,0 +1,240 @@
1/* zd_usb.h: Header for USB interface implemented by ZD1211 chip
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#ifndef _ZD_USB_H
19#define _ZD_USB_H
20
21#include <linux/completion.h>
22#include <linux/netdevice.h>
23#include <linux/spinlock.h>
24#include <linux/skbuff.h>
25#include <linux/usb.h>
26
27#include "zd_def.h"
28#include "zd_types.h"
29
30enum devicetype {
31 DEVICE_ZD1211 = 0,
32 DEVICE_ZD1211B = 1,
33};
34
35enum endpoints {
36 EP_CTRL = 0,
37 EP_DATA_OUT = 1,
38 EP_DATA_IN = 2,
39 EP_INT_IN = 3,
40 EP_REGS_OUT = 4,
41};
42
43enum {
44 USB_MAX_TRANSFER_SIZE = 4096, /* bytes */
45 /* FIXME: The original driver uses this value. We have to check,
46 * whether the MAX_TRANSFER_SIZE is sufficient and this needs only be
47 * used if one combined frame is split over two USB transactions.
48 */
49 USB_MAX_RX_SIZE = 4800, /* bytes */
50 USB_MAX_IOWRITE16_COUNT = 15,
51 USB_MAX_IOWRITE32_COUNT = USB_MAX_IOWRITE16_COUNT/2,
52 USB_MAX_IOREAD16_COUNT = 15,
53 USB_MAX_IOREAD32_COUNT = USB_MAX_IOREAD16_COUNT/2,
54 USB_MIN_RFWRITE_BIT_COUNT = 16,
55 USB_MAX_RFWRITE_BIT_COUNT = 28,
56 USB_MAX_EP_INT_BUFFER = 64,
57 USB_ZD1211B_BCD_DEVICE = 0x4810,
58};
59
60enum control_requests {
61 USB_REQ_WRITE_REGS = 0x21,
62 USB_REQ_READ_REGS = 0x22,
63 USB_REQ_WRITE_RF = 0x23,
64 USB_REQ_PROG_FLASH = 0x24,
65 USB_REQ_EEPROM_START = 0x0128, /* ? request is a byte */
66 USB_REQ_EEPROM_MID = 0x28,
67 USB_REQ_EEPROM_END = 0x0228, /* ? request is a byte */
68 USB_REQ_FIRMWARE_DOWNLOAD = 0x30,
69 USB_REQ_FIRMWARE_CONFIRM = 0x31,
70 USB_REQ_FIRMWARE_READ_DATA = 0x32,
71};
72
73struct usb_req_read_regs {
74 __le16 id;
75 __le16 addr[0];
76} __attribute__((packed));
77
78struct reg_data {
79 __le16 addr;
80 __le16 value;
81} __attribute__((packed));
82
83struct usb_req_write_regs {
84 __le16 id;
85 struct reg_data reg_writes[0];
86} __attribute__((packed));
87
88enum {
89 RF_IF_LE = 0x02,
90 RF_CLK = 0x04,
91 RF_DATA = 0x08,
92};
93
94struct usb_req_rfwrite {
95 __le16 id;
96 __le16 value;
97 /* 1: 3683a */
98 /* 2: other (default) */
99 __le16 bits;
100 /* RF2595: 24 */
101 __le16 bit_values[0];
102 /* (CR203 & ~(RF_IF_LE | RF_CLK | RF_DATA)) | (bit ? RF_DATA : 0) */
103} __attribute__((packed));
104
105/* USB interrupt */
106
107enum usb_int_id {
108 USB_INT_TYPE = 0x01,
109 USB_INT_ID_REGS = 0x90,
110 USB_INT_ID_RETRY_FAILED = 0xa0,
111};
112
113enum usb_int_flags {
114 USB_INT_READ_REGS_EN = 0x01,
115};
116
117struct usb_int_header {
118 u8 type; /* must always be 1 */
119 u8 id;
120} __attribute__((packed));
121
122struct usb_int_regs {
123 struct usb_int_header hdr;
124 struct reg_data regs[0];
125} __attribute__((packed));
126
127struct usb_int_retry_fail {
128 struct usb_int_header hdr;
129 u8 new_rate;
130 u8 _dummy;
131 u8 addr[ETH_ALEN];
132 u8 ibss_wakeup_dest;
133} __attribute__((packed));
134
135struct read_regs_int {
136 struct completion completion;
137 /* Stores the USB int structure and contains the USB address of the
138 * first requested register before request.
139 */
140 u8 buffer[USB_MAX_EP_INT_BUFFER];
141 int length;
142 __le16 cr_int_addr;
143};
144
145struct zd_ioreq16 {
146 zd_addr_t addr;
147 u16 value;
148};
149
150struct zd_ioreq32 {
151 zd_addr_t addr;
152 u32 value;
153};
154
155struct zd_usb_interrupt {
156 struct read_regs_int read_regs;
157 spinlock_t lock;
158 struct urb *urb;
159 int interval;
160 u8 read_regs_enabled:1;
161};
162
163static inline struct usb_int_regs *get_read_regs(struct zd_usb_interrupt *intr)
164{
165 return (struct usb_int_regs *)intr->read_regs.buffer;
166}
167
168#define URBS_COUNT 5
169
170struct zd_usb_rx {
171 spinlock_t lock;
172 u8 fragment[2*USB_MAX_RX_SIZE];
173 unsigned int fragment_length;
174 unsigned int usb_packet_size;
175 struct urb **urbs;
176 int urbs_count;
177};
178
179struct zd_usb_tx {
180 spinlock_t lock;
181};
182
183/* Contains the usb parts. The structure doesn't require a lock, because intf
184 * and fw_base_offset, will not be changed after initialization.
185 */
186struct zd_usb {
187 struct zd_usb_interrupt intr;
188 struct zd_usb_rx rx;
189 struct zd_usb_tx tx;
190 struct usb_interface *intf;
191 u16 fw_base_offset;
192};
193
194#define zd_usb_dev(usb) (&usb->intf->dev)
195
196static inline struct usb_device *zd_usb_to_usbdev(struct zd_usb *usb)
197{
198 return interface_to_usbdev(usb->intf);
199}
200
201static inline struct net_device *zd_intf_to_netdev(struct usb_interface *intf)
202{
203 return usb_get_intfdata(intf);
204}
205
206static inline struct net_device *zd_usb_to_netdev(struct zd_usb *usb)
207{
208 return zd_intf_to_netdev(usb->intf);
209}
210
211void zd_usb_init(struct zd_usb *usb, struct net_device *netdev,
212 struct usb_interface *intf);
213int zd_usb_init_hw(struct zd_usb *usb);
214void zd_usb_clear(struct zd_usb *usb);
215
216int zd_usb_scnprint_id(struct zd_usb *usb, char *buffer, size_t size);
217
218int zd_usb_enable_int(struct zd_usb *usb);
219void zd_usb_disable_int(struct zd_usb *usb);
220
221int zd_usb_enable_rx(struct zd_usb *usb);
222void zd_usb_disable_rx(struct zd_usb *usb);
223
224int zd_usb_tx(struct zd_usb *usb, const u8 *frame, unsigned int length);
225
226int zd_usb_ioread16v(struct zd_usb *usb, u16 *values,
227 const zd_addr_t *addresses, unsigned int count);
228
229static inline int zd_usb_ioread16(struct zd_usb *usb, u16 *value,
230 const zd_addr_t addr)
231{
232 return zd_usb_ioread16v(usb, value, (const zd_addr_t *)&addr, 1);
233}
234
235int zd_usb_iowrite16v(struct zd_usb *usb, const struct zd_ioreq16 *ioreqs,
236 unsigned int count);
237
238int zd_usb_rfwrite(struct zd_usb *usb, u32 value, u8 bits);
239
240#endif /* _ZD_USB_H */
diff --git a/drivers/net/wireless/zd1211rw/zd_util.c b/drivers/net/wireless/zd1211rw/zd_util.c
new file mode 100644
index 000000000000..d20036c15d11
--- /dev/null
+++ b/drivers/net/wireless/zd1211rw/zd_util.c
@@ -0,0 +1,82 @@
1/* zd_util.c
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Utility program
18 */
19
20#include "zd_def.h"
21#include "zd_util.h"
22
23#ifdef DEBUG
24static char hex(u8 v)
25{
26 v &= 0xf;
27 return (v < 10 ? '0' : 'a' - 10) + v;
28}
29
30static char hex_print(u8 c)
31{
32 return (0x20 <= c && c < 0x7f) ? c : '.';
33}
34
35static void dump_line(const u8 *bytes, size_t size)
36{
37 char c;
38 size_t i;
39
40 size = size <= 8 ? size : 8;
41 printk(KERN_DEBUG "zd1211 %p ", bytes);
42 for (i = 0; i < 8; i++) {
43 switch (i) {
44 case 1:
45 case 5:
46 c = '.';
47 break;
48 case 3:
49 c = ':';
50 break;
51 default:
52 c = ' ';
53 }
54 if (i < size) {
55 printk("%c%c%c", hex(bytes[i] >> 4), hex(bytes[i]), c);
56 } else {
57 printk(" %c", c);
58 }
59 }
60
61 for (i = 0; i < size; i++)
62 printk("%c", hex_print(bytes[i]));
63 printk("\n");
64}
65
66void zd_hexdump(const void *bytes, size_t size)
67{
68 size_t i = 0;
69
70 do {
71 dump_line((u8 *)bytes + i, size-i);
72 i += 8;
73 } while (i < size);
74}
75#endif /* DEBUG */
76
77void *zd_tail(const void *buffer, size_t buffer_size, size_t tail_size)
78{
79 if (buffer_size < tail_size)
80 return NULL;
81 return (u8 *)buffer + (buffer_size - tail_size);
82}
diff --git a/drivers/w1/w1_io.h b/drivers/net/wireless/zd1211rw/zd_util.h
index 9a76d2ad69c5..ce26f7adea92 100644
--- a/drivers/w1/w1_io.h
+++ b/drivers/net/wireless/zd1211rw/zd_util.h
@@ -1,8 +1,4 @@
1/* 1/* zd_util.h
2 * w1_io.h
3 *
4 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
5 *
6 * 2 *
7 * This program is free software; you can redistribute it and/or modify 3 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
@@ -19,18 +15,15 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 16 */
21 17
22#ifndef __W1_IO_H 18#ifndef _ZD_UTIL_H
23#define __W1_IO_H 19#define _ZD_UTIL_H
24 20
25#include "w1.h" 21void *zd_tail(const void *buffer, size_t buffer_size, size_t tail_size);
26 22
27u8 w1_triplet(struct w1_master *dev, int bdir); 23#ifdef DEBUG
28void w1_write_8(struct w1_master *, u8); 24void zd_hexdump(const void *bytes, size_t size);
29int w1_reset_bus(struct w1_master *); 25#else
30u8 w1_calc_crc8(u8 *, int); 26#define zd_hexdump(bytes, size)
31void w1_write_block(struct w1_master *, const u8 *, int); 27#endif /* DEBUG */
32u8 w1_read_block(struct w1_master *, u8 *, int);
33void w1_search_devices(struct w1_master *dev, w1_slave_found_callback cb);
34int w1_reset_select_slave(struct w1_slave *sl);
35 28
36#endif /* __W1_IO_H */ 29#endif /* _ZD_UTIL_H */
diff --git a/drivers/net/yellowfin.c b/drivers/net/yellowfin.c
index bbbf7e274a2a..8459a18254a4 100644
--- a/drivers/net/yellowfin.c
+++ b/drivers/net/yellowfin.c
@@ -19,37 +19,13 @@
19 19
20 Support and updates available at 20 Support and updates available at
21 http://www.scyld.com/network/yellowfin.html 21 http://www.scyld.com/network/yellowfin.html
22 [link no longer provides useful info -jgarzik]
22 23
23
24 Linux kernel changelog:
25 -----------------------
26
27 LK1.1.1 (jgarzik): Port to 2.4 kernel
28
29 LK1.1.2 (jgarzik):
30 * Merge in becker version 1.05
31
32 LK1.1.3 (jgarzik):
33 * Various cleanups
34 * Update yellowfin_timer to correctly calculate duplex.
35 (suggested by Manfred Spraul)
36
37 LK1.1.4 (val@nmt.edu):
38 * Fix three endian-ness bugs
39 * Support dual function SYM53C885E ethernet chip
40
41 LK1.1.5 (val@nmt.edu):
42 * Fix forced full-duplex bug I introduced
43
44 LK1.1.6 (val@nmt.edu):
45 * Only print warning on truly "oversized" packets
46 * Fix theoretical bug on gigabit cards - return to 1.1.3 behavior
47
48*/ 24*/
49 25
50#define DRV_NAME "yellowfin" 26#define DRV_NAME "yellowfin"
51#define DRV_VERSION "1.05+LK1.1.6" 27#define DRV_VERSION "2.0"
52#define DRV_RELDATE "Feb 11, 2002" 28#define DRV_RELDATE "Jun 27, 2006"
53 29
54#define PFX DRV_NAME ": " 30#define PFX DRV_NAME ": "
55 31
@@ -239,8 +215,11 @@ enum capability_flags {
239 HasMACAddrBug=32, /* Only on early revs. */ 215 HasMACAddrBug=32, /* Only on early revs. */
240 DontUseEeprom=64, /* Don't read the MAC from the EEPROm. */ 216 DontUseEeprom=64, /* Don't read the MAC from the EEPROm. */
241}; 217};
218
242/* The PCI I/O space extent. */ 219/* The PCI I/O space extent. */
243#define YELLOWFIN_SIZE 0x100 220enum {
221 YELLOWFIN_SIZE = 0x100,
222};
244 223
245struct pci_id_info { 224struct pci_id_info {
246 const char *name; 225 const char *name;
@@ -248,16 +227,14 @@ struct pci_id_info {
248 int pci, pci_mask, subsystem, subsystem_mask; 227 int pci, pci_mask, subsystem, subsystem_mask;
249 int revision, revision_mask; /* Only 8 bits. */ 228 int revision, revision_mask; /* Only 8 bits. */
250 } id; 229 } id;
251 int io_size; /* Needed for I/O region check or ioremap(). */
252 int drv_flags; /* Driver use, intended as capability flags. */ 230 int drv_flags; /* Driver use, intended as capability flags. */
253}; 231};
254 232
255static const struct pci_id_info pci_id_tbl[] = { 233static const struct pci_id_info pci_id_tbl[] = {
256 {"Yellowfin G-NIC Gigabit Ethernet", { 0x07021000, 0xffffffff}, 234 {"Yellowfin G-NIC Gigabit Ethernet", { 0x07021000, 0xffffffff},
257 YELLOWFIN_SIZE,
258 FullTxStatus | IsGigabit | HasMulticastBug | HasMACAddrBug | DontUseEeprom}, 235 FullTxStatus | IsGigabit | HasMulticastBug | HasMACAddrBug | DontUseEeprom},
259 {"Symbios SYM83C885", { 0x07011000, 0xffffffff}, 236 {"Symbios SYM83C885", { 0x07011000, 0xffffffff},
260 YELLOWFIN_SIZE, HasMII | DontUseEeprom }, 237 HasMII | DontUseEeprom },
261 { } 238 { }
262}; 239};
263 240
diff --git a/drivers/pci/hotplug/Kconfig b/drivers/pci/hotplug/Kconfig
index 222a1cc4aa28..8a60f391ffcf 100644
--- a/drivers/pci/hotplug/Kconfig
+++ b/drivers/pci/hotplug/Kconfig
@@ -6,8 +6,7 @@ menu "PCI Hotplug Support"
6 6
7config HOTPLUG_PCI 7config HOTPLUG_PCI
8 tristate "Support for PCI Hotplug (EXPERIMENTAL)" 8 tristate "Support for PCI Hotplug (EXPERIMENTAL)"
9 depends on PCI && EXPERIMENTAL 9 depends on PCI && EXPERIMENTAL && HOTPLUG
10 select HOTPLUG
11 ---help--- 10 ---help---
12 Say Y here if you have a motherboard with a PCI Hotplug controller. 11 Say Y here if you have a motherboard with a PCI Hotplug controller.
13 This allows you to add and remove PCI cards while the machine is 12 This allows you to add and remove PCI cards while the machine is
@@ -77,7 +76,7 @@ config HOTPLUG_PCI_IBM
77 76
78config HOTPLUG_PCI_ACPI 77config HOTPLUG_PCI_ACPI
79 tristate "ACPI PCI Hotplug driver" 78 tristate "ACPI PCI Hotplug driver"
80 depends on ACPI && HOTPLUG_PCI 79 depends on (!ACPI_DOCK && ACPI && HOTPLUG_PCI) || (ACPI_DOCK && HOTPLUG_PCI)
81 help 80 help
82 Say Y here if you have a system that supports PCI Hotplug using 81 Say Y here if you have a system that supports PCI Hotplug using
83 ACPI. 82 ACPI.
@@ -154,13 +153,6 @@ config HOTPLUG_PCI_SHPC_POLL_EVENT_MODE
154 153
155 When in doubt, say N. 154 When in doubt, say N.
156 155
157config HOTPLUG_PCI_SHPC_PHPRM_LEGACY
158 bool "For AMD SHPC only: Use $HRT for resource/configuration"
159 depends on HOTPLUG_PCI_SHPC && !ACPI
160 help
161 Say Y here for AMD SHPC. You have to select this option if you are
162 using this driver on platform with AMD SHPC.
163
164config HOTPLUG_PCI_RPA 156config HOTPLUG_PCI_RPA
165 tristate "RPA PCI Hotplug driver" 157 tristate "RPA PCI Hotplug driver"
166 depends on HOTPLUG_PCI && PPC_PSERIES && PPC64 && !HOTPLUG_PCI_FAKE 158 depends on HOTPLUG_PCI && PPC_PSERIES && PPC64 && !HOTPLUG_PCI_FAKE
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index 34de5697983d..e2fef60c2d06 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -27,8 +27,7 @@
27 * along with this program; if not, write to the Free Software 27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 * 29 *
30 * Send feedback to <gregkh@us.ibm.com>, 30 * Send feedback to <kristen.c.accardi@intel.com>
31 * <t-kochi@bq.jp.nec.com>
32 * 31 *
33 */ 32 */
34 33
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index ef95d12fb32c..ae67a8f55ba1 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -26,7 +26,7 @@
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * 28 *
29 * Send feedback to <t-kochi@bq.jp.nec.com> 29 * Send feedback to <kristen.c.accardi@intel.com>
30 * 30 *
31 */ 31 */
32 32
diff --git a/drivers/pci/hotplug/cpci_hotplug_pci.c b/drivers/pci/hotplug/cpci_hotplug_pci.c
index 02be74caa89f..4afcaffd031c 100644
--- a/drivers/pci/hotplug/cpci_hotplug_pci.c
+++ b/drivers/pci/hotplug/cpci_hotplug_pci.c
@@ -254,8 +254,8 @@ int cpci_led_off(struct slot* slot)
254 254
255int cpci_configure_slot(struct slot* slot) 255int cpci_configure_slot(struct slot* slot)
256{ 256{
257 unsigned char busnr; 257 struct pci_bus *parent;
258 struct pci_bus *child; 258 int fn;
259 259
260 dbg("%s - enter", __FUNCTION__); 260 dbg("%s - enter", __FUNCTION__);
261 261
@@ -276,23 +276,53 @@ int cpci_configure_slot(struct slot* slot)
276 */ 276 */
277 n = pci_scan_slot(slot->bus, slot->devfn); 277 n = pci_scan_slot(slot->bus, slot->devfn);
278 dbg("%s: pci_scan_slot returned %d", __FUNCTION__, n); 278 dbg("%s: pci_scan_slot returned %d", __FUNCTION__, n);
279 if (n > 0)
280 pci_bus_add_devices(slot->bus);
281 slot->dev = pci_get_slot(slot->bus, slot->devfn); 279 slot->dev = pci_get_slot(slot->bus, slot->devfn);
282 if (slot->dev == NULL) { 280 if (slot->dev == NULL) {
283 err("Could not find PCI device for slot %02x", slot->number); 281 err("Could not find PCI device for slot %02x", slot->number);
284 return 1; 282 return -ENODEV;
285 } 283 }
286 } 284 }
287 285 parent = slot->dev->bus;
288 if (slot->dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { 286
289 pci_read_config_byte(slot->dev, PCI_SECONDARY_BUS, &busnr); 287 for (fn = 0; fn < 8; fn++) {
290 child = pci_add_new_bus(slot->dev->bus, slot->dev, busnr); 288 struct pci_dev *dev;
291 pci_do_scan_bus(child); 289
292 pci_bus_size_bridges(child); 290 dev = pci_get_slot(parent, PCI_DEVFN(PCI_SLOT(slot->devfn), fn));
291 if (!dev)
292 continue;
293 if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) ||
294 (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) {
295 /* Find an unused bus number for the new bridge */
296 struct pci_bus *child;
297 unsigned char busnr, start = parent->secondary;
298 unsigned char end = parent->subordinate;
299
300 for (busnr = start; busnr <= end; busnr++) {
301 if (!pci_find_bus(pci_domain_nr(parent),
302 busnr))
303 break;
304 }
305 if (busnr >= end) {
306 err("No free bus for hot-added bridge\n");
307 pci_dev_put(dev);
308 continue;
309 }
310 child = pci_add_new_bus(parent, dev, busnr);
311 if (!child) {
312 err("Cannot add new bus for %s\n",
313 pci_name(dev));
314 pci_dev_put(dev);
315 continue;
316 }
317 child->subordinate = pci_do_scan_bus(child);
318 pci_bus_size_bridges(child);
319 }
320 pci_dev_put(dev);
293 } 321 }
294 322
295 pci_bus_assign_resources(slot->dev->bus); 323 pci_bus_assign_resources(parent);
324 pci_bus_add_devices(parent);
325 pci_enable_bridges(parent);
296 326
297 dbg("%s - exit", __FUNCTION__); 327 dbg("%s - exit", __FUNCTION__);
298 return 0; 328 return 0;
diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
index ce89f5815861..eaea9d36a1bb 100644
--- a/drivers/pci/hotplug/pciehp.h
+++ b/drivers/pci/hotplug/pciehp.h
@@ -279,6 +279,11 @@ struct hpc_ops {
279 279
280 280
281#ifdef CONFIG_ACPI 281#ifdef CONFIG_ACPI
282#include <acpi/acpi.h>
283#include <acpi/acpi_bus.h>
284#include <acpi/actypes.h>
285#include <linux/pci-acpi.h>
286
282#define pciehp_get_hp_hw_control_from_firmware(dev) \ 287#define pciehp_get_hp_hw_control_from_firmware(dev) \
283 pciehp_acpi_get_hp_hw_control_from_firmware(dev) 288 pciehp_acpi_get_hp_hw_control_from_firmware(dev)
284static inline int pciehp_get_hp_params_from_firmware(struct pci_dev *dev, 289static inline int pciehp_get_hp_params_from_firmware(struct pci_dev *dev,
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 0d8fb6e607a1..6ab3b6cd2b54 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -38,10 +38,6 @@
38 38
39#include "../pci.h" 39#include "../pci.h"
40#include "pciehp.h" 40#include "pciehp.h"
41#include <acpi/acpi.h>
42#include <acpi/acpi_bus.h>
43#include <acpi/actypes.h>
44#include <linux/pci-acpi.h>
45#ifdef DEBUG 41#ifdef DEBUG
46#define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */ 42#define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */
47#define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */ 43#define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 36bc7c415af7..a83c1f5735d6 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -47,13 +47,13 @@ msi_register(struct msi_ops *ops)
47 47
48static void msi_cache_ctor(void *p, kmem_cache_t *cache, unsigned long flags) 48static void msi_cache_ctor(void *p, kmem_cache_t *cache, unsigned long flags)
49{ 49{
50 memset(p, 0, NR_IRQS * sizeof(struct msi_desc)); 50 memset(p, 0, sizeof(struct msi_desc));
51} 51}
52 52
53static int msi_cache_init(void) 53static int msi_cache_init(void)
54{ 54{
55 msi_cachep = kmem_cache_create("msi_cache", 55 msi_cachep = kmem_cache_create("msi_cache",
56 NR_IRQS * sizeof(struct msi_desc), 56 sizeof(struct msi_desc),
57 0, SLAB_HWCACHE_ALIGN, msi_cache_ctor, NULL); 57 0, SLAB_HWCACHE_ALIGN, msi_cache_ctor, NULL);
58 if (!msi_cachep) 58 if (!msi_cachep)
59 return -ENOMEM; 59 return -ENOMEM;
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 10e1a905c144..474e9cd0e9e4 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -139,9 +139,8 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
139/** 139/**
140 * pci_match_device - Tell if a PCI device structure has a matching 140 * pci_match_device - Tell if a PCI device structure has a matching
141 * PCI device id structure 141 * PCI device id structure
142 * @ids: array of PCI device id structures to search in
143 * @dev: the PCI device structure to match against
144 * @drv: the PCI driver to match against 142 * @drv: the PCI driver to match against
143 * @dev: the PCI device structure to match against
145 * 144 *
146 * Used by a driver to check whether a PCI device present in the 145 * Used by a driver to check whether a PCI device present in the
147 * system is in its list of supported devices. Returns the matching 146 * system is in its list of supported devices. Returns the matching
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index cf57d7de3765..9f79dd6d51ab 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -19,6 +19,7 @@
19#include <asm/dma.h> /* isa_dma_bridge_buggy */ 19#include <asm/dma.h> /* isa_dma_bridge_buggy */
20#include "pci.h" 20#include "pci.h"
21 21
22unsigned int pci_pm_d3_delay = 10;
22 23
23/** 24/**
24 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children 25 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
@@ -313,6 +314,14 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
313 } else if (dev->current_state == state) 314 } else if (dev->current_state == state)
314 return 0; /* we're already there */ 315 return 0; /* we're already there */
315 316
317 /*
318 * If the device or the parent bridge can't support PCI PM, ignore
319 * the request if we're doing anything besides putting it into D0
320 * (which would only happen on boot).
321 */
322 if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev))
323 return 0;
324
316 /* find PCI PM capability in list */ 325 /* find PCI PM capability in list */
317 pm = pci_find_capability(dev, PCI_CAP_ID_PM); 326 pm = pci_find_capability(dev, PCI_CAP_ID_PM);
318 327
@@ -363,7 +372,7 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
363 /* Mandatory power management transition delays */ 372 /* Mandatory power management transition delays */
364 /* see PCI PM 1.1 5.6.1 table 18 */ 373 /* see PCI PM 1.1 5.6.1 table 18 */
365 if (state == PCI_D3hot || dev->current_state == PCI_D3hot) 374 if (state == PCI_D3hot || dev->current_state == PCI_D3hot)
366 msleep(10); 375 msleep(pci_pm_d3_delay);
367 else if (state == PCI_D2 || dev->current_state == PCI_D2) 376 else if (state == PCI_D2 || dev->current_state == PCI_D2)
368 udelay(200); 377 udelay(200);
369 378
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 9cc842b666eb..08d58fc78ee1 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -47,7 +47,7 @@ extern int pci_msi_quirk;
47#else 47#else
48#define pci_msi_quirk 0 48#define pci_msi_quirk 0
49#endif 49#endif
50 50extern unsigned int pci_pm_d3_delay;
51#ifdef CONFIG_PCI_MSI 51#ifdef CONFIG_PCI_MSI
52void disable_msi_mode(struct pci_dev *dev, int pos, int type); 52void disable_msi_mode(struct pci_dev *dev, int pos, int type);
53void pci_no_msi(void); 53void pci_no_msi(void);
@@ -66,7 +66,15 @@ static inline int pci_save_msix_state(struct pci_dev *dev) { return 0; }
66static inline void pci_restore_msi_state(struct pci_dev *dev) {} 66static inline void pci_restore_msi_state(struct pci_dev *dev) {}
67static inline void pci_restore_msix_state(struct pci_dev *dev) {} 67static inline void pci_restore_msix_state(struct pci_dev *dev) {}
68#endif 68#endif
69static inline int pci_no_d1d2(struct pci_dev *dev)
70{
71 unsigned int parent_dstates = 0;
69 72
73 if (dev->bus->self)
74 parent_dstates = dev->bus->self->no_d1d2;
75 return (dev->no_d1d2 || parent_dstates);
76
77}
70extern int pcie_mch_quirk; 78extern int pcie_mch_quirk;
71extern struct device_attribute pci_dev_attrs[]; 79extern struct device_attribute pci_dev_attrs[];
72extern struct class_device_attribute class_device_attr_cpuaffinity; 80extern struct class_device_attribute class_device_attr_cpuaffinity;
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index 50bfc1b2f3bf..478d0d28f7ad 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -30,23 +30,6 @@ MODULE_LICENSE("GPL");
30/* global data */ 30/* global data */
31static const char device_name[] = "pcieport-driver"; 31static const char device_name[] = "pcieport-driver";
32 32
33static int pcie_portdrv_save_config(struct pci_dev *dev)
34{
35 return pci_save_state(dev);
36}
37
38static int pcie_portdrv_restore_config(struct pci_dev *dev)
39{
40 int retval;
41
42 pci_restore_state(dev);
43 retval = pci_enable_device(dev);
44 if (retval)
45 return retval;
46 pci_set_master(dev);
47 return 0;
48}
49
50/* 33/*
51 * pcie_portdrv_probe - Probe PCI-Express port devices 34 * pcie_portdrv_probe - Probe PCI-Express port devices
52 * @dev: PCI-Express port device being probed 35 * @dev: PCI-Express port device being probed
@@ -73,8 +56,10 @@ static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
73 "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n", 56 "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n",
74 __FUNCTION__, dev->device, dev->vendor); 57 __FUNCTION__, dev->device, dev->vendor);
75 } 58 }
76 if (pcie_port_device_register(dev)) 59 if (pcie_port_device_register(dev)) {
60 pci_disable_device(dev);
77 return -ENOMEM; 61 return -ENOMEM;
62 }
78 63
79 return 0; 64 return 0;
80} 65}
@@ -86,6 +71,23 @@ static void pcie_portdrv_remove (struct pci_dev *dev)
86} 71}
87 72
88#ifdef CONFIG_PM 73#ifdef CONFIG_PM
74static int pcie_portdrv_save_config(struct pci_dev *dev)
75{
76 return pci_save_state(dev);
77}
78
79static int pcie_portdrv_restore_config(struct pci_dev *dev)
80{
81 int retval;
82
83 pci_restore_state(dev);
84 retval = pci_enable_device(dev);
85 if (retval)
86 return retval;
87 pci_set_master(dev);
88 return 0;
89}
90
89static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state) 91static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state)
90{ 92{
91 int ret = pcie_port_device_suspend(dev, state); 93 int ret = pcie_port_device_suspend(dev, state);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index f89dbc3738b7..c5a58d1c6c1c 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -815,6 +815,7 @@ pci_scan_device(struct pci_bus *bus, int devfn)
815 dev->vendor = l & 0xffff; 815 dev->vendor = l & 0xffff;
816 dev->device = (l >> 16) & 0xffff; 816 dev->device = (l >> 16) & 0xffff;
817 dev->cfg_size = pci_cfg_space_size(dev); 817 dev->cfg_size = pci_cfg_space_size(dev);
818 dev->error_state = pci_channel_io_normal;
818 819
819 /* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer) 820 /* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer)
820 set this higher, assuming the system even supports it. */ 821 set this higher, assuming the system even supports it. */
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index d1d7333bb71b..17e709e7d72a 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -400,6 +400,7 @@ static void __devinit quirk_piix4_acpi(struct pci_dev *dev)
400 piix4_io_quirk(dev, "PIIX4 devres J", 0x7c, 1 << 20); 400 piix4_io_quirk(dev, "PIIX4 devres J", 0x7c, 1 << 20);
401} 401}
402DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, quirk_piix4_acpi ); 402DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, quirk_piix4_acpi );
403DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3, quirk_piix4_acpi );
403 404
404/* 405/*
405 * ICH4, ICH4-M, ICH5, ICH5-M ACPI: Three IO regions pointed to by longwords at 406 * ICH4, ICH4-M, ICH5, ICH5-M ACPI: Three IO regions pointed to by longwords at
@@ -437,6 +438,7 @@ static void __devinit quirk_ich6_lpc_acpi(struct pci_dev *dev)
437 pci_read_config_dword(dev, 0x48, &region); 438 pci_read_config_dword(dev, 0x48, &region);
438 quirk_io_region(dev, region, 64, PCI_BRIDGE_RESOURCES+1, "ICH6 GPIO"); 439 quirk_io_region(dev, region, 64, PCI_BRIDGE_RESOURCES+1, "ICH6 GPIO");
439} 440}
441DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0, quirk_ich6_lpc_acpi );
440DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, quirk_ich6_lpc_acpi ); 442DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, quirk_ich6_lpc_acpi );
441 443
442/* 444/*
@@ -665,6 +667,7 @@ DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_0, quirk_vi
665DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, quirk_via_irq); 667DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, quirk_via_irq);
666DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_2, quirk_via_irq); 668DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_2, quirk_via_irq);
667DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_via_irq); 669DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_via_irq);
670DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235_USB_2, quirk_via_irq);
668DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_irq); 671DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_irq);
669DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_via_irq); 672DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_via_irq);
670DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5, quirk_via_irq); 673DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5, quirk_via_irq);
@@ -682,6 +685,33 @@ static void __devinit quirk_vt82c598_id(struct pci_dev *dev)
682} 685}
683DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C597_0, quirk_vt82c598_id ); 686DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C597_0, quirk_vt82c598_id );
684 687
688#ifdef CONFIG_ACPI_SLEEP
689
690/*
691 * Some VIA systems boot with the abnormal status flag set. This can cause
692 * the BIOS to re-POST the system on resume rather than passing control
693 * back to the OS. Clear the flag on boot
694 */
695static void __devinit quirk_via_abnormal_poweroff(struct pci_dev *dev)
696{
697 u32 reg;
698
699 acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS,
700 &reg);
701
702 if (reg & 0x800) {
703 printk("Clearing abnormal poweroff flag\n");
704 acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK,
705 ACPI_REGISTER_PM1_STATUS,
706 (u16)0x800);
707 }
708}
709
710DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_via_abnormal_poweroff);
711DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_abnormal_poweroff);
712
713#endif
714
685/* 715/*
686 * CardBus controllers have a legacy base address that enables them 716 * CardBus controllers have a legacy base address that enables them
687 * to respond as i82365 pcmcia controllers. We don't want them to 717 * to respond as i82365 pcmcia controllers. We don't want them to
@@ -962,6 +992,11 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
962 case 0x8070: /* P4G8X Deluxe */ 992 case 0x8070: /* P4G8X Deluxe */
963 asus_hides_smbus = 1; 993 asus_hides_smbus = 1;
964 } 994 }
995 if (dev->device == PCI_DEVICE_ID_INTEL_E7501_MCH)
996 switch (dev->subsystem_device) {
997 case 0x80c9: /* PU-DLS */
998 asus_hides_smbus = 1;
999 }
965 if (dev->device == PCI_DEVICE_ID_INTEL_82855GM_HB) 1000 if (dev->device == PCI_DEVICE_ID_INTEL_82855GM_HB)
966 switch (dev->subsystem_device) { 1001 switch (dev->subsystem_device) {
967 case 0x1751: /* M2N notebook */ 1002 case 0x1751: /* M2N notebook */
@@ -1030,6 +1065,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845G_HB, asu
1030DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82850_HB, asus_hides_smbus_hostbridge ); 1065DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82850_HB, asus_hides_smbus_hostbridge );
1031DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82865_HB, asus_hides_smbus_hostbridge ); 1066DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82865_HB, asus_hides_smbus_hostbridge );
1032DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_7205_0, asus_hides_smbus_hostbridge ); 1067DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_7205_0, asus_hides_smbus_hostbridge );
1068DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7501_MCH, asus_hides_smbus_hostbridge );
1033DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855PM_HB, asus_hides_smbus_hostbridge ); 1069DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855PM_HB, asus_hides_smbus_hostbridge );
1034DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge ); 1070DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge );
1035DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge ); 1071DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge );
@@ -1053,10 +1089,10 @@ static void __init asus_hides_smbus_lpc(struct pci_dev *dev)
1053} 1089}
1054DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc ); 1090DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc );
1055DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc ); 1091DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc );
1092DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc );
1056DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc ); 1093DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc );
1057DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc ); 1094DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc );
1058DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc ); 1095DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc );
1059DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc );
1060 1096
1061static void __init asus_hides_smbus_lpc_ich6(struct pci_dev *dev) 1097static void __init asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
1062{ 1098{
@@ -1174,6 +1210,55 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_
1174DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus ); 1210DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus );
1175DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus ); 1211DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus );
1176 1212
1213#if defined(CONFIG_SCSI_SATA) || defined(CONFIG_SCSI_SATA_MODULE)
1214
1215/*
1216 * If we are using libata we can drive this chip properly but must
1217 * do this early on to make the additional device appear during
1218 * the PCI scanning.
1219 */
1220
1221static void __devinit quirk_jmicron_dualfn(struct pci_dev *pdev)
1222{
1223 u32 conf;
1224 u8 hdr;
1225
1226 /* Only poke fn 0 */
1227 if (PCI_FUNC(pdev->devfn))
1228 return;
1229
1230 switch(pdev->device) {
1231 case PCI_DEVICE_ID_JMICRON_JMB365:
1232 case PCI_DEVICE_ID_JMICRON_JMB366:
1233 /* Redirect IDE second PATA port to the right spot */
1234 pci_read_config_dword(pdev, 0x80, &conf);
1235 conf |= (1 << 24);
1236 /* Fall through */
1237 pci_write_config_dword(pdev, 0x80, conf);
1238 case PCI_DEVICE_ID_JMICRON_JMB361:
1239 case PCI_DEVICE_ID_JMICRON_JMB363:
1240 pci_read_config_dword(pdev, 0x40, &conf);
1241 /* Enable dual function mode, AHCI on fn 0, IDE fn1 */
1242 /* Set the class codes correctly and then direct IDE 0 */
1243 conf &= ~0x000F0200; /* Clear bit 9 and 16-19 */
1244 conf |= 0x00C20002; /* Set bit 1, 17, 22, 23 */
1245 pci_write_config_dword(pdev, 0x40, conf);
1246
1247 /* Reconfigure so that the PCI scanner discovers the
1248 device is now multifunction */
1249
1250 pci_read_config_byte(pdev, PCI_HEADER_TYPE, &hdr);
1251 pdev->hdr_type = hdr & 0x7f;
1252 pdev->multifunction = !!(hdr & 0x80);
1253
1254 break;
1255 }
1256}
1257
1258DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, quirk_jmicron_dualfn);
1259
1260#endif
1261
1177#ifdef CONFIG_X86_IO_APIC 1262#ifdef CONFIG_X86_IO_APIC
1178static void __init quirk_alder_ioapic(struct pci_dev *pdev) 1263static void __init quirk_alder_ioapic(struct pci_dev *pdev)
1179{ 1264{
@@ -1341,6 +1426,37 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0, quirk_pc
1341DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1, quirk_pcie_pxh); 1426DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1, quirk_pcie_pxh);
1342DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHV, quirk_pcie_pxh); 1427DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHV, quirk_pcie_pxh);
1343 1428
1429/*
1430 * Some Intel PCI Express chipsets have trouble with downstream
1431 * device power management.
1432 */
1433static void quirk_intel_pcie_pm(struct pci_dev * dev)
1434{
1435 pci_pm_d3_delay = 120;
1436 dev->no_d1d2 = 1;
1437}
1438
1439DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e2, quirk_intel_pcie_pm);
1440DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e3, quirk_intel_pcie_pm);
1441DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e4, quirk_intel_pcie_pm);
1442DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e5, quirk_intel_pcie_pm);
1443DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e6, quirk_intel_pcie_pm);
1444DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e7, quirk_intel_pcie_pm);
1445DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25f7, quirk_intel_pcie_pm);
1446DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25f8, quirk_intel_pcie_pm);
1447DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25f9, quirk_intel_pcie_pm);
1448DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25fa, quirk_intel_pcie_pm);
1449DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2601, quirk_intel_pcie_pm);
1450DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2602, quirk_intel_pcie_pm);
1451DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2603, quirk_intel_pcie_pm);
1452DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2604, quirk_intel_pcie_pm);
1453DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2605, quirk_intel_pcie_pm);
1454DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2606, quirk_intel_pcie_pm);
1455DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2607, quirk_intel_pcie_pm);
1456DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2608, quirk_intel_pcie_pm);
1457DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2609, quirk_intel_pcie_pm);
1458DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x260a, quirk_intel_pcie_pm);
1459DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x260b, quirk_intel_pcie_pm);
1344 1460
1345/* 1461/*
1346 * Fixup the cardbus bridges on the IBM Dock II docking station 1462 * Fixup the cardbus bridges on the IBM Dock II docking station
@@ -1403,6 +1519,63 @@ static void __devinit quirk_netmos(struct pci_dev *dev)
1403} 1519}
1404DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NETMOS, PCI_ANY_ID, quirk_netmos); 1520DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NETMOS, PCI_ANY_ID, quirk_netmos);
1405 1521
1522static void __devinit quirk_e100_interrupt(struct pci_dev *dev)
1523{
1524 u16 command;
1525 u32 bar;
1526 u8 __iomem *csr;
1527 u8 cmd_hi;
1528
1529 switch (dev->device) {
1530 /* PCI IDs taken from drivers/net/e100.c */
1531 case 0x1029:
1532 case 0x1030 ... 0x1034:
1533 case 0x1038 ... 0x103E:
1534 case 0x1050 ... 0x1057:
1535 case 0x1059:
1536 case 0x1064 ... 0x106B:
1537 case 0x1091 ... 0x1095:
1538 case 0x1209:
1539 case 0x1229:
1540 case 0x2449:
1541 case 0x2459:
1542 case 0x245D:
1543 case 0x27DC:
1544 break;
1545 default:
1546 return;
1547 }
1548
1549 /*
1550 * Some firmware hands off the e100 with interrupts enabled,
1551 * which can cause a flood of interrupts if packets are
1552 * received before the driver attaches to the device. So
1553 * disable all e100 interrupts here. The driver will
1554 * re-enable them when it's ready.
1555 */
1556 pci_read_config_word(dev, PCI_COMMAND, &command);
1557 pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar);
1558
1559 if (!(command & PCI_COMMAND_MEMORY) || !bar)
1560 return;
1561
1562 csr = ioremap(bar, 8);
1563 if (!csr) {
1564 printk(KERN_WARNING "PCI: Can't map %s e100 registers\n",
1565 pci_name(dev));
1566 return;
1567 }
1568
1569 cmd_hi = readb(csr + 3);
1570 if (cmd_hi == 0) {
1571 printk(KERN_WARNING "PCI: Firmware left %s e100 interrupts "
1572 "enabled, disabling\n", pci_name(dev));
1573 writeb(1, csr + 3);
1574 }
1575
1576 iounmap(csr);
1577}
1578DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, quirk_e100_interrupt);
1406 1579
1407static void __devinit fixup_rev1_53c810(struct pci_dev* dev) 1580static void __devinit fixup_rev1_53c810(struct pci_dev* dev)
1408{ 1581{
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 622b3f8ba820..d529462d1b53 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -41,7 +41,7 @@ pci_do_find_bus(struct pci_bus* bus, unsigned char busnr)
41 * in the global list of PCI buses. If the bus is found, a pointer to its 41 * in the global list of PCI buses. If the bus is found, a pointer to its
42 * data structure is returned. If no bus is found, %NULL is returned. 42 * data structure is returned. If no bus is found, %NULL is returned.
43 */ 43 */
44struct pci_bus * __devinit pci_find_bus(int domain, int busnr) 44struct pci_bus * pci_find_bus(int domain, int busnr)
45{ 45{
46 struct pci_bus *bus = NULL; 46 struct pci_bus *bus = NULL;
47 struct pci_bus *tmp_bus; 47 struct pci_bus *tmp_bus;
@@ -61,7 +61,7 @@ struct pci_bus * __devinit pci_find_bus(int domain, int busnr)
61 * @from: Previous PCI bus found, or %NULL for new search. 61 * @from: Previous PCI bus found, or %NULL for new search.
62 * 62 *
63 * Iterates through the list of known PCI busses. A new search is 63 * Iterates through the list of known PCI busses. A new search is
64 * initiated by passing %NULL to the @from argument. Otherwise if 64 * initiated by passing %NULL as the @from argument. Otherwise if
65 * @from is not %NULL, searches continue from next device on the 65 * @from is not %NULL, searches continue from next device on the
66 * global list. 66 * global list.
67 */ 67 */
@@ -148,13 +148,14 @@ struct pci_dev * pci_get_slot(struct pci_bus *bus, unsigned int devfn)
148 * @from: Previous PCI device found in search, or %NULL for new search. 148 * @from: Previous PCI device found in search, or %NULL for new search.
149 * 149 *
150 * Iterates through the list of known PCI devices. If a PCI device is 150 * Iterates through the list of known PCI devices. If a PCI device is
151 * found with a matching @vendor, @device, @ss_vendor and @ss_device, a pointer to its 151 * found with a matching @vendor, @device, @ss_vendor and @ss_device, a
152 * device structure is returned. Otherwise, %NULL is returned. 152 * pointer to its device structure is returned. Otherwise, %NULL is returned.
153 * A new search is initiated by passing %NULL to the @from argument. 153 * A new search is initiated by passing %NULL as the @from argument.
154 * Otherwise if @from is not %NULL, searches continue from next device on the global list. 154 * Otherwise if @from is not %NULL, searches continue from next device
155 * on the global list.
155 * 156 *
156 * NOTE: Do not use this function anymore, use pci_get_subsys() instead, as 157 * NOTE: Do not use this function any more; use pci_get_subsys() instead, as
157 * the pci device returned by this function can disappear at any moment in 158 * the PCI device returned by this function can disappear at any moment in
158 * time. 159 * time.
159 */ 160 */
160static struct pci_dev * pci_find_subsys(unsigned int vendor, 161static struct pci_dev * pci_find_subsys(unsigned int vendor,
@@ -191,14 +192,15 @@ exit:
191 * @device: PCI device id to match, or %PCI_ANY_ID to match all device ids 192 * @device: PCI device id to match, or %PCI_ANY_ID to match all device ids
192 * @from: Previous PCI device found in search, or %NULL for new search. 193 * @from: Previous PCI device found in search, or %NULL for new search.
193 * 194 *
194 * Iterates through the list of known PCI devices. If a PCI device is 195 * Iterates through the list of known PCI devices. If a PCI device is found
195 * found with a matching @vendor and @device, a pointer to its device structure is 196 * with a matching @vendor and @device, a pointer to its device structure is
196 * returned. Otherwise, %NULL is returned. 197 * returned. Otherwise, %NULL is returned.
197 * A new search is initiated by passing %NULL to the @from argument. 198 * A new search is initiated by passing %NULL as the @from argument.
198 * Otherwise if @from is not %NULL, searches continue from next device on the global list. 199 * Otherwise if @from is not %NULL, searches continue from next device
200 * on the global list.
199 * 201 *
200 * NOTE: Do not use this function anymore, use pci_get_device() instead, as 202 * NOTE: Do not use this function any more; use pci_get_device() instead, as
201 * the pci device returned by this function can disappear at any moment in 203 * the PCI device returned by this function can disappear at any moment in
202 * time. 204 * time.
203 */ 205 */
204struct pci_dev * 206struct pci_dev *
@@ -215,11 +217,11 @@ pci_find_device(unsigned int vendor, unsigned int device, const struct pci_dev *
215 * @ss_device: PCI subsystem device id to match, or %PCI_ANY_ID to match all device ids 217 * @ss_device: PCI subsystem device id to match, or %PCI_ANY_ID to match all device ids
216 * @from: Previous PCI device found in search, or %NULL for new search. 218 * @from: Previous PCI device found in search, or %NULL for new search.
217 * 219 *
218 * Iterates through the list of known PCI devices. If a PCI device is 220 * Iterates through the list of known PCI devices. If a PCI device is found
219 * found with a matching @vendor, @device, @ss_vendor and @ss_device, a pointer to its 221 * with a matching @vendor, @device, @ss_vendor and @ss_device, a pointer to its
220 * device structure is returned, and the reference count to the device is 222 * device structure is returned, and the reference count to the device is
221 * incremented. Otherwise, %NULL is returned. A new search is initiated by 223 * incremented. Otherwise, %NULL is returned. A new search is initiated by
222 * passing %NULL to the @from argument. Otherwise if @from is not %NULL, 224 * passing %NULL as the @from argument. Otherwise if @from is not %NULL,
223 * searches continue from next device on the global list. 225 * searches continue from next device on the global list.
224 * The reference count for @from is always decremented if it is not %NULL. 226 * The reference count for @from is always decremented if it is not %NULL.
225 */ 227 */
@@ -262,7 +264,7 @@ exit:
262 * found with a matching @vendor and @device, the reference count to the 264 * found with a matching @vendor and @device, the reference count to the
263 * device is incremented and a pointer to its device structure is returned. 265 * device is incremented and a pointer to its device structure is returned.
264 * Otherwise, %NULL is returned. A new search is initiated by passing %NULL 266 * Otherwise, %NULL is returned. A new search is initiated by passing %NULL
265 * to the @from argument. Otherwise if @from is not %NULL, searches continue 267 * as the @from argument. Otherwise if @from is not %NULL, searches continue
266 * from next device on the global list. The reference count for @from is 268 * from next device on the global list. The reference count for @from is
267 * always decremented if it is not %NULL. 269 * always decremented if it is not %NULL.
268 */ 270 */
@@ -279,11 +281,13 @@ pci_get_device(unsigned int vendor, unsigned int device, struct pci_dev *from)
279 * @device: PCI device id to match, or %PCI_ANY_ID to match all device ids 281 * @device: PCI device id to match, or %PCI_ANY_ID to match all device ids
280 * @from: Previous PCI device found in search, or %NULL for new search. 282 * @from: Previous PCI device found in search, or %NULL for new search.
281 * 283 *
282 * Iterates through the list of known PCI devices in the reverse order of pci_find_device(). 284 * Iterates through the list of known PCI devices in the reverse order of
285 * pci_find_device().
283 * If a PCI device is found with a matching @vendor and @device, a pointer to 286 * If a PCI device is found with a matching @vendor and @device, a pointer to
284 * its device structure is returned. Otherwise, %NULL is returned. 287 * its device structure is returned. Otherwise, %NULL is returned.
285 * A new search is initiated by passing %NULL to the @from argument. 288 * A new search is initiated by passing %NULL as the @from argument.
286 * Otherwise if @from is not %NULL, searches continue from previous device on the global list. 289 * Otherwise if @from is not %NULL, searches continue from previous device
290 * on the global list.
287 */ 291 */
288struct pci_dev * 292struct pci_dev *
289pci_find_device_reverse(unsigned int vendor, unsigned int device, const struct pci_dev *from) 293pci_find_device_reverse(unsigned int vendor, unsigned int device, const struct pci_dev *from)
@@ -317,7 +321,7 @@ exit:
317 * found with a matching @class, the reference count to the device is 321 * found with a matching @class, the reference count to the device is
318 * incremented and a pointer to its device structure is returned. 322 * incremented and a pointer to its device structure is returned.
319 * Otherwise, %NULL is returned. 323 * Otherwise, %NULL is returned.
320 * A new search is initiated by passing %NULL to the @from argument. 324 * A new search is initiated by passing %NULL as the @from argument.
321 * Otherwise if @from is not %NULL, searches continue from next device 325 * Otherwise if @from is not %NULL, searches continue from next device
322 * on the global list. The reference count for @from is always decremented 326 * on the global list. The reference count for @from is always decremented
323 * if it is not %NULL. 327 * if it is not %NULL.
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index 61cb4b29f55c..35f88649d3b7 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -6,7 +6,7 @@ menu "PCCARD (PCMCIA/CardBus) support"
6 6
7config PCCARD 7config PCCARD
8 tristate "PCCard (PCMCIA/CardBus) support" 8 tristate "PCCard (PCMCIA/CardBus) support"
9 select HOTPLUG 9 depends on HOTPLUG
10 ---help--- 10 ---help---
11 Say Y here if you want to attach PCMCIA- or PC-cards to your Linux 11 Say Y here if you want to attach PCMCIA- or PC-cards to your Linux
12 computer. These are credit-card size devices such as network cards, 12 computer. These are credit-card size devices such as network cards,
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
index 738b1ef595a3..9ad18e62658d 100644
--- a/drivers/pcmcia/pcmcia_ioctl.c
+++ b/drivers/pcmcia/pcmcia_ioctl.c
@@ -601,12 +601,8 @@ static int ds_ioctl(struct inode * inode, struct file * file,
601 ret = CS_BAD_ARGS; 601 ret = CS_BAD_ARGS;
602 else { 602 else {
603 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->config.Function); 603 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->config.Function);
604 if (p_dev == NULL) 604 ret = pccard_get_configuration_info(s, p_dev, &buf->config);
605 ret = CS_BAD_ARGS; 605 pcmcia_put_dev(p_dev);
606 else {
607 ret = pccard_get_configuration_info(s, p_dev, &buf->config);
608 pcmcia_put_dev(p_dev);
609 }
610 } 606 }
611 break; 607 break;
612 case DS_GET_FIRST_TUPLE: 608 case DS_GET_FIRST_TUPLE:
@@ -636,12 +632,8 @@ static int ds_ioctl(struct inode * inode, struct file * file,
636 ret = CS_BAD_ARGS; 632 ret = CS_BAD_ARGS;
637 else { 633 else {
638 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->status.Function); 634 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->status.Function);
639 if (p_dev == NULL) 635 ret = pccard_get_status(s, p_dev, &buf->status);
640 ret = CS_BAD_ARGS; 636 pcmcia_put_dev(p_dev);
641 else {
642 ret = pccard_get_status(s, p_dev, &buf->status);
643 pcmcia_put_dev(p_dev);
644 }
645 } 637 }
646 break; 638 break;
647 case DS_VALIDATE_CIS: 639 case DS_VALIDATE_CIS:
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c
index 7bf25b88ea31..c8323399e9e4 100644
--- a/drivers/pcmcia/pcmcia_resource.c
+++ b/drivers/pcmcia/pcmcia_resource.c
@@ -245,10 +245,17 @@ int pccard_get_configuration_info(struct pcmcia_socket *s,
245 return CS_SUCCESS; 245 return CS_SUCCESS;
246 } 246 }
247 247
248 /* !!! This is a hack !!! */ 248 config->Attributes = c->Attributes | CONF_VALID_CLIENT;
249 memcpy(&config->Attributes, &c->Attributes, sizeof(config_t)); 249 config->Vcc = s->socket.Vcc;
250 config->Attributes |= CONF_VALID_CLIENT; 250 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
251 config->CardValues = c->CardValues; 251 config->IntType = c->IntType;
252 config->ConfigBase = c->ConfigBase;
253 config->Status = c->Status;
254 config->Pin = c->Pin;
255 config->Copy = c->Copy;
256 config->Option = c->Option;
257 config->ExtStatus = c->ExtStatus;
258 config->Present = config->CardValues = c->CardValues;
252 config->IRQAttributes = c->irq.Attributes; 259 config->IRQAttributes = c->irq.Attributes;
253 config->AssignedIRQ = s->irq.AssignedIRQ; 260 config->AssignedIRQ = s->irq.AssignedIRQ;
254 config->BasePort1 = c->io.BasePort1; 261 config->BasePort1 = c->io.BasePort1;
diff --git a/drivers/pnp/interface.c b/drivers/pnp/interface.c
index 3163e3d73da1..9d8b415eca79 100644
--- a/drivers/pnp/interface.c
+++ b/drivers/pnp/interface.c
@@ -265,8 +265,8 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, struct device_at
265 pnp_printf(buffer," disabled\n"); 265 pnp_printf(buffer," disabled\n");
266 else 266 else
267 pnp_printf(buffer," 0x%llx-0x%llx\n", 267 pnp_printf(buffer," 0x%llx-0x%llx\n",
268 pnp_port_start(dev, i), 268 (unsigned long long)pnp_port_start(dev, i),
269 pnp_port_end(dev, i)); 269 (unsigned long long)pnp_port_end(dev, i));
270 } 270 }
271 } 271 }
272 for (i = 0; i < PNP_MAX_MEM; i++) { 272 for (i = 0; i < PNP_MAX_MEM; i++) {
@@ -276,8 +276,8 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, struct device_at
276 pnp_printf(buffer," disabled\n"); 276 pnp_printf(buffer," disabled\n");
277 else 277 else
278 pnp_printf(buffer," 0x%llx-0x%llx\n", 278 pnp_printf(buffer," 0x%llx-0x%llx\n",
279 pnp_mem_start(dev, i), 279 (unsigned long long)pnp_mem_start(dev, i),
280 pnp_mem_end(dev, i)); 280 (unsigned long long)pnp_mem_end(dev, i));
281 } 281 }
282 } 282 }
283 for (i = 0; i < PNP_MAX_IRQ; i++) { 283 for (i = 0; i < PNP_MAX_IRQ; i++) {
@@ -287,7 +287,7 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, struct device_at
287 pnp_printf(buffer," disabled\n"); 287 pnp_printf(buffer," disabled\n");
288 else 288 else
289 pnp_printf(buffer," %lld\n", 289 pnp_printf(buffer," %lld\n",
290 pnp_irq(dev, i)); 290 (unsigned long long)pnp_irq(dev, i));
291 } 291 }
292 } 292 }
293 for (i = 0; i < PNP_MAX_DMA; i++) { 293 for (i = 0; i < PNP_MAX_DMA; i++) {
@@ -297,7 +297,7 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, struct device_at
297 pnp_printf(buffer," disabled\n"); 297 pnp_printf(buffer," disabled\n");
298 else 298 else
299 pnp_printf(buffer," %lld\n", 299 pnp_printf(buffer," %lld\n",
300 pnp_dma(dev, i)); 300 (unsigned long long)pnp_dma(dev, i));
301 } 301 }
302 } 302 }
303 ret = (buffer->curr - buf); 303 ret = (buffer->curr - buf);
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index 3a4a644c2686..dc79b0a0059f 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -74,7 +74,7 @@ static void decode_irq_flags(int flag, int *triggering, int *polarity)
74 74
75static void 75static void
76pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res, u32 gsi, 76pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res, u32 gsi,
77 int triggering, int polarity) 77 int triggering, int polarity, int shareable)
78{ 78{
79 int i = 0; 79 int i = 0;
80 int irq; 80 int irq;
@@ -95,6 +95,9 @@ pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res, u32 gsi,
95 return; 95 return;
96 } 96 }
97 97
98 if (shareable)
99 res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE;
100
98 res->irq_resource[i].start = irq; 101 res->irq_resource[i].start = irq;
99 res->irq_resource[i].end = irq; 102 res->irq_resource[i].end = irq;
100 pcibios_penalize_isa_irq(irq, 1); 103 pcibios_penalize_isa_irq(irq, 1);
@@ -170,6 +173,9 @@ pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
170 return; 173 return;
171 } 174 }
172 175
176 if (p->producer_consumer == ACPI_PRODUCER)
177 return;
178
173 if (p->resource_type == ACPI_MEMORY_RANGE) 179 if (p->resource_type == ACPI_MEMORY_RANGE)
174 pnpacpi_parse_allocated_memresource(res_table, 180 pnpacpi_parse_allocated_memresource(res_table,
175 p->minimum, p->address_length); 181 p->minimum, p->address_length);
@@ -194,7 +200,8 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
194 pnpacpi_parse_allocated_irqresource(res_table, 200 pnpacpi_parse_allocated_irqresource(res_table,
195 res->data.irq.interrupts[i], 201 res->data.irq.interrupts[i],
196 res->data.irq.triggering, 202 res->data.irq.triggering,
197 res->data.irq.polarity); 203 res->data.irq.polarity,
204 res->data.irq.sharable);
198 } 205 }
199 break; 206 break;
200 207
@@ -248,14 +255,20 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
248 break; 255 break;
249 256
250 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: 257 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
258 if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
259 return AE_OK;
251 break; 260 break;
252 261
253 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: 262 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
263 if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER)
264 return AE_OK;
265
254 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) { 266 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
255 pnpacpi_parse_allocated_irqresource(res_table, 267 pnpacpi_parse_allocated_irqresource(res_table,
256 res->data.extended_irq.interrupts[i], 268 res->data.extended_irq.interrupts[i],
257 res->data.extended_irq.triggering, 269 res->data.extended_irq.triggering,
258 res->data.extended_irq.polarity); 270 res->data.extended_irq.polarity,
271 res->data.extended_irq.sharable);
259 } 272 }
260 break; 273 break;
261 274
diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c
index b154b3f52cbe..551f58e29810 100644
--- a/drivers/pnp/pnpbios/core.c
+++ b/drivers/pnp/pnpbios/core.c
@@ -346,7 +346,7 @@ static int insert_device(struct pnp_dev *dev, struct pnp_bios_node * node)
346 dev->flags = node->flags; 346 dev->flags = node->flags;
347 if (!(dev->flags & PNPBIOS_NO_CONFIG)) 347 if (!(dev->flags & PNPBIOS_NO_CONFIG))
348 dev->capabilities |= PNP_CONFIGURABLE; 348 dev->capabilities |= PNP_CONFIGURABLE;
349 if (!(dev->flags & PNPBIOS_NO_DISABLE)) 349 if (!(dev->flags & PNPBIOS_NO_DISABLE) && pnpbios_is_dynamic(dev))
350 dev->capabilities |= PNP_DISABLE; 350 dev->capabilities |= PNP_DISABLE;
351 dev->capabilities |= PNP_READ; 351 dev->capabilities |= PNP_READ;
352 if (pnpbios_is_dynamic(dev)) 352 if (pnpbios_is_dynamic(dev))
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index f5b9f187a930..7ff1d88094b6 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -121,6 +121,16 @@ config RTC_DRV_DS1553
121 This driver can also be built as a module. If so, the module 121 This driver can also be built as a module. If so, the module
122 will be called rtc-ds1553. 122 will be called rtc-ds1553.
123 123
124config RTC_DRV_ISL1208
125 tristate "Intersil 1208"
126 depends on RTC_CLASS && I2C
127 help
128 If you say yes here you get support for the
129 Intersil 1208 RTC chip.
130
131 This driver can also be built as a module. If so, the module
132 will be called rtc-isl1208.
133
124config RTC_DRV_DS1672 134config RTC_DRV_DS1672
125 tristate "Dallas/Maxim DS1672" 135 tristate "Dallas/Maxim DS1672"
126 depends on RTC_CLASS && I2C 136 depends on RTC_CLASS && I2C
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 54220714ff49..bbcfb09d81d9 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o
12obj-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o 12obj-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o
13 13
14obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o 14obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
15obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
15obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o 16obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
16obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o 17obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o
17obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o 18obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
new file mode 100644
index 000000000000..f324d0a635d4
--- /dev/null
+++ b/drivers/rtc/rtc-isl1208.c
@@ -0,0 +1,591 @@
1/*
2 * Intersil ISL1208 rtc class driver
3 *
4 * Copyright 2005,2006 Hebert Valerio Riedel <hvr@gnu.org>
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
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 */
12
13#include <linux/module.h>
14#include <linux/i2c.h>
15#include <linux/bcd.h>
16#include <linux/rtc.h>
17
18#define DRV_NAME "isl1208"
19#define DRV_VERSION "0.2"
20
21/* Register map */
22/* rtc section */
23#define ISL1208_REG_SC 0x00
24#define ISL1208_REG_MN 0x01
25#define ISL1208_REG_HR 0x02
26#define ISL1208_REG_HR_MIL (1<<7) /* 24h/12h mode */
27#define ISL1208_REG_HR_PM (1<<5) /* PM/AM bit in 12h mode */
28#define ISL1208_REG_DT 0x03
29#define ISL1208_REG_MO 0x04
30#define ISL1208_REG_YR 0x05
31#define ISL1208_REG_DW 0x06
32#define ISL1208_RTC_SECTION_LEN 7
33
34/* control/status section */
35#define ISL1208_REG_SR 0x07
36#define ISL1208_REG_SR_ARST (1<<7) /* auto reset */
37#define ISL1208_REG_SR_XTOSCB (1<<6) /* crystal oscillator */
38#define ISL1208_REG_SR_WRTC (1<<4) /* write rtc */
39#define ISL1208_REG_SR_ALM (1<<2) /* alarm */
40#define ISL1208_REG_SR_BAT (1<<1) /* battery */
41#define ISL1208_REG_SR_RTCF (1<<0) /* rtc fail */
42#define ISL1208_REG_INT 0x08
43#define ISL1208_REG_09 0x09 /* reserved */
44#define ISL1208_REG_ATR 0x0a
45#define ISL1208_REG_DTR 0x0b
46
47/* alarm section */
48#define ISL1208_REG_SCA 0x0c
49#define ISL1208_REG_MNA 0x0d
50#define ISL1208_REG_HRA 0x0e
51#define ISL1208_REG_DTA 0x0f
52#define ISL1208_REG_MOA 0x10
53#define ISL1208_REG_DWA 0x11
54#define ISL1208_ALARM_SECTION_LEN 6
55
56/* user section */
57#define ISL1208_REG_USR1 0x12
58#define ISL1208_REG_USR2 0x13
59#define ISL1208_USR_SECTION_LEN 2
60
61/* i2c configuration */
62#define ISL1208_I2C_ADDR 0xde
63
64static unsigned short normal_i2c[] = {
65 ISL1208_I2C_ADDR>>1, I2C_CLIENT_END
66};
67I2C_CLIENT_INSMOD; /* defines addr_data */
68
69static int isl1208_attach_adapter(struct i2c_adapter *adapter);
70static int isl1208_detach_client(struct i2c_client *client);
71
72static struct i2c_driver isl1208_driver = {
73 .driver = {
74 .name = DRV_NAME,
75 },
76 .id = I2C_DRIVERID_ISL1208,
77 .attach_adapter = &isl1208_attach_adapter,
78 .detach_client = &isl1208_detach_client,
79};
80
81/* block read */
82static int
83isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
84 unsigned len)
85{
86 u8 reg_addr[1] = { reg };
87 struct i2c_msg msgs[2] = {
88 { client->addr, client->flags, sizeof(reg_addr), reg_addr },
89 { client->addr, client->flags | I2C_M_RD, len, buf }
90 };
91 int ret;
92
93 BUG_ON(len == 0);
94 BUG_ON(reg > ISL1208_REG_USR2);
95 BUG_ON(reg + len > ISL1208_REG_USR2 + 1);
96
97 ret = i2c_transfer(client->adapter, msgs, 2);
98 if (ret > 0)
99 ret = 0;
100 return ret;
101}
102
103/* block write */
104static int
105isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
106 unsigned len)
107{
108 u8 i2c_buf[ISL1208_REG_USR2 + 2];
109 struct i2c_msg msgs[1] = {
110 { client->addr, client->flags, len + 1, i2c_buf }
111 };
112 int ret;
113
114 BUG_ON(len == 0);
115 BUG_ON(reg > ISL1208_REG_USR2);
116 BUG_ON(reg + len > ISL1208_REG_USR2 + 1);
117
118 i2c_buf[0] = reg;
119 memcpy(&i2c_buf[1], &buf[0], len);
120
121 ret = i2c_transfer(client->adapter, msgs, 1);
122 if (ret > 0)
123 ret = 0;
124 return ret;
125}
126
127/* simple check to see wether we have a isl1208 */
128static int isl1208_i2c_validate_client(struct i2c_client *client)
129{
130 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
131 u8 zero_mask[ISL1208_RTC_SECTION_LEN] = {
132 0x80, 0x80, 0x40, 0xc0, 0xe0, 0x00, 0xf8
133 };
134 int i;
135 int ret;
136
137 ret = isl1208_i2c_read_regs(client, 0, regs, ISL1208_RTC_SECTION_LEN);
138 if (ret < 0)
139 return ret;
140
141 for (i = 0; i < ISL1208_RTC_SECTION_LEN; ++i) {
142 if (regs[i] & zero_mask[i]) /* check if bits are cleared */
143 return -ENODEV;
144 }
145
146 return 0;
147}
148
149static int isl1208_i2c_get_sr(struct i2c_client *client)
150{
151 return i2c_smbus_read_byte_data(client, ISL1208_REG_SR) == -1 ? -EIO:0;
152}
153
154static int isl1208_i2c_get_atr(struct i2c_client *client)
155{
156 int atr = i2c_smbus_read_byte_data(client, ISL1208_REG_ATR);
157
158 if (atr < 0)
159 return -EIO;
160
161 /* The 6bit value in the ATR register controls the load
162 * capacitance C_load * in steps of 0.25pF
163 *
164 * bit (1<<5) of the ATR register is inverted
165 *
166 * C_load(ATR=0x20) = 4.50pF
167 * C_load(ATR=0x00) = 12.50pF
168 * C_load(ATR=0x1f) = 20.25pF
169 *
170 */
171
172 atr &= 0x3f; /* mask out lsb */
173 atr ^= 1<<5; /* invert 6th bit */
174 atr += 2*9; /* add offset of 4.5pF; unit[atr] = 0.25pF */
175
176 return atr;
177}
178
179static int isl1208_i2c_get_dtr(struct i2c_client *client)
180{
181 int dtr = i2c_smbus_read_byte_data(client, ISL1208_REG_DTR);
182
183 if (dtr < 0)
184 return -EIO;
185
186 /* dtr encodes adjustments of {-60,-40,-20,0,20,40,60} ppm */
187 dtr = ((dtr & 0x3) * 20) * (dtr & (1<<2) ? -1 : 1);
188
189 return dtr;
190}
191
192static int isl1208_i2c_get_usr(struct i2c_client *client)
193{
194 u8 buf[ISL1208_USR_SECTION_LEN] = { 0, };
195 int ret;
196
197 ret = isl1208_i2c_read_regs (client, ISL1208_REG_USR1, buf,
198 ISL1208_USR_SECTION_LEN);
199 if (ret < 0)
200 return ret;
201
202 return (buf[1] << 8) | buf[0];
203}
204
205static int isl1208_i2c_set_usr(struct i2c_client *client, u16 usr)
206{
207 u8 buf[ISL1208_USR_SECTION_LEN];
208
209 buf[0] = usr & 0xff;
210 buf[1] = (usr >> 8) & 0xff;
211
212 return isl1208_i2c_set_regs (client, ISL1208_REG_USR1, buf,
213 ISL1208_USR_SECTION_LEN);
214}
215
216static int isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
217{
218 struct i2c_client *const client = to_i2c_client(dev);
219 int sr, dtr, atr, usr;
220
221 sr = isl1208_i2c_get_sr(client);
222 if (sr < 0) {
223 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
224 return sr;
225 }
226
227 seq_printf(seq, "status_reg\t:%s%s%s%s%s%s (0x%.2x)\n",
228 (sr & ISL1208_REG_SR_RTCF) ? " RTCF" : "",
229 (sr & ISL1208_REG_SR_BAT) ? " BAT" : "",
230 (sr & ISL1208_REG_SR_ALM) ? " ALM" : "",
231 (sr & ISL1208_REG_SR_WRTC) ? " WRTC" : "",
232 (sr & ISL1208_REG_SR_XTOSCB) ? " XTOSCB" : "",
233 (sr & ISL1208_REG_SR_ARST) ? " ARST" : "",
234 sr);
235
236 seq_printf(seq, "batt_status\t: %s\n",
237 (sr & ISL1208_REG_SR_RTCF) ? "bad" : "okay");
238
239 dtr = isl1208_i2c_get_dtr(client);
240 if (dtr >= 0 -1)
241 seq_printf(seq, "digital_trim\t: %d ppm\n", dtr);
242
243 atr = isl1208_i2c_get_atr(client);
244 if (atr >= 0)
245 seq_printf(seq, "analog_trim\t: %d.%.2d pF\n",
246 atr>>2, (atr&0x3)*25);
247
248 usr = isl1208_i2c_get_usr(client);
249 if (usr >= 0)
250 seq_printf(seq, "user_data\t: 0x%.4x\n", usr);
251
252 return 0;
253}
254
255
256static int isl1208_i2c_read_time(struct i2c_client *client,
257 struct rtc_time *tm)
258{
259 int sr;
260 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
261
262 sr = isl1208_i2c_get_sr(client);
263 if (sr < 0) {
264 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
265 return -EIO;
266 }
267
268 sr = isl1208_i2c_read_regs(client, 0, regs, ISL1208_RTC_SECTION_LEN);
269 if (sr < 0) {
270 dev_err(&client->dev, "%s: reading RTC section failed\n",
271 __func__);
272 return sr;
273 }
274
275 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SC]);
276 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MN]);
277 { /* HR field has a more complex interpretation */
278 const u8 _hr = regs[ISL1208_REG_HR];
279 if (_hr & ISL1208_REG_HR_MIL) /* 24h format */
280 tm->tm_hour = BCD2BIN(_hr & 0x3f);
281 else { // 12h format
282 tm->tm_hour = BCD2BIN(_hr & 0x1f);
283 if (_hr & ISL1208_REG_HR_PM) /* PM flag set */
284 tm->tm_hour += 12;
285 }
286 }
287
288 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DT]);
289 tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */
290 tm->tm_year = BCD2BIN(regs[ISL1208_REG_YR]) + 100;
291 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DW]);
292
293 return 0;
294}
295
296static int isl1208_i2c_read_alarm(struct i2c_client *client,
297 struct rtc_wkalrm *alarm)
298{
299 struct rtc_time *const tm = &alarm->time;
300 u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, };
301 int sr;
302
303 sr = isl1208_i2c_get_sr(client);
304 if (sr < 0) {
305 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
306 return sr;
307 }
308
309 sr = isl1208_i2c_read_regs(client, ISL1208_REG_SCA, regs,
310 ISL1208_ALARM_SECTION_LEN);
311 if (sr < 0) {
312 dev_err(&client->dev, "%s: reading alarm section failed\n",
313 __func__);
314 return sr;
315 }
316
317 /* MSB of each alarm register is an enable bit */
318 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA-ISL1208_REG_SCA] & 0x7f);
319 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA-ISL1208_REG_SCA] & 0x7f);
320 tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA-ISL1208_REG_SCA] & 0x3f);
321 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA-ISL1208_REG_SCA] & 0x3f);
322 tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MOA-ISL1208_REG_SCA] & 0x1f)-1;
323 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA-ISL1208_REG_SCA] & 0x03);
324
325 return 0;
326}
327
328static int isl1208_rtc_read_time(struct device *dev, struct rtc_time *tm)
329{
330 return isl1208_i2c_read_time(to_i2c_client(dev), tm);
331}
332
333static int isl1208_i2c_set_time(struct i2c_client *client,
334 struct rtc_time const *tm)
335{
336 int sr;
337 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
338
339 regs[ISL1208_REG_SC] = BIN2BCD(tm->tm_sec);
340 regs[ISL1208_REG_MN] = BIN2BCD(tm->tm_min);
341 regs[ISL1208_REG_HR] = BIN2BCD(tm->tm_hour) | ISL1208_REG_HR_MIL;
342
343 regs[ISL1208_REG_DT] = BIN2BCD(tm->tm_mday);
344 regs[ISL1208_REG_MO] = BIN2BCD(tm->tm_mon + 1);
345 regs[ISL1208_REG_YR] = BIN2BCD(tm->tm_year - 100);
346
347 regs[ISL1208_REG_DW] = BIN2BCD(tm->tm_wday & 7);
348
349 sr = isl1208_i2c_get_sr(client);
350 if (sr < 0) {
351 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
352 return sr;
353 }
354
355 /* set WRTC */
356 sr = i2c_smbus_write_byte_data (client, ISL1208_REG_SR,
357 sr | ISL1208_REG_SR_WRTC);
358 if (sr < 0) {
359 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
360 return sr;
361 }
362
363 /* write RTC registers */
364 sr = isl1208_i2c_set_regs(client, 0, regs, ISL1208_RTC_SECTION_LEN);
365 if (sr < 0) {
366 dev_err(&client->dev, "%s: writing RTC section failed\n",
367 __func__);
368 return sr;
369 }
370
371 /* clear WRTC again */
372 sr = i2c_smbus_write_byte_data (client, ISL1208_REG_SR,
373 sr & ~ISL1208_REG_SR_WRTC);
374 if (sr < 0) {
375 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
376 return sr;
377 }
378
379 return 0;
380}
381
382
383static int isl1208_rtc_set_time(struct device *dev, struct rtc_time *tm)
384{
385 return isl1208_i2c_set_time(to_i2c_client(dev), tm);
386}
387
388static int isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
389{
390 return isl1208_i2c_read_alarm(to_i2c_client(dev), alarm);
391}
392
393static struct rtc_class_ops isl1208_rtc_ops = {
394 .proc = isl1208_rtc_proc,
395 .read_time = isl1208_rtc_read_time,
396 .set_time = isl1208_rtc_set_time,
397 .read_alarm = isl1208_rtc_read_alarm,
398 //.set_alarm = isl1208_rtc_set_alarm,
399};
400
401/* sysfs interface */
402
403static ssize_t isl1208_sysfs_show_atrim(struct device *dev,
404 struct device_attribute *attr,
405 char *buf)
406{
407 int atr;
408
409 atr = isl1208_i2c_get_atr(to_i2c_client(dev));
410 if (atr < 0)
411 return atr;
412
413 return sprintf(buf, "%d.%.2d pF\n", atr>>2, (atr&0x3)*25);
414}
415static DEVICE_ATTR(atrim, S_IRUGO, isl1208_sysfs_show_atrim, NULL);
416
417static ssize_t isl1208_sysfs_show_dtrim(struct device *dev,
418 struct device_attribute *attr,
419 char *buf)
420{
421 int dtr;
422
423 dtr = isl1208_i2c_get_dtr(to_i2c_client(dev));
424 if (dtr < 0)
425 return dtr;
426
427 return sprintf(buf, "%d ppm\n", dtr);
428}
429static DEVICE_ATTR(dtrim, S_IRUGO, isl1208_sysfs_show_dtrim, NULL);
430
431static ssize_t isl1208_sysfs_show_usr(struct device *dev,
432 struct device_attribute *attr,
433 char *buf)
434{
435 int usr;
436
437 usr = isl1208_i2c_get_usr(to_i2c_client(dev));
438 if (usr < 0)
439 return usr;
440
441 return sprintf(buf, "0x%.4x\n", usr);
442}
443
444static ssize_t isl1208_sysfs_store_usr(struct device *dev,
445 struct device_attribute *attr,
446 const char *buf, size_t count)
447{
448 int usr = -1;
449
450 if (buf[0] == '0' && (buf[1] == 'x' || buf[1] == 'X')) {
451 if (sscanf(buf, "%x", &usr) != 1)
452 return -EINVAL;
453 } else {
454 if (sscanf(buf, "%d", &usr) != 1)
455 return -EINVAL;
456 }
457
458 if (usr < 0 || usr > 0xffff)
459 return -EINVAL;
460
461 return isl1208_i2c_set_usr(to_i2c_client(dev), usr) ? -EIO : count;
462}
463static DEVICE_ATTR(usr, S_IRUGO | S_IWUSR, isl1208_sysfs_show_usr,
464 isl1208_sysfs_store_usr);
465
466static int
467isl1208_probe(struct i2c_adapter *adapter, int addr, int kind)
468{
469 int rc = 0;
470 struct i2c_client *new_client = NULL;
471 struct rtc_device *rtc = NULL;
472
473 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
474 rc = -ENODEV;
475 goto failout;
476 }
477
478 new_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
479 if (new_client == NULL) {
480 rc = -ENOMEM;
481 goto failout;
482 }
483
484 new_client->addr = addr;
485 new_client->adapter = adapter;
486 new_client->driver = &isl1208_driver;
487 new_client->flags = 0;
488 strcpy(new_client->name, DRV_NAME);
489
490 if (kind < 0) {
491 rc = isl1208_i2c_validate_client(new_client);
492 if (rc < 0)
493 goto failout;
494 }
495
496 rc = i2c_attach_client(new_client);
497 if (rc < 0)
498 goto failout;
499
500 dev_info(&new_client->dev,
501 "chip found, driver version " DRV_VERSION "\n");
502
503 rtc = rtc_device_register(isl1208_driver.driver.name,
504 &new_client->dev,
505 &isl1208_rtc_ops, THIS_MODULE);
506
507 if (IS_ERR(rtc)) {
508 rc = PTR_ERR(rtc);
509 goto failout_detach;
510 }
511
512 i2c_set_clientdata(new_client, rtc);
513
514 rc = isl1208_i2c_get_sr(new_client);
515 if (rc < 0) {
516 dev_err(&new_client->dev, "reading status failed\n");
517 goto failout_unregister;
518 }
519
520 if (rc & ISL1208_REG_SR_RTCF)
521 dev_warn(&new_client->dev, "rtc power failure detected, "
522 "please set clock.\n");
523
524 rc = device_create_file(&new_client->dev, &dev_attr_atrim);
525 if (rc < 0)
526 goto failout_unregister;
527 rc = device_create_file(&new_client->dev, &dev_attr_dtrim);
528 if (rc < 0)
529 goto failout_atrim;
530 rc = device_create_file(&new_client->dev, &dev_attr_usr);
531 if (rc < 0)
532 goto failout_dtrim;
533
534 return 0;
535
536 failout_dtrim:
537 device_remove_file(&new_client->dev, &dev_attr_dtrim);
538 failout_atrim:
539 device_remove_file(&new_client->dev, &dev_attr_atrim);
540 failout_unregister:
541 rtc_device_unregister(rtc);
542 failout_detach:
543 i2c_detach_client(new_client);
544 failout:
545 kfree(new_client);
546 return rc;
547}
548
549static int
550isl1208_attach_adapter (struct i2c_adapter *adapter)
551{
552 return i2c_probe(adapter, &addr_data, isl1208_probe);
553}
554
555static int
556isl1208_detach_client(struct i2c_client *client)
557{
558 int rc;
559 struct rtc_device *const rtc = i2c_get_clientdata(client);
560
561 if (rtc)
562 rtc_device_unregister(rtc); /* do we need to kfree? */
563
564 rc = i2c_detach_client(client);
565 if (rc)
566 return rc;
567
568 kfree(client);
569
570 return 0;
571}
572
573/* module management */
574
575static int __init isl1208_init(void)
576{
577 return i2c_add_driver(&isl1208_driver);
578}
579
580static void __exit isl1208_exit(void)
581{
582 i2c_del_driver(&isl1208_driver);
583}
584
585MODULE_AUTHOR("Herbert Valerio Riedel <hvr@gnu.org>");
586MODULE_DESCRIPTION("Intersil ISL1208 RTC driver");
587MODULE_LICENSE("GPL");
588MODULE_VERSION(DRV_VERSION);
589
590module_init(isl1208_init);
591module_exit(isl1208_exit);
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index d6d1bff52b8e..2c7de79c83b9 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -69,12 +69,12 @@ static void s3c_rtc_setaie(int to)
69 69
70 pr_debug("%s: aie=%d\n", __FUNCTION__, to); 70 pr_debug("%s: aie=%d\n", __FUNCTION__, to);
71 71
72 tmp = readb(S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; 72 tmp = readb(s3c_rtc_base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN;
73 73
74 if (to) 74 if (to)
75 tmp |= S3C2410_RTCALM_ALMEN; 75 tmp |= S3C2410_RTCALM_ALMEN;
76 76
77 writeb(tmp, S3C2410_RTCALM); 77 writeb(tmp, s3c_rtc_base + S3C2410_RTCALM);
78} 78}
79 79
80static void s3c_rtc_setpie(int to) 80static void s3c_rtc_setpie(int to)
@@ -84,12 +84,12 @@ static void s3c_rtc_setpie(int to)
84 pr_debug("%s: pie=%d\n", __FUNCTION__, to); 84 pr_debug("%s: pie=%d\n", __FUNCTION__, to);
85 85
86 spin_lock_irq(&s3c_rtc_pie_lock); 86 spin_lock_irq(&s3c_rtc_pie_lock);
87 tmp = readb(S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE; 87 tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE;
88 88
89 if (to) 89 if (to)
90 tmp |= S3C2410_TICNT_ENABLE; 90 tmp |= S3C2410_TICNT_ENABLE;
91 91
92 writeb(tmp, S3C2410_TICNT); 92 writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
93 spin_unlock_irq(&s3c_rtc_pie_lock); 93 spin_unlock_irq(&s3c_rtc_pie_lock);
94} 94}
95 95
@@ -98,13 +98,13 @@ static void s3c_rtc_setfreq(int freq)
98 unsigned int tmp; 98 unsigned int tmp;
99 99
100 spin_lock_irq(&s3c_rtc_pie_lock); 100 spin_lock_irq(&s3c_rtc_pie_lock);
101 tmp = readb(S3C2410_TICNT) & S3C2410_TICNT_ENABLE; 101 tmp = readb(s3c_rtc_base + S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
102 102
103 s3c_rtc_freq = freq; 103 s3c_rtc_freq = freq;
104 104
105 tmp |= (128 / freq)-1; 105 tmp |= (128 / freq)-1;
106 106
107 writeb(tmp, S3C2410_TICNT); 107 writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
108 spin_unlock_irq(&s3c_rtc_pie_lock); 108 spin_unlock_irq(&s3c_rtc_pie_lock);
109} 109}
110 110
@@ -113,14 +113,15 @@ static void s3c_rtc_setfreq(int freq)
113static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) 113static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
114{ 114{
115 unsigned int have_retried = 0; 115 unsigned int have_retried = 0;
116 void __iomem *base = s3c_rtc_base;
116 117
117 retry_get_time: 118 retry_get_time:
118 rtc_tm->tm_min = readb(S3C2410_RTCMIN); 119 rtc_tm->tm_min = readb(base + S3C2410_RTCMIN);
119 rtc_tm->tm_hour = readb(S3C2410_RTCHOUR); 120 rtc_tm->tm_hour = readb(base + S3C2410_RTCHOUR);
120 rtc_tm->tm_mday = readb(S3C2410_RTCDATE); 121 rtc_tm->tm_mday = readb(base + S3C2410_RTCDATE);
121 rtc_tm->tm_mon = readb(S3C2410_RTCMON); 122 rtc_tm->tm_mon = readb(base + S3C2410_RTCMON);
122 rtc_tm->tm_year = readb(S3C2410_RTCYEAR); 123 rtc_tm->tm_year = readb(base + S3C2410_RTCYEAR);
123 rtc_tm->tm_sec = readb(S3C2410_RTCSEC); 124 rtc_tm->tm_sec = readb(base + S3C2410_RTCSEC);
124 125
125 /* the only way to work out wether the system was mid-update 126 /* the only way to work out wether the system was mid-update
126 * when we read it is to check the second counter, and if it 127 * when we read it is to check the second counter, and if it
@@ -151,17 +152,26 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
151 152
152static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm) 153static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
153{ 154{
154 /* the rtc gets round the y2k problem by just not supporting it */ 155 void __iomem *base = s3c_rtc_base;
156 int year = tm->tm_year - 100;
155 157
156 if (tm->tm_year < 100) 158 pr_debug("set time %02d.%02d.%02d %02d/%02d/%02d\n",
159 tm->tm_year, tm->tm_mon, tm->tm_mday,
160 tm->tm_hour, tm->tm_min, tm->tm_sec);
161
162 /* we get around y2k by simply not supporting it */
163
164 if (year < 0 || year >= 100) {
165 dev_err(dev, "rtc only supports 100 years\n");
157 return -EINVAL; 166 return -EINVAL;
167 }
158 168
159 writeb(BIN2BCD(tm->tm_sec), S3C2410_RTCSEC); 169 writeb(BIN2BCD(tm->tm_sec), base + S3C2410_RTCSEC);
160 writeb(BIN2BCD(tm->tm_min), S3C2410_RTCMIN); 170 writeb(BIN2BCD(tm->tm_min), base + S3C2410_RTCMIN);
161 writeb(BIN2BCD(tm->tm_hour), S3C2410_RTCHOUR); 171 writeb(BIN2BCD(tm->tm_hour), base + S3C2410_RTCHOUR);
162 writeb(BIN2BCD(tm->tm_mday), S3C2410_RTCDATE); 172 writeb(BIN2BCD(tm->tm_mday), base + S3C2410_RTCDATE);
163 writeb(BIN2BCD(tm->tm_mon + 1), S3C2410_RTCMON); 173 writeb(BIN2BCD(tm->tm_mon + 1), base + S3C2410_RTCMON);
164 writeb(BIN2BCD(tm->tm_year - 100), S3C2410_RTCYEAR); 174 writeb(BIN2BCD(year), base + S3C2410_RTCYEAR);
165 175
166 return 0; 176 return 0;
167} 177}
@@ -169,16 +179,17 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
169static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) 179static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
170{ 180{
171 struct rtc_time *alm_tm = &alrm->time; 181 struct rtc_time *alm_tm = &alrm->time;
182 void __iomem *base = s3c_rtc_base;
172 unsigned int alm_en; 183 unsigned int alm_en;
173 184
174 alm_tm->tm_sec = readb(S3C2410_ALMSEC); 185 alm_tm->tm_sec = readb(base + S3C2410_ALMSEC);
175 alm_tm->tm_min = readb(S3C2410_ALMMIN); 186 alm_tm->tm_min = readb(base + S3C2410_ALMMIN);
176 alm_tm->tm_hour = readb(S3C2410_ALMHOUR); 187 alm_tm->tm_hour = readb(base + S3C2410_ALMHOUR);
177 alm_tm->tm_mon = readb(S3C2410_ALMMON); 188 alm_tm->tm_mon = readb(base + S3C2410_ALMMON);
178 alm_tm->tm_mday = readb(S3C2410_ALMDATE); 189 alm_tm->tm_mday = readb(base + S3C2410_ALMDATE);
179 alm_tm->tm_year = readb(S3C2410_ALMYEAR); 190 alm_tm->tm_year = readb(base + S3C2410_ALMYEAR);
180 191
181 alm_en = readb(S3C2410_RTCALM); 192 alm_en = readb(base + S3C2410_RTCALM);
182 193
183 pr_debug("read alarm %02x %02x.%02x.%02x %02x/%02x/%02x\n", 194 pr_debug("read alarm %02x %02x.%02x.%02x %02x/%02x/%02x\n",
184 alm_en, 195 alm_en,
@@ -226,6 +237,7 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
226static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) 237static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
227{ 238{
228 struct rtc_time *tm = &alrm->time; 239 struct rtc_time *tm = &alrm->time;
240 void __iomem *base = s3c_rtc_base;
229 unsigned int alrm_en; 241 unsigned int alrm_en;
230 242
231 pr_debug("s3c_rtc_setalarm: %d, %02x/%02x/%02x %02x.%02x.%02x\n", 243 pr_debug("s3c_rtc_setalarm: %d, %02x/%02x/%02x %02x.%02x.%02x\n",
@@ -234,32 +246,32 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
234 tm->tm_hour & 0xff, tm->tm_min & 0xff, tm->tm_sec); 246 tm->tm_hour & 0xff, tm->tm_min & 0xff, tm->tm_sec);
235 247
236 248
237 alrm_en = readb(S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; 249 alrm_en = readb(base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;
238 writeb(0x00, S3C2410_RTCALM); 250 writeb(0x00, base + S3C2410_RTCALM);
239 251
240 if (tm->tm_sec < 60 && tm->tm_sec >= 0) { 252 if (tm->tm_sec < 60 && tm->tm_sec >= 0) {
241 alrm_en |= S3C2410_RTCALM_SECEN; 253 alrm_en |= S3C2410_RTCALM_SECEN;
242 writeb(BIN2BCD(tm->tm_sec), S3C2410_ALMSEC); 254 writeb(BIN2BCD(tm->tm_sec), base + S3C2410_ALMSEC);
243 } 255 }
244 256
245 if (tm->tm_min < 60 && tm->tm_min >= 0) { 257 if (tm->tm_min < 60 && tm->tm_min >= 0) {
246 alrm_en |= S3C2410_RTCALM_MINEN; 258 alrm_en |= S3C2410_RTCALM_MINEN;
247 writeb(BIN2BCD(tm->tm_min), S3C2410_ALMMIN); 259 writeb(BIN2BCD(tm->tm_min), base + S3C2410_ALMMIN);
248 } 260 }
249 261
250 if (tm->tm_hour < 24 && tm->tm_hour >= 0) { 262 if (tm->tm_hour < 24 && tm->tm_hour >= 0) {
251 alrm_en |= S3C2410_RTCALM_HOUREN; 263 alrm_en |= S3C2410_RTCALM_HOUREN;
252 writeb(BIN2BCD(tm->tm_hour), S3C2410_ALMHOUR); 264 writeb(BIN2BCD(tm->tm_hour), base + S3C2410_ALMHOUR);
253 } 265 }
254 266
255 pr_debug("setting S3C2410_RTCALM to %08x\n", alrm_en); 267 pr_debug("setting S3C2410_RTCALM to %08x\n", alrm_en);
256 268
257 writeb(alrm_en, S3C2410_RTCALM); 269 writeb(alrm_en, base + S3C2410_RTCALM);
258 270
259 if (0) { 271 if (0) {
260 alrm_en = readb(S3C2410_RTCALM); 272 alrm_en = readb(base + S3C2410_RTCALM);
261 alrm_en &= ~S3C2410_RTCALM_ALMEN; 273 alrm_en &= ~S3C2410_RTCALM_ALMEN;
262 writeb(alrm_en, S3C2410_RTCALM); 274 writeb(alrm_en, base + S3C2410_RTCALM);
263 disable_irq_wake(s3c_rtc_alarmno); 275 disable_irq_wake(s3c_rtc_alarmno);
264 } 276 }
265 277
@@ -319,8 +331,8 @@ static int s3c_rtc_ioctl(struct device *dev,
319 331
320static int s3c_rtc_proc(struct device *dev, struct seq_file *seq) 332static int s3c_rtc_proc(struct device *dev, struct seq_file *seq)
321{ 333{
322 unsigned int rtcalm = readb(S3C2410_RTCALM); 334 unsigned int rtcalm = readb(s3c_rtc_base + S3C2410_RTCALM);
323 unsigned int ticnt = readb (S3C2410_TICNT); 335 unsigned int ticnt = readb(s3c_rtc_base + S3C2410_TICNT);
324 336
325 seq_printf(seq, "alarm_IRQ\t: %s\n", 337 seq_printf(seq, "alarm_IRQ\t: %s\n",
326 (rtcalm & S3C2410_RTCALM_ALMEN) ? "yes" : "no" ); 338 (rtcalm & S3C2410_RTCALM_ALMEN) ? "yes" : "no" );
@@ -387,39 +399,40 @@ static struct rtc_class_ops s3c_rtcops = {
387 399
388static void s3c_rtc_enable(struct platform_device *pdev, int en) 400static void s3c_rtc_enable(struct platform_device *pdev, int en)
389{ 401{
402 void __iomem *base = s3c_rtc_base;
390 unsigned int tmp; 403 unsigned int tmp;
391 404
392 if (s3c_rtc_base == NULL) 405 if (s3c_rtc_base == NULL)
393 return; 406 return;
394 407
395 if (!en) { 408 if (!en) {
396 tmp = readb(S3C2410_RTCCON); 409 tmp = readb(base + S3C2410_RTCCON);
397 writeb(tmp & ~S3C2410_RTCCON_RTCEN, S3C2410_RTCCON); 410 writeb(tmp & ~S3C2410_RTCCON_RTCEN, base + S3C2410_RTCCON);
398 411
399 tmp = readb(S3C2410_TICNT); 412 tmp = readb(base + S3C2410_TICNT);
400 writeb(tmp & ~S3C2410_TICNT_ENABLE, S3C2410_TICNT); 413 writeb(tmp & ~S3C2410_TICNT_ENABLE, base + S3C2410_TICNT);
401 } else { 414 } else {
402 /* re-enable the device, and check it is ok */ 415 /* re-enable the device, and check it is ok */
403 416
404 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_RTCEN) == 0){ 417 if ((readb(base+S3C2410_RTCCON) & S3C2410_RTCCON_RTCEN) == 0){
405 dev_info(&pdev->dev, "rtc disabled, re-enabling\n"); 418 dev_info(&pdev->dev, "rtc disabled, re-enabling\n");
406 419
407 tmp = readb(S3C2410_RTCCON); 420 tmp = readb(base + S3C2410_RTCCON);
408 writeb(tmp | S3C2410_RTCCON_RTCEN , S3C2410_RTCCON); 421 writeb(tmp|S3C2410_RTCCON_RTCEN, base+S3C2410_RTCCON);
409 } 422 }
410 423
411 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_CNTSEL)){ 424 if ((readb(base + S3C2410_RTCCON) & S3C2410_RTCCON_CNTSEL)){
412 dev_info(&pdev->dev, "removing RTCCON_CNTSEL\n"); 425 dev_info(&pdev->dev, "removing RTCCON_CNTSEL\n");
413 426
414 tmp = readb(S3C2410_RTCCON); 427 tmp = readb(base + S3C2410_RTCCON);
415 writeb(tmp& ~S3C2410_RTCCON_CNTSEL , S3C2410_RTCCON); 428 writeb(tmp& ~S3C2410_RTCCON_CNTSEL, base+S3C2410_RTCCON);
416 } 429 }
417 430
418 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_CLKRST)){ 431 if ((readb(base + S3C2410_RTCCON) & S3C2410_RTCCON_CLKRST)){
419 dev_info(&pdev->dev, "removing RTCCON_CLKRST\n"); 432 dev_info(&pdev->dev, "removing RTCCON_CLKRST\n");
420 433
421 tmp = readb(S3C2410_RTCCON); 434 tmp = readb(base + S3C2410_RTCCON);
422 writeb(tmp & ~S3C2410_RTCCON_CLKRST, S3C2410_RTCCON); 435 writeb(tmp & ~S3C2410_RTCCON_CLKRST, base+S3C2410_RTCCON);
423 } 436 }
424 } 437 }
425} 438}
@@ -475,8 +488,8 @@ static int s3c_rtc_probe(struct platform_device *pdev)
475 } 488 }
476 489
477 s3c_rtc_mem = request_mem_region(res->start, 490 s3c_rtc_mem = request_mem_region(res->start,
478 res->end-res->start+1, 491 res->end-res->start+1,
479 pdev->name); 492 pdev->name);
480 493
481 if (s3c_rtc_mem == NULL) { 494 if (s3c_rtc_mem == NULL) {
482 dev_err(&pdev->dev, "failed to reserve memory region\n"); 495 dev_err(&pdev->dev, "failed to reserve memory region\n");
@@ -495,7 +508,8 @@ static int s3c_rtc_probe(struct platform_device *pdev)
495 508
496 s3c_rtc_enable(pdev, 1); 509 s3c_rtc_enable(pdev, 1);
497 510
498 pr_debug("s3c2410_rtc: RTCCON=%02x\n", readb(S3C2410_RTCCON)); 511 pr_debug("s3c2410_rtc: RTCCON=%02x\n",
512 readb(s3c_rtc_base + S3C2410_RTCCON));
499 513
500 s3c_rtc_setfreq(s3c_rtc_freq); 514 s3c_rtc_setfreq(s3c_rtc_freq);
501 515
@@ -543,7 +557,7 @@ static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
543 557
544 /* save TICNT for anyone using periodic interrupts */ 558 /* save TICNT for anyone using periodic interrupts */
545 559
546 ticnt_save = readb(S3C2410_TICNT); 560 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
547 561
548 /* calculate time delta for suspend */ 562 /* calculate time delta for suspend */
549 563
@@ -567,7 +581,7 @@ static int s3c_rtc_resume(struct platform_device *pdev)
567 rtc_tm_to_time(&tm, &time.tv_sec); 581 rtc_tm_to_time(&tm, &time.tv_sec);
568 restore_time_delta(&s3c_rtc_delta, &time); 582 restore_time_delta(&s3c_rtc_delta, &time);
569 583
570 writeb(ticnt_save, S3C2410_TICNT); 584 writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
571 return 0; 585 return 0;
572} 586}
573#else 587#else
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index bb6d5ff24fd0..596764fd29f5 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -30,7 +30,7 @@
30#include <asm/div64.h> 30#include <asm/div64.h>
31#include <asm/io.h> 31#include <asm/io.h>
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33#include <asm/vr41xx/vr41xx.h> 33#include <asm/vr41xx/irq.h>
34 34
35MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>"); 35MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>");
36MODULE_DESCRIPTION("NEC VR4100 series RTC driver"); 36MODULE_DESCRIPTION("NEC VR4100 series RTC driver");
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 4bf03fb67f8d..25c1ef6dfd44 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -52,7 +52,7 @@ static void dasd_setup_queue(struct dasd_device * device);
52static void dasd_free_queue(struct dasd_device * device); 52static void dasd_free_queue(struct dasd_device * device);
53static void dasd_flush_request_queue(struct dasd_device *); 53static void dasd_flush_request_queue(struct dasd_device *);
54static void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *); 54static void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
55static void dasd_flush_ccw_queue(struct dasd_device *, int); 55static int dasd_flush_ccw_queue(struct dasd_device *, int);
56static void dasd_tasklet(struct dasd_device *); 56static void dasd_tasklet(struct dasd_device *);
57static void do_kick_device(void *data); 57static void do_kick_device(void *data);
58 58
@@ -60,6 +60,7 @@ static void do_kick_device(void *data);
60 * SECTION: Operations on the device structure. 60 * SECTION: Operations on the device structure.
61 */ 61 */
62static wait_queue_head_t dasd_init_waitq; 62static wait_queue_head_t dasd_init_waitq;
63static wait_queue_head_t dasd_flush_wq;
63 64
64/* 65/*
65 * Allocate memory for a new device structure. 66 * Allocate memory for a new device structure.
@@ -121,7 +122,7 @@ dasd_free_device(struct dasd_device *device)
121/* 122/*
122 * Make a new device known to the system. 123 * Make a new device known to the system.
123 */ 124 */
124static inline int 125static int
125dasd_state_new_to_known(struct dasd_device *device) 126dasd_state_new_to_known(struct dasd_device *device)
126{ 127{
127 int rc; 128 int rc;
@@ -145,7 +146,7 @@ dasd_state_new_to_known(struct dasd_device *device)
145/* 146/*
146 * Let the system forget about a device. 147 * Let the system forget about a device.
147 */ 148 */
148static inline void 149static int
149dasd_state_known_to_new(struct dasd_device * device) 150dasd_state_known_to_new(struct dasd_device * device)
150{ 151{
151 /* Disable extended error reporting for this device. */ 152 /* Disable extended error reporting for this device. */
@@ -163,12 +164,13 @@ dasd_state_known_to_new(struct dasd_device * device)
163 164
164 /* Give up reference we took in dasd_state_new_to_known. */ 165 /* Give up reference we took in dasd_state_new_to_known. */
165 dasd_put_device(device); 166 dasd_put_device(device);
167 return 0;
166} 168}
167 169
168/* 170/*
169 * Request the irq line for the device. 171 * Request the irq line for the device.
170 */ 172 */
171static inline int 173static int
172dasd_state_known_to_basic(struct dasd_device * device) 174dasd_state_known_to_basic(struct dasd_device * device)
173{ 175{
174 int rc; 176 int rc;
@@ -192,17 +194,23 @@ dasd_state_known_to_basic(struct dasd_device * device)
192/* 194/*
193 * Release the irq line for the device. Terminate any running i/o. 195 * Release the irq line for the device. Terminate any running i/o.
194 */ 196 */
195static inline void 197static int
196dasd_state_basic_to_known(struct dasd_device * device) 198dasd_state_basic_to_known(struct dasd_device * device)
197{ 199{
200 int rc;
201
198 dasd_gendisk_free(device); 202 dasd_gendisk_free(device);
199 dasd_flush_ccw_queue(device, 1); 203 rc = dasd_flush_ccw_queue(device, 1);
204 if (rc)
205 return rc;
206
200 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device); 207 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
201 if (device->debug_area != NULL) { 208 if (device->debug_area != NULL) {
202 debug_unregister(device->debug_area); 209 debug_unregister(device->debug_area);
203 device->debug_area = NULL; 210 device->debug_area = NULL;
204 } 211 }
205 device->state = DASD_STATE_KNOWN; 212 device->state = DASD_STATE_KNOWN;
213 return 0;
206} 214}
207 215
208/* 216/*
@@ -219,7 +227,7 @@ dasd_state_basic_to_known(struct dasd_device * device)
219 * In case the analysis returns an error, the device setup is stopped 227 * In case the analysis returns an error, the device setup is stopped
220 * (a fake disk was already added to allow formatting). 228 * (a fake disk was already added to allow formatting).
221 */ 229 */
222static inline int 230static int
223dasd_state_basic_to_ready(struct dasd_device * device) 231dasd_state_basic_to_ready(struct dasd_device * device)
224{ 232{
225 int rc; 233 int rc;
@@ -247,25 +255,31 @@ dasd_state_basic_to_ready(struct dasd_device * device)
247 * Forget format information. Check if the target level is basic 255 * Forget format information. Check if the target level is basic
248 * and if it is create fake disk for formatting. 256 * and if it is create fake disk for formatting.
249 */ 257 */
250static inline void 258static int
251dasd_state_ready_to_basic(struct dasd_device * device) 259dasd_state_ready_to_basic(struct dasd_device * device)
252{ 260{
253 dasd_flush_ccw_queue(device, 0); 261 int rc;
262
263 rc = dasd_flush_ccw_queue(device, 0);
264 if (rc)
265 return rc;
254 dasd_destroy_partitions(device); 266 dasd_destroy_partitions(device);
255 dasd_flush_request_queue(device); 267 dasd_flush_request_queue(device);
256 device->blocks = 0; 268 device->blocks = 0;
257 device->bp_block = 0; 269 device->bp_block = 0;
258 device->s2b_shift = 0; 270 device->s2b_shift = 0;
259 device->state = DASD_STATE_BASIC; 271 device->state = DASD_STATE_BASIC;
272 return 0;
260} 273}
261 274
262/* 275/*
263 * Back to basic. 276 * Back to basic.
264 */ 277 */
265static inline void 278static int
266dasd_state_unfmt_to_basic(struct dasd_device * device) 279dasd_state_unfmt_to_basic(struct dasd_device * device)
267{ 280{
268 device->state = DASD_STATE_BASIC; 281 device->state = DASD_STATE_BASIC;
282 return 0;
269} 283}
270 284
271/* 285/*
@@ -273,7 +287,7 @@ dasd_state_unfmt_to_basic(struct dasd_device * device)
273 * the requeueing of requests from the linux request queue to the 287 * the requeueing of requests from the linux request queue to the
274 * ccw queue. 288 * ccw queue.
275 */ 289 */
276static inline int 290static int
277dasd_state_ready_to_online(struct dasd_device * device) 291dasd_state_ready_to_online(struct dasd_device * device)
278{ 292{
279 device->state = DASD_STATE_ONLINE; 293 device->state = DASD_STATE_ONLINE;
@@ -284,16 +298,17 @@ dasd_state_ready_to_online(struct dasd_device * device)
284/* 298/*
285 * Stop the requeueing of requests again. 299 * Stop the requeueing of requests again.
286 */ 300 */
287static inline void 301static int
288dasd_state_online_to_ready(struct dasd_device * device) 302dasd_state_online_to_ready(struct dasd_device * device)
289{ 303{
290 device->state = DASD_STATE_READY; 304 device->state = DASD_STATE_READY;
305 return 0;
291} 306}
292 307
293/* 308/*
294 * Device startup state changes. 309 * Device startup state changes.
295 */ 310 */
296static inline int 311static int
297dasd_increase_state(struct dasd_device *device) 312dasd_increase_state(struct dasd_device *device)
298{ 313{
299 int rc; 314 int rc;
@@ -329,30 +344,37 @@ dasd_increase_state(struct dasd_device *device)
329/* 344/*
330 * Device shutdown state changes. 345 * Device shutdown state changes.
331 */ 346 */
332static inline int 347static int
333dasd_decrease_state(struct dasd_device *device) 348dasd_decrease_state(struct dasd_device *device)
334{ 349{
350 int rc;
351
352 rc = 0;
335 if (device->state == DASD_STATE_ONLINE && 353 if (device->state == DASD_STATE_ONLINE &&
336 device->target <= DASD_STATE_READY) 354 device->target <= DASD_STATE_READY)
337 dasd_state_online_to_ready(device); 355 rc = dasd_state_online_to_ready(device);
338 356
339 if (device->state == DASD_STATE_READY && 357 if (!rc &&
358 device->state == DASD_STATE_READY &&
340 device->target <= DASD_STATE_BASIC) 359 device->target <= DASD_STATE_BASIC)
341 dasd_state_ready_to_basic(device); 360 rc = dasd_state_ready_to_basic(device);
342 361
343 if (device->state == DASD_STATE_UNFMT && 362 if (!rc &&
363 device->state == DASD_STATE_UNFMT &&
344 device->target <= DASD_STATE_BASIC) 364 device->target <= DASD_STATE_BASIC)
345 dasd_state_unfmt_to_basic(device); 365 rc = dasd_state_unfmt_to_basic(device);
346 366
347 if (device->state == DASD_STATE_BASIC && 367 if (!rc &&
368 device->state == DASD_STATE_BASIC &&
348 device->target <= DASD_STATE_KNOWN) 369 device->target <= DASD_STATE_KNOWN)
349 dasd_state_basic_to_known(device); 370 rc = dasd_state_basic_to_known(device);
350 371
351 if (device->state == DASD_STATE_KNOWN && 372 if (!rc &&
373 device->state == DASD_STATE_KNOWN &&
352 device->target <= DASD_STATE_NEW) 374 device->target <= DASD_STATE_NEW)
353 dasd_state_known_to_new(device); 375 rc = dasd_state_known_to_new(device);
354 376
355 return 0; 377 return rc;
356} 378}
357 379
358/* 380/*
@@ -701,6 +723,7 @@ dasd_term_IO(struct dasd_ccw_req * cqr)
701 cqr->retries--; 723 cqr->retries--;
702 cqr->status = DASD_CQR_CLEAR; 724 cqr->status = DASD_CQR_CLEAR;
703 cqr->stopclk = get_clock(); 725 cqr->stopclk = get_clock();
726 cqr->starttime = 0;
704 DBF_DEV_EVENT(DBF_DEBUG, device, 727 DBF_DEV_EVENT(DBF_DEBUG, device,
705 "terminate cqr %p successful", 728 "terminate cqr %p successful",
706 cqr); 729 cqr);
@@ -978,6 +1001,7 @@ dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
978 irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) { 1001 irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
979 cqr->status = DASD_CQR_QUEUED; 1002 cqr->status = DASD_CQR_QUEUED;
980 dasd_clear_timer(device); 1003 dasd_clear_timer(device);
1004 wake_up(&dasd_flush_wq);
981 dasd_schedule_bh(device); 1005 dasd_schedule_bh(device);
982 return; 1006 return;
983 } 1007 }
@@ -1241,6 +1265,10 @@ __dasd_check_expire(struct dasd_device * device)
1241 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list); 1265 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1242 if (cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) { 1266 if (cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) {
1243 if (time_after_eq(jiffies, cqr->expires + cqr->starttime)) { 1267 if (time_after_eq(jiffies, cqr->expires + cqr->starttime)) {
1268 DEV_MESSAGE(KERN_ERR, device,
1269 "internal error - timeout (%is) expired "
1270 "for cqr %p (%i retries left)",
1271 (cqr->expires/HZ), cqr, cqr->retries);
1244 if (device->discipline->term_IO(cqr) != 0) 1272 if (device->discipline->term_IO(cqr) != 0)
1245 /* Hmpf, try again in 1/10 sec */ 1273 /* Hmpf, try again in 1/10 sec */
1246 dasd_set_timer(device, 10); 1274 dasd_set_timer(device, 10);
@@ -1285,46 +1313,100 @@ __dasd_start_head(struct dasd_device * device)
1285 dasd_set_timer(device, 50); 1313 dasd_set_timer(device, 50);
1286} 1314}
1287 1315
1316static inline int
1317_wait_for_clear(struct dasd_ccw_req *cqr)
1318{
1319 return (cqr->status == DASD_CQR_QUEUED);
1320}
1321
1288/* 1322/*
1289 * Remove requests from the ccw queue. 1323 * Remove all requests from the ccw queue (all = '1') or only block device
1324 * requests in case all = '0'.
1325 * Take care of the erp-chain (chained via cqr->refers) and remove either
1326 * the whole erp-chain or none of the erp-requests.
1327 * If a request is currently running, term_IO is called and the request
1328 * is re-queued. Prior to removing the terminated request we need to wait
1329 * for the clear-interrupt.
1330 * In case termination is not possible we stop processing and just finishing
1331 * the already moved requests.
1290 */ 1332 */
1291static void 1333static int
1292dasd_flush_ccw_queue(struct dasd_device * device, int all) 1334dasd_flush_ccw_queue(struct dasd_device * device, int all)
1293{ 1335{
1336 struct dasd_ccw_req *cqr, *orig, *n;
1337 int rc, i;
1338
1294 struct list_head flush_queue; 1339 struct list_head flush_queue;
1295 struct list_head *l, *n;
1296 struct dasd_ccw_req *cqr;
1297 1340
1298 INIT_LIST_HEAD(&flush_queue); 1341 INIT_LIST_HEAD(&flush_queue);
1299 spin_lock_irq(get_ccwdev_lock(device->cdev)); 1342 spin_lock_irq(get_ccwdev_lock(device->cdev));
1300 list_for_each_safe(l, n, &device->ccw_queue) { 1343 rc = 0;
1301 cqr = list_entry(l, struct dasd_ccw_req, list); 1344restart:
1345 list_for_each_entry_safe(cqr, n, &device->ccw_queue, list) {
1346 /* get original request of erp request-chain */
1347 for (orig = cqr; orig->refers != NULL; orig = orig->refers);
1348
1302 /* Flush all request or only block device requests? */ 1349 /* Flush all request or only block device requests? */
1303 if (all == 0 && cqr->callback == dasd_end_request_cb) 1350 if (all == 0 && cqr->callback != dasd_end_request_cb &&
1351 orig->callback != dasd_end_request_cb) {
1304 continue; 1352 continue;
1305 if (cqr->status == DASD_CQR_IN_IO) 1353 }
1306 device->discipline->term_IO(cqr); 1354 /* Check status and move request to flush_queue */
1307 if (cqr->status != DASD_CQR_DONE || 1355 switch (cqr->status) {
1308 cqr->status != DASD_CQR_FAILED) { 1356 case DASD_CQR_IN_IO:
1309 cqr->status = DASD_CQR_FAILED; 1357 rc = device->discipline->term_IO(cqr);
1358 if (rc) {
1359 /* unable to terminate requeust */
1360 DEV_MESSAGE(KERN_ERR, device,
1361 "dasd flush ccw_queue is unable "
1362 " to terminate request %p",
1363 cqr);
1364 /* stop flush processing */
1365 goto finished;
1366 }
1367 break;
1368 case DASD_CQR_QUEUED:
1369 case DASD_CQR_ERROR:
1370 /* set request to FAILED */
1310 cqr->stopclk = get_clock(); 1371 cqr->stopclk = get_clock();
1372 cqr->status = DASD_CQR_FAILED;
1373 break;
1374 default: /* do not touch the others */
1375 break;
1376 }
1377 /* Rechain request (including erp chain) */
1378 for (i = 0; cqr != NULL; cqr = cqr->refers, i++) {
1379 cqr->endclk = get_clock();
1380 list_move_tail(&cqr->list, &flush_queue);
1381 }
1382 if (i > 1)
1383 /* moved more than one request - need to restart */
1384 goto restart;
1385 }
1386
1387finished:
1388 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1389 /* Now call the callback function of flushed requests */
1390restart_cb:
1391 list_for_each_entry_safe(cqr, n, &flush_queue, list) {
1392 if (cqr->status == DASD_CQR_CLEAR) {
1393 /* wait for clear interrupt! */
1394 wait_event(dasd_flush_wq, _wait_for_clear(cqr));
1395 cqr->status = DASD_CQR_FAILED;
1311 } 1396 }
1312 /* Process finished ERP request. */ 1397 /* Process finished ERP request. */
1313 if (cqr->refers) { 1398 if (cqr->refers) {
1314 __dasd_process_erp(device, cqr); 1399 __dasd_process_erp(device, cqr);
1315 continue; 1400 /* restart list_for_xx loop since dasd_process_erp
1401 * might remove multiple elements */
1402 goto restart_cb;
1316 } 1403 }
1317 /* Rechain request on device request queue */ 1404 /* call the callback function */
1318 cqr->endclk = get_clock(); 1405 cqr->endclk = get_clock();
1319 list_move_tail(&cqr->list, &flush_queue);
1320 }
1321 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1322 /* Now call the callback function of flushed requests */
1323 list_for_each_safe(l, n, &flush_queue) {
1324 cqr = list_entry(l, struct dasd_ccw_req, list);
1325 if (cqr->callback != NULL) 1406 if (cqr->callback != NULL)
1326 (cqr->callback)(cqr, cqr->callback_data); 1407 (cqr->callback)(cqr, cqr->callback_data);
1327 } 1408 }
1409 return rc;
1328} 1410}
1329 1411
1330/* 1412/*
@@ -1510,10 +1592,8 @@ dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr)
1510 if (device->discipline->term_IO) { 1592 if (device->discipline->term_IO) {
1511 cqr->retries = -1; 1593 cqr->retries = -1;
1512 device->discipline->term_IO(cqr); 1594 device->discipline->term_IO(cqr);
1513 /*nished = 1595 /* wait (non-interruptible) for final status
1514 * wait (non-interruptible) for final status 1596 * because signal ist still pending */
1515 * because signal ist still pending
1516 */
1517 spin_unlock_irq(get_ccwdev_lock(device->cdev)); 1597 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1518 wait_event(wait_q, _wait_for_wakeup(cqr)); 1598 wait_event(wait_q, _wait_for_wakeup(cqr));
1519 spin_lock_irq(get_ccwdev_lock(device->cdev)); 1599 spin_lock_irq(get_ccwdev_lock(device->cdev));
@@ -1546,19 +1626,11 @@ static inline int
1546_dasd_term_running_cqr(struct dasd_device *device) 1626_dasd_term_running_cqr(struct dasd_device *device)
1547{ 1627{
1548 struct dasd_ccw_req *cqr; 1628 struct dasd_ccw_req *cqr;
1549 int rc;
1550 1629
1551 if (list_empty(&device->ccw_queue)) 1630 if (list_empty(&device->ccw_queue))
1552 return 0; 1631 return 0;
1553 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list); 1632 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1554 rc = device->discipline->term_IO(cqr); 1633 return device->discipline->term_IO(cqr);
1555 if (rc == 0) {
1556 /* termination successful */
1557 cqr->status = DASD_CQR_QUEUED;
1558 cqr->startclk = cqr->stopclk = 0;
1559 cqr->starttime = 0;
1560 }
1561 return rc;
1562} 1634}
1563 1635
1564int 1636int
@@ -1726,12 +1798,9 @@ dasd_flush_request_queue(struct dasd_device * device)
1726 return; 1798 return;
1727 1799
1728 spin_lock_irq(&device->request_queue_lock); 1800 spin_lock_irq(&device->request_queue_lock);
1729 while (!list_empty(&device->request_queue->queue_head)) { 1801 while ((req = elv_next_request(device->request_queue))) {
1730 req = elv_next_request(device->request_queue);
1731 if (req == NULL)
1732 break;
1733 dasd_end_request(req, 0);
1734 blkdev_dequeue_request(req); 1802 blkdev_dequeue_request(req);
1803 dasd_end_request(req, 0);
1735 } 1804 }
1736 spin_unlock_irq(&device->request_queue_lock); 1805 spin_unlock_irq(&device->request_queue_lock);
1737} 1806}
@@ -2091,6 +2160,7 @@ dasd_init(void)
2091 int rc; 2160 int rc;
2092 2161
2093 init_waitqueue_head(&dasd_init_waitq); 2162 init_waitqueue_head(&dasd_init_waitq);
2163 init_waitqueue_head(&dasd_flush_wq);
2094 2164
2095 /* register 'common' DASD debug area, used for all DBF_XXX calls */ 2165 /* register 'common' DASD debug area, used for all DBF_XXX calls */
2096 dasd_debug_area = debug_register("dasd", 1, 2, 8 * sizeof (long)); 2166 dasd_debug_area = debug_register("dasd", 1, 2, 8 * sizeof (long));
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
index d7295386821c..9af02c79ce8a 100644
--- a/drivers/s390/block/dasd_devmap.c
+++ b/drivers/s390/block/dasd_devmap.c
@@ -48,18 +48,20 @@ struct dasd_devmap {
48}; 48};
49 49
50/* 50/*
51 * dasd_servermap is used to store the server_id of all storage servers 51 * dasd_server_ssid_map contains a globally unique storage server subsystem ID.
52 * accessed by DASD device driver. 52 * dasd_server_ssid_list contains the list of all subsystem IDs accessed by
53 * the DASD device driver.
53 */ 54 */
54struct dasd_servermap { 55struct dasd_server_ssid_map {
55 struct list_head list; 56 struct list_head list;
56 struct server_id { 57 struct system_id {
57 char vendor[4]; 58 char vendor[4];
58 char serial[15]; 59 char serial[15];
60 __u16 ssid;
59 } sid; 61 } sid;
60}; 62};
61 63
62static struct list_head dasd_serverlist; 64static struct list_head dasd_server_ssid_list;
63 65
64/* 66/*
65 * Parameter parsing functions for dasd= parameter. The syntax is: 67 * Parameter parsing functions for dasd= parameter. The syntax is:
@@ -89,7 +91,7 @@ static char *dasd[256];
89module_param_array(dasd, charp, NULL, 0); 91module_param_array(dasd, charp, NULL, 0);
90 92
91/* 93/*
92 * Single spinlock to protect devmap structures and lists. 94 * Single spinlock to protect devmap and servermap structures and lists.
93 */ 95 */
94static DEFINE_SPINLOCK(dasd_devmap_lock); 96static DEFINE_SPINLOCK(dasd_devmap_lock);
95 97
@@ -264,8 +266,9 @@ dasd_parse_keyword( char *parsestring ) {
264 if (dasd_page_cache) 266 if (dasd_page_cache)
265 return residual_str; 267 return residual_str;
266 dasd_page_cache = 268 dasd_page_cache =
267 kmem_cache_create("dasd_page_cache", PAGE_SIZE, 0, 269 kmem_cache_create("dasd_page_cache", PAGE_SIZE,
268 SLAB_CACHE_DMA, NULL, NULL ); 270 PAGE_SIZE, SLAB_CACHE_DMA,
271 NULL, NULL );
269 if (!dasd_page_cache) 272 if (!dasd_page_cache)
270 MESSAGE(KERN_WARNING, "%s", "Failed to create slab, " 273 MESSAGE(KERN_WARNING, "%s", "Failed to create slab, "
271 "fixed buffer mode disabled."); 274 "fixed buffer mode disabled.");
@@ -394,7 +397,7 @@ dasd_add_busid(char *bus_id, int features)
394 if (!new) 397 if (!new)
395 return ERR_PTR(-ENOMEM); 398 return ERR_PTR(-ENOMEM);
396 spin_lock(&dasd_devmap_lock); 399 spin_lock(&dasd_devmap_lock);
397 devmap = 0; 400 devmap = NULL;
398 hash = dasd_hash_busid(bus_id); 401 hash = dasd_hash_busid(bus_id);
399 list_for_each_entry(tmp, &dasd_hashlists[hash], list) 402 list_for_each_entry(tmp, &dasd_hashlists[hash], list)
400 if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) { 403 if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
@@ -406,10 +409,10 @@ dasd_add_busid(char *bus_id, int features)
406 new->devindex = dasd_max_devindex++; 409 new->devindex = dasd_max_devindex++;
407 strncpy(new->bus_id, bus_id, BUS_ID_SIZE); 410 strncpy(new->bus_id, bus_id, BUS_ID_SIZE);
408 new->features = features; 411 new->features = features;
409 new->device = 0; 412 new->device = NULL;
410 list_add(&new->list, &dasd_hashlists[hash]); 413 list_add(&new->list, &dasd_hashlists[hash]);
411 devmap = new; 414 devmap = new;
412 new = 0; 415 new = NULL;
413 } 416 }
414 spin_unlock(&dasd_devmap_lock); 417 spin_unlock(&dasd_devmap_lock);
415 kfree(new); 418 kfree(new);
@@ -479,7 +482,7 @@ dasd_device_from_devindex(int devindex)
479 int i; 482 int i;
480 483
481 spin_lock(&dasd_devmap_lock); 484 spin_lock(&dasd_devmap_lock);
482 devmap = 0; 485 devmap = NULL;
483 for (i = 0; (i < 256) && !devmap; i++) 486 for (i = 0; (i < 256) && !devmap; i++)
484 list_for_each_entry(tmp, &dasd_hashlists[i], list) 487 list_for_each_entry(tmp, &dasd_hashlists[i], list)
485 if (tmp->devindex == devindex) { 488 if (tmp->devindex == devindex) {
@@ -859,39 +862,6 @@ static struct attribute_group dasd_attr_group = {
859}; 862};
860 863
861/* 864/*
862 * Check if the related storage server is already contained in the
863 * dasd_serverlist. If server is not contained, create new entry.
864 * Return 0 if server was already in serverlist,
865 * 1 if the server was added successfully
866 * <0 in case of error.
867 */
868static int
869dasd_add_server(struct dasd_uid *uid)
870{
871 struct dasd_servermap *new, *tmp;
872
873 /* check if server is already contained */
874 list_for_each_entry(tmp, &dasd_serverlist, list)
875 // normale cmp?
876 if (strncmp(tmp->sid.vendor, uid->vendor,
877 sizeof(tmp->sid.vendor)) == 0
878 && strncmp(tmp->sid.serial, uid->serial,
879 sizeof(tmp->sid.serial)) == 0)
880 return 0;
881
882 new = (struct dasd_servermap *)
883 kzalloc(sizeof(struct dasd_servermap), GFP_KERNEL);
884 if (!new)
885 return -ENOMEM;
886
887 strncpy(new->sid.vendor, uid->vendor, sizeof(new->sid.vendor));
888 strncpy(new->sid.serial, uid->serial, sizeof(new->sid.serial));
889 list_add(&new->list, &dasd_serverlist);
890 return 1;
891}
892
893
894/*
895 * Return copy of the device unique identifier. 865 * Return copy of the device unique identifier.
896 */ 866 */
897int 867int
@@ -910,6 +880,9 @@ dasd_get_uid(struct ccw_device *cdev, struct dasd_uid *uid)
910 880
911/* 881/*
912 * Register the given device unique identifier into devmap struct. 882 * Register the given device unique identifier into devmap struct.
883 * In addition check if the related storage server subsystem ID is already
884 * contained in the dasd_server_ssid_list. If subsystem ID is not contained,
885 * create new entry.
913 * Return 0 if server was already in serverlist, 886 * Return 0 if server was already in serverlist,
914 * 1 if the server was added successful 887 * 1 if the server was added successful
915 * <0 in case of error. 888 * <0 in case of error.
@@ -918,16 +891,39 @@ int
918dasd_set_uid(struct ccw_device *cdev, struct dasd_uid *uid) 891dasd_set_uid(struct ccw_device *cdev, struct dasd_uid *uid)
919{ 892{
920 struct dasd_devmap *devmap; 893 struct dasd_devmap *devmap;
921 int rc; 894 struct dasd_server_ssid_map *srv, *tmp;
922 895
923 devmap = dasd_find_busid(cdev->dev.bus_id); 896 devmap = dasd_find_busid(cdev->dev.bus_id);
924 if (IS_ERR(devmap)) 897 if (IS_ERR(devmap))
925 return PTR_ERR(devmap); 898 return PTR_ERR(devmap);
899
900 /* generate entry for server_ssid_map */
901 srv = (struct dasd_server_ssid_map *)
902 kzalloc(sizeof(struct dasd_server_ssid_map), GFP_KERNEL);
903 if (!srv)
904 return -ENOMEM;
905 strncpy(srv->sid.vendor, uid->vendor, sizeof(srv->sid.vendor) - 1);
906 strncpy(srv->sid.serial, uid->serial, sizeof(srv->sid.serial) - 1);
907 srv->sid.ssid = uid->ssid;
908
909 /* server is already contained ? */
926 spin_lock(&dasd_devmap_lock); 910 spin_lock(&dasd_devmap_lock);
927 devmap->uid = *uid; 911 devmap->uid = *uid;
928 rc = dasd_add_server(uid); 912 list_for_each_entry(tmp, &dasd_server_ssid_list, list) {
913 if (!memcmp(&srv->sid, &tmp->sid,
914 sizeof(struct system_id))) {
915 kfree(srv);
916 srv = NULL;
917 break;
918 }
919 }
920
921 /* add servermap to serverlist */
922 if (srv)
923 list_add(&srv->list, &dasd_server_ssid_list);
929 spin_unlock(&dasd_devmap_lock); 924 spin_unlock(&dasd_devmap_lock);
930 return rc; 925
926 return (srv ? 1 : 0);
931} 927}
932EXPORT_SYMBOL_GPL(dasd_set_uid); 928EXPORT_SYMBOL_GPL(dasd_set_uid);
933 929
@@ -995,7 +991,7 @@ dasd_devmap_init(void)
995 INIT_LIST_HEAD(&dasd_hashlists[i]); 991 INIT_LIST_HEAD(&dasd_hashlists[i]);
996 992
997 /* Initialize servermap structure. */ 993 /* Initialize servermap structure. */
998 INIT_LIST_HEAD(&dasd_serverlist); 994 INIT_LIST_HEAD(&dasd_server_ssid_list);
999 return 0; 995 return 0;
1000} 996}
1001 997
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index 2e655f466743..b7a7fac3f7c3 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -65,16 +65,16 @@ struct dasd_eckd_private {
65/* The ccw bus type uses this table to find devices that it sends to 65/* The ccw bus type uses this table to find devices that it sends to
66 * dasd_eckd_probe */ 66 * dasd_eckd_probe */
67static struct ccw_device_id dasd_eckd_ids[] = { 67static struct ccw_device_id dasd_eckd_ids[] = {
68 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), driver_info: 0x1}, 68 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
69 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), driver_info: 0x2}, 69 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
70 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), driver_info: 0x3}, 70 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info = 0x3},
71 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), driver_info: 0x4}, 71 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
72 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), driver_info: 0x5}, 72 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
73 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), driver_info: 0x6}, 73 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
74 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), driver_info: 0x7}, 74 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
75 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), driver_info: 0x8}, 75 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
76 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), driver_info: 0x9}, 76 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
77 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), driver_info: 0xa}, 77 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
78 { /* end of list */ }, 78 { /* end of list */ },
79}; 79};
80 80
@@ -468,11 +468,11 @@ dasd_eckd_generate_uid(struct dasd_device *device, struct dasd_uid *uid)
468 return -ENODEV; 468 return -ENODEV;
469 469
470 memset(uid, 0, sizeof(struct dasd_uid)); 470 memset(uid, 0, sizeof(struct dasd_uid));
471 strncpy(uid->vendor, confdata->ned1.HDA_manufacturer, 471 memcpy(uid->vendor, confdata->ned1.HDA_manufacturer,
472 sizeof(uid->vendor) - 1); 472 sizeof(uid->vendor) - 1);
473 EBCASC(uid->vendor, sizeof(uid->vendor) - 1); 473 EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
474 strncpy(uid->serial, confdata->ned1.HDA_location, 474 memcpy(uid->serial, confdata->ned1.HDA_location,
475 sizeof(uid->serial) - 1); 475 sizeof(uid->serial) - 1);
476 EBCASC(uid->serial, sizeof(uid->serial) - 1); 476 EBCASC(uid->serial, sizeof(uid->serial) - 1);
477 uid->ssid = confdata->neq.subsystemID; 477 uid->ssid = confdata->neq.subsystemID;
478 if (confdata->ned2.sneq.flags == 0x40) { 478 if (confdata->ned2.sneq.flags == 0x40) {
@@ -607,7 +607,7 @@ dasd_eckd_psf_ssc(struct dasd_device *device)
607 * Valide storage server of current device. 607 * Valide storage server of current device.
608 */ 608 */
609static int 609static int
610dasd_eckd_validate_server(struct dasd_device *device) 610dasd_eckd_validate_server(struct dasd_device *device, struct dasd_uid *uid)
611{ 611{
612 int rc; 612 int rc;
613 613
@@ -616,11 +616,11 @@ dasd_eckd_validate_server(struct dasd_device *device)
616 return 0; 616 return 0;
617 617
618 rc = dasd_eckd_psf_ssc(device); 618 rc = dasd_eckd_psf_ssc(device);
619 if (rc) 619 /* may be requested feature is not available on server,
620 /* may be requested feature is not available on server, 620 * therefore just report error and go ahead */
621 * therefore just report error and go ahead */ 621 DEV_MESSAGE(KERN_INFO, device,
622 DEV_MESSAGE(KERN_INFO, device, 622 "PSF-SSC on storage subsystem %s.%s.%04x returned rc=%d",
623 "Perform Subsystem Function returned rc=%d", rc); 623 uid->vendor, uid->serial, uid->ssid, rc);
624 /* RE-Read Configuration Data */ 624 /* RE-Read Configuration Data */
625 return dasd_eckd_read_conf(device); 625 return dasd_eckd_read_conf(device);
626} 626}
@@ -666,7 +666,7 @@ dasd_eckd_check_characteristics(struct dasd_device *device)
666 return rc; 666 return rc;
667 rc = dasd_set_uid(device->cdev, &uid); 667 rc = dasd_set_uid(device->cdev, &uid);
668 if (rc == 1) /* new server found */ 668 if (rc == 1) /* new server found */
669 rc = dasd_eckd_validate_server(device); 669 rc = dasd_eckd_validate_server(device, &uid);
670 if (rc) 670 if (rc)
671 return rc; 671 return rc;
672 672
diff --git a/drivers/s390/block/dasd_fba.c b/drivers/s390/block/dasd_fba.c
index 808434d38526..e85015be109b 100644
--- a/drivers/s390/block/dasd_fba.c
+++ b/drivers/s390/block/dasd_fba.c
@@ -44,8 +44,8 @@ struct dasd_fba_private {
44}; 44};
45 45
46static struct ccw_device_id dasd_fba_ids[] = { 46static struct ccw_device_id dasd_fba_ids[] = {
47 { CCW_DEVICE_DEVTYPE (0x6310, 0, 0x9336, 0), driver_info: 0x1}, 47 { CCW_DEVICE_DEVTYPE (0x6310, 0, 0x9336, 0), .driver_info = 0x1},
48 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3370, 0), driver_info: 0x2}, 48 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3370, 0), .driver_info = 0x2},
49 { /* end of list */ }, 49 { /* end of list */ },
50}; 50};
51 51
diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c
index 12c7d296eaa8..d163632101d2 100644
--- a/drivers/s390/block/dasd_genhd.c
+++ b/drivers/s390/block/dasd_genhd.c
@@ -83,10 +83,12 @@ dasd_gendisk_alloc(struct dasd_device *device)
83void 83void
84dasd_gendisk_free(struct dasd_device *device) 84dasd_gendisk_free(struct dasd_device *device)
85{ 85{
86 del_gendisk(device->gdp); 86 if (device->gdp) {
87 device->gdp->queue = 0; 87 del_gendisk(device->gdp);
88 put_disk(device->gdp); 88 device->gdp->queue = NULL;
89 device->gdp = 0; 89 put_disk(device->gdp);
90 device->gdp = NULL;
91 }
90} 92}
91 93
92/* 94/*
@@ -136,7 +138,7 @@ dasd_destroy_partitions(struct dasd_device * device)
136 * device->bdev to lower the offline open_count limit again. 138 * device->bdev to lower the offline open_count limit again.
137 */ 139 */
138 bdev = device->bdev; 140 bdev = device->bdev;
139 device->bdev = 0; 141 device->bdev = NULL;
140 142
141 /* 143 /*
142 * See fs/partition/check.c:delete_partition 144 * See fs/partition/check.c:delete_partition
@@ -145,7 +147,7 @@ dasd_destroy_partitions(struct dasd_device * device)
145 */ 147 */
146 memset(&bpart, 0, sizeof(struct blkpg_partition)); 148 memset(&bpart, 0, sizeof(struct blkpg_partition));
147 memset(&barg, 0, sizeof(struct blkpg_ioctl_arg)); 149 memset(&barg, 0, sizeof(struct blkpg_ioctl_arg));
148 barg.data = &bpart; 150 barg.data = (void __user *) &bpart;
149 barg.op = BLKPG_DEL_PARTITION; 151 barg.op = BLKPG_DEL_PARTITION;
150 for (bpart.pno = device->gdp->minors - 1; bpart.pno > 0; bpart.pno--) 152 for (bpart.pno = device->gdp->minors - 1; bpart.pno > 0; bpart.pno--)
151 ioctl_by_bdev(bdev, BLKPG, (unsigned long) &barg); 153 ioctl_by_bdev(bdev, BLKPG, (unsigned long) &barg);
diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c
index e97f5316ad2d..8fed3603e9ea 100644
--- a/drivers/s390/block/dasd_ioctl.c
+++ b/drivers/s390/block/dasd_ioctl.c
@@ -345,7 +345,7 @@ dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)
345 if (bdev != bdev->bd_contains) 345 if (bdev != bdev->bd_contains)
346 // ro setting is not allowed for partitions 346 // ro setting is not allowed for partitions
347 return -EINVAL; 347 return -EINVAL;
348 if (get_user(intval, (int *)argp)) 348 if (get_user(intval, (int __user *)argp))
349 return -EFAULT; 349 return -EFAULT;
350 350
351 set_disk_ro(bdev->bd_disk, intval); 351 set_disk_ro(bdev->bd_disk, intval);
diff --git a/drivers/s390/block/xpram.c b/drivers/s390/block/xpram.c
index 4c1e56b9b98d..ca7d51f7eccc 100644
--- a/drivers/s390/block/xpram.c
+++ b/drivers/s390/block/xpram.c
@@ -48,15 +48,6 @@
48#define PRINT_ERR(x...) printk(KERN_ERR XPRAM_NAME " error:" x) 48#define PRINT_ERR(x...) printk(KERN_ERR XPRAM_NAME " error:" x)
49 49
50 50
51static struct sysdev_class xpram_sysclass = {
52 set_kset_name("xpram"),
53};
54
55static struct sys_device xpram_sys_device = {
56 .id = 0,
57 .cls = &xpram_sysclass,
58};
59
60typedef struct { 51typedef struct {
61 unsigned int size; /* size of xpram segment in pages */ 52 unsigned int size; /* size of xpram segment in pages */
62 unsigned int offset; /* start page of xpram segment */ 53 unsigned int offset; /* start page of xpram segment */
@@ -71,11 +62,11 @@ static int xpram_devs;
71/* 62/*
72 * Parameter parsing functions. 63 * Parameter parsing functions.
73 */ 64 */
74static int devs = XPRAM_DEVS; 65static int __initdata devs = XPRAM_DEVS;
75static unsigned int sizes[XPRAM_MAX_DEVS]; 66static char __initdata *sizes[XPRAM_MAX_DEVS];
76 67
77module_param(devs, int, 0); 68module_param(devs, int, 0);
78module_param_array(sizes, int, NULL, 0); 69module_param_array(sizes, charp, NULL, 0);
79 70
80MODULE_PARM_DESC(devs, "number of devices (\"partitions\"), " \ 71MODULE_PARM_DESC(devs, "number of devices (\"partitions\"), " \
81 "the default is " __MODULE_STRING(XPRAM_DEVS) "\n"); 72 "the default is " __MODULE_STRING(XPRAM_DEVS) "\n");
@@ -86,59 +77,6 @@ MODULE_PARM_DESC(sizes, "list of device (partition) sizes " \
86 "claimed by explicit sizes\n"); 77 "claimed by explicit sizes\n");
87MODULE_LICENSE("GPL"); 78MODULE_LICENSE("GPL");
88 79
89#ifndef MODULE
90/*
91 * Parses the kernel parameters given in the kernel parameter line.
92 * The expected format is
93 * <number_of_partitions>[","<partition_size>]*
94 * where
95 * devices is a positive integer that initializes xpram_devs
96 * each size is a non-negative integer possibly followed by a
97 * magnitude (k,K,m,M,g,G), the list of sizes initialises
98 * xpram_sizes
99 *
100 * Arguments
101 * str: substring of kernel parameter line that contains xprams
102 * kernel parameters.
103 *
104 * Result 0 on success, -EINVAL else -- only for Version > 2.3
105 *
106 * Side effects
107 * the global variabls devs is set to the value of
108 * <number_of_partitions> and sizes[i] is set to the i-th
109 * partition size (if provided). A parsing error of a value
110 * results in this value being set to -EINVAL.
111 */
112static int __init xpram_setup (char *str)
113{
114 char *cp;
115 int i;
116
117 devs = simple_strtoul(str, &cp, 10);
118 if (cp <= str || devs > XPRAM_MAX_DEVS)
119 return 0;
120 for (i = 0; (i < devs) && (*cp++ == ','); i++) {
121 sizes[i] = simple_strtoul(cp, &cp, 10);
122 if (*cp == 'g' || *cp == 'G') {
123 sizes[i] <<= 20;
124 cp++;
125 } else if (*cp == 'm' || *cp == 'M') {
126 sizes[i] <<= 10;
127 cp++;
128 } else if (*cp == 'k' || *cp == 'K')
129 cp++;
130 while (isspace(*cp)) cp++;
131 }
132 if (*cp == ',' && i >= devs)
133 PRINT_WARN("partition sizes list has too many entries.\n");
134 else if (*cp != 0)
135 PRINT_WARN("ignored '%s' at end of parameter string.\n", cp);
136 return 1;
137}
138
139__setup("xpram_parts=", xpram_setup);
140#endif
141
142/* 80/*
143 * Copy expanded memory page (4kB) into main memory 81 * Copy expanded memory page (4kB) into main memory
144 * Arguments 82 * Arguments
@@ -357,6 +295,7 @@ static int __init xpram_setup_sizes(unsigned long pages)
357{ 295{
358 unsigned long mem_needed; 296 unsigned long mem_needed;
359 unsigned long mem_auto; 297 unsigned long mem_auto;
298 unsigned long long size;
360 int mem_auto_no; 299 int mem_auto_no;
361 int i; 300 int i;
362 301
@@ -374,7 +313,19 @@ static int __init xpram_setup_sizes(unsigned long pages)
374 mem_needed = 0; 313 mem_needed = 0;
375 mem_auto_no = 0; 314 mem_auto_no = 0;
376 for (i = 0; i < xpram_devs; i++) { 315 for (i = 0; i < xpram_devs; i++) {
377 xpram_sizes[i] = (sizes[i] + 3) & -4UL; 316 if (sizes[i]) {
317 size = simple_strtoull(sizes[i], &sizes[i], 0);
318 switch (sizes[i][0]) {
319 case 'g':
320 case 'G':
321 size <<= 20;
322 break;
323 case 'm':
324 case 'M':
325 size <<= 10;
326 }
327 xpram_sizes[i] = (size + 3) & -4UL;
328 }
378 if (xpram_sizes[i]) 329 if (xpram_sizes[i])
379 mem_needed += xpram_sizes[i]; 330 mem_needed += xpram_sizes[i];
380 else 331 else
@@ -491,8 +442,6 @@ static void __exit xpram_exit(void)
491 } 442 }
492 unregister_blkdev(XPRAM_MAJOR, XPRAM_NAME); 443 unregister_blkdev(XPRAM_MAJOR, XPRAM_NAME);
493 blk_cleanup_queue(xpram_queue); 444 blk_cleanup_queue(xpram_queue);
494 sysdev_unregister(&xpram_sys_device);
495 sysdev_class_unregister(&xpram_sysclass);
496} 445}
497 446
498static int __init xpram_init(void) 447static int __init xpram_init(void)
@@ -510,19 +459,7 @@ static int __init xpram_init(void)
510 rc = xpram_setup_sizes(xpram_pages); 459 rc = xpram_setup_sizes(xpram_pages);
511 if (rc) 460 if (rc)
512 return rc; 461 return rc;
513 rc = sysdev_class_register(&xpram_sysclass); 462 return xpram_setup_blkdev();
514 if (rc)
515 return rc;
516
517 rc = sysdev_register(&xpram_sys_device);
518 if (rc) {
519 sysdev_class_unregister(&xpram_sysclass);
520 return rc;
521 }
522 rc = xpram_setup_blkdev();
523 if (rc)
524 sysdev_unregister(&xpram_sys_device);
525 return rc;
526} 463}
527 464
528module_init(xpram_init); 465module_init(xpram_init);
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index f25c6d116f6f..2fa566fa6da4 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -693,7 +693,7 @@ raw3215_probe (struct ccw_device *cdev)
693 GFP_KERNEL|GFP_DMA); 693 GFP_KERNEL|GFP_DMA);
694 if (raw->buffer == NULL) { 694 if (raw->buffer == NULL) {
695 spin_lock(&raw3215_device_lock); 695 spin_lock(&raw3215_device_lock);
696 raw3215[line] = 0; 696 raw3215[line] = NULL;
697 spin_unlock(&raw3215_device_lock); 697 spin_unlock(&raw3215_device_lock);
698 kfree(raw); 698 kfree(raw);
699 return -ENOMEM; 699 return -ENOMEM;
diff --git a/drivers/s390/char/ctrlchar.c b/drivers/s390/char/ctrlchar.c
index 0ea6f36a2527..d83eb6358bac 100644
--- a/drivers/s390/char/ctrlchar.c
+++ b/drivers/s390/char/ctrlchar.c
@@ -23,7 +23,7 @@ ctrlchar_handle_sysrq(void *tty)
23 handle_sysrq(ctrlchar_sysrq_key, NULL, (struct tty_struct *) tty); 23 handle_sysrq(ctrlchar_sysrq_key, NULL, (struct tty_struct *) tty);
24} 24}
25 25
26static DECLARE_WORK(ctrlchar_work, ctrlchar_handle_sysrq, 0); 26static DECLARE_WORK(ctrlchar_work, ctrlchar_handle_sysrq, NULL);
27#endif 27#endif
28 28
29 29
diff --git a/drivers/s390/char/defkeymap.c b/drivers/s390/char/defkeymap.c
index ca15adb140d1..17027d918cf7 100644
--- a/drivers/s390/char/defkeymap.c
+++ b/drivers/s390/char/defkeymap.c
@@ -83,8 +83,8 @@ static u_short shift_ctrl_map[NR_KEYS] = {
83}; 83};
84 84
85ushort *key_maps[MAX_NR_KEYMAPS] = { 85ushort *key_maps[MAX_NR_KEYMAPS] = {
86 plain_map, shift_map, 0, 0, 86 plain_map, shift_map, NULL, NULL,
87 ctrl_map, shift_ctrl_map, 0 87 ctrl_map, shift_ctrl_map, NULL,
88}; 88};
89 89
90unsigned int keymap_count = 4; 90unsigned int keymap_count = 4;
@@ -145,7 +145,7 @@ char *func_table[MAX_NR_FUNC] = {
145 func_buf + 97, 145 func_buf + 97,
146 func_buf + 103, 146 func_buf + 103,
147 func_buf + 109, 147 func_buf + 109,
148 0, 148 NULL,
149}; 149};
150 150
151struct kbdiacr accent_table[MAX_DIACR] = { 151struct kbdiacr accent_table[MAX_DIACR] = {
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index 6099c14de429..ef004d089712 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -236,7 +236,7 @@ fs3270_irq(struct fs3270 *fp, struct raw3270_request *rq, struct irb *irb)
236 * Process reads from fullscreen 3270. 236 * Process reads from fullscreen 3270.
237 */ 237 */
238static ssize_t 238static ssize_t
239fs3270_read(struct file *filp, char *data, size_t count, loff_t *off) 239fs3270_read(struct file *filp, char __user *data, size_t count, loff_t *off)
240{ 240{
241 struct fs3270 *fp; 241 struct fs3270 *fp;
242 struct raw3270_request *rq; 242 struct raw3270_request *rq;
@@ -281,7 +281,7 @@ fs3270_read(struct file *filp, char *data, size_t count, loff_t *off)
281 * Process writes to fullscreen 3270. 281 * Process writes to fullscreen 3270.
282 */ 282 */
283static ssize_t 283static ssize_t
284fs3270_write(struct file *filp, const char *data, size_t count, loff_t *off) 284fs3270_write(struct file *filp, const char __user *data, size_t count, loff_t *off)
285{ 285{
286 struct fs3270 *fp; 286 struct fs3270 *fp;
287 struct raw3270_request *rq; 287 struct raw3270_request *rq;
@@ -338,10 +338,10 @@ fs3270_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
338 fp->write_command = arg; 338 fp->write_command = arg;
339 break; 339 break;
340 case TUBGETI: 340 case TUBGETI:
341 rc = put_user(fp->read_command, (char *) arg); 341 rc = put_user(fp->read_command, (char __user *) arg);
342 break; 342 break;
343 case TUBGETO: 343 case TUBGETO:
344 rc = put_user(fp->write_command,(char *) arg); 344 rc = put_user(fp->write_command,(char __user *) arg);
345 break; 345 break;
346 case TUBGETMOD: 346 case TUBGETMOD:
347 iocb.model = fp->view.model; 347 iocb.model = fp->view.model;
@@ -350,7 +350,7 @@ fs3270_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
350 iocb.pf_cnt = 24; 350 iocb.pf_cnt = 24;
351 iocb.re_cnt = 20; 351 iocb.re_cnt = 20;
352 iocb.map = 0; 352 iocb.map = 0;
353 if (copy_to_user((char *) arg, &iocb, 353 if (copy_to_user((char __user *) arg, &iocb,
354 sizeof(struct raw3270_iocb))) 354 sizeof(struct raw3270_iocb)))
355 rc = -EFAULT; 355 rc = -EFAULT;
356 break; 356 break;
@@ -479,7 +479,7 @@ fs3270_close(struct inode *inode, struct file *filp)
479 struct fs3270 *fp; 479 struct fs3270 *fp;
480 480
481 fp = filp->private_data; 481 fp = filp->private_data;
482 filp->private_data = 0; 482 filp->private_data = NULL;
483 if (fp) { 483 if (fp) {
484 fp->fs_pid = 0; 484 fp->fs_pid = 0;
485 raw3270_reset(&fp->view); 485 raw3270_reset(&fp->view);
diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c
index 547ef906ae2c..3be06569180d 100644
--- a/drivers/s390/char/keyboard.c
+++ b/drivers/s390/char/keyboard.c
@@ -103,7 +103,7 @@ out_maps:
103out_kbd: 103out_kbd:
104 kfree(kbd); 104 kfree(kbd);
105out: 105out:
106 return 0; 106 return NULL;
107} 107}
108 108
109void 109void
@@ -304,7 +304,7 @@ kbd_keycode(struct kbd_data *kbd, unsigned int keycode)
304 if (kbd->sysrq) { 304 if (kbd->sysrq) {
305 if (kbd->sysrq == K(KT_LATIN, '-')) { 305 if (kbd->sysrq == K(KT_LATIN, '-')) {
306 kbd->sysrq = 0; 306 kbd->sysrq = 0;
307 handle_sysrq(value, 0, kbd->tty); 307 handle_sysrq(value, NULL, kbd->tty);
308 return; 308 return;
309 } 309 }
310 if (value == '-') { 310 if (value == '-') {
@@ -363,7 +363,7 @@ do_kdsk_ioctl(struct kbd_data *kbd, struct kbentry __user *user_kbe,
363 /* disallocate map */ 363 /* disallocate map */
364 key_map = kbd->key_maps[tmp.kb_table]; 364 key_map = kbd->key_maps[tmp.kb_table];
365 if (key_map) { 365 if (key_map) {
366 kbd->key_maps[tmp.kb_table] = 0; 366 kbd->key_maps[tmp.kb_table] = NULL;
367 kfree(key_map); 367 kfree(key_map);
368 } 368 }
369 break; 369 break;
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index e95b56f810db..7a84014f2037 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -555,7 +555,7 @@ raw3270_start_init(struct raw3270 *rp, struct raw3270_view *view,
555#ifdef CONFIG_TN3270_CONSOLE 555#ifdef CONFIG_TN3270_CONSOLE
556 if (raw3270_registered == 0) { 556 if (raw3270_registered == 0) {
557 spin_lock_irqsave(get_ccwdev_lock(view->dev->cdev), flags); 557 spin_lock_irqsave(get_ccwdev_lock(view->dev->cdev), flags);
558 rq->callback = 0; 558 rq->callback = NULL;
559 rc = __raw3270_start(rp, view, rq); 559 rc = __raw3270_start(rp, view, rq);
560 if (rc == 0) 560 if (rc == 0)
561 while (!raw3270_request_final(rq)) { 561 while (!raw3270_request_final(rq)) {
@@ -719,8 +719,8 @@ raw3270_size_device(struct raw3270 *rp)
719 rc = __raw3270_size_device_vm(rp); 719 rc = __raw3270_size_device_vm(rp);
720 else 720 else
721 rc = __raw3270_size_device(rp); 721 rc = __raw3270_size_device(rp);
722 raw3270_init_view.dev = 0; 722 raw3270_init_view.dev = NULL;
723 rp->view = 0; 723 rp->view = NULL;
724 up(&raw3270_init_sem); 724 up(&raw3270_init_sem);
725 if (rc == 0) { /* Found something. */ 725 if (rc == 0) { /* Found something. */
726 /* Try to find a model. */ 726 /* Try to find a model. */
@@ -761,8 +761,8 @@ raw3270_reset_device(struct raw3270 *rp)
761 rp->view = &raw3270_init_view; 761 rp->view = &raw3270_init_view;
762 raw3270_init_view.dev = rp; 762 raw3270_init_view.dev = rp;
763 rc = raw3270_start_init(rp, &raw3270_init_view, &rp->init_request); 763 rc = raw3270_start_init(rp, &raw3270_init_view, &rp->init_request);
764 raw3270_init_view.dev = 0; 764 raw3270_init_view.dev = NULL;
765 rp->view = 0; 765 rp->view = NULL;
766 up(&raw3270_init_sem); 766 up(&raw3270_init_sem);
767 return rc; 767 return rc;
768} 768}
@@ -934,7 +934,7 @@ raw3270_activate_view(struct raw3270_view *view)
934 else if (!test_bit(RAW3270_FLAGS_READY, &rp->flags)) 934 else if (!test_bit(RAW3270_FLAGS_READY, &rp->flags))
935 rc = -ENODEV; 935 rc = -ENODEV;
936 else { 936 else {
937 oldview = 0; 937 oldview = NULL;
938 if (rp->view) { 938 if (rp->view) {
939 oldview = rp->view; 939 oldview = rp->view;
940 oldview->fn->deactivate(oldview); 940 oldview->fn->deactivate(oldview);
@@ -951,7 +951,7 @@ raw3270_activate_view(struct raw3270_view *view)
951 rp->view = nv; 951 rp->view = nv;
952 if (nv->fn->activate(nv) == 0) 952 if (nv->fn->activate(nv) == 0)
953 break; 953 break;
954 rp->view = 0; 954 rp->view = NULL;
955 } 955 }
956 } 956 }
957 } 957 }
@@ -975,7 +975,7 @@ raw3270_deactivate_view(struct raw3270_view *view)
975 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags); 975 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
976 if (rp->view == view) { 976 if (rp->view == view) {
977 view->fn->deactivate(view); 977 view->fn->deactivate(view);
978 rp->view = 0; 978 rp->view = NULL;
979 /* Move deactivated view to end of list. */ 979 /* Move deactivated view to end of list. */
980 list_del_init(&view->list); 980 list_del_init(&view->list);
981 list_add_tail(&view->list, &rp->view_list); 981 list_add_tail(&view->list, &rp->view_list);
@@ -985,7 +985,7 @@ raw3270_deactivate_view(struct raw3270_view *view)
985 rp->view = view; 985 rp->view = view;
986 if (view->fn->activate(view) == 0) 986 if (view->fn->activate(view) == 0)
987 break; 987 break;
988 rp->view = 0; 988 rp->view = NULL;
989 } 989 }
990 } 990 }
991 } 991 }
@@ -1076,7 +1076,7 @@ raw3270_del_view(struct raw3270_view *view)
1076 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags); 1076 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
1077 if (rp->view == view) { 1077 if (rp->view == view) {
1078 view->fn->deactivate(view); 1078 view->fn->deactivate(view);
1079 rp->view = 0; 1079 rp->view = NULL;
1080 } 1080 }
1081 list_del_init(&view->list); 1081 list_del_init(&view->list);
1082 if (!rp->view && test_bit(RAW3270_FLAGS_READY, &rp->flags)) { 1082 if (!rp->view && test_bit(RAW3270_FLAGS_READY, &rp->flags)) {
@@ -1106,10 +1106,10 @@ raw3270_delete_device(struct raw3270 *rp)
1106 1106
1107 /* Remove from device chain. */ 1107 /* Remove from device chain. */
1108 mutex_lock(&raw3270_mutex); 1108 mutex_lock(&raw3270_mutex);
1109 if (rp->clttydev) 1109 if (rp->clttydev && !IS_ERR(rp->clttydev))
1110 class_device_destroy(class3270, 1110 class_device_destroy(class3270,
1111 MKDEV(IBM_TTY3270_MAJOR, rp->minor)); 1111 MKDEV(IBM_TTY3270_MAJOR, rp->minor));
1112 if (rp->cltubdev) 1112 if (rp->cltubdev && !IS_ERR(rp->cltubdev))
1113 class_device_destroy(class3270, 1113 class_device_destroy(class3270,
1114 MKDEV(IBM_FS3270_MAJOR, rp->minor)); 1114 MKDEV(IBM_FS3270_MAJOR, rp->minor));
1115 list_del_init(&rp->list); 1115 list_del_init(&rp->list);
@@ -1117,9 +1117,9 @@ raw3270_delete_device(struct raw3270 *rp)
1117 1117
1118 /* Disconnect from ccw_device. */ 1118 /* Disconnect from ccw_device. */
1119 cdev = rp->cdev; 1119 cdev = rp->cdev;
1120 rp->cdev = 0; 1120 rp->cdev = NULL;
1121 cdev->dev.driver_data = 0; 1121 cdev->dev.driver_data = NULL;
1122 cdev->handler = 0; 1122 cdev->handler = NULL;
1123 1123
1124 /* Put ccw_device structure. */ 1124 /* Put ccw_device structure. */
1125 put_device(&cdev->dev); 1125 put_device(&cdev->dev);
@@ -1144,7 +1144,7 @@ raw3270_model_show(struct device *dev, struct device_attribute *attr, char *buf)
1144 return snprintf(buf, PAGE_SIZE, "%i\n", 1144 return snprintf(buf, PAGE_SIZE, "%i\n",
1145 ((struct raw3270 *) dev->driver_data)->model); 1145 ((struct raw3270 *) dev->driver_data)->model);
1146} 1146}
1147static DEVICE_ATTR(model, 0444, raw3270_model_show, 0); 1147static DEVICE_ATTR(model, 0444, raw3270_model_show, NULL);
1148 1148
1149static ssize_t 1149static ssize_t
1150raw3270_rows_show(struct device *dev, struct device_attribute *attr, char *buf) 1150raw3270_rows_show(struct device *dev, struct device_attribute *attr, char *buf)
@@ -1152,7 +1152,7 @@ raw3270_rows_show(struct device *dev, struct device_attribute *attr, char *buf)
1152 return snprintf(buf, PAGE_SIZE, "%i\n", 1152 return snprintf(buf, PAGE_SIZE, "%i\n",
1153 ((struct raw3270 *) dev->driver_data)->rows); 1153 ((struct raw3270 *) dev->driver_data)->rows);
1154} 1154}
1155static DEVICE_ATTR(rows, 0444, raw3270_rows_show, 0); 1155static DEVICE_ATTR(rows, 0444, raw3270_rows_show, NULL);
1156 1156
1157static ssize_t 1157static ssize_t
1158raw3270_columns_show(struct device *dev, struct device_attribute *attr, char *buf) 1158raw3270_columns_show(struct device *dev, struct device_attribute *attr, char *buf)
@@ -1160,7 +1160,7 @@ raw3270_columns_show(struct device *dev, struct device_attribute *attr, char *bu
1160 return snprintf(buf, PAGE_SIZE, "%i\n", 1160 return snprintf(buf, PAGE_SIZE, "%i\n",
1161 ((struct raw3270 *) dev->driver_data)->cols); 1161 ((struct raw3270 *) dev->driver_data)->cols);
1162} 1162}
1163static DEVICE_ATTR(columns, 0444, raw3270_columns_show, 0); 1163static DEVICE_ATTR(columns, 0444, raw3270_columns_show, NULL);
1164 1164
1165static struct attribute * raw3270_attrs[] = { 1165static struct attribute * raw3270_attrs[] = {
1166 &dev_attr_model.attr, 1166 &dev_attr_model.attr,
@@ -1173,21 +1173,37 @@ static struct attribute_group raw3270_attr_group = {
1173 .attrs = raw3270_attrs, 1173 .attrs = raw3270_attrs,
1174}; 1174};
1175 1175
1176static void 1176static int raw3270_create_attributes(struct raw3270 *rp)
1177raw3270_create_attributes(struct raw3270 *rp)
1178{ 1177{
1179 //FIXME: check return code 1178 int rc;
1180 sysfs_create_group(&rp->cdev->dev.kobj, &raw3270_attr_group); 1179
1181 rp->clttydev = 1180 rc = sysfs_create_group(&rp->cdev->dev.kobj, &raw3270_attr_group);
1182 class_device_create(class3270, NULL, 1181 if (rc)
1183 MKDEV(IBM_TTY3270_MAJOR, rp->minor), 1182 goto out;
1184 &rp->cdev->dev, "tty%s", 1183
1185 rp->cdev->dev.bus_id); 1184 rp->clttydev = class_device_create(class3270, NULL,
1186 rp->cltubdev = 1185 MKDEV(IBM_TTY3270_MAJOR, rp->minor),
1187 class_device_create(class3270, NULL, 1186 &rp->cdev->dev, "tty%s",
1188 MKDEV(IBM_FS3270_MAJOR, rp->minor), 1187 rp->cdev->dev.bus_id);
1189 &rp->cdev->dev, "tub%s", 1188 if (IS_ERR(rp->clttydev)) {
1190 rp->cdev->dev.bus_id); 1189 rc = PTR_ERR(rp->clttydev);
1190 goto out_ttydev;
1191 }
1192
1193 rp->cltubdev = class_device_create(class3270, NULL,
1194 MKDEV(IBM_FS3270_MAJOR, rp->minor),
1195 &rp->cdev->dev, "tub%s",
1196 rp->cdev->dev.bus_id);
1197 if (!IS_ERR(rp->cltubdev))
1198 goto out;
1199
1200 rc = PTR_ERR(rp->cltubdev);
1201 class_device_destroy(class3270, MKDEV(IBM_TTY3270_MAJOR, rp->minor));
1202
1203out_ttydev:
1204 sysfs_remove_group(&rp->cdev->dev.kobj, &raw3270_attr_group);
1205out:
1206 return rc;
1191} 1207}
1192 1208
1193/* 1209/*
@@ -1255,7 +1271,9 @@ raw3270_set_online (struct ccw_device *cdev)
1255 rc = raw3270_reset_device(rp); 1271 rc = raw3270_reset_device(rp);
1256 if (rc) 1272 if (rc)
1257 goto failure; 1273 goto failure;
1258 raw3270_create_attributes(rp); 1274 rc = raw3270_create_attributes(rp);
1275 if (rc)
1276 goto failure;
1259 set_bit(RAW3270_FLAGS_READY, &rp->flags); 1277 set_bit(RAW3270_FLAGS_READY, &rp->flags);
1260 mutex_lock(&raw3270_mutex); 1278 mutex_lock(&raw3270_mutex);
1261 list_for_each_entry(np, &raw3270_notifier, list) 1279 list_for_each_entry(np, &raw3270_notifier, list)
@@ -1296,7 +1314,7 @@ raw3270_remove (struct ccw_device *cdev)
1296 spin_lock_irqsave(get_ccwdev_lock(cdev), flags); 1314 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1297 if (rp->view) { 1315 if (rp->view) {
1298 rp->view->fn->deactivate(rp->view); 1316 rp->view->fn->deactivate(rp->view);
1299 rp->view = 0; 1317 rp->view = NULL;
1300 } 1318 }
1301 while (!list_empty(&rp->view_list)) { 1319 while (!list_empty(&rp->view_list)) {
1302 v = list_entry(rp->view_list.next, struct raw3270_view, list); 1320 v = list_entry(rp->view_list.next, struct raw3270_view, list);
diff --git a/drivers/s390/char/raw3270.h b/drivers/s390/char/raw3270.h
index b635bf8e7775..90beaa80a782 100644
--- a/drivers/s390/char/raw3270.h
+++ b/drivers/s390/char/raw3270.h
@@ -231,7 +231,7 @@ alloc_string(struct list_head *free_list, unsigned long len)
231 INIT_LIST_HEAD(&cs->update); 231 INIT_LIST_HEAD(&cs->update);
232 return cs; 232 return cs;
233 } 233 }
234 return 0; 234 return NULL;
235} 235}
236 236
237static inline unsigned long 237static inline unsigned long
diff --git a/drivers/s390/char/sclp.c b/drivers/s390/char/sclp.c
index 4138564402b8..985d1613baaa 100644
--- a/drivers/s390/char/sclp.c
+++ b/drivers/s390/char/sclp.c
@@ -383,6 +383,7 @@ void
383sclp_sync_wait(void) 383sclp_sync_wait(void)
384{ 384{
385 unsigned long psw_mask; 385 unsigned long psw_mask;
386 unsigned long flags;
386 unsigned long cr0, cr0_sync; 387 unsigned long cr0, cr0_sync;
387 u64 timeout; 388 u64 timeout;
388 389
@@ -395,9 +396,11 @@ sclp_sync_wait(void)
395 sclp_tod_from_jiffies(sclp_request_timer.expires - 396 sclp_tod_from_jiffies(sclp_request_timer.expires -
396 jiffies); 397 jiffies);
397 } 398 }
399 local_irq_save(flags);
398 /* Prevent bottom half from executing once we force interrupts open */ 400 /* Prevent bottom half from executing once we force interrupts open */
399 local_bh_disable(); 401 local_bh_disable();
400 /* Enable service-signal interruption, disable timer interrupts */ 402 /* Enable service-signal interruption, disable timer interrupts */
403 trace_hardirqs_on();
401 __ctl_store(cr0, 0, 0); 404 __ctl_store(cr0, 0, 0);
402 cr0_sync = cr0; 405 cr0_sync = cr0;
403 cr0_sync |= 0x00000200; 406 cr0_sync |= 0x00000200;
@@ -415,11 +418,10 @@ sclp_sync_wait(void)
415 barrier(); 418 barrier();
416 cpu_relax(); 419 cpu_relax();
417 } 420 }
418 /* Restore interrupt settings */ 421 local_irq_disable();
419 asm volatile ("SSM 0(%0)"
420 : : "a" (&psw_mask) : "memory");
421 __ctl_load(cr0, 0, 0); 422 __ctl_load(cr0, 0, 0);
422 __local_bh_enable(); 423 _local_bh_enable();
424 local_irq_restore(flags);
423} 425}
424 426
425EXPORT_SYMBOL(sclp_sync_wait); 427EXPORT_SYMBOL(sclp_sync_wait);
diff --git a/drivers/s390/char/tape_34xx.c b/drivers/s390/char/tape_34xx.c
index 48b4d30a7256..7b95dab913d0 100644
--- a/drivers/s390/char/tape_34xx.c
+++ b/drivers/s390/char/tape_34xx.c
@@ -1309,9 +1309,9 @@ static struct tape_discipline tape_discipline_34xx = {
1309}; 1309};
1310 1310
1311static struct ccw_device_id tape_34xx_ids[] = { 1311static struct ccw_device_id tape_34xx_ids[] = {
1312 { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), driver_info: tape_3480}, 1312 { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), .driver_info = tape_3480},
1313 { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), driver_info: tape_3490}, 1313 { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), .driver_info = tape_3490},
1314 { /* end of list */ } 1314 { /* end of list */ },
1315}; 1315};
1316 1316
1317static int 1317static int
diff --git a/drivers/s390/char/tape_class.c b/drivers/s390/char/tape_class.c
index a5c68e60fcf4..56b87618b100 100644
--- a/drivers/s390/char/tape_class.c
+++ b/drivers/s390/char/tape_class.c
@@ -76,14 +76,22 @@ struct tape_class_device *register_tape_dev(
76 device, 76 device,
77 "%s", tcd->device_name 77 "%s", tcd->device_name
78 ); 78 );
79 sysfs_create_link( 79 rc = IS_ERR(tcd->class_device) ? PTR_ERR(tcd->class_device) : 0;
80 if (rc)
81 goto fail_with_cdev;
82 rc = sysfs_create_link(
80 &device->kobj, 83 &device->kobj,
81 &tcd->class_device->kobj, 84 &tcd->class_device->kobj,
82 tcd->mode_name 85 tcd->mode_name
83 ); 86 );
87 if (rc)
88 goto fail_with_class_device;
84 89
85 return tcd; 90 return tcd;
86 91
92fail_with_class_device:
93 class_device_destroy(tape_class, tcd->char_device->dev);
94
87fail_with_cdev: 95fail_with_cdev:
88 cdev_del(tcd->char_device); 96 cdev_del(tcd->char_device);
89 97
diff --git a/drivers/s390/char/tape_core.c b/drivers/s390/char/tape_core.c
index 122b4d8965c3..2826aed91043 100644
--- a/drivers/s390/char/tape_core.c
+++ b/drivers/s390/char/tape_core.c
@@ -543,20 +543,24 @@ int
543tape_generic_probe(struct ccw_device *cdev) 543tape_generic_probe(struct ccw_device *cdev)
544{ 544{
545 struct tape_device *device; 545 struct tape_device *device;
546 int ret;
546 547
547 device = tape_alloc_device(); 548 device = tape_alloc_device();
548 if (IS_ERR(device)) 549 if (IS_ERR(device))
549 return -ENODEV; 550 return -ENODEV;
550 PRINT_INFO("tape device %s found\n", cdev->dev.bus_id); 551 ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
552 ret = sysfs_create_group(&cdev->dev.kobj, &tape_attr_group);
553 if (ret) {
554 tape_put_device(device);
555 PRINT_ERR("probe failed for tape device %s\n", cdev->dev.bus_id);
556 return ret;
557 }
551 cdev->dev.driver_data = device; 558 cdev->dev.driver_data = device;
559 cdev->handler = __tape_do_irq;
552 device->cdev = cdev; 560 device->cdev = cdev;
553 device->cdev_id = busid_to_int(cdev->dev.bus_id); 561 device->cdev_id = busid_to_int(cdev->dev.bus_id);
554 cdev->handler = __tape_do_irq; 562 PRINT_INFO("tape device %s found\n", cdev->dev.bus_id);
555 563 return ret;
556 ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
557 sysfs_create_group(&cdev->dev.kobj, &tape_attr_group);
558
559 return 0;
560} 564}
561 565
562static inline void 566static inline void
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index f496f236b9c0..29718042c6c9 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -437,7 +437,7 @@ tty3270_rcl_add(struct tty3270 *tp, char *input, int len)
437{ 437{
438 struct string *s; 438 struct string *s;
439 439
440 tp->rcl_walk = 0; 440 tp->rcl_walk = NULL;
441 if (len <= 0) 441 if (len <= 0)
442 return; 442 return;
443 if (tp->rcl_nr >= tp->rcl_max) { 443 if (tp->rcl_nr >= tp->rcl_max) {
@@ -466,12 +466,12 @@ tty3270_rcl_backward(struct kbd_data *kbd)
466 else if (!list_empty(&tp->rcl_lines)) 466 else if (!list_empty(&tp->rcl_lines))
467 tp->rcl_walk = tp->rcl_lines.prev; 467 tp->rcl_walk = tp->rcl_lines.prev;
468 s = tp->rcl_walk ? 468 s = tp->rcl_walk ?
469 list_entry(tp->rcl_walk, struct string, list) : 0; 469 list_entry(tp->rcl_walk, struct string, list) : NULL;
470 if (tp->rcl_walk) { 470 if (tp->rcl_walk) {
471 s = list_entry(tp->rcl_walk, struct string, list); 471 s = list_entry(tp->rcl_walk, struct string, list);
472 tty3270_update_prompt(tp, s->string, s->len); 472 tty3270_update_prompt(tp, s->string, s->len);
473 } else 473 } else
474 tty3270_update_prompt(tp, 0, 0); 474 tty3270_update_prompt(tp, NULL, 0);
475 tty3270_set_timer(tp, 1); 475 tty3270_set_timer(tp, 1);
476 } 476 }
477 spin_unlock_bh(&tp->view.lock); 477 spin_unlock_bh(&tp->view.lock);
@@ -553,7 +553,7 @@ tty3270_read_tasklet(struct raw3270_request *rrq)
553 * has to be emitted to the tty and for 0x6d the screen 553 * has to be emitted to the tty and for 0x6d the screen
554 * needs to be redrawn. 554 * needs to be redrawn.
555 */ 555 */
556 input = 0; 556 input = NULL;
557 len = 0; 557 len = 0;
558 if (tp->input->string[0] == 0x7d) { 558 if (tp->input->string[0] == 0x7d) {
559 /* Enter: write input to tty. */ 559 /* Enter: write input to tty. */
@@ -567,7 +567,7 @@ tty3270_read_tasklet(struct raw3270_request *rrq)
567 tty3270_update_status(tp); 567 tty3270_update_status(tp);
568 } 568 }
569 /* Clear input area. */ 569 /* Clear input area. */
570 tty3270_update_prompt(tp, 0, 0); 570 tty3270_update_prompt(tp, NULL, 0);
571 tty3270_set_timer(tp, 1); 571 tty3270_set_timer(tp, 1);
572 } else if (tp->input->string[0] == 0x6d) { 572 } else if (tp->input->string[0] == 0x6d) {
573 /* Display has been cleared. Redraw. */ 573 /* Display has been cleared. Redraw. */
@@ -808,8 +808,8 @@ tty3270_release(struct raw3270_view *view)
808 tp = (struct tty3270 *) view; 808 tp = (struct tty3270 *) view;
809 tty = tp->tty; 809 tty = tp->tty;
810 if (tty) { 810 if (tty) {
811 tty->driver_data = 0; 811 tty->driver_data = NULL;
812 tp->tty = tp->kbd->tty = 0; 812 tp->tty = tp->kbd->tty = NULL;
813 tty_hangup(tty); 813 tty_hangup(tty);
814 raw3270_put_view(&tp->view); 814 raw3270_put_view(&tp->view);
815 } 815 }
@@ -948,8 +948,8 @@ tty3270_close(struct tty_struct *tty, struct file * filp)
948 return; 948 return;
949 tp = (struct tty3270 *) tty->driver_data; 949 tp = (struct tty3270 *) tty->driver_data;
950 if (tp) { 950 if (tp) {
951 tty->driver_data = 0; 951 tty->driver_data = NULL;
952 tp->tty = tp->kbd->tty = 0; 952 tp->tty = tp->kbd->tty = NULL;
953 raw3270_put_view(&tp->view); 953 raw3270_put_view(&tp->view);
954 } 954 }
955} 955}
@@ -1673,7 +1673,7 @@ tty3270_set_termios(struct tty_struct *tty, struct termios *old)
1673 new = L_ECHO(tty) ? TF_INPUT: TF_INPUTN; 1673 new = L_ECHO(tty) ? TF_INPUT: TF_INPUTN;
1674 if (new != tp->inattr) { 1674 if (new != tp->inattr) {
1675 tp->inattr = new; 1675 tp->inattr = new;
1676 tty3270_update_prompt(tp, 0, 0); 1676 tty3270_update_prompt(tp, NULL, 0);
1677 tty3270_set_timer(tp, 1); 1677 tty3270_set_timer(tp, 1);
1678 } 1678 }
1679 } 1679 }
@@ -1759,7 +1759,7 @@ void
1759tty3270_notifier(int index, int active) 1759tty3270_notifier(int index, int active)
1760{ 1760{
1761 if (active) 1761 if (active)
1762 tty_register_device(tty3270_driver, index, 0); 1762 tty_register_device(tty3270_driver, index, NULL);
1763 else 1763 else
1764 tty_unregister_device(tty3270_driver, index); 1764 tty_unregister_device(tty3270_driver, index);
1765} 1765}
@@ -1818,7 +1818,7 @@ tty3270_exit(void)
1818 1818
1819 raw3270_unregister_notifier(tty3270_notifier); 1819 raw3270_unregister_notifier(tty3270_notifier);
1820 driver = tty3270_driver; 1820 driver = tty3270_driver;
1821 tty3270_driver = 0; 1821 tty3270_driver = NULL;
1822 tty_unregister_driver(driver); 1822 tty_unregister_driver(driver);
1823 tty3270_del_views(); 1823 tty3270_del_views();
1824} 1824}
diff --git a/drivers/s390/char/vmlogrdr.c b/drivers/s390/char/vmlogrdr.c
index c625b69ebd19..6cb23040954b 100644
--- a/drivers/s390/char/vmlogrdr.c
+++ b/drivers/s390/char/vmlogrdr.c
@@ -86,8 +86,8 @@ struct vmlogrdr_priv_t {
86 */ 86 */
87static int vmlogrdr_open(struct inode *, struct file *); 87static int vmlogrdr_open(struct inode *, struct file *);
88static int vmlogrdr_release(struct inode *, struct file *); 88static int vmlogrdr_release(struct inode *, struct file *);
89static ssize_t vmlogrdr_read (struct file *filp, char *data, size_t count, 89static ssize_t vmlogrdr_read (struct file *filp, char __user *data,
90 loff_t * ppos); 90 size_t count, loff_t * ppos);
91 91
92static struct file_operations vmlogrdr_fops = { 92static struct file_operations vmlogrdr_fops = {
93 .owner = THIS_MODULE, 93 .owner = THIS_MODULE,
@@ -515,7 +515,7 @@ vmlogrdr_receive_data(struct vmlogrdr_priv_t *priv) {
515 515
516 516
517static ssize_t 517static ssize_t
518vmlogrdr_read (struct file *filp, char *data, size_t count, loff_t * ppos) 518vmlogrdr_read(struct file *filp, char __user *data, size_t count, loff_t * ppos)
519{ 519{
520 int rc; 520 int rc;
521 struct vmlogrdr_priv_t * priv = filp->private_data; 521 struct vmlogrdr_priv_t * priv = filp->private_data;
diff --git a/drivers/s390/char/vmwatchdog.c b/drivers/s390/char/vmwatchdog.c
index 5acc0ace3d7d..807320a41fa4 100644
--- a/drivers/s390/char/vmwatchdog.c
+++ b/drivers/s390/char/vmwatchdog.c
@@ -193,7 +193,7 @@ static int vmwdt_ioctl(struct inode *i, struct file *f,
193 return 0; 193 return 0;
194 case WDIOC_GETSTATUS: 194 case WDIOC_GETSTATUS:
195 case WDIOC_GETBOOTSTATUS: 195 case WDIOC_GETBOOTSTATUS:
196 return put_user(0, (int *)arg); 196 return put_user(0, (int __user *)arg);
197 case WDIOC_GETTEMP: 197 case WDIOC_GETTEMP:
198 return -EINVAL; 198 return -EINVAL;
199 case WDIOC_SETOPTIONS: 199 case WDIOC_SETOPTIONS:
diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index c7319a07ba35..38954f5cd14c 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -152,7 +152,6 @@ ccwgroup_create(struct device *root,
152 struct ccwgroup_device *gdev; 152 struct ccwgroup_device *gdev;
153 int i; 153 int i;
154 int rc; 154 int rc;
155 int del_drvdata;
156 155
157 if (argc > 256) /* disallow dumb users */ 156 if (argc > 256) /* disallow dumb users */
158 return -EINVAL; 157 return -EINVAL;
@@ -163,7 +162,6 @@ ccwgroup_create(struct device *root,
163 162
164 atomic_set(&gdev->onoff, 0); 163 atomic_set(&gdev->onoff, 0);
165 164
166 del_drvdata = 0;
167 for (i = 0; i < argc; i++) { 165 for (i = 0; i < argc; i++) {
168 gdev->cdev[i] = get_ccwdev_by_busid(cdrv, argv[i]); 166 gdev->cdev[i] = get_ccwdev_by_busid(cdrv, argv[i]);
169 167
@@ -180,18 +178,14 @@ ccwgroup_create(struct device *root,
180 rc = -EINVAL; 178 rc = -EINVAL;
181 goto free_dev; 179 goto free_dev;
182 } 180 }
183 }
184 for (i = 0; i < argc; i++)
185 gdev->cdev[i]->dev.driver_data = gdev; 181 gdev->cdev[i]->dev.driver_data = gdev;
186 del_drvdata = 1; 182 }
187 183
188 gdev->creator_id = creator_id; 184 gdev->creator_id = creator_id;
189 gdev->count = argc; 185 gdev->count = argc;
190 gdev->dev = (struct device ) { 186 gdev->dev.bus = &ccwgroup_bus_type;
191 .bus = &ccwgroup_bus_type, 187 gdev->dev.parent = root;
192 .parent = root, 188 gdev->dev.release = ccwgroup_release;
193 .release = ccwgroup_release,
194 };
195 189
196 snprintf (gdev->dev.bus_id, BUS_ID_SIZE, "%s", 190 snprintf (gdev->dev.bus_id, BUS_ID_SIZE, "%s",
197 gdev->cdev[0]->dev.bus_id); 191 gdev->cdev[0]->dev.bus_id);
@@ -226,9 +220,9 @@ error:
226free_dev: 220free_dev:
227 for (i = 0; i < argc; i++) 221 for (i = 0; i < argc; i++)
228 if (gdev->cdev[i]) { 222 if (gdev->cdev[i]) {
229 put_device(&gdev->cdev[i]->dev); 223 if (gdev->cdev[i]->dev.driver_data == gdev)
230 if (del_drvdata)
231 gdev->cdev[i]->dev.driver_data = NULL; 224 gdev->cdev[i]->dev.driver_data = NULL;
225 put_device(&gdev->cdev[i]->dev);
232 } 226 }
233 kfree(gdev); 227 kfree(gdev);
234 return rc; 228 return rc;
@@ -319,7 +313,7 @@ ccwgroup_online_store (struct device *dev, struct device_attribute *attr, const
319 if (!try_module_get(gdrv->owner)) 313 if (!try_module_get(gdrv->owner))
320 return -EINVAL; 314 return -EINVAL;
321 315
322 value = simple_strtoul(buf, 0, 0); 316 value = simple_strtoul(buf, NULL, 0);
323 ret = count; 317 ret = count;
324 if (value == 1) 318 if (value == 1)
325 ccwgroup_set_online(gdev); 319 ccwgroup_set_online(gdev);
@@ -395,10 +389,8 @@ int
395ccwgroup_driver_register (struct ccwgroup_driver *cdriver) 389ccwgroup_driver_register (struct ccwgroup_driver *cdriver)
396{ 390{
397 /* register our new driver with the core */ 391 /* register our new driver with the core */
398 cdriver->driver = (struct device_driver) { 392 cdriver->driver.bus = &ccwgroup_bus_type;
399 .bus = &ccwgroup_bus_type, 393 cdriver->driver.name = cdriver->name;
400 .name = cdriver->name,
401 };
402 394
403 return driver_register(&cdriver->driver); 395 return driver_register(&cdriver->driver);
404} 396}
diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
index a01f3bba4a7b..c28444af0919 100644
--- a/drivers/s390/cio/chsc.c
+++ b/drivers/s390/cio/chsc.c
@@ -238,8 +238,6 @@ s390_subchannel_remove_chpid(struct device *dev, void *data)
238 /* Check for single path devices. */ 238 /* Check for single path devices. */
239 if (sch->schib.pmcw.pim == 0x80) 239 if (sch->schib.pmcw.pim == 0x80)
240 goto out_unreg; 240 goto out_unreg;
241 if (sch->vpm == mask)
242 goto out_unreg;
243 241
244 if ((sch->schib.scsw.actl & SCSW_ACTL_DEVACT) && 242 if ((sch->schib.scsw.actl & SCSW_ACTL_DEVACT) &&
245 (sch->schib.scsw.actl & SCSW_ACTL_SCHACT) && 243 (sch->schib.scsw.actl & SCSW_ACTL_SCHACT) &&
@@ -258,6 +256,8 @@ s390_subchannel_remove_chpid(struct device *dev, void *data)
258 /* trigger path verification. */ 256 /* trigger path verification. */
259 if (sch->driver && sch->driver->verify) 257 if (sch->driver && sch->driver->verify)
260 sch->driver->verify(&sch->dev); 258 sch->driver->verify(&sch->dev);
259 else if (sch->vpm == mask)
260 goto out_unreg;
261out_unlock: 261out_unlock:
262 spin_unlock_irq(&sch->lock); 262 spin_unlock_irq(&sch->lock);
263 return 0; 263 return 0;
@@ -1391,10 +1391,8 @@ new_channel_path(int chpid)
1391 /* fill in status, etc. */ 1391 /* fill in status, etc. */
1392 chp->id = chpid; 1392 chp->id = chpid;
1393 chp->state = 1; 1393 chp->state = 1;
1394 chp->dev = (struct device) { 1394 chp->dev.parent = &css[0]->device;
1395 .parent = &css[0]->device, 1395 chp->dev.release = chp_release;
1396 .release = chp_release,
1397 };
1398 snprintf(chp->dev.bus_id, BUS_ID_SIZE, "chp0.%x", chpid); 1396 snprintf(chp->dev.bus_id, BUS_ID_SIZE, "chp0.%x", chpid);
1399 1397
1400 /* Obtain channel path description and fill it in. */ 1398 /* Obtain channel path description and fill it in. */
@@ -1464,6 +1462,40 @@ chsc_get_chp_desc(struct subchannel *sch, int chp_no)
1464 return desc; 1462 return desc;
1465} 1463}
1466 1464
1465static int reset_channel_path(struct channel_path *chp)
1466{
1467 int cc;
1468
1469 cc = rchp(chp->id);
1470 switch (cc) {
1471 case 0:
1472 return 0;
1473 case 2:
1474 return -EBUSY;
1475 default:
1476 return -ENODEV;
1477 }
1478}
1479
1480static void reset_channel_paths_css(struct channel_subsystem *css)
1481{
1482 int i;
1483
1484 for (i = 0; i <= __MAX_CHPID; i++) {
1485 if (css->chps[i])
1486 reset_channel_path(css->chps[i]);
1487 }
1488}
1489
1490void cio_reset_channel_paths(void)
1491{
1492 int i;
1493
1494 for (i = 0; i <= __MAX_CSSID; i++) {
1495 if (css[i] && css[i]->valid)
1496 reset_channel_paths_css(css[i]);
1497 }
1498}
1467 1499
1468static int __init 1500static int __init
1469chsc_alloc_sei_area(void) 1501chsc_alloc_sei_area(void)
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index a3423267467f..89320c1ad825 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -147,7 +147,7 @@ cio_tpi(void)
147 sch->driver->irq(&sch->dev); 147 sch->driver->irq(&sch->dev);
148 spin_unlock(&sch->lock); 148 spin_unlock(&sch->lock);
149 irq_exit (); 149 irq_exit ();
150 __local_bh_enable(); 150 _local_bh_enable();
151 return 1; 151 return 1;
152} 152}
153 153
@@ -519,6 +519,7 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
519 memset(sch, 0, sizeof(struct subchannel)); 519 memset(sch, 0, sizeof(struct subchannel));
520 520
521 spin_lock_init(&sch->lock); 521 spin_lock_init(&sch->lock);
522 mutex_init(&sch->reg_mutex);
522 523
523 /* Set a name for the subchannel */ 524 /* Set a name for the subchannel */
524 snprintf (sch->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", schid.ssid, 525 snprintf (sch->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", schid.ssid,
@@ -797,7 +798,7 @@ struct subchannel *
797cio_get_console_subchannel(void) 798cio_get_console_subchannel(void)
798{ 799{
799 if (!console_subchannel_in_use) 800 if (!console_subchannel_in_use)
800 return 0; 801 return NULL;
801 return &console_subchannel; 802 return &console_subchannel;
802} 803}
803 804
@@ -875,5 +876,6 @@ void
875reipl(unsigned long devno) 876reipl(unsigned long devno)
876{ 877{
877 clear_all_subchannels(); 878 clear_all_subchannels();
879 cio_reset_channel_paths();
878 do_reipl(devno); 880 do_reipl(devno);
879} 881}
diff --git a/drivers/s390/cio/cio.h b/drivers/s390/cio/cio.h
index 0ca987344e07..4541c1af4b66 100644
--- a/drivers/s390/cio/cio.h
+++ b/drivers/s390/cio/cio.h
@@ -2,6 +2,7 @@
2#define S390_CIO_H 2#define S390_CIO_H
3 3
4#include "schid.h" 4#include "schid.h"
5#include <linux/mutex.h>
5 6
6/* 7/*
7 * where we put the ssd info 8 * where we put the ssd info
@@ -87,7 +88,7 @@ struct orb {
87struct subchannel { 88struct subchannel {
88 struct subchannel_id schid; 89 struct subchannel_id schid;
89 spinlock_t lock; /* subchannel lock */ 90 spinlock_t lock; /* subchannel lock */
90 91 struct mutex reg_mutex;
91 enum { 92 enum {
92 SUBCHANNEL_TYPE_IO = 0, 93 SUBCHANNEL_TYPE_IO = 0,
93 SUBCHANNEL_TYPE_CHSC = 1, 94 SUBCHANNEL_TYPE_CHSC = 1,
diff --git a/drivers/s390/cio/cmf.c b/drivers/s390/cio/cmf.c
index 1c3e8e9012b0..828b2d334f0a 100644
--- a/drivers/s390/cio/cmf.c
+++ b/drivers/s390/cio/cmf.c
@@ -1068,6 +1068,7 @@ cmb_show_avg_sample_interval(struct device *dev, struct device_attribute *attr,
1068 if (count) { 1068 if (count) {
1069 interval = cmb_data->last_update - 1069 interval = cmb_data->last_update -
1070 cdev->private->cmb_start_time; 1070 cdev->private->cmb_start_time;
1071 interval = (interval * 1000) >> 12;
1071 interval /= count; 1072 interval /= count;
1072 } else 1073 } else
1073 interval = -1; 1074 interval = -1;
@@ -1140,7 +1141,7 @@ static struct attribute *cmf_attributes[] = {
1140 &dev_attr_avg_device_disconnect_time.attr, 1141 &dev_attr_avg_device_disconnect_time.attr,
1141 &dev_attr_avg_control_unit_queuing_time.attr, 1142 &dev_attr_avg_control_unit_queuing_time.attr,
1142 &dev_attr_avg_device_active_only_time.attr, 1143 &dev_attr_avg_device_active_only_time.attr,
1143 0, 1144 NULL,
1144}; 1145};
1145 1146
1146static struct attribute_group cmf_attr_group = { 1147static struct attribute_group cmf_attr_group = {
@@ -1160,7 +1161,7 @@ static struct attribute *cmf_attributes_ext[] = {
1160 &dev_attr_avg_device_active_only_time.attr, 1161 &dev_attr_avg_device_active_only_time.attr,
1161 &dev_attr_avg_device_busy_time.attr, 1162 &dev_attr_avg_device_busy_time.attr,
1162 &dev_attr_avg_initial_command_response_time.attr, 1163 &dev_attr_avg_initial_command_response_time.attr,
1163 0, 1164 NULL,
1164}; 1165};
1165 1166
1166static struct attribute_group cmf_attr_group_ext = { 1167static struct attribute_group cmf_attr_group_ext = {
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index 1d3be80797f8..13eeea3d547f 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -108,6 +108,24 @@ css_subchannel_release(struct device *dev)
108 108
109extern int css_get_ssd_info(struct subchannel *sch); 109extern int css_get_ssd_info(struct subchannel *sch);
110 110
111
112int css_sch_device_register(struct subchannel *sch)
113{
114 int ret;
115
116 mutex_lock(&sch->reg_mutex);
117 ret = device_register(&sch->dev);
118 mutex_unlock(&sch->reg_mutex);
119 return ret;
120}
121
122void css_sch_device_unregister(struct subchannel *sch)
123{
124 mutex_lock(&sch->reg_mutex);
125 device_unregister(&sch->dev);
126 mutex_unlock(&sch->reg_mutex);
127}
128
111static int 129static int
112css_register_subchannel(struct subchannel *sch) 130css_register_subchannel(struct subchannel *sch)
113{ 131{
@@ -119,7 +137,7 @@ css_register_subchannel(struct subchannel *sch)
119 sch->dev.release = &css_subchannel_release; 137 sch->dev.release = &css_subchannel_release;
120 138
121 /* make it known to the system */ 139 /* make it known to the system */
122 ret = device_register(&sch->dev); 140 ret = css_sch_device_register(sch);
123 if (ret) 141 if (ret)
124 printk (KERN_WARNING "%s: could not register %s\n", 142 printk (KERN_WARNING "%s: could not register %s\n",
125 __func__, sch->dev.bus_id); 143 __func__, sch->dev.bus_id);
@@ -250,7 +268,7 @@ css_evaluate_subchannel(struct subchannel_id schid, int slow)
250 * The device will be killed automatically. 268 * The device will be killed automatically.
251 */ 269 */
252 cio_disable_subchannel(sch); 270 cio_disable_subchannel(sch);
253 device_unregister(&sch->dev); 271 css_sch_device_unregister(sch);
254 /* Reset intparm to zeroes. */ 272 /* Reset intparm to zeroes. */
255 sch->schib.pmcw.intparm = 0; 273 sch->schib.pmcw.intparm = 0;
256 cio_modify(sch); 274 cio_modify(sch);
@@ -264,7 +282,7 @@ css_evaluate_subchannel(struct subchannel_id schid, int slow)
264 * away in any case. 282 * away in any case.
265 */ 283 */
266 if (!disc) { 284 if (!disc) {
267 device_unregister(&sch->dev); 285 css_sch_device_unregister(sch);
268 /* Reset intparm to zeroes. */ 286 /* Reset intparm to zeroes. */
269 sch->schib.pmcw.intparm = 0; 287 sch->schib.pmcw.intparm = 0;
270 cio_modify(sch); 288 cio_modify(sch);
@@ -605,9 +623,13 @@ init_channel_subsystem (void)
605 ret = device_register(&css[i]->device); 623 ret = device_register(&css[i]->device);
606 if (ret) 624 if (ret)
607 goto out_free; 625 goto out_free;
608 if (css_characteristics_avail && css_chsc_characteristics.secm) 626 if (css_characteristics_avail &&
609 device_create_file(&css[i]->device, 627 css_chsc_characteristics.secm) {
610 &dev_attr_cm_enable); 628 ret = device_create_file(&css[i]->device,
629 &dev_attr_cm_enable);
630 if (ret)
631 goto out_device;
632 }
611 } 633 }
612 css_init_done = 1; 634 css_init_done = 1;
613 635
@@ -615,6 +637,8 @@ init_channel_subsystem (void)
615 637
616 for_each_subchannel(__init_channel_subsystem, NULL); 638 for_each_subchannel(__init_channel_subsystem, NULL);
617 return 0; 639 return 0;
640out_device:
641 device_unregister(&css[i]->device);
618out_free: 642out_free:
619 kfree(css[i]); 643 kfree(css[i]);
620out_unregister: 644out_unregister:
diff --git a/drivers/s390/cio/css.h b/drivers/s390/cio/css.h
index e210f89a2449..8aabb4adeb5f 100644
--- a/drivers/s390/cio/css.h
+++ b/drivers/s390/cio/css.h
@@ -100,7 +100,7 @@ struct ccw_device_private {
100 struct qdio_irq *qdio_data; 100 struct qdio_irq *qdio_data;
101 struct irb irb; /* device status */ 101 struct irb irb; /* device status */
102 struct senseid senseid; /* SenseID info */ 102 struct senseid senseid; /* SenseID info */
103 struct pgid pgid; /* path group ID */ 103 struct pgid pgid[8]; /* path group IDs per chpid*/
104 struct ccw1 iccws[2]; /* ccws for SNID/SID/SPGID commands */ 104 struct ccw1 iccws[2]; /* ccws for SNID/SID/SPGID commands */
105 struct work_struct kick_work; 105 struct work_struct kick_work;
106 wait_queue_head_t wait_q; 106 wait_queue_head_t wait_q;
@@ -136,6 +136,8 @@ extern struct bus_type css_bus_type;
136extern struct css_driver io_subchannel_driver; 136extern struct css_driver io_subchannel_driver;
137 137
138extern int css_probe_device(struct subchannel_id); 138extern int css_probe_device(struct subchannel_id);
139extern int css_sch_device_register(struct subchannel *);
140extern void css_sch_device_unregister(struct subchannel *);
139extern struct subchannel * get_subchannel_by_schid(struct subchannel_id); 141extern struct subchannel * get_subchannel_by_schid(struct subchannel_id);
140extern int css_init_done; 142extern int css_init_done;
141extern int for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *); 143extern int for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *);
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index 67f0de6aed33..646da5640401 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -100,7 +100,7 @@ ccw_uevent (struct device *dev, char **envp, int num_envp,
100 if ((buffer_size - length <= 0) || (i >= num_envp)) 100 if ((buffer_size - length <= 0) || (i >= num_envp))
101 return -ENOMEM; 101 return -ENOMEM;
102 102
103 envp[i] = 0; 103 envp[i] = NULL;
104 104
105 return 0; 105 return 0;
106} 106}
@@ -280,7 +280,7 @@ ccw_device_remove_disconnected(struct ccw_device *cdev)
280 * 'throw away device'. 280 * 'throw away device'.
281 */ 281 */
282 sch = to_subchannel(cdev->dev.parent); 282 sch = to_subchannel(cdev->dev.parent);
283 device_unregister(&sch->dev); 283 css_sch_device_unregister(sch);
284 /* Reset intparm to zeroes. */ 284 /* Reset intparm to zeroes. */
285 sch->schib.pmcw.intparm = 0; 285 sch->schib.pmcw.intparm = 0;
286 cio_modify(sch); 286 cio_modify(sch);
@@ -556,12 +556,11 @@ get_disc_ccwdev_by_devno(unsigned int devno, unsigned int ssid,
556 struct ccw_device *sibling) 556 struct ccw_device *sibling)
557{ 557{
558 struct device *dev; 558 struct device *dev;
559 struct match_data data = { 559 struct match_data data;
560 .devno = devno,
561 .ssid = ssid,
562 .sibling = sibling,
563 };
564 560
561 data.devno = devno;
562 data.ssid = ssid;
563 data.sibling = sibling;
565 dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno); 564 dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno);
566 565
567 return dev ? to_ccwdev(dev) : NULL; 566 return dev ? to_ccwdev(dev) : NULL;
@@ -625,7 +624,7 @@ ccw_device_do_unreg_rereg(void *data)
625 other_sch->schib.pmcw.intparm = 0; 624 other_sch->schib.pmcw.intparm = 0;
626 cio_modify(other_sch); 625 cio_modify(other_sch);
627 } 626 }
628 device_unregister(&other_sch->dev); 627 css_sch_device_unregister(other_sch);
629 } 628 }
630 } 629 }
631 /* Update ssd info here. */ 630 /* Update ssd info here. */
@@ -709,7 +708,7 @@ ccw_device_call_sch_unregister(void *data)
709 struct subchannel *sch; 708 struct subchannel *sch;
710 709
711 sch = to_subchannel(cdev->dev.parent); 710 sch = to_subchannel(cdev->dev.parent);
712 device_unregister(&sch->dev); 711 css_sch_device_unregister(sch);
713 /* Reset intparm to zeroes. */ 712 /* Reset intparm to zeroes. */
714 sch->schib.pmcw.intparm = 0; 713 sch->schib.pmcw.intparm = 0;
715 cio_modify(sch); 714 cio_modify(sch);
@@ -835,10 +834,8 @@ io_subchannel_probe (struct subchannel *sch)
835 return -ENOMEM; 834 return -ENOMEM;
836 } 835 }
837 atomic_set(&cdev->private->onoff, 0); 836 atomic_set(&cdev->private->onoff, 0);
838 cdev->dev = (struct device) { 837 cdev->dev.parent = &sch->dev;
839 .parent = &sch->dev, 838 cdev->dev.release = ccw_device_release;
840 .release = ccw_device_release,
841 };
842 INIT_LIST_HEAD(&cdev->private->kick_work.entry); 839 INIT_LIST_HEAD(&cdev->private->kick_work.entry);
843 /* Do first half of device_register. */ 840 /* Do first half of device_register. */
844 device_initialize(&cdev->dev); 841 device_initialize(&cdev->dev);
@@ -977,9 +974,7 @@ ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch)
977 int rc; 974 int rc;
978 975
979 /* Initialize the ccw_device structure. */ 976 /* Initialize the ccw_device structure. */
980 cdev->dev = (struct device) { 977 cdev->dev.parent= &sch->dev;
981 .parent = &sch->dev,
982 };
983 rc = io_subchannel_recog(cdev, sch); 978 rc = io_subchannel_recog(cdev, sch);
984 if (rc) 979 if (rc)
985 return rc; 980 return rc;
@@ -1057,7 +1052,7 @@ get_ccwdev_by_busid(struct ccw_driver *cdrv, const char *bus_id)
1057 __ccwdev_check_busid); 1052 __ccwdev_check_busid);
1058 put_driver(drv); 1053 put_driver(drv);
1059 1054
1060 return dev ? to_ccwdev(dev) : 0; 1055 return dev ? to_ccwdev(dev) : NULL;
1061} 1056}
1062 1057
1063/************************** device driver handling ************************/ 1058/************************** device driver handling ************************/
@@ -1082,7 +1077,7 @@ ccw_device_probe (struct device *dev)
1082 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV; 1077 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1083 1078
1084 if (ret) { 1079 if (ret) {
1085 cdev->drv = 0; 1080 cdev->drv = NULL;
1086 return ret; 1081 return ret;
1087 } 1082 }
1088 1083
@@ -1113,7 +1108,7 @@ ccw_device_remove (struct device *dev)
1113 ret, cdev->dev.bus_id); 1108 ret, cdev->dev.bus_id);
1114 } 1109 }
1115 ccw_device_set_timeout(cdev, 0); 1110 ccw_device_set_timeout(cdev, 0);
1116 cdev->drv = 0; 1111 cdev->drv = NULL;
1117 return 0; 1112 return 0;
1118} 1113}
1119 1114
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index cb1af0b6f033..35e162ba6d54 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -152,7 +152,8 @@ ccw_device_cancel_halt_clear(struct ccw_device *cdev)
152 if (cdev->private->iretry) { 152 if (cdev->private->iretry) {
153 cdev->private->iretry--; 153 cdev->private->iretry--;
154 ret = cio_halt(sch); 154 ret = cio_halt(sch);
155 return (ret == 0) ? -EBUSY : ret; 155 if (ret != -EBUSY)
156 return (ret == 0) ? -EBUSY : ret;
156 } 157 }
157 /* halt io unsuccessful. */ 158 /* halt io unsuccessful. */
158 cdev->private->iretry = 255; /* 255 clear retries. */ 159 cdev->private->iretry = 255; /* 255 clear retries. */
@@ -266,12 +267,10 @@ ccw_device_recog_done(struct ccw_device *cdev, int state)
266 notify = 1; 267 notify = 1;
267 } 268 }
268 /* fill out sense information */ 269 /* fill out sense information */
269 cdev->id = (struct ccw_device_id) { 270 cdev->id.cu_type = cdev->private->senseid.cu_type;
270 .cu_type = cdev->private->senseid.cu_type, 271 cdev->id.cu_model = cdev->private->senseid.cu_model;
271 .cu_model = cdev->private->senseid.cu_model, 272 cdev->id.dev_type = cdev->private->senseid.dev_type;
272 .dev_type = cdev->private->senseid.dev_type, 273 cdev->id.dev_model = cdev->private->senseid.dev_model;
273 .dev_model = cdev->private->senseid.dev_model,
274 };
275 if (notify) { 274 if (notify) {
276 cdev->private->state = DEV_STATE_OFFLINE; 275 cdev->private->state = DEV_STATE_OFFLINE;
277 if (same_dev) { 276 if (same_dev) {
@@ -378,6 +377,56 @@ ccw_device_done(struct ccw_device *cdev, int state)
378 put_device (&cdev->dev); 377 put_device (&cdev->dev);
379} 378}
380 379
380static inline int cmp_pgid(struct pgid *p1, struct pgid *p2)
381{
382 char *c1;
383 char *c2;
384
385 c1 = (char *)p1;
386 c2 = (char *)p2;
387
388 return memcmp(c1 + 1, c2 + 1, sizeof(struct pgid) - 1);
389}
390
391static void __ccw_device_get_common_pgid(struct ccw_device *cdev)
392{
393 int i;
394 int last;
395
396 last = 0;
397 for (i = 0; i < 8; i++) {
398 if (cdev->private->pgid[i].inf.ps.state1 == SNID_STATE1_RESET)
399 /* No PGID yet */
400 continue;
401 if (cdev->private->pgid[last].inf.ps.state1 ==
402 SNID_STATE1_RESET) {
403 /* First non-zero PGID */
404 last = i;
405 continue;
406 }
407 if (cmp_pgid(&cdev->private->pgid[i],
408 &cdev->private->pgid[last]) == 0)
409 /* Non-conflicting PGIDs */
410 continue;
411
412 /* PGID mismatch, can't pathgroup. */
413 CIO_MSG_EVENT(0, "SNID - pgid mismatch for device "
414 "0.%x.%04x, can't pathgroup\n",
415 cdev->private->ssid, cdev->private->devno);
416 cdev->private->options.pgroup = 0;
417 return;
418 }
419 if (cdev->private->pgid[last].inf.ps.state1 ==
420 SNID_STATE1_RESET)
421 /* No previous pgid found */
422 memcpy(&cdev->private->pgid[0], &css[0]->global_pgid,
423 sizeof(struct pgid));
424 else
425 /* Use existing pgid */
426 memcpy(&cdev->private->pgid[0], &cdev->private->pgid[last],
427 sizeof(struct pgid));
428}
429
381/* 430/*
382 * Function called from device_pgid.c after sense path ground has completed. 431 * Function called from device_pgid.c after sense path ground has completed.
383 */ 432 */
@@ -388,24 +437,26 @@ ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
388 437
389 sch = to_subchannel(cdev->dev.parent); 438 sch = to_subchannel(cdev->dev.parent);
390 switch (err) { 439 switch (err) {
391 case 0: 440 case -EOPNOTSUPP: /* path grouping not supported, use nop instead. */
392 /* Start Path Group verification. */ 441 cdev->private->options.pgroup = 0;
393 sch->vpm = 0; /* Start with no path groups set. */ 442 break;
394 cdev->private->state = DEV_STATE_VERIFY; 443 case 0: /* success */
395 ccw_device_verify_start(cdev); 444 case -EACCES: /* partial success, some paths not operational */
445 /* Check if all pgids are equal or 0. */
446 __ccw_device_get_common_pgid(cdev);
396 break; 447 break;
397 case -ETIME: /* Sense path group id stopped by timeout. */ 448 case -ETIME: /* Sense path group id stopped by timeout. */
398 case -EUSERS: /* device is reserved for someone else. */ 449 case -EUSERS: /* device is reserved for someone else. */
399 ccw_device_done(cdev, DEV_STATE_BOXED); 450 ccw_device_done(cdev, DEV_STATE_BOXED);
400 break; 451 return;
401 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
402 cdev->private->options.pgroup = 0;
403 ccw_device_done(cdev, DEV_STATE_ONLINE);
404 break;
405 default: 452 default:
406 ccw_device_done(cdev, DEV_STATE_NOT_OPER); 453 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
407 break; 454 return;
408 } 455 }
456 /* Start Path Group verification. */
457 sch->vpm = 0; /* Start with no path groups set. */
458 cdev->private->state = DEV_STATE_VERIFY;
459 ccw_device_verify_start(cdev);
409} 460}
410 461
411/* 462/*
@@ -513,12 +564,10 @@ ccw_device_verify_done(struct ccw_device *cdev, int err)
513 /* Deliver fake irb to device driver, if needed. */ 564 /* Deliver fake irb to device driver, if needed. */
514 if (cdev->private->flags.fake_irb) { 565 if (cdev->private->flags.fake_irb) {
515 memset(&cdev->private->irb, 0, sizeof(struct irb)); 566 memset(&cdev->private->irb, 0, sizeof(struct irb));
516 cdev->private->irb.scsw = (struct scsw) { 567 cdev->private->irb.scsw.cc = 1;
517 .cc = 1, 568 cdev->private->irb.scsw.fctl = SCSW_FCTL_START_FUNC;
518 .fctl = SCSW_FCTL_START_FUNC, 569 cdev->private->irb.scsw.actl = SCSW_ACTL_START_PEND;
519 .actl = SCSW_ACTL_START_PEND, 570 cdev->private->irb.scsw.stctl = SCSW_STCTL_STATUS_PEND;
520 .stctl = SCSW_STCTL_STATUS_PEND,
521 };
522 cdev->private->flags.fake_irb = 0; 571 cdev->private->flags.fake_irb = 0;
523 if (cdev->handler) 572 if (cdev->handler)
524 cdev->handler(cdev, cdev->private->intparm, 573 cdev->handler(cdev, cdev->private->intparm,
@@ -562,8 +611,9 @@ ccw_device_online(struct ccw_device *cdev)
562 } 611 }
563 /* Do we want to do path grouping? */ 612 /* Do we want to do path grouping? */
564 if (!cdev->private->options.pgroup) { 613 if (!cdev->private->options.pgroup) {
565 /* No, set state online immediately. */ 614 /* Start initial path verification. */
566 ccw_device_done(cdev, DEV_STATE_ONLINE); 615 cdev->private->state = DEV_STATE_VERIFY;
616 ccw_device_verify_start(cdev);
567 return 0; 617 return 0;
568 } 618 }
569 /* Do a SensePGID first. */ 619 /* Do a SensePGID first. */
@@ -609,6 +659,7 @@ ccw_device_offline(struct ccw_device *cdev)
609 /* Are we doing path grouping? */ 659 /* Are we doing path grouping? */
610 if (!cdev->private->options.pgroup) { 660 if (!cdev->private->options.pgroup) {
611 /* No, set state offline immediately. */ 661 /* No, set state offline immediately. */
662 sch->vpm = 0;
612 ccw_device_done(cdev, DEV_STATE_OFFLINE); 663 ccw_device_done(cdev, DEV_STATE_OFFLINE);
613 return 0; 664 return 0;
614 } 665 }
@@ -705,8 +756,6 @@ ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
705{ 756{
706 struct subchannel *sch; 757 struct subchannel *sch;
707 758
708 if (!cdev->private->options.pgroup)
709 return;
710 if (cdev->private->state == DEV_STATE_W4SENSE) { 759 if (cdev->private->state == DEV_STATE_W4SENSE) {
711 cdev->private->flags.doverify = 1; 760 cdev->private->flags.doverify = 1;
712 return; 761 return;
@@ -719,6 +768,7 @@ ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
719 stsch(sch->schid, &sch->schib); 768 stsch(sch->schid, &sch->schib);
720 769
721 if (sch->schib.scsw.actl != 0 || 770 if (sch->schib.scsw.actl != 0 ||
771 (sch->schib.scsw.stctl & SCSW_STCTL_STATUS_PEND) ||
722 (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) { 772 (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
723 /* 773 /*
724 * No final status yet or final status not yet delivered 774 * No final status yet or final status not yet delivered
@@ -995,8 +1045,7 @@ static void
995ccw_device_wait4io_verify(struct ccw_device *cdev, enum dev_event dev_event) 1045ccw_device_wait4io_verify(struct ccw_device *cdev, enum dev_event dev_event)
996{ 1046{
997 /* When the I/O has terminated, we have to start verification. */ 1047 /* When the I/O has terminated, we have to start verification. */
998 if (cdev->private->options.pgroup) 1048 cdev->private->flags.doverify = 1;
999 cdev->private->flags.doverify = 1;
1000} 1049}
1001 1050
1002static void 1051static void
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index a60124264bee..9e3de0bd59b5 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -263,6 +263,9 @@ ccw_device_wake_up(struct ccw_device *cdev, unsigned long ip, struct irb *irb)
263 /* Abuse intparm for error reporting. */ 263 /* Abuse intparm for error reporting. */
264 if (IS_ERR(irb)) 264 if (IS_ERR(irb))
265 cdev->private->intparm = -EIO; 265 cdev->private->intparm = -EIO;
266 else if (irb->scsw.cc == 1)
267 /* Retry for deferred condition code. */
268 cdev->private->intparm = -EAGAIN;
266 else if ((irb->scsw.dstat != 269 else if ((irb->scsw.dstat !=
267 (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) || 270 (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) ||
268 (irb->scsw.cstat != 0)) { 271 (irb->scsw.cstat != 0)) {
diff --git a/drivers/s390/cio/device_pgid.c b/drivers/s390/cio/device_pgid.c
index 54cb64ed0786..1693a102dcfe 100644
--- a/drivers/s390/cio/device_pgid.c
+++ b/drivers/s390/cio/device_pgid.c
@@ -24,6 +24,21 @@
24#include "ioasm.h" 24#include "ioasm.h"
25 25
26/* 26/*
27 * Helper function called from interrupt context to decide whether an
28 * operation should be tried again.
29 */
30static int __ccw_device_should_retry(struct scsw *scsw)
31{
32 /* CC is only valid if start function bit is set. */
33 if ((scsw->fctl & SCSW_FCTL_START_FUNC) && scsw->cc == 1)
34 return 1;
35 /* No more activity. For sense and set PGID we stubbornly try again. */
36 if (!scsw->actl)
37 return 1;
38 return 0;
39}
40
41/*
27 * Start Sense Path Group ID helper function. Used in ccw_device_recog 42 * Start Sense Path Group ID helper function. Used in ccw_device_recog
28 * and ccw_device_sense_pgid. 43 * and ccw_device_sense_pgid.
29 */ 44 */
@@ -33,12 +48,17 @@ __ccw_device_sense_pgid_start(struct ccw_device *cdev)
33 struct subchannel *sch; 48 struct subchannel *sch;
34 struct ccw1 *ccw; 49 struct ccw1 *ccw;
35 int ret; 50 int ret;
51 int i;
36 52
37 sch = to_subchannel(cdev->dev.parent); 53 sch = to_subchannel(cdev->dev.parent);
54 /* Return if we already checked on all paths. */
55 if (cdev->private->imask == 0)
56 return (sch->lpm == 0) ? -ENODEV : -EACCES;
57 i = 8 - ffs(cdev->private->imask);
58
38 /* Setup sense path group id channel program. */ 59 /* Setup sense path group id channel program. */
39 ccw = cdev->private->iccws; 60 ccw = cdev->private->iccws;
40 ccw->cmd_code = CCW_CMD_SENSE_PGID; 61 ccw->cmd_code = CCW_CMD_SENSE_PGID;
41 ccw->cda = (__u32) __pa (&cdev->private->pgid);
42 ccw->count = sizeof (struct pgid); 62 ccw->count = sizeof (struct pgid);
43 ccw->flags = CCW_FLAG_SLI; 63 ccw->flags = CCW_FLAG_SLI;
44 64
@@ -48,6 +68,7 @@ __ccw_device_sense_pgid_start(struct ccw_device *cdev)
48 ret = -ENODEV; 68 ret = -ENODEV;
49 while (cdev->private->imask != 0) { 69 while (cdev->private->imask != 0) {
50 /* Try every path multiple times. */ 70 /* Try every path multiple times. */
71 ccw->cda = (__u32) __pa (&cdev->private->pgid[i]);
51 if (cdev->private->iretry > 0) { 72 if (cdev->private->iretry > 0) {
52 cdev->private->iretry--; 73 cdev->private->iretry--;
53 ret = cio_start (sch, cdev->private->iccws, 74 ret = cio_start (sch, cdev->private->iccws,
@@ -64,7 +85,9 @@ __ccw_device_sense_pgid_start(struct ccw_device *cdev)
64 } 85 }
65 cdev->private->imask >>= 1; 86 cdev->private->imask >>= 1;
66 cdev->private->iretry = 5; 87 cdev->private->iretry = 5;
88 i++;
67 } 89 }
90
68 return ret; 91 return ret;
69} 92}
70 93
@@ -76,7 +99,7 @@ ccw_device_sense_pgid_start(struct ccw_device *cdev)
76 cdev->private->state = DEV_STATE_SENSE_PGID; 99 cdev->private->state = DEV_STATE_SENSE_PGID;
77 cdev->private->imask = 0x80; 100 cdev->private->imask = 0x80;
78 cdev->private->iretry = 5; 101 cdev->private->iretry = 5;
79 memset (&cdev->private->pgid, 0, sizeof (struct pgid)); 102 memset (&cdev->private->pgid, 0, sizeof (cdev->private->pgid));
80 ret = __ccw_device_sense_pgid_start(cdev); 103 ret = __ccw_device_sense_pgid_start(cdev);
81 if (ret && ret != -EBUSY) 104 if (ret && ret != -EBUSY)
82 ccw_device_sense_pgid_done(cdev, ret); 105 ccw_device_sense_pgid_done(cdev, ret);
@@ -91,6 +114,7 @@ __ccw_device_check_sense_pgid(struct ccw_device *cdev)
91{ 114{
92 struct subchannel *sch; 115 struct subchannel *sch;
93 struct irb *irb; 116 struct irb *irb;
117 int i;
94 118
95 sch = to_subchannel(cdev->dev.parent); 119 sch = to_subchannel(cdev->dev.parent);
96 irb = &cdev->private->irb; 120 irb = &cdev->private->irb;
@@ -124,7 +148,8 @@ __ccw_device_check_sense_pgid(struct ccw_device *cdev)
124 sch->schid.sch_no, sch->orb.lpm); 148 sch->schid.sch_no, sch->orb.lpm);
125 return -EACCES; 149 return -EACCES;
126 } 150 }
127 if (cdev->private->pgid.inf.ps.state2 == SNID_STATE2_RESVD_ELSE) { 151 i = 8 - ffs(cdev->private->imask);
152 if (cdev->private->pgid[i].inf.ps.state2 == SNID_STATE2_RESVD_ELSE) {
128 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel 0.%x.%04x " 153 CIO_MSG_EVENT(2, "SNID - Device %04x on Subchannel 0.%x.%04x "
129 "is reserved by someone else\n", 154 "is reserved by someone else\n",
130 cdev->private->devno, sch->schid.ssid, 155 cdev->private->devno, sch->schid.ssid,
@@ -145,10 +170,10 @@ ccw_device_sense_pgid_irq(struct ccw_device *cdev, enum dev_event dev_event)
145 int ret; 170 int ret;
146 171
147 irb = (struct irb *) __LC_IRB; 172 irb = (struct irb *) __LC_IRB;
148 /* Retry sense pgid for cc=1. */ 173
149 if (irb->scsw.stctl == 174 if (irb->scsw.stctl ==
150 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { 175 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
151 if (irb->scsw.cc == 1) { 176 if (__ccw_device_should_retry(&irb->scsw)) {
152 ret = __ccw_device_sense_pgid_start(cdev); 177 ret = __ccw_device_sense_pgid_start(cdev);
153 if (ret && ret != -EBUSY) 178 if (ret && ret != -EBUSY)
154 ccw_device_sense_pgid_done(cdev, ret); 179 ccw_device_sense_pgid_done(cdev, ret);
@@ -162,12 +187,6 @@ ccw_device_sense_pgid_irq(struct ccw_device *cdev, enum dev_event dev_event)
162 memset(&cdev->private->irb, 0, sizeof(struct irb)); 187 memset(&cdev->private->irb, 0, sizeof(struct irb));
163 switch (ret) { 188 switch (ret) {
164 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN, -EACCES or -EUSERS */ 189 /* 0, -ETIME, -EOPNOTSUPP, -EAGAIN, -EACCES or -EUSERS */
165 case 0: /* Sense Path Group ID successful. */
166 if (cdev->private->pgid.inf.ps.state1 == SNID_STATE1_RESET)
167 memcpy(&cdev->private->pgid, &css[0]->global_pgid,
168 sizeof(struct pgid));
169 ccw_device_sense_pgid_done(cdev, 0);
170 break;
171 case -EOPNOTSUPP: /* Sense Path Group ID not supported */ 190 case -EOPNOTSUPP: /* Sense Path Group ID not supported */
172 ccw_device_sense_pgid_done(cdev, -EOPNOTSUPP); 191 ccw_device_sense_pgid_done(cdev, -EOPNOTSUPP);
173 break; 192 break;
@@ -176,13 +195,15 @@ ccw_device_sense_pgid_irq(struct ccw_device *cdev, enum dev_event dev_event)
176 break; 195 break;
177 case -EACCES: /* channel is not operational. */ 196 case -EACCES: /* channel is not operational. */
178 sch->lpm &= ~cdev->private->imask; 197 sch->lpm &= ~cdev->private->imask;
198 /* Fall through. */
199 case 0: /* Sense Path Group ID successful. */
179 cdev->private->imask >>= 1; 200 cdev->private->imask >>= 1;
180 cdev->private->iretry = 5; 201 cdev->private->iretry = 5;
181 /* Fall through. */ 202 /* Fall through. */
182 case -EAGAIN: /* Try again. */ 203 case -EAGAIN: /* Try again. */
183 ret = __ccw_device_sense_pgid_start(cdev); 204 ret = __ccw_device_sense_pgid_start(cdev);
184 if (ret != 0 && ret != -EBUSY) 205 if (ret != 0 && ret != -EBUSY)
185 ccw_device_sense_pgid_done(cdev, -ENODEV); 206 ccw_device_sense_pgid_done(cdev, ret);
186 break; 207 break;
187 case -EUSERS: /* device is reserved for someone else. */ 208 case -EUSERS: /* device is reserved for someone else. */
188 ccw_device_sense_pgid_done(cdev, -EUSERS); 209 ccw_device_sense_pgid_done(cdev, -EUSERS);
@@ -203,20 +224,20 @@ __ccw_device_do_pgid(struct ccw_device *cdev, __u8 func)
203 sch = to_subchannel(cdev->dev.parent); 224 sch = to_subchannel(cdev->dev.parent);
204 225
205 /* Setup sense path group id channel program. */ 226 /* Setup sense path group id channel program. */
206 cdev->private->pgid.inf.fc = func; 227 cdev->private->pgid[0].inf.fc = func;
207 ccw = cdev->private->iccws; 228 ccw = cdev->private->iccws;
208 if (!cdev->private->flags.pgid_single) { 229 if (!cdev->private->flags.pgid_single) {
209 cdev->private->pgid.inf.fc |= SPID_FUNC_MULTI_PATH; 230 cdev->private->pgid[0].inf.fc |= SPID_FUNC_MULTI_PATH;
210 ccw->cmd_code = CCW_CMD_SUSPEND_RECONN; 231 ccw->cmd_code = CCW_CMD_SUSPEND_RECONN;
211 ccw->cda = 0; 232 ccw->cda = 0;
212 ccw->count = 0; 233 ccw->count = 0;
213 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC; 234 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC;
214 ccw++; 235 ccw++;
215 } else 236 } else
216 cdev->private->pgid.inf.fc |= SPID_FUNC_SINGLE_PATH; 237 cdev->private->pgid[0].inf.fc |= SPID_FUNC_SINGLE_PATH;
217 238
218 ccw->cmd_code = CCW_CMD_SET_PGID; 239 ccw->cmd_code = CCW_CMD_SET_PGID;
219 ccw->cda = (__u32) __pa (&cdev->private->pgid); 240 ccw->cda = (__u32) __pa (&cdev->private->pgid[0]);
220 ccw->count = sizeof (struct pgid); 241 ccw->count = sizeof (struct pgid);
221 ccw->flags = CCW_FLAG_SLI; 242 ccw->flags = CCW_FLAG_SLI;
222 243
@@ -244,6 +265,48 @@ __ccw_device_do_pgid(struct ccw_device *cdev, __u8 func)
244} 265}
245 266
246/* 267/*
268 * Helper function to send a nop ccw down a path.
269 */
270static int __ccw_device_do_nop(struct ccw_device *cdev)
271{
272 struct subchannel *sch;
273 struct ccw1 *ccw;
274 int ret;
275
276 sch = to_subchannel(cdev->dev.parent);
277
278 /* Setup nop channel program. */
279 ccw = cdev->private->iccws;
280 ccw->cmd_code = CCW_CMD_NOOP;
281 ccw->cda = 0;
282 ccw->count = 0;
283 ccw->flags = CCW_FLAG_SLI;
284
285 /* Reset device status. */
286 memset(&cdev->private->irb, 0, sizeof(struct irb));
287
288 /* Try multiple times. */
289 ret = -ENODEV;
290 if (cdev->private->iretry > 0) {
291 cdev->private->iretry--;
292 ret = cio_start (sch, cdev->private->iccws,
293 cdev->private->imask);
294 /* ret is 0, -EBUSY, -EACCES or -ENODEV */
295 if ((ret != -EACCES) && (ret != -ENODEV))
296 return ret;
297 }
298 /* nop command failed on this path. Switch it off. */
299 sch->lpm &= ~cdev->private->imask;
300 sch->vpm &= ~cdev->private->imask;
301 CIO_MSG_EVENT(2, "NOP - Device %04x on Subchannel "
302 "0.%x.%04x, lpm %02X, became 'not operational'\n",
303 cdev->private->devno, sch->schid.ssid,
304 sch->schid.sch_no, cdev->private->imask);
305 return ret;
306}
307
308
309/*
247 * Called from interrupt context to check if a valid answer 310 * Called from interrupt context to check if a valid answer
248 * to Set Path Group ID was received. 311 * to Set Path Group ID was received.
249 */ 312 */
@@ -282,6 +345,29 @@ __ccw_device_check_pgid(struct ccw_device *cdev)
282 return 0; 345 return 0;
283} 346}
284 347
348/*
349 * Called from interrupt context to check the path status after a nop has
350 * been send.
351 */
352static int __ccw_device_check_nop(struct ccw_device *cdev)
353{
354 struct subchannel *sch;
355 struct irb *irb;
356
357 sch = to_subchannel(cdev->dev.parent);
358 irb = &cdev->private->irb;
359 if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC))
360 return -ETIME;
361 if (irb->scsw.cc == 3) {
362 CIO_MSG_EVENT(2, "NOP - Device %04x on Subchannel 0.%x.%04x,"
363 " lpm %02X, became 'not operational'\n",
364 cdev->private->devno, sch->schid.ssid,
365 sch->schid.sch_no, cdev->private->imask);
366 return -EACCES;
367 }
368 return 0;
369}
370
285static void 371static void
286__ccw_device_verify_start(struct ccw_device *cdev) 372__ccw_device_verify_start(struct ccw_device *cdev)
287{ 373{
@@ -296,9 +382,12 @@ __ccw_device_verify_start(struct ccw_device *cdev)
296 if ((sch->vpm & imask) != (sch->lpm & imask)) 382 if ((sch->vpm & imask) != (sch->lpm & imask))
297 break; 383 break;
298 cdev->private->imask = imask; 384 cdev->private->imask = imask;
299 func = (sch->vpm & imask) ? 385 if (cdev->private->options.pgroup) {
300 SPID_FUNC_RESIGN : SPID_FUNC_ESTABLISH; 386 func = (sch->vpm & imask) ?
301 ret = __ccw_device_do_pgid(cdev, func); 387 SPID_FUNC_RESIGN : SPID_FUNC_ESTABLISH;
388 ret = __ccw_device_do_pgid(cdev, func);
389 } else
390 ret = __ccw_device_do_nop(cdev);
302 if (ret == 0 || ret == -EBUSY) 391 if (ret == 0 || ret == -EBUSY)
303 return; 392 return;
304 cdev->private->iretry = 5; 393 cdev->private->iretry = 5;
@@ -317,17 +406,20 @@ ccw_device_verify_irq(struct ccw_device *cdev, enum dev_event dev_event)
317 int ret; 406 int ret;
318 407
319 irb = (struct irb *) __LC_IRB; 408 irb = (struct irb *) __LC_IRB;
320 /* Retry set pgid for cc=1. */ 409
321 if (irb->scsw.stctl == 410 if (irb->scsw.stctl ==
322 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { 411 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
323 if (irb->scsw.cc == 1) 412 if (__ccw_device_should_retry(&irb->scsw))
324 __ccw_device_verify_start(cdev); 413 __ccw_device_verify_start(cdev);
325 return; 414 return;
326 } 415 }
327 if (ccw_device_accumulate_and_sense(cdev, irb) != 0) 416 if (ccw_device_accumulate_and_sense(cdev, irb) != 0)
328 return; 417 return;
329 sch = to_subchannel(cdev->dev.parent); 418 sch = to_subchannel(cdev->dev.parent);
330 ret = __ccw_device_check_pgid(cdev); 419 if (cdev->private->options.pgroup)
420 ret = __ccw_device_check_pgid(cdev);
421 else
422 ret = __ccw_device_check_nop(cdev);
331 memset(&cdev->private->irb, 0, sizeof(struct irb)); 423 memset(&cdev->private->irb, 0, sizeof(struct irb));
332 switch (ret) { 424 switch (ret) {
333 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */ 425 /* 0, -ETIME, -EAGAIN, -EOPNOTSUPP or -EACCES */
@@ -345,11 +437,10 @@ ccw_device_verify_irq(struct ccw_device *cdev, enum dev_event dev_event)
345 * One of those strange devices which claim to be able 437 * One of those strange devices which claim to be able
346 * to do multipathing but not for Set Path Group ID. 438 * to do multipathing but not for Set Path Group ID.
347 */ 439 */
348 if (cdev->private->flags.pgid_single) { 440 if (cdev->private->flags.pgid_single)
349 ccw_device_verify_done(cdev, -EOPNOTSUPP); 441 cdev->private->options.pgroup = 0;
350 break; 442 else
351 } 443 cdev->private->flags.pgid_single = 1;
352 cdev->private->flags.pgid_single = 1;
353 /* fall through. */ 444 /* fall through. */
354 case -EAGAIN: /* Try again. */ 445 case -EAGAIN: /* Try again. */
355 __ccw_device_verify_start(cdev); 446 __ccw_device_verify_start(cdev);
@@ -418,10 +509,10 @@ ccw_device_disband_irq(struct ccw_device *cdev, enum dev_event dev_event)
418 int ret; 509 int ret;
419 510
420 irb = (struct irb *) __LC_IRB; 511 irb = (struct irb *) __LC_IRB;
421 /* Retry set pgid for cc=1. */ 512
422 if (irb->scsw.stctl == 513 if (irb->scsw.stctl ==
423 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { 514 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
424 if (irb->scsw.cc == 1) 515 if (__ccw_device_should_retry(&irb->scsw))
425 __ccw_device_disband_start(cdev); 516 __ccw_device_disband_start(cdev);
426 return; 517 return;
427 } 518 }
diff --git a/drivers/s390/cio/device_status.c b/drivers/s390/cio/device_status.c
index 14bef2c179bf..caf148d5caad 100644
--- a/drivers/s390/cio/device_status.c
+++ b/drivers/s390/cio/device_status.c
@@ -67,8 +67,7 @@ ccw_device_path_notoper(struct ccw_device *cdev)
67 sch->schib.pmcw.pnom); 67 sch->schib.pmcw.pnom);
68 68
69 sch->lpm &= ~sch->schib.pmcw.pnom; 69 sch->lpm &= ~sch->schib.pmcw.pnom;
70 if (cdev->private->options.pgroup) 70 cdev->private->flags.doverify = 1;
71 cdev->private->flags.doverify = 1;
72} 71}
73 72
74/* 73/*
@@ -180,7 +179,7 @@ ccw_device_accumulate_esw(struct ccw_device *cdev, struct irb *irb)
180 cdev_irb->esw.esw0.erw.auth = irb->esw.esw0.erw.auth; 179 cdev_irb->esw.esw0.erw.auth = irb->esw.esw0.erw.auth;
181 /* Copy path verification required flag. */ 180 /* Copy path verification required flag. */
182 cdev_irb->esw.esw0.erw.pvrf = irb->esw.esw0.erw.pvrf; 181 cdev_irb->esw.esw0.erw.pvrf = irb->esw.esw0.erw.pvrf;
183 if (irb->esw.esw0.erw.pvrf && cdev->private->options.pgroup) 182 if (irb->esw.esw0.erw.pvrf)
184 cdev->private->flags.doverify = 1; 183 cdev->private->flags.doverify = 1;
185 /* Copy concurrent sense bit. */ 184 /* Copy concurrent sense bit. */
186 cdev_irb->esw.esw0.erw.cons = irb->esw.esw0.erw.cons; 185 cdev_irb->esw.esw0.erw.cons = irb->esw.esw0.erw.cons;
@@ -354,7 +353,7 @@ ccw_device_accumulate_basic_sense(struct ccw_device *cdev, struct irb *irb)
354 } 353 }
355 /* Check if path verification is required. */ 354 /* Check if path verification is required. */
356 if (ccw_device_accumulate_esw_valid(irb) && 355 if (ccw_device_accumulate_esw_valid(irb) &&
357 irb->esw.esw0.erw.pvrf && cdev->private->options.pgroup) 356 irb->esw.esw0.erw.pvrf)
358 cdev->private->flags.doverify = 1; 357 cdev->private->flags.doverify = 1;
359} 358}
360 359
diff --git a/drivers/s390/cio/qdio.c b/drivers/s390/cio/qdio.c
index b70039af70d6..7c93a8798d23 100644
--- a/drivers/s390/cio/qdio.c
+++ b/drivers/s390/cio/qdio.c
@@ -2735,7 +2735,7 @@ qdio_free(struct ccw_device *cdev)
2735 QDIO_DBF_TEXT1(0,trace,dbf_text); 2735 QDIO_DBF_TEXT1(0,trace,dbf_text);
2736 QDIO_DBF_TEXT0(0,setup,dbf_text); 2736 QDIO_DBF_TEXT0(0,setup,dbf_text);
2737 2737
2738 cdev->private->qdio_data = 0; 2738 cdev->private->qdio_data = NULL;
2739 2739
2740 up(&irq_ptr->setting_up_sema); 2740 up(&irq_ptr->setting_up_sema);
2741 2741
diff --git a/drivers/s390/net/Kconfig b/drivers/s390/net/Kconfig
index 548854754921..1a93fa684e9f 100644
--- a/drivers/s390/net/Kconfig
+++ b/drivers/s390/net/Kconfig
@@ -92,15 +92,6 @@ config QETH_VLAN
92 If CONFIG_QETH is switched on, this option will include IEEE 92 If CONFIG_QETH is switched on, this option will include IEEE
93 802.1q VLAN support in the qeth device driver. 93 802.1q VLAN support in the qeth device driver.
94 94
95config QETH_PERF_STATS
96 bool "Performance statistics in /proc"
97 depends on QETH
98 help
99 When switched on, this option will add a file in the proc-fs
100 (/proc/qeth_perf_stats) containing performance statistics. It
101 may slightly impact performance, so this is only recommended for
102 internal tuning of the device driver.
103
104config CCWGROUP 95config CCWGROUP
105 tristate 96 tristate
106 default (LCS || CTC || QETH) 97 default (LCS || CTC || QETH)
diff --git a/drivers/s390/net/Makefile b/drivers/s390/net/Makefile
index 6775a837d646..4777e36a922f 100644
--- a/drivers/s390/net/Makefile
+++ b/drivers/s390/net/Makefile
@@ -10,7 +10,6 @@ obj-$(CONFIG_SMSGIUCV) += smsgiucv.o
10obj-$(CONFIG_CTC) += ctc.o fsm.o cu3088.o 10obj-$(CONFIG_CTC) += ctc.o fsm.o cu3088.o
11obj-$(CONFIG_LCS) += lcs.o cu3088.o 11obj-$(CONFIG_LCS) += lcs.o cu3088.o
12obj-$(CONFIG_CLAW) += claw.o cu3088.o 12obj-$(CONFIG_CLAW) += claw.o cu3088.o
13obj-$(CONFIG_MPC) += ctcmpc.o fsm.o cu3088.o
14qeth-y := qeth_main.o qeth_mpc.o qeth_sys.o qeth_eddp.o 13qeth-y := qeth_main.o qeth_mpc.o qeth_sys.o qeth_eddp.o
15qeth-$(CONFIG_PROC_FS) += qeth_proc.o 14qeth-$(CONFIG_PROC_FS) += qeth_proc.o
16obj-$(CONFIG_QETH) += qeth.o 15obj-$(CONFIG_QETH) += qeth.o
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index 23d53bf9daf1..95f4e105cb96 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -529,7 +529,7 @@ claw_open(struct net_device *dev)
529 printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__); 529 printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
530#endif 530#endif
531 CLAW_DBF_TEXT(4,trace,"open"); 531 CLAW_DBF_TEXT(4,trace,"open");
532 if (!dev | (dev->name[0] == 0x00)) { 532 if (!dev || (dev->name[0] == 0x00)) {
533 CLAW_DBF_TEXT(2,trace,"BadDev"); 533 CLAW_DBF_TEXT(2,trace,"BadDev");
534 printk(KERN_WARNING "claw: Bad device at open failing \n"); 534 printk(KERN_WARNING "claw: Bad device at open failing \n");
535 return -ENODEV; 535 return -ENODEV;
diff --git a/drivers/s390/net/ctcmain.c b/drivers/s390/net/ctcmain.c
index 20c8eb16f464..3257c22dd79c 100644
--- a/drivers/s390/net/ctcmain.c
+++ b/drivers/s390/net/ctcmain.c
@@ -1714,6 +1714,9 @@ add_channel(struct ccw_device *cdev, enum channel_types type)
1714 kfree(ch); 1714 kfree(ch);
1715 return 0; 1715 return 0;
1716 } 1716 }
1717
1718 spin_lock_init(&ch->collect_lock);
1719
1717 fsm_settimer(ch->fsm, &ch->timer); 1720 fsm_settimer(ch->fsm, &ch->timer);
1718 skb_queue_head_init(&ch->io_queue); 1721 skb_queue_head_init(&ch->io_queue);
1719 skb_queue_head_init(&ch->collect_queue); 1722 skb_queue_head_init(&ch->collect_queue);
@@ -2686,9 +2689,17 @@ static struct attribute_group ctc_attr_group = {
2686static int 2689static int
2687ctc_add_attributes(struct device *dev) 2690ctc_add_attributes(struct device *dev)
2688{ 2691{
2689 device_create_file(dev, &dev_attr_loglevel); 2692 int rc;
2690 device_create_file(dev, &dev_attr_stats); 2693
2691 return 0; 2694 rc = device_create_file(dev, &dev_attr_loglevel);
2695 if (rc)
2696 goto out;
2697 rc = device_create_file(dev, &dev_attr_stats);
2698 if (!rc)
2699 goto out;
2700 device_remove_file(dev, &dev_attr_loglevel);
2701out:
2702 return rc;
2692} 2703}
2693 2704
2694static void 2705static void
@@ -2901,7 +2912,12 @@ ctc_new_device(struct ccwgroup_device *cgdev)
2901 goto out; 2912 goto out;
2902 } 2913 }
2903 2914
2904 ctc_add_attributes(&cgdev->dev); 2915 if (ctc_add_attributes(&cgdev->dev)) {
2916 ctc_netdev_unregister(dev);
2917 dev->priv = NULL;
2918 ctc_free_netdevice(dev, 1);
2919 goto out;
2920 }
2905 2921
2906 strlcpy(privptr->fsm->name, dev->name, sizeof (privptr->fsm->name)); 2922 strlcpy(privptr->fsm->name, dev->name, sizeof (privptr->fsm->name));
2907 2923
diff --git a/drivers/s390/net/iucv.c b/drivers/s390/net/iucv.c
index 189a49275433..821dde86e240 100644
--- a/drivers/s390/net/iucv.c
+++ b/drivers/s390/net/iucv.c
@@ -335,8 +335,8 @@ do { \
335 335
336#else 336#else
337 337
338#define iucv_debug(lvl, fmt, args...) 338#define iucv_debug(lvl, fmt, args...) do { } while (0)
339#define iucv_dumpit(title, buf, len) 339#define iucv_dumpit(title, buf, len) do { } while (0)
340 340
341#endif 341#endif
342 342
@@ -692,7 +692,7 @@ iucv_retrieve_buffer (void)
692 iucv_debug(1, "entering"); 692 iucv_debug(1, "entering");
693 if (iucv_cpuid != -1) { 693 if (iucv_cpuid != -1) {
694 smp_call_function_on(iucv_retrieve_buffer_cpuid, 694 smp_call_function_on(iucv_retrieve_buffer_cpuid,
695 0, 0, 1, iucv_cpuid); 695 NULL, 0, 1, iucv_cpuid);
696 /* Release the cpu reserved by iucv_declare_buffer. */ 696 /* Release the cpu reserved by iucv_declare_buffer. */
697 smp_put_cpu(iucv_cpuid); 697 smp_put_cpu(iucv_cpuid);
698 iucv_cpuid = -1; 698 iucv_cpuid = -1;
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index 2eded55ae88d..16ac68c27a27 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -670,9 +670,8 @@ lcs_ready_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer)
670 int index, rc; 670 int index, rc;
671 671
672 LCS_DBF_TEXT(5, trace, "rdybuff"); 672 LCS_DBF_TEXT(5, trace, "rdybuff");
673 if (buffer->state != BUF_STATE_LOCKED && 673 BUG_ON(buffer->state != BUF_STATE_LOCKED &&
674 buffer->state != BUF_STATE_PROCESSED) 674 buffer->state != BUF_STATE_PROCESSED);
675 BUG();
676 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 675 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
677 buffer->state = BUF_STATE_READY; 676 buffer->state = BUF_STATE_READY;
678 index = buffer - channel->iob; 677 index = buffer - channel->iob;
@@ -696,8 +695,7 @@ __lcs_processed_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer)
696 int index, prev, next; 695 int index, prev, next;
697 696
698 LCS_DBF_TEXT(5, trace, "prcsbuff"); 697 LCS_DBF_TEXT(5, trace, "prcsbuff");
699 if (buffer->state != BUF_STATE_READY) 698 BUG_ON(buffer->state != BUF_STATE_READY);
700 BUG();
701 buffer->state = BUF_STATE_PROCESSED; 699 buffer->state = BUF_STATE_PROCESSED;
702 index = buffer - channel->iob; 700 index = buffer - channel->iob;
703 prev = (index - 1) & (LCS_NUM_BUFFS - 1); 701 prev = (index - 1) & (LCS_NUM_BUFFS - 1);
@@ -729,9 +727,8 @@ lcs_release_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer)
729 unsigned long flags; 727 unsigned long flags;
730 728
731 LCS_DBF_TEXT(5, trace, "relbuff"); 729 LCS_DBF_TEXT(5, trace, "relbuff");
732 if (buffer->state != BUF_STATE_LOCKED && 730 BUG_ON(buffer->state != BUF_STATE_LOCKED &&
733 buffer->state != BUF_STATE_PROCESSED) 731 buffer->state != BUF_STATE_PROCESSED);
734 BUG();
735 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 732 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
736 buffer->state = BUF_STATE_EMPTY; 733 buffer->state = BUF_STATE_EMPTY;
737 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); 734 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index b452cc1afd55..d7d1cc0a5c8e 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -112,7 +112,12 @@ struct iucv_connection {
112/** 112/**
113 * Linked list of all connection structs. 113 * Linked list of all connection structs.
114 */ 114 */
115static struct iucv_connection *iucv_connections; 115struct iucv_connection_struct {
116 struct iucv_connection *iucv_connections;
117 rwlock_t iucv_rwlock;
118};
119
120static struct iucv_connection_struct iucv_conns;
116 121
117/** 122/**
118 * Representation of event-data for the 123 * Representation of event-data for the
@@ -1368,8 +1373,10 @@ user_write (struct device *dev, struct device_attribute *attr, const char *buf,
1368 struct net_device *ndev = priv->conn->netdev; 1373 struct net_device *ndev = priv->conn->netdev;
1369 char *p; 1374 char *p;
1370 char *tmp; 1375 char *tmp;
1371 char username[10]; 1376 char username[9];
1372 int i; 1377 int i;
1378 struct iucv_connection **clist = &iucv_conns.iucv_connections;
1379 unsigned long flags;
1373 1380
1374 IUCV_DBF_TEXT(trace, 3, __FUNCTION__); 1381 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1375 if (count>9) { 1382 if (count>9) {
@@ -1382,7 +1389,7 @@ user_write (struct device *dev, struct device_attribute *attr, const char *buf,
1382 tmp = strsep((char **) &buf, "\n"); 1389 tmp = strsep((char **) &buf, "\n");
1383 for (i=0, p=tmp; i<8 && *p; i++, p++) { 1390 for (i=0, p=tmp; i<8 && *p; i++, p++) {
1384 if (isalnum(*p) || (*p == '$')) 1391 if (isalnum(*p) || (*p == '$'))
1385 username[i]= *p; 1392 username[i]= toupper(*p);
1386 else if (*p == '\n') { 1393 else if (*p == '\n') {
1387 /* trailing lf, grr */ 1394 /* trailing lf, grr */
1388 break; 1395 break;
@@ -1395,11 +1402,11 @@ user_write (struct device *dev, struct device_attribute *attr, const char *buf,
1395 return -EINVAL; 1402 return -EINVAL;
1396 } 1403 }
1397 } 1404 }
1398 while (i<9) 1405 while (i<8)
1399 username[i++] = ' '; 1406 username[i++] = ' ';
1400 username[9] = '\0'; 1407 username[8] = '\0';
1401 1408
1402 if (memcmp(username, priv->conn->userid, 8)) { 1409 if (memcmp(username, priv->conn->userid, 9)) {
1403 /* username changed */ 1410 /* username changed */
1404 if (ndev->flags & (IFF_UP | IFF_RUNNING)) { 1411 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
1405 PRINT_WARN( 1412 PRINT_WARN(
@@ -1410,6 +1417,19 @@ user_write (struct device *dev, struct device_attribute *attr, const char *buf,
1410 return -EBUSY; 1417 return -EBUSY;
1411 } 1418 }
1412 } 1419 }
1420 read_lock_irqsave(&iucv_conns.iucv_rwlock, flags);
1421 while (*clist) {
1422 if (!strncmp(username, (*clist)->userid, 9) ||
1423 ((*clist)->netdev != ndev))
1424 break;
1425 clist = &((*clist)->next);
1426 }
1427 read_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
1428 if (*clist) {
1429 PRINT_WARN("netiucv: Connection to %s already exists\n",
1430 username);
1431 return -EEXIST;
1432 }
1413 memcpy(priv->conn->userid, username, 9); 1433 memcpy(priv->conn->userid, username, 9);
1414 1434
1415 return count; 1435 return count;
@@ -1781,13 +1801,15 @@ netiucv_unregister_device(struct device *dev)
1781static struct iucv_connection * 1801static struct iucv_connection *
1782netiucv_new_connection(struct net_device *dev, char *username) 1802netiucv_new_connection(struct net_device *dev, char *username)
1783{ 1803{
1784 struct iucv_connection **clist = &iucv_connections; 1804 unsigned long flags;
1805 struct iucv_connection **clist = &iucv_conns.iucv_connections;
1785 struct iucv_connection *conn = 1806 struct iucv_connection *conn =
1786 kzalloc(sizeof(struct iucv_connection), GFP_KERNEL); 1807 kzalloc(sizeof(struct iucv_connection), GFP_KERNEL);
1787 1808
1788 if (conn) { 1809 if (conn) {
1789 skb_queue_head_init(&conn->collect_queue); 1810 skb_queue_head_init(&conn->collect_queue);
1790 skb_queue_head_init(&conn->commit_queue); 1811 skb_queue_head_init(&conn->commit_queue);
1812 spin_lock_init(&conn->collect_lock);
1791 conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT; 1813 conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT;
1792 conn->netdev = dev; 1814 conn->netdev = dev;
1793 1815
@@ -1822,8 +1844,10 @@ netiucv_new_connection(struct net_device *dev, char *username)
1822 fsm_newstate(conn->fsm, CONN_STATE_STOPPED); 1844 fsm_newstate(conn->fsm, CONN_STATE_STOPPED);
1823 } 1845 }
1824 1846
1847 write_lock_irqsave(&iucv_conns.iucv_rwlock, flags);
1825 conn->next = *clist; 1848 conn->next = *clist;
1826 *clist = conn; 1849 *clist = conn;
1850 write_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
1827 } 1851 }
1828 return conn; 1852 return conn;
1829} 1853}
@@ -1835,14 +1859,17 @@ netiucv_new_connection(struct net_device *dev, char *username)
1835static void 1859static void
1836netiucv_remove_connection(struct iucv_connection *conn) 1860netiucv_remove_connection(struct iucv_connection *conn)
1837{ 1861{
1838 struct iucv_connection **clist = &iucv_connections; 1862 struct iucv_connection **clist = &iucv_conns.iucv_connections;
1863 unsigned long flags;
1839 1864
1840 IUCV_DBF_TEXT(trace, 3, __FUNCTION__); 1865 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1841 if (conn == NULL) 1866 if (conn == NULL)
1842 return; 1867 return;
1868 write_lock_irqsave(&iucv_conns.iucv_rwlock, flags);
1843 while (*clist) { 1869 while (*clist) {
1844 if (*clist == conn) { 1870 if (*clist == conn) {
1845 *clist = conn->next; 1871 *clist = conn->next;
1872 write_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
1846 if (conn->handle) { 1873 if (conn->handle) {
1847 iucv_unregister_program(conn->handle); 1874 iucv_unregister_program(conn->handle);
1848 conn->handle = NULL; 1875 conn->handle = NULL;
@@ -1855,6 +1882,7 @@ netiucv_remove_connection(struct iucv_connection *conn)
1855 } 1882 }
1856 clist = &((*clist)->next); 1883 clist = &((*clist)->next);
1857 } 1884 }
1885 write_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
1858} 1886}
1859 1887
1860/** 1888/**
@@ -1947,9 +1975,11 @@ static ssize_t
1947conn_write(struct device_driver *drv, const char *buf, size_t count) 1975conn_write(struct device_driver *drv, const char *buf, size_t count)
1948{ 1976{
1949 char *p; 1977 char *p;
1950 char username[10]; 1978 char username[9];
1951 int i, ret; 1979 int i, ret;
1952 struct net_device *dev; 1980 struct net_device *dev;
1981 struct iucv_connection **clist = &iucv_conns.iucv_connections;
1982 unsigned long flags;
1953 1983
1954 IUCV_DBF_TEXT(trace, 3, __FUNCTION__); 1984 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1955 if (count>9) { 1985 if (count>9) {
@@ -1960,7 +1990,7 @@ conn_write(struct device_driver *drv, const char *buf, size_t count)
1960 1990
1961 for (i=0, p=(char *)buf; i<8 && *p; i++, p++) { 1991 for (i=0, p=(char *)buf; i<8 && *p; i++, p++) {
1962 if (isalnum(*p) || (*p == '$')) 1992 if (isalnum(*p) || (*p == '$'))
1963 username[i]= *p; 1993 username[i]= toupper(*p);
1964 else if (*p == '\n') { 1994 else if (*p == '\n') {
1965 /* trailing lf, grr */ 1995 /* trailing lf, grr */
1966 break; 1996 break;
@@ -1971,9 +2001,22 @@ conn_write(struct device_driver *drv, const char *buf, size_t count)
1971 return -EINVAL; 2001 return -EINVAL;
1972 } 2002 }
1973 } 2003 }
1974 while (i<9) 2004 while (i<8)
1975 username[i++] = ' '; 2005 username[i++] = ' ';
1976 username[9] = '\0'; 2006 username[8] = '\0';
2007
2008 read_lock_irqsave(&iucv_conns.iucv_rwlock, flags);
2009 while (*clist) {
2010 if (!strncmp(username, (*clist)->userid, 9))
2011 break;
2012 clist = &((*clist)->next);
2013 }
2014 read_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
2015 if (*clist) {
2016 PRINT_WARN("netiucv: Connection to %s already exists\n",
2017 username);
2018 return -EEXIST;
2019 }
1977 dev = netiucv_init_netdevice(username); 2020 dev = netiucv_init_netdevice(username);
1978 if (!dev) { 2021 if (!dev) {
1979 PRINT_WARN( 2022 PRINT_WARN(
@@ -2015,7 +2058,8 @@ DRIVER_ATTR(connection, 0200, NULL, conn_write);
2015static ssize_t 2058static ssize_t
2016remove_write (struct device_driver *drv, const char *buf, size_t count) 2059remove_write (struct device_driver *drv, const char *buf, size_t count)
2017{ 2060{
2018 struct iucv_connection **clist = &iucv_connections; 2061 struct iucv_connection **clist = &iucv_conns.iucv_connections;
2062 unsigned long flags;
2019 struct net_device *ndev; 2063 struct net_device *ndev;
2020 struct netiucv_priv *priv; 2064 struct netiucv_priv *priv;
2021 struct device *dev; 2065 struct device *dev;
@@ -2026,10 +2070,10 @@ remove_write (struct device_driver *drv, const char *buf, size_t count)
2026 IUCV_DBF_TEXT(trace, 3, __FUNCTION__); 2070 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
2027 2071
2028 if (count >= IFNAMSIZ) 2072 if (count >= IFNAMSIZ)
2029 count = IFNAMSIZ-1; 2073 count = IFNAMSIZ - 1;;
2030 2074
2031 for (i=0, p=(char *)buf; i<count && *p; i++, p++) { 2075 for (i=0, p=(char *)buf; i<count && *p; i++, p++) {
2032 if ((*p == '\n') | (*p == ' ')) { 2076 if ((*p == '\n') || (*p == ' ')) {
2033 /* trailing lf, grr */ 2077 /* trailing lf, grr */
2034 break; 2078 break;
2035 } else { 2079 } else {
@@ -2038,6 +2082,7 @@ remove_write (struct device_driver *drv, const char *buf, size_t count)
2038 } 2082 }
2039 name[i] = '\0'; 2083 name[i] = '\0';
2040 2084
2085 read_lock_irqsave(&iucv_conns.iucv_rwlock, flags);
2041 while (*clist) { 2086 while (*clist) {
2042 ndev = (*clist)->netdev; 2087 ndev = (*clist)->netdev;
2043 priv = (struct netiucv_priv*)ndev->priv; 2088 priv = (struct netiucv_priv*)ndev->priv;
@@ -2047,6 +2092,7 @@ remove_write (struct device_driver *drv, const char *buf, size_t count)
2047 clist = &((*clist)->next); 2092 clist = &((*clist)->next);
2048 continue; 2093 continue;
2049 } 2094 }
2095 read_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
2050 if (ndev->flags & (IFF_UP | IFF_RUNNING)) { 2096 if (ndev->flags & (IFF_UP | IFF_RUNNING)) {
2051 PRINT_WARN( 2097 PRINT_WARN(
2052 "netiucv: net device %s active with peer %s\n", 2098 "netiucv: net device %s active with peer %s\n",
@@ -2060,6 +2106,7 @@ remove_write (struct device_driver *drv, const char *buf, size_t count)
2060 netiucv_unregister_device(dev); 2106 netiucv_unregister_device(dev);
2061 return count; 2107 return count;
2062 } 2108 }
2109 read_unlock_irqrestore(&iucv_conns.iucv_rwlock, flags);
2063 PRINT_WARN("netiucv: net device %s unknown\n", name); 2110 PRINT_WARN("netiucv: net device %s unknown\n", name);
2064 IUCV_DBF_TEXT(data, 2, "remove_write: unknown device\n"); 2111 IUCV_DBF_TEXT(data, 2, "remove_write: unknown device\n");
2065 return -EINVAL; 2112 return -EINVAL;
@@ -2077,8 +2124,8 @@ static void __exit
2077netiucv_exit(void) 2124netiucv_exit(void)
2078{ 2125{
2079 IUCV_DBF_TEXT(trace, 3, __FUNCTION__); 2126 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
2080 while (iucv_connections) { 2127 while (iucv_conns.iucv_connections) {
2081 struct net_device *ndev = iucv_connections->netdev; 2128 struct net_device *ndev = iucv_conns.iucv_connections->netdev;
2082 struct netiucv_priv *priv = (struct netiucv_priv*)ndev->priv; 2129 struct netiucv_priv *priv = (struct netiucv_priv*)ndev->priv;
2083 struct device *dev = priv->dev; 2130 struct device *dev = priv->dev;
2084 2131
@@ -2120,6 +2167,7 @@ netiucv_init(void)
2120 if (!ret) { 2167 if (!ret) {
2121 ret = driver_create_file(&netiucv_driver, &driver_attr_remove); 2168 ret = driver_create_file(&netiucv_driver, &driver_attr_remove);
2122 netiucv_banner(); 2169 netiucv_banner();
2170 rwlock_init(&iucv_conns.iucv_rwlock);
2123 } else { 2171 } else {
2124 PRINT_ERR("NETIUCV: failed to add driver attribute.\n"); 2172 PRINT_ERR("NETIUCV: failed to add driver attribute.\n");
2125 IUCV_DBF_TEXT_(setup, 2, "ret %d from driver_create_file\n", ret); 2173 IUCV_DBF_TEXT_(setup, 2, "ret %d from driver_create_file\n", ret);
diff --git a/drivers/s390/net/qeth.h b/drivers/s390/net/qeth.h
index 619f4a0c7160..821383d8cbe7 100644
--- a/drivers/s390/net/qeth.h
+++ b/drivers/s390/net/qeth.h
@@ -176,7 +176,6 @@ extern struct ccwgroup_driver qeth_ccwgroup_driver;
176/** 176/**
177 * card stuff 177 * card stuff
178 */ 178 */
179#ifdef CONFIG_QETH_PERF_STATS
180struct qeth_perf_stats { 179struct qeth_perf_stats {
181 unsigned int bufs_rec; 180 unsigned int bufs_rec;
182 unsigned int bufs_sent; 181 unsigned int bufs_sent;
@@ -211,8 +210,10 @@ struct qeth_perf_stats {
211 unsigned int large_send_cnt; 210 unsigned int large_send_cnt;
212 unsigned int sg_skbs_sent; 211 unsigned int sg_skbs_sent;
213 unsigned int sg_frags_sent; 212 unsigned int sg_frags_sent;
213 /* initial values when measuring starts */
214 unsigned long initial_rx_packets;
215 unsigned long initial_tx_packets;
214}; 216};
215#endif /* CONFIG_QETH_PERF_STATS */
216 217
217/* Routing stuff */ 218/* Routing stuff */
218struct qeth_routing_info { 219struct qeth_routing_info {
@@ -462,6 +463,7 @@ enum qeth_qdio_info_states {
462 QETH_QDIO_UNINITIALIZED, 463 QETH_QDIO_UNINITIALIZED,
463 QETH_QDIO_ALLOCATED, 464 QETH_QDIO_ALLOCATED,
464 QETH_QDIO_ESTABLISHED, 465 QETH_QDIO_ESTABLISHED,
466 QETH_QDIO_CLEANING
465}; 467};
466 468
467struct qeth_buffer_pool_entry { 469struct qeth_buffer_pool_entry {
@@ -536,7 +538,7 @@ struct qeth_qdio_out_q {
536} __attribute__ ((aligned(256))); 538} __attribute__ ((aligned(256)));
537 539
538struct qeth_qdio_info { 540struct qeth_qdio_info {
539 volatile enum qeth_qdio_info_states state; 541 atomic_t state;
540 /* input */ 542 /* input */
541 struct qeth_qdio_q *in_q; 543 struct qeth_qdio_q *in_q;
542 struct qeth_qdio_buffer_pool in_buf_pool; 544 struct qeth_qdio_buffer_pool in_buf_pool;
@@ -767,6 +769,7 @@ struct qeth_card_options {
767 int fake_ll; 769 int fake_ll;
768 int layer2; 770 int layer2;
769 enum qeth_large_send_types large_send; 771 enum qeth_large_send_types large_send;
772 int performance_stats;
770}; 773};
771 774
772/* 775/*
@@ -819,9 +822,7 @@ struct qeth_card {
819 struct list_head cmd_waiter_list; 822 struct list_head cmd_waiter_list;
820 /* QDIO buffer handling */ 823 /* QDIO buffer handling */
821 struct qeth_qdio_info qdio; 824 struct qeth_qdio_info qdio;
822#ifdef CONFIG_QETH_PERF_STATS
823 struct qeth_perf_stats perf_stats; 825 struct qeth_perf_stats perf_stats;
824#endif /* CONFIG_QETH_PERF_STATS */
825 int use_hard_stop; 826 int use_hard_stop;
826 int (*orig_hard_header)(struct sk_buff *,struct net_device *, 827 int (*orig_hard_header)(struct sk_buff *,struct net_device *,
827 unsigned short,void *,void *,unsigned); 828 unsigned short,void *,void *,unsigned);
@@ -859,23 +860,18 @@ qeth_get_ipa_adp_type(enum qeth_link_types link_type)
859 } 860 }
860} 861}
861 862
862static inline int 863static inline struct sk_buff *
863qeth_realloc_headroom(struct qeth_card *card, struct sk_buff **skb, int size) 864qeth_realloc_headroom(struct qeth_card *card, struct sk_buff *skb, int size)
864{ 865{
865 struct sk_buff *new_skb = NULL; 866 struct sk_buff *new_skb = skb;
866 867
867 if (skb_headroom(*skb) < size){ 868 if (skb_headroom(skb) >= size)
868 new_skb = skb_realloc_headroom(*skb, size); 869 return skb;
869 if (!new_skb) { 870 new_skb = skb_realloc_headroom(skb, size);
870 PRINT_ERR("qeth_prepare_skb: could " 871 if (!new_skb)
871 "not realloc headroom for qeth_hdr " 872 PRINT_ERR("Could not realloc headroom for qeth_hdr "
872 "on interface %s", QETH_CARD_IFNAME(card)); 873 "on interface %s", QETH_CARD_IFNAME(card));
873 return -ENOMEM; 874 return new_skb;
874 }
875 kfree_skb(*skb);
876 *skb = new_skb;
877 }
878 return 0;
879} 875}
880 876
881static inline struct sk_buff * 877static inline struct sk_buff *
@@ -885,16 +881,15 @@ qeth_pskb_unshare(struct sk_buff *skb, int pri)
885 if (!skb_cloned(skb)) 881 if (!skb_cloned(skb))
886 return skb; 882 return skb;
887 nskb = skb_copy(skb, pri); 883 nskb = skb_copy(skb, pri);
888 kfree_skb(skb); /* free our shared copy */
889 return nskb; 884 return nskb;
890} 885}
891 886
892static inline void * 887static inline void *
893qeth_push_skb(struct qeth_card *card, struct sk_buff **skb, int size) 888qeth_push_skb(struct qeth_card *card, struct sk_buff *skb, int size)
894{ 889{
895 void *hdr; 890 void *hdr;
896 891
897 hdr = (void *) skb_push(*skb, size); 892 hdr = (void *) skb_push(skb, size);
898 /* 893 /*
899 * sanity check, the Linux memory allocation scheme should 894 * sanity check, the Linux memory allocation scheme should
900 * never present us cases like this one (the qdio header size plus 895 * never present us cases like this one (the qdio header size plus
@@ -903,8 +898,7 @@ qeth_push_skb(struct qeth_card *card, struct sk_buff **skb, int size)
903 if ((((unsigned long) hdr) & (~(PAGE_SIZE - 1))) != 898 if ((((unsigned long) hdr) & (~(PAGE_SIZE - 1))) !=
904 (((unsigned long) hdr + size + 899 (((unsigned long) hdr + size +
905 QETH_IP_HEADER_SIZE) & (~(PAGE_SIZE - 1)))) { 900 QETH_IP_HEADER_SIZE) & (~(PAGE_SIZE - 1)))) {
906 PRINT_ERR("qeth_prepare_skb: misaligned " 901 PRINT_ERR("Misaligned packet on interface %s. Discarded.",
907 "packet on interface %s. Discarded.",
908 QETH_CARD_IFNAME(card)); 902 QETH_CARD_IFNAME(card));
909 return NULL; 903 return NULL;
910 } 904 }
@@ -1056,13 +1050,11 @@ qeth_get_arphdr_type(int cardtype, int linktype)
1056 } 1050 }
1057} 1051}
1058 1052
1059#ifdef CONFIG_QETH_PERF_STATS
1060static inline int 1053static inline int
1061qeth_get_micros(void) 1054qeth_get_micros(void)
1062{ 1055{
1063 return (int) (get_clock() >> 12); 1056 return (int) (get_clock() >> 12);
1064} 1057}
1065#endif
1066 1058
1067static inline int 1059static inline int
1068qeth_get_qdio_q_format(struct qeth_card *card) 1060qeth_get_qdio_q_format(struct qeth_card *card)
@@ -1096,10 +1088,11 @@ qeth_string_to_ipaddr4(const char *buf, __u8 *addr)
1096{ 1088{
1097 int count = 0, rc = 0; 1089 int count = 0, rc = 0;
1098 int in[4]; 1090 int in[4];
1091 char c;
1099 1092
1100 rc = sscanf(buf, "%d.%d.%d.%d%n", 1093 rc = sscanf(buf, "%u.%u.%u.%u%c",
1101 &in[0], &in[1], &in[2], &in[3], &count); 1094 &in[0], &in[1], &in[2], &in[3], &c);
1102 if (rc != 4 || count<=0) 1095 if (rc != 4 && (rc != 5 || c != '\n'))
1103 return -EINVAL; 1096 return -EINVAL;
1104 for (count = 0; count < 4; count++) { 1097 for (count = 0; count < 4; count++) {
1105 if (in[count] > 255) 1098 if (in[count] > 255)
@@ -1123,24 +1116,28 @@ qeth_ipaddr6_to_string(const __u8 *addr, char *buf)
1123static inline int 1116static inline int
1124qeth_string_to_ipaddr6(const char *buf, __u8 *addr) 1117qeth_string_to_ipaddr6(const char *buf, __u8 *addr)
1125{ 1118{
1126 char *end, *start; 1119 const char *end, *end_tmp, *start;
1127 __u16 *in; 1120 __u16 *in;
1128 char num[5]; 1121 char num[5];
1129 int num2, cnt, out, found, save_cnt; 1122 int num2, cnt, out, found, save_cnt;
1130 unsigned short in_tmp[8] = {0, }; 1123 unsigned short in_tmp[8] = {0, };
1131 1124
1132 cnt = out = found = save_cnt = num2 = 0; 1125 cnt = out = found = save_cnt = num2 = 0;
1133 end = start = (char *) buf; 1126 end = start = buf;
1134 in = (__u16 *) addr; 1127 in = (__u16 *) addr;
1135 memset(in, 0, 16); 1128 memset(in, 0, 16);
1136 while (end) { 1129 while (*end) {
1137 end = strchr(end,':'); 1130 end = strchr(start,':');
1138 if (end == NULL) { 1131 if (end == NULL) {
1139 end = (char *)buf + (strlen(buf)); 1132 end = buf + strlen(buf);
1140 out = 1; 1133 if ((end_tmp = strchr(start, '\n')) != NULL)
1134 end = end_tmp;
1135 out = 1;
1141 } 1136 }
1142 if ((end - start)) { 1137 if ((end - start)) {
1143 memset(num, 0, 5); 1138 memset(num, 0, 5);
1139 if ((end - start) > 4)
1140 return -EINVAL;
1144 memcpy(num, start, end - start); 1141 memcpy(num, start, end - start);
1145 if (!qeth_isxdigit(num)) 1142 if (!qeth_isxdigit(num))
1146 return -EINVAL; 1143 return -EINVAL;
@@ -1158,6 +1155,8 @@ qeth_string_to_ipaddr6(const char *buf, __u8 *addr)
1158 } 1155 }
1159 start = ++end; 1156 start = ++end;
1160 } 1157 }
1158 if (cnt + save_cnt > 8)
1159 return -EINVAL;
1161 cnt = 7; 1160 cnt = 7;
1162 while (save_cnt) 1161 while (save_cnt)
1163 in[cnt--] = in_tmp[--save_cnt]; 1162 in[cnt--] = in_tmp[--save_cnt];
diff --git a/drivers/s390/net/qeth_eddp.c b/drivers/s390/net/qeth_eddp.c
index 8491598f9149..a363721cf28d 100644
--- a/drivers/s390/net/qeth_eddp.c
+++ b/drivers/s390/net/qeth_eddp.c
@@ -179,9 +179,8 @@ out_check:
179 flush_cnt++; 179 flush_cnt++;
180 } 180 }
181 } else { 181 } else {
182#ifdef CONFIG_QETH_PERF_STATS 182 if (queue->card->options.performance_stats)
183 queue->card->perf_stats.skbs_sent_pack++; 183 queue->card->perf_stats.skbs_sent_pack++;
184#endif
185 QETH_DBF_TEXT(trace, 6, "fillbfpa"); 184 QETH_DBF_TEXT(trace, 6, "fillbfpa");
186 if (buf->next_element_to_fill >= 185 if (buf->next_element_to_fill >=
187 QETH_MAX_BUFFER_ELEMENTS(queue->card)) { 186 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
diff --git a/drivers/s390/net/qeth_main.c b/drivers/s390/net/qeth_main.c
index 36733b9823c6..5613b4564fa2 100644
--- a/drivers/s390/net/qeth_main.c
+++ b/drivers/s390/net/qeth_main.c
@@ -84,6 +84,8 @@ static debug_info_t *qeth_dbf_qerr = NULL;
84 84
85DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf); 85DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf);
86 86
87static struct lock_class_key qdio_out_skb_queue_key;
88
87/** 89/**
88 * some more definitions and declarations 90 * some more definitions and declarations
89 */ 91 */
@@ -1071,6 +1073,7 @@ qeth_set_intial_options(struct qeth_card *card)
1071 card->options.layer2 = 1; 1073 card->options.layer2 = 1;
1072 else 1074 else
1073 card->options.layer2 = 0; 1075 card->options.layer2 = 0;
1076 card->options.performance_stats = 1;
1074} 1077}
1075 1078
1076/** 1079/**
@@ -1706,6 +1709,7 @@ qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1706 "IP address reset.\n", 1709 "IP address reset.\n",
1707 QETH_CARD_IFNAME(card), 1710 QETH_CARD_IFNAME(card),
1708 card->info.chpid); 1711 card->info.chpid);
1712 netif_carrier_on(card->dev);
1709 qeth_schedule_recovery(card); 1713 qeth_schedule_recovery(card);
1710 return NULL; 1714 return NULL;
1711 case IPA_CMD_MODCCID: 1715 case IPA_CMD_MODCCID:
@@ -2462,24 +2466,6 @@ qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb,
2462 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr); 2466 qeth_rebuild_skb_fake_ll_eth(card, skb, hdr);
2463} 2467}
2464 2468
2465static inline void
2466qeth_rebuild_skb_vlan(struct qeth_card *card, struct sk_buff *skb,
2467 struct qeth_hdr *hdr)
2468{
2469#ifdef CONFIG_QETH_VLAN
2470 u16 *vlan_tag;
2471
2472 if (hdr->hdr.l3.ext_flags &
2473 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2474 vlan_tag = (u16 *) skb_push(skb, VLAN_HLEN);
2475 *vlan_tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2476 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2477 *(vlan_tag + 1) = skb->protocol;
2478 skb->protocol = __constant_htons(ETH_P_8021Q);
2479 }
2480#endif /* CONFIG_QETH_VLAN */
2481}
2482
2483static inline __u16 2469static inline __u16
2484qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb, 2470qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2485 struct qeth_hdr *hdr) 2471 struct qeth_hdr *hdr)
@@ -2508,15 +2494,16 @@ qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2508 return vlan_id; 2494 return vlan_id;
2509} 2495}
2510 2496
2511static inline void 2497static inline __u16
2512qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb, 2498qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2513 struct qeth_hdr *hdr) 2499 struct qeth_hdr *hdr)
2514{ 2500{
2501 unsigned short vlan_id = 0;
2515#ifdef CONFIG_QETH_IPV6 2502#ifdef CONFIG_QETH_IPV6
2516 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) { 2503 if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) {
2517 skb->pkt_type = PACKET_HOST; 2504 skb->pkt_type = PACKET_HOST;
2518 skb->protocol = qeth_type_trans(skb, card->dev); 2505 skb->protocol = qeth_type_trans(skb, card->dev);
2519 return; 2506 return 0;
2520 } 2507 }
2521#endif /* CONFIG_QETH_IPV6 */ 2508#endif /* CONFIG_QETH_IPV6 */
2522 skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 : 2509 skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
@@ -2538,7 +2525,13 @@ qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2538 default: 2525 default:
2539 skb->pkt_type = PACKET_HOST; 2526 skb->pkt_type = PACKET_HOST;
2540 } 2527 }
2541 qeth_rebuild_skb_vlan(card, skb, hdr); 2528
2529 if (hdr->hdr.l3.ext_flags &
2530 (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
2531 vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)?
2532 hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
2533 }
2534
2542 if (card->options.fake_ll) 2535 if (card->options.fake_ll)
2543 qeth_rebuild_skb_fake_ll(card, skb, hdr); 2536 qeth_rebuild_skb_fake_ll(card, skb, hdr);
2544 else 2537 else
@@ -2554,6 +2547,7 @@ qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
2554 else 2547 else
2555 skb->ip_summed = SW_CHECKSUMMING; 2548 skb->ip_summed = SW_CHECKSUMMING;
2556 } 2549 }
2550 return vlan_id;
2557} 2551}
2558 2552
2559static inline void 2553static inline void
@@ -2566,20 +2560,20 @@ qeth_process_inbound_buffer(struct qeth_card *card,
2566 int offset; 2560 int offset;
2567 int rxrc; 2561 int rxrc;
2568 __u16 vlan_tag = 0; 2562 __u16 vlan_tag = 0;
2563 __u16 *vlan_addr;
2569 2564
2570 /* get first element of current buffer */ 2565 /* get first element of current buffer */
2571 element = (struct qdio_buffer_element *)&buf->buffer->element[0]; 2566 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
2572 offset = 0; 2567 offset = 0;
2573#ifdef CONFIG_QETH_PERF_STATS 2568 if (card->options.performance_stats)
2574 card->perf_stats.bufs_rec++; 2569 card->perf_stats.bufs_rec++;
2575#endif
2576 while((skb = qeth_get_next_skb(card, buf->buffer, &element, 2570 while((skb = qeth_get_next_skb(card, buf->buffer, &element,
2577 &offset, &hdr))) { 2571 &offset, &hdr))) {
2578 skb->dev = card->dev; 2572 skb->dev = card->dev;
2579 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2) 2573 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
2580 vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr); 2574 vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr);
2581 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3) 2575 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3)
2582 qeth_rebuild_skb(card, skb, hdr); 2576 vlan_tag = qeth_rebuild_skb(card, skb, hdr);
2583 else { /*in case of OSN*/ 2577 else { /*in case of OSN*/
2584 skb_push(skb, sizeof(struct qeth_hdr)); 2578 skb_push(skb, sizeof(struct qeth_hdr));
2585 memcpy(skb->data, hdr, sizeof(struct qeth_hdr)); 2579 memcpy(skb->data, hdr, sizeof(struct qeth_hdr));
@@ -2589,14 +2583,19 @@ qeth_process_inbound_buffer(struct qeth_card *card,
2589 dev_kfree_skb_any(skb); 2583 dev_kfree_skb_any(skb);
2590 continue; 2584 continue;
2591 } 2585 }
2586 if (card->info.type == QETH_CARD_TYPE_OSN)
2587 rxrc = card->osn_info.data_cb(skb);
2588 else
2592#ifdef CONFIG_QETH_VLAN 2589#ifdef CONFIG_QETH_VLAN
2593 if (vlan_tag) 2590 if (vlan_tag)
2594 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag); 2591 if (card->vlangrp)
2592 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag);
2593 else {
2594 dev_kfree_skb_any(skb);
2595 continue;
2596 }
2595 else 2597 else
2596#endif 2598#endif
2597 if (card->info.type == QETH_CARD_TYPE_OSN)
2598 rxrc = card->osn_info.data_cb(skb);
2599 else
2600 rxrc = netif_rx(skb); 2599 rxrc = netif_rx(skb);
2601 card->dev->last_rx = jiffies; 2600 card->dev->last_rx = jiffies;
2602 card->stats.rx_packets++; 2601 card->stats.rx_packets++;
@@ -2624,7 +2623,7 @@ qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf)
2624{ 2623{
2625 struct qeth_buffer_pool_entry *pool_entry; 2624 struct qeth_buffer_pool_entry *pool_entry;
2626 int i; 2625 int i;
2627 2626
2628 pool_entry = qeth_get_buffer_pool_entry(card); 2627 pool_entry = qeth_get_buffer_pool_entry(card);
2629 /* 2628 /*
2630 * since the buffer is accessed only from the input_tasklet 2629 * since the buffer is accessed only from the input_tasklet
@@ -2698,17 +2697,18 @@ qeth_queue_input_buffer(struct qeth_card *card, int index)
2698 * 'index') un-requeued -> this buffer is the first buffer that 2697 * 'index') un-requeued -> this buffer is the first buffer that
2699 * will be requeued the next time 2698 * will be requeued the next time
2700 */ 2699 */
2701#ifdef CONFIG_QETH_PERF_STATS 2700 if (card->options.performance_stats) {
2702 card->perf_stats.inbound_do_qdio_cnt++; 2701 card->perf_stats.inbound_do_qdio_cnt++;
2703 card->perf_stats.inbound_do_qdio_start_time = qeth_get_micros(); 2702 card->perf_stats.inbound_do_qdio_start_time =
2704#endif 2703 qeth_get_micros();
2704 }
2705 rc = do_QDIO(CARD_DDEV(card), 2705 rc = do_QDIO(CARD_DDEV(card),
2706 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT, 2706 QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT,
2707 0, queue->next_buf_to_init, count, NULL); 2707 0, queue->next_buf_to_init, count, NULL);
2708#ifdef CONFIG_QETH_PERF_STATS 2708 if (card->options.performance_stats)
2709 card->perf_stats.inbound_do_qdio_time += qeth_get_micros() - 2709 card->perf_stats.inbound_do_qdio_time +=
2710 card->perf_stats.inbound_do_qdio_start_time; 2710 qeth_get_micros() -
2711#endif 2711 card->perf_stats.inbound_do_qdio_start_time;
2712 if (rc){ 2712 if (rc){
2713 PRINT_WARN("qeth_queue_input_buffer's do_QDIO " 2713 PRINT_WARN("qeth_queue_input_buffer's do_QDIO "
2714 "return %i (device %s).\n", 2714 "return %i (device %s).\n",
@@ -2744,10 +2744,10 @@ qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status,
2744 QETH_DBF_TEXT(trace, 6, "qdinput"); 2744 QETH_DBF_TEXT(trace, 6, "qdinput");
2745 card = (struct qeth_card *) card_ptr; 2745 card = (struct qeth_card *) card_ptr;
2746 net_dev = card->dev; 2746 net_dev = card->dev;
2747#ifdef CONFIG_QETH_PERF_STATS 2747 if (card->options.performance_stats) {
2748 card->perf_stats.inbound_cnt++; 2748 card->perf_stats.inbound_cnt++;
2749 card->perf_stats.inbound_start_time = qeth_get_micros(); 2749 card->perf_stats.inbound_start_time = qeth_get_micros();
2750#endif 2750 }
2751 if (status & QDIO_STATUS_LOOK_FOR_ERROR) { 2751 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
2752 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){ 2752 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){
2753 QETH_DBF_TEXT(trace, 1,"qdinchk"); 2753 QETH_DBF_TEXT(trace, 1,"qdinchk");
@@ -2769,10 +2769,9 @@ qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status,
2769 qeth_put_buffer_pool_entry(card, buffer->pool_entry); 2769 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
2770 qeth_queue_input_buffer(card, index); 2770 qeth_queue_input_buffer(card, index);
2771 } 2771 }
2772#ifdef CONFIG_QETH_PERF_STATS 2772 if (card->options.performance_stats)
2773 card->perf_stats.inbound_time += qeth_get_micros() - 2773 card->perf_stats.inbound_time += qeth_get_micros() -
2774 card->perf_stats.inbound_start_time; 2774 card->perf_stats.inbound_start_time;
2775#endif
2776} 2775}
2777 2776
2778static inline int 2777static inline int
@@ -2862,10 +2861,11 @@ qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2862 } 2861 }
2863 2862
2864 queue->card->dev->trans_start = jiffies; 2863 queue->card->dev->trans_start = jiffies;
2865#ifdef CONFIG_QETH_PERF_STATS 2864 if (queue->card->options.performance_stats) {
2866 queue->card->perf_stats.outbound_do_qdio_cnt++; 2865 queue->card->perf_stats.outbound_do_qdio_cnt++;
2867 queue->card->perf_stats.outbound_do_qdio_start_time = qeth_get_micros(); 2866 queue->card->perf_stats.outbound_do_qdio_start_time =
2868#endif 2867 qeth_get_micros();
2868 }
2869 if (under_int) 2869 if (under_int)
2870 rc = do_QDIO(CARD_DDEV(queue->card), 2870 rc = do_QDIO(CARD_DDEV(queue->card),
2871 QDIO_FLAG_SYNC_OUTPUT | QDIO_FLAG_UNDER_INTERRUPT, 2871 QDIO_FLAG_SYNC_OUTPUT | QDIO_FLAG_UNDER_INTERRUPT,
@@ -2873,10 +2873,10 @@ qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2873 else 2873 else
2874 rc = do_QDIO(CARD_DDEV(queue->card), QDIO_FLAG_SYNC_OUTPUT, 2874 rc = do_QDIO(CARD_DDEV(queue->card), QDIO_FLAG_SYNC_OUTPUT,
2875 queue->queue_no, index, count, NULL); 2875 queue->queue_no, index, count, NULL);
2876#ifdef CONFIG_QETH_PERF_STATS 2876 if (queue->card->options.performance_stats)
2877 queue->card->perf_stats.outbound_do_qdio_time += qeth_get_micros() - 2877 queue->card->perf_stats.outbound_do_qdio_time +=
2878 queue->card->perf_stats.outbound_do_qdio_start_time; 2878 qeth_get_micros() -
2879#endif 2879 queue->card->perf_stats.outbound_do_qdio_start_time;
2880 if (rc){ 2880 if (rc){
2881 QETH_DBF_TEXT(trace, 2, "flushbuf"); 2881 QETH_DBF_TEXT(trace, 2, "flushbuf");
2882 QETH_DBF_TEXT_(trace, 2, " err%d", rc); 2882 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
@@ -2888,9 +2888,8 @@ qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2888 return; 2888 return;
2889 } 2889 }
2890 atomic_add(count, &queue->used_buffers); 2890 atomic_add(count, &queue->used_buffers);
2891#ifdef CONFIG_QETH_PERF_STATS 2891 if (queue->card->options.performance_stats)
2892 queue->card->perf_stats.bufs_sent += count; 2892 queue->card->perf_stats.bufs_sent += count;
2893#endif
2894} 2893}
2895 2894
2896/* 2895/*
@@ -2905,9 +2904,8 @@ qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue)
2905 >= QETH_HIGH_WATERMARK_PACK){ 2904 >= QETH_HIGH_WATERMARK_PACK){
2906 /* switch non-PACKING -> PACKING */ 2905 /* switch non-PACKING -> PACKING */
2907 QETH_DBF_TEXT(trace, 6, "np->pack"); 2906 QETH_DBF_TEXT(trace, 6, "np->pack");
2908#ifdef CONFIG_QETH_PERF_STATS 2907 if (queue->card->options.performance_stats)
2909 queue->card->perf_stats.sc_dp_p++; 2908 queue->card->perf_stats.sc_dp_p++;
2910#endif
2911 queue->do_pack = 1; 2909 queue->do_pack = 1;
2912 } 2910 }
2913 } 2911 }
@@ -2930,9 +2928,8 @@ qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2930 <= QETH_LOW_WATERMARK_PACK) { 2928 <= QETH_LOW_WATERMARK_PACK) {
2931 /* switch PACKING -> non-PACKING */ 2929 /* switch PACKING -> non-PACKING */
2932 QETH_DBF_TEXT(trace, 6, "pack->np"); 2930 QETH_DBF_TEXT(trace, 6, "pack->np");
2933#ifdef CONFIG_QETH_PERF_STATS 2931 if (queue->card->options.performance_stats)
2934 queue->card->perf_stats.sc_p_dp++; 2932 queue->card->perf_stats.sc_p_dp++;
2935#endif
2936 queue->do_pack = 0; 2933 queue->do_pack = 0;
2937 /* flush packing buffers */ 2934 /* flush packing buffers */
2938 buffer = &queue->bufs[queue->next_buf_to_fill]; 2935 buffer = &queue->bufs[queue->next_buf_to_fill];
@@ -2944,7 +2941,7 @@ qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue)
2944 queue->next_buf_to_fill = 2941 queue->next_buf_to_fill =
2945 (queue->next_buf_to_fill + 1) % 2942 (queue->next_buf_to_fill + 1) %
2946 QDIO_MAX_BUFFERS_PER_Q; 2943 QDIO_MAX_BUFFERS_PER_Q;
2947 } 2944 }
2948 } 2945 }
2949 } 2946 }
2950 return flush_count; 2947 return flush_count;
@@ -3000,11 +2997,10 @@ qeth_check_outbound_queue(struct qeth_qdio_out_q *queue)
3000 !atomic_read(&queue->set_pci_flags_count)) 2997 !atomic_read(&queue->set_pci_flags_count))
3001 flush_cnt += 2998 flush_cnt +=
3002 qeth_flush_buffers_on_no_pci(queue); 2999 qeth_flush_buffers_on_no_pci(queue);
3003#ifdef CONFIG_QETH_PERF_STATS 3000 if (queue->card->options.performance_stats &&
3004 if (q_was_packing) 3001 q_was_packing)
3005 queue->card->perf_stats.bufs_sent_pack += 3002 queue->card->perf_stats.bufs_sent_pack +=
3006 flush_cnt; 3003 flush_cnt;
3007#endif
3008 if (flush_cnt) 3004 if (flush_cnt)
3009 qeth_flush_buffers(queue, 1, index, flush_cnt); 3005 qeth_flush_buffers(queue, 1, index, flush_cnt);
3010 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); 3006 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
@@ -3034,10 +3030,11 @@ qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status,
3034 return; 3030 return;
3035 } 3031 }
3036 } 3032 }
3037#ifdef CONFIG_QETH_PERF_STATS 3033 if (card->options.performance_stats) {
3038 card->perf_stats.outbound_handler_cnt++; 3034 card->perf_stats.outbound_handler_cnt++;
3039 card->perf_stats.outbound_handler_start_time = qeth_get_micros(); 3035 card->perf_stats.outbound_handler_start_time =
3040#endif 3036 qeth_get_micros();
3037 }
3041 for(i = first_element; i < (first_element + count); ++i){ 3038 for(i = first_element; i < (first_element + count); ++i){
3042 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]; 3039 buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
3043 /*we only handle the KICK_IT error by doing a recovery */ 3040 /*we only handle the KICK_IT error by doing a recovery */
@@ -3056,10 +3053,9 @@ qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status,
3056 qeth_check_outbound_queue(queue); 3053 qeth_check_outbound_queue(queue);
3057 3054
3058 netif_wake_queue(queue->card->dev); 3055 netif_wake_queue(queue->card->dev);
3059#ifdef CONFIG_QETH_PERF_STATS 3056 if (card->options.performance_stats)
3060 card->perf_stats.outbound_handler_time += qeth_get_micros() - 3057 card->perf_stats.outbound_handler_time += qeth_get_micros() -
3061 card->perf_stats.outbound_handler_start_time; 3058 card->perf_stats.outbound_handler_start_time;
3062#endif
3063} 3059}
3064 3060
3065static void 3061static void
@@ -3183,13 +3179,14 @@ qeth_alloc_qdio_buffers(struct qeth_card *card)
3183 3179
3184 QETH_DBF_TEXT(setup, 2, "allcqdbf"); 3180 QETH_DBF_TEXT(setup, 2, "allcqdbf");
3185 3181
3186 if (card->qdio.state == QETH_QDIO_ALLOCATED) 3182 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_UNINITIALIZED,
3183 QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
3187 return 0; 3184 return 0;
3188 3185
3189 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q), 3186 card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q),
3190 GFP_KERNEL|GFP_DMA); 3187 GFP_KERNEL|GFP_DMA);
3191 if (!card->qdio.in_q) 3188 if (!card->qdio.in_q)
3192 return - ENOMEM; 3189 goto out_nomem;
3193 QETH_DBF_TEXT(setup, 2, "inq"); 3190 QETH_DBF_TEXT(setup, 2, "inq");
3194 QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *)); 3191 QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *));
3195 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q)); 3192 memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
@@ -3198,27 +3195,19 @@ qeth_alloc_qdio_buffers(struct qeth_card *card)
3198 card->qdio.in_q->bufs[i].buffer = 3195 card->qdio.in_q->bufs[i].buffer =
3199 &card->qdio.in_q->qdio_bufs[i]; 3196 &card->qdio.in_q->qdio_bufs[i];
3200 /* inbound buffer pool */ 3197 /* inbound buffer pool */
3201 if (qeth_alloc_buffer_pool(card)){ 3198 if (qeth_alloc_buffer_pool(card))
3202 kfree(card->qdio.in_q); 3199 goto out_freeinq;
3203 return -ENOMEM;
3204 }
3205 /* outbound */ 3200 /* outbound */
3206 card->qdio.out_qs = 3201 card->qdio.out_qs =
3207 kmalloc(card->qdio.no_out_queues * 3202 kmalloc(card->qdio.no_out_queues *
3208 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL); 3203 sizeof(struct qeth_qdio_out_q *), GFP_KERNEL);
3209 if (!card->qdio.out_qs){ 3204 if (!card->qdio.out_qs)
3210 qeth_free_buffer_pool(card); 3205 goto out_freepool;
3211 return -ENOMEM; 3206 for (i = 0; i < card->qdio.no_out_queues; ++i) {
3212 }
3213 for (i = 0; i < card->qdio.no_out_queues; ++i){
3214 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q), 3207 card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q),
3215 GFP_KERNEL|GFP_DMA); 3208 GFP_KERNEL|GFP_DMA);
3216 if (!card->qdio.out_qs[i]){ 3209 if (!card->qdio.out_qs[i])
3217 while (i > 0) 3210 goto out_freeoutq;
3218 kfree(card->qdio.out_qs[--i]);
3219 kfree(card->qdio.out_qs);
3220 return -ENOMEM;
3221 }
3222 QETH_DBF_TEXT_(setup, 2, "outq %i", i); 3211 QETH_DBF_TEXT_(setup, 2, "outq %i", i);
3223 QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *)); 3212 QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *));
3224 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q)); 3213 memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q));
@@ -3229,11 +3218,25 @@ qeth_alloc_qdio_buffers(struct qeth_card *card)
3229 &card->qdio.out_qs[i]->qdio_bufs[j]; 3218 &card->qdio.out_qs[i]->qdio_bufs[j];
3230 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j]. 3219 skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j].
3231 skb_list); 3220 skb_list);
3221 lockdep_set_class(
3222 &card->qdio.out_qs[i]->bufs[j].skb_list.lock,
3223 &qdio_out_skb_queue_key);
3232 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list); 3224 INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list);
3233 } 3225 }
3234 } 3226 }
3235 card->qdio.state = QETH_QDIO_ALLOCATED;
3236 return 0; 3227 return 0;
3228
3229out_freeoutq:
3230 while (i > 0)
3231 kfree(card->qdio.out_qs[--i]);
3232 kfree(card->qdio.out_qs);
3233out_freepool:
3234 qeth_free_buffer_pool(card);
3235out_freeinq:
3236 kfree(card->qdio.in_q);
3237out_nomem:
3238 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
3239 return -ENOMEM;
3237} 3240}
3238 3241
3239static void 3242static void
@@ -3242,7 +3245,8 @@ qeth_free_qdio_buffers(struct qeth_card *card)
3242 int i, j; 3245 int i, j;
3243 3246
3244 QETH_DBF_TEXT(trace, 2, "freeqdbf"); 3247 QETH_DBF_TEXT(trace, 2, "freeqdbf");
3245 if (card->qdio.state == QETH_QDIO_UNINITIALIZED) 3248 if (atomic_swap(&card->qdio.state, QETH_QDIO_UNINITIALIZED) ==
3249 QETH_QDIO_UNINITIALIZED)
3246 return; 3250 return;
3247 kfree(card->qdio.in_q); 3251 kfree(card->qdio.in_q);
3248 /* inbound buffer pool */ 3252 /* inbound buffer pool */
@@ -3255,7 +3259,6 @@ qeth_free_qdio_buffers(struct qeth_card *card)
3255 kfree(card->qdio.out_qs[i]); 3259 kfree(card->qdio.out_qs[i]);
3256 } 3260 }
3257 kfree(card->qdio.out_qs); 3261 kfree(card->qdio.out_qs);
3258 card->qdio.state = QETH_QDIO_UNINITIALIZED;
3259} 3262}
3260 3263
3261static void 3264static void
@@ -3277,7 +3280,7 @@ static void
3277qeth_init_qdio_info(struct qeth_card *card) 3280qeth_init_qdio_info(struct qeth_card *card)
3278{ 3281{
3279 QETH_DBF_TEXT(setup, 4, "intqdinf"); 3282 QETH_DBF_TEXT(setup, 4, "intqdinf");
3280 card->qdio.state = QETH_QDIO_UNINITIALIZED; 3283 atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
3281 /* inbound */ 3284 /* inbound */
3282 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT; 3285 card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT;
3283 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT; 3286 card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT;
@@ -3340,7 +3343,7 @@ qeth_qdio_establish(struct qeth_card *card)
3340 struct qdio_buffer **in_sbal_ptrs; 3343 struct qdio_buffer **in_sbal_ptrs;
3341 struct qdio_buffer **out_sbal_ptrs; 3344 struct qdio_buffer **out_sbal_ptrs;
3342 int i, j, k; 3345 int i, j, k;
3343 int rc; 3346 int rc = 0;
3344 3347
3345 QETH_DBF_TEXT(setup, 2, "qdioest"); 3348 QETH_DBF_TEXT(setup, 2, "qdioest");
3346 3349
@@ -3399,8 +3402,10 @@ qeth_qdio_establish(struct qeth_card *card)
3399 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs; 3402 init_data.input_sbal_addr_array = (void **) in_sbal_ptrs;
3400 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs; 3403 init_data.output_sbal_addr_array = (void **) out_sbal_ptrs;
3401 3404
3402 if (!(rc = qdio_initialize(&init_data))) 3405 if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
3403 card->qdio.state = QETH_QDIO_ESTABLISHED; 3406 QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED)
3407 if ((rc = qdio_initialize(&init_data)))
3408 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3404 3409
3405 kfree(out_sbal_ptrs); 3410 kfree(out_sbal_ptrs);
3406 kfree(in_sbal_ptrs); 3411 kfree(in_sbal_ptrs);
@@ -3516,13 +3521,20 @@ qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
3516 int rc = 0; 3521 int rc = 0;
3517 3522
3518 QETH_DBF_TEXT(trace,3,"qdioclr"); 3523 QETH_DBF_TEXT(trace,3,"qdioclr");
3519 if (card->qdio.state == QETH_QDIO_ESTABLISHED){ 3524 switch (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ESTABLISHED,
3525 QETH_QDIO_CLEANING)) {
3526 case QETH_QDIO_ESTABLISHED:
3520 if ((rc = qdio_cleanup(CARD_DDEV(card), 3527 if ((rc = qdio_cleanup(CARD_DDEV(card),
3521 (card->info.type == QETH_CARD_TYPE_IQD) ? 3528 (card->info.type == QETH_CARD_TYPE_IQD) ?
3522 QDIO_FLAG_CLEANUP_USING_HALT : 3529 QDIO_FLAG_CLEANUP_USING_HALT :
3523 QDIO_FLAG_CLEANUP_USING_CLEAR))) 3530 QDIO_FLAG_CLEANUP_USING_CLEAR)))
3524 QETH_DBF_TEXT_(trace, 3, "1err%d", rc); 3531 QETH_DBF_TEXT_(trace, 3, "1err%d", rc);
3525 card->qdio.state = QETH_QDIO_ALLOCATED; 3532 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
3533 break;
3534 case QETH_QDIO_CLEANING:
3535 return rc;
3536 default:
3537 break;
3526 } 3538 }
3527 if ((rc = qeth_clear_halt_card(card, use_halt))) 3539 if ((rc = qeth_clear_halt_card(card, use_halt)))
3528 QETH_DBF_TEXT_(trace, 3, "2err%d", rc); 3540 QETH_DBF_TEXT_(trace, 3, "2err%d", rc);
@@ -3682,10 +3694,10 @@ qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3682 /* return OK; otherwise ksoftirqd goes to 100% */ 3694 /* return OK; otherwise ksoftirqd goes to 100% */
3683 return NETDEV_TX_OK; 3695 return NETDEV_TX_OK;
3684 } 3696 }
3685#ifdef CONFIG_QETH_PERF_STATS 3697 if (card->options.performance_stats) {
3686 card->perf_stats.outbound_cnt++; 3698 card->perf_stats.outbound_cnt++;
3687 card->perf_stats.outbound_start_time = qeth_get_micros(); 3699 card->perf_stats.outbound_start_time = qeth_get_micros();
3688#endif 3700 }
3689 netif_stop_queue(dev); 3701 netif_stop_queue(dev);
3690 if ((rc = qeth_send_packet(card, skb))) { 3702 if ((rc = qeth_send_packet(card, skb))) {
3691 if (rc == -EBUSY) { 3703 if (rc == -EBUSY) {
@@ -3699,10 +3711,9 @@ qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
3699 } 3711 }
3700 } 3712 }
3701 netif_wake_queue(dev); 3713 netif_wake_queue(dev);
3702#ifdef CONFIG_QETH_PERF_STATS 3714 if (card->options.performance_stats)
3703 card->perf_stats.outbound_time += qeth_get_micros() - 3715 card->perf_stats.outbound_time += qeth_get_micros() -
3704 card->perf_stats.outbound_start_time; 3716 card->perf_stats.outbound_start_time;
3705#endif
3706 return rc; 3717 return rc;
3707} 3718}
3708 3719
@@ -3917,49 +3928,59 @@ qeth_get_ip_version(struct sk_buff *skb)
3917 } 3928 }
3918} 3929}
3919 3930
3920static inline int 3931static inline struct qeth_hdr *
3921qeth_prepare_skb(struct qeth_card *card, struct sk_buff **skb, 3932__qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb, int ipv)
3922 struct qeth_hdr **hdr, int ipv)
3923{ 3933{
3924 int rc = 0;
3925#ifdef CONFIG_QETH_VLAN 3934#ifdef CONFIG_QETH_VLAN
3926 u16 *tag; 3935 u16 *tag;
3927#endif 3936 if (card->vlangrp && vlan_tx_tag_present(skb) &&
3928
3929 QETH_DBF_TEXT(trace, 6, "prepskb");
3930 if (card->info.type == QETH_CARD_TYPE_OSN) {
3931 *hdr = (struct qeth_hdr *)(*skb)->data;
3932 return rc;
3933 }
3934 rc = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr));
3935 if (rc)
3936 return rc;
3937#ifdef CONFIG_QETH_VLAN
3938 if (card->vlangrp && vlan_tx_tag_present(*skb) &&
3939 ((ipv == 6) || card->options.layer2) ) { 3937 ((ipv == 6) || card->options.layer2) ) {
3940 /* 3938 /*
3941 * Move the mac addresses (6 bytes src, 6 bytes dest) 3939 * Move the mac addresses (6 bytes src, 6 bytes dest)
3942 * to the beginning of the new header. We are using three 3940 * to the beginning of the new header. We are using three
3943 * memcpys instead of one memmove to save cycles. 3941 * memcpys instead of one memmove to save cycles.
3944 */ 3942 */
3945 skb_push(*skb, VLAN_HLEN); 3943 skb_push(skb, VLAN_HLEN);
3946 memcpy((*skb)->data, (*skb)->data + 4, 4); 3944 memcpy(skb->data, skb->data + 4, 4);
3947 memcpy((*skb)->data + 4, (*skb)->data + 8, 4); 3945 memcpy(skb->data + 4, skb->data + 8, 4);
3948 memcpy((*skb)->data + 8, (*skb)->data + 12, 4); 3946 memcpy(skb->data + 8, skb->data + 12, 4);
3949 tag = (u16 *)((*skb)->data + 12); 3947 tag = (u16 *)(skb->data + 12);
3950 /* 3948 /*
3951 * first two bytes = ETH_P_8021Q (0x8100) 3949 * first two bytes = ETH_P_8021Q (0x8100)
3952 * second two bytes = VLANID 3950 * second two bytes = VLANID
3953 */ 3951 */
3954 *tag = __constant_htons(ETH_P_8021Q); 3952 *tag = __constant_htons(ETH_P_8021Q);
3955 *(tag + 1) = htons(vlan_tx_tag_get(*skb)); 3953 *(tag + 1) = htons(vlan_tx_tag_get(skb));
3956 } 3954 }
3957#endif 3955#endif
3958 *hdr = (struct qeth_hdr *) 3956 return ((struct qeth_hdr *)
3959 qeth_push_skb(card, skb, sizeof(struct qeth_hdr)); 3957 qeth_push_skb(card, skb, sizeof(struct qeth_hdr)));
3960 if (*hdr == NULL) 3958}
3961 return -EINVAL; 3959
3962 return 0; 3960static inline void
3961__qeth_free_new_skb(struct sk_buff *orig_skb, struct sk_buff *new_skb)
3962{
3963 if (orig_skb != new_skb)
3964 dev_kfree_skb_any(new_skb);
3965}
3966
3967static inline struct sk_buff *
3968qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb,
3969 struct qeth_hdr **hdr, int ipv)
3970{
3971 struct sk_buff *new_skb;
3972
3973 QETH_DBF_TEXT(trace, 6, "prepskb");
3974
3975 new_skb = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr));
3976 if (new_skb == NULL)
3977 return NULL;
3978 *hdr = __qeth_prepare_skb(card, new_skb, ipv);
3979 if (*hdr == NULL) {
3980 __qeth_free_new_skb(skb, new_skb);
3981 return NULL;
3982 }
3983 return new_skb;
3963} 3984}
3964 3985
3965static inline u8 3986static inline u8
@@ -4201,9 +4222,8 @@ qeth_fill_buffer(struct qeth_qdio_out_q *queue,
4201 flush_cnt = 1; 4222 flush_cnt = 1;
4202 } else { 4223 } else {
4203 QETH_DBF_TEXT(trace, 6, "fillbfpa"); 4224 QETH_DBF_TEXT(trace, 6, "fillbfpa");
4204#ifdef CONFIG_QETH_PERF_STATS 4225 if (queue->card->options.performance_stats)
4205 queue->card->perf_stats.skbs_sent_pack++; 4226 queue->card->perf_stats.skbs_sent_pack++;
4206#endif
4207 if (buf->next_element_to_fill >= 4227 if (buf->next_element_to_fill >=
4208 QETH_MAX_BUFFER_ELEMENTS(queue->card)) { 4228 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
4209 /* 4229 /*
@@ -4240,21 +4260,15 @@ qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4240 * check if buffer is empty to make sure that we do not 'overtake' 4260 * check if buffer is empty to make sure that we do not 'overtake'
4241 * ourselves and try to fill a buffer that is already primed 4261 * ourselves and try to fill a buffer that is already primed
4242 */ 4262 */
4243 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) { 4263 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY)
4244 card->stats.tx_dropped++; 4264 goto out;
4245 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4246 return -EBUSY;
4247 }
4248 if (ctx == NULL) 4265 if (ctx == NULL)
4249 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) % 4266 queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) %
4250 QDIO_MAX_BUFFERS_PER_Q; 4267 QDIO_MAX_BUFFERS_PER_Q;
4251 else { 4268 else {
4252 buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx); 4269 buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx);
4253 if (buffers_needed < 0) { 4270 if (buffers_needed < 0)
4254 card->stats.tx_dropped++; 4271 goto out;
4255 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4256 return -EBUSY;
4257 }
4258 queue->next_buf_to_fill = 4272 queue->next_buf_to_fill =
4259 (queue->next_buf_to_fill + buffers_needed) % 4273 (queue->next_buf_to_fill + buffers_needed) %
4260 QDIO_MAX_BUFFERS_PER_Q; 4274 QDIO_MAX_BUFFERS_PER_Q;
@@ -4269,6 +4283,9 @@ qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4269 qeth_flush_buffers(queue, 0, index, flush_cnt); 4283 qeth_flush_buffers(queue, 0, index, flush_cnt);
4270 } 4284 }
4271 return 0; 4285 return 0;
4286out:
4287 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4288 return -EBUSY;
4272} 4289}
4273 4290
4274static inline int 4291static inline int
@@ -4294,8 +4311,7 @@ qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4294 * check if buffer is empty to make sure that we do not 'overtake' 4311 * check if buffer is empty to make sure that we do not 'overtake'
4295 * ourselves and try to fill a buffer that is already primed 4312 * ourselves and try to fill a buffer that is already primed
4296 */ 4313 */
4297 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY){ 4314 if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) {
4298 card->stats.tx_dropped++;
4299 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); 4315 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4300 return -EBUSY; 4316 return -EBUSY;
4301 } 4317 }
@@ -4318,7 +4334,6 @@ qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4318 * again */ 4334 * again */
4319 if (atomic_read(&buffer->state) != 4335 if (atomic_read(&buffer->state) !=
4320 QETH_QDIO_BUF_EMPTY){ 4336 QETH_QDIO_BUF_EMPTY){
4321 card->stats.tx_dropped++;
4322 qeth_flush_buffers(queue, 0, start_index, flush_count); 4337 qeth_flush_buffers(queue, 0, start_index, flush_count);
4323 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); 4338 atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED);
4324 return -EBUSY; 4339 return -EBUSY;
@@ -4329,7 +4344,6 @@ qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4329 * free buffers) to handle eddp context */ 4344 * free buffers) to handle eddp context */
4330 if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){ 4345 if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){
4331 printk("eddp tx_dropped 1\n"); 4346 printk("eddp tx_dropped 1\n");
4332 card->stats.tx_dropped++;
4333 rc = -EBUSY; 4347 rc = -EBUSY;
4334 goto out; 4348 goto out;
4335 } 4349 }
@@ -4341,7 +4355,6 @@ qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
4341 tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill); 4355 tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill);
4342 if (tmp < 0) { 4356 if (tmp < 0) {
4343 printk("eddp tx_dropped 2\n"); 4357 printk("eddp tx_dropped 2\n");
4344 card->stats.tx_dropped++;
4345 rc = - EBUSY; 4358 rc = - EBUSY;
4346 goto out; 4359 goto out;
4347 } 4360 }
@@ -4375,10 +4388,8 @@ out:
4375 qeth_flush_buffers(queue, 0, start_index, flush_count); 4388 qeth_flush_buffers(queue, 0, start_index, flush_count);
4376 } 4389 }
4377 /* at this point the queue is UNLOCKED again */ 4390 /* at this point the queue is UNLOCKED again */
4378#ifdef CONFIG_QETH_PERF_STATS 4391 if (queue->card->options.performance_stats && do_pack)
4379 if (do_pack)
4380 queue->card->perf_stats.bufs_sent_pack += flush_count; 4392 queue->card->perf_stats.bufs_sent_pack += flush_count;
4381#endif /* CONFIG_QETH_PERF_STATS */
4382 4393
4383 return rc; 4394 return rc;
4384} 4395}
@@ -4389,21 +4400,21 @@ qeth_get_elements_no(struct qeth_card *card, void *hdr,
4389{ 4400{
4390 int elements_needed = 0; 4401 int elements_needed = 0;
4391 4402
4392 if (skb_shinfo(skb)->nr_frags > 0) { 4403 if (skb_shinfo(skb)->nr_frags > 0)
4393 elements_needed = (skb_shinfo(skb)->nr_frags + 1); 4404 elements_needed = (skb_shinfo(skb)->nr_frags + 1);
4394 } 4405 if (elements_needed == 0)
4395 if (elements_needed == 0 )
4396 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE) 4406 elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE)
4397 + skb->len) >> PAGE_SHIFT); 4407 + skb->len) >> PAGE_SHIFT);
4398 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){ 4408 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){
4399 PRINT_ERR("qeth_do_send_packet: invalid size of " 4409 PRINT_ERR("Invalid size of IP packet "
4400 "IP packet (Number=%d / Length=%d). Discarded.\n", 4410 "(Number=%d / Length=%d). Discarded.\n",
4401 (elements_needed+elems), skb->len); 4411 (elements_needed+elems), skb->len);
4402 return 0; 4412 return 0;
4403 } 4413 }
4404 return elements_needed; 4414 return elements_needed;
4405} 4415}
4406 4416
4417
4407static inline int 4418static inline int
4408qeth_send_packet(struct qeth_card *card, struct sk_buff *skb) 4419qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4409{ 4420{
@@ -4417,108 +4428,110 @@ qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4417 int tx_bytes = skb->len; 4428 int tx_bytes = skb->len;
4418 unsigned short nr_frags = skb_shinfo(skb)->nr_frags; 4429 unsigned short nr_frags = skb_shinfo(skb)->nr_frags;
4419 unsigned short tso_size = skb_shinfo(skb)->gso_size; 4430 unsigned short tso_size = skb_shinfo(skb)->gso_size;
4431 struct sk_buff *new_skb, *new_skb2;
4420 int rc; 4432 int rc;
4421 4433
4422 QETH_DBF_TEXT(trace, 6, "sendpkt"); 4434 QETH_DBF_TEXT(trace, 6, "sendpkt");
4423 4435
4436 new_skb = skb;
4437 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
4438 (skb->protocol == htons(ETH_P_IPV6)))
4439 return -EPERM;
4440 cast_type = qeth_get_cast_type(card, skb);
4441 if ((cast_type == RTN_BROADCAST) &&
4442 (card->info.broadcast_capable == 0))
4443 return -EPERM;
4444 queue = card->qdio.out_qs
4445 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
4424 if (!card->options.layer2) { 4446 if (!card->options.layer2) {
4425 ipv = qeth_get_ip_version(skb); 4447 ipv = qeth_get_ip_version(skb);
4426 if ((card->dev->hard_header == qeth_fake_header) && ipv) { 4448 if ((card->dev->hard_header == qeth_fake_header) && ipv) {
4427 if ((skb = qeth_pskb_unshare(skb,GFP_ATOMIC)) == NULL) { 4449 new_skb = qeth_pskb_unshare(skb, GFP_ATOMIC);
4428 card->stats.tx_dropped++; 4450 if (!new_skb)
4429 dev_kfree_skb_irq(skb); 4451 return -ENOMEM;
4430 return 0;
4431 }
4432 if(card->dev->type == ARPHRD_IEEE802_TR){ 4452 if(card->dev->type == ARPHRD_IEEE802_TR){
4433 skb_pull(skb, QETH_FAKE_LL_LEN_TR); 4453 skb_pull(new_skb, QETH_FAKE_LL_LEN_TR);
4434 } else { 4454 } else {
4435 skb_pull(skb, QETH_FAKE_LL_LEN_ETH); 4455 skb_pull(new_skb, QETH_FAKE_LL_LEN_ETH);
4436 } 4456 }
4437 } 4457 }
4438 } 4458 }
4439 if ((card->info.type == QETH_CARD_TYPE_OSN) && 4459 if (skb_is_gso(skb))
4440 (skb->protocol == htons(ETH_P_IPV6))) {
4441 dev_kfree_skb_any(skb);
4442 return 0;
4443 }
4444 cast_type = qeth_get_cast_type(card, skb);
4445 if ((cast_type == RTN_BROADCAST) &&
4446 (card->info.broadcast_capable == 0)){
4447 card->stats.tx_dropped++;
4448 card->stats.tx_errors++;
4449 dev_kfree_skb_any(skb);
4450 return NETDEV_TX_OK;
4451 }
4452 queue = card->qdio.out_qs
4453 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
4454
4455 if (skb_shinfo(skb)->gso_size)
4456 large_send = card->options.large_send; 4460 large_send = card->options.large_send;
4457 4461 /* check on OSN device*/
4458 /*are we able to do TSO ? If so ,prepare and send it from here */ 4462 if (card->info.type == QETH_CARD_TYPE_OSN)
4463 hdr = (struct qeth_hdr *)new_skb->data;
4464 /*are we able to do TSO ? */
4459 if ((large_send == QETH_LARGE_SEND_TSO) && 4465 if ((large_send == QETH_LARGE_SEND_TSO) &&
4460 (cast_type == RTN_UNSPEC)) { 4466 (cast_type == RTN_UNSPEC)) {
4461 rc = qeth_tso_prepare_packet(card, skb, ipv, cast_type); 4467 rc = qeth_tso_prepare_packet(card, new_skb, ipv, cast_type);
4462 if (rc) { 4468 if (rc) {
4463 card->stats.tx_dropped++; 4469 __qeth_free_new_skb(skb, new_skb);
4464 card->stats.tx_errors++; 4470 return rc;
4465 dev_kfree_skb_any(skb);
4466 return NETDEV_TX_OK;
4467 } 4471 }
4468 elements_needed++; 4472 elements_needed++;
4469 } else { 4473 } else if (card->info.type != QETH_CARD_TYPE_OSN) {
4470 if ((rc = qeth_prepare_skb(card, &skb, &hdr, ipv))) { 4474 new_skb2 = qeth_prepare_skb(card, new_skb, &hdr, ipv);
4471 QETH_DBF_TEXT_(trace, 4, "pskbe%d", rc); 4475 if (!new_skb2) {
4472 return rc; 4476 __qeth_free_new_skb(skb, new_skb);
4477 return -EINVAL;
4473 } 4478 }
4474 if (card->info.type != QETH_CARD_TYPE_OSN) 4479 if (new_skb != skb)
4475 qeth_fill_header(card, hdr, skb, ipv, cast_type); 4480 __qeth_free_new_skb(new_skb2, new_skb);
4481 new_skb = new_skb2;
4482 qeth_fill_header(card, hdr, new_skb, ipv, cast_type);
4476 } 4483 }
4477
4478 if (large_send == QETH_LARGE_SEND_EDDP) { 4484 if (large_send == QETH_LARGE_SEND_EDDP) {
4479 ctx = qeth_eddp_create_context(card, skb, hdr); 4485 ctx = qeth_eddp_create_context(card, new_skb, hdr);
4480 if (ctx == NULL) { 4486 if (ctx == NULL) {
4487 __qeth_free_new_skb(skb, new_skb);
4481 PRINT_WARN("could not create eddp context\n"); 4488 PRINT_WARN("could not create eddp context\n");
4482 return -EINVAL; 4489 return -EINVAL;
4483 } 4490 }
4484 } else { 4491 } else {
4485 int elems = qeth_get_elements_no(card,(void*) hdr, skb, 4492 int elems = qeth_get_elements_no(card,(void*) hdr, new_skb,
4486 elements_needed); 4493 elements_needed);
4487 if (!elems) 4494 if (!elems) {
4495 __qeth_free_new_skb(skb, new_skb);
4488 return -EINVAL; 4496 return -EINVAL;
4497 }
4489 elements_needed += elems; 4498 elements_needed += elems;
4490 } 4499 }
4491 4500
4492 if (card->info.type != QETH_CARD_TYPE_IQD) 4501 if (card->info.type != QETH_CARD_TYPE_IQD)
4493 rc = qeth_do_send_packet(card, queue, skb, hdr, 4502 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
4494 elements_needed, ctx); 4503 elements_needed, ctx);
4495 else 4504 else
4496 rc = qeth_do_send_packet_fast(card, queue, skb, hdr, 4505 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
4497 elements_needed, ctx); 4506 elements_needed, ctx);
4498 if (!rc){ 4507 if (!rc) {
4499 card->stats.tx_packets++; 4508 card->stats.tx_packets++;
4500 card->stats.tx_bytes += tx_bytes; 4509 card->stats.tx_bytes += tx_bytes;
4501#ifdef CONFIG_QETH_PERF_STATS 4510 if (new_skb != skb)
4502 if (tso_size && 4511 dev_kfree_skb_any(skb);
4503 !(large_send == QETH_LARGE_SEND_NO)) { 4512 if (card->options.performance_stats) {
4504 card->perf_stats.large_send_bytes += tx_bytes; 4513 if (tso_size &&
4505 card->perf_stats.large_send_cnt++; 4514 !(large_send == QETH_LARGE_SEND_NO)) {
4506 } 4515 card->perf_stats.large_send_bytes += tx_bytes;
4507 if (nr_frags > 0){ 4516 card->perf_stats.large_send_cnt++;
4508 card->perf_stats.sg_skbs_sent++; 4517 }
4509 /* nr_frags + skb->data */ 4518 if (nr_frags > 0) {
4510 card->perf_stats.sg_frags_sent += 4519 card->perf_stats.sg_skbs_sent++;
4511 nr_frags + 1; 4520 /* nr_frags + skb->data */
4521 card->perf_stats.sg_frags_sent +=
4522 nr_frags + 1;
4523 }
4512 } 4524 }
4513#endif /* CONFIG_QETH_PERF_STATS */ 4525 } else {
4526 card->stats.tx_dropped++;
4527 __qeth_free_new_skb(skb, new_skb);
4514 } 4528 }
4515 if (ctx != NULL) { 4529 if (ctx != NULL) {
4516 /* drop creator's reference */ 4530 /* drop creator's reference */
4517 qeth_eddp_put_context(ctx); 4531 qeth_eddp_put_context(ctx);
4518 /* free skb; it's not referenced by a buffer */ 4532 /* free skb; it's not referenced by a buffer */
4519 if (rc == 0) 4533 if (!rc)
4520 dev_kfree_skb_any(skb); 4534 dev_kfree_skb_any(new_skb);
4521
4522 } 4535 }
4523 return rc; 4536 return rc;
4524} 4537}
@@ -4797,7 +4810,7 @@ static struct qeth_cmd_buffer *
4797qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs, 4810qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs,
4798 __u16, __u16, enum qeth_prot_versions); 4811 __u16, __u16, enum qeth_prot_versions);
4799static int 4812static int
4800qeth_arp_query(struct qeth_card *card, char *udata) 4813qeth_arp_query(struct qeth_card *card, char __user *udata)
4801{ 4814{
4802 struct qeth_cmd_buffer *iob; 4815 struct qeth_cmd_buffer *iob;
4803 struct qeth_arp_query_info qinfo = {0, }; 4816 struct qeth_arp_query_info qinfo = {0, };
@@ -4930,7 +4943,7 @@ qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen)
4930 * function to send SNMP commands to OSA-E card 4943 * function to send SNMP commands to OSA-E card
4931 */ 4944 */
4932static int 4945static int
4933qeth_snmp_command(struct qeth_card *card, char *udata) 4946qeth_snmp_command(struct qeth_card *card, char __user *udata)
4934{ 4947{
4935 struct qeth_cmd_buffer *iob; 4948 struct qeth_cmd_buffer *iob;
4936 struct qeth_ipa_cmd *cmd; 4949 struct qeth_ipa_cmd *cmd;
@@ -5272,6 +5285,7 @@ qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf,
5272 struct sk_buff_head tmp_list; 5285 struct sk_buff_head tmp_list;
5273 5286
5274 skb_queue_head_init(&tmp_list); 5287 skb_queue_head_init(&tmp_list);
5288 lockdep_set_class(&tmp_list.lock, &qdio_out_skb_queue_key);
5275 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){ 5289 for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){
5276 while ((skb = skb_dequeue(&buf->skb_list))){ 5290 while ((skb = skb_dequeue(&buf->skb_list))){
5277 if (vlan_tx_tag_present(skb) && 5291 if (vlan_tx_tag_present(skb) &&
@@ -7330,6 +7344,8 @@ qeth_setrouting_v6(struct qeth_card *card)
7330 QETH_DBF_TEXT(trace,3,"setrtg6"); 7344 QETH_DBF_TEXT(trace,3,"setrtg6");
7331#ifdef CONFIG_QETH_IPV6 7345#ifdef CONFIG_QETH_IPV6
7332 7346
7347 if (!qeth_is_supported(card, IPA_IPV6))
7348 return 0;
7333 qeth_correct_routing_type(card, &card->options.route6.type, 7349 qeth_correct_routing_type(card, &card->options.route6.type,
7334 QETH_PROT_IPV6); 7350 QETH_PROT_IPV6);
7335 7351
@@ -7868,12 +7884,12 @@ __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
7868 QETH_DBF_TEXT_(setup, 2, "5err%d", rc); 7884 QETH_DBF_TEXT_(setup, 2, "5err%d", rc);
7869 goto out_remove; 7885 goto out_remove;
7870 } 7886 }
7871 card->state = CARD_STATE_SOFTSETUP;
7872 7887
7873 if ((rc = qeth_init_qdio_queues(card))){ 7888 if ((rc = qeth_init_qdio_queues(card))){
7874 QETH_DBF_TEXT_(setup, 2, "6err%d", rc); 7889 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
7875 goto out_remove; 7890 goto out_remove;
7876 } 7891 }
7892 card->state = CARD_STATE_SOFTSETUP;
7877 netif_carrier_on(card->dev); 7893 netif_carrier_on(card->dev);
7878 7894
7879 qeth_set_allowed_threads(card, 0xffffffff, 0); 7895 qeth_set_allowed_threads(card, 0xffffffff, 0);
@@ -7901,9 +7917,9 @@ qeth_set_online(struct ccwgroup_device *gdev)
7901} 7917}
7902 7918
7903static struct ccw_device_id qeth_ids[] = { 7919static struct ccw_device_id qeth_ids[] = {
7904 {CCW_DEVICE(0x1731, 0x01), driver_info:QETH_CARD_TYPE_OSAE}, 7920 {CCW_DEVICE(0x1731, 0x01), .driver_info = QETH_CARD_TYPE_OSAE},
7905 {CCW_DEVICE(0x1731, 0x05), driver_info:QETH_CARD_TYPE_IQD}, 7921 {CCW_DEVICE(0x1731, 0x05), .driver_info = QETH_CARD_TYPE_IQD},
7906 {CCW_DEVICE(0x1731, 0x06), driver_info:QETH_CARD_TYPE_OSN}, 7922 {CCW_DEVICE(0x1731, 0x06), .driver_info = QETH_CARD_TYPE_OSN},
7907 {}, 7923 {},
7908}; 7924};
7909MODULE_DEVICE_TABLE(ccw, qeth_ids); 7925MODULE_DEVICE_TABLE(ccw, qeth_ids);
@@ -8372,7 +8388,7 @@ out:
8372 8388
8373static struct notifier_block qeth_ip_notifier = { 8389static struct notifier_block qeth_ip_notifier = {
8374 qeth_ip_event, 8390 qeth_ip_event,
8375 0 8391 NULL,
8376}; 8392};
8377 8393
8378#ifdef CONFIG_QETH_IPV6 8394#ifdef CONFIG_QETH_IPV6
@@ -8425,7 +8441,7 @@ out:
8425 8441
8426static struct notifier_block qeth_ip6_notifier = { 8442static struct notifier_block qeth_ip6_notifier = {
8427 qeth_ip6_event, 8443 qeth_ip6_event,
8428 0 8444 NULL,
8429}; 8445};
8430#endif 8446#endif
8431 8447
@@ -8443,16 +8459,17 @@ __qeth_reboot_event_card(struct device *dev, void *data)
8443static int 8459static int
8444qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr) 8460qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8445{ 8461{
8462 int ret;
8446 8463
8447 driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL, 8464 ret = driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8448 __qeth_reboot_event_card); 8465 __qeth_reboot_event_card);
8449 return NOTIFY_DONE; 8466 return ret ? NOTIFY_BAD : NOTIFY_DONE;
8450} 8467}
8451 8468
8452 8469
8453static struct notifier_block qeth_reboot_notifier = { 8470static struct notifier_block qeth_reboot_notifier = {
8454 qeth_reboot_event, 8471 qeth_reboot_event,
8455 0 8472 NULL,
8456}; 8473};
8457 8474
8458static int 8475static int
@@ -8501,9 +8518,9 @@ static int
8501qeth_ipv6_init(void) 8518qeth_ipv6_init(void)
8502{ 8519{
8503 qeth_old_arp_constructor = arp_tbl.constructor; 8520 qeth_old_arp_constructor = arp_tbl.constructor;
8504 write_lock(&arp_tbl.lock); 8521 write_lock_bh(&arp_tbl.lock);
8505 arp_tbl.constructor = qeth_arp_constructor; 8522 arp_tbl.constructor = qeth_arp_constructor;
8506 write_unlock(&arp_tbl.lock); 8523 write_unlock_bh(&arp_tbl.lock);
8507 8524
8508 arp_direct_ops = (struct neigh_ops*) 8525 arp_direct_ops = (struct neigh_ops*)
8509 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL); 8526 kmalloc(sizeof(struct neigh_ops), GFP_KERNEL);
@@ -8519,9 +8536,9 @@ qeth_ipv6_init(void)
8519static void 8536static void
8520qeth_ipv6_uninit(void) 8537qeth_ipv6_uninit(void)
8521{ 8538{
8522 write_lock(&arp_tbl.lock); 8539 write_lock_bh(&arp_tbl.lock);
8523 arp_tbl.constructor = qeth_old_arp_constructor; 8540 arp_tbl.constructor = qeth_old_arp_constructor;
8524 write_unlock(&arp_tbl.lock); 8541 write_unlock_bh(&arp_tbl.lock);
8525 kfree(arp_direct_ops); 8542 kfree(arp_direct_ops);
8526} 8543}
8527#endif /* CONFIG_QETH_IPV6 */ 8544#endif /* CONFIG_QETH_IPV6 */
@@ -8529,34 +8546,44 @@ qeth_ipv6_uninit(void)
8529static void 8546static void
8530qeth_sysfs_unregister(void) 8547qeth_sysfs_unregister(void)
8531{ 8548{
8549 s390_root_dev_unregister(qeth_root_dev);
8532 qeth_remove_driver_attributes(); 8550 qeth_remove_driver_attributes();
8533 ccw_driver_unregister(&qeth_ccw_driver); 8551 ccw_driver_unregister(&qeth_ccw_driver);
8534 ccwgroup_driver_unregister(&qeth_ccwgroup_driver); 8552 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8535 s390_root_dev_unregister(qeth_root_dev);
8536} 8553}
8554
8537/** 8555/**
8538 * register qeth at sysfs 8556 * register qeth at sysfs
8539 */ 8557 */
8540static int 8558static int
8541qeth_sysfs_register(void) 8559qeth_sysfs_register(void)
8542{ 8560{
8543 int rc=0; 8561 int rc;
8544 8562
8545 rc = ccwgroup_driver_register(&qeth_ccwgroup_driver); 8563 rc = ccwgroup_driver_register(&qeth_ccwgroup_driver);
8546 if (rc) 8564 if (rc)
8547 return rc; 8565 goto out;
8566
8548 rc = ccw_driver_register(&qeth_ccw_driver); 8567 rc = ccw_driver_register(&qeth_ccw_driver);
8549 if (rc) 8568 if (rc)
8550 return rc; 8569 goto out_ccw_driver;
8570
8551 rc = qeth_create_driver_attributes(); 8571 rc = qeth_create_driver_attributes();
8552 if (rc) 8572 if (rc)
8553 return rc; 8573 goto out_qeth_attr;
8574
8554 qeth_root_dev = s390_root_dev_register("qeth"); 8575 qeth_root_dev = s390_root_dev_register("qeth");
8555 if (IS_ERR(qeth_root_dev)) { 8576 rc = IS_ERR(qeth_root_dev) ? PTR_ERR(qeth_root_dev) : 0;
8556 rc = PTR_ERR(qeth_root_dev); 8577 if (!rc)
8557 return rc; 8578 goto out;
8558 } 8579
8559 return 0; 8580 qeth_remove_driver_attributes();
8581out_qeth_attr:
8582 ccw_driver_unregister(&qeth_ccw_driver);
8583out_ccw_driver:
8584 ccwgroup_driver_unregister(&qeth_ccwgroup_driver);
8585out:
8586 return rc;
8560} 8587}
8561 8588
8562/*** 8589/***
@@ -8565,7 +8592,7 @@ qeth_sysfs_register(void)
8565static int __init 8592static int __init
8566qeth_init(void) 8593qeth_init(void)
8567{ 8594{
8568 int rc=0; 8595 int rc;
8569 8596
8570 PRINT_INFO("loading %s\n", version); 8597 PRINT_INFO("loading %s\n", version);
8571 8598
@@ -8574,20 +8601,26 @@ qeth_init(void)
8574 spin_lock_init(&qeth_notify_lock); 8601 spin_lock_init(&qeth_notify_lock);
8575 rwlock_init(&qeth_card_list.rwlock); 8602 rwlock_init(&qeth_card_list.rwlock);
8576 8603
8577 if (qeth_register_dbf_views()) 8604 rc = qeth_register_dbf_views();
8605 if (rc)
8578 goto out_err; 8606 goto out_err;
8579 if (qeth_sysfs_register()) 8607
8580 goto out_sysfs; 8608 rc = qeth_sysfs_register();
8609 if (rc)
8610 goto out_dbf;
8581 8611
8582#ifdef CONFIG_QETH_IPV6 8612#ifdef CONFIG_QETH_IPV6
8583 if (qeth_ipv6_init()) { 8613 rc = qeth_ipv6_init();
8584 PRINT_ERR("Out of memory during ipv6 init.\n"); 8614 if (rc) {
8615 PRINT_ERR("Out of memory during ipv6 init code = %d\n", rc);
8585 goto out_sysfs; 8616 goto out_sysfs;
8586 } 8617 }
8587#endif /* QETH_IPV6 */ 8618#endif /* QETH_IPV6 */
8588 if (qeth_register_notifiers()) 8619 rc = qeth_register_notifiers();
8620 if (rc)
8589 goto out_ipv6; 8621 goto out_ipv6;
8590 if (qeth_create_procfs_entries()) 8622 rc = qeth_create_procfs_entries();
8623 if (rc)
8591 goto out_notifiers; 8624 goto out_notifiers;
8592 8625
8593 return rc; 8626 return rc;
@@ -8597,12 +8630,13 @@ out_notifiers:
8597out_ipv6: 8630out_ipv6:
8598#ifdef CONFIG_QETH_IPV6 8631#ifdef CONFIG_QETH_IPV6
8599 qeth_ipv6_uninit(); 8632 qeth_ipv6_uninit();
8600#endif /* QETH_IPV6 */
8601out_sysfs: 8633out_sysfs:
8634#endif /* QETH_IPV6 */
8602 qeth_sysfs_unregister(); 8635 qeth_sysfs_unregister();
8636out_dbf:
8603 qeth_unregister_dbf_views(); 8637 qeth_unregister_dbf_views();
8604out_err: 8638out_err:
8605 PRINT_ERR("Initialization failed"); 8639 PRINT_ERR("Initialization failed with code %d\n", rc);
8606 return rc; 8640 return rc;
8607} 8641}
8608 8642
diff --git a/drivers/s390/net/qeth_proc.c b/drivers/s390/net/qeth_proc.c
index 66f2da14e6e3..faa768e59257 100644
--- a/drivers/s390/net/qeth_proc.c
+++ b/drivers/s390/net/qeth_proc.c
@@ -173,7 +173,6 @@ static struct file_operations qeth_procfile_fops = {
173#define QETH_PERF_PROCFILE_NAME "qeth_perf" 173#define QETH_PERF_PROCFILE_NAME "qeth_perf"
174static struct proc_dir_entry *qeth_perf_procfile; 174static struct proc_dir_entry *qeth_perf_procfile;
175 175
176#ifdef CONFIG_QETH_PERF_STATS
177static int 176static int
178qeth_perf_procfile_seq_show(struct seq_file *s, void *it) 177qeth_perf_procfile_seq_show(struct seq_file *s, void *it)
179{ 178{
@@ -192,14 +191,21 @@ qeth_perf_procfile_seq_show(struct seq_file *s, void *it)
192 CARD_DDEV_ID(card), 191 CARD_DDEV_ID(card),
193 QETH_CARD_IFNAME(card) 192 QETH_CARD_IFNAME(card)
194 ); 193 );
194 if (!card->options.performance_stats)
195 seq_printf(s, "Performance statistics are deactivated.\n");
195 seq_printf(s, " Skb's/buffers received : %lu/%u\n" 196 seq_printf(s, " Skb's/buffers received : %lu/%u\n"
196 " Skb's/buffers sent : %lu/%u\n\n", 197 " Skb's/buffers sent : %lu/%u\n\n",
197 card->stats.rx_packets, card->perf_stats.bufs_rec, 198 card->stats.rx_packets -
198 card->stats.tx_packets, card->perf_stats.bufs_sent 199 card->perf_stats.initial_rx_packets,
200 card->perf_stats.bufs_rec,
201 card->stats.tx_packets -
202 card->perf_stats.initial_tx_packets,
203 card->perf_stats.bufs_sent
199 ); 204 );
200 seq_printf(s, " Skb's/buffers sent without packing : %lu/%u\n" 205 seq_printf(s, " Skb's/buffers sent without packing : %lu/%u\n"
201 " Skb's/buffers sent with packing : %u/%u\n\n", 206 " Skb's/buffers sent with packing : %u/%u\n\n",
202 card->stats.tx_packets - card->perf_stats.skbs_sent_pack, 207 card->stats.tx_packets - card->perf_stats.initial_tx_packets
208 - card->perf_stats.skbs_sent_pack,
203 card->perf_stats.bufs_sent - card->perf_stats.bufs_sent_pack, 209 card->perf_stats.bufs_sent - card->perf_stats.bufs_sent_pack,
204 card->perf_stats.skbs_sent_pack, 210 card->perf_stats.skbs_sent_pack,
205 card->perf_stats.bufs_sent_pack 211 card->perf_stats.bufs_sent_pack
@@ -275,11 +281,6 @@ static struct file_operations qeth_perf_procfile_fops = {
275 .release = seq_release, 281 .release = seq_release,
276}; 282};
277 283
278#define qeth_perf_procfile_created qeth_perf_procfile
279#else
280#define qeth_perf_procfile_created 1
281#endif /* CONFIG_QETH_PERF_STATS */
282
283int __init 284int __init
284qeth_create_procfs_entries(void) 285qeth_create_procfs_entries(void)
285{ 286{
@@ -288,15 +289,13 @@ qeth_create_procfs_entries(void)
288 if (qeth_procfile) 289 if (qeth_procfile)
289 qeth_procfile->proc_fops = &qeth_procfile_fops; 290 qeth_procfile->proc_fops = &qeth_procfile_fops;
290 291
291#ifdef CONFIG_QETH_PERF_STATS
292 qeth_perf_procfile = create_proc_entry(QETH_PERF_PROCFILE_NAME, 292 qeth_perf_procfile = create_proc_entry(QETH_PERF_PROCFILE_NAME,
293 S_IFREG | 0444, NULL); 293 S_IFREG | 0444, NULL);
294 if (qeth_perf_procfile) 294 if (qeth_perf_procfile)
295 qeth_perf_procfile->proc_fops = &qeth_perf_procfile_fops; 295 qeth_perf_procfile->proc_fops = &qeth_perf_procfile_fops;
296#endif /* CONFIG_QETH_PERF_STATS */
297 296
298 if (qeth_procfile && 297 if (qeth_procfile &&
299 qeth_perf_procfile_created) 298 qeth_perf_procfile)
300 return 0; 299 return 0;
301 else 300 else
302 return -ENOMEM; 301 return -ENOMEM;
diff --git a/drivers/s390/net/qeth_sys.c b/drivers/s390/net/qeth_sys.c
index 185a9cfbcbdc..5836737ac58f 100644
--- a/drivers/s390/net/qeth_sys.c
+++ b/drivers/s390/net/qeth_sys.c
@@ -743,6 +743,47 @@ static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
743 qeth_dev_layer2_store); 743 qeth_dev_layer2_store);
744 744
745static ssize_t 745static ssize_t
746qeth_dev_performance_stats_show(struct device *dev, struct device_attribute *attr, char *buf)
747{
748 struct qeth_card *card = dev->driver_data;
749
750 if (!card)
751 return -EINVAL;
752
753 return sprintf(buf, "%i\n", card->options.performance_stats ? 1:0);
754}
755
756static ssize_t
757qeth_dev_performance_stats_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
758{
759 struct qeth_card *card = dev->driver_data;
760 char *tmp;
761 int i;
762
763 if (!card)
764 return -EINVAL;
765
766 i = simple_strtoul(buf, &tmp, 16);
767 if ((i == 0) || (i == 1)) {
768 if (i == card->options.performance_stats)
769 return count;
770 card->options.performance_stats = i;
771 if (i == 0)
772 memset(&card->perf_stats, 0,
773 sizeof(struct qeth_perf_stats));
774 card->perf_stats.initial_rx_packets = card->stats.rx_packets;
775 card->perf_stats.initial_tx_packets = card->stats.tx_packets;
776 } else {
777 PRINT_WARN("performance_stats: write 0 or 1 to this file!\n");
778 return -EINVAL;
779 }
780 return count;
781}
782
783static DEVICE_ATTR(performance_stats, 0644, qeth_dev_performance_stats_show,
784 qeth_dev_performance_stats_store);
785
786static ssize_t
746qeth_dev_large_send_show(struct device *dev, struct device_attribute *attr, char *buf) 787qeth_dev_large_send_show(struct device *dev, struct device_attribute *attr, char *buf)
747{ 788{
748 struct qeth_card *card = dev->driver_data; 789 struct qeth_card *card = dev->driver_data;
@@ -928,6 +969,7 @@ static struct device_attribute * qeth_device_attrs[] = {
928 &dev_attr_canonical_macaddr, 969 &dev_attr_canonical_macaddr,
929 &dev_attr_layer2, 970 &dev_attr_layer2,
930 &dev_attr_large_send, 971 &dev_attr_large_send,
972 &dev_attr_performance_stats,
931 NULL, 973 NULL,
932}; 974};
933 975
@@ -1110,12 +1152,12 @@ qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
1110{ 1152{
1111 const char *start, *end; 1153 const char *start, *end;
1112 char *tmp; 1154 char *tmp;
1113 char buffer[49] = {0, }; 1155 char buffer[40] = {0, };
1114 1156
1115 start = buf; 1157 start = buf;
1116 /* get address string */ 1158 /* get address string */
1117 end = strchr(start, '/'); 1159 end = strchr(start, '/');
1118 if (!end || (end-start >= 49)){ 1160 if (!end || (end - start >= 40)){
1119 PRINT_WARN("Invalid format for ipato_addx/delx. " 1161 PRINT_WARN("Invalid format for ipato_addx/delx. "
1120 "Use <ip addr>/<mask bits>\n"); 1162 "Use <ip addr>/<mask bits>\n");
1121 return -EINVAL; 1163 return -EINVAL;
@@ -1127,7 +1169,12 @@ qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
1127 } 1169 }
1128 start = end + 1; 1170 start = end + 1;
1129 *mask_bits = simple_strtoul(start, &tmp, 10); 1171 *mask_bits = simple_strtoul(start, &tmp, 10);
1130 1172 if (!strlen(start) ||
1173 (tmp == start) ||
1174 (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
1175 PRINT_WARN("Invalid mask bits for ipato_addx/delx !\n");
1176 return -EINVAL;
1177 }
1131 return 0; 1178 return 0;
1132} 1179}
1133 1180
@@ -1698,11 +1745,16 @@ qeth_create_device_attributes(struct device *dev)
1698 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group); 1745 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1699 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group); 1746 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1700 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group); 1747 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1748 return ret;
1701 } 1749 }
1702 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_blkt_group))) 1750 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_blkt_group))){
1751 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1752 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1753 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1754 sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
1703 return ret; 1755 return ret;
1704 1756 }
1705 return ret; 1757 return 0;
1706} 1758}
1707 1759
1708void 1760void
@@ -1755,7 +1807,7 @@ qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
1755} 1807}
1756 1808
1757 1809
1758static DRIVER_ATTR(group, 0200, 0, qeth_driver_group_store); 1810static DRIVER_ATTR(group, 0200, NULL, qeth_driver_group_store);
1759 1811
1760static ssize_t 1812static ssize_t
1761qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf, 1813qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
@@ -1783,7 +1835,7 @@ qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
1783 return count; 1835 return count;
1784} 1836}
1785 1837
1786static DRIVER_ATTR(notifier_register, 0200, 0, 1838static DRIVER_ATTR(notifier_register, 0200, NULL,
1787 qeth_driver_notifier_register_store); 1839 qeth_driver_notifier_register_store);
1788 1840
1789int 1841int
diff --git a/drivers/s390/net/qeth_tso.h b/drivers/s390/net/qeth_tso.h
index 593f298142c1..14504afb044e 100644
--- a/drivers/s390/net/qeth_tso.h
+++ b/drivers/s390/net/qeth_tso.h
@@ -24,7 +24,7 @@ static inline struct qeth_hdr_tso *
24qeth_tso_prepare_skb(struct qeth_card *card, struct sk_buff **skb) 24qeth_tso_prepare_skb(struct qeth_card *card, struct sk_buff **skb)
25{ 25{
26 QETH_DBF_TEXT(trace, 5, "tsoprsk"); 26 QETH_DBF_TEXT(trace, 5, "tsoprsk");
27 return qeth_push_skb(card, skb, sizeof(struct qeth_hdr_tso)); 27 return qeth_push_skb(card, *skb, sizeof(struct qeth_hdr_tso));
28} 28}
29 29
30/** 30/**
diff --git a/drivers/s390/net/smsgiucv.c b/drivers/s390/net/smsgiucv.c
index 72118ee68954..b8179c27ceb6 100644
--- a/drivers/s390/net/smsgiucv.c
+++ b/drivers/s390/net/smsgiucv.c
@@ -66,7 +66,7 @@ smsg_message_pending(iucv_MessagePending *eib, void *pgm_data)
66 return; 66 return;
67 } 67 }
68 rc = iucv_receive(eib->ippathid, eib->ipmsgid, eib->iptrgcls, 68 rc = iucv_receive(eib->ippathid, eib->ipmsgid, eib->iptrgcls,
69 msg, len, 0, 0, 0); 69 msg, len, NULL, NULL, NULL);
70 if (rc == 0) { 70 if (rc == 0) {
71 msg[len] = 0; 71 msg[len] = 0;
72 EBCASC(msg, len); 72 EBCASC(msg, len);
@@ -122,7 +122,7 @@ smsg_unregister_callback(char *prefix, void (*callback)(char *from, char *str))
122 struct smsg_callback *cb, *tmp; 122 struct smsg_callback *cb, *tmp;
123 123
124 spin_lock(&smsg_list_lock); 124 spin_lock(&smsg_list_lock);
125 cb = 0; 125 cb = NULL;
126 list_for_each_entry(tmp, &smsg_list, list) 126 list_for_each_entry(tmp, &smsg_list, list)
127 if (tmp->callback == callback && 127 if (tmp->callback == callback &&
128 strcmp(tmp->prefix, prefix) == 0) { 128 strcmp(tmp->prefix, prefix) == 0) {
@@ -139,7 +139,7 @@ smsg_exit(void)
139{ 139{
140 if (smsg_handle > 0) { 140 if (smsg_handle > 0) {
141 cpcmd("SET SMSG OFF", NULL, 0, NULL); 141 cpcmd("SET SMSG OFF", NULL, 0, NULL);
142 iucv_sever(smsg_pathid, 0); 142 iucv_sever(smsg_pathid, NULL);
143 iucv_unregister_program(smsg_handle); 143 iucv_unregister_program(smsg_handle);
144 driver_unregister(&smsg_driver); 144 driver_unregister(&smsg_driver);
145 } 145 }
@@ -162,19 +162,19 @@ smsg_init(void)
162 return rc; 162 return rc;
163 } 163 }
164 smsg_handle = iucv_register_program("SMSGIUCV ", "*MSG ", 164 smsg_handle = iucv_register_program("SMSGIUCV ", "*MSG ",
165 pgmmask, &smsg_ops, 0); 165 pgmmask, &smsg_ops, NULL);
166 if (!smsg_handle) { 166 if (!smsg_handle) {
167 printk(KERN_ERR "SMSGIUCV: failed to register to iucv"); 167 printk(KERN_ERR "SMSGIUCV: failed to register to iucv");
168 driver_unregister(&smsg_driver); 168 driver_unregister(&smsg_driver);
169 return -EIO; /* better errno ? */ 169 return -EIO; /* better errno ? */
170 } 170 }
171 rc = iucv_connect (&smsg_pathid, 255, 0, "*MSG ", 0, 0, 0, 0, 171 rc = iucv_connect (&smsg_pathid, 255, NULL, "*MSG ", NULL, 0,
172 smsg_handle, 0); 172 NULL, NULL, smsg_handle, NULL);
173 if (rc) { 173 if (rc) {
174 printk(KERN_ERR "SMSGIUCV: failed to connect to *MSG"); 174 printk(KERN_ERR "SMSGIUCV: failed to connect to *MSG");
175 iucv_unregister_program(smsg_handle); 175 iucv_unregister_program(smsg_handle);
176 driver_unregister(&smsg_driver); 176 driver_unregister(&smsg_driver);
177 smsg_handle = 0; 177 smsg_handle = NULL;
178 return -EIO; 178 return -EIO;
179 } 179 }
180 cpcmd("SET SMSG IUCV", NULL, 0, NULL); 180 cpcmd("SET SMSG IUCV", NULL, 0, NULL);
diff --git a/drivers/s390/s390mach.c b/drivers/s390/s390mach.c
index 432136f96e64..5399c5d99b81 100644
--- a/drivers/s390/s390mach.c
+++ b/drivers/s390/s390mach.c
@@ -111,6 +111,16 @@ repeat:
111 break; 111 break;
112 case CRW_RSC_CPATH: 112 case CRW_RSC_CPATH:
113 pr_debug("source is channel path %02X\n", crw[0].rsid); 113 pr_debug("source is channel path %02X\n", crw[0].rsid);
114 /*
115 * Check for solicited machine checks. These are
116 * created by reset channel path and need not be
117 * reported to the common I/O layer.
118 */
119 if (crw[chain].slct) {
120 DBG(KERN_INFO"solicited machine check for "
121 "channel path %02X\n", crw[0].rsid);
122 break;
123 }
114 switch (crw[0].erc) { 124 switch (crw[0].erc) {
115 case CRW_ERC_IPARM: /* Path has come. */ 125 case CRW_ERC_IPARM: /* Path has come. */
116 ret = chp_process_crw(crw[0].rsid, 1); 126 ret = chp_process_crw(crw[0].rsid, 1);
@@ -378,6 +388,8 @@ s390_do_machine_check(struct pt_regs *regs)
378 struct mcck_struct *mcck; 388 struct mcck_struct *mcck;
379 int umode; 389 int umode;
380 390
391 lockdep_off();
392
381 mci = (struct mci *) &S390_lowcore.mcck_interruption_code; 393 mci = (struct mci *) &S390_lowcore.mcck_interruption_code;
382 mcck = &__get_cpu_var(cpu_mcck); 394 mcck = &__get_cpu_var(cpu_mcck);
383 umode = user_mode(regs); 395 umode = user_mode(regs);
@@ -482,6 +494,7 @@ s390_do_machine_check(struct pt_regs *regs)
482 mcck->warning = 1; 494 mcck->warning = 1;
483 set_thread_flag(TIF_MCCK_PENDING); 495 set_thread_flag(TIF_MCCK_PENDING);
484 } 496 }
497 lockdep_on();
485} 498}
486 499
487/* 500/*
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index 9cd789b8acd4..adc9d8f2c28f 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -112,6 +112,105 @@ _zfcp_hex_dump(char *addr, int count)
112 printk("\n"); 112 printk("\n");
113} 113}
114 114
115
116/****************************************************************/
117/****** Functions to handle the request ID hash table ********/
118/****************************************************************/
119
120#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
121
122static int zfcp_reqlist_init(struct zfcp_adapter *adapter)
123{
124 int i;
125
126 adapter->req_list = kcalloc(REQUEST_LIST_SIZE, sizeof(struct list_head),
127 GFP_KERNEL);
128
129 if (!adapter->req_list)
130 return -ENOMEM;
131
132 for (i=0; i<REQUEST_LIST_SIZE; i++)
133 INIT_LIST_HEAD(&adapter->req_list[i]);
134
135 return 0;
136}
137
138static void zfcp_reqlist_free(struct zfcp_adapter *adapter)
139{
140 struct zfcp_fsf_req *request, *tmp;
141 unsigned int i;
142
143 for (i=0; i<REQUEST_LIST_SIZE; i++) {
144 if (list_empty(&adapter->req_list[i]))
145 continue;
146
147 list_for_each_entry_safe(request, tmp,
148 &adapter->req_list[i], list)
149 list_del(&request->list);
150 }
151
152 kfree(adapter->req_list);
153}
154
155void zfcp_reqlist_add(struct zfcp_adapter *adapter,
156 struct zfcp_fsf_req *fsf_req)
157{
158 unsigned int i;
159
160 i = fsf_req->req_id % REQUEST_LIST_SIZE;
161 list_add_tail(&fsf_req->list, &adapter->req_list[i]);
162}
163
164void zfcp_reqlist_remove(struct zfcp_adapter *adapter, unsigned long req_id)
165{
166 struct zfcp_fsf_req *request, *tmp;
167 unsigned int i, counter;
168 u64 dbg_tmp[2];
169
170 i = req_id % REQUEST_LIST_SIZE;
171 BUG_ON(list_empty(&adapter->req_list[i]));
172
173 counter = 0;
174 list_for_each_entry_safe(request, tmp, &adapter->req_list[i], list) {
175 if (request->req_id == req_id) {
176 dbg_tmp[0] = (u64) atomic_read(&adapter->reqs_active);
177 dbg_tmp[1] = (u64) counter;
178 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
179 list_del(&request->list);
180 break;
181 }
182 counter++;
183 }
184}
185
186struct zfcp_fsf_req *zfcp_reqlist_ismember(struct zfcp_adapter *adapter,
187 unsigned long req_id)
188{
189 struct zfcp_fsf_req *request, *tmp;
190 unsigned int i;
191
192 i = req_id % REQUEST_LIST_SIZE;
193
194 list_for_each_entry_safe(request, tmp, &adapter->req_list[i], list)
195 if (request->req_id == req_id)
196 return request;
197
198 return NULL;
199}
200
201int zfcp_reqlist_isempty(struct zfcp_adapter *adapter)
202{
203 unsigned int i;
204
205 for (i=0; i<REQUEST_LIST_SIZE; i++)
206 if (!list_empty(&adapter->req_list[i]))
207 return 0;
208
209 return 1;
210}
211
212#undef ZFCP_LOG_AREA
213
115/****************************************************************/ 214/****************************************************************/
116/************** Uncategorised Functions *************************/ 215/************** Uncategorised Functions *************************/
117/****************************************************************/ 216/****************************************************************/
@@ -961,8 +1060,12 @@ zfcp_adapter_enqueue(struct ccw_device *ccw_device)
961 INIT_LIST_HEAD(&adapter->port_remove_lh); 1060 INIT_LIST_HEAD(&adapter->port_remove_lh);
962 1061
963 /* initialize list of fsf requests */ 1062 /* initialize list of fsf requests */
964 spin_lock_init(&adapter->fsf_req_list_lock); 1063 spin_lock_init(&adapter->req_list_lock);
965 INIT_LIST_HEAD(&adapter->fsf_req_list_head); 1064 retval = zfcp_reqlist_init(adapter);
1065 if (retval) {
1066 ZFCP_LOG_INFO("request list initialization failed\n");
1067 goto failed_low_mem_buffers;
1068 }
966 1069
967 /* initialize debug locks */ 1070 /* initialize debug locks */
968 1071
@@ -1041,8 +1144,6 @@ zfcp_adapter_enqueue(struct ccw_device *ccw_device)
1041 * !0 - struct zfcp_adapter data structure could not be removed 1144 * !0 - struct zfcp_adapter data structure could not be removed
1042 * (e.g. still used) 1145 * (e.g. still used)
1043 * locks: adapter list write lock is assumed to be held by caller 1146 * locks: adapter list write lock is assumed to be held by caller
1044 * adapter->fsf_req_list_lock is taken and released within this
1045 * function and must not be held on entry
1046 */ 1147 */
1047void 1148void
1048zfcp_adapter_dequeue(struct zfcp_adapter *adapter) 1149zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
@@ -1054,14 +1155,14 @@ zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
1054 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev); 1155 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1055 dev_set_drvdata(&adapter->ccw_device->dev, NULL); 1156 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
1056 /* sanity check: no pending FSF requests */ 1157 /* sanity check: no pending FSF requests */
1057 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags); 1158 spin_lock_irqsave(&adapter->req_list_lock, flags);
1058 retval = !list_empty(&adapter->fsf_req_list_head); 1159 retval = zfcp_reqlist_isempty(adapter);
1059 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags); 1160 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
1060 if (retval) { 1161 if (!retval) {
1061 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, " 1162 ZFCP_LOG_NORMAL("bug: adapter %s (%p) still in use, "
1062 "%i requests outstanding\n", 1163 "%i requests outstanding\n",
1063 zfcp_get_busid_by_adapter(adapter), adapter, 1164 zfcp_get_busid_by_adapter(adapter), adapter,
1064 atomic_read(&adapter->fsf_reqs_active)); 1165 atomic_read(&adapter->reqs_active));
1065 retval = -EBUSY; 1166 retval = -EBUSY;
1066 goto out; 1167 goto out;
1067 } 1168 }
@@ -1087,6 +1188,7 @@ zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
1087 zfcp_free_low_mem_buffers(adapter); 1188 zfcp_free_low_mem_buffers(adapter);
1088 /* free memory of adapter data structure and queues */ 1189 /* free memory of adapter data structure and queues */
1089 zfcp_qdio_free_queues(adapter); 1190 zfcp_qdio_free_queues(adapter);
1191 zfcp_reqlist_free(adapter);
1090 kfree(adapter->fc_stats); 1192 kfree(adapter->fc_stats);
1091 kfree(adapter->stats_reset_data); 1193 kfree(adapter->stats_reset_data);
1092 ZFCP_LOG_TRACE("freeing adapter structure\n"); 1194 ZFCP_LOG_TRACE("freeing adapter structure\n");
diff --git a/drivers/s390/scsi/zfcp_ccw.c b/drivers/s390/scsi/zfcp_ccw.c
index 57d8e4bfb8d9..fdabadeaa9ee 100644
--- a/drivers/s390/scsi/zfcp_ccw.c
+++ b/drivers/s390/scsi/zfcp_ccw.c
@@ -164,6 +164,11 @@ zfcp_ccw_set_online(struct ccw_device *ccw_device)
164 retval = zfcp_adapter_scsi_register(adapter); 164 retval = zfcp_adapter_scsi_register(adapter);
165 if (retval) 165 if (retval)
166 goto out_scsi_register; 166 goto out_scsi_register;
167
168 /* initialize request counter */
169 BUG_ON(!zfcp_reqlist_isempty(adapter));
170 adapter->req_no = 0;
171
167 zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING, 172 zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
168 ZFCP_SET); 173 ZFCP_SET);
169 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED); 174 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
diff --git a/drivers/s390/scsi/zfcp_def.h b/drivers/s390/scsi/zfcp_def.h
index 2df512a18e2c..94d1b74db356 100644
--- a/drivers/s390/scsi/zfcp_def.h
+++ b/drivers/s390/scsi/zfcp_def.h
@@ -52,7 +52,7 @@
52/********************* GENERAL DEFINES *********************************/ 52/********************* GENERAL DEFINES *********************************/
53 53
54/* zfcp version number, it consists of major, minor, and patch-level number */ 54/* zfcp version number, it consists of major, minor, and patch-level number */
55#define ZFCP_VERSION "4.7.0" 55#define ZFCP_VERSION "4.8.0"
56 56
57/** 57/**
58 * zfcp_sg_to_address - determine kernel address from struct scatterlist 58 * zfcp_sg_to_address - determine kernel address from struct scatterlist
@@ -80,7 +80,7 @@ zfcp_address_to_sg(void *address, struct scatterlist *list)
80#define REQUEST_LIST_SIZE 128 80#define REQUEST_LIST_SIZE 128
81 81
82/********************* SCSI SPECIFIC DEFINES *********************************/ 82/********************* SCSI SPECIFIC DEFINES *********************************/
83#define ZFCP_SCSI_ER_TIMEOUT (100*HZ) 83#define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
84 84
85/********************* CIO/QDIO SPECIFIC DEFINES *****************************/ 85/********************* CIO/QDIO SPECIFIC DEFINES *****************************/
86 86
@@ -886,11 +886,11 @@ struct zfcp_adapter {
886 struct list_head port_remove_lh; /* head of ports to be 886 struct list_head port_remove_lh; /* head of ports to be
887 removed */ 887 removed */
888 u32 ports; /* number of remote ports */ 888 u32 ports; /* number of remote ports */
889 struct timer_list scsi_er_timer; /* SCSI err recovery watch */ 889 struct timer_list scsi_er_timer; /* SCSI err recovery watch */
890 struct list_head fsf_req_list_head; /* head of FSF req list */ 890 atomic_t reqs_active; /* # active FSF reqs */
891 spinlock_t fsf_req_list_lock; /* lock for ops on list of 891 unsigned long req_no; /* unique FSF req number */
892 FSF requests */ 892 struct list_head *req_list; /* list of pending reqs */
893 atomic_t fsf_reqs_active; /* # active FSF reqs */ 893 spinlock_t req_list_lock; /* request list lock */
894 struct zfcp_qdio_queue request_queue; /* request queue */ 894 struct zfcp_qdio_queue request_queue; /* request queue */
895 u32 fsf_req_seq_no; /* FSF cmnd seq number */ 895 u32 fsf_req_seq_no; /* FSF cmnd seq number */
896 wait_queue_head_t request_wq; /* can be used to wait for 896 wait_queue_head_t request_wq; /* can be used to wait for
@@ -986,6 +986,7 @@ struct zfcp_unit {
986/* FSF request */ 986/* FSF request */
987struct zfcp_fsf_req { 987struct zfcp_fsf_req {
988 struct list_head list; /* list of FSF requests */ 988 struct list_head list; /* list of FSF requests */
989 unsigned long req_id; /* unique request ID */
989 struct zfcp_adapter *adapter; /* adapter request belongs to */ 990 struct zfcp_adapter *adapter; /* adapter request belongs to */
990 u8 sbal_number; /* nr of SBALs free for use */ 991 u8 sbal_number; /* nr of SBALs free for use */
991 u8 sbal_first; /* first SBAL for this request */ 992 u8 sbal_first; /* first SBAL for this request */
diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c
index 909731b99d26..7f60b6fdf724 100644
--- a/drivers/s390/scsi/zfcp_erp.c
+++ b/drivers/s390/scsi/zfcp_erp.c
@@ -64,8 +64,8 @@ static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
64static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *); 64static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
65static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int); 65static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
66static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *); 66static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
67static int zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *); 67static void zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *);
68static int zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *); 68static void zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *);
69static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *); 69static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
70static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *); 70static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
71static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *); 71static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
@@ -93,10 +93,9 @@ static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
93static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *); 93static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
94static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *); 94static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
95 95
96static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *); 96static void zfcp_erp_action_dismiss_port(struct zfcp_port *);
97static int zfcp_erp_action_dismiss_port(struct zfcp_port *); 97static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
98static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *); 98static void zfcp_erp_action_dismiss(struct zfcp_erp_action *);
99static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
100 99
101static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *, 100static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
102 struct zfcp_port *, struct zfcp_unit *); 101 struct zfcp_port *, struct zfcp_unit *);
@@ -135,29 +134,39 @@ zfcp_fsf_request_timeout_handler(unsigned long data)
135 zfcp_erp_adapter_reopen(adapter, 0); 134 zfcp_erp_adapter_reopen(adapter, 0);
136} 135}
137 136
138/* 137/**
139 * function: zfcp_fsf_scsi_er_timeout_handler 138 * zfcp_fsf_scsi_er_timeout_handler - timeout handler for scsi eh tasks
140 * 139 *
141 * purpose: This function needs to be called whenever a SCSI error recovery 140 * This function needs to be called whenever a SCSI error recovery
142 * action (abort/reset) does not return. 141 * action (abort/reset) does not return. Re-opening the adapter means
143 * Re-opening the adapter means that the command can be returned 142 * that the abort/reset command can be returned by zfcp. It won't complete
144 * by zfcp (it is guarranteed that it does not return via the 143 * via the adapter anymore (because qdio queues are closed). If ERP is
145 * adapter anymore). The buffer can then be used again. 144 * already running on this adapter it will be stopped.
146 *
147 * returns: sod all
148 */ 145 */
149void 146void zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
150zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
151{ 147{
152 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data; 148 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
149 unsigned long flags;
153 150
154 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. " 151 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
155 "Restarting all operations on the adapter %s\n", 152 "Restarting all operations on the adapter %s\n",
156 zfcp_get_busid_by_adapter(adapter)); 153 zfcp_get_busid_by_adapter(adapter));
157 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout"); 154 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
158 zfcp_erp_adapter_reopen(adapter, 0);
159 155
160 return; 156 write_lock_irqsave(&adapter->erp_lock, flags);
157 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
158 &adapter->status)) {
159 zfcp_erp_modify_adapter_status(adapter,
160 ZFCP_STATUS_COMMON_UNBLOCKED|ZFCP_STATUS_COMMON_OPEN,
161 ZFCP_CLEAR);
162 zfcp_erp_action_dismiss_adapter(adapter);
163 write_unlock_irqrestore(&adapter->erp_lock, flags);
164 /* dismiss all pending requests including requests for ERP */
165 zfcp_fsf_req_dismiss_all(adapter);
166 adapter->fsf_req_seq_no = 0;
167 } else
168 write_unlock_irqrestore(&adapter->erp_lock, flags);
169 zfcp_erp_adapter_reopen(adapter, 0);
161} 170}
162 171
163/* 172/*
@@ -670,17 +679,10 @@ zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
670 return retval; 679 return retval;
671} 680}
672 681
673/* 682/**
674 * function: 683 * zfcp_erp_adapter_block - mark adapter as blocked, block scsi requests
675 *
676 * purpose: disable I/O,
677 * return any open requests and clean them up,
678 * aim: no pending and incoming I/O
679 *
680 * returns:
681 */ 684 */
682static void 685static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
683zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
684{ 686{
685 debug_text_event(adapter->erp_dbf, 6, "a_bl"); 687 debug_text_event(adapter->erp_dbf, 6, "a_bl");
686 zfcp_erp_modify_adapter_status(adapter, 688 zfcp_erp_modify_adapter_status(adapter,
@@ -688,15 +690,10 @@ zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
688 clear_mask, ZFCP_CLEAR); 690 clear_mask, ZFCP_CLEAR);
689} 691}
690 692
691/* 693/**
692 * function: 694 * zfcp_erp_adapter_unblock - mark adapter as unblocked, allow scsi requests
693 *
694 * purpose: enable I/O
695 *
696 * returns:
697 */ 695 */
698static void 696static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
699zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
700{ 697{
701 debug_text_event(adapter->erp_dbf, 6, "a_ubl"); 698 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
702 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status); 699 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
@@ -848,18 +845,16 @@ zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
848 struct zfcp_adapter *adapter = erp_action->adapter; 845 struct zfcp_adapter *adapter = erp_action->adapter;
849 846
850 if (erp_action->fsf_req) { 847 if (erp_action->fsf_req) {
851 /* take lock to ensure that request is not being deleted meanwhile */ 848 /* take lock to ensure that request is not deleted meanwhile */
852 spin_lock(&adapter->fsf_req_list_lock); 849 spin_lock(&adapter->req_list_lock);
853 /* check whether fsf req does still exist */ 850 if ((!zfcp_reqlist_ismember(adapter,
854 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list) 851 erp_action->fsf_req->req_id)) &&
855 if (fsf_req == erp_action->fsf_req) 852 (fsf_req->erp_action == erp_action)) {
856 break;
857 if (fsf_req && (fsf_req->erp_action == erp_action)) {
858 /* fsf_req still exists */ 853 /* fsf_req still exists */
859 debug_text_event(adapter->erp_dbf, 3, "a_ca_req"); 854 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
860 debug_event(adapter->erp_dbf, 3, &fsf_req, 855 debug_event(adapter->erp_dbf, 3, &fsf_req,
861 sizeof (unsigned long)); 856 sizeof (unsigned long));
862 /* dismiss fsf_req of timed out or dismissed erp_action */ 857 /* dismiss fsf_req of timed out/dismissed erp_action */
863 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED | 858 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
864 ZFCP_STATUS_ERP_TIMEDOUT)) { 859 ZFCP_STATUS_ERP_TIMEDOUT)) {
865 debug_text_event(adapter->erp_dbf, 3, 860 debug_text_event(adapter->erp_dbf, 3,
@@ -892,30 +887,22 @@ zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
892 */ 887 */
893 erp_action->fsf_req = NULL; 888 erp_action->fsf_req = NULL;
894 } 889 }
895 spin_unlock(&adapter->fsf_req_list_lock); 890 spin_unlock(&adapter->req_list_lock);
896 } else 891 } else
897 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq"); 892 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
898 893
899 return retval; 894 return retval;
900} 895}
901 896
902/* 897/**
903 * purpose: generic handler for asynchronous events related to erp_action events 898 * zfcp_erp_async_handler_nolock - complete erp_action
904 * (normal completion, time-out, dismissing, retry after
905 * low memory condition)
906 *
907 * note: deletion of timer is not required (e.g. in case of a time-out),
908 * but a second try does no harm,
909 * we leave it in here to allow for greater simplification
910 * 899 *
911 * returns: 0 - there was an action to handle 900 * Used for normal completion, time-out, dismissal and failure after
912 * !0 - otherwise 901 * low memory condition.
913 */ 902 */
914static int 903static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
915zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action, 904 unsigned long set_mask)
916 unsigned long set_mask)
917{ 905{
918 int retval;
919 struct zfcp_adapter *adapter = erp_action->adapter; 906 struct zfcp_adapter *adapter = erp_action->adapter;
920 907
921 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) { 908 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
@@ -926,43 +913,26 @@ zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
926 del_timer(&erp_action->timer); 913 del_timer(&erp_action->timer);
927 erp_action->status |= set_mask; 914 erp_action->status |= set_mask;
928 zfcp_erp_action_ready(erp_action); 915 zfcp_erp_action_ready(erp_action);
929 retval = 0;
930 } else { 916 } else {
931 /* action is ready or gone - nothing to do */ 917 /* action is ready or gone - nothing to do */
932 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone"); 918 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
933 debug_event(adapter->erp_dbf, 3, &erp_action->action, 919 debug_event(adapter->erp_dbf, 3, &erp_action->action,
934 sizeof (int)); 920 sizeof (int));
935 retval = 1;
936 } 921 }
937
938 return retval;
939} 922}
940 923
941/* 924/**
942 * purpose: generic handler for asynchronous events related to erp_action 925 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
943 * events (normal completion, time-out, dismissing, retry after
944 * low memory condition)
945 *
946 * note: deletion of timer is not required (e.g. in case of a time-out),
947 * but a second try does no harm,
948 * we leave it in here to allow for greater simplification
949 *
950 * returns: 0 - there was an action to handle
951 * !0 - otherwise
952 */ 926 */
953int 927void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
954zfcp_erp_async_handler(struct zfcp_erp_action *erp_action, 928 unsigned long set_mask)
955 unsigned long set_mask)
956{ 929{
957 struct zfcp_adapter *adapter = erp_action->adapter; 930 struct zfcp_adapter *adapter = erp_action->adapter;
958 unsigned long flags; 931 unsigned long flags;
959 int retval;
960 932
961 write_lock_irqsave(&adapter->erp_lock, flags); 933 write_lock_irqsave(&adapter->erp_lock, flags);
962 retval = zfcp_erp_async_handler_nolock(erp_action, set_mask); 934 zfcp_erp_async_handler_nolock(erp_action, set_mask);
963 write_unlock_irqrestore(&adapter->erp_lock, flags); 935 write_unlock_irqrestore(&adapter->erp_lock, flags);
964
965 return retval;
966} 936}
967 937
968/* 938/*
@@ -999,17 +969,15 @@ zfcp_erp_timeout_handler(unsigned long data)
999 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT); 969 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1000} 970}
1001 971
1002/* 972/**
1003 * purpose: is called for an erp_action which needs to be ended 973 * zfcp_erp_action_dismiss - dismiss an erp_action
1004 * though not being done,
1005 * this is usually required if an higher is generated,
1006 * action gets an appropriate flag and will be processed
1007 * accordingly
1008 * 974 *
1009 * locks: erp_lock held (thus we need to call another handler variant) 975 * adapter->erp_lock must be held
976 *
977 * Dismissal of an erp_action is usually required if an erp_action of
978 * higher priority is generated.
1010 */ 979 */
1011static int 980static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1012zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1013{ 981{
1014 struct zfcp_adapter *adapter = erp_action->adapter; 982 struct zfcp_adapter *adapter = erp_action->adapter;
1015 983
@@ -1017,8 +985,6 @@ zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1017 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int)); 985 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1018 986
1019 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED); 987 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
1020
1021 return 0;
1022} 988}
1023 989
1024int 990int
@@ -2074,18 +2040,12 @@ zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2074 return retval; 2040 return retval;
2075} 2041}
2076 2042
2077/* 2043/**
2078 * function: zfcp_qdio_cleanup 2044 * zfcp_erp_adapter_strategy_close_qdio - close qdio queues for an adapter
2079 *
2080 * purpose: cleans up QDIO operation for the specified adapter
2081 *
2082 * returns: 0 - successful cleanup
2083 * !0 - failed cleanup
2084 */ 2045 */
2085int 2046static void
2086zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action) 2047zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2087{ 2048{
2088 int retval = ZFCP_ERP_SUCCEEDED;
2089 int first_used; 2049 int first_used;
2090 int used_count; 2050 int used_count;
2091 struct zfcp_adapter *adapter = erp_action->adapter; 2051 struct zfcp_adapter *adapter = erp_action->adapter;
@@ -2094,15 +2054,13 @@ zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2094 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO " 2054 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2095 "queues on adapter %s\n", 2055 "queues on adapter %s\n",
2096 zfcp_get_busid_by_adapter(adapter)); 2056 zfcp_get_busid_by_adapter(adapter));
2097 retval = ZFCP_ERP_FAILED; 2057 return;
2098 goto out;
2099 } 2058 }
2100 2059
2101 /* 2060 /*
2102 * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that 2061 * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
2103 * do_QDIO won't be called while qdio_shutdown is in progress. 2062 * do_QDIO won't be called while qdio_shutdown is in progress.
2104 */ 2063 */
2105
2106 write_lock_irq(&adapter->request_queue.queue_lock); 2064 write_lock_irq(&adapter->request_queue.queue_lock);
2107 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status); 2065 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2108 write_unlock_irq(&adapter->request_queue.queue_lock); 2066 write_unlock_irq(&adapter->request_queue.queue_lock);
@@ -2134,8 +2092,6 @@ zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2134 adapter->request_queue.free_index = 0; 2092 adapter->request_queue.free_index = 0;
2135 atomic_set(&adapter->request_queue.free_count, 0); 2093 atomic_set(&adapter->request_queue.free_count, 0);
2136 adapter->request_queue.distance_from_int = 0; 2094 adapter->request_queue.distance_from_int = 0;
2137 out:
2138 return retval;
2139} 2095}
2140 2096
2141static int 2097static int
@@ -2168,9 +2124,9 @@ zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2168 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, 2124 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2169 &adapter->status); 2125 &adapter->status);
2170 ZFCP_LOG_DEBUG("Doing exchange config data\n"); 2126 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2171 write_lock(&adapter->erp_lock); 2127 write_lock_irq(&adapter->erp_lock);
2172 zfcp_erp_action_to_running(erp_action); 2128 zfcp_erp_action_to_running(erp_action);
2173 write_unlock(&adapter->erp_lock); 2129 write_unlock_irq(&adapter->erp_lock);
2174 zfcp_erp_timeout_init(erp_action); 2130 zfcp_erp_timeout_init(erp_action);
2175 if (zfcp_fsf_exchange_config_data(erp_action)) { 2131 if (zfcp_fsf_exchange_config_data(erp_action)) {
2176 retval = ZFCP_ERP_FAILED; 2132 retval = ZFCP_ERP_FAILED;
@@ -2236,9 +2192,9 @@ zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2236 adapter = erp_action->adapter; 2192 adapter = erp_action->adapter;
2237 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); 2193 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2238 2194
2239 write_lock(&adapter->erp_lock); 2195 write_lock_irq(&adapter->erp_lock);
2240 zfcp_erp_action_to_running(erp_action); 2196 zfcp_erp_action_to_running(erp_action);
2241 write_unlock(&adapter->erp_lock); 2197 write_unlock_irq(&adapter->erp_lock);
2242 2198
2243 zfcp_erp_timeout_init(erp_action); 2199 zfcp_erp_timeout_init(erp_action);
2244 ret = zfcp_fsf_exchange_port_data(erp_action, adapter, NULL); 2200 ret = zfcp_fsf_exchange_port_data(erp_action, adapter, NULL);
@@ -2258,11 +2214,11 @@ zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2258 "%s)\n", zfcp_get_busid_by_adapter(adapter)); 2214 "%s)\n", zfcp_get_busid_by_adapter(adapter));
2259 ret = ZFCP_ERP_FAILED; 2215 ret = ZFCP_ERP_FAILED;
2260 } 2216 }
2261 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status)) { 2217
2262 ZFCP_LOG_INFO("error: exchange port data failed (adapter " 2218 /* don't treat as error for the sake of compatibility */
2219 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
2220 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
2263 "%s\n", zfcp_get_busid_by_adapter(adapter)); 2221 "%s\n", zfcp_get_busid_by_adapter(adapter));
2264 ret = ZFCP_ERP_FAILED;
2265 }
2266 2222
2267 return ret; 2223 return ret;
2268} 2224}
@@ -2292,18 +2248,12 @@ zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2292 return retval; 2248 return retval;
2293} 2249}
2294 2250
2295/* 2251/**
2296 * function: zfcp_fsf_cleanup 2252 * zfcp_erp_adapter_strategy_close_fsf - stop FSF operations for an adapter
2297 *
2298 * purpose: cleanup FSF operation for specified adapter
2299 *
2300 * returns: 0 - FSF operation successfully cleaned up
2301 * !0 - failed to cleanup FSF operation for this adapter
2302 */ 2253 */
2303static int 2254static void
2304zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action) 2255zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2305{ 2256{
2306 int retval = ZFCP_ERP_SUCCEEDED;
2307 struct zfcp_adapter *adapter = erp_action->adapter; 2257 struct zfcp_adapter *adapter = erp_action->adapter;
2308 2258
2309 /* 2259 /*
@@ -2317,8 +2267,6 @@ zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2317 /* all ports and units are closed */ 2267 /* all ports and units are closed */
2318 zfcp_erp_modify_adapter_status(adapter, 2268 zfcp_erp_modify_adapter_status(adapter,
2319 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR); 2269 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2320
2321 return retval;
2322} 2270}
2323 2271
2324/* 2272/*
@@ -3293,10 +3241,8 @@ zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3293} 3241}
3294 3242
3295 3243
3296static int 3244void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3297zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3298{ 3245{
3299 int retval = 0;
3300 struct zfcp_port *port; 3246 struct zfcp_port *port;
3301 3247
3302 debug_text_event(adapter->erp_dbf, 5, "a_actab"); 3248 debug_text_event(adapter->erp_dbf, 5, "a_actab");
@@ -3305,14 +3251,10 @@ zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3305 else 3251 else
3306 list_for_each_entry(port, &adapter->port_list_head, list) 3252 list_for_each_entry(port, &adapter->port_list_head, list)
3307 zfcp_erp_action_dismiss_port(port); 3253 zfcp_erp_action_dismiss_port(port);
3308
3309 return retval;
3310} 3254}
3311 3255
3312static int 3256static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3313zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3314{ 3257{
3315 int retval = 0;
3316 struct zfcp_unit *unit; 3258 struct zfcp_unit *unit;
3317 struct zfcp_adapter *adapter = port->adapter; 3259 struct zfcp_adapter *adapter = port->adapter;
3318 3260
@@ -3323,22 +3265,16 @@ zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3323 else 3265 else
3324 list_for_each_entry(unit, &port->unit_list_head, list) 3266 list_for_each_entry(unit, &port->unit_list_head, list)
3325 zfcp_erp_action_dismiss_unit(unit); 3267 zfcp_erp_action_dismiss_unit(unit);
3326
3327 return retval;
3328} 3268}
3329 3269
3330static int 3270static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3331zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3332{ 3271{
3333 int retval = 0;
3334 struct zfcp_adapter *adapter = unit->port->adapter; 3272 struct zfcp_adapter *adapter = unit->port->adapter;
3335 3273
3336 debug_text_event(adapter->erp_dbf, 5, "u_actab"); 3274 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3337 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t)); 3275 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3338 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) 3276 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3339 zfcp_erp_action_dismiss(&unit->erp_action); 3277 zfcp_erp_action_dismiss(&unit->erp_action);
3340
3341 return retval;
3342} 3278}
3343 3279
3344static inline void 3280static inline void
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index d02366004cdd..146d7a2b4c4a 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -63,7 +63,6 @@ extern int zfcp_qdio_allocate_queues(struct zfcp_adapter *);
63extern void zfcp_qdio_free_queues(struct zfcp_adapter *); 63extern void zfcp_qdio_free_queues(struct zfcp_adapter *);
64extern int zfcp_qdio_determine_pci(struct zfcp_qdio_queue *, 64extern int zfcp_qdio_determine_pci(struct zfcp_qdio_queue *,
65 struct zfcp_fsf_req *); 65 struct zfcp_fsf_req *);
66extern int zfcp_qdio_reqid_check(struct zfcp_adapter *, void *);
67 66
68extern volatile struct qdio_buffer_element *zfcp_qdio_sbale_req 67extern volatile struct qdio_buffer_element *zfcp_qdio_sbale_req
69 (struct zfcp_fsf_req *, int, int); 68 (struct zfcp_fsf_req *, int, int);
@@ -140,6 +139,7 @@ extern void zfcp_erp_modify_adapter_status(struct zfcp_adapter *, u32, int);
140extern int zfcp_erp_adapter_reopen(struct zfcp_adapter *, int); 139extern int zfcp_erp_adapter_reopen(struct zfcp_adapter *, int);
141extern int zfcp_erp_adapter_shutdown(struct zfcp_adapter *, int); 140extern int zfcp_erp_adapter_shutdown(struct zfcp_adapter *, int);
142extern void zfcp_erp_adapter_failed(struct zfcp_adapter *); 141extern void zfcp_erp_adapter_failed(struct zfcp_adapter *);
142extern void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
143 143
144extern void zfcp_erp_modify_port_status(struct zfcp_port *, u32, int); 144extern void zfcp_erp_modify_port_status(struct zfcp_port *, u32, int);
145extern int zfcp_erp_port_reopen(struct zfcp_port *, int); 145extern int zfcp_erp_port_reopen(struct zfcp_port *, int);
@@ -156,7 +156,7 @@ extern void zfcp_erp_unit_failed(struct zfcp_unit *);
156extern int zfcp_erp_thread_setup(struct zfcp_adapter *); 156extern int zfcp_erp_thread_setup(struct zfcp_adapter *);
157extern int zfcp_erp_thread_kill(struct zfcp_adapter *); 157extern int zfcp_erp_thread_kill(struct zfcp_adapter *);
158extern int zfcp_erp_wait(struct zfcp_adapter *); 158extern int zfcp_erp_wait(struct zfcp_adapter *);
159extern int zfcp_erp_async_handler(struct zfcp_erp_action *, unsigned long); 159extern void zfcp_erp_async_handler(struct zfcp_erp_action *, unsigned long);
160 160
161extern int zfcp_test_link(struct zfcp_port *); 161extern int zfcp_test_link(struct zfcp_port *);
162 162
@@ -190,5 +190,10 @@ extern void zfcp_scsi_dbf_event_abort(const char *, struct zfcp_adapter *,
190 struct zfcp_fsf_req *); 190 struct zfcp_fsf_req *);
191extern void zfcp_scsi_dbf_event_devreset(const char *, u8, struct zfcp_unit *, 191extern void zfcp_scsi_dbf_event_devreset(const char *, u8, struct zfcp_unit *,
192 struct scsi_cmnd *); 192 struct scsi_cmnd *);
193extern void zfcp_reqlist_add(struct zfcp_adapter *, struct zfcp_fsf_req *);
194extern void zfcp_reqlist_remove(struct zfcp_adapter *, unsigned long);
195extern struct zfcp_fsf_req *zfcp_reqlist_ismember(struct zfcp_adapter *,
196 unsigned long);
197extern int zfcp_reqlist_isempty(struct zfcp_adapter *);
193 198
194#endif /* ZFCP_EXT_H */ 199#endif /* ZFCP_EXT_H */
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
index 6335f9229184..ff2eacf5ec8c 100644
--- a/drivers/s390/scsi/zfcp_fsf.c
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -49,7 +49,6 @@ static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
49static void zfcp_fsf_link_down_info_eval(struct zfcp_adapter *, 49static void zfcp_fsf_link_down_info_eval(struct zfcp_adapter *,
50 struct fsf_link_down_info *); 50 struct fsf_link_down_info *);
51static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *); 51static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
52static void zfcp_fsf_req_dismiss(struct zfcp_fsf_req *);
53 52
54/* association between FSF command and FSF QTCB type */ 53/* association between FSF command and FSF QTCB type */
55static u32 fsf_qtcb_type[] = { 54static u32 fsf_qtcb_type[] = {
@@ -146,47 +145,48 @@ zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
146 kfree(fsf_req); 145 kfree(fsf_req);
147} 146}
148 147
149/* 148/**
150 * function: 149 * zfcp_fsf_req_dismiss - dismiss a single fsf request
151 *
152 * purpose:
153 *
154 * returns:
155 *
156 * note: qdio queues shall be down (no ongoing inbound processing)
157 */ 150 */
158int 151static void zfcp_fsf_req_dismiss(struct zfcp_adapter *adapter,
159zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter) 152 struct zfcp_fsf_req *fsf_req,
153 unsigned int counter)
160{ 154{
161 struct zfcp_fsf_req *fsf_req, *tmp; 155 u64 dbg_tmp[2];
162 unsigned long flags;
163 LIST_HEAD(remove_queue);
164
165 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
166 list_splice_init(&adapter->fsf_req_list_head, &remove_queue);
167 atomic_set(&adapter->fsf_reqs_active, 0);
168 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
169 156
170 list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) { 157 dbg_tmp[0] = (u64) atomic_read(&adapter->reqs_active);
171 list_del(&fsf_req->list); 158 dbg_tmp[1] = (u64) counter;
172 zfcp_fsf_req_dismiss(fsf_req); 159 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
173 } 160 list_del(&fsf_req->list);
174 161 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
175 return 0; 162 zfcp_fsf_req_complete(fsf_req);
176} 163}
177 164
178/* 165/**
179 * function: 166 * zfcp_fsf_req_dismiss_all - dismiss all remaining fsf requests
180 *
181 * purpose:
182 *
183 * returns:
184 */ 167 */
185static void 168int zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
186zfcp_fsf_req_dismiss(struct zfcp_fsf_req *fsf_req)
187{ 169{
188 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; 170 struct zfcp_fsf_req *request, *tmp;
189 zfcp_fsf_req_complete(fsf_req); 171 unsigned long flags;
172 unsigned int i, counter;
173
174 spin_lock_irqsave(&adapter->req_list_lock, flags);
175 atomic_set(&adapter->reqs_active, 0);
176 for (i=0; i<REQUEST_LIST_SIZE; i++) {
177 if (list_empty(&adapter->req_list[i]))
178 continue;
179
180 counter = 0;
181 list_for_each_entry_safe(request, tmp,
182 &adapter->req_list[i], list) {
183 zfcp_fsf_req_dismiss(adapter, request, counter);
184 counter++;
185 }
186 }
187 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
188
189 return 0;
190} 190}
191 191
192/* 192/*
@@ -2227,7 +2227,7 @@ zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
2227 /* setup new FSF request */ 2227 /* setup new FSF request */
2228 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 2228 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2229 erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0, 2229 erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0,
2230 0, &lock_flags, &fsf_req); 2230 NULL, &lock_flags, &fsf_req);
2231 if (retval < 0) { 2231 if (retval < 0) {
2232 ZFCP_LOG_INFO("error: Out of resources. Could not create an " 2232 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2233 "exchange port data request for" 2233 "exchange port data request for"
@@ -4592,12 +4592,14 @@ static inline void
4592zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req) 4592zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4593{ 4593{
4594 if (likely(fsf_req->qtcb != NULL)) { 4594 if (likely(fsf_req->qtcb != NULL)) {
4595 fsf_req->qtcb->prefix.req_seq_no = fsf_req->adapter->fsf_req_seq_no; 4595 fsf_req->qtcb->prefix.req_seq_no =
4596 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req; 4596 fsf_req->adapter->fsf_req_seq_no;
4597 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
4597 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION; 4598 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4598 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_req->fsf_command]; 4599 fsf_req->qtcb->prefix.qtcb_type =
4600 fsf_qtcb_type[fsf_req->fsf_command];
4599 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION; 4601 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4600 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req; 4602 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
4601 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command; 4603 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4602 } 4604 }
4603} 4605}
@@ -4654,6 +4656,7 @@ zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4654{ 4656{
4655 volatile struct qdio_buffer_element *sbale; 4657 volatile struct qdio_buffer_element *sbale;
4656 struct zfcp_fsf_req *fsf_req = NULL; 4658 struct zfcp_fsf_req *fsf_req = NULL;
4659 unsigned long flags;
4657 int ret = 0; 4660 int ret = 0;
4658 struct zfcp_qdio_queue *req_queue = &adapter->request_queue; 4661 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4659 4662
@@ -4668,6 +4671,12 @@ zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4668 4671
4669 fsf_req->adapter = adapter; 4672 fsf_req->adapter = adapter;
4670 fsf_req->fsf_command = fsf_cmd; 4673 fsf_req->fsf_command = fsf_cmd;
4674 INIT_LIST_HEAD(&fsf_req->list);
4675
4676 /* unique request id */
4677 spin_lock_irqsave(&adapter->req_list_lock, flags);
4678 fsf_req->req_id = adapter->req_no++;
4679 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
4671 4680
4672 zfcp_fsf_req_qtcb_init(fsf_req); 4681 zfcp_fsf_req_qtcb_init(fsf_req);
4673 4682
@@ -4707,7 +4716,7 @@ zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4707 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); 4716 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4708 4717
4709 /* setup common SBALE fields */ 4718 /* setup common SBALE fields */
4710 sbale[0].addr = fsf_req; 4719 sbale[0].addr = (void *) fsf_req->req_id;
4711 sbale[0].flags |= SBAL_FLAGS0_COMMAND; 4720 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4712 if (likely(fsf_req->qtcb != NULL)) { 4721 if (likely(fsf_req->qtcb != NULL)) {
4713 sbale[1].addr = (void *) fsf_req->qtcb; 4722 sbale[1].addr = (void *) fsf_req->qtcb;
@@ -4747,7 +4756,7 @@ zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4747 volatile struct qdio_buffer_element *sbale; 4756 volatile struct qdio_buffer_element *sbale;
4748 int inc_seq_no; 4757 int inc_seq_no;
4749 int new_distance_from_int; 4758 int new_distance_from_int;
4750 unsigned long flags; 4759 u64 dbg_tmp[2];
4751 int retval = 0; 4760 int retval = 0;
4752 4761
4753 adapter = fsf_req->adapter; 4762 adapter = fsf_req->adapter;
@@ -4761,10 +4770,10 @@ zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4761 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr, 4770 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4762 sbale[1].length); 4771 sbale[1].length);
4763 4772
4764 /* put allocated FSF request at list tail */ 4773 /* put allocated FSF request into hash table */
4765 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags); 4774 spin_lock(&adapter->req_list_lock);
4766 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head); 4775 zfcp_reqlist_add(adapter, fsf_req);
4767 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags); 4776 spin_unlock(&adapter->req_list_lock);
4768 4777
4769 inc_seq_no = (fsf_req->qtcb != NULL); 4778 inc_seq_no = (fsf_req->qtcb != NULL);
4770 4779
@@ -4803,6 +4812,10 @@ zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4803 QDIO_FLAG_SYNC_OUTPUT, 4812 QDIO_FLAG_SYNC_OUTPUT,
4804 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL); 4813 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4805 4814
4815 dbg_tmp[0] = (unsigned long) sbale[0].addr;
4816 dbg_tmp[1] = (u64) retval;
4817 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
4818
4806 if (unlikely(retval)) { 4819 if (unlikely(retval)) {
4807 /* Queues are down..... */ 4820 /* Queues are down..... */
4808 retval = -EIO; 4821 retval = -EIO;
@@ -4812,22 +4825,17 @@ zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4812 */ 4825 */
4813 if (timer) 4826 if (timer)
4814 del_timer(timer); 4827 del_timer(timer);
4815 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags); 4828 spin_lock(&adapter->req_list_lock);
4816 list_del(&fsf_req->list); 4829 zfcp_reqlist_remove(adapter, fsf_req->req_id);
4817 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags); 4830 spin_unlock(&adapter->req_list_lock);
4818 /* 4831 /* undo changes in request queue made for this request */
4819 * adjust the number of free SBALs in request queue as well as
4820 * position of first one
4821 */
4822 zfcp_qdio_zero_sbals(req_queue->buffer, 4832 zfcp_qdio_zero_sbals(req_queue->buffer,
4823 fsf_req->sbal_first, fsf_req->sbal_number); 4833 fsf_req->sbal_first, fsf_req->sbal_number);
4824 atomic_add(fsf_req->sbal_number, &req_queue->free_count); 4834 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4825 req_queue->free_index -= fsf_req->sbal_number; /* increase */ 4835 req_queue->free_index -= fsf_req->sbal_number;
4826 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q; 4836 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4827 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */ 4837 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4828 ZFCP_LOG_DEBUG 4838 zfcp_erp_adapter_reopen(adapter, 0);
4829 ("error: do_QDIO failed. Buffers could not be enqueued "
4830 "to request queue.\n");
4831 } else { 4839 } else {
4832 req_queue->distance_from_int = new_distance_from_int; 4840 req_queue->distance_from_int = new_distance_from_int;
4833 /* 4841 /*
@@ -4843,7 +4851,7 @@ zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4843 adapter->fsf_req_seq_no++; 4851 adapter->fsf_req_seq_no++;
4844 4852
4845 /* count FSF requests pending */ 4853 /* count FSF requests pending */
4846 atomic_inc(&adapter->fsf_reqs_active); 4854 atomic_inc(&adapter->reqs_active);
4847 } 4855 }
4848 return retval; 4856 return retval;
4849} 4857}
diff --git a/drivers/s390/scsi/zfcp_qdio.c b/drivers/s390/scsi/zfcp_qdio.c
index 345a191926a4..dbd9f48e863e 100644
--- a/drivers/s390/scsi/zfcp_qdio.c
+++ b/drivers/s390/scsi/zfcp_qdio.c
@@ -282,6 +282,37 @@ zfcp_qdio_request_handler(struct ccw_device *ccw_device,
282 return; 282 return;
283} 283}
284 284
285/**
286 * zfcp_qdio_reqid_check - checks for valid reqids or unsolicited status
287 */
288static int zfcp_qdio_reqid_check(struct zfcp_adapter *adapter,
289 unsigned long req_id)
290{
291 struct zfcp_fsf_req *fsf_req;
292 unsigned long flags;
293
294 debug_long_event(adapter->erp_dbf, 4, req_id);
295
296 spin_lock_irqsave(&adapter->req_list_lock, flags);
297 fsf_req = zfcp_reqlist_ismember(adapter, req_id);
298
299 if (!fsf_req) {
300 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
301 ZFCP_LOG_NORMAL("error: unknown request id (%ld).\n", req_id);
302 zfcp_erp_adapter_reopen(adapter, 0);
303 return -EINVAL;
304 }
305
306 zfcp_reqlist_remove(adapter, req_id);
307 atomic_dec(&adapter->reqs_active);
308 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
309
310 /* finish the FSF request */
311 zfcp_fsf_req_complete(fsf_req);
312
313 return 0;
314}
315
285/* 316/*
286 * function: zfcp_qdio_response_handler 317 * function: zfcp_qdio_response_handler
287 * 318 *
@@ -344,7 +375,7 @@ zfcp_qdio_response_handler(struct ccw_device *ccw_device,
344 /* look for QDIO request identifiers in SB */ 375 /* look for QDIO request identifiers in SB */
345 buffere = &buffer->element[buffere_index]; 376 buffere = &buffer->element[buffere_index];
346 retval = zfcp_qdio_reqid_check(adapter, 377 retval = zfcp_qdio_reqid_check(adapter,
347 (void *) buffere->addr); 378 (unsigned long) buffere->addr);
348 379
349 if (retval) { 380 if (retval) {
350 ZFCP_LOG_NORMAL("bug: unexpected inbound " 381 ZFCP_LOG_NORMAL("bug: unexpected inbound "
@@ -415,51 +446,6 @@ zfcp_qdio_response_handler(struct ccw_device *ccw_device,
415 return; 446 return;
416} 447}
417 448
418/*
419 * function: zfcp_qdio_reqid_check
420 *
421 * purpose: checks for valid reqids or unsolicited status
422 *
423 * returns: 0 - valid request id or unsolicited status
424 * !0 - otherwise
425 */
426int
427zfcp_qdio_reqid_check(struct zfcp_adapter *adapter, void *sbale_addr)
428{
429 struct zfcp_fsf_req *fsf_req;
430
431 /* invalid (per convention used in this driver) */
432 if (unlikely(!sbale_addr)) {
433 ZFCP_LOG_NORMAL("bug: invalid reqid\n");
434 return -EINVAL;
435 }
436
437 /* valid request id and thus (hopefully :) valid fsf_req address */
438 fsf_req = (struct zfcp_fsf_req *) sbale_addr;
439
440 /* serialize with zfcp_fsf_req_dismiss_all */
441 spin_lock(&adapter->fsf_req_list_lock);
442 if (list_empty(&adapter->fsf_req_list_head)) {
443 spin_unlock(&adapter->fsf_req_list_lock);
444 return 0;
445 }
446 list_del(&fsf_req->list);
447 atomic_dec(&adapter->fsf_reqs_active);
448 spin_unlock(&adapter->fsf_req_list_lock);
449
450 if (unlikely(adapter != fsf_req->adapter)) {
451 ZFCP_LOG_NORMAL("bug: invalid reqid (fsf_req=%p, "
452 "fsf_req->adapter=%p, adapter=%p)\n",
453 fsf_req, fsf_req->adapter, adapter);
454 return -EINVAL;
455 }
456
457 /* finish the FSF request */
458 zfcp_fsf_req_complete(fsf_req);
459
460 return 0;
461}
462
463/** 449/**
464 * zfcp_qdio_sbale_get - return pointer to SBALE of qdio_queue 450 * zfcp_qdio_sbale_get - return pointer to SBALE of qdio_queue
465 * @queue: queue from which SBALE should be returned 451 * @queue: queue from which SBALE should be returned
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index 46e14f22ec18..1bb55086db9f 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -30,7 +30,6 @@ static int zfcp_scsi_queuecommand(struct scsi_cmnd *,
30 void (*done) (struct scsi_cmnd *)); 30 void (*done) (struct scsi_cmnd *));
31static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *); 31static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *);
32static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *); 32static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *);
33static int zfcp_scsi_eh_bus_reset_handler(struct scsi_cmnd *);
34static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *); 33static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *);
35static int zfcp_task_management_function(struct zfcp_unit *, u8, 34static int zfcp_task_management_function(struct zfcp_unit *, u8,
36 struct scsi_cmnd *); 35 struct scsi_cmnd *);
@@ -44,33 +43,24 @@ struct scsi_transport_template *zfcp_transport_template;
44 43
45struct zfcp_data zfcp_data = { 44struct zfcp_data zfcp_data = {
46 .scsi_host_template = { 45 .scsi_host_template = {
47 name: ZFCP_NAME, 46 .name = ZFCP_NAME,
48 proc_name: "zfcp", 47 .proc_name = "zfcp",
49 proc_info: NULL, 48 .slave_alloc = zfcp_scsi_slave_alloc,
50 detect: NULL, 49 .slave_configure = zfcp_scsi_slave_configure,
51 slave_alloc: zfcp_scsi_slave_alloc, 50 .slave_destroy = zfcp_scsi_slave_destroy,
52 slave_configure: zfcp_scsi_slave_configure, 51 .queuecommand = zfcp_scsi_queuecommand,
53 slave_destroy: zfcp_scsi_slave_destroy, 52 .eh_abort_handler = zfcp_scsi_eh_abort_handler,
54 queuecommand: zfcp_scsi_queuecommand, 53 .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler,
55 eh_abort_handler: zfcp_scsi_eh_abort_handler, 54 .eh_bus_reset_handler = zfcp_scsi_eh_host_reset_handler,
56 eh_device_reset_handler: zfcp_scsi_eh_device_reset_handler, 55 .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler,
57 eh_bus_reset_handler: zfcp_scsi_eh_bus_reset_handler, 56 .can_queue = 4096,
58 eh_host_reset_handler: zfcp_scsi_eh_host_reset_handler, 57 .this_id = -1,
59 /* FIXME(openfcp): Tune */ 58 .sg_tablesize = ZFCP_MAX_SBALES_PER_REQ,
60 can_queue: 4096, 59 .cmd_per_lun = 1,
61 this_id: -1, 60 .use_clustering = 1,
62 /* 61 .sdev_attrs = zfcp_sysfs_sdev_attrs,
63 * FIXME:
64 * one less? can zfcp_create_sbale cope with it?
65 */
66 sg_tablesize: ZFCP_MAX_SBALES_PER_REQ,
67 cmd_per_lun: 1,
68 unchecked_isa_dma: 0,
69 use_clustering: 1,
70 sdev_attrs: zfcp_sysfs_sdev_attrs,
71 }, 62 },
72 .driver_version = ZFCP_VERSION, 63 .driver_version = ZFCP_VERSION,
73 /* rest initialised with zeros */
74}; 64};
75 65
76/* Find start of Response Information in FCP response unit*/ 66/* Find start of Response Information in FCP response unit*/
@@ -177,8 +167,14 @@ zfcp_scsi_slave_alloc(struct scsi_device *sdp)
177 return retval; 167 return retval;
178} 168}
179 169
180static void 170/**
181zfcp_scsi_slave_destroy(struct scsi_device *sdpnt) 171 * zfcp_scsi_slave_destroy - called when scsi device is removed
172 *
173 * Remove reference to associated scsi device for an zfcp_unit.
174 * Mark zfcp_unit as failed. The scsi device might be deleted via sysfs
175 * or a scan for this device might have failed.
176 */
177static void zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
182{ 178{
183 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata; 179 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata;
184 180
@@ -186,6 +182,7 @@ zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
186 atomic_clear_mask(ZFCP_STATUS_UNIT_REGISTERED, &unit->status); 182 atomic_clear_mask(ZFCP_STATUS_UNIT_REGISTERED, &unit->status);
187 sdpnt->hostdata = NULL; 183 sdpnt->hostdata = NULL;
188 unit->device = NULL; 184 unit->device = NULL;
185 zfcp_erp_unit_failed(unit);
189 zfcp_unit_put(unit); 186 zfcp_unit_put(unit);
190 } else { 187 } else {
191 ZFCP_LOG_NORMAL("bug: no unit associated with SCSI device at " 188 ZFCP_LOG_NORMAL("bug: no unit associated with SCSI device at "
@@ -550,35 +547,38 @@ zfcp_task_management_function(struct zfcp_unit *unit, u8 tm_flags,
550} 547}
551 548
552/** 549/**
553 * zfcp_scsi_eh_bus_reset_handler - reset bus (reopen adapter) 550 * zfcp_scsi_eh_host_reset_handler - handler for host and bus reset
551 *
552 * If ERP is already running it will be stopped.
554 */ 553 */
555int 554int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
556zfcp_scsi_eh_bus_reset_handler(struct scsi_cmnd *scpnt)
557{ 555{
558 struct zfcp_unit *unit = (struct zfcp_unit*) scpnt->device->hostdata; 556 struct zfcp_unit *unit;
559 struct zfcp_adapter *adapter = unit->port->adapter; 557 struct zfcp_adapter *adapter;
560 558 unsigned long flags;
561 ZFCP_LOG_NORMAL("bus reset because of problems with "
562 "unit 0x%016Lx\n", unit->fcp_lun);
563 zfcp_erp_adapter_reopen(adapter, 0);
564 zfcp_erp_wait(adapter);
565
566 return SUCCESS;
567}
568 559
569/** 560 unit = (struct zfcp_unit*) scpnt->device->hostdata;
570 * zfcp_scsi_eh_host_reset_handler - reset host (reopen adapter) 561 adapter = unit->port->adapter;
571 */
572int
573zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
574{
575 struct zfcp_unit *unit = (struct zfcp_unit*) scpnt->device->hostdata;
576 struct zfcp_adapter *adapter = unit->port->adapter;
577 562
578 ZFCP_LOG_NORMAL("host reset because of problems with " 563 ZFCP_LOG_NORMAL("host/bus reset because of problems with "
579 "unit 0x%016Lx\n", unit->fcp_lun); 564 "unit 0x%016Lx\n", unit->fcp_lun);
580 zfcp_erp_adapter_reopen(adapter, 0); 565
581 zfcp_erp_wait(adapter); 566 write_lock_irqsave(&adapter->erp_lock, flags);
567 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
568 &adapter->status)) {
569 zfcp_erp_modify_adapter_status(adapter,
570 ZFCP_STATUS_COMMON_UNBLOCKED|ZFCP_STATUS_COMMON_OPEN,
571 ZFCP_CLEAR);
572 zfcp_erp_action_dismiss_adapter(adapter);
573 write_unlock_irqrestore(&adapter->erp_lock, flags);
574 zfcp_fsf_req_dismiss_all(adapter);
575 adapter->fsf_req_seq_no = 0;
576 zfcp_erp_adapter_reopen(adapter, 0);
577 } else {
578 write_unlock_irqrestore(&adapter->erp_lock, flags);
579 zfcp_erp_adapter_reopen(adapter, 0);
580 zfcp_erp_wait(adapter);
581 }
582 582
583 return SUCCESS; 583 return SUCCESS;
584} 584}
diff --git a/drivers/sbus/sbus.c b/drivers/sbus/sbus.c
index 16b59773c0bb..935952ef88f1 100644
--- a/drivers/sbus/sbus.c
+++ b/drivers/sbus/sbus.c
@@ -233,7 +233,7 @@ static void __init build_one_sbus(struct device_node *dp, int num_sbus)
233 sbus->ofdev.node = dp; 233 sbus->ofdev.node = dp;
234 sbus->ofdev.dev.parent = NULL; 234 sbus->ofdev.dev.parent = NULL;
235 sbus->ofdev.dev.bus = &sbus_bus_type; 235 sbus->ofdev.dev.bus = &sbus_bus_type;
236 strcpy(sbus->ofdev.dev.bus_id, dp->path_component_name); 236 sprintf(sbus->ofdev.dev.bus_id, "sbus%d", num_sbus);
237 237
238 if (of_device_register(&sbus->ofdev) != 0) 238 if (of_device_register(&sbus->ofdev) != 0)
239 printk(KERN_DEBUG "sbus: device registration error for %s!\n", 239 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index eb7a6a4ded75..657a3ab75399 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -173,6 +173,7 @@ STATIC int NCR_700_bus_reset(struct scsi_cmnd * SCpnt);
173STATIC int NCR_700_host_reset(struct scsi_cmnd * SCpnt); 173STATIC int NCR_700_host_reset(struct scsi_cmnd * SCpnt);
174STATIC void NCR_700_chip_setup(struct Scsi_Host *host); 174STATIC void NCR_700_chip_setup(struct Scsi_Host *host);
175STATIC void NCR_700_chip_reset(struct Scsi_Host *host); 175STATIC void NCR_700_chip_reset(struct Scsi_Host *host);
176STATIC int NCR_700_slave_alloc(struct scsi_device *SDpnt);
176STATIC int NCR_700_slave_configure(struct scsi_device *SDpnt); 177STATIC int NCR_700_slave_configure(struct scsi_device *SDpnt);
177STATIC void NCR_700_slave_destroy(struct scsi_device *SDpnt); 178STATIC void NCR_700_slave_destroy(struct scsi_device *SDpnt);
178static int NCR_700_change_queue_depth(struct scsi_device *SDpnt, int depth); 179static int NCR_700_change_queue_depth(struct scsi_device *SDpnt, int depth);
@@ -182,10 +183,6 @@ STATIC struct device_attribute *NCR_700_dev_attrs[];
182 183
183STATIC struct scsi_transport_template *NCR_700_transport_template = NULL; 184STATIC struct scsi_transport_template *NCR_700_transport_template = NULL;
184 185
185struct NCR_700_sense {
186 unsigned char cmnd[MAX_COMMAND_SIZE];
187};
188
189static char *NCR_700_phase[] = { 186static char *NCR_700_phase[] = {
190 "", 187 "",
191 "after selection", 188 "after selection",
@@ -333,6 +330,7 @@ NCR_700_detect(struct scsi_host_template *tpnt,
333 tpnt->use_clustering = ENABLE_CLUSTERING; 330 tpnt->use_clustering = ENABLE_CLUSTERING;
334 tpnt->slave_configure = NCR_700_slave_configure; 331 tpnt->slave_configure = NCR_700_slave_configure;
335 tpnt->slave_destroy = NCR_700_slave_destroy; 332 tpnt->slave_destroy = NCR_700_slave_destroy;
333 tpnt->slave_alloc = NCR_700_slave_alloc;
336 tpnt->change_queue_depth = NCR_700_change_queue_depth; 334 tpnt->change_queue_depth = NCR_700_change_queue_depth;
337 tpnt->change_queue_type = NCR_700_change_queue_type; 335 tpnt->change_queue_type = NCR_700_change_queue_type;
338 336
@@ -611,9 +609,10 @@ NCR_700_scsi_done(struct NCR_700_Host_Parameters *hostdata,
611 struct NCR_700_command_slot *slot = 609 struct NCR_700_command_slot *slot =
612 (struct NCR_700_command_slot *)SCp->host_scribble; 610 (struct NCR_700_command_slot *)SCp->host_scribble;
613 611
614 NCR_700_unmap(hostdata, SCp, slot); 612 dma_unmap_single(hostdata->dev, slot->pCmd,
613 sizeof(SCp->cmnd), DMA_TO_DEVICE);
615 if (slot->flags == NCR_700_FLAG_AUTOSENSE) { 614 if (slot->flags == NCR_700_FLAG_AUTOSENSE) {
616 struct NCR_700_sense *sense = SCp->device->hostdata; 615 char *cmnd = NCR_700_get_sense_cmnd(SCp->device);
617#ifdef NCR_700_DEBUG 616#ifdef NCR_700_DEBUG
618 printk(" ORIGINAL CMD %p RETURNED %d, new return is %d sense is\n", 617 printk(" ORIGINAL CMD %p RETURNED %d, new return is %d sense is\n",
619 SCp, SCp->cmnd[7], result); 618 SCp, SCp->cmnd[7], result);
@@ -624,10 +623,9 @@ NCR_700_scsi_done(struct NCR_700_Host_Parameters *hostdata,
624 /* restore the old result if the request sense was 623 /* restore the old result if the request sense was
625 * successful */ 624 * successful */
626 if(result == 0) 625 if(result == 0)
627 result = sense->cmnd[7]; 626 result = cmnd[7];
628 } else 627 } else
629 dma_unmap_single(hostdata->dev, slot->pCmd, 628 NCR_700_unmap(hostdata, SCp, slot);
630 sizeof(SCp->cmnd), DMA_TO_DEVICE);
631 629
632 free_slot(slot, hostdata); 630 free_slot(slot, hostdata);
633#ifdef NCR_700_DEBUG 631#ifdef NCR_700_DEBUG
@@ -969,14 +967,15 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp,
969 status_byte(hostdata->status[0]) == COMMAND_TERMINATED) { 967 status_byte(hostdata->status[0]) == COMMAND_TERMINATED) {
970 struct NCR_700_command_slot *slot = 968 struct NCR_700_command_slot *slot =
971 (struct NCR_700_command_slot *)SCp->host_scribble; 969 (struct NCR_700_command_slot *)SCp->host_scribble;
972 if(SCp->cmnd[0] == REQUEST_SENSE) { 970 if(slot->flags == NCR_700_FLAG_AUTOSENSE) {
973 /* OOPS: bad device, returning another 971 /* OOPS: bad device, returning another
974 * contingent allegiance condition */ 972 * contingent allegiance condition */
975 scmd_printk(KERN_ERR, SCp, 973 scmd_printk(KERN_ERR, SCp,
976 "broken device is looping in contingent allegiance: ignoring\n"); 974 "broken device is looping in contingent allegiance: ignoring\n");
977 NCR_700_scsi_done(hostdata, SCp, hostdata->status[0]); 975 NCR_700_scsi_done(hostdata, SCp, hostdata->status[0]);
978 } else { 976 } else {
979 struct NCR_700_sense *sense = SCp->device->hostdata; 977 char *cmnd =
978 NCR_700_get_sense_cmnd(SCp->device);
980#ifdef NCR_DEBUG 979#ifdef NCR_DEBUG
981 scsi_print_command(SCp); 980 scsi_print_command(SCp);
982 printk(" cmd %p has status %d, requesting sense\n", 981 printk(" cmd %p has status %d, requesting sense\n",
@@ -994,21 +993,21 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp,
994 sizeof(SCp->cmnd), 993 sizeof(SCp->cmnd),
995 DMA_TO_DEVICE); 994 DMA_TO_DEVICE);
996 995
997 sense->cmnd[0] = REQUEST_SENSE; 996 cmnd[0] = REQUEST_SENSE;
998 sense->cmnd[1] = (SCp->device->lun & 0x7) << 5; 997 cmnd[1] = (SCp->device->lun & 0x7) << 5;
999 sense->cmnd[2] = 0; 998 cmnd[2] = 0;
1000 sense->cmnd[3] = 0; 999 cmnd[3] = 0;
1001 sense->cmnd[4] = sizeof(SCp->sense_buffer); 1000 cmnd[4] = sizeof(SCp->sense_buffer);
1002 sense->cmnd[5] = 0; 1001 cmnd[5] = 0;
1003 /* Here's a quiet hack: the 1002 /* Here's a quiet hack: the
1004 * REQUEST_SENSE command is six bytes, 1003 * REQUEST_SENSE command is six bytes,
1005 * so store a flag indicating that 1004 * so store a flag indicating that
1006 * this was an internal sense request 1005 * this was an internal sense request
1007 * and the original status at the end 1006 * and the original status at the end
1008 * of the command */ 1007 * of the command */
1009 sense->cmnd[6] = NCR_700_INTERNAL_SENSE_MAGIC; 1008 cmnd[6] = NCR_700_INTERNAL_SENSE_MAGIC;
1010 sense->cmnd[7] = hostdata->status[0]; 1009 cmnd[7] = hostdata->status[0];
1011 slot->pCmd = dma_map_single(hostdata->dev, sense->cmnd, sizeof(sense->cmnd), DMA_TO_DEVICE); 1010 slot->pCmd = dma_map_single(hostdata->dev, cmnd, MAX_COMMAND_SIZE, DMA_TO_DEVICE);
1012 slot->dma_handle = dma_map_single(hostdata->dev, SCp->sense_buffer, sizeof(SCp->sense_buffer), DMA_FROM_DEVICE); 1011 slot->dma_handle = dma_map_single(hostdata->dev, SCp->sense_buffer, sizeof(SCp->sense_buffer), DMA_FROM_DEVICE);
1013 slot->SG[0].ins = bS_to_host(SCRIPT_MOVE_DATA_IN | sizeof(SCp->sense_buffer)); 1012 slot->SG[0].ins = bS_to_host(SCRIPT_MOVE_DATA_IN | sizeof(SCp->sense_buffer));
1014 slot->SG[0].pAddr = bS_to_host(slot->dma_handle); 1013 slot->SG[0].pAddr = bS_to_host(slot->dma_handle);
@@ -1530,7 +1529,7 @@ NCR_700_intr(int irq, void *dev_id, struct pt_regs *regs)
1530 1529
1531 /* clear all the negotiated parameters */ 1530 /* clear all the negotiated parameters */
1532 __shost_for_each_device(SDp, host) 1531 __shost_for_each_device(SDp, host)
1533 SDp->hostdata = NULL; 1532 NCR_700_clear_flag(SDp, ~0);
1534 1533
1535 /* clear all the slots and their pending commands */ 1534 /* clear all the slots and their pending commands */
1536 for(i = 0; i < NCR_700_COMMAND_SLOTS_PER_HOST; i++) { 1535 for(i = 0; i < NCR_700_COMMAND_SLOTS_PER_HOST; i++) {
@@ -2035,7 +2034,17 @@ NCR_700_set_offset(struct scsi_target *STp, int offset)
2035 spi_flags(STp) |= NCR_700_DEV_PRINT_SYNC_NEGOTIATION; 2034 spi_flags(STp) |= NCR_700_DEV_PRINT_SYNC_NEGOTIATION;
2036} 2035}
2037 2036
2037STATIC int
2038NCR_700_slave_alloc(struct scsi_device *SDp)
2039{
2040 SDp->hostdata = kzalloc(sizeof(struct NCR_700_Device_Parameters),
2041 GFP_KERNEL);
2038 2042
2043 if (!SDp->hostdata)
2044 return -ENOMEM;
2045
2046 return 0;
2047}
2039 2048
2040STATIC int 2049STATIC int
2041NCR_700_slave_configure(struct scsi_device *SDp) 2050NCR_700_slave_configure(struct scsi_device *SDp)
@@ -2043,11 +2052,6 @@ NCR_700_slave_configure(struct scsi_device *SDp)
2043 struct NCR_700_Host_Parameters *hostdata = 2052 struct NCR_700_Host_Parameters *hostdata =
2044 (struct NCR_700_Host_Parameters *)SDp->host->hostdata[0]; 2053 (struct NCR_700_Host_Parameters *)SDp->host->hostdata[0];
2045 2054
2046 SDp->hostdata = kmalloc(GFP_KERNEL, sizeof(struct NCR_700_sense));
2047
2048 if (!SDp->hostdata)
2049 return -ENOMEM;
2050
2051 /* to do here: allocate memory; build a queue_full list */ 2055 /* to do here: allocate memory; build a queue_full list */
2052 if(SDp->tagged_supported) { 2056 if(SDp->tagged_supported) {
2053 scsi_set_tag_type(SDp, MSG_ORDERED_TAG); 2057 scsi_set_tag_type(SDp, MSG_ORDERED_TAG);
diff --git a/drivers/scsi/53c700.h b/drivers/scsi/53c700.h
index 7f22a06fe5ec..97ebe71b701b 100644
--- a/drivers/scsi/53c700.h
+++ b/drivers/scsi/53c700.h
@@ -12,7 +12,7 @@
12#include <asm/io.h> 12#include <asm/io.h>
13 13
14#include <scsi/scsi_device.h> 14#include <scsi/scsi_device.h>
15 15#include <scsi/scsi_cmnd.h>
16 16
17/* Turn on for general debugging---too verbose for normal use */ 17/* Turn on for general debugging---too verbose for normal use */
18#undef NCR_700_DEBUG 18#undef NCR_700_DEBUG
@@ -76,11 +76,16 @@ struct NCR_700_SG_List {
76 #define SCRIPT_RETURN 0x90080000 76 #define SCRIPT_RETURN 0x90080000
77}; 77};
78 78
79/* We use device->hostdata to store negotiated parameters. This is 79struct NCR_700_Device_Parameters {
80 * supposed to be a pointer to a device private area, but we cannot 80 /* space for creating a request sense command. Really, except
81 * really use it as such since it will never be freed, so just use the 81 * for the annoying SCSI-2 requirement for LUN information in
82 * 32 bits to cram the information. The SYNC negotiation sequence looks 82 * cmnd[1], this could be in static storage */
83 * like: 83 unsigned char cmnd[MAX_COMMAND_SIZE];
84 __u8 depth;
85};
86
87
88/* The SYNC negotiation sequence looks like:
84 * 89 *
85 * If DEV_NEGOTIATED_SYNC not set, tack and SDTR message on to the 90 * If DEV_NEGOTIATED_SYNC not set, tack and SDTR message on to the
86 * initial identify for the device and set DEV_BEGIN_SYNC_NEGOTATION 91 * initial identify for the device and set DEV_BEGIN_SYNC_NEGOTATION
@@ -98,19 +103,26 @@ struct NCR_700_SG_List {
98#define NCR_700_DEV_BEGIN_SYNC_NEGOTIATION (1<<17) 103#define NCR_700_DEV_BEGIN_SYNC_NEGOTIATION (1<<17)
99#define NCR_700_DEV_PRINT_SYNC_NEGOTIATION (1<<19) 104#define NCR_700_DEV_PRINT_SYNC_NEGOTIATION (1<<19)
100 105
106static inline char *NCR_700_get_sense_cmnd(struct scsi_device *SDp)
107{
108 struct NCR_700_Device_Parameters *hostdata = SDp->hostdata;
109
110 return hostdata->cmnd;
111}
112
101static inline void 113static inline void
102NCR_700_set_depth(struct scsi_device *SDp, __u8 depth) 114NCR_700_set_depth(struct scsi_device *SDp, __u8 depth)
103{ 115{
104 long l = (long)SDp->hostdata; 116 struct NCR_700_Device_Parameters *hostdata = SDp->hostdata;
105 117
106 l &= 0xffff00ff; 118 hostdata->depth = depth;
107 l |= 0xff00 & (depth << 8);
108 SDp->hostdata = (void *)l;
109} 119}
110static inline __u8 120static inline __u8
111NCR_700_get_depth(struct scsi_device *SDp) 121NCR_700_get_depth(struct scsi_device *SDp)
112{ 122{
113 return ((((unsigned long)SDp->hostdata) & 0xff00)>>8); 123 struct NCR_700_Device_Parameters *hostdata = SDp->hostdata;
124
125 return hostdata->depth;
114} 126}
115static inline int 127static inline int
116NCR_700_is_flag_set(struct scsi_device *SDp, __u32 flag) 128NCR_700_is_flag_set(struct scsi_device *SDp, __u32 flag)
diff --git a/drivers/scsi/53c7xx.c b/drivers/scsi/53c7xx.c
index c690c2b89e41..acf292736b4e 100644
--- a/drivers/scsi/53c7xx.c
+++ b/drivers/scsi/53c7xx.c
@@ -3451,12 +3451,12 @@ create_cmd (Scsi_Cmnd *cmd) {
3451 for (i = 0; cmd->use_sg ? (i < cmd->use_sg) : !i; cmd_datain += 4, 3451 for (i = 0; cmd->use_sg ? (i < cmd->use_sg) : !i; cmd_datain += 4,
3452 cmd_dataout += 4, ++i) { 3452 cmd_dataout += 4, ++i) {
3453 u32 vbuf = cmd->use_sg 3453 u32 vbuf = cmd->use_sg
3454 ? (u32)page_address(((struct scatterlist *)cmd->buffer)[i].page)+ 3454 ? (u32)page_address(((struct scatterlist *)cmd->request_buffer)[i].page)+
3455 ((struct scatterlist *)cmd->buffer)[i].offset 3455 ((struct scatterlist *)cmd->request_buffer)[i].offset
3456 : (u32)(cmd->request_buffer); 3456 : (u32)(cmd->request_buffer);
3457 u32 bbuf = virt_to_bus((void *)vbuf); 3457 u32 bbuf = virt_to_bus((void *)vbuf);
3458 u32 count = cmd->use_sg ? 3458 u32 count = cmd->use_sg ?
3459 ((struct scatterlist *)cmd->buffer)[i].length : 3459 ((struct scatterlist *)cmd->request_buffer)[i].length :
3460 cmd->request_bufflen; 3460 cmd->request_bufflen;
3461 3461
3462 /* 3462 /*
@@ -5417,7 +5417,7 @@ insn_to_offset (Scsi_Cmnd *cmd, u32 *insn) {
5417 5417
5418 if ((buffers = cmd->use_sg)) { 5418 if ((buffers = cmd->use_sg)) {
5419 for (offset = 0, 5419 for (offset = 0,
5420 segment = (struct scatterlist *) cmd->buffer; 5420 segment = (struct scatterlist *) cmd->request_buffer;
5421 buffers && !((found = ((ptr >= (char *)page_address(segment->page)+segment->offset) && 5421 buffers && !((found = ((ptr >= (char *)page_address(segment->page)+segment->offset) &&
5422 (ptr < ((char *)page_address(segment->page)+segment->offset+segment->length))))); 5422 (ptr < ((char *)page_address(segment->page)+segment->offset+segment->length)))));
5423 --buffers, offset += segment->length, ++segment) 5423 --buffers, offset += segment->length, ++segment)
diff --git a/drivers/scsi/NCR53C9x.c b/drivers/scsi/NCR53C9x.c
index 8a4659e94105..bdc6bb262bce 100644
--- a/drivers/scsi/NCR53C9x.c
+++ b/drivers/scsi/NCR53C9x.c
@@ -911,7 +911,7 @@ static void esp_get_dmabufs(struct NCR_ESP *esp, Scsi_Cmnd *sp)
911 sp->SCp.ptr = 911 sp->SCp.ptr =
912 (char *) virt_to_phys(sp->request_buffer); 912 (char *) virt_to_phys(sp->request_buffer);
913 } else { 913 } else {
914 sp->SCp.buffer = (struct scatterlist *) sp->buffer; 914 sp->SCp.buffer = (struct scatterlist *) sp->request_buffer;
915 sp->SCp.buffers_residual = sp->use_sg - 1; 915 sp->SCp.buffers_residual = sp->use_sg - 1;
916 sp->SCp.this_residual = sp->SCp.buffer->length; 916 sp->SCp.this_residual = sp->SCp.buffer->length;
917 if (esp->dma_mmu_get_scsi_sgl) 917 if (esp->dma_mmu_get_scsi_sgl)
@@ -2152,29 +2152,23 @@ static int esp_do_data_finale(struct NCR_ESP *esp,
2152 */ 2152 */
2153static int esp_should_clear_sync(Scsi_Cmnd *sp) 2153static int esp_should_clear_sync(Scsi_Cmnd *sp)
2154{ 2154{
2155 unchar cmd1 = sp->cmnd[0]; 2155 unchar cmd = sp->cmnd[0];
2156 unchar cmd2 = sp->data_cmnd[0];
2157 2156
2158 /* These cases are for spinning up a disk and 2157 /* These cases are for spinning up a disk and
2159 * waiting for that spinup to complete. 2158 * waiting for that spinup to complete.
2160 */ 2159 */
2161 if(cmd1 == START_STOP || 2160 if(cmd == START_STOP)
2162 cmd2 == START_STOP)
2163 return 0; 2161 return 0;
2164 2162
2165 if(cmd1 == TEST_UNIT_READY || 2163 if(cmd == TEST_UNIT_READY)
2166 cmd2 == TEST_UNIT_READY)
2167 return 0; 2164 return 0;
2168 2165
2169 /* One more special case for SCSI tape drives, 2166 /* One more special case for SCSI tape drives,
2170 * this is what is used to probe the device for 2167 * this is what is used to probe the device for
2171 * completion of a rewind or tape load operation. 2168 * completion of a rewind or tape load operation.
2172 */ 2169 */
2173 if(sp->device->type == TYPE_TAPE) { 2170 if(sp->device->type == TYPE_TAPE && cmd == MODE_SENSE)
2174 if(cmd1 == MODE_SENSE || 2171 return 0;
2175 cmd2 == MODE_SENSE)
2176 return 0;
2177 }
2178 2172
2179 return 1; 2173 return 1;
2180} 2174}
diff --git a/drivers/scsi/NCR_D700.c b/drivers/scsi/NCR_D700.c
index a06f547e87f7..d05681f9d81a 100644
--- a/drivers/scsi/NCR_D700.c
+++ b/drivers/scsi/NCR_D700.c
@@ -114,7 +114,7 @@ MODULE_DESCRIPTION("NCR Dual700 SCSI Driver");
114MODULE_LICENSE("GPL"); 114MODULE_LICENSE("GPL");
115module_param(NCR_D700, charp, 0); 115module_param(NCR_D700, charp, 0);
116 116
117static __u8 __initdata id_array[2*(MCA_MAX_SLOT_NR + 1)] = 117static __u8 __devinitdata id_array[2*(MCA_MAX_SLOT_NR + 1)] =
118 { [0 ... 2*(MCA_MAX_SLOT_NR + 1)-1] = 7 }; 118 { [0 ... 2*(MCA_MAX_SLOT_NR + 1)-1] = 7 };
119 119
120#ifdef MODULE 120#ifdef MODULE
@@ -173,7 +173,7 @@ struct NCR_D700_private {
173 char pad; 173 char pad;
174}; 174};
175 175
176static int 176static int __devinit
177NCR_D700_probe_one(struct NCR_D700_private *p, int siop, int irq, 177NCR_D700_probe_one(struct NCR_D700_private *p, int siop, int irq,
178 int slot, u32 region, int differential) 178 int slot, u32 region, int differential)
179{ 179{
@@ -243,7 +243,7 @@ NCR_D700_intr(int irq, void *data, struct pt_regs *regs)
243 * essentially connectecd to the MCA bus independently, it is easier 243 * essentially connectecd to the MCA bus independently, it is easier
244 * to set them up as two separate host adapters, rather than one 244 * to set them up as two separate host adapters, rather than one
245 * adapter with two channels */ 245 * adapter with two channels */
246static int 246static int __devinit
247NCR_D700_probe(struct device *dev) 247NCR_D700_probe(struct device *dev)
248{ 248{
249 struct NCR_D700_private *p; 249 struct NCR_D700_private *p;
@@ -329,7 +329,7 @@ NCR_D700_probe(struct device *dev)
329 for (i = 0; i < 2; i++) { 329 for (i = 0; i < 2; i++) {
330 int err; 330 int err;
331 331
332 if ((err = NCR_D700_probe_one(p, i, slot, irq, 332 if ((err = NCR_D700_probe_one(p, i, irq, slot,
333 offset_addr + (0x80 * i), 333 offset_addr + (0x80 * i),
334 differential)) != 0) 334 differential)) != 0)
335 printk("D700: SIOP%d: probe failed, error = %d\n", 335 printk("D700: SIOP%d: probe failed, error = %d\n",
@@ -349,7 +349,7 @@ NCR_D700_probe(struct device *dev)
349 return 0; 349 return 0;
350} 350}
351 351
352static void 352static void __devexit
353NCR_D700_remove_one(struct Scsi_Host *host) 353NCR_D700_remove_one(struct Scsi_Host *host)
354{ 354{
355 scsi_remove_host(host); 355 scsi_remove_host(host);
@@ -359,7 +359,7 @@ NCR_D700_remove_one(struct Scsi_Host *host)
359 release_region(host->base, 64); 359 release_region(host->base, 64);
360} 360}
361 361
362static int 362static int __devexit
363NCR_D700_remove(struct device *dev) 363NCR_D700_remove(struct device *dev)
364{ 364{
365 struct NCR_D700_private *p = dev_get_drvdata(dev); 365 struct NCR_D700_private *p = dev_get_drvdata(dev);
@@ -380,7 +380,7 @@ static struct mca_driver NCR_D700_driver = {
380 .name = "NCR_D700", 380 .name = "NCR_D700",
381 .bus = &mca_bus_type, 381 .bus = &mca_bus_type,
382 .probe = NCR_D700_probe, 382 .probe = NCR_D700_probe,
383 .remove = NCR_D700_remove, 383 .remove = __devexit_p(NCR_D700_remove),
384 }, 384 },
385}; 385};
386 386
diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c
index 7cea514e810a..1cd3584ba7ff 100644
--- a/drivers/scsi/aacraid/comminit.c
+++ b/drivers/scsi/aacraid/comminit.c
@@ -92,31 +92,7 @@ static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long co
92 init->AdapterFibsPhysicalAddress = cpu_to_le32((u32)phys); 92 init->AdapterFibsPhysicalAddress = cpu_to_le32((u32)phys);
93 init->AdapterFibsSize = cpu_to_le32(fibsize); 93 init->AdapterFibsSize = cpu_to_le32(fibsize);
94 init->AdapterFibAlign = cpu_to_le32(sizeof(struct hw_fib)); 94 init->AdapterFibAlign = cpu_to_le32(sizeof(struct hw_fib));
95 /* 95 init->HostPhysMemPages = cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES);
96 * number of 4k pages of host physical memory. The aacraid fw needs
97 * this number to be less than 4gb worth of pages. num_physpages is in
98 * system page units. New firmware doesn't have any issues with the
99 * mapping system, but older Firmware did, and had *troubles* dealing
100 * with the math overloading past 32 bits, thus we must limit this
101 * field.
102 *
103 * This assumes the memory is mapped zero->n, which isnt
104 * always true on real computers. It also has some slight problems
105 * with the GART on x86-64. I've btw never tried DMA from PCI space
106 * on this platform but don't be surprised if its problematic.
107 * [AK: something is very very wrong when a driver tests this symbol.
108 * Someone should figure out what the comment writer really meant here and fix
109 * the code. Or just remove that bad code. ]
110 */
111#ifndef CONFIG_IOMMU
112 if ((num_physpages << (PAGE_SHIFT - 12)) <= AAC_MAX_HOSTPHYSMEMPAGES) {
113 init->HostPhysMemPages =
114 cpu_to_le32(num_physpages << (PAGE_SHIFT-12));
115 } else
116#endif
117 {
118 init->HostPhysMemPages = cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES);
119 }
120 96
121 init->InitFlags = 0; 97 init->InitFlags = 0;
122 if (dev->new_comm_interface) { 98 if (dev->new_comm_interface) {
diff --git a/drivers/scsi/aha152x.c b/drivers/scsi/aha152x.c
index 36e63f82d9f8..f974869ea323 100644
--- a/drivers/scsi/aha152x.c
+++ b/drivers/scsi/aha152x.c
@@ -551,6 +551,11 @@ struct aha152x_hostdata {
551struct aha152x_scdata { 551struct aha152x_scdata {
552 Scsi_Cmnd *next; /* next sc in queue */ 552 Scsi_Cmnd *next; /* next sc in queue */
553 struct semaphore *sem; /* semaphore to block on */ 553 struct semaphore *sem; /* semaphore to block on */
554 unsigned char cmd_len;
555 unsigned char cmnd[MAX_COMMAND_SIZE];
556 unsigned short use_sg;
557 unsigned request_bufflen;
558 void *request_buffer;
554}; 559};
555 560
556 561
@@ -1006,11 +1011,20 @@ static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct semaphore *sem, int p
1006 return FAILED; 1011 return FAILED;
1007 } 1012 }
1008 } else { 1013 } else {
1014 struct aha152x_scdata *sc;
1015
1009 SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC); 1016 SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC);
1010 if(SCpnt->host_scribble==0) { 1017 if(SCpnt->host_scribble==0) {
1011 printk(ERR_LEAD "allocation failed\n", CMDINFO(SCpnt)); 1018 printk(ERR_LEAD "allocation failed\n", CMDINFO(SCpnt));
1012 return FAILED; 1019 return FAILED;
1013 } 1020 }
1021
1022 sc = SCDATA(SCpnt);
1023 memcpy(sc->cmnd, SCpnt->cmnd, sizeof(sc->cmnd));
1024 sc->request_buffer = SCpnt->request_buffer;
1025 sc->request_bufflen = SCpnt->request_bufflen;
1026 sc->use_sg = SCpnt->use_sg;
1027 sc->cmd_len = SCpnt->cmd_len;
1014 } 1028 }
1015 1029
1016 SCNEXT(SCpnt) = NULL; 1030 SCNEXT(SCpnt) = NULL;
@@ -1165,6 +1179,10 @@ static int aha152x_device_reset(Scsi_Cmnd * SCpnt)
1165 DECLARE_MUTEX_LOCKED(sem); 1179 DECLARE_MUTEX_LOCKED(sem);
1166 struct timer_list timer; 1180 struct timer_list timer;
1167 int ret, issued, disconnected; 1181 int ret, issued, disconnected;
1182 unsigned char old_cmd_len = SCpnt->cmd_len;
1183 unsigned short old_use_sg = SCpnt->use_sg;
1184 void *old_buffer = SCpnt->request_buffer;
1185 unsigned old_bufflen = SCpnt->request_bufflen;
1168 unsigned long flags; 1186 unsigned long flags;
1169 1187
1170#if defined(AHA152X_DEBUG) 1188#if defined(AHA152X_DEBUG)
@@ -1198,11 +1216,11 @@ static int aha152x_device_reset(Scsi_Cmnd * SCpnt)
1198 add_timer(&timer); 1216 add_timer(&timer);
1199 down(&sem); 1217 down(&sem);
1200 del_timer(&timer); 1218 del_timer(&timer);
1201 1219
1202 SCpnt->cmd_len = SCpnt->old_cmd_len; 1220 SCpnt->cmd_len = old_cmd_len;
1203 SCpnt->use_sg = SCpnt->old_use_sg; 1221 SCpnt->use_sg = old_use_sg;
1204 SCpnt->request_buffer = SCpnt->buffer; 1222 SCpnt->request_buffer = old_buffer;
1205 SCpnt->request_bufflen = SCpnt->bufflen; 1223 SCpnt->request_bufflen = old_bufflen;
1206 1224
1207 DO_LOCK(flags); 1225 DO_LOCK(flags);
1208 1226
@@ -1565,6 +1583,9 @@ static void busfree_run(struct Scsi_Host *shpnt)
1565#endif 1583#endif
1566 1584
1567 if(DONE_SC->SCp.phase & check_condition) { 1585 if(DONE_SC->SCp.phase & check_condition) {
1586 struct scsi_cmnd *cmd = HOSTDATA(shpnt)->done_SC;
1587 struct aha152x_scdata *sc = SCDATA(cmd);
1588
1568#if 0 1589#if 0
1569 if(HOSTDATA(shpnt)->debug & debug_eh) { 1590 if(HOSTDATA(shpnt)->debug & debug_eh) {
1570 printk(ERR_LEAD "received sense: ", CMDINFO(DONE_SC)); 1591 printk(ERR_LEAD "received sense: ", CMDINFO(DONE_SC));
@@ -1573,13 +1594,13 @@ static void busfree_run(struct Scsi_Host *shpnt)
1573#endif 1594#endif
1574 1595
1575 /* restore old command */ 1596 /* restore old command */
1576 memcpy((void *) DONE_SC->cmnd, (void *) DONE_SC->data_cmnd, sizeof(DONE_SC->data_cmnd)); 1597 memcpy(cmd->cmnd, sc->cmnd, sizeof(sc->cmnd));
1577 DONE_SC->request_buffer = DONE_SC->buffer; 1598 cmd->request_buffer = sc->request_buffer;
1578 DONE_SC->request_bufflen = DONE_SC->bufflen; 1599 cmd->request_bufflen = sc->request_bufflen;
1579 DONE_SC->use_sg = DONE_SC->old_use_sg; 1600 cmd->use_sg = sc->use_sg;
1580 DONE_SC->cmd_len = DONE_SC->old_cmd_len; 1601 cmd->cmd_len = sc->cmd_len;
1581 1602
1582 DONE_SC->SCp.Status = 0x02; 1603 cmd->SCp.Status = 0x02;
1583 1604
1584 HOSTDATA(shpnt)->commands--; 1605 HOSTDATA(shpnt)->commands--;
1585 if (!HOSTDATA(shpnt)->commands) 1606 if (!HOSTDATA(shpnt)->commands)
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 15f6cd4279b7..904c25fb4ba4 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -940,14 +940,8 @@ static void ahci_host_intr(struct ata_port *ap)
940 return; 940 return;
941 941
942 /* ignore interim PIO setup fis interrupts */ 942 /* ignore interim PIO setup fis interrupts */
943 if (ata_tag_valid(ap->active_tag)) { 943 if (ata_tag_valid(ap->active_tag) && (status & PORT_IRQ_PIOS_FIS))
944 struct ata_queued_cmd *qc = 944 return;
945 ata_qc_from_tag(ap, ap->active_tag);
946
947 if (qc && qc->tf.protocol == ATA_PROT_PIO &&
948 (status & PORT_IRQ_PIOS_FIS))
949 return;
950 }
951 945
952 if (ata_ratelimit()) 946 if (ata_ratelimit())
953 ata_port_printk(ap, KERN_INFO, "spurious interrupt " 947 ata_port_printk(ap, KERN_INFO, "spurious interrupt "
@@ -1052,7 +1046,7 @@ static void ahci_thaw(struct ata_port *ap)
1052 1046
1053static void ahci_error_handler(struct ata_port *ap) 1047static void ahci_error_handler(struct ata_port *ap)
1054{ 1048{
1055 if (!(ap->flags & ATA_FLAG_FROZEN)) { 1049 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
1056 /* restart engine */ 1050 /* restart engine */
1057 ahci_stop_engine(ap); 1051 ahci_stop_engine(ap);
1058 ahci_start_engine(ap); 1052 ahci_start_engine(ap);
@@ -1323,6 +1317,17 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1323 if (!printed_version++) 1317 if (!printed_version++)
1324 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1318 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1325 1319
1320 /* JMicron-specific fixup: make sure we're in AHCI mode */
1321 /* This is protected from races with ata_jmicron by the pci probe
1322 locking */
1323 if (pdev->vendor == PCI_VENDOR_ID_JMICRON) {
1324 /* AHCI enable, AHCI on function 0 */
1325 pci_write_config_byte(pdev, 0x41, 0xa1);
1326 /* Function 1 is the PATA controller */
1327 if (PCI_FUNC(pdev->devfn))
1328 return -ENODEV;
1329 }
1330
1326 rc = pci_enable_device(pdev); 1331 rc = pci_enable_device(pdev);
1327 if (rc) 1332 if (rc)
1328 return rc; 1333 return rc;
@@ -1378,10 +1383,6 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1378 if (have_msi) 1383 if (have_msi)
1379 hpriv->flags |= AHCI_FLAG_MSI; 1384 hpriv->flags |= AHCI_FLAG_MSI;
1380 1385
1381 /* JMicron-specific fixup: make sure we're in AHCI mode */
1382 if (pdev->vendor == 0x197b)
1383 pci_write_config_byte(pdev, 0x41, 0xa1);
1384
1385 /* initialize adapter */ 1386 /* initialize adapter */
1386 rc = ahci_host_init(probe_ent); 1387 rc = ahci_host_init(probe_ent);
1387 if (rc) 1388 if (rc)
diff --git a/drivers/scsi/aic7xxx/aic79xx.h b/drivers/scsi/aic7xxx/aic79xx.h
index eb7745692682..df3346b5caf8 100644
--- a/drivers/scsi/aic7xxx/aic79xx.h
+++ b/drivers/scsi/aic7xxx/aic79xx.h
@@ -1487,6 +1487,7 @@ typedef enum {
1487} ahd_queue_alg; 1487} ahd_queue_alg;
1488 1488
1489void ahd_set_tags(struct ahd_softc *ahd, 1489void ahd_set_tags(struct ahd_softc *ahd,
1490 struct scsi_cmnd *cmd,
1490 struct ahd_devinfo *devinfo, 1491 struct ahd_devinfo *devinfo,
1491 ahd_queue_alg alg); 1492 ahd_queue_alg alg);
1492 1493
diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c
index 801fc81d0b20..653818d2f802 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -1090,7 +1090,7 @@ ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat)
1090 1090
1091 /* Notify XPT */ 1091 /* Notify XPT */
1092 ahd_send_async(ahd, devinfo.channel, devinfo.target, 1092 ahd_send_async(ahd, devinfo.channel, devinfo.target,
1093 CAM_LUN_WILDCARD, AC_SENT_BDR, NULL); 1093 CAM_LUN_WILDCARD, AC_SENT_BDR);
1094 1094
1095 /* 1095 /*
1096 * Allow the sequencer to continue with 1096 * Allow the sequencer to continue with
@@ -3062,7 +3062,7 @@ ahd_set_syncrate(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3062 tinfo->curr.ppr_options = ppr_options; 3062 tinfo->curr.ppr_options = ppr_options;
3063 3063
3064 ahd_send_async(ahd, devinfo->channel, devinfo->target, 3064 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3065 CAM_LUN_WILDCARD, AC_TRANSFER_NEG, NULL); 3065 CAM_LUN_WILDCARD, AC_TRANSFER_NEG);
3066 if (bootverbose) { 3066 if (bootverbose) {
3067 if (offset != 0) { 3067 if (offset != 0) {
3068 int options; 3068 int options;
@@ -3184,7 +3184,7 @@ ahd_set_width(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3184 3184
3185 tinfo->curr.width = width; 3185 tinfo->curr.width = width;
3186 ahd_send_async(ahd, devinfo->channel, devinfo->target, 3186 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3187 CAM_LUN_WILDCARD, AC_TRANSFER_NEG, NULL); 3187 CAM_LUN_WILDCARD, AC_TRANSFER_NEG);
3188 if (bootverbose) { 3188 if (bootverbose) {
3189 printf("%s: target %d using %dbit transfers\n", 3189 printf("%s: target %d using %dbit transfers\n",
3190 ahd_name(ahd), devinfo->target, 3190 ahd_name(ahd), devinfo->target,
@@ -3211,12 +3211,14 @@ ahd_set_width(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3211 * Update the current state of tagged queuing for a given target. 3211 * Update the current state of tagged queuing for a given target.
3212 */ 3212 */
3213void 3213void
3214ahd_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo, 3214ahd_set_tags(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
3215 ahd_queue_alg alg) 3215 struct ahd_devinfo *devinfo, ahd_queue_alg alg)
3216{ 3216{
3217 ahd_platform_set_tags(ahd, devinfo, alg); 3217 struct scsi_device *sdev = cmd->device;
3218
3219 ahd_platform_set_tags(ahd, sdev, devinfo, alg);
3218 ahd_send_async(ahd, devinfo->channel, devinfo->target, 3220 ahd_send_async(ahd, devinfo->channel, devinfo->target,
3219 devinfo->lun, AC_TRANSFER_NEG, &alg); 3221 devinfo->lun, AC_TRANSFER_NEG);
3220} 3222}
3221 3223
3222static void 3224static void
@@ -4746,7 +4748,7 @@ ahd_handle_msg_reject(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4746 printf("(%s:%c:%d:%d): refuses tagged commands. " 4748 printf("(%s:%c:%d:%d): refuses tagged commands. "
4747 "Performing non-tagged I/O\n", ahd_name(ahd), 4749 "Performing non-tagged I/O\n", ahd_name(ahd),
4748 devinfo->channel, devinfo->target, devinfo->lun); 4750 devinfo->channel, devinfo->target, devinfo->lun);
4749 ahd_set_tags(ahd, devinfo, AHD_QUEUE_NONE); 4751 ahd_set_tags(ahd, scb->io_ctx, devinfo, AHD_QUEUE_NONE);
4750 mask = ~0x23; 4752 mask = ~0x23;
4751 } else { 4753 } else {
4752 printf("(%s:%c:%d:%d): refuses %s tagged commands. " 4754 printf("(%s:%c:%d:%d): refuses %s tagged commands. "
@@ -4754,7 +4756,7 @@ ahd_handle_msg_reject(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4754 ahd_name(ahd), devinfo->channel, devinfo->target, 4756 ahd_name(ahd), devinfo->channel, devinfo->target,
4755 devinfo->lun, tag_type == MSG_ORDERED_TASK 4757 devinfo->lun, tag_type == MSG_ORDERED_TASK
4756 ? "ordered" : "head of queue"); 4758 ? "ordered" : "head of queue");
4757 ahd_set_tags(ahd, devinfo, AHD_QUEUE_BASIC); 4759 ahd_set_tags(ahd, scb->io_ctx, devinfo, AHD_QUEUE_BASIC);
4758 mask = ~0x03; 4760 mask = ~0x03;
4759 } 4761 }
4760 4762
@@ -5098,7 +5100,7 @@ ahd_handle_devreset(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
5098 5100
5099 if (status != CAM_SEL_TIMEOUT) 5101 if (status != CAM_SEL_TIMEOUT)
5100 ahd_send_async(ahd, devinfo->channel, devinfo->target, 5102 ahd_send_async(ahd, devinfo->channel, devinfo->target,
5101 CAM_LUN_WILDCARD, AC_SENT_BDR, NULL); 5103 CAM_LUN_WILDCARD, AC_SENT_BDR);
5102 5104
5103 if (message != NULL && bootverbose) 5105 if (message != NULL && bootverbose)
5104 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahd_name(ahd), 5106 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahd_name(ahd),
@@ -7287,7 +7289,7 @@ ahd_reset_cmds_pending(struct ahd_softc *ahd)
7287 ahd->flags &= ~AHD_UPDATE_PEND_CMDS; 7289 ahd->flags &= ~AHD_UPDATE_PEND_CMDS;
7288} 7290}
7289 7291
7290void 7292static void
7291ahd_done_with_status(struct ahd_softc *ahd, struct scb *scb, uint32_t status) 7293ahd_done_with_status(struct ahd_softc *ahd, struct scb *scb, uint32_t status)
7292{ 7294{
7293 cam_status ostat; 7295 cam_status ostat;
@@ -7952,7 +7954,7 @@ ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
7952#endif 7954#endif
7953 /* Notify the XPT that a bus reset occurred */ 7955 /* Notify the XPT that a bus reset occurred */
7954 ahd_send_async(ahd, devinfo.channel, CAM_TARGET_WILDCARD, 7956 ahd_send_async(ahd, devinfo.channel, CAM_TARGET_WILDCARD,
7955 CAM_LUN_WILDCARD, AC_BUS_RESET, NULL); 7957 CAM_LUN_WILDCARD, AC_BUS_RESET);
7956 7958
7957 /* 7959 /*
7958 * Revert to async/narrow transfers until we renegotiate. 7960 * Revert to async/narrow transfers until we renegotiate.
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index e0ccdf362200..998999c0a972 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -243,25 +243,6 @@ ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
243static uint32_t aic79xx_no_reset; 243static uint32_t aic79xx_no_reset;
244 244
245/* 245/*
246 * Certain PCI motherboards will scan PCI devices from highest to lowest,
247 * others scan from lowest to highest, and they tend to do all kinds of
248 * strange things when they come into contact with PCI bridge chips. The
249 * net result of all this is that the PCI card that is actually used to boot
250 * the machine is very hard to detect. Most motherboards go from lowest
251 * PCI slot number to highest, and the first SCSI controller found is the
252 * one you boot from. The only exceptions to this are when a controller
253 * has its BIOS disabled. So, we by default sort all of our SCSI controllers
254 * from lowest PCI slot number to highest PCI slot number. We also force
255 * all controllers with their BIOS disabled to the end of the list. This
256 * works on *almost* all computers. Where it doesn't work, we have this
257 * option. Setting this option to non-0 will reverse the order of the sort
258 * to highest first, then lowest, but will still leave cards with their BIOS
259 * disabled at the very end. That should fix everyone up unless there are
260 * really strange cirumstances.
261 */
262static uint32_t aic79xx_reverse_scan;
263
264/*
265 * Should we force EXTENDED translation on a controller. 246 * Should we force EXTENDED translation on a controller.
266 * 0 == Use whatever is in the SEEPROM or default to off 247 * 0 == Use whatever is in the SEEPROM or default to off
267 * 1 == Use whatever is in the SEEPROM or default to on 248 * 1 == Use whatever is in the SEEPROM or default to on
@@ -350,7 +331,6 @@ MODULE_PARM_DESC(aic79xx,
350" periodically to prevent tag starvation.\n" 331" periodically to prevent tag starvation.\n"
351" This may be required by some older disk\n" 332" This may be required by some older disk\n"
352" or drives/RAID arrays.\n" 333" or drives/RAID arrays.\n"
353" reverse_scan Sort PCI devices highest Bus/Slot to lowest\n"
354" tag_info:<tag_str> Set per-target tag depth\n" 334" tag_info:<tag_str> Set per-target tag depth\n"
355" global_tag_depth:<int> Global tag depth for all targets on all buses\n" 335" global_tag_depth:<int> Global tag depth for all targets on all buses\n"
356" slewrate:<slewrate_list>Set the signal slew rate (0-15).\n" 336" slewrate:<slewrate_list>Set the signal slew rate (0-15).\n"
@@ -484,7 +464,6 @@ ahd_linux_target_alloc(struct scsi_target *starget)
484 struct seeprom_config *sc = ahd->seep_config; 464 struct seeprom_config *sc = ahd->seep_config;
485 unsigned long flags; 465 unsigned long flags;
486 struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget); 466 struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
487 struct ahd_linux_target *targ = scsi_transport_target_data(starget);
488 struct ahd_devinfo devinfo; 467 struct ahd_devinfo devinfo;
489 struct ahd_initiator_tinfo *tinfo; 468 struct ahd_initiator_tinfo *tinfo;
490 struct ahd_tmode_tstate *tstate; 469 struct ahd_tmode_tstate *tstate;
@@ -495,7 +474,6 @@ ahd_linux_target_alloc(struct scsi_target *starget)
495 BUG_ON(*ahd_targp != NULL); 474 BUG_ON(*ahd_targp != NULL);
496 475
497 *ahd_targp = starget; 476 *ahd_targp = starget;
498 memset(targ, 0, sizeof(*targ));
499 477
500 if (sc) { 478 if (sc) {
501 int flags = sc->device_flags[starget->id]; 479 int flags = sc->device_flags[starget->id];
@@ -551,15 +529,11 @@ ahd_linux_slave_alloc(struct scsi_device *sdev)
551{ 529{
552 struct ahd_softc *ahd = 530 struct ahd_softc *ahd =
553 *((struct ahd_softc **)sdev->host->hostdata); 531 *((struct ahd_softc **)sdev->host->hostdata);
554 struct scsi_target *starget = sdev->sdev_target;
555 struct ahd_linux_target *targ = scsi_transport_target_data(starget);
556 struct ahd_linux_device *dev; 532 struct ahd_linux_device *dev;
557 533
558 if (bootverbose) 534 if (bootverbose)
559 printf("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id); 535 printf("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id);
560 536
561 BUG_ON(targ->sdev[sdev->lun] != NULL);
562
563 dev = scsi_transport_device_data(sdev); 537 dev = scsi_transport_device_data(sdev);
564 memset(dev, 0, sizeof(*dev)); 538 memset(dev, 0, sizeof(*dev));
565 539
@@ -576,8 +550,6 @@ ahd_linux_slave_alloc(struct scsi_device *sdev)
576 */ 550 */
577 dev->maxtags = 0; 551 dev->maxtags = 0;
578 552
579 targ->sdev[sdev->lun] = sdev;
580
581 return (0); 553 return (0);
582} 554}
583 555
@@ -599,23 +571,6 @@ ahd_linux_slave_configure(struct scsi_device *sdev)
599 return 0; 571 return 0;
600} 572}
601 573
602static void
603ahd_linux_slave_destroy(struct scsi_device *sdev)
604{
605 struct ahd_softc *ahd;
606 struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
607 struct ahd_linux_target *targ = scsi_transport_target_data(sdev->sdev_target);
608
609 ahd = *((struct ahd_softc **)sdev->host->hostdata);
610 if (bootverbose)
611 printf("%s: Slave Destroy %d\n", ahd_name(ahd), sdev->id);
612
613 BUG_ON(dev->active);
614
615 targ->sdev[sdev->lun] = NULL;
616
617}
618
619#if defined(__i386__) 574#if defined(__i386__)
620/* 575/*
621 * Return the disk geometry for the given SCSI device. 576 * Return the disk geometry for the given SCSI device.
@@ -822,7 +777,6 @@ struct scsi_host_template aic79xx_driver_template = {
822 .use_clustering = ENABLE_CLUSTERING, 777 .use_clustering = ENABLE_CLUSTERING,
823 .slave_alloc = ahd_linux_slave_alloc, 778 .slave_alloc = ahd_linux_slave_alloc,
824 .slave_configure = ahd_linux_slave_configure, 779 .slave_configure = ahd_linux_slave_configure,
825 .slave_destroy = ahd_linux_slave_destroy,
826 .target_alloc = ahd_linux_target_alloc, 780 .target_alloc = ahd_linux_target_alloc,
827 .target_destroy = ahd_linux_target_destroy, 781 .target_destroy = ahd_linux_target_destroy,
828}; 782};
@@ -1057,7 +1011,6 @@ aic79xx_setup(char *s)
1057#ifdef AHD_DEBUG 1011#ifdef AHD_DEBUG
1058 { "debug", &ahd_debug }, 1012 { "debug", &ahd_debug },
1059#endif 1013#endif
1060 { "reverse_scan", &aic79xx_reverse_scan },
1061 { "periodic_otag", &aic79xx_periodic_otag }, 1014 { "periodic_otag", &aic79xx_periodic_otag },
1062 { "pci_parity", &aic79xx_pci_parity }, 1015 { "pci_parity", &aic79xx_pci_parity },
1063 { "seltime", &aic79xx_seltime }, 1016 { "seltime", &aic79xx_seltime },
@@ -1249,20 +1202,13 @@ void
1249ahd_platform_free(struct ahd_softc *ahd) 1202ahd_platform_free(struct ahd_softc *ahd)
1250{ 1203{
1251 struct scsi_target *starget; 1204 struct scsi_target *starget;
1252 int i, j; 1205 int i;
1253 1206
1254 if (ahd->platform_data != NULL) { 1207 if (ahd->platform_data != NULL) {
1255 /* destroy all of the device and target objects */ 1208 /* destroy all of the device and target objects */
1256 for (i = 0; i < AHD_NUM_TARGETS; i++) { 1209 for (i = 0; i < AHD_NUM_TARGETS; i++) {
1257 starget = ahd->platform_data->starget[i]; 1210 starget = ahd->platform_data->starget[i];
1258 if (starget != NULL) { 1211 if (starget != NULL) {
1259 for (j = 0; j < AHD_NUM_LUNS; j++) {
1260 struct ahd_linux_target *targ =
1261 scsi_transport_target_data(starget);
1262 if (targ->sdev[j] == NULL)
1263 continue;
1264 targ->sdev[j] = NULL;
1265 }
1266 ahd->platform_data->starget[i] = NULL; 1212 ahd->platform_data->starget[i] = NULL;
1267 } 1213 }
1268 } 1214 }
@@ -1318,20 +1264,13 @@ ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
1318} 1264}
1319 1265
1320void 1266void
1321ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo, 1267ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
1322 ahd_queue_alg alg) 1268 struct ahd_devinfo *devinfo, ahd_queue_alg alg)
1323{ 1269{
1324 struct scsi_target *starget;
1325 struct ahd_linux_target *targ;
1326 struct ahd_linux_device *dev; 1270 struct ahd_linux_device *dev;
1327 struct scsi_device *sdev;
1328 int was_queuing; 1271 int was_queuing;
1329 int now_queuing; 1272 int now_queuing;
1330 1273
1331 starget = ahd->platform_data->starget[devinfo->target];
1332 targ = scsi_transport_target_data(starget);
1333 BUG_ON(targ == NULL);
1334 sdev = targ->sdev[devinfo->lun];
1335 if (sdev == NULL) 1274 if (sdev == NULL)
1336 return; 1275 return;
1337 1276
@@ -1467,11 +1406,15 @@ ahd_linux_device_queue_depth(struct scsi_device *sdev)
1467 tags = ahd_linux_user_tagdepth(ahd, &devinfo); 1406 tags = ahd_linux_user_tagdepth(ahd, &devinfo);
1468 if (tags != 0 && sdev->tagged_supported != 0) { 1407 if (tags != 0 && sdev->tagged_supported != 0) {
1469 1408
1470 ahd_set_tags(ahd, &devinfo, AHD_QUEUE_TAGGED); 1409 ahd_platform_set_tags(ahd, sdev, &devinfo, AHD_QUEUE_TAGGED);
1410 ahd_send_async(ahd, devinfo.channel, devinfo.target,
1411 devinfo.lun, AC_TRANSFER_NEG);
1471 ahd_print_devinfo(ahd, &devinfo); 1412 ahd_print_devinfo(ahd, &devinfo);
1472 printf("Tagged Queuing enabled. Depth %d\n", tags); 1413 printf("Tagged Queuing enabled. Depth %d\n", tags);
1473 } else { 1414 } else {
1474 ahd_set_tags(ahd, &devinfo, AHD_QUEUE_NONE); 1415 ahd_platform_set_tags(ahd, sdev, &devinfo, AHD_QUEUE_NONE);
1416 ahd_send_async(ahd, devinfo.channel, devinfo.target,
1417 devinfo.lun, AC_TRANSFER_NEG);
1475 } 1418 }
1476} 1419}
1477 1420
@@ -1629,7 +1572,7 @@ ahd_linux_isr(int irq, void *dev_id, struct pt_regs * regs)
1629 1572
1630void 1573void
1631ahd_send_async(struct ahd_softc *ahd, char channel, 1574ahd_send_async(struct ahd_softc *ahd, char channel,
1632 u_int target, u_int lun, ac_code code, void *arg) 1575 u_int target, u_int lun, ac_code code)
1633{ 1576{
1634 switch (code) { 1577 switch (code) {
1635 case AC_TRANSFER_NEG: 1578 case AC_TRANSFER_NEG:
@@ -1956,7 +1899,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
1956 } 1899 }
1957 ahd_set_transaction_status(scb, CAM_REQUEUE_REQ); 1900 ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
1958 ahd_set_scsi_status(scb, SCSI_STATUS_OK); 1901 ahd_set_scsi_status(scb, SCSI_STATUS_OK);
1959 ahd_platform_set_tags(ahd, &devinfo, 1902 ahd_platform_set_tags(ahd, sdev, &devinfo,
1960 (dev->flags & AHD_DEV_Q_BASIC) 1903 (dev->flags & AHD_DEV_Q_BASIC)
1961 ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED); 1904 ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
1962 break; 1905 break;
@@ -1966,7 +1909,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
1966 * as if the target returned BUSY SCSI status. 1909 * as if the target returned BUSY SCSI status.
1967 */ 1910 */
1968 dev->openings = 1; 1911 dev->openings = 1;
1969 ahd_platform_set_tags(ahd, &devinfo, 1912 ahd_platform_set_tags(ahd, sdev, &devinfo,
1970 (dev->flags & AHD_DEV_Q_BASIC) 1913 (dev->flags & AHD_DEV_Q_BASIC)
1971 ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED); 1914 ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
1972 ahd_set_scsi_status(scb, SCSI_STATUS_BUSY); 1915 ahd_set_scsi_status(scb, SCSI_STATUS_BUSY);
@@ -2778,8 +2721,6 @@ ahd_linux_init(void)
2778 if (!ahd_linux_transport_template) 2721 if (!ahd_linux_transport_template)
2779 return -ENODEV; 2722 return -ENODEV;
2780 2723
2781 scsi_transport_reserve_target(ahd_linux_transport_template,
2782 sizeof(struct ahd_linux_target));
2783 scsi_transport_reserve_device(ahd_linux_transport_template, 2724 scsi_transport_reserve_device(ahd_linux_transport_template,
2784 sizeof(struct ahd_linux_device)); 2725 sizeof(struct ahd_linux_device));
2785 2726
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.h b/drivers/scsi/aic7xxx/aic79xx_osm.h
index 92c6154575e7..601340d84410 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.h
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.h
@@ -93,7 +93,6 @@
93#endif 93#endif
94 94
95/********************************** Misc Macros *******************************/ 95/********************************** Misc Macros *******************************/
96#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
97#define powerof2(x) ((((x)-1)&(x))==0) 96#define powerof2(x) ((((x)-1)&(x))==0)
98 97
99/************************* Forward Declarations *******************************/ 98/************************* Forward Declarations *******************************/
@@ -262,7 +261,6 @@ typedef enum {
262 AHD_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */ 261 AHD_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */
263} ahd_linux_dev_flags; 262} ahd_linux_dev_flags;
264 263
265struct ahd_linux_target;
266struct ahd_linux_device { 264struct ahd_linux_device {
267 TAILQ_ENTRY(ahd_linux_device) links; 265 TAILQ_ENTRY(ahd_linux_device) links;
268 266
@@ -342,12 +340,6 @@ struct ahd_linux_device {
342#define AHD_OTAG_THRESH 500 340#define AHD_OTAG_THRESH 500
343}; 341};
344 342
345struct ahd_linux_target {
346 struct scsi_device *sdev[AHD_NUM_LUNS];
347 struct ahd_transinfo last_tinfo;
348 struct ahd_softc *ahd;
349};
350
351/********************* Definitions Required by the Core ***********************/ 343/********************* Definitions Required by the Core ***********************/
352/* 344/*
353 * Number of SG segments we require. So long as the S/G segments for 345 * Number of SG segments we require. So long as the S/G segments for
@@ -864,7 +856,7 @@ ahd_freeze_scb(struct scb *scb)
864 } 856 }
865} 857}
866 858
867void ahd_platform_set_tags(struct ahd_softc *ahd, 859void ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
868 struct ahd_devinfo *devinfo, ahd_queue_alg); 860 struct ahd_devinfo *devinfo, ahd_queue_alg);
869int ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, 861int ahd_platform_abort_scbs(struct ahd_softc *ahd, int target,
870 char channel, int lun, u_int tag, 862 char channel, int lun, u_int tag,
@@ -873,7 +865,7 @@ irqreturn_t
873 ahd_linux_isr(int irq, void *dev_id, struct pt_regs * regs); 865 ahd_linux_isr(int irq, void *dev_id, struct pt_regs * regs);
874void ahd_done(struct ahd_softc*, struct scb*); 866void ahd_done(struct ahd_softc*, struct scb*);
875void ahd_send_async(struct ahd_softc *, char channel, 867void ahd_send_async(struct ahd_softc *, char channel,
876 u_int target, u_int lun, ac_code, void *); 868 u_int target, u_int lun, ac_code);
877void ahd_print_path(struct ahd_softc *, struct scb *); 869void ahd_print_path(struct ahd_softc *, struct scb *);
878 870
879#ifdef CONFIG_PCI 871#ifdef CONFIG_PCI
diff --git a/drivers/scsi/aic7xxx/aic79xx_proc.c b/drivers/scsi/aic7xxx/aic79xx_proc.c
index 24fd59a230bf..c5f0ee591509 100644
--- a/drivers/scsi/aic7xxx/aic79xx_proc.c
+++ b/drivers/scsi/aic7xxx/aic79xx_proc.c
@@ -47,7 +47,7 @@ static int copy_info(struct info_str *info, char *fmt, ...);
47static void ahd_dump_target_state(struct ahd_softc *ahd, 47static void ahd_dump_target_state(struct ahd_softc *ahd,
48 struct info_str *info, 48 struct info_str *info,
49 u_int our_id, char channel, 49 u_int our_id, char channel,
50 u_int target_id, u_int target_offset); 50 u_int target_id);
51static void ahd_dump_device_state(struct info_str *info, 51static void ahd_dump_device_state(struct info_str *info,
52 struct scsi_device *sdev); 52 struct scsi_device *sdev);
53static int ahd_proc_write_seeprom(struct ahd_softc *ahd, 53static int ahd_proc_write_seeprom(struct ahd_softc *ahd,
@@ -204,10 +204,8 @@ ahd_format_transinfo(struct info_str *info, struct ahd_transinfo *tinfo)
204 204
205static void 205static void
206ahd_dump_target_state(struct ahd_softc *ahd, struct info_str *info, 206ahd_dump_target_state(struct ahd_softc *ahd, struct info_str *info,
207 u_int our_id, char channel, u_int target_id, 207 u_int our_id, char channel, u_int target_id)
208 u_int target_offset)
209{ 208{
210 struct ahd_linux_target *targ;
211 struct scsi_target *starget; 209 struct scsi_target *starget;
212 struct ahd_initiator_tinfo *tinfo; 210 struct ahd_initiator_tinfo *tinfo;
213 struct ahd_tmode_tstate *tstate; 211 struct ahd_tmode_tstate *tstate;
@@ -218,10 +216,9 @@ ahd_dump_target_state(struct ahd_softc *ahd, struct info_str *info,
218 copy_info(info, "Target %d Negotiation Settings\n", target_id); 216 copy_info(info, "Target %d Negotiation Settings\n", target_id);
219 copy_info(info, "\tUser: "); 217 copy_info(info, "\tUser: ");
220 ahd_format_transinfo(info, &tinfo->user); 218 ahd_format_transinfo(info, &tinfo->user);
221 starget = ahd->platform_data->starget[target_offset]; 219 starget = ahd->platform_data->starget[target_id];
222 if (starget == NULL) 220 if (starget == NULL)
223 return; 221 return;
224 targ = scsi_transport_target_data(starget);
225 222
226 copy_info(info, "\tGoal: "); 223 copy_info(info, "\tGoal: ");
227 ahd_format_transinfo(info, &tinfo->goal); 224 ahd_format_transinfo(info, &tinfo->goal);
@@ -231,7 +228,7 @@ ahd_dump_target_state(struct ahd_softc *ahd, struct info_str *info,
231 for (lun = 0; lun < AHD_NUM_LUNS; lun++) { 228 for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
232 struct scsi_device *dev; 229 struct scsi_device *dev;
233 230
234 dev = targ->sdev[lun]; 231 dev = scsi_device_lookup_by_target(starget, lun);
235 232
236 if (dev == NULL) 233 if (dev == NULL)
237 continue; 234 continue;
@@ -355,7 +352,7 @@ ahd_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
355 copy_info(&info, "Allocated SCBs: %d, SG List Length: %d\n\n", 352 copy_info(&info, "Allocated SCBs: %d, SG List Length: %d\n\n",
356 ahd->scb_data.numscbs, AHD_NSEG); 353 ahd->scb_data.numscbs, AHD_NSEG);
357 354
358 max_targ = 15; 355 max_targ = 16;
359 356
360 if (ahd->seep_config == NULL) 357 if (ahd->seep_config == NULL)
361 copy_info(&info, "No Serial EEPROM\n"); 358 copy_info(&info, "No Serial EEPROM\n");
@@ -373,12 +370,12 @@ ahd_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
373 copy_info(&info, "\n"); 370 copy_info(&info, "\n");
374 371
375 if ((ahd->features & AHD_WIDE) == 0) 372 if ((ahd->features & AHD_WIDE) == 0)
376 max_targ = 7; 373 max_targ = 8;
377 374
378 for (i = 0; i <= max_targ; i++) { 375 for (i = 0; i < max_targ; i++) {
379 376
380 ahd_dump_target_state(ahd, &info, ahd->our_id, 'A', 377 ahd_dump_target_state(ahd, &info, ahd->our_id, 'A',
381 /*target_id*/i, /*target_offset*/i); 378 /*target_id*/i);
382 } 379 }
383 retval = info.pos > info.offset ? info.pos - info.offset : 0; 380 retval = info.pos > info.offset ? info.pos - info.offset : 0;
384done: 381done:
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index debf3e2a0798..aa4be8a31415 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -353,7 +353,6 @@ MODULE_PARM_DESC(aic7xxx,
353" periodically to prevent tag starvation.\n" 353" periodically to prevent tag starvation.\n"
354" This may be required by some older disk\n" 354" This may be required by some older disk\n"
355" drives or RAID arrays.\n" 355" drives or RAID arrays.\n"
356" reverse_scan Sort PCI devices highest Bus/Slot to lowest\n"
357" tag_info:<tag_str> Set per-target tag depth\n" 356" tag_info:<tag_str> Set per-target tag depth\n"
358" global_tag_depth:<int> Global tag depth for every target\n" 357" global_tag_depth:<int> Global tag depth for every target\n"
359" on every bus\n" 358" on every bus\n"
diff --git a/drivers/scsi/aic7xxx/aicasm/Makefile b/drivers/scsi/aic7xxx/aicasm/Makefile
index 8c91fda6482c..b98c5c1056c3 100644
--- a/drivers/scsi/aic7xxx/aicasm/Makefile
+++ b/drivers/scsi/aic7xxx/aicasm/Makefile
@@ -14,6 +14,8 @@ LIBS= -ldb
14clean-files:= ${GENSRCS} ${GENHDRS} $(YSRCS:.y=.output) $(PROG) 14clean-files:= ${GENSRCS} ${GENHDRS} $(YSRCS:.y=.output) $(PROG)
15# Override default kernel CFLAGS. This is a userland app. 15# Override default kernel CFLAGS. This is a userland app.
16AICASM_CFLAGS:= -I/usr/include -I. 16AICASM_CFLAGS:= -I/usr/include -I.
17LEX= flex
18YACC= bison
17YFLAGS= -d 19YFLAGS= -d
18 20
19NOMAN= noman 21NOMAN= noman
diff --git a/drivers/scsi/arm/Kconfig b/drivers/scsi/arm/Kconfig
index 06d7601cdf56..d006a8cb4a74 100644
--- a/drivers/scsi/arm/Kconfig
+++ b/drivers/scsi/arm/Kconfig
@@ -69,6 +69,7 @@ comment "The following drivers are not fully supported"
69config SCSI_CUMANA_1 69config SCSI_CUMANA_1
70 tristate "CumanaSCSI I support (EXPERIMENTAL)" 70 tristate "CumanaSCSI I support (EXPERIMENTAL)"
71 depends on ARCH_ACORN && EXPERIMENTAL && SCSI 71 depends on ARCH_ACORN && EXPERIMENTAL && SCSI
72 select SCSI_SPI_ATTRS
72 help 73 help
73 This enables support for the Cumana SCSI I card. If you have an 74 This enables support for the Cumana SCSI I card. If you have an
74 Acorn system with one of these, say Y. If unsure, say N. 75 Acorn system with one of these, say Y. If unsure, say N.
@@ -76,6 +77,7 @@ config SCSI_CUMANA_1
76config SCSI_ECOSCSI 77config SCSI_ECOSCSI
77 tristate "EcoScsi support (EXPERIMENTAL)" 78 tristate "EcoScsi support (EXPERIMENTAL)"
78 depends on ARCH_ACORN && EXPERIMENTAL && (ARCH_ARC || ARCH_A5K) && SCSI 79 depends on ARCH_ACORN && EXPERIMENTAL && (ARCH_ARC || ARCH_A5K) && SCSI
80 select SCSI_SPI_ATTRS
79 help 81 help
80 This enables support for the EcoSCSI card -- a small card that sits 82 This enables support for the EcoSCSI card -- a small card that sits
81 in the Econet socket. If you have an Acorn system with one of these, 83 in the Econet socket. If you have an Acorn system with one of these,
@@ -84,6 +86,7 @@ config SCSI_ECOSCSI
84config SCSI_OAK1 86config SCSI_OAK1
85 tristate "Oak SCSI support (EXPERIMENTAL)" 87 tristate "Oak SCSI support (EXPERIMENTAL)"
86 depends on ARCH_ACORN && EXPERIMENTAL && SCSI 88 depends on ARCH_ACORN && EXPERIMENTAL && SCSI
89 select SCSI_SPI_ATTRS
87 help 90 help
88 This enables support for the Oak SCSI card. If you have an Acorn 91 This enables support for the Oak SCSI card. If you have an Acorn
89 system with one of these, say Y. If unsure, say N. 92 system with one of these, say Y. If unsure, say N.
diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index 3e1053f111dc..4cf7afc31cc7 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -2427,7 +2427,7 @@ int fas216_eh_abort(Scsi_Cmnd *SCpnt)
2427 info->stats.aborts += 1; 2427 info->stats.aborts += 1;
2428 2428
2429 printk(KERN_WARNING "scsi%d: abort command ", info->host->host_no); 2429 printk(KERN_WARNING "scsi%d: abort command ", info->host->host_no);
2430 __scsi_print_command(SCpnt->data_cmnd); 2430 __scsi_print_command(SCpnt->cmnd);
2431 2431
2432 print_debug_list(); 2432 print_debug_list();
2433 fas216_dumpstate(info); 2433 fas216_dumpstate(info);
diff --git a/drivers/scsi/arm/scsi.h b/drivers/scsi/arm/scsi.h
index 6dd544a5eb56..8c2600ffc6af 100644
--- a/drivers/scsi/arm/scsi.h
+++ b/drivers/scsi/arm/scsi.h
@@ -74,7 +74,7 @@ static inline void init_SCp(Scsi_Cmnd *SCpnt)
74 unsigned long len = 0; 74 unsigned long len = 0;
75 int buf; 75 int buf;
76 76
77 SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->buffer; 77 SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->request_buffer;
78 SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1; 78 SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1;
79 SCpnt->SCp.ptr = (char *) 79 SCpnt->SCp.ptr = (char *)
80 (page_address(SCpnt->SCp.buffer->page) + 80 (page_address(SCpnt->SCp.buffer->page) +
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c
index 94b1261a259d..a9bb3cb7e89b 100644
--- a/drivers/scsi/ata_piix.c
+++ b/drivers/scsi/ata_piix.c
@@ -105,9 +105,6 @@ enum {
105 PIIX_FLAG_SCR = (1 << 26), /* SCR available */ 105 PIIX_FLAG_SCR = (1 << 26), /* SCR available */
106 PIIX_FLAG_AHCI = (1 << 27), /* AHCI possible */ 106 PIIX_FLAG_AHCI = (1 << 27), /* AHCI possible */
107 PIIX_FLAG_CHECKINTR = (1 << 28), /* make sure PCI INTx enabled */ 107 PIIX_FLAG_CHECKINTR = (1 << 28), /* make sure PCI INTx enabled */
108 PIIX_FLAG_COMBINED = (1 << 29), /* combined mode possible */
109 /* ICH6/7 use different scheme for map value */
110 PIIX_FLAG_COMBINED_ICH6 = PIIX_FLAG_COMBINED | (1 << 30),
111 108
112 /* combined mode. if set, PATA is channel 0. 109 /* combined mode. if set, PATA is channel 0.
113 * if clear, PATA is channel 1. 110 * if clear, PATA is channel 1.
@@ -126,6 +123,8 @@ enum {
126 ich6_sata = 4, 123 ich6_sata = 4,
127 ich6_sata_ahci = 5, 124 ich6_sata_ahci = 5,
128 ich6m_sata_ahci = 6, 125 ich6m_sata_ahci = 6,
126 ich7m_sata_ahci = 7,
127 ich8_sata_ahci = 8,
129 128
130 /* constants for mapping table */ 129 /* constants for mapping table */
131 P0 = 0, /* port 0 */ 130 P0 = 0, /* port 0 */
@@ -141,11 +140,19 @@ enum {
141 140
142struct piix_map_db { 141struct piix_map_db {
143 const u32 mask; 142 const u32 mask;
143 const u16 port_enable;
144 const int present_shift;
144 const int map[][4]; 145 const int map[][4];
145}; 146};
146 147
148struct piix_host_priv {
149 const int *map;
150 const struct piix_map_db *map_db;
151};
152
147static int piix_init_one (struct pci_dev *pdev, 153static int piix_init_one (struct pci_dev *pdev,
148 const struct pci_device_id *ent); 154 const struct pci_device_id *ent);
155static void piix_host_stop(struct ata_host_set *host_set);
149static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev); 156static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev);
150static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev); 157static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev);
151static void piix_pata_error_handler(struct ata_port *ap); 158static void piix_pata_error_handler(struct ata_port *ap);
@@ -182,15 +189,15 @@ static const struct pci_device_id piix_pci_tbl[] = {
182 /* 82801GB/GR/GH (ICH7, identical to ICH6) */ 189 /* 82801GB/GR/GH (ICH7, identical to ICH6) */
183 { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 190 { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
184 /* 2801GBM/GHM (ICH7M, identical to ICH6M) */ 191 /* 2801GBM/GHM (ICH7M, identical to ICH6M) */
185 { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6m_sata_ahci }, 192 { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich7m_sata_ahci },
186 /* Enterprise Southbridge 2 (where's the datasheet?) */ 193 /* Enterprise Southbridge 2 (where's the datasheet?) */
187 { 0x8086, 0x2680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 194 { 0x8086, 0x2680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
188 /* SATA Controller 1 IDE (ICH8, no datasheet yet) */ 195 /* SATA Controller 1 IDE (ICH8, no datasheet yet) */
189 { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 196 { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
190 /* SATA Controller 2 IDE (ICH8, ditto) */ 197 /* SATA Controller 2 IDE (ICH8, ditto) */
191 { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 198 { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
192 /* Mobile SATA Controller IDE (ICH8M, ditto) */ 199 /* Mobile SATA Controller IDE (ICH8M, ditto) */
193 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6m_sata_ahci }, 200 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
194 201
195 { } /* terminate list */ 202 { } /* terminate list */
196}; 203};
@@ -254,7 +261,7 @@ static const struct ata_port_operations piix_pata_ops = {
254 261
255 .port_start = ata_port_start, 262 .port_start = ata_port_start,
256 .port_stop = ata_port_stop, 263 .port_stop = ata_port_stop,
257 .host_stop = ata_host_stop, 264 .host_stop = piix_host_stop,
258}; 265};
259 266
260static const struct ata_port_operations piix_sata_ops = { 267static const struct ata_port_operations piix_sata_ops = {
@@ -284,11 +291,13 @@ static const struct ata_port_operations piix_sata_ops = {
284 291
285 .port_start = ata_port_start, 292 .port_start = ata_port_start,
286 .port_stop = ata_port_stop, 293 .port_stop = ata_port_stop,
287 .host_stop = ata_host_stop, 294 .host_stop = piix_host_stop,
288}; 295};
289 296
290static struct piix_map_db ich5_map_db = { 297static const struct piix_map_db ich5_map_db = {
291 .mask = 0x7, 298 .mask = 0x7,
299 .port_enable = 0x3,
300 .present_shift = 4,
292 .map = { 301 .map = {
293 /* PM PS SM SS MAP */ 302 /* PM PS SM SS MAP */
294 { P0, NA, P1, NA }, /* 000b */ 303 { P0, NA, P1, NA }, /* 000b */
@@ -302,8 +311,10 @@ static struct piix_map_db ich5_map_db = {
302 }, 311 },
303}; 312};
304 313
305static struct piix_map_db ich6_map_db = { 314static const struct piix_map_db ich6_map_db = {
306 .mask = 0x3, 315 .mask = 0x3,
316 .port_enable = 0xf,
317 .present_shift = 4,
307 .map = { 318 .map = {
308 /* PM PS SM SS MAP */ 319 /* PM PS SM SS MAP */
309 { P0, P2, P1, P3 }, /* 00b */ 320 { P0, P2, P1, P3 }, /* 00b */
@@ -313,8 +324,10 @@ static struct piix_map_db ich6_map_db = {
313 }, 324 },
314}; 325};
315 326
316static struct piix_map_db ich6m_map_db = { 327static const struct piix_map_db ich6m_map_db = {
317 .mask = 0x3, 328 .mask = 0x3,
329 .port_enable = 0x5,
330 .present_shift = 4,
318 .map = { 331 .map = {
319 /* PM PS SM SS MAP */ 332 /* PM PS SM SS MAP */
320 { P0, P2, RV, RV }, /* 00b */ 333 { P0, P2, RV, RV }, /* 00b */
@@ -324,6 +337,47 @@ static struct piix_map_db ich6m_map_db = {
324 }, 337 },
325}; 338};
326 339
340static const struct piix_map_db ich7m_map_db = {
341 .mask = 0x3,
342 .port_enable = 0x5,
343 .present_shift = 4,
344
345 /* Map 01b isn't specified in the doc but some notebooks use
346 * it anyway. ATM, the only case spotted carries subsystem ID
347 * 1025:0107. This is the only difference from ich6m.
348 */
349 .map = {
350 /* PM PS SM SS MAP */
351 { P0, P2, RV, RV }, /* 00b */
352 { IDE, IDE, P1, P3 }, /* 01b */
353 { P0, P2, IDE, IDE }, /* 10b */
354 { RV, RV, RV, RV },
355 },
356};
357
358static const struct piix_map_db ich8_map_db = {
359 .mask = 0x3,
360 .port_enable = 0x3,
361 .present_shift = 8,
362 .map = {
363 /* PM PS SM SS MAP */
364 { P0, NA, P1, NA }, /* 00b (hardwired) */
365 { RV, RV, RV, RV },
366 { RV, RV, RV, RV }, /* 10b (never) */
367 { RV, RV, RV, RV },
368 },
369};
370
371static const struct piix_map_db *piix_map_db_table[] = {
372 [ich5_sata] = &ich5_map_db,
373 [esb_sata] = &ich5_map_db,
374 [ich6_sata] = &ich6_map_db,
375 [ich6_sata_ahci] = &ich6_map_db,
376 [ich6m_sata_ahci] = &ich6m_map_db,
377 [ich7m_sata_ahci] = &ich7m_map_db,
378 [ich8_sata_ahci] = &ich8_map_db,
379};
380
327static struct ata_port_info piix_port_info[] = { 381static struct ata_port_info piix_port_info[] = {
328 /* piix4_pata */ 382 /* piix4_pata */
329 { 383 {
@@ -356,63 +410,82 @@ static struct ata_port_info piix_port_info[] = {
356 /* ich5_sata */ 410 /* ich5_sata */
357 { 411 {
358 .sht = &piix_sht, 412 .sht = &piix_sht,
359 .host_flags = ATA_FLAG_SATA | PIIX_FLAG_COMBINED | 413 .host_flags = ATA_FLAG_SATA | PIIX_FLAG_CHECKINTR |
360 PIIX_FLAG_CHECKINTR, 414 PIIX_FLAG_IGNORE_PCS,
361 .pio_mask = 0x1f, /* pio0-4 */ 415 .pio_mask = 0x1f, /* pio0-4 */
362 .mwdma_mask = 0x07, /* mwdma0-2 */ 416 .mwdma_mask = 0x07, /* mwdma0-2 */
363 .udma_mask = 0x7f, /* udma0-6 */ 417 .udma_mask = 0x7f, /* udma0-6 */
364 .port_ops = &piix_sata_ops, 418 .port_ops = &piix_sata_ops,
365 .private_data = &ich5_map_db,
366 }, 419 },
367 420
368 /* i6300esb_sata */ 421 /* i6300esb_sata */
369 { 422 {
370 .sht = &piix_sht, 423 .sht = &piix_sht,
371 .host_flags = ATA_FLAG_SATA | PIIX_FLAG_COMBINED | 424 .host_flags = ATA_FLAG_SATA |
372 PIIX_FLAG_CHECKINTR | PIIX_FLAG_IGNORE_PCS, 425 PIIX_FLAG_CHECKINTR | PIIX_FLAG_IGNORE_PCS,
373 .pio_mask = 0x1f, /* pio0-4 */ 426 .pio_mask = 0x1f, /* pio0-4 */
374 .mwdma_mask = 0x07, /* mwdma0-2 */ 427 .mwdma_mask = 0x07, /* mwdma0-2 */
375 .udma_mask = 0x7f, /* udma0-6 */ 428 .udma_mask = 0x7f, /* udma0-6 */
376 .port_ops = &piix_sata_ops, 429 .port_ops = &piix_sata_ops,
377 .private_data = &ich5_map_db,
378 }, 430 },
379 431
380 /* ich6_sata */ 432 /* ich6_sata */
381 { 433 {
382 .sht = &piix_sht, 434 .sht = &piix_sht,
383 .host_flags = ATA_FLAG_SATA | PIIX_FLAG_COMBINED_ICH6 | 435 .host_flags = ATA_FLAG_SATA |
384 PIIX_FLAG_CHECKINTR | PIIX_FLAG_SCR, 436 PIIX_FLAG_CHECKINTR | PIIX_FLAG_SCR,
385 .pio_mask = 0x1f, /* pio0-4 */ 437 .pio_mask = 0x1f, /* pio0-4 */
386 .mwdma_mask = 0x07, /* mwdma0-2 */ 438 .mwdma_mask = 0x07, /* mwdma0-2 */
387 .udma_mask = 0x7f, /* udma0-6 */ 439 .udma_mask = 0x7f, /* udma0-6 */
388 .port_ops = &piix_sata_ops, 440 .port_ops = &piix_sata_ops,
389 .private_data = &ich6_map_db,
390 }, 441 },
391 442
392 /* ich6_sata_ahci */ 443 /* ich6_sata_ahci */
393 { 444 {
394 .sht = &piix_sht, 445 .sht = &piix_sht,
395 .host_flags = ATA_FLAG_SATA | PIIX_FLAG_COMBINED_ICH6 | 446 .host_flags = ATA_FLAG_SATA |
396 PIIX_FLAG_CHECKINTR | PIIX_FLAG_SCR | 447 PIIX_FLAG_CHECKINTR | PIIX_FLAG_SCR |
397 PIIX_FLAG_AHCI, 448 PIIX_FLAG_AHCI,
398 .pio_mask = 0x1f, /* pio0-4 */ 449 .pio_mask = 0x1f, /* pio0-4 */
399 .mwdma_mask = 0x07, /* mwdma0-2 */ 450 .mwdma_mask = 0x07, /* mwdma0-2 */
400 .udma_mask = 0x7f, /* udma0-6 */ 451 .udma_mask = 0x7f, /* udma0-6 */
401 .port_ops = &piix_sata_ops, 452 .port_ops = &piix_sata_ops,
402 .private_data = &ich6_map_db,
403 }, 453 },
404 454
405 /* ich6m_sata_ahci */ 455 /* ich6m_sata_ahci */
406 { 456 {
407 .sht = &piix_sht, 457 .sht = &piix_sht,
408 .host_flags = ATA_FLAG_SATA | PIIX_FLAG_COMBINED_ICH6 | 458 .host_flags = ATA_FLAG_SATA |
459 PIIX_FLAG_CHECKINTR | PIIX_FLAG_SCR |
460 PIIX_FLAG_AHCI,
461 .pio_mask = 0x1f, /* pio0-4 */
462 .mwdma_mask = 0x07, /* mwdma0-2 */
463 .udma_mask = 0x7f, /* udma0-6 */
464 .port_ops = &piix_sata_ops,
465 },
466
467 /* ich7m_sata_ahci */
468 {
469 .sht = &piix_sht,
470 .host_flags = ATA_FLAG_SATA |
471 PIIX_FLAG_CHECKINTR | PIIX_FLAG_SCR |
472 PIIX_FLAG_AHCI,
473 .pio_mask = 0x1f, /* pio0-4 */
474 .mwdma_mask = 0x07, /* mwdma0-2 */
475 .udma_mask = 0x7f, /* udma0-6 */
476 .port_ops = &piix_sata_ops,
477 },
478
479 /* ich8_sata_ahci */
480 {
481 .sht = &piix_sht,
482 .host_flags = ATA_FLAG_SATA |
409 PIIX_FLAG_CHECKINTR | PIIX_FLAG_SCR | 483 PIIX_FLAG_CHECKINTR | PIIX_FLAG_SCR |
410 PIIX_FLAG_AHCI, 484 PIIX_FLAG_AHCI,
411 .pio_mask = 0x1f, /* pio0-4 */ 485 .pio_mask = 0x1f, /* pio0-4 */
412 .mwdma_mask = 0x07, /* mwdma0-2 */ 486 .mwdma_mask = 0x07, /* mwdma0-2 */
413 .udma_mask = 0x7f, /* udma0-6 */ 487 .udma_mask = 0x7f, /* udma0-6 */
414 .port_ops = &piix_sata_ops, 488 .port_ops = &piix_sata_ops,
415 .private_data = &ich6m_map_db,
416 }, 489 },
417}; 490};
418 491
@@ -427,6 +500,11 @@ MODULE_LICENSE("GPL");
427MODULE_DEVICE_TABLE(pci, piix_pci_tbl); 500MODULE_DEVICE_TABLE(pci, piix_pci_tbl);
428MODULE_VERSION(DRV_VERSION); 501MODULE_VERSION(DRV_VERSION);
429 502
503static int force_pcs = 0;
504module_param(force_pcs, int, 0444);
505MODULE_PARM_DESC(force_pcs, "force honoring or ignoring PCS to work around "
506 "device mis-detection (0=default, 1=ignore PCS, 2=honor PCS)");
507
430/** 508/**
431 * piix_pata_cbl_detect - Probe host controller cable detect info 509 * piix_pata_cbl_detect - Probe host controller cable detect info
432 * @ap: Port for which cable detect info is desired 510 * @ap: Port for which cable detect info is desired
@@ -491,74 +569,83 @@ static void piix_pata_error_handler(struct ata_port *ap)
491} 569}
492 570
493/** 571/**
494 * piix_sata_prereset - prereset for SATA host controller 572 * piix_sata_present_mask - determine present mask for SATA host controller
495 * @ap: Target port 573 * @ap: Target port
496 * 574 *
497 * Reads and configures SATA PCI device's PCI config register 575 * Reads SATA PCI device's PCI config register Port Configuration
498 * Port Configuration and Status (PCS) to determine port and 576 * and Status (PCS) to determine port and device availability.
499 * device availability. Return -ENODEV to skip reset if no
500 * device is present.
501 * 577 *
502 * LOCKING: 578 * LOCKING:
503 * None (inherited from caller). 579 * None (inherited from caller).
504 * 580 *
505 * RETURNS: 581 * RETURNS:
506 * 0 if device is present, -ENODEV otherwise. 582 * determined present_mask
507 */ 583 */
508static int piix_sata_prereset(struct ata_port *ap) 584static unsigned int piix_sata_present_mask(struct ata_port *ap)
509{ 585{
510 struct pci_dev *pdev = to_pci_dev(ap->host_set->dev); 586 struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
511 const unsigned int *map = ap->host_set->private_data; 587 struct piix_host_priv *hpriv = ap->host_set->private_data;
588 const unsigned int *map = hpriv->map;
512 int base = 2 * ap->hard_port_no; 589 int base = 2 * ap->hard_port_no;
513 unsigned int present_mask = 0; 590 unsigned int present_mask = 0;
514 int port, i; 591 int port, i;
515 u8 pcs; 592 u16 pcs;
516 593
517 pci_read_config_byte(pdev, ICH5_PCS, &pcs); 594 pci_read_config_word(pdev, ICH5_PCS, &pcs);
518 DPRINTK("ata%u: ENTER, pcs=0x%x base=%d\n", ap->id, pcs, base); 595 DPRINTK("ata%u: ENTER, pcs=0x%x base=%d\n", ap->id, pcs, base);
519 596
520 /* enable all ports on this ap and wait for them to settle */
521 for (i = 0; i < 2; i++) {
522 port = map[base + i];
523 if (port >= 0)
524 pcs |= 1 << port;
525 }
526
527 pci_write_config_byte(pdev, ICH5_PCS, pcs);
528 msleep(100);
529
530 /* let's see which devices are present */
531 pci_read_config_byte(pdev, ICH5_PCS, &pcs);
532
533 for (i = 0; i < 2; i++) { 597 for (i = 0; i < 2; i++) {
534 port = map[base + i]; 598 port = map[base + i];
535 if (port < 0) 599 if (port < 0)
536 continue; 600 continue;
537 if (ap->flags & PIIX_FLAG_IGNORE_PCS || pcs & 1 << (4 + port)) 601 if ((ap->flags & PIIX_FLAG_IGNORE_PCS) ||
602 (pcs & 1 << (hpriv->map_db->present_shift + port)))
538 present_mask |= 1 << i; 603 present_mask |= 1 << i;
539 else
540 pcs &= ~(1 << port);
541 } 604 }
542 605
543 /* disable offline ports on non-AHCI controllers */
544 if (!(ap->flags & PIIX_FLAG_AHCI))
545 pci_write_config_byte(pdev, ICH5_PCS, pcs);
546
547 DPRINTK("ata%u: LEAVE, pcs=0x%x present_mask=0x%x\n", 606 DPRINTK("ata%u: LEAVE, pcs=0x%x present_mask=0x%x\n",
548 ap->id, pcs, present_mask); 607 ap->id, pcs, present_mask);
549 608
550 if (!present_mask) { 609 return present_mask;
551 ata_port_printk(ap, KERN_INFO, "SATA port has no device.\n"); 610}
552 ap->eh_context.i.action &= ~ATA_EH_RESET_MASK; 611
553 return 0; 612/**
613 * piix_sata_softreset - reset SATA host port via ATA SRST
614 * @ap: port to reset
615 * @classes: resulting classes of attached devices
616 *
617 * Reset SATA host port via ATA SRST. On controllers with
618 * reliable PCS present bits, the bits are used to determine
619 * device presence.
620 *
621 * LOCKING:
622 * Kernel thread context (may sleep)
623 *
624 * RETURNS:
625 * 0 on success, -errno otherwise.
626 */
627static int piix_sata_softreset(struct ata_port *ap, unsigned int *classes)
628{
629 unsigned int present_mask;
630 int i, rc;
631
632 present_mask = piix_sata_present_mask(ap);
633
634 rc = ata_std_softreset(ap, classes);
635 if (rc)
636 return rc;
637
638 for (i = 0; i < ATA_MAX_DEVICES; i++) {
639 if (!(present_mask & (1 << i)))
640 classes[i] = ATA_DEV_NONE;
554 } 641 }
555 642
556 return ata_std_prereset(ap); 643 return 0;
557} 644}
558 645
559static void piix_sata_error_handler(struct ata_port *ap) 646static void piix_sata_error_handler(struct ata_port *ap)
560{ 647{
561 ata_bmdma_drive_eh(ap, piix_sata_prereset, ata_std_softreset, NULL, 648 ata_bmdma_drive_eh(ap, ata_std_prereset, piix_sata_softreset, NULL,
562 ata_std_postreset); 649 ata_std_postreset);
563} 650}
564 651
@@ -761,10 +848,40 @@ static int __devinit piix_check_450nx_errata(struct pci_dev *ata_dev)
761 return no_piix_dma; 848 return no_piix_dma;
762} 849}
763 850
851static void __devinit piix_init_pcs(struct pci_dev *pdev,
852 struct ata_port_info *pinfo,
853 const struct piix_map_db *map_db)
854{
855 u16 pcs, new_pcs;
856
857 pci_read_config_word(pdev, ICH5_PCS, &pcs);
858
859 new_pcs = pcs | map_db->port_enable;
860
861 if (new_pcs != pcs) {
862 DPRINTK("updating PCS from 0x%x to 0x%x\n", pcs, new_pcs);
863 pci_write_config_word(pdev, ICH5_PCS, new_pcs);
864 msleep(150);
865 }
866
867 if (force_pcs == 1) {
868 dev_printk(KERN_INFO, &pdev->dev,
869 "force ignoring PCS (0x%x)\n", new_pcs);
870 pinfo[0].host_flags |= PIIX_FLAG_IGNORE_PCS;
871 pinfo[1].host_flags |= PIIX_FLAG_IGNORE_PCS;
872 } else if (force_pcs == 2) {
873 dev_printk(KERN_INFO, &pdev->dev,
874 "force honoring PCS (0x%x)\n", new_pcs);
875 pinfo[0].host_flags &= ~PIIX_FLAG_IGNORE_PCS;
876 pinfo[1].host_flags &= ~PIIX_FLAG_IGNORE_PCS;
877 }
878}
879
764static void __devinit piix_init_sata_map(struct pci_dev *pdev, 880static void __devinit piix_init_sata_map(struct pci_dev *pdev,
765 struct ata_port_info *pinfo) 881 struct ata_port_info *pinfo,
882 const struct piix_map_db *map_db)
766{ 883{
767 struct piix_map_db *map_db = pinfo[0].private_data; 884 struct piix_host_priv *hpriv = pinfo[0].private_data;
768 const unsigned int *map; 885 const unsigned int *map;
769 int i, invalid_map = 0; 886 int i, invalid_map = 0;
770 u8 map_value; 887 u8 map_value;
@@ -788,6 +905,7 @@ static void __devinit piix_init_sata_map(struct pci_dev *pdev,
788 case IDE: 905 case IDE:
789 WARN_ON((i & 1) || map[i + 1] != IDE); 906 WARN_ON((i & 1) || map[i + 1] != IDE);
790 pinfo[i / 2] = piix_port_info[ich5_pata]; 907 pinfo[i / 2] = piix_port_info[ich5_pata];
908 pinfo[i / 2].private_data = hpriv;
791 i++; 909 i++;
792 printk(" IDE IDE"); 910 printk(" IDE IDE");
793 break; 911 break;
@@ -805,8 +923,8 @@ static void __devinit piix_init_sata_map(struct pci_dev *pdev,
805 dev_printk(KERN_ERR, &pdev->dev, 923 dev_printk(KERN_ERR, &pdev->dev,
806 "invalid MAP value %u\n", map_value); 924 "invalid MAP value %u\n", map_value);
807 925
808 pinfo[0].private_data = (void *)map; 926 hpriv->map = map;
809 pinfo[1].private_data = (void *)map; 927 hpriv->map_db = map_db;
810} 928}
811 929
812/** 930/**
@@ -829,6 +947,7 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
829 static int printed_version; 947 static int printed_version;
830 struct ata_port_info port_info[2]; 948 struct ata_port_info port_info[2];
831 struct ata_port_info *ppinfo[2] = { &port_info[0], &port_info[1] }; 949 struct ata_port_info *ppinfo[2] = { &port_info[0], &port_info[1] };
950 struct piix_host_priv *hpriv;
832 unsigned long host_flags; 951 unsigned long host_flags;
833 952
834 if (!printed_version++) 953 if (!printed_version++)
@@ -839,8 +958,14 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
839 if (!in_module_init) 958 if (!in_module_init)
840 return -ENODEV; 959 return -ENODEV;
841 960
961 hpriv = kzalloc(sizeof(*hpriv), GFP_KERNEL);
962 if (!hpriv)
963 return -ENOMEM;
964
842 port_info[0] = piix_port_info[ent->driver_data]; 965 port_info[0] = piix_port_info[ent->driver_data];
843 port_info[1] = piix_port_info[ent->driver_data]; 966 port_info[1] = piix_port_info[ent->driver_data];
967 port_info[0].private_data = hpriv;
968 port_info[1].private_data = hpriv;
844 969
845 host_flags = port_info[0].host_flags; 970 host_flags = port_info[0].host_flags;
846 971
@@ -855,8 +980,12 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
855 } 980 }
856 981
857 /* Initialize SATA map */ 982 /* Initialize SATA map */
858 if (host_flags & ATA_FLAG_SATA) 983 if (host_flags & ATA_FLAG_SATA) {
859 piix_init_sata_map(pdev, port_info); 984 piix_init_sata_map(pdev, port_info,
985 piix_map_db_table[ent->driver_data]);
986 piix_init_pcs(pdev, port_info,
987 piix_map_db_table[ent->driver_data]);
988 }
860 989
861 /* On ICH5, some BIOSen disable the interrupt using the 990 /* On ICH5, some BIOSen disable the interrupt using the
862 * PCI_COMMAND_INTX_DISABLE bit added in PCI 2.3. 991 * PCI_COMMAND_INTX_DISABLE bit added in PCI 2.3.
@@ -879,6 +1008,13 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
879 return ata_pci_init_one(pdev, ppinfo, 2); 1008 return ata_pci_init_one(pdev, ppinfo, 2);
880} 1009}
881 1010
1011static void piix_host_stop(struct ata_host_set *host_set)
1012{
1013 if (host_set->next == NULL)
1014 kfree(host_set->private_data);
1015 ata_host_stop(host_set);
1016}
1017
882static int __init piix_init(void) 1018static int __init piix_init(void)
883{ 1019{
884 int rc; 1020 int rc;
diff --git a/drivers/scsi/atari_NCR5380.c b/drivers/scsi/atari_NCR5380.c
index 007a14e5c3fd..e397129c90d1 100644
--- a/drivers/scsi/atari_NCR5380.c
+++ b/drivers/scsi/atari_NCR5380.c
@@ -507,7 +507,7 @@ static __inline__ void initialize_SCp(Scsi_Cmnd *cmd)
507 */ 507 */
508 508
509 if (cmd->use_sg) { 509 if (cmd->use_sg) {
510 cmd->SCp.buffer = (struct scatterlist *) cmd->buffer; 510 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
511 cmd->SCp.buffers_residual = cmd->use_sg - 1; 511 cmd->SCp.buffers_residual = cmd->use_sg - 1;
512 cmd->SCp.ptr = (char *)page_address(cmd->SCp.buffer->page)+ 512 cmd->SCp.ptr = (char *)page_address(cmd->SCp.buffer->page)+
513 cmd->SCp.buffer->offset; 513 cmd->SCp.buffer->offset;
diff --git a/drivers/scsi/atp870u.c b/drivers/scsi/atp870u.c
index 412f8301b757..0ec41f34f462 100644
--- a/drivers/scsi/atp870u.c
+++ b/drivers/scsi/atp870u.c
@@ -2625,29 +2625,32 @@ static int atp870u_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2625 unsigned int base_io, tmport, error,n; 2625 unsigned int base_io, tmport, error,n;
2626 unsigned char host_id; 2626 unsigned char host_id;
2627 struct Scsi_Host *shpnt = NULL; 2627 struct Scsi_Host *shpnt = NULL;
2628 struct atp_unit atp_dev, *p; 2628 struct atp_unit *atpdev, *p;
2629 unsigned char setupdata[2][16]; 2629 unsigned char setupdata[2][16];
2630 int count = 0; 2630 int count = 0;
2631 2631
2632 atpdev = kzalloc(sizeof(*atpdev), GFP_KERNEL);
2633 if (!atpdev)
2634 return -ENOMEM;
2635
2632 if (pci_enable_device(pdev)) 2636 if (pci_enable_device(pdev))
2633 return -EIO; 2637 goto err_eio;
2634 2638
2635 if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) { 2639 if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
2636 printk(KERN_INFO "atp870u: use 32bit DMA mask.\n"); 2640 printk(KERN_INFO "atp870u: use 32bit DMA mask.\n");
2637 } else { 2641 } else {
2638 printk(KERN_ERR "atp870u: DMA mask required but not available.\n"); 2642 printk(KERN_ERR "atp870u: DMA mask required but not available.\n");
2639 return -EIO; 2643 goto err_eio;
2640 } 2644 }
2641 2645
2642 memset(&atp_dev, 0, sizeof atp_dev);
2643 /* 2646 /*
2644 * It's probably easier to weed out some revisions like 2647 * It's probably easier to weed out some revisions like
2645 * this than via the PCI device table 2648 * this than via the PCI device table
2646 */ 2649 */
2647 if (ent->device == PCI_DEVICE_ID_ARTOP_AEC7610) { 2650 if (ent->device == PCI_DEVICE_ID_ARTOP_AEC7610) {
2648 error = pci_read_config_byte(pdev, PCI_CLASS_REVISION, &atp_dev.chip_ver); 2651 error = pci_read_config_byte(pdev, PCI_CLASS_REVISION, &atpdev->chip_ver);
2649 if (atp_dev.chip_ver < 2) 2652 if (atpdev->chip_ver < 2)
2650 return -EIO; 2653 goto err_eio;
2651 } 2654 }
2652 2655
2653 switch (ent->device) { 2656 switch (ent->device) {
@@ -2656,15 +2659,15 @@ static int atp870u_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2656 case ATP880_DEVID1: 2659 case ATP880_DEVID1:
2657 case ATP880_DEVID2: 2660 case ATP880_DEVID2:
2658 case ATP885_DEVID: 2661 case ATP885_DEVID:
2659 atp_dev.chip_ver = 0x04; 2662 atpdev->chip_ver = 0x04;
2660 default: 2663 default:
2661 break; 2664 break;
2662 } 2665 }
2663 base_io = pci_resource_start(pdev, 0); 2666 base_io = pci_resource_start(pdev, 0);
2664 base_io &= 0xfffffff8; 2667 base_io &= 0xfffffff8;
2665 2668
2666 if ((ent->device == ATP880_DEVID1)||(ent->device == ATP880_DEVID2)) { 2669 if ((ent->device == ATP880_DEVID1)||(ent->device == ATP880_DEVID2)) {
2667 error = pci_read_config_byte(pdev, PCI_CLASS_REVISION, &atp_dev.chip_ver); 2670 error = pci_read_config_byte(pdev, PCI_CLASS_REVISION, &atpdev->chip_ver);
2668 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);//JCC082803 2671 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);//JCC082803
2669 2672
2670 host_id = inb(base_io + 0x39); 2673 host_id = inb(base_io + 0x39);
@@ -2672,17 +2675,17 @@ static int atp870u_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2672 2675
2673 printk(KERN_INFO " ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d" 2676 printk(KERN_INFO " ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
2674 " IO:%x, IRQ:%d.\n", count, base_io, pdev->irq); 2677 " IO:%x, IRQ:%d.\n", count, base_io, pdev->irq);
2675 atp_dev.ioport[0] = base_io + 0x40; 2678 atpdev->ioport[0] = base_io + 0x40;
2676 atp_dev.pciport[0] = base_io + 0x28; 2679 atpdev->pciport[0] = base_io + 0x28;
2677 atp_dev.dev_id = ent->device; 2680 atpdev->dev_id = ent->device;
2678 atp_dev.host_id[0] = host_id; 2681 atpdev->host_id[0] = host_id;
2679 2682
2680 tmport = base_io + 0x22; 2683 tmport = base_io + 0x22;
2681 atp_dev.scam_on = inb(tmport); 2684 atpdev->scam_on = inb(tmport);
2682 tmport += 0x13; 2685 tmport += 0x13;
2683 atp_dev.global_map[0] = inb(tmport); 2686 atpdev->global_map[0] = inb(tmport);
2684 tmport += 0x07; 2687 tmport += 0x07;
2685 atp_dev.ultra_map[0] = inw(tmport); 2688 atpdev->ultra_map[0] = inw(tmport);
2686 2689
2687 n = 0x3f09; 2690 n = 0x3f09;
2688next_fblk_880: 2691next_fblk_880:
@@ -2695,57 +2698,57 @@ next_fblk_880:
2695 if (inb(base_io + 0x30) == 0xff) 2698 if (inb(base_io + 0x30) == 0xff)
2696 goto flash_ok_880; 2699 goto flash_ok_880;
2697 2700
2698 atp_dev.sp[0][m++] = inb(base_io + 0x30); 2701 atpdev->sp[0][m++] = inb(base_io + 0x30);
2699 atp_dev.sp[0][m++] = inb(base_io + 0x31); 2702 atpdev->sp[0][m++] = inb(base_io + 0x31);
2700 atp_dev.sp[0][m++] = inb(base_io + 0x32); 2703 atpdev->sp[0][m++] = inb(base_io + 0x32);
2701 atp_dev.sp[0][m++] = inb(base_io + 0x33); 2704 atpdev->sp[0][m++] = inb(base_io + 0x33);
2702 outw(n, base_io + 0x34); 2705 outw(n, base_io + 0x34);
2703 n += 0x0002; 2706 n += 0x0002;
2704 atp_dev.sp[0][m++] = inb(base_io + 0x30); 2707 atpdev->sp[0][m++] = inb(base_io + 0x30);
2705 atp_dev.sp[0][m++] = inb(base_io + 0x31); 2708 atpdev->sp[0][m++] = inb(base_io + 0x31);
2706 atp_dev.sp[0][m++] = inb(base_io + 0x32); 2709 atpdev->sp[0][m++] = inb(base_io + 0x32);
2707 atp_dev.sp[0][m++] = inb(base_io + 0x33); 2710 atpdev->sp[0][m++] = inb(base_io + 0x33);
2708 outw(n, base_io + 0x34); 2711 outw(n, base_io + 0x34);
2709 n += 0x0002; 2712 n += 0x0002;
2710 atp_dev.sp[0][m++] = inb(base_io + 0x30); 2713 atpdev->sp[0][m++] = inb(base_io + 0x30);
2711 atp_dev.sp[0][m++] = inb(base_io + 0x31); 2714 atpdev->sp[0][m++] = inb(base_io + 0x31);
2712 atp_dev.sp[0][m++] = inb(base_io + 0x32); 2715 atpdev->sp[0][m++] = inb(base_io + 0x32);
2713 atp_dev.sp[0][m++] = inb(base_io + 0x33); 2716 atpdev->sp[0][m++] = inb(base_io + 0x33);
2714 outw(n, base_io + 0x34); 2717 outw(n, base_io + 0x34);
2715 n += 0x0002; 2718 n += 0x0002;
2716 atp_dev.sp[0][m++] = inb(base_io + 0x30); 2719 atpdev->sp[0][m++] = inb(base_io + 0x30);
2717 atp_dev.sp[0][m++] = inb(base_io + 0x31); 2720 atpdev->sp[0][m++] = inb(base_io + 0x31);
2718 atp_dev.sp[0][m++] = inb(base_io + 0x32); 2721 atpdev->sp[0][m++] = inb(base_io + 0x32);
2719 atp_dev.sp[0][m++] = inb(base_io + 0x33); 2722 atpdev->sp[0][m++] = inb(base_io + 0x33);
2720 n += 0x0018; 2723 n += 0x0018;
2721 goto next_fblk_880; 2724 goto next_fblk_880;
2722flash_ok_880: 2725flash_ok_880:
2723 outw(0, base_io + 0x34); 2726 outw(0, base_io + 0x34);
2724 atp_dev.ultra_map[0] = 0; 2727 atpdev->ultra_map[0] = 0;
2725 atp_dev.async[0] = 0; 2728 atpdev->async[0] = 0;
2726 for (k = 0; k < 16; k++) { 2729 for (k = 0; k < 16; k++) {
2727 n = 1; 2730 n = 1;
2728 n = n << k; 2731 n = n << k;
2729 if (atp_dev.sp[0][k] > 1) { 2732 if (atpdev->sp[0][k] > 1) {
2730 atp_dev.ultra_map[0] |= n; 2733 atpdev->ultra_map[0] |= n;
2731 } else { 2734 } else {
2732 if (atp_dev.sp[0][k] == 0) 2735 if (atpdev->sp[0][k] == 0)
2733 atp_dev.async[0] |= n; 2736 atpdev->async[0] |= n;
2734 } 2737 }
2735 } 2738 }
2736 atp_dev.async[0] = ~(atp_dev.async[0]); 2739 atpdev->async[0] = ~(atpdev->async[0]);
2737 outb(atp_dev.global_map[0], base_io + 0x35); 2740 outb(atpdev->global_map[0], base_io + 0x35);
2738 2741
2739 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit)); 2742 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
2740 if (!shpnt) 2743 if (!shpnt)
2741 return -ENOMEM; 2744 goto err_nomem;
2742 2745
2743 p = (struct atp_unit *)&shpnt->hostdata; 2746 p = (struct atp_unit *)&shpnt->hostdata;
2744 2747
2745 atp_dev.host = shpnt; 2748 atpdev->host = shpnt;
2746 atp_dev.pdev = pdev; 2749 atpdev->pdev = pdev;
2747 pci_set_drvdata(pdev, p); 2750 pci_set_drvdata(pdev, p);
2748 memcpy(p, &atp_dev, sizeof atp_dev); 2751 memcpy(p, atpdev, sizeof(*atpdev));
2749 if (atp870u_init_tables(shpnt) < 0) { 2752 if (atp870u_init_tables(shpnt) < 0) {
2750 printk(KERN_ERR "Unable to allocate tables for Acard controller\n"); 2753 printk(KERN_ERR "Unable to allocate tables for Acard controller\n");
2751 goto unregister; 2754 goto unregister;
@@ -2798,24 +2801,24 @@ flash_ok_880:
2798 printk(KERN_INFO " ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n" 2801 printk(KERN_INFO " ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
2799 , base_io, pdev->irq); 2802 , base_io, pdev->irq);
2800 2803
2801 atp_dev.pdev = pdev; 2804 atpdev->pdev = pdev;
2802 atp_dev.dev_id = ent->device; 2805 atpdev->dev_id = ent->device;
2803 atp_dev.baseport = base_io; 2806 atpdev->baseport = base_io;
2804 atp_dev.ioport[0] = base_io + 0x80; 2807 atpdev->ioport[0] = base_io + 0x80;
2805 atp_dev.ioport[1] = base_io + 0xc0; 2808 atpdev->ioport[1] = base_io + 0xc0;
2806 atp_dev.pciport[0] = base_io + 0x40; 2809 atpdev->pciport[0] = base_io + 0x40;
2807 atp_dev.pciport[1] = base_io + 0x50; 2810 atpdev->pciport[1] = base_io + 0x50;
2808 2811
2809 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit)); 2812 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
2810 if (!shpnt) 2813 if (!shpnt)
2811 return -ENOMEM; 2814 goto err_nomem;
2812 2815
2813 p = (struct atp_unit *)&shpnt->hostdata; 2816 p = (struct atp_unit *)&shpnt->hostdata;
2814 2817
2815 atp_dev.host = shpnt; 2818 atpdev->host = shpnt;
2816 atp_dev.pdev = pdev; 2819 atpdev->pdev = pdev;
2817 pci_set_drvdata(pdev, p); 2820 pci_set_drvdata(pdev, p);
2818 memcpy(p, &atp_dev, sizeof(struct atp_unit)); 2821 memcpy(p, atpdev, sizeof(struct atp_unit));
2819 if (atp870u_init_tables(shpnt) < 0) 2822 if (atp870u_init_tables(shpnt) < 0)
2820 goto unregister; 2823 goto unregister;
2821 2824
@@ -2974,33 +2977,33 @@ flash_ok_885:
2974 printk(KERN_INFO " ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d " 2977 printk(KERN_INFO " ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
2975 "IO:%x, IRQ:%d.\n", count, base_io, pdev->irq); 2978 "IO:%x, IRQ:%d.\n", count, base_io, pdev->irq);
2976 2979
2977 atp_dev.ioport[0] = base_io; 2980 atpdev->ioport[0] = base_io;
2978 atp_dev.pciport[0] = base_io + 0x20; 2981 atpdev->pciport[0] = base_io + 0x20;
2979 atp_dev.dev_id = ent->device; 2982 atpdev->dev_id = ent->device;
2980 host_id &= 0x07; 2983 host_id &= 0x07;
2981 atp_dev.host_id[0] = host_id; 2984 atpdev->host_id[0] = host_id;
2982 tmport = base_io + 0x22; 2985 tmport = base_io + 0x22;
2983 atp_dev.scam_on = inb(tmport); 2986 atpdev->scam_on = inb(tmport);
2984 tmport += 0x0b; 2987 tmport += 0x0b;
2985 atp_dev.global_map[0] = inb(tmport++); 2988 atpdev->global_map[0] = inb(tmport++);
2986 atp_dev.ultra_map[0] = inw(tmport); 2989 atpdev->ultra_map[0] = inw(tmport);
2987 2990
2988 if (atp_dev.ultra_map[0] == 0) { 2991 if (atpdev->ultra_map[0] == 0) {
2989 atp_dev.scam_on = 0x00; 2992 atpdev->scam_on = 0x00;
2990 atp_dev.global_map[0] = 0x20; 2993 atpdev->global_map[0] = 0x20;
2991 atp_dev.ultra_map[0] = 0xffff; 2994 atpdev->ultra_map[0] = 0xffff;
2992 } 2995 }
2993 2996
2994 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit)); 2997 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
2995 if (!shpnt) 2998 if (!shpnt)
2996 return -ENOMEM; 2999 goto err_nomem;
2997 3000
2998 p = (struct atp_unit *)&shpnt->hostdata; 3001 p = (struct atp_unit *)&shpnt->hostdata;
2999 3002
3000 atp_dev.host = shpnt; 3003 atpdev->host = shpnt;
3001 atp_dev.pdev = pdev; 3004 atpdev->pdev = pdev;
3002 pci_set_drvdata(pdev, p); 3005 pci_set_drvdata(pdev, p);
3003 memcpy(p, &atp_dev, sizeof atp_dev); 3006 memcpy(p, atpdev, sizeof(*atpdev));
3004 if (atp870u_init_tables(shpnt) < 0) 3007 if (atp870u_init_tables(shpnt) < 0)
3005 goto unregister; 3008 goto unregister;
3006 3009
@@ -3010,7 +3013,7 @@ flash_ok_885:
3010 } 3013 }
3011 3014
3012 spin_lock_irqsave(shpnt->host_lock, flags); 3015 spin_lock_irqsave(shpnt->host_lock, flags);
3013 if (atp_dev.chip_ver > 0x07) { /* check if atp876 chip then enable terminator */ 3016 if (atpdev->chip_ver > 0x07) { /* check if atp876 chip then enable terminator */
3014 tmport = base_io + 0x3e; 3017 tmport = base_io + 0x3e;
3015 outb(0x00, tmport); 3018 outb(0x00, tmport);
3016 } 3019 }
@@ -3044,7 +3047,7 @@ flash_ok_885:
3044 outb((inb(tmport) & 0xef), tmport); 3047 outb((inb(tmport) & 0xef), tmport);
3045 tmport++; 3048 tmport++;
3046 outb((inb(tmport) | 0x20), tmport); 3049 outb((inb(tmport) | 0x20), tmport);
3047 if (atp_dev.chip_ver == 4) 3050 if (atpdev->chip_ver == 4)
3048 shpnt->max_id = 16; 3051 shpnt->max_id = 16;
3049 else 3052 else
3050 shpnt->max_id = 8; 3053 shpnt->max_id = 8;
@@ -3093,6 +3096,12 @@ unregister:
3093 printk("atp870u_prob:unregister\n"); 3096 printk("atp870u_prob:unregister\n");
3094 scsi_host_put(shpnt); 3097 scsi_host_put(shpnt);
3095 return -1; 3098 return -1;
3099err_eio:
3100 kfree(atpdev);
3101 return -EIO;
3102err_nomem:
3103 kfree(atpdev);
3104 return -ENOMEM;
3096} 3105}
3097 3106
3098/* The abort command does not leave the device in a clean state where 3107/* The abort command does not leave the device in a clean state where
diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index dddd2acce76f..61f6024b61ba 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -5,6 +5,7 @@
5 * Additions for SCSI 3+ (SPC-3 T10/1416-D Rev 07 3 May 2002) 5 * Additions for SCSI 3+ (SPC-3 T10/1416-D Rev 07 3 May 2002)
6 * by D. Gilbert and aeb (20020609) 6 * by D. Gilbert and aeb (20020609)
7 * Additions for SPC-3 T10/1416-D Rev 21 22 Sept 2004, D. Gilbert 20041025 7 * Additions for SPC-3 T10/1416-D Rev 21 22 Sept 2004, D. Gilbert 20041025
8 * Update to SPC-4 T10/1713-D Rev 5a, 14 June 2006, D. Gilbert 20060702
8 */ 9 */
9 10
10#include <linux/blkdev.h> 11#include <linux/blkdev.h>
@@ -36,55 +37,56 @@ static const char * cdb_byte0_names[] = {
36/* 00-03 */ "Test Unit Ready", "Rezero Unit/Rewind", NULL, "Request Sense", 37/* 00-03 */ "Test Unit Ready", "Rezero Unit/Rewind", NULL, "Request Sense",
37/* 04-07 */ "Format Unit/Medium", "Read Block Limits", NULL, 38/* 04-07 */ "Format Unit/Medium", "Read Block Limits", NULL,
38 "Reasssign Blocks", 39 "Reasssign Blocks",
39/* 08-0d */ "Read (6)", NULL, "Write (6)", "Seek (6)", NULL, NULL, 40/* 08-0d */ "Read(6)", NULL, "Write(6)", "Seek(6)", NULL, NULL,
40/* 0e-12 */ NULL, "Read Reverse", "Write Filemarks", "Space", "Inquiry", 41/* 0e-12 */ NULL, "Read Reverse", "Write Filemarks", "Space", "Inquiry",
41/* 13-16 */ "Verify (6)", "Recover Buffered Data", "Mode Select (6)", 42/* 13-16 */ "Verify(6)", "Recover Buffered Data", "Mode Select(6)",
42 "Reserve (6)", 43 "Reserve(6)",
43/* 17-1a */ "Release (6)", "Copy", "Erase", "Mode Sense (6)", 44/* 17-1a */ "Release(6)", "Copy", "Erase", "Mode Sense(6)",
44/* 1b-1d */ "Start/Stop Unit", "Receive Diagnostic", "Send Diagnostic", 45/* 1b-1d */ "Start/Stop Unit", "Receive Diagnostic", "Send Diagnostic",
45/* 1e-1f */ "Prevent/Allow Medium Removal", NULL, 46/* 1e-1f */ "Prevent/Allow Medium Removal", NULL,
46/* 20-22 */ NULL, NULL, NULL, 47/* 20-22 */ NULL, NULL, NULL,
47/* 23-28 */ "Read Format Capacities", "Set Window", 48/* 23-28 */ "Read Format Capacities", "Set Window",
48 "Read Capacity (10)", NULL, NULL, "Read (10)", 49 "Read Capacity(10)", NULL, NULL, "Read(10)",
49/* 29-2d */ "Read Generation", "Write (10)", "Seek (10)", "Erase (10)", 50/* 29-2d */ "Read Generation", "Write(10)", "Seek(10)", "Erase(10)",
50 "Read updated block", 51 "Read updated block",
51/* 2e-31 */ "Write Verify (10)", "Verify (10)", "Search High", "Search Equal", 52/* 2e-31 */ "Write Verify(10)", "Verify(10)", "Search High", "Search Equal",
52/* 32-34 */ "Search Low", "Set Limits", "Prefetch/Read Position", 53/* 32-34 */ "Search Low", "Set Limits", "Prefetch/Read Position",
53/* 35-37 */ "Synchronize Cache (10)", "Lock/Unlock Cache (10)", 54/* 35-37 */ "Synchronize Cache(10)", "Lock/Unlock Cache(10)",
54 "Read Defect Data(10)", 55 "Read Defect Data(10)",
55/* 38-3c */ "Medium Scan", "Compare", "Copy Verify", "Write Buffer", 56/* 38-3c */ "Medium Scan", "Compare", "Copy Verify", "Write Buffer",
56 "Read Buffer", 57 "Read Buffer",
57/* 3d-3f */ "Update Block", "Read Long (10)", "Write Long (10)", 58/* 3d-3f */ "Update Block", "Read Long(10)", "Write Long(10)",
58/* 40-41 */ "Change Definition", "Write Same (10)", 59/* 40-41 */ "Change Definition", "Write Same(10)",
59/* 42-48 */ "Read sub-channel", "Read TOC/PMA/ATIP", "Read density support", 60/* 42-48 */ "Read sub-channel", "Read TOC/PMA/ATIP", "Read density support",
60 "Play audio (10)", "Get configuration", "Play audio msf", 61 "Play audio(10)", "Get configuration", "Play audio msf",
61 "Play audio track/index", 62 "Play audio track/index",
62/* 49-4f */ "Play track relative (10)", "Get event status notification", 63/* 49-4f */ "Play track relative(10)", "Get event status notification",
63 "Pause/resume", "Log Select", "Log Sense", "Stop play/scan", 64 "Pause/resume", "Log Select", "Log Sense", "Stop play/scan",
64 NULL, 65 NULL,
65/* 50-55 */ "Xdwrite", "Xpwrite, Read disk info", "Xdread, Read track info", 66/* 50-55 */ "Xdwrite", "Xpwrite, Read disk info", "Xdread, Read track info",
66 "Reserve track", "Send OPC info", "Mode Select (10)", 67 "Reserve track", "Send OPC info", "Mode Select(10)",
67/* 56-5b */ "Reserve (10)", "Release (10)", "Repair track", "Read master cue", 68/* 56-5b */ "Reserve(10)", "Release(10)", "Repair track", "Read master cue",
68 "Mode Sense (10)", "Close track/session", 69 "Mode Sense(10)", "Close track/session",
69/* 5c-5f */ "Read buffer capacity", "Send cue sheet", "Persistent reserve in", 70/* 5c-5f */ "Read buffer capacity", "Send cue sheet", "Persistent reserve in",
70 "Persistent reserve out", 71 "Persistent reserve out",
71/* 60-67 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 72/* 60-67 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
72/* 68-6f */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 73/* 68-6f */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
73/* 70-77 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 74/* 70-77 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
74/* 78-7f */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, "Variable length", 75/* 78-7f */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, "Variable length",
75/* 80-84 */ "Xdwrite (16)", "Rebuild (16)", "Regenerate (16)", "Extended copy", 76/* 80-84 */ "Xdwrite(16)", "Rebuild(16)", "Regenerate(16)", "Extended copy",
76 "Receive copy results", 77 "Receive copy results",
77/* 85-89 */ "Memory Export In (16)", "Access control in", "Access control out", 78/* 85-89 */ "ATA command pass through(16)", "Access control in",
78 "Read (16)", "Memory Export Out (16)", 79 "Access control out", "Read(16)", "Memory Export Out(16)",
79/* 8a-8f */ "Write (16)", NULL, "Read attributes", "Write attributes", 80/* 8a-8f */ "Write(16)", NULL, "Read attributes", "Write attributes",
80 "Write and verify (16)", "Verify (16)", 81 "Write and verify(16)", "Verify(16)",
81/* 90-94 */ "Pre-fetch (16)", "Synchronize cache (16)", 82/* 90-94 */ "Pre-fetch(16)", "Synchronize cache(16)",
82 "Lock/unlock cache (16)", "Write same (16)", NULL, 83 "Lock/unlock cache(16)", "Write same(16)", NULL,
83/* 95-99 */ NULL, NULL, NULL, NULL, NULL, 84/* 95-99 */ NULL, NULL, NULL, NULL, NULL,
84/* 9a-9f */ NULL, NULL, NULL, NULL, "Service action in (16)", 85/* 9a-9f */ NULL, NULL, NULL, NULL, "Service action in(16)",
85 "Service action out (16)", 86 "Service action out(16)",
86/* a0-a5 */ "Report luns", "Blank", "Send event", "Maintenance in", 87/* a0-a5 */ "Report luns", "ATA command pass through(12)/Blank",
87 "Maintenance out", "Move medium/play audio(12)", 88 "Security protocol in", "Maintenance in", "Maintenance out",
89 "Move medium/play audio(12)",
88/* a6-a9 */ "Exchange medium", "Move medium attached", "Read(12)", 90/* a6-a9 */ "Exchange medium", "Move medium attached", "Read(12)",
89 "Play track relative(12)", 91 "Play track relative(12)",
90/* aa-ae */ "Write(12)", NULL, "Erase(12), Get Performance", 92/* aa-ae */ "Write(12)", NULL, "Erase(12), Get Performance",
@@ -92,12 +94,12 @@ static const char * cdb_byte0_names[] = {
92/* af-b1 */ "Verify(12)", "Search data high(12)", "Search data equal(12)", 94/* af-b1 */ "Verify(12)", "Search data high(12)", "Search data equal(12)",
93/* b2-b4 */ "Search data low(12)", "Set limits(12)", 95/* b2-b4 */ "Search data low(12)", "Set limits(12)",
94 "Read element status attached", 96 "Read element status attached",
95/* b5-b6 */ "Request volume element address", "Send volume tag, set streaming", 97/* b5-b6 */ "Security protocol out", "Send volume tag, set streaming",
96/* b7-b9 */ "Read defect data(12)", "Read element status", "Read CD msf", 98/* b7-b9 */ "Read defect data(12)", "Read element status", "Read CD msf",
97/* ba-bc */ "Redundancy group (in), Scan", 99/* ba-bc */ "Redundancy group (in), Scan",
98 "Redundancy group (out), Set cd-rom speed", "Spare in, Play cd", 100 "Redundancy group (out), Set cd-rom speed", "Spare (in), Play cd",
99/* bd-bf */ "Spare out, Mechanism status", "Volume set in, Read cd", 101/* bd-bf */ "Spare (out), Mechanism status", "Volume set (in), Read cd",
100 "Volume set out, Send DVD structure", 102 "Volume set (out), Send DVD structure",
101}; 103};
102 104
103struct value_name_pair { 105struct value_name_pair {
@@ -112,6 +114,7 @@ static const struct value_name_pair maint_in_arr[] = {
112 {0xc, "Report supported operation codes"}, 114 {0xc, "Report supported operation codes"},
113 {0xd, "Report supported task management functions"}, 115 {0xd, "Report supported task management functions"},
114 {0xe, "Report priority"}, 116 {0xe, "Report priority"},
117 {0xf, "Report timestamp"},
115}; 118};
116#define MAINT_IN_SZ ARRAY_SIZE(maint_in_arr) 119#define MAINT_IN_SZ ARRAY_SIZE(maint_in_arr)
117 120
@@ -120,6 +123,7 @@ static const struct value_name_pair maint_out_arr[] = {
120 {0xa, "Set target port groups"}, 123 {0xa, "Set target port groups"},
121 {0xb, "Change aliases"}, 124 {0xb, "Change aliases"},
122 {0xe, "Set priority"}, 125 {0xe, "Set priority"},
126 {0xe, "Set timestamp"},
123}; 127};
124#define MAINT_OUT_SZ ARRAY_SIZE(maint_out_arr) 128#define MAINT_OUT_SZ ARRAY_SIZE(maint_out_arr)
125 129
@@ -427,6 +431,7 @@ static struct error_info additional[] =
427 {0x001A, "Rewind operation in progress"}, 431 {0x001A, "Rewind operation in progress"},
428 {0x001B, "Set capacity operation in progress"}, 432 {0x001B, "Set capacity operation in progress"},
429 {0x001C, "Verify operation in progress"}, 433 {0x001C, "Verify operation in progress"},
434 {0x001D, "ATA pass through information available"},
430 435
431 {0x0100, "No index/sector signal"}, 436 {0x0100, "No index/sector signal"},
432 437
@@ -438,7 +443,7 @@ static struct error_info additional[] =
438 443
439 {0x0400, "Logical unit not ready, cause not reportable"}, 444 {0x0400, "Logical unit not ready, cause not reportable"},
440 {0x0401, "Logical unit is in process of becoming ready"}, 445 {0x0401, "Logical unit is in process of becoming ready"},
441 {0x0402, "Logical unit not ready, initializing cmd. required"}, 446 {0x0402, "Logical unit not ready, initializing command required"},
442 {0x0403, "Logical unit not ready, manual intervention required"}, 447 {0x0403, "Logical unit not ready, manual intervention required"},
443 {0x0404, "Logical unit not ready, format in progress"}, 448 {0x0404, "Logical unit not ready, format in progress"},
444 {0x0405, "Logical unit not ready, rebuild in progress"}, 449 {0x0405, "Logical unit not ready, rebuild in progress"},
@@ -478,6 +483,9 @@ static struct error_info additional[] =
478 {0x0B00, "Warning"}, 483 {0x0B00, "Warning"},
479 {0x0B01, "Warning - specified temperature exceeded"}, 484 {0x0B01, "Warning - specified temperature exceeded"},
480 {0x0B02, "Warning - enclosure degraded"}, 485 {0x0B02, "Warning - enclosure degraded"},
486 {0x0B03, "Warning - background self-test failed"},
487 {0x0B04, "Warning - background pre-scan detected medium error"},
488 {0x0B05, "Warning - background medium scan detected medium error"},
481 489
482 {0x0C00, "Write error"}, 490 {0x0C00, "Write error"},
483 {0x0C01, "Write error - recovered with auto reallocation"}, 491 {0x0C01, "Write error - recovered with auto reallocation"},
@@ -493,6 +501,7 @@ static struct error_info additional[] =
493 {0x0C0B, "Auxiliary memory write error"}, 501 {0x0C0B, "Auxiliary memory write error"},
494 {0x0C0C, "Write error - unexpected unsolicited data"}, 502 {0x0C0C, "Write error - unexpected unsolicited data"},
495 {0x0C0D, "Write error - not enough unsolicited data"}, 503 {0x0C0D, "Write error - not enough unsolicited data"},
504 {0x0C0F, "Defects in error window"},
496 505
497 {0x0D00, "Error detected by third party temporary initiator"}, 506 {0x0D00, "Error detected by third party temporary initiator"},
498 {0x0D01, "Third party device failure"}, 507 {0x0D01, "Third party device failure"},
@@ -504,11 +513,12 @@ static struct error_info additional[] =
504 {0x0E00, "Invalid information unit"}, 513 {0x0E00, "Invalid information unit"},
505 {0x0E01, "Information unit too short"}, 514 {0x0E01, "Information unit too short"},
506 {0x0E02, "Information unit too long"}, 515 {0x0E02, "Information unit too long"},
516 {0x0E03, "Invalid field in command information unit"},
507 517
508 {0x1000, "Id CRC or ECC error"}, 518 {0x1000, "Id CRC or ECC error"},
509 {0x1001, "Data block guard check failed"}, 519 {0x1001, "Logical block guard check failed"},
510 {0x1002, "Data block application tag check failed"}, 520 {0x1002, "Logical block application tag check failed"},
511 {0x1003, "Data block reference tag check failed"}, 521 {0x1003, "Logical block reference tag check failed"},
512 522
513 {0x1100, "Unrecovered read error"}, 523 {0x1100, "Unrecovered read error"},
514 {0x1101, "Read retries exhausted"}, 524 {0x1101, "Read retries exhausted"},
@@ -530,6 +540,7 @@ static struct error_info additional[] =
530 {0x1111, "Read error - loss of streaming"}, 540 {0x1111, "Read error - loss of streaming"},
531 {0x1112, "Auxiliary memory read error"}, 541 {0x1112, "Auxiliary memory read error"},
532 {0x1113, "Read error - failed retransmission request"}, 542 {0x1113, "Read error - failed retransmission request"},
543 {0x1114, "Read error - lba marked bad by application client"},
533 544
534 {0x1200, "Address mark not found for id field"}, 545 {0x1200, "Address mark not found for id field"},
535 546
@@ -610,11 +621,14 @@ static struct error_info additional[] =
610 {0x2100, "Logical block address out of range"}, 621 {0x2100, "Logical block address out of range"},
611 {0x2101, "Invalid element address"}, 622 {0x2101, "Invalid element address"},
612 {0x2102, "Invalid address for write"}, 623 {0x2102, "Invalid address for write"},
624 {0x2103, "Invalid write crossing layer jump"},
613 625
614 {0x2200, "Illegal function (use 20 00, 24 00, or 26 00)"}, 626 {0x2200, "Illegal function (use 20 00, 24 00, or 26 00)"},
615 627
616 {0x2400, "Invalid field in cdb"}, 628 {0x2400, "Invalid field in cdb"},
617 {0x2401, "CDB decryption error"}, 629 {0x2401, "CDB decryption error"},
630 {0x2402, "Obsolete"},
631 {0x2403, "Obsolete"},
618 {0x2404, "Security audit value frozen"}, 632 {0x2404, "Security audit value frozen"},
619 {0x2405, "Security working key frozen"}, 633 {0x2405, "Security working key frozen"},
620 {0x2406, "Nonce not unique"}, 634 {0x2406, "Nonce not unique"},
@@ -637,7 +651,10 @@ static struct error_info additional[] =
637 {0x260C, "Invalid operation for copy source or destination"}, 651 {0x260C, "Invalid operation for copy source or destination"},
638 {0x260D, "Copy segment granularity violation"}, 652 {0x260D, "Copy segment granularity violation"},
639 {0x260E, "Invalid parameter while port is enabled"}, 653 {0x260E, "Invalid parameter while port is enabled"},
640 {0x260F, "Invalid data-out buffer integrity"}, 654 {0x260F, "Invalid data-out buffer integrity check value"},
655 {0x2610, "Data decryption key fail limit reached"},
656 {0x2611, "Incomplete key-associated data set"},
657 {0x2612, "Vendor specific key reference not found"},
641 658
642 {0x2700, "Write protected"}, 659 {0x2700, "Write protected"},
643 {0x2701, "Hardware write protected"}, 660 {0x2701, "Hardware write protected"},
@@ -649,6 +666,7 @@ static struct error_info additional[] =
649 666
650 {0x2800, "Not ready to ready change, medium may have changed"}, 667 {0x2800, "Not ready to ready change, medium may have changed"},
651 {0x2801, "Import or export element accessed"}, 668 {0x2801, "Import or export element accessed"},
669 {0x2802, "Format-layer may have changed"},
652 670
653 {0x2900, "Power on, reset, or bus device reset occurred"}, 671 {0x2900, "Power on, reset, or bus device reset occurred"},
654 {0x2901, "Power on occurred"}, 672 {0x2901, "Power on occurred"},
@@ -669,6 +687,11 @@ static struct error_info additional[] =
669 {0x2A07, "Implicit asymmetric access state transition failed"}, 687 {0x2A07, "Implicit asymmetric access state transition failed"},
670 {0x2A08, "Priority changed"}, 688 {0x2A08, "Priority changed"},
671 {0x2A09, "Capacity data has changed"}, 689 {0x2A09, "Capacity data has changed"},
690 {0x2A10, "Timestamp changed"},
691 {0x2A11, "Data encryption parameters changed by another i_t nexus"},
692 {0x2A12, "Data encryption parameters changed by vendor specific "
693 "event"},
694 {0x2A13, "Data encryption key instance counter has changed"},
672 695
673 {0x2B00, "Copy cannot execute since host cannot disconnect"}, 696 {0x2B00, "Copy cannot execute since host cannot disconnect"},
674 697
@@ -690,6 +713,7 @@ static struct error_info additional[] =
690 {0x2E00, "Insufficient time for operation"}, 713 {0x2E00, "Insufficient time for operation"},
691 714
692 {0x2F00, "Commands cleared by another initiator"}, 715 {0x2F00, "Commands cleared by another initiator"},
716 {0x2F01, "Commands cleared by power loss notification"},
693 717
694 {0x3000, "Incompatible medium installed"}, 718 {0x3000, "Incompatible medium installed"},
695 {0x3001, "Cannot read medium - unknown format"}, 719 {0x3001, "Cannot read medium - unknown format"},
@@ -702,7 +726,8 @@ static struct error_info additional[] =
702 {0x3008, "Cannot write - application code mismatch"}, 726 {0x3008, "Cannot write - application code mismatch"},
703 {0x3009, "Current session not fixated for append"}, 727 {0x3009, "Current session not fixated for append"},
704 {0x300A, "Cleaning request rejected"}, 728 {0x300A, "Cleaning request rejected"},
705 {0x300C, "WORM medium, overwrite attempted"}, 729 {0x300C, "WORM medium - overwrite attempted"},
730 {0x300D, "WORM medium - integrity check"},
706 {0x3010, "Medium not formatted"}, 731 {0x3010, "Medium not formatted"},
707 732
708 {0x3100, "Medium format corrupted"}, 733 {0x3100, "Medium format corrupted"},
@@ -790,6 +815,9 @@ static struct error_info additional[] =
790 {0x3F0F, "Echo buffer overwritten"}, 815 {0x3F0F, "Echo buffer overwritten"},
791 {0x3F10, "Medium loadable"}, 816 {0x3F10, "Medium loadable"},
792 {0x3F11, "Medium auxiliary memory accessible"}, 817 {0x3F11, "Medium auxiliary memory accessible"},
818 {0x3F12, "iSCSI IP address added"},
819 {0x3F13, "iSCSI IP address removed"},
820 {0x3F14, "iSCSI IP address changed"},
793/* 821/*
794 * {0x40NN, "Ram failure"}, 822 * {0x40NN, "Ram failure"},
795 * {0x40NN, "Diagnostic failure on component nn"}, 823 * {0x40NN, "Diagnostic failure on component nn"},
@@ -799,6 +827,7 @@ static struct error_info additional[] =
799 {0x4300, "Message error"}, 827 {0x4300, "Message error"},
800 828
801 {0x4400, "Internal target failure"}, 829 {0x4400, "Internal target failure"},
830 {0x4471, "ATA device failed set features"},
802 831
803 {0x4500, "Select or reselect failure"}, 832 {0x4500, "Select or reselect failure"},
804 833
@@ -807,9 +836,10 @@ static struct error_info additional[] =
807 {0x4700, "Scsi parity error"}, 836 {0x4700, "Scsi parity error"},
808 {0x4701, "Data phase CRC error detected"}, 837 {0x4701, "Data phase CRC error detected"},
809 {0x4702, "Scsi parity error detected during st data phase"}, 838 {0x4702, "Scsi parity error detected during st data phase"},
810 {0x4703, "Information unit CRC error detected"}, 839 {0x4703, "Information unit iuCRC error detected"},
811 {0x4704, "Asynchronous information protection error detected"}, 840 {0x4704, "Asynchronous information protection error detected"},
812 {0x4705, "Protocol service CRC error"}, 841 {0x4705, "Protocol service CRC error"},
842 {0x4706, "Phy test function in progress"},
813 {0x477f, "Some commands cleared by iSCSI Protocol event"}, 843 {0x477f, "Some commands cleared by iSCSI Protocol event"},
814 844
815 {0x4800, "Initiator detected error message received"}, 845 {0x4800, "Initiator detected error message received"},
@@ -844,6 +874,8 @@ static struct error_info additional[] =
844 {0x5300, "Media load or eject failed"}, 874 {0x5300, "Media load or eject failed"},
845 {0x5301, "Unload tape failure"}, 875 {0x5301, "Unload tape failure"},
846 {0x5302, "Medium removal prevented"}, 876 {0x5302, "Medium removal prevented"},
877 {0x5303, "Medium removal prevented by data transfer element"},
878 {0x5304, "Medium thread or unthread failure"},
847 879
848 {0x5400, "Scsi to host system interface failure"}, 880 {0x5400, "Scsi to host system interface failure"},
849 881
@@ -855,6 +887,7 @@ static struct error_info additional[] =
855 {0x5505, "Insufficient access control resources"}, 887 {0x5505, "Insufficient access control resources"},
856 {0x5506, "Auxiliary memory out of space"}, 888 {0x5506, "Auxiliary memory out of space"},
857 {0x5507, "Quota error"}, 889 {0x5507, "Quota error"},
890 {0x5508, "Maximum number of supplemental decryption keys exceeded"},
858 891
859 {0x5700, "Unable to recover table-of-contents"}, 892 {0x5700, "Unable to recover table-of-contents"},
860 893
@@ -1004,6 +1037,7 @@ static struct error_info additional[] =
1004 {0x6708, "Assign failure occurred"}, 1037 {0x6708, "Assign failure occurred"},
1005 {0x6709, "Multiply assigned logical unit"}, 1038 {0x6709, "Multiply assigned logical unit"},
1006 {0x670A, "Set target port groups command failed"}, 1039 {0x670A, "Set target port groups command failed"},
1040 {0x670B, "ATA device feature not enabled"},
1007 1041
1008 {0x6800, "Logical unit not configured"}, 1042 {0x6800, "Logical unit not configured"},
1009 1043
@@ -1030,6 +1064,8 @@ static struct error_info additional[] =
1030 {0x6F03, "Read of scrambled sector without authentication"}, 1064 {0x6F03, "Read of scrambled sector without authentication"},
1031 {0x6F04, "Media region code is mismatched to logical unit region"}, 1065 {0x6F04, "Media region code is mismatched to logical unit region"},
1032 {0x6F05, "Drive region must be permanent/region reset count error"}, 1066 {0x6F05, "Drive region must be permanent/region reset count error"},
1067 {0x6F06, "Insufficient block count for binding nonce recording"},
1068 {0x6F07, "Conflict in binding nonce recording"},
1033/* 1069/*
1034 * {0x70NN, "Decompression exception short algorithm id of nn"}, 1070 * {0x70NN, "Decompression exception short algorithm id of nn"},
1035 */ 1071 */
@@ -1041,6 +1077,8 @@ static struct error_info additional[] =
1041 {0x7203, "Session fixation error - incomplete track in session"}, 1077 {0x7203, "Session fixation error - incomplete track in session"},
1042 {0x7204, "Empty or partially written reserved track"}, 1078 {0x7204, "Empty or partially written reserved track"},
1043 {0x7205, "No more track reservations allowed"}, 1079 {0x7205, "No more track reservations allowed"},
1080 {0x7206, "RMZ extension is not allowed"},
1081 {0x7207, "No more test zone extensions are allowed"},
1044 1082
1045 {0x7300, "Cd control error"}, 1083 {0x7300, "Cd control error"},
1046 {0x7301, "Power calibration area almost full"}, 1084 {0x7301, "Power calibration area almost full"},
@@ -1049,6 +1087,18 @@ static struct error_info additional[] =
1049 {0x7304, "Program memory area update failure"}, 1087 {0x7304, "Program memory area update failure"},
1050 {0x7305, "Program memory area is full"}, 1088 {0x7305, "Program memory area is full"},
1051 {0x7306, "RMA/PMA is almost full"}, 1089 {0x7306, "RMA/PMA is almost full"},
1090 {0x7310, "Current power calibration area almost full"},
1091 {0x7311, "Current power calibration area is full"},
1092 {0x7317, "RDZ is full"},
1093
1094 {0x7400, "Security error"},
1095 {0x7401, "Unable to decrypt data"},
1096 {0x7402, "Unencrypted data encountered while decrypting"},
1097 {0x7403, "Incorrect data encryption key"},
1098 {0x7404, "Cryptographic integrity validation failed"},
1099 {0x7405, "Error decrypting data"},
1100 {0x7471, "Logical unit access not authorized"},
1101
1052 {0, NULL} 1102 {0, NULL}
1053}; 1103};
1054 1104
diff --git a/drivers/scsi/esp.c b/drivers/scsi/esp.c
index 10573c24a50b..5630868c1b25 100644
--- a/drivers/scsi/esp.c
+++ b/drivers/scsi/esp.c
@@ -1146,7 +1146,7 @@ static struct sbus_dev sun4_esp_dev;
1146static int __init esp_sun4_probe(struct scsi_host_template *tpnt) 1146static int __init esp_sun4_probe(struct scsi_host_template *tpnt)
1147{ 1147{
1148 if (sun4_esp_physaddr) { 1148 if (sun4_esp_physaddr) {
1149 memset(&sun4_esp_dev, 0, sizeof(esp_dev)); 1149 memset(&sun4_esp_dev, 0, sizeof(sun4_esp_dev));
1150 sun4_esp_dev.reg_addrs[0].phys_addr = sun4_esp_physaddr; 1150 sun4_esp_dev.reg_addrs[0].phys_addr = sun4_esp_physaddr;
1151 sun4_esp_dev.irqs[0] = 4; 1151 sun4_esp_dev.irqs[0] = 4;
1152 sun4_esp_dev.resource[0].start = sun4_esp_physaddr; 1152 sun4_esp_dev.resource[0].start = sun4_esp_physaddr;
@@ -1162,6 +1162,7 @@ static int __init esp_sun4_probe(struct scsi_host_template *tpnt)
1162 1162
1163static int __devexit esp_sun4_remove(void) 1163static int __devexit esp_sun4_remove(void)
1164{ 1164{
1165 struct of_device *dev = &sun4_esp_dev.ofdev;
1165 struct esp *esp = dev_get_drvdata(&dev->dev); 1166 struct esp *esp = dev_get_drvdata(&dev->dev);
1166 1167
1167 return esp_remove_common(esp); 1168 return esp_remove_common(esp);
@@ -1397,7 +1398,7 @@ static void esp_get_dmabufs(struct esp *esp, struct scsi_cmnd *sp)
1397 sp->SCp.ptr = NULL; 1398 sp->SCp.ptr = NULL;
1398 } 1399 }
1399 } else { 1400 } else {
1400 sp->SCp.buffer = (struct scatterlist *) sp->buffer; 1401 sp->SCp.buffer = (struct scatterlist *) sp->request_buffer;
1401 sp->SCp.buffers_residual = sbus_map_sg(esp->sdev, 1402 sp->SCp.buffers_residual = sbus_map_sg(esp->sdev,
1402 sp->SCp.buffer, 1403 sp->SCp.buffer,
1403 sp->use_sg, 1404 sp->use_sg,
@@ -1410,7 +1411,7 @@ static void esp_get_dmabufs(struct esp *esp, struct scsi_cmnd *sp)
1410static void esp_release_dmabufs(struct esp *esp, struct scsi_cmnd *sp) 1411static void esp_release_dmabufs(struct esp *esp, struct scsi_cmnd *sp)
1411{ 1412{
1412 if (sp->use_sg) { 1413 if (sp->use_sg) {
1413 sbus_unmap_sg(esp->sdev, sp->buffer, sp->use_sg, 1414 sbus_unmap_sg(esp->sdev, sp->request_buffer, sp->use_sg,
1414 sp->sc_data_direction); 1415 sp->sc_data_direction);
1415 } else if (sp->request_bufflen) { 1416 } else if (sp->request_bufflen) {
1416 sbus_unmap_single(esp->sdev, 1417 sbus_unmap_single(esp->sdev,
@@ -2754,18 +2755,15 @@ static int esp_do_data_finale(struct esp *esp)
2754 */ 2755 */
2755static int esp_should_clear_sync(struct scsi_cmnd *sp) 2756static int esp_should_clear_sync(struct scsi_cmnd *sp)
2756{ 2757{
2757 u8 cmd1 = sp->cmnd[0]; 2758 u8 cmd = sp->cmnd[0];
2758 u8 cmd2 = sp->data_cmnd[0];
2759 2759
2760 /* These cases are for spinning up a disk and 2760 /* These cases are for spinning up a disk and
2761 * waiting for that spinup to complete. 2761 * waiting for that spinup to complete.
2762 */ 2762 */
2763 if (cmd1 == START_STOP || 2763 if (cmd == START_STOP)
2764 cmd2 == START_STOP)
2765 return 0; 2764 return 0;
2766 2765
2767 if (cmd1 == TEST_UNIT_READY || 2766 if (cmd == TEST_UNIT_READY)
2768 cmd2 == TEST_UNIT_READY)
2769 return 0; 2767 return 0;
2770 2768
2771 /* One more special case for SCSI tape drives, 2769 /* One more special case for SCSI tape drives,
@@ -2773,8 +2771,7 @@ static int esp_should_clear_sync(struct scsi_cmnd *sp)
2773 * completion of a rewind or tape load operation. 2771 * completion of a rewind or tape load operation.
2774 */ 2772 */
2775 if (sp->device->type == TYPE_TAPE) { 2773 if (sp->device->type == TYPE_TAPE) {
2776 if (cmd1 == MODE_SENSE || 2774 if (cmd == MODE_SENSE)
2777 cmd2 == MODE_SENSE)
2778 return 0; 2775 return 0;
2779 } 2776 }
2780 2777
diff --git a/drivers/scsi/hptiop.c b/drivers/scsi/hptiop.c
index ab2f8b267908..bcb3444f1dcf 100644
--- a/drivers/scsi/hptiop.c
+++ b/drivers/scsi/hptiop.c
@@ -45,10 +45,6 @@ static char driver_name[] = "hptiop";
45static const char driver_name_long[] = "RocketRAID 3xxx SATA Controller driver"; 45static const char driver_name_long[] = "RocketRAID 3xxx SATA Controller driver";
46static const char driver_ver[] = "v1.0 (060426)"; 46static const char driver_ver[] = "v1.0 (060426)";
47 47
48static DEFINE_SPINLOCK(hptiop_hba_list_lock);
49static LIST_HEAD(hptiop_hba_list);
50static int hptiop_cdev_major = -1;
51
52static void hptiop_host_request_callback(struct hptiop_hba *hba, u32 tag); 48static void hptiop_host_request_callback(struct hptiop_hba *hba, u32 tag);
53static void hptiop_iop_request_callback(struct hptiop_hba *hba, u32 tag); 49static void hptiop_iop_request_callback(struct hptiop_hba *hba, u32 tag);
54static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg); 50static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg);
@@ -577,7 +573,7 @@ static int hptiop_reset_hba(struct hptiop_hba *hba)
577 if (atomic_xchg(&hba->resetting, 1) == 0) { 573 if (atomic_xchg(&hba->resetting, 1) == 0) {
578 atomic_inc(&hba->reset_count); 574 atomic_inc(&hba->reset_count);
579 writel(IOPMU_INBOUND_MSG0_RESET, 575 writel(IOPMU_INBOUND_MSG0_RESET,
580 &hba->iop->outbound_msgaddr0); 576 &hba->iop->inbound_msgaddr0);
581 hptiop_pci_posting_flush(hba->iop); 577 hptiop_pci_posting_flush(hba->iop);
582 } 578 }
583 579
@@ -620,532 +616,11 @@ static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev,
620 return queue_depth; 616 return queue_depth;
621} 617}
622 618
623struct hptiop_getinfo {
624 char __user *buffer;
625 loff_t buflength;
626 loff_t bufoffset;
627 loff_t buffillen;
628 loff_t filpos;
629};
630
631static void hptiop_copy_mem_info(struct hptiop_getinfo *pinfo,
632 char *data, int datalen)
633{
634 if (pinfo->filpos < pinfo->bufoffset) {
635 if (pinfo->filpos + datalen <= pinfo->bufoffset) {
636 pinfo->filpos += datalen;
637 return;
638 } else {
639 data += (pinfo->bufoffset - pinfo->filpos);
640 datalen -= (pinfo->bufoffset - pinfo->filpos);
641 pinfo->filpos = pinfo->bufoffset;
642 }
643 }
644
645 pinfo->filpos += datalen;
646 if (pinfo->buffillen == pinfo->buflength)
647 return;
648
649 if (pinfo->buflength - pinfo->buffillen < datalen)
650 datalen = pinfo->buflength - pinfo->buffillen;
651
652 if (copy_to_user(pinfo->buffer + pinfo->buffillen, data, datalen))
653 return;
654
655 pinfo->buffillen += datalen;
656}
657
658static int hptiop_copy_info(struct hptiop_getinfo *pinfo, char *fmt, ...)
659{
660 va_list args;
661 char buf[128];
662 int len;
663
664 va_start(args, fmt);
665 len = vsnprintf(buf, sizeof(buf), fmt, args);
666 va_end(args);
667 hptiop_copy_mem_info(pinfo, buf, len);
668 return len;
669}
670
671static void hptiop_ioctl_done(struct hpt_ioctl_k *arg)
672{
673 arg->done = NULL;
674 wake_up(&arg->hba->ioctl_wq);
675}
676
677static void hptiop_do_ioctl(struct hpt_ioctl_k *arg)
678{
679 struct hptiop_hba *hba = arg->hba;
680 u32 val;
681 struct hpt_iop_request_ioctl_command __iomem *req;
682 int ioctl_retry = 0;
683
684 dprintk("scsi%d: hptiop_do_ioctl\n", hba->host->host_no);
685
686 /*
687 * check (in + out) buff size from application.
688 * outbuf must be dword aligned.
689 */
690 if (((arg->inbuf_size + 3) & ~3) + arg->outbuf_size >
691 hba->max_request_size
692 - sizeof(struct hpt_iop_request_header)
693 - 4 * sizeof(u32)) {
694 dprintk("scsi%d: ioctl buf size (%d/%d) is too large\n",
695 hba->host->host_no,
696 arg->inbuf_size, arg->outbuf_size);
697 arg->result = HPT_IOCTL_RESULT_FAILED;
698 return;
699 }
700
701retry:
702 spin_lock_irq(hba->host->host_lock);
703
704 val = readl(&hba->iop->inbound_queue);
705 if (val == IOPMU_QUEUE_EMPTY) {
706 spin_unlock_irq(hba->host->host_lock);
707 dprintk("scsi%d: no free req for ioctl\n", hba->host->host_no);
708 arg->result = -1;
709 return;
710 }
711
712 req = (struct hpt_iop_request_ioctl_command __iomem *)
713 ((unsigned long)hba->iop + val);
714
715 writel(HPT_CTL_CODE_LINUX_TO_IOP(arg->ioctl_code),
716 &req->ioctl_code);
717 writel(arg->inbuf_size, &req->inbuf_size);
718 writel(arg->outbuf_size, &req->outbuf_size);
719
720 /*
721 * use the buffer on the IOP local memory first, then copy it
722 * back to host.
723 * the caller's request buffer shoudl be little-endian.
724 */
725 if (arg->inbuf_size)
726 memcpy_toio(req->buf, arg->inbuf, arg->inbuf_size);
727
728 /* correct the controller ID for IOP */
729 if ((arg->ioctl_code == HPT_IOCTL_GET_CHANNEL_INFO ||
730 arg->ioctl_code == HPT_IOCTL_GET_CONTROLLER_INFO_V2 ||
731 arg->ioctl_code == HPT_IOCTL_GET_CONTROLLER_INFO)
732 && arg->inbuf_size >= sizeof(u32))
733 writel(0, req->buf);
734
735 writel(IOP_REQUEST_TYPE_IOCTL_COMMAND, &req->header.type);
736 writel(0, &req->header.flags);
737 writel(offsetof(struct hpt_iop_request_ioctl_command, buf)
738 + arg->inbuf_size, &req->header.size);
739 writel((u32)(unsigned long)arg, &req->header.context);
740 writel(BITS_PER_LONG > 32 ? (u32)((unsigned long)arg>>32) : 0,
741 &req->header.context_hi32);
742 writel(IOP_RESULT_PENDING, &req->header.result);
743
744 arg->result = HPT_IOCTL_RESULT_FAILED;
745 arg->done = hptiop_ioctl_done;
746
747 writel(val, &hba->iop->inbound_queue);
748 hptiop_pci_posting_flush(hba->iop);
749
750 spin_unlock_irq(hba->host->host_lock);
751
752 wait_event_timeout(hba->ioctl_wq, arg->done == NULL, 60 * HZ);
753
754 if (arg->done != NULL) {
755 hptiop_reset_hba(hba);
756 if (ioctl_retry++ < 3)
757 goto retry;
758 }
759
760 dprintk("hpt_iop_ioctl %x result %d\n",
761 arg->ioctl_code, arg->result);
762}
763
764static int __hpt_do_ioctl(struct hptiop_hba *hba, u32 code, void *inbuf,
765 u32 insize, void *outbuf, u32 outsize)
766{
767 struct hpt_ioctl_k arg;
768 arg.hba = hba;
769 arg.ioctl_code = code;
770 arg.inbuf = inbuf;
771 arg.outbuf = outbuf;
772 arg.inbuf_size = insize;
773 arg.outbuf_size = outsize;
774 arg.bytes_returned = NULL;
775 hptiop_do_ioctl(&arg);
776 return arg.result;
777}
778
779static inline int hpt_id_valid(__le32 id)
780{
781 return id != 0 && id != cpu_to_le32(0xffffffff);
782}
783
784static int hptiop_get_controller_info(struct hptiop_hba *hba,
785 struct hpt_controller_info *pinfo)
786{
787 int id = 0;
788
789 return __hpt_do_ioctl(hba, HPT_IOCTL_GET_CONTROLLER_INFO,
790 &id, sizeof(int), pinfo, sizeof(*pinfo));
791}
792
793
794static int hptiop_get_channel_info(struct hptiop_hba *hba, int bus,
795 struct hpt_channel_info *pinfo)
796{
797 u32 ids[2];
798
799 ids[0] = 0;
800 ids[1] = bus;
801 return __hpt_do_ioctl(hba, HPT_IOCTL_GET_CHANNEL_INFO,
802 ids, sizeof(ids), pinfo, sizeof(*pinfo));
803
804}
805
806static int hptiop_get_logical_devices(struct hptiop_hba *hba,
807 __le32 *pids, int maxcount)
808{
809 int i;
810 u32 count = maxcount - 1;
811
812 if (__hpt_do_ioctl(hba, HPT_IOCTL_GET_LOGICAL_DEVICES,
813 &count, sizeof(u32),
814 pids, sizeof(u32) * maxcount))
815 return -1;
816
817 maxcount = le32_to_cpu(pids[0]);
818 for (i = 0; i < maxcount; i++)
819 pids[i] = pids[i+1];
820
821 return maxcount;
822}
823
824static int hptiop_get_device_info_v3(struct hptiop_hba *hba, __le32 id,
825 struct hpt_logical_device_info_v3 *pinfo)
826{
827 return __hpt_do_ioctl(hba, HPT_IOCTL_GET_DEVICE_INFO_V3,
828 &id, sizeof(u32),
829 pinfo, sizeof(*pinfo));
830}
831
832static const char *get_array_status(struct hpt_logical_device_info_v3 *devinfo)
833{
834 static char s[64];
835 u32 flags = le32_to_cpu(devinfo->u.array.flags);
836 u32 trans_prog = le32_to_cpu(devinfo->u.array.transforming_progress);
837 u32 reb_prog = le32_to_cpu(devinfo->u.array.rebuilding_progress);
838
839 if (flags & ARRAY_FLAG_DISABLED)
840 return "Disabled";
841 else if (flags & ARRAY_FLAG_TRANSFORMING)
842 sprintf(s, "Expanding/Migrating %d.%d%%%s%s",
843 trans_prog / 100,
844 trans_prog % 100,
845 (flags & (ARRAY_FLAG_NEEDBUILDING|ARRAY_FLAG_BROKEN))?
846 ", Critical" : "",
847 ((flags & ARRAY_FLAG_NEEDINITIALIZING) &&
848 !(flags & ARRAY_FLAG_REBUILDING) &&
849 !(flags & ARRAY_FLAG_INITIALIZING))?
850 ", Unintialized" : "");
851 else if ((flags & ARRAY_FLAG_BROKEN) &&
852 devinfo->u.array.array_type != AT_RAID6)
853 return "Critical";
854 else if (flags & ARRAY_FLAG_REBUILDING)
855 sprintf(s,
856 (flags & ARRAY_FLAG_NEEDINITIALIZING)?
857 "%sBackground initializing %d.%d%%" :
858 "%sRebuilding %d.%d%%",
859 (flags & ARRAY_FLAG_BROKEN)? "Critical, " : "",
860 reb_prog / 100,
861 reb_prog % 100);
862 else if (flags & ARRAY_FLAG_VERIFYING)
863 sprintf(s, "%sVerifying %d.%d%%",
864 (flags & ARRAY_FLAG_BROKEN)? "Critical, " : "",
865 reb_prog / 100,
866 reb_prog % 100);
867 else if (flags & ARRAY_FLAG_INITIALIZING)
868 sprintf(s, "%sForground initializing %d.%d%%",
869 (flags & ARRAY_FLAG_BROKEN)? "Critical, " : "",
870 reb_prog / 100,
871 reb_prog % 100);
872 else if (flags & ARRAY_FLAG_NEEDTRANSFORM)
873 sprintf(s,"%s%s%s", "Need Expanding/Migrating",
874 (flags & ARRAY_FLAG_BROKEN)? "Critical, " : "",
875 ((flags & ARRAY_FLAG_NEEDINITIALIZING) &&
876 !(flags & ARRAY_FLAG_REBUILDING) &&
877 !(flags & ARRAY_FLAG_INITIALIZING))?
878 ", Unintialized" : "");
879 else if (flags & ARRAY_FLAG_NEEDINITIALIZING &&
880 !(flags & ARRAY_FLAG_REBUILDING) &&
881 !(flags & ARRAY_FLAG_INITIALIZING))
882 sprintf(s,"%sUninitialized",
883 (flags & ARRAY_FLAG_BROKEN)? "Critical, " : "");
884 else if ((flags & ARRAY_FLAG_NEEDBUILDING) ||
885 (flags & ARRAY_FLAG_BROKEN))
886 return "Critical";
887 else
888 return "Normal";
889 return s;
890}
891
892static void hptiop_dump_devinfo(struct hptiop_hba *hba,
893 struct hptiop_getinfo *pinfo, __le32 id, int indent)
894{
895 struct hpt_logical_device_info_v3 devinfo;
896 int i;
897 u64 capacity;
898
899 for (i = 0; i < indent; i++)
900 hptiop_copy_info(pinfo, "\t");
901
902 if (hptiop_get_device_info_v3(hba, id, &devinfo)) {
903 hptiop_copy_info(pinfo, "unknown\n");
904 return;
905 }
906
907 switch (devinfo.type) {
908
909 case LDT_DEVICE: {
910 struct hd_driveid *driveid;
911 u32 flags = le32_to_cpu(devinfo.u.device.flags);
912
913 driveid = (struct hd_driveid *)devinfo.u.device.ident;
914 /* model[] is 40 chars long, but we just want 20 chars here */
915 driveid->model[20] = 0;
916
917 if (indent)
918 if (flags & DEVICE_FLAG_DISABLED)
919 hptiop_copy_info(pinfo,"Missing\n");
920 else
921 hptiop_copy_info(pinfo, "CH%d %s\n",
922 devinfo.u.device.path_id + 1,
923 driveid->model);
924 else {
925 capacity = le64_to_cpu(devinfo.capacity) * 512;
926 do_div(capacity, 1000000);
927 hptiop_copy_info(pinfo,
928 "CH%d %s, %lluMB, %s %s%s%s%s\n",
929 devinfo.u.device.path_id + 1,
930 driveid->model,
931 capacity,
932 (flags & DEVICE_FLAG_DISABLED)?
933 "Disabled" : "Normal",
934 devinfo.u.device.read_ahead_enabled?
935 "[RA]" : "",
936 devinfo.u.device.write_cache_enabled?
937 "[WC]" : "",
938 devinfo.u.device.TCQ_enabled?
939 "[TCQ]" : "",
940 devinfo.u.device.NCQ_enabled?
941 "[NCQ]" : ""
942 );
943 }
944 break;
945 }
946
947 case LDT_ARRAY:
948 if (devinfo.target_id != INVALID_TARGET_ID)
949 hptiop_copy_info(pinfo, "[DISK %d_%d] ",
950 devinfo.vbus_id, devinfo.target_id);
951
952 capacity = le64_to_cpu(devinfo.capacity) * 512;
953 do_div(capacity, 1000000);
954 hptiop_copy_info(pinfo, "%s (%s), %lluMB, %s\n",
955 devinfo.u.array.name,
956 devinfo.u.array.array_type==AT_RAID0? "RAID0" :
957 devinfo.u.array.array_type==AT_RAID1? "RAID1" :
958 devinfo.u.array.array_type==AT_RAID5? "RAID5" :
959 devinfo.u.array.array_type==AT_RAID6? "RAID6" :
960 devinfo.u.array.array_type==AT_JBOD? "JBOD" :
961 "unknown",
962 capacity,
963 get_array_status(&devinfo));
964 for (i = 0; i < devinfo.u.array.ndisk; i++) {
965 if (hpt_id_valid(devinfo.u.array.members[i])) {
966 if (cpu_to_le16(1<<i) &
967 devinfo.u.array.critical_members)
968 hptiop_copy_info(pinfo, "\t*");
969 hptiop_dump_devinfo(hba, pinfo,
970 devinfo.u.array.members[i], indent+1);
971 }
972 else
973 hptiop_copy_info(pinfo, "\tMissing\n");
974 }
975 if (id == devinfo.u.array.transform_source) {
976 hptiop_copy_info(pinfo, "\tExpanding/Migrating to:\n");
977 hptiop_dump_devinfo(hba, pinfo,
978 devinfo.u.array.transform_target, indent+1);
979 }
980 break;
981 }
982}
983
984static ssize_t hptiop_show_version(struct class_device *class_dev, char *buf) 619static ssize_t hptiop_show_version(struct class_device *class_dev, char *buf)
985{ 620{
986 return snprintf(buf, PAGE_SIZE, "%s\n", driver_ver); 621 return snprintf(buf, PAGE_SIZE, "%s\n", driver_ver);
987} 622}
988 623
989static ssize_t hptiop_cdev_read(struct file *filp, char __user *buf,
990 size_t count, loff_t *ppos)
991{
992 struct hptiop_hba *hba = filp->private_data;
993 struct hptiop_getinfo info;
994 int i, j, ndev;
995 struct hpt_controller_info con_info;
996 struct hpt_channel_info chan_info;
997 __le32 ids[32];
998
999 info.buffer = buf;
1000 info.buflength = count;
1001 info.bufoffset = ppos ? *ppos : 0;
1002 info.filpos = 0;
1003 info.buffillen = 0;
1004
1005 if (hptiop_get_controller_info(hba, &con_info))
1006 return -EIO;
1007
1008 for (i = 0; i < con_info.num_buses; i++) {
1009 if (hptiop_get_channel_info(hba, i, &chan_info) == 0) {
1010 if (hpt_id_valid(chan_info.devices[0]))
1011 hptiop_dump_devinfo(hba, &info,
1012 chan_info.devices[0], 0);
1013 if (hpt_id_valid(chan_info.devices[1]))
1014 hptiop_dump_devinfo(hba, &info,
1015 chan_info.devices[1], 0);
1016 }
1017 }
1018
1019 ndev = hptiop_get_logical_devices(hba, ids,
1020 sizeof(ids) / sizeof(ids[0]));
1021
1022 /*
1023 * if hptiop_get_logical_devices fails, ndev==-1 and it just
1024 * output nothing here
1025 */
1026 for (j = 0; j < ndev; j++)
1027 hptiop_dump_devinfo(hba, &info, ids[j], 0);
1028
1029 if (ppos)
1030 *ppos += info.buffillen;
1031
1032 return info.buffillen;
1033}
1034
1035static int hptiop_cdev_ioctl(struct inode *inode, struct file *file,
1036 unsigned int cmd, unsigned long arg)
1037{
1038 struct hptiop_hba *hba = file->private_data;
1039 struct hpt_ioctl_u ioctl_u;
1040 struct hpt_ioctl_k ioctl_k;
1041 u32 bytes_returned;
1042 int err = -EINVAL;
1043
1044 if (copy_from_user(&ioctl_u,
1045 (void __user *)arg, sizeof(struct hpt_ioctl_u)))
1046 return -EINVAL;
1047
1048 if (ioctl_u.magic != HPT_IOCTL_MAGIC)
1049 return -EINVAL;
1050
1051 ioctl_k.ioctl_code = ioctl_u.ioctl_code;
1052 ioctl_k.inbuf = NULL;
1053 ioctl_k.inbuf_size = ioctl_u.inbuf_size;
1054 ioctl_k.outbuf = NULL;
1055 ioctl_k.outbuf_size = ioctl_u.outbuf_size;
1056 ioctl_k.hba = hba;
1057 ioctl_k.bytes_returned = &bytes_returned;
1058
1059 /* verify user buffer */
1060 if ((ioctl_k.inbuf_size && !access_ok(VERIFY_READ,
1061 ioctl_u.inbuf, ioctl_k.inbuf_size)) ||
1062 (ioctl_k.outbuf_size && !access_ok(VERIFY_WRITE,
1063 ioctl_u.outbuf, ioctl_k.outbuf_size)) ||
1064 (ioctl_u.bytes_returned && !access_ok(VERIFY_WRITE,
1065 ioctl_u.bytes_returned, sizeof(u32))) ||
1066 ioctl_k.inbuf_size + ioctl_k.outbuf_size > 0x10000) {
1067
1068 dprintk("scsi%d: got bad user address\n", hba->host->host_no);
1069 return -EINVAL;
1070 }
1071
1072 /* map buffer to kernel. */
1073 if (ioctl_k.inbuf_size) {
1074 ioctl_k.inbuf = kmalloc(ioctl_k.inbuf_size, GFP_KERNEL);
1075 if (!ioctl_k.inbuf) {
1076 dprintk("scsi%d: fail to alloc inbuf\n",
1077 hba->host->host_no);
1078 err = -ENOMEM;
1079 goto err_exit;
1080 }
1081
1082 if (copy_from_user(ioctl_k.inbuf,
1083 ioctl_u.inbuf, ioctl_k.inbuf_size)) {
1084 goto err_exit;
1085 }
1086 }
1087
1088 if (ioctl_k.outbuf_size) {
1089 ioctl_k.outbuf = kmalloc(ioctl_k.outbuf_size, GFP_KERNEL);
1090 if (!ioctl_k.outbuf) {
1091 dprintk("scsi%d: fail to alloc outbuf\n",
1092 hba->host->host_no);
1093 err = -ENOMEM;
1094 goto err_exit;
1095 }
1096 }
1097
1098 hptiop_do_ioctl(&ioctl_k);
1099
1100 if (ioctl_k.result == HPT_IOCTL_RESULT_OK) {
1101 if (ioctl_k.outbuf_size &&
1102 copy_to_user(ioctl_u.outbuf,
1103 ioctl_k.outbuf, ioctl_k.outbuf_size))
1104 goto err_exit;
1105
1106 if (ioctl_u.bytes_returned &&
1107 copy_to_user(ioctl_u.bytes_returned,
1108 &bytes_returned, sizeof(u32)))
1109 goto err_exit;
1110
1111 err = 0;
1112 }
1113
1114err_exit:
1115 kfree(ioctl_k.inbuf);
1116 kfree(ioctl_k.outbuf);
1117
1118 return err;
1119}
1120
1121static int hptiop_cdev_open(struct inode *inode, struct file *file)
1122{
1123 struct hptiop_hba *hba;
1124 unsigned i = 0, minor = iminor(inode);
1125 int ret = -ENODEV;
1126
1127 spin_lock(&hptiop_hba_list_lock);
1128 list_for_each_entry(hba, &hptiop_hba_list, link) {
1129 if (i == minor) {
1130 file->private_data = hba;
1131 ret = 0;
1132 goto out;
1133 }
1134 i++;
1135 }
1136
1137out:
1138 spin_unlock(&hptiop_hba_list_lock);
1139 return ret;
1140}
1141
1142static struct file_operations hptiop_cdev_fops = {
1143 .owner = THIS_MODULE,
1144 .read = hptiop_cdev_read,
1145 .ioctl = hptiop_cdev_ioctl,
1146 .open = hptiop_cdev_open,
1147};
1148
1149static ssize_t hptiop_show_fw_version(struct class_device *class_dev, char *buf) 624static ssize_t hptiop_show_fw_version(struct class_device *class_dev, char *buf)
1150{ 625{
1151 struct Scsi_Host *host = class_to_shost(class_dev); 626 struct Scsi_Host *host = class_to_shost(class_dev);
@@ -1296,19 +771,13 @@ static int __devinit hptiop_probe(struct pci_dev *pcidev,
1296 goto unmap_pci_bar; 771 goto unmap_pci_bar;
1297 } 772 }
1298 773
1299 if (scsi_add_host(host, &pcidev->dev)) {
1300 printk(KERN_ERR "scsi%d: scsi_add_host failed\n",
1301 hba->host->host_no);
1302 goto unmap_pci_bar;
1303 }
1304
1305 pci_set_drvdata(pcidev, host); 774 pci_set_drvdata(pcidev, host);
1306 775
1307 if (request_irq(pcidev->irq, hptiop_intr, IRQF_SHARED, 776 if (request_irq(pcidev->irq, hptiop_intr, IRQF_SHARED,
1308 driver_name, hba)) { 777 driver_name, hba)) {
1309 printk(KERN_ERR "scsi%d: request irq %d failed\n", 778 printk(KERN_ERR "scsi%d: request irq %d failed\n",
1310 hba->host->host_no, pcidev->irq); 779 hba->host->host_no, pcidev->irq);
1311 goto remove_scsi_host; 780 goto unmap_pci_bar;
1312 } 781 }
1313 782
1314 /* Allocate request mem */ 783 /* Allocate request mem */
@@ -1355,9 +824,12 @@ static int __devinit hptiop_probe(struct pci_dev *pcidev,
1355 if (hptiop_initialize_iop(hba)) 824 if (hptiop_initialize_iop(hba))
1356 goto free_request_mem; 825 goto free_request_mem;
1357 826
1358 spin_lock(&hptiop_hba_list_lock); 827 if (scsi_add_host(host, &pcidev->dev)) {
1359 list_add_tail(&hba->link, &hptiop_hba_list); 828 printk(KERN_ERR "scsi%d: scsi_add_host failed\n",
1360 spin_unlock(&hptiop_hba_list_lock); 829 hba->host->host_no);
830 goto free_request_mem;
831 }
832
1361 833
1362 scsi_scan_host(host); 834 scsi_scan_host(host);
1363 835
@@ -1372,9 +844,6 @@ free_request_mem:
1372free_request_irq: 844free_request_irq:
1373 free_irq(hba->pcidev->irq, hba); 845 free_irq(hba->pcidev->irq, hba);
1374 846
1375remove_scsi_host:
1376 scsi_remove_host(host);
1377
1378unmap_pci_bar: 847unmap_pci_bar:
1379 iounmap(hba->iop); 848 iounmap(hba->iop);
1380 849
@@ -1422,10 +891,6 @@ static void hptiop_remove(struct pci_dev *pcidev)
1422 891
1423 scsi_remove_host(host); 892 scsi_remove_host(host);
1424 893
1425 spin_lock(&hptiop_hba_list_lock);
1426 list_del_init(&hba->link);
1427 spin_unlock(&hptiop_hba_list_lock);
1428
1429 hptiop_shutdown(pcidev); 894 hptiop_shutdown(pcidev);
1430 895
1431 free_irq(hba->pcidev->irq, hba); 896 free_irq(hba->pcidev->irq, hba);
@@ -1462,27 +927,12 @@ static struct pci_driver hptiop_pci_driver = {
1462 927
1463static int __init hptiop_module_init(void) 928static int __init hptiop_module_init(void)
1464{ 929{
1465 int error;
1466
1467 printk(KERN_INFO "%s %s\n", driver_name_long, driver_ver); 930 printk(KERN_INFO "%s %s\n", driver_name_long, driver_ver);
1468 931 return pci_register_driver(&hptiop_pci_driver);
1469 error = pci_register_driver(&hptiop_pci_driver);
1470 if (error < 0)
1471 return error;
1472
1473 hptiop_cdev_major = register_chrdev(0, "hptiop", &hptiop_cdev_fops);
1474 if (hptiop_cdev_major < 0) {
1475 printk(KERN_WARNING "unable to register hptiop device.\n");
1476 return hptiop_cdev_major;
1477 }
1478
1479 return 0;
1480} 932}
1481 933
1482static void __exit hptiop_module_exit(void) 934static void __exit hptiop_module_exit(void)
1483{ 935{
1484 dprintk("hptiop_module_exit\n");
1485 unregister_chrdev(hptiop_cdev_major, "hptiop");
1486 pci_unregister_driver(&hptiop_pci_driver); 936 pci_unregister_driver(&hptiop_pci_driver);
1487} 937}
1488 938
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index 944fc1203ebd..669ea4fff166 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -535,6 +535,7 @@ static int ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct,
535 struct ibmvscsi_host_data *hostdata) 535 struct ibmvscsi_host_data *hostdata)
536{ 536{
537 u64 *crq_as_u64 = (u64 *) &evt_struct->crq; 537 u64 *crq_as_u64 = (u64 *) &evt_struct->crq;
538 int request_status;
538 int rc; 539 int rc;
539 540
540 /* If we have exhausted our request limit, just fail this request. 541 /* If we have exhausted our request limit, just fail this request.
@@ -542,9 +543,18 @@ static int ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct,
542 * (such as task management requests) that the mid layer may think we 543 * (such as task management requests) that the mid layer may think we
543 * can handle more requests (can_queue) when we actually can't 544 * can handle more requests (can_queue) when we actually can't
544 */ 545 */
545 if ((evt_struct->crq.format == VIOSRP_SRP_FORMAT) && 546 if (evt_struct->crq.format == VIOSRP_SRP_FORMAT) {
546 (atomic_dec_if_positive(&hostdata->request_limit) < 0)) 547 request_status =
547 goto send_error; 548 atomic_dec_if_positive(&hostdata->request_limit);
549 /* If request limit was -1 when we started, it is now even
550 * less than that
551 */
552 if (request_status < -1)
553 goto send_error;
554 /* Otherwise, if we have run out of requests */
555 else if (request_status < 0)
556 goto send_busy;
557 }
548 558
549 /* Copy the IU into the transfer area */ 559 /* Copy the IU into the transfer area */
550 *evt_struct->xfer_iu = evt_struct->iu; 560 *evt_struct->xfer_iu = evt_struct->iu;
@@ -567,11 +577,23 @@ static int ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct,
567 577
568 return 0; 578 return 0;
569 579
570 send_error: 580 send_busy:
571 unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev); 581 unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev);
572 582
573 free_event_struct(&hostdata->pool, evt_struct); 583 free_event_struct(&hostdata->pool, evt_struct);
574 return SCSI_MLQUEUE_HOST_BUSY; 584 return SCSI_MLQUEUE_HOST_BUSY;
585
586 send_error:
587 unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev);
588
589 if (evt_struct->cmnd != NULL) {
590 evt_struct->cmnd->result = DID_ERROR << 16;
591 evt_struct->cmnd_done(evt_struct->cmnd);
592 } else if (evt_struct->done)
593 evt_struct->done(evt_struct);
594
595 free_event_struct(&hostdata->pool, evt_struct);
596 return 0;
575} 597}
576 598
577/** 599/**
@@ -1184,27 +1206,37 @@ void ibmvscsi_handle_crq(struct viosrp_crq *crq,
1184 return; 1206 return;
1185 case 0xFF: /* Hypervisor telling us the connection is closed */ 1207 case 0xFF: /* Hypervisor telling us the connection is closed */
1186 scsi_block_requests(hostdata->host); 1208 scsi_block_requests(hostdata->host);
1209 atomic_set(&hostdata->request_limit, 0);
1187 if (crq->format == 0x06) { 1210 if (crq->format == 0x06) {
1188 /* We need to re-setup the interpartition connection */ 1211 /* We need to re-setup the interpartition connection */
1189 printk(KERN_INFO 1212 printk(KERN_INFO
1190 "ibmvscsi: Re-enabling adapter!\n"); 1213 "ibmvscsi: Re-enabling adapter!\n");
1191 atomic_set(&hostdata->request_limit, -1);
1192 purge_requests(hostdata, DID_REQUEUE); 1214 purge_requests(hostdata, DID_REQUEUE);
1193 if (ibmvscsi_reenable_crq_queue(&hostdata->queue, 1215 if ((ibmvscsi_reenable_crq_queue(&hostdata->queue,
1194 hostdata) == 0) 1216 hostdata) == 0) ||
1195 if (ibmvscsi_send_crq(hostdata, 1217 (ibmvscsi_send_crq(hostdata,
1196 0xC001000000000000LL, 0)) 1218 0xC001000000000000LL, 0))) {
1219 atomic_set(&hostdata->request_limit,
1220 -1);
1197 printk(KERN_ERR 1221 printk(KERN_ERR
1198 "ibmvscsi: transmit error after" 1222 "ibmvscsi: error after"
1199 " enable\n"); 1223 " enable\n");
1224 }
1200 } else { 1225 } else {
1201 printk(KERN_INFO 1226 printk(KERN_INFO
1202 "ibmvscsi: Virtual adapter failed rc %d!\n", 1227 "ibmvscsi: Virtual adapter failed rc %d!\n",
1203 crq->format); 1228 crq->format);
1204 1229
1205 atomic_set(&hostdata->request_limit, -1);
1206 purge_requests(hostdata, DID_ERROR); 1230 purge_requests(hostdata, DID_ERROR);
1207 ibmvscsi_reset_crq_queue(&hostdata->queue, hostdata); 1231 if ((ibmvscsi_reset_crq_queue(&hostdata->queue,
1232 hostdata)) ||
1233 (ibmvscsi_send_crq(hostdata,
1234 0xC001000000000000LL, 0))) {
1235 atomic_set(&hostdata->request_limit,
1236 -1);
1237 printk(KERN_ERR
1238 "ibmvscsi: error after reset\n");
1239 }
1208 } 1240 }
1209 scsi_unblock_requests(hostdata->host); 1241 scsi_unblock_requests(hostdata->host);
1210 return; 1242 return;
@@ -1467,6 +1499,7 @@ static int ibmvscsi_probe(struct vio_dev *vdev, const struct vio_device_id *id)
1467 struct Scsi_Host *host; 1499 struct Scsi_Host *host;
1468 struct device *dev = &vdev->dev; 1500 struct device *dev = &vdev->dev;
1469 unsigned long wait_switch = 0; 1501 unsigned long wait_switch = 0;
1502 int rc;
1470 1503
1471 vdev->dev.driver_data = NULL; 1504 vdev->dev.driver_data = NULL;
1472 1505
@@ -1484,8 +1517,8 @@ static int ibmvscsi_probe(struct vio_dev *vdev, const struct vio_device_id *id)
1484 atomic_set(&hostdata->request_limit, -1); 1517 atomic_set(&hostdata->request_limit, -1);
1485 hostdata->host->max_sectors = 32 * 8; /* default max I/O 32 pages */ 1518 hostdata->host->max_sectors = 32 * 8; /* default max I/O 32 pages */
1486 1519
1487 if (ibmvscsi_init_crq_queue(&hostdata->queue, hostdata, 1520 rc = ibmvscsi_init_crq_queue(&hostdata->queue, hostdata, max_requests);
1488 max_requests) != 0) { 1521 if (rc != 0 && rc != H_RESOURCE) {
1489 printk(KERN_ERR "ibmvscsi: couldn't initialize crq\n"); 1522 printk(KERN_ERR "ibmvscsi: couldn't initialize crq\n");
1490 goto init_crq_failed; 1523 goto init_crq_failed;
1491 } 1524 }
@@ -1505,7 +1538,8 @@ static int ibmvscsi_probe(struct vio_dev *vdev, const struct vio_device_id *id)
1505 * to fail if the other end is not acive. In that case we don't 1538 * to fail if the other end is not acive. In that case we don't
1506 * want to scan 1539 * want to scan
1507 */ 1540 */
1508 if (ibmvscsi_send_crq(hostdata, 0xC001000000000000LL, 0) == 0) { 1541 if (ibmvscsi_send_crq(hostdata, 0xC001000000000000LL, 0) == 0
1542 || rc == H_RESOURCE) {
1509 /* 1543 /*
1510 * Wait around max init_timeout secs for the adapter to finish 1544 * Wait around max init_timeout secs for the adapter to finish
1511 * initializing. When we are done initializing, we will have a 1545 * initializing. When we are done initializing, we will have a
diff --git a/drivers/scsi/ibmvscsi/iseries_vscsi.c b/drivers/scsi/ibmvscsi/iseries_vscsi.c
index 7eed0b098171..6aeb5f003c3c 100644
--- a/drivers/scsi/ibmvscsi/iseries_vscsi.c
+++ b/drivers/scsi/ibmvscsi/iseries_vscsi.c
@@ -81,7 +81,7 @@ int ibmvscsi_init_crq_queue(struct crq_queue *queue,
81 int rc; 81 int rc;
82 82
83 single_host_data = hostdata; 83 single_host_data = hostdata;
84 rc = viopath_open(viopath_hostLp, viomajorsubtype_scsi, 0); 84 rc = viopath_open(viopath_hostLp, viomajorsubtype_scsi, max_requests);
85 if (rc < 0) { 85 if (rc < 0) {
86 printk("viopath_open failed with rc %d in open_event_path\n", 86 printk("viopath_open failed with rc %d in open_event_path\n",
87 rc); 87 rc);
diff --git a/drivers/scsi/ibmvscsi/rpa_vscsi.c b/drivers/scsi/ibmvscsi/rpa_vscsi.c
index 1a9992bdfef8..ed22b96580c6 100644
--- a/drivers/scsi/ibmvscsi/rpa_vscsi.c
+++ b/drivers/scsi/ibmvscsi/rpa_vscsi.c
@@ -208,6 +208,7 @@ int ibmvscsi_init_crq_queue(struct crq_queue *queue,
208 int max_requests) 208 int max_requests)
209{ 209{
210 int rc; 210 int rc;
211 int retrc;
211 struct vio_dev *vdev = to_vio_dev(hostdata->dev); 212 struct vio_dev *vdev = to_vio_dev(hostdata->dev);
212 213
213 queue->msgs = (struct viosrp_crq *)get_zeroed_page(GFP_KERNEL); 214 queue->msgs = (struct viosrp_crq *)get_zeroed_page(GFP_KERNEL);
@@ -226,7 +227,7 @@ int ibmvscsi_init_crq_queue(struct crq_queue *queue,
226 gather_partition_info(); 227 gather_partition_info();
227 set_adapter_info(hostdata); 228 set_adapter_info(hostdata);
228 229
229 rc = plpar_hcall_norets(H_REG_CRQ, 230 retrc = rc = plpar_hcall_norets(H_REG_CRQ,
230 vdev->unit_address, 231 vdev->unit_address,
231 queue->msg_token, PAGE_SIZE); 232 queue->msg_token, PAGE_SIZE);
232 if (rc == H_RESOURCE) 233 if (rc == H_RESOURCE)
@@ -237,6 +238,7 @@ int ibmvscsi_init_crq_queue(struct crq_queue *queue,
237 if (rc == 2) { 238 if (rc == 2) {
238 /* Adapter is good, but other end is not ready */ 239 /* Adapter is good, but other end is not ready */
239 printk(KERN_WARNING "ibmvscsi: Partner adapter not ready\n"); 240 printk(KERN_WARNING "ibmvscsi: Partner adapter not ready\n");
241 retrc = 0;
240 } else if (rc != 0) { 242 } else if (rc != 0) {
241 printk(KERN_WARNING "ibmvscsi: Error %d opening adapter\n", rc); 243 printk(KERN_WARNING "ibmvscsi: Error %d opening adapter\n", rc);
242 goto reg_crq_failed; 244 goto reg_crq_failed;
@@ -263,7 +265,7 @@ int ibmvscsi_init_crq_queue(struct crq_queue *queue,
263 tasklet_init(&hostdata->srp_task, (void *)ibmvscsi_task, 265 tasklet_init(&hostdata->srp_task, (void *)ibmvscsi_task,
264 (unsigned long)hostdata); 266 (unsigned long)hostdata);
265 267
266 return 0; 268 return retrc;
267 269
268 req_irq_failed: 270 req_irq_failed:
269 do { 271 do {
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index f7b5d7372d26..94d1de55607f 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -517,7 +517,7 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
517 /* No more interrupts */ 517 /* No more interrupts */
518 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) 518 if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
519 printk (KERN_INFO "Packet command completed, %d bytes transferred\n", pc->actually_transferred); 519 printk (KERN_INFO "Packet command completed, %d bytes transferred\n", pc->actually_transferred);
520 local_irq_enable(); 520 local_irq_enable_in_hardirq();
521 if (status.b.check) 521 if (status.b.check)
522 rq->errors++; 522 rq->errors++;
523 idescsi_end_request (drive, 1, 0); 523 idescsi_end_request (drive, 1, 0);
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index b4743a9ecc80..058f094f945a 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -43,13 +43,10 @@
43 43
44#include "iscsi_tcp.h" 44#include "iscsi_tcp.h"
45 45
46#define ISCSI_TCP_VERSION "1.0-595"
47
48MODULE_AUTHOR("Dmitry Yusupov <dmitry_yus@yahoo.com>, " 46MODULE_AUTHOR("Dmitry Yusupov <dmitry_yus@yahoo.com>, "
49 "Alex Aizman <itn780@yahoo.com>"); 47 "Alex Aizman <itn780@yahoo.com>");
50MODULE_DESCRIPTION("iSCSI/TCP data-path"); 48MODULE_DESCRIPTION("iSCSI/TCP data-path");
51MODULE_LICENSE("GPL"); 49MODULE_LICENSE("GPL");
52MODULE_VERSION(ISCSI_TCP_VERSION);
53/* #define DEBUG_TCP */ 50/* #define DEBUG_TCP */
54#define DEBUG_ASSERT 51#define DEBUG_ASSERT
55 52
@@ -185,11 +182,19 @@ iscsi_hdr_extract(struct iscsi_tcp_conn *tcp_conn)
185 * must be called with session lock 182 * must be called with session lock
186 */ 183 */
187static void 184static void
188__iscsi_ctask_cleanup(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) 185iscsi_tcp_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
189{ 186{
190 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; 187 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
188 struct iscsi_r2t_info *r2t;
191 struct scsi_cmnd *sc; 189 struct scsi_cmnd *sc;
192 190
191 /* flush ctask's r2t queues */
192 while (__kfifo_get(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*))) {
193 __kfifo_put(tcp_ctask->r2tpool.queue, (void*)&r2t,
194 sizeof(void*));
195 debug_scsi("iscsi_tcp_cleanup_ctask pending r2t dropped\n");
196 }
197
193 sc = ctask->sc; 198 sc = ctask->sc;
194 if (unlikely(!sc)) 199 if (unlikely(!sc))
195 return; 200 return;
@@ -374,6 +379,7 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
374 spin_unlock(&session->lock); 379 spin_unlock(&session->lock);
375 return 0; 380 return 0;
376 } 381 }
382
377 rc = __kfifo_get(tcp_ctask->r2tpool.queue, (void*)&r2t, sizeof(void*)); 383 rc = __kfifo_get(tcp_ctask->r2tpool.queue, (void*)&r2t, sizeof(void*));
378 BUG_ON(!rc); 384 BUG_ON(!rc);
379 385
@@ -399,7 +405,7 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
399 tcp_ctask->exp_r2tsn = r2tsn + 1; 405 tcp_ctask->exp_r2tsn = r2tsn + 1;
400 tcp_ctask->xmstate |= XMSTATE_SOL_HDR; 406 tcp_ctask->xmstate |= XMSTATE_SOL_HDR;
401 __kfifo_put(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*)); 407 __kfifo_put(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*));
402 __kfifo_put(conn->xmitqueue, (void*)&ctask, sizeof(void*)); 408 list_move_tail(&ctask->running, &conn->xmitqueue);
403 409
404 scsi_queue_work(session->host, &conn->xmitwork); 410 scsi_queue_work(session->host, &conn->xmitwork);
405 conn->r2t_pdus_cnt++; 411 conn->r2t_pdus_cnt++;
@@ -477,6 +483,8 @@ iscsi_tcp_hdr_recv(struct iscsi_conn *conn)
477 case ISCSI_OP_SCSI_DATA_IN: 483 case ISCSI_OP_SCSI_DATA_IN:
478 tcp_conn->in.ctask = session->cmds[itt]; 484 tcp_conn->in.ctask = session->cmds[itt];
479 rc = iscsi_data_rsp(conn, tcp_conn->in.ctask); 485 rc = iscsi_data_rsp(conn, tcp_conn->in.ctask);
486 if (rc)
487 return rc;
480 /* fall through */ 488 /* fall through */
481 case ISCSI_OP_SCSI_CMD_RSP: 489 case ISCSI_OP_SCSI_CMD_RSP:
482 tcp_conn->in.ctask = session->cmds[itt]; 490 tcp_conn->in.ctask = session->cmds[itt];
@@ -484,7 +492,7 @@ iscsi_tcp_hdr_recv(struct iscsi_conn *conn)
484 goto copy_hdr; 492 goto copy_hdr;
485 493
486 spin_lock(&session->lock); 494 spin_lock(&session->lock);
487 __iscsi_ctask_cleanup(conn, tcp_conn->in.ctask); 495 iscsi_tcp_cleanup_ctask(conn, tcp_conn->in.ctask);
488 rc = __iscsi_complete_pdu(conn, hdr, NULL, 0); 496 rc = __iscsi_complete_pdu(conn, hdr, NULL, 0);
489 spin_unlock(&session->lock); 497 spin_unlock(&session->lock);
490 break; 498 break;
@@ -500,13 +508,28 @@ iscsi_tcp_hdr_recv(struct iscsi_conn *conn)
500 break; 508 break;
501 case ISCSI_OP_LOGIN_RSP: 509 case ISCSI_OP_LOGIN_RSP:
502 case ISCSI_OP_TEXT_RSP: 510 case ISCSI_OP_TEXT_RSP:
503 case ISCSI_OP_LOGOUT_RSP:
504 case ISCSI_OP_NOOP_IN:
505 case ISCSI_OP_REJECT: 511 case ISCSI_OP_REJECT:
506 case ISCSI_OP_ASYNC_EVENT: 512 case ISCSI_OP_ASYNC_EVENT:
513 /*
514 * It is possible that we could get a PDU with a buffer larger
515 * than 8K, but there are no targets that currently do this.
516 * For now we fail until we find a vendor that needs it
517 */
518 if (DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH <
519 tcp_conn->in.datalen) {
520 printk(KERN_ERR "iscsi_tcp: received buffer of len %u "
521 "but conn buffer is only %u (opcode %0x)\n",
522 tcp_conn->in.datalen,
523 DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH, opcode);
524 rc = ISCSI_ERR_PROTO;
525 break;
526 }
527
507 if (tcp_conn->in.datalen) 528 if (tcp_conn->in.datalen)
508 goto copy_hdr; 529 goto copy_hdr;
509 /* fall through */ 530 /* fall through */
531 case ISCSI_OP_LOGOUT_RSP:
532 case ISCSI_OP_NOOP_IN:
510 case ISCSI_OP_SCSI_TMFUNC_RSP: 533 case ISCSI_OP_SCSI_TMFUNC_RSP:
511 rc = iscsi_complete_pdu(conn, hdr, NULL, 0); 534 rc = iscsi_complete_pdu(conn, hdr, NULL, 0);
512 break; 535 break;
@@ -523,7 +546,7 @@ copy_hdr:
523 * skbs to complete the command then we have to copy the header 546 * skbs to complete the command then we have to copy the header
524 * for later use 547 * for later use
525 */ 548 */
526 if (tcp_conn->in.zero_copy_hdr && tcp_conn->in.copy < 549 if (tcp_conn->in.zero_copy_hdr && tcp_conn->in.copy <=
527 (tcp_conn->in.datalen + tcp_conn->in.padding + 550 (tcp_conn->in.datalen + tcp_conn->in.padding +
528 (conn->datadgst_en ? 4 : 0))) { 551 (conn->datadgst_en ? 4 : 0))) {
529 debug_tcp("Copying header for later use. in.copy %d in.datalen" 552 debug_tcp("Copying header for later use. in.copy %d in.datalen"
@@ -614,9 +637,9 @@ iscsi_ctask_copy(struct iscsi_tcp_conn *tcp_conn, struct iscsi_cmd_task *ctask,
614 * byte counters. 637 * byte counters.
615 **/ 638 **/
616static inline int 639static inline int
617iscsi_tcp_copy(struct iscsi_tcp_conn *tcp_conn) 640iscsi_tcp_copy(struct iscsi_conn *conn)
618{ 641{
619 void *buf = tcp_conn->data; 642 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
620 int buf_size = tcp_conn->in.datalen; 643 int buf_size = tcp_conn->in.datalen;
621 int buf_left = buf_size - tcp_conn->data_copied; 644 int buf_left = buf_size - tcp_conn->data_copied;
622 int size = min(tcp_conn->in.copy, buf_left); 645 int size = min(tcp_conn->in.copy, buf_left);
@@ -627,7 +650,7 @@ iscsi_tcp_copy(struct iscsi_tcp_conn *tcp_conn)
627 BUG_ON(size <= 0); 650 BUG_ON(size <= 0);
628 651
629 rc = skb_copy_bits(tcp_conn->in.skb, tcp_conn->in.offset, 652 rc = skb_copy_bits(tcp_conn->in.skb, tcp_conn->in.offset,
630 (char*)buf + tcp_conn->data_copied, size); 653 (char*)conn->data + tcp_conn->data_copied, size);
631 BUG_ON(rc); 654 BUG_ON(rc);
632 655
633 tcp_conn->in.offset += size; 656 tcp_conn->in.offset += size;
@@ -745,10 +768,11 @@ static int iscsi_scsi_data_in(struct iscsi_conn *conn)
745done: 768done:
746 /* check for non-exceptional status */ 769 /* check for non-exceptional status */
747 if (tcp_conn->in.hdr->flags & ISCSI_FLAG_DATA_STATUS) { 770 if (tcp_conn->in.hdr->flags & ISCSI_FLAG_DATA_STATUS) {
748 debug_scsi("done [sc %lx res %d itt 0x%x]\n", 771 debug_scsi("done [sc %lx res %d itt 0x%x flags 0x%x]\n",
749 (long)sc, sc->result, ctask->itt); 772 (long)sc, sc->result, ctask->itt,
773 tcp_conn->in.hdr->flags);
750 spin_lock(&conn->session->lock); 774 spin_lock(&conn->session->lock);
751 __iscsi_ctask_cleanup(conn, ctask); 775 iscsi_tcp_cleanup_ctask(conn, ctask);
752 __iscsi_complete_pdu(conn, tcp_conn->in.hdr, NULL, 0); 776 __iscsi_complete_pdu(conn, tcp_conn->in.hdr, NULL, 0);
753 spin_unlock(&conn->session->lock); 777 spin_unlock(&conn->session->lock);
754 } 778 }
@@ -769,26 +793,25 @@ iscsi_data_recv(struct iscsi_conn *conn)
769 break; 793 break;
770 case ISCSI_OP_SCSI_CMD_RSP: 794 case ISCSI_OP_SCSI_CMD_RSP:
771 spin_lock(&conn->session->lock); 795 spin_lock(&conn->session->lock);
772 __iscsi_ctask_cleanup(conn, tcp_conn->in.ctask); 796 iscsi_tcp_cleanup_ctask(conn, tcp_conn->in.ctask);
773 spin_unlock(&conn->session->lock); 797 spin_unlock(&conn->session->lock);
774 case ISCSI_OP_TEXT_RSP: 798 case ISCSI_OP_TEXT_RSP:
775 case ISCSI_OP_LOGIN_RSP: 799 case ISCSI_OP_LOGIN_RSP:
776 case ISCSI_OP_NOOP_IN:
777 case ISCSI_OP_ASYNC_EVENT: 800 case ISCSI_OP_ASYNC_EVENT:
778 case ISCSI_OP_REJECT: 801 case ISCSI_OP_REJECT:
779 /* 802 /*
780 * Collect data segment to the connection's data 803 * Collect data segment to the connection's data
781 * placeholder 804 * placeholder
782 */ 805 */
783 if (iscsi_tcp_copy(tcp_conn)) { 806 if (iscsi_tcp_copy(conn)) {
784 rc = -EAGAIN; 807 rc = -EAGAIN;
785 goto exit; 808 goto exit;
786 } 809 }
787 810
788 rc = iscsi_complete_pdu(conn, tcp_conn->in.hdr, tcp_conn->data, 811 rc = iscsi_complete_pdu(conn, tcp_conn->in.hdr, conn->data,
789 tcp_conn->in.datalen); 812 tcp_conn->in.datalen);
790 if (!rc && conn->datadgst_en && opcode != ISCSI_OP_LOGIN_RSP) 813 if (!rc && conn->datadgst_en && opcode != ISCSI_OP_LOGIN_RSP)
791 iscsi_recv_digest_update(tcp_conn, tcp_conn->data, 814 iscsi_recv_digest_update(tcp_conn, conn->data,
792 tcp_conn->in.datalen); 815 tcp_conn->in.datalen);
793 break; 816 break;
794 default: 817 default:
@@ -843,7 +866,7 @@ more:
843 if (rc == -EAGAIN) 866 if (rc == -EAGAIN)
844 goto nomore; 867 goto nomore;
845 else { 868 else {
846 iscsi_conn_failure(conn, rc); 869 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
847 return 0; 870 return 0;
848 } 871 }
849 } 872 }
@@ -897,7 +920,7 @@ more:
897 if (rc) { 920 if (rc) {
898 if (rc == -EAGAIN) 921 if (rc == -EAGAIN)
899 goto again; 922 goto again;
900 iscsi_conn_failure(conn, rc); 923 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
901 return 0; 924 return 0;
902 } 925 }
903 tcp_conn->in.copy -= tcp_conn->in.padding; 926 tcp_conn->in.copy -= tcp_conn->in.padding;
@@ -1028,9 +1051,8 @@ iscsi_conn_set_callbacks(struct iscsi_conn *conn)
1028} 1051}
1029 1052
1030static void 1053static void
1031iscsi_conn_restore_callbacks(struct iscsi_conn *conn) 1054iscsi_conn_restore_callbacks(struct iscsi_tcp_conn *tcp_conn)
1032{ 1055{
1033 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1034 struct sock *sk = tcp_conn->sock->sk; 1056 struct sock *sk = tcp_conn->sock->sk;
1035 1057
1036 /* restore socket callbacks, see also: iscsi_conn_set_callbacks() */ 1058 /* restore socket callbacks, see also: iscsi_conn_set_callbacks() */
@@ -1308,7 +1330,7 @@ iscsi_tcp_cmd_init(struct iscsi_cmd_task *ctask)
1308 ctask->imm_count - 1330 ctask->imm_count -
1309 ctask->unsol_count; 1331 ctask->unsol_count;
1310 1332
1311 debug_scsi("cmd [itt %x total %d imm %d imm_data %d " 1333 debug_scsi("cmd [itt 0x%x total %d imm %d imm_data %d "
1312 "r2t_data %d]\n", 1334 "r2t_data %d]\n",
1313 ctask->itt, ctask->total_length, ctask->imm_count, 1335 ctask->itt, ctask->total_length, ctask->imm_count,
1314 ctask->unsol_count, tcp_ctask->r2t_data_count); 1336 ctask->unsol_count, tcp_ctask->r2t_data_count);
@@ -1636,7 +1658,7 @@ handle_xmstate_sol_data(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1636 } 1658 }
1637solicit_again: 1659solicit_again:
1638 /* 1660 /*
1639 * send Data-Out whitnin this R2T sequence. 1661 * send Data-Out within this R2T sequence.
1640 */ 1662 */
1641 if (!r2t->data_count) 1663 if (!r2t->data_count)
1642 goto data_out_done; 1664 goto data_out_done;
@@ -1731,7 +1753,7 @@ handle_xmstate_w_pad(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1731 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; 1753 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1732 struct iscsi_tcp_conn *tcp_conn = conn->dd_data; 1754 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1733 struct iscsi_data_task *dtask = tcp_ctask->dtask; 1755 struct iscsi_data_task *dtask = tcp_ctask->dtask;
1734 int sent, rc; 1756 int sent = 0, rc;
1735 1757
1736 tcp_ctask->xmstate &= ~XMSTATE_W_PAD; 1758 tcp_ctask->xmstate &= ~XMSTATE_W_PAD;
1737 iscsi_buf_init_iov(&tcp_ctask->sendbuf, (char*)&tcp_ctask->pad, 1759 iscsi_buf_init_iov(&tcp_ctask->sendbuf, (char*)&tcp_ctask->pad,
@@ -1900,27 +1922,32 @@ iscsi_tcp_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
1900 tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER; 1922 tcp_conn->in_progress = IN_PROGRESS_WAIT_HEADER;
1901 /* initial operational parameters */ 1923 /* initial operational parameters */
1902 tcp_conn->hdr_size = sizeof(struct iscsi_hdr); 1924 tcp_conn->hdr_size = sizeof(struct iscsi_hdr);
1903 tcp_conn->data_size = DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH;
1904
1905 /* allocate initial PDU receive place holder */
1906 if (tcp_conn->data_size <= PAGE_SIZE)
1907 tcp_conn->data = kmalloc(tcp_conn->data_size, GFP_KERNEL);
1908 else
1909 tcp_conn->data = (void*)__get_free_pages(GFP_KERNEL,
1910 get_order(tcp_conn->data_size));
1911 if (!tcp_conn->data)
1912 goto max_recv_dlenght_alloc_fail;
1913 1925
1914 return cls_conn; 1926 return cls_conn;
1915 1927
1916max_recv_dlenght_alloc_fail:
1917 kfree(tcp_conn);
1918tcp_conn_alloc_fail: 1928tcp_conn_alloc_fail:
1919 iscsi_conn_teardown(cls_conn); 1929 iscsi_conn_teardown(cls_conn);
1920 return NULL; 1930 return NULL;
1921} 1931}
1922 1932
1923static void 1933static void
1934iscsi_tcp_release_conn(struct iscsi_conn *conn)
1935{
1936 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1937
1938 if (!tcp_conn->sock)
1939 return;
1940
1941 sock_hold(tcp_conn->sock->sk);
1942 iscsi_conn_restore_callbacks(tcp_conn);
1943 sock_put(tcp_conn->sock->sk);
1944
1945 sock_release(tcp_conn->sock);
1946 tcp_conn->sock = NULL;
1947 conn->recv_lock = NULL;
1948}
1949
1950static void
1924iscsi_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn) 1951iscsi_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn)
1925{ 1952{
1926 struct iscsi_conn *conn = cls_conn->dd_data; 1953 struct iscsi_conn *conn = cls_conn->dd_data;
@@ -1930,6 +1957,7 @@ iscsi_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn)
1930 if (conn->hdrdgst_en || conn->datadgst_en) 1957 if (conn->hdrdgst_en || conn->datadgst_en)
1931 digest = 1; 1958 digest = 1;
1932 1959
1960 iscsi_tcp_release_conn(conn);
1933 iscsi_conn_teardown(cls_conn); 1961 iscsi_conn_teardown(cls_conn);
1934 1962
1935 /* now free tcp_conn */ 1963 /* now free tcp_conn */
@@ -1944,15 +1972,18 @@ iscsi_tcp_conn_destroy(struct iscsi_cls_conn *cls_conn)
1944 crypto_free_tfm(tcp_conn->data_rx_tfm); 1972 crypto_free_tfm(tcp_conn->data_rx_tfm);
1945 } 1973 }
1946 1974
1947 /* free conn->data, size = MaxRecvDataSegmentLength */
1948 if (tcp_conn->data_size <= PAGE_SIZE)
1949 kfree(tcp_conn->data);
1950 else
1951 free_pages((unsigned long)tcp_conn->data,
1952 get_order(tcp_conn->data_size));
1953 kfree(tcp_conn); 1975 kfree(tcp_conn);
1954} 1976}
1955 1977
1978static void
1979iscsi_tcp_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
1980{
1981 struct iscsi_conn *conn = cls_conn->dd_data;
1982
1983 iscsi_conn_stop(cls_conn, flag);
1984 iscsi_tcp_release_conn(conn);
1985}
1986
1956static int 1987static int
1957iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session, 1988iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session,
1958 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph, 1989 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
@@ -2001,52 +2032,6 @@ iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session,
2001 return 0; 2032 return 0;
2002} 2033}
2003 2034
2004static void
2005iscsi_tcp_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
2006{
2007 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
2008 struct iscsi_r2t_info *r2t;
2009
2010 /* flush ctask's r2t queues */
2011 while (__kfifo_get(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*)))
2012 __kfifo_put(tcp_ctask->r2tpool.queue, (void*)&r2t,
2013 sizeof(void*));
2014
2015 __iscsi_ctask_cleanup(conn, ctask);
2016}
2017
2018static void
2019iscsi_tcp_suspend_conn_rx(struct iscsi_conn *conn)
2020{
2021 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
2022 struct sock *sk;
2023
2024 if (!tcp_conn->sock)
2025 return;
2026
2027 sk = tcp_conn->sock->sk;
2028 write_lock_bh(&sk->sk_callback_lock);
2029 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
2030 write_unlock_bh(&sk->sk_callback_lock);
2031}
2032
2033static void
2034iscsi_tcp_terminate_conn(struct iscsi_conn *conn)
2035{
2036 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
2037
2038 if (!tcp_conn->sock)
2039 return;
2040
2041 sock_hold(tcp_conn->sock->sk);
2042 iscsi_conn_restore_callbacks(conn);
2043 sock_put(tcp_conn->sock->sk);
2044
2045 sock_release(tcp_conn->sock);
2046 tcp_conn->sock = NULL;
2047 conn->recv_lock = NULL;
2048}
2049
2050/* called with host lock */ 2035/* called with host lock */
2051static void 2036static void
2052iscsi_tcp_mgmt_init(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask, 2037iscsi_tcp_mgmt_init(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask,
@@ -2057,6 +2042,7 @@ iscsi_tcp_mgmt_init(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask,
2057 iscsi_buf_init_iov(&tcp_mtask->headbuf, (char*)mtask->hdr, 2042 iscsi_buf_init_iov(&tcp_mtask->headbuf, (char*)mtask->hdr,
2058 sizeof(struct iscsi_hdr)); 2043 sizeof(struct iscsi_hdr));
2059 tcp_mtask->xmstate = XMSTATE_IMM_HDR; 2044 tcp_mtask->xmstate = XMSTATE_IMM_HDR;
2045 tcp_mtask->sent = 0;
2060 2046
2061 if (mtask->data_count) 2047 if (mtask->data_count)
2062 iscsi_buf_init_iov(&tcp_mtask->sendbuf, (char*)mtask->data, 2048 iscsi_buf_init_iov(&tcp_mtask->sendbuf, (char*)mtask->data,
@@ -2130,50 +2116,16 @@ iscsi_r2tpool_free(struct iscsi_session *session)
2130 2116
2131static int 2117static int
2132iscsi_conn_set_param(struct iscsi_cls_conn *cls_conn, enum iscsi_param param, 2118iscsi_conn_set_param(struct iscsi_cls_conn *cls_conn, enum iscsi_param param,
2133 uint32_t value) 2119 char *buf, int buflen)
2134{ 2120{
2135 struct iscsi_conn *conn = cls_conn->dd_data; 2121 struct iscsi_conn *conn = cls_conn->dd_data;
2136 struct iscsi_session *session = conn->session; 2122 struct iscsi_session *session = conn->session;
2137 struct iscsi_tcp_conn *tcp_conn = conn->dd_data; 2123 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
2124 int value;
2138 2125
2139 switch(param) { 2126 switch(param) {
2140 case ISCSI_PARAM_MAX_RECV_DLENGTH: {
2141 char *saveptr = tcp_conn->data;
2142 gfp_t flags = GFP_KERNEL;
2143
2144 if (tcp_conn->data_size >= value) {
2145 conn->max_recv_dlength = value;
2146 break;
2147 }
2148
2149 spin_lock_bh(&session->lock);
2150 if (conn->stop_stage == STOP_CONN_RECOVER)
2151 flags = GFP_ATOMIC;
2152 spin_unlock_bh(&session->lock);
2153
2154 if (value <= PAGE_SIZE)
2155 tcp_conn->data = kmalloc(value, flags);
2156 else
2157 tcp_conn->data = (void*)__get_free_pages(flags,
2158 get_order(value));
2159 if (tcp_conn->data == NULL) {
2160 tcp_conn->data = saveptr;
2161 return -ENOMEM;
2162 }
2163 if (tcp_conn->data_size <= PAGE_SIZE)
2164 kfree(saveptr);
2165 else
2166 free_pages((unsigned long)saveptr,
2167 get_order(tcp_conn->data_size));
2168 conn->max_recv_dlength = value;
2169 tcp_conn->data_size = value;
2170 }
2171 break;
2172 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
2173 conn->max_xmit_dlength = value;
2174 break;
2175 case ISCSI_PARAM_HDRDGST_EN: 2127 case ISCSI_PARAM_HDRDGST_EN:
2176 conn->hdrdgst_en = value; 2128 iscsi_set_param(cls_conn, param, buf, buflen);
2177 tcp_conn->hdr_size = sizeof(struct iscsi_hdr); 2129 tcp_conn->hdr_size = sizeof(struct iscsi_hdr);
2178 if (conn->hdrdgst_en) { 2130 if (conn->hdrdgst_en) {
2179 tcp_conn->hdr_size += sizeof(__u32); 2131 tcp_conn->hdr_size += sizeof(__u32);
@@ -2197,7 +2149,7 @@ iscsi_conn_set_param(struct iscsi_cls_conn *cls_conn, enum iscsi_param param,
2197 } 2149 }
2198 break; 2150 break;
2199 case ISCSI_PARAM_DATADGST_EN: 2151 case ISCSI_PARAM_DATADGST_EN:
2200 conn->datadgst_en = value; 2152 iscsi_set_param(cls_conn, param, buf, buflen);
2201 if (conn->datadgst_en) { 2153 if (conn->datadgst_en) {
2202 if (!tcp_conn->data_tx_tfm) 2154 if (!tcp_conn->data_tx_tfm)
2203 tcp_conn->data_tx_tfm = 2155 tcp_conn->data_tx_tfm =
@@ -2220,121 +2172,36 @@ iscsi_conn_set_param(struct iscsi_cls_conn *cls_conn, enum iscsi_param param,
2220 tcp_conn->sendpage = conn->datadgst_en ? 2172 tcp_conn->sendpage = conn->datadgst_en ?
2221 sock_no_sendpage : tcp_conn->sock->ops->sendpage; 2173 sock_no_sendpage : tcp_conn->sock->ops->sendpage;
2222 break; 2174 break;
2223 case ISCSI_PARAM_INITIAL_R2T_EN:
2224 session->initial_r2t_en = value;
2225 break;
2226 case ISCSI_PARAM_MAX_R2T: 2175 case ISCSI_PARAM_MAX_R2T:
2176 sscanf(buf, "%d", &value);
2227 if (session->max_r2t == roundup_pow_of_two(value)) 2177 if (session->max_r2t == roundup_pow_of_two(value))
2228 break; 2178 break;
2229 iscsi_r2tpool_free(session); 2179 iscsi_r2tpool_free(session);
2230 session->max_r2t = value; 2180 iscsi_set_param(cls_conn, param, buf, buflen);
2231 if (session->max_r2t & (session->max_r2t - 1)) 2181 if (session->max_r2t & (session->max_r2t - 1))
2232 session->max_r2t = roundup_pow_of_two(session->max_r2t); 2182 session->max_r2t = roundup_pow_of_two(session->max_r2t);
2233 if (iscsi_r2tpool_alloc(session)) 2183 if (iscsi_r2tpool_alloc(session))
2234 return -ENOMEM; 2184 return -ENOMEM;
2235 break; 2185 break;
2236 case ISCSI_PARAM_IMM_DATA_EN:
2237 session->imm_data_en = value;
2238 break;
2239 case ISCSI_PARAM_FIRST_BURST:
2240 session->first_burst = value;
2241 break;
2242 case ISCSI_PARAM_MAX_BURST:
2243 session->max_burst = value;
2244 break;
2245 case ISCSI_PARAM_PDU_INORDER_EN:
2246 session->pdu_inorder_en = value;
2247 break;
2248 case ISCSI_PARAM_DATASEQ_INORDER_EN:
2249 session->dataseq_inorder_en = value;
2250 break;
2251 case ISCSI_PARAM_ERL:
2252 session->erl = value;
2253 break;
2254 case ISCSI_PARAM_IFMARKER_EN:
2255 BUG_ON(value);
2256 session->ifmarker_en = value;
2257 break;
2258 case ISCSI_PARAM_OFMARKER_EN:
2259 BUG_ON(value);
2260 session->ofmarker_en = value;
2261 break;
2262 case ISCSI_PARAM_EXP_STATSN:
2263 conn->exp_statsn = value;
2264 break;
2265 default: 2186 default:
2266 break; 2187 return iscsi_set_param(cls_conn, param, buf, buflen);
2267 } 2188 }
2268 2189
2269 return 0; 2190 return 0;
2270} 2191}
2271 2192
2272static int 2193static int
2273iscsi_session_get_param(struct iscsi_cls_session *cls_session, 2194iscsi_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
2274 enum iscsi_param param, uint32_t *value) 2195 enum iscsi_param param, char *buf)
2275{
2276 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
2277 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
2278
2279 switch(param) {
2280 case ISCSI_PARAM_INITIAL_R2T_EN:
2281 *value = session->initial_r2t_en;
2282 break;
2283 case ISCSI_PARAM_MAX_R2T:
2284 *value = session->max_r2t;
2285 break;
2286 case ISCSI_PARAM_IMM_DATA_EN:
2287 *value = session->imm_data_en;
2288 break;
2289 case ISCSI_PARAM_FIRST_BURST:
2290 *value = session->first_burst;
2291 break;
2292 case ISCSI_PARAM_MAX_BURST:
2293 *value = session->max_burst;
2294 break;
2295 case ISCSI_PARAM_PDU_INORDER_EN:
2296 *value = session->pdu_inorder_en;
2297 break;
2298 case ISCSI_PARAM_DATASEQ_INORDER_EN:
2299 *value = session->dataseq_inorder_en;
2300 break;
2301 case ISCSI_PARAM_ERL:
2302 *value = session->erl;
2303 break;
2304 case ISCSI_PARAM_IFMARKER_EN:
2305 *value = session->ifmarker_en;
2306 break;
2307 case ISCSI_PARAM_OFMARKER_EN:
2308 *value = session->ofmarker_en;
2309 break;
2310 default:
2311 return -EINVAL;
2312 }
2313
2314 return 0;
2315}
2316
2317static int
2318iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
2319 enum iscsi_param param, uint32_t *value)
2320{ 2196{
2321 struct iscsi_conn *conn = cls_conn->dd_data; 2197 struct iscsi_conn *conn = cls_conn->dd_data;
2322 struct iscsi_tcp_conn *tcp_conn = conn->dd_data; 2198 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
2323 struct inet_sock *inet; 2199 struct inet_sock *inet;
2200 struct ipv6_pinfo *np;
2201 struct sock *sk;
2202 int len;
2324 2203
2325 switch(param) { 2204 switch(param) {
2326 case ISCSI_PARAM_MAX_RECV_DLENGTH:
2327 *value = conn->max_recv_dlength;
2328 break;
2329 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
2330 *value = conn->max_xmit_dlength;
2331 break;
2332 case ISCSI_PARAM_HDRDGST_EN:
2333 *value = conn->hdrdgst_en;
2334 break;
2335 case ISCSI_PARAM_DATADGST_EN:
2336 *value = conn->datadgst_en;
2337 break;
2338 case ISCSI_PARAM_CONN_PORT: 2205 case ISCSI_PARAM_CONN_PORT:
2339 mutex_lock(&conn->xmitmutex); 2206 mutex_lock(&conn->xmitmutex);
2340 if (!tcp_conn->sock) { 2207 if (!tcp_conn->sock) {
@@ -2343,30 +2210,9 @@ iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
2343 } 2210 }
2344 2211
2345 inet = inet_sk(tcp_conn->sock->sk); 2212 inet = inet_sk(tcp_conn->sock->sk);
2346 *value = be16_to_cpu(inet->dport); 2213 len = sprintf(buf, "%hu\n", be16_to_cpu(inet->dport));
2347 mutex_unlock(&conn->xmitmutex); 2214 mutex_unlock(&conn->xmitmutex);
2348 case ISCSI_PARAM_EXP_STATSN:
2349 *value = conn->exp_statsn;
2350 break; 2215 break;
2351 default:
2352 return -EINVAL;
2353 }
2354
2355 return 0;
2356}
2357
2358static int
2359iscsi_conn_get_str_param(struct iscsi_cls_conn *cls_conn,
2360 enum iscsi_param param, char *buf)
2361{
2362 struct iscsi_conn *conn = cls_conn->dd_data;
2363 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
2364 struct sock *sk;
2365 struct inet_sock *inet;
2366 struct ipv6_pinfo *np;
2367 int len = 0;
2368
2369 switch (param) {
2370 case ISCSI_PARAM_CONN_ADDRESS: 2216 case ISCSI_PARAM_CONN_ADDRESS:
2371 mutex_lock(&conn->xmitmutex); 2217 mutex_lock(&conn->xmitmutex);
2372 if (!tcp_conn->sock) { 2218 if (!tcp_conn->sock) {
@@ -2388,7 +2234,7 @@ iscsi_conn_get_str_param(struct iscsi_cls_conn *cls_conn,
2388 mutex_unlock(&conn->xmitmutex); 2234 mutex_unlock(&conn->xmitmutex);
2389 break; 2235 break;
2390 default: 2236 default:
2391 return -EINVAL; 2237 return iscsi_conn_get_param(cls_conn, param, buf);
2392 } 2238 }
2393 2239
2394 return len; 2240 return len;
@@ -2468,8 +2314,7 @@ static void iscsi_tcp_session_destroy(struct iscsi_cls_session *cls_session)
2468} 2314}
2469 2315
2470static struct scsi_host_template iscsi_sht = { 2316static struct scsi_host_template iscsi_sht = {
2471 .name = "iSCSI Initiator over TCP/IP, v" 2317 .name = "iSCSI Initiator over TCP/IP",
2472 ISCSI_TCP_VERSION,
2473 .queuecommand = iscsi_queuecommand, 2318 .queuecommand = iscsi_queuecommand,
2474 .change_queue_depth = iscsi_change_queue_depth, 2319 .change_queue_depth = iscsi_change_queue_depth,
2475 .can_queue = ISCSI_XMIT_CMDS_MAX - 1, 2320 .can_queue = ISCSI_XMIT_CMDS_MAX - 1,
@@ -2501,7 +2346,11 @@ static struct iscsi_transport iscsi_tcp_transport = {
2501 ISCSI_ERL | 2346 ISCSI_ERL |
2502 ISCSI_CONN_PORT | 2347 ISCSI_CONN_PORT |
2503 ISCSI_CONN_ADDRESS | 2348 ISCSI_CONN_ADDRESS |
2504 ISCSI_EXP_STATSN, 2349 ISCSI_EXP_STATSN |
2350 ISCSI_PERSISTENT_PORT |
2351 ISCSI_PERSISTENT_ADDRESS |
2352 ISCSI_TARGET_NAME |
2353 ISCSI_TPGT,
2505 .host_template = &iscsi_sht, 2354 .host_template = &iscsi_sht,
2506 .conndata_size = sizeof(struct iscsi_conn), 2355 .conndata_size = sizeof(struct iscsi_conn),
2507 .max_conn = 1, 2356 .max_conn = 1,
@@ -2514,14 +2363,10 @@ static struct iscsi_transport iscsi_tcp_transport = {
2514 .bind_conn = iscsi_tcp_conn_bind, 2363 .bind_conn = iscsi_tcp_conn_bind,
2515 .destroy_conn = iscsi_tcp_conn_destroy, 2364 .destroy_conn = iscsi_tcp_conn_destroy,
2516 .set_param = iscsi_conn_set_param, 2365 .set_param = iscsi_conn_set_param,
2517 .get_conn_param = iscsi_conn_get_param, 2366 .get_conn_param = iscsi_tcp_conn_get_param,
2518 .get_conn_str_param = iscsi_conn_get_str_param,
2519 .get_session_param = iscsi_session_get_param, 2367 .get_session_param = iscsi_session_get_param,
2520 .start_conn = iscsi_conn_start, 2368 .start_conn = iscsi_conn_start,
2521 .stop_conn = iscsi_conn_stop, 2369 .stop_conn = iscsi_tcp_conn_stop,
2522 /* these are called as part of conn recovery */
2523 .suspend_conn_recv = iscsi_tcp_suspend_conn_rx,
2524 .terminate_conn = iscsi_tcp_terminate_conn,
2525 /* IO */ 2370 /* IO */
2526 .send_pdu = iscsi_conn_send_pdu, 2371 .send_pdu = iscsi_conn_send_pdu,
2527 .get_stats = iscsi_conn_get_stats, 2372 .get_stats = iscsi_conn_get_stats,
diff --git a/drivers/scsi/iscsi_tcp.h b/drivers/scsi/iscsi_tcp.h
index 808302832e68..6a4ee704e46e 100644
--- a/drivers/scsi/iscsi_tcp.h
+++ b/drivers/scsi/iscsi_tcp.h
@@ -78,8 +78,6 @@ struct iscsi_tcp_conn {
78 char hdrext[4*sizeof(__u16) + 78 char hdrext[4*sizeof(__u16) +
79 sizeof(__u32)]; 79 sizeof(__u32)];
80 int data_copied; 80 int data_copied;
81 char *data; /* data placeholder */
82 int data_size; /* actual recv_dlength */
83 int stop_stage; /* conn_stop() flag: * 81 int stop_stage; /* conn_stop() flag: *
84 * stop to recover, * 82 * stop to recover, *
85 * stop to terminate */ 83 * stop to terminate */
diff --git a/drivers/scsi/jazz_esp.c b/drivers/scsi/jazz_esp.c
index 3fd8a96f2af3..bfac4441d89f 100644
--- a/drivers/scsi/jazz_esp.c
+++ b/drivers/scsi/jazz_esp.c
@@ -257,7 +257,7 @@ static void dma_mmu_release_scsi_one (struct NCR_ESP *esp, struct scsi_cmnd *sp)
257static void dma_mmu_release_scsi_sgl (struct NCR_ESP *esp, struct scsi_cmnd *sp) 257static void dma_mmu_release_scsi_sgl (struct NCR_ESP *esp, struct scsi_cmnd *sp)
258{ 258{
259 int sz = sp->use_sg - 1; 259 int sz = sp->use_sg - 1;
260 struct scatterlist *sg = (struct scatterlist *)sp->buffer; 260 struct scatterlist *sg = (struct scatterlist *)sp->request_buffer;
261 261
262 while(sz >= 0) { 262 while(sz >= 0) {
263 vdma_free(sg[sz].dma_address); 263 vdma_free(sg[sz].dma_address);
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 82caba464291..427b73a3886a 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -61,9 +61,9 @@
61#include "libata.h" 61#include "libata.h"
62 62
63/* debounce timing parameters in msecs { interval, duration, timeout } */ 63/* debounce timing parameters in msecs { interval, duration, timeout } */
64const unsigned long sata_deb_timing_boot[] = { 5, 100, 2000 }; 64const unsigned long sata_deb_timing_normal[] = { 5, 100, 2000 };
65const unsigned long sata_deb_timing_eh[] = { 25, 500, 2000 }; 65const unsigned long sata_deb_timing_hotplug[] = { 25, 500, 2000 };
66const unsigned long sata_deb_timing_before_fsrst[] = { 100, 2000, 5000 }; 66const unsigned long sata_deb_timing_long[] = { 100, 2000, 5000 };
67 67
68static unsigned int ata_dev_init_params(struct ata_device *dev, 68static unsigned int ata_dev_init_params(struct ata_device *dev,
69 u16 heads, u16 sectors); 69 u16 heads, u16 sectors);
@@ -907,7 +907,7 @@ void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *), void *data,
907{ 907{
908 int rc; 908 int rc;
909 909
910 if (ap->flags & ATA_FLAG_FLUSH_PORT_TASK) 910 if (ap->pflags & ATA_PFLAG_FLUSH_PORT_TASK)
911 return; 911 return;
912 912
913 PREPARE_WORK(&ap->port_task, fn, data); 913 PREPARE_WORK(&ap->port_task, fn, data);
@@ -938,7 +938,7 @@ void ata_port_flush_task(struct ata_port *ap)
938 DPRINTK("ENTER\n"); 938 DPRINTK("ENTER\n");
939 939
940 spin_lock_irqsave(ap->lock, flags); 940 spin_lock_irqsave(ap->lock, flags);
941 ap->flags |= ATA_FLAG_FLUSH_PORT_TASK; 941 ap->pflags |= ATA_PFLAG_FLUSH_PORT_TASK;
942 spin_unlock_irqrestore(ap->lock, flags); 942 spin_unlock_irqrestore(ap->lock, flags);
943 943
944 DPRINTK("flush #1\n"); 944 DPRINTK("flush #1\n");
@@ -957,7 +957,7 @@ void ata_port_flush_task(struct ata_port *ap)
957 } 957 }
958 958
959 spin_lock_irqsave(ap->lock, flags); 959 spin_lock_irqsave(ap->lock, flags);
960 ap->flags &= ~ATA_FLAG_FLUSH_PORT_TASK; 960 ap->pflags &= ~ATA_PFLAG_FLUSH_PORT_TASK;
961 spin_unlock_irqrestore(ap->lock, flags); 961 spin_unlock_irqrestore(ap->lock, flags);
962 962
963 if (ata_msg_ctl(ap)) 963 if (ata_msg_ctl(ap))
@@ -1001,7 +1001,7 @@ unsigned ata_exec_internal(struct ata_device *dev,
1001 struct ata_queued_cmd *qc; 1001 struct ata_queued_cmd *qc;
1002 unsigned int tag, preempted_tag; 1002 unsigned int tag, preempted_tag;
1003 u32 preempted_sactive, preempted_qc_active; 1003 u32 preempted_sactive, preempted_qc_active;
1004 DECLARE_COMPLETION(wait); 1004 DECLARE_COMPLETION_ONSTACK(wait);
1005 unsigned long flags; 1005 unsigned long flags;
1006 unsigned int err_mask; 1006 unsigned int err_mask;
1007 int rc; 1007 int rc;
@@ -1009,7 +1009,7 @@ unsigned ata_exec_internal(struct ata_device *dev,
1009 spin_lock_irqsave(ap->lock, flags); 1009 spin_lock_irqsave(ap->lock, flags);
1010 1010
1011 /* no internal command while frozen */ 1011 /* no internal command while frozen */
1012 if (ap->flags & ATA_FLAG_FROZEN) { 1012 if (ap->pflags & ATA_PFLAG_FROZEN) {
1013 spin_unlock_irqrestore(ap->lock, flags); 1013 spin_unlock_irqrestore(ap->lock, flags);
1014 return AC_ERR_SYSTEM; 1014 return AC_ERR_SYSTEM;
1015 } 1015 }
@@ -1256,10 +1256,15 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1256 swap_buf_le16(id, ATA_ID_WORDS); 1256 swap_buf_le16(id, ATA_ID_WORDS);
1257 1257
1258 /* sanity check */ 1258 /* sanity check */
1259 if ((class == ATA_DEV_ATA) != (ata_id_is_ata(id) | ata_id_is_cfa(id))) { 1259 rc = -EINVAL;
1260 rc = -EINVAL; 1260 reason = "device reports illegal type";
1261 reason = "device reports illegal type"; 1261
1262 goto err_out; 1262 if (class == ATA_DEV_ATA) {
1263 if (!ata_id_is_ata(id) && !ata_id_is_cfa(id))
1264 goto err_out;
1265 } else {
1266 if (ata_id_is_ata(id))
1267 goto err_out;
1263 } 1268 }
1264 1269
1265 if (post_reset && class == ATA_DEV_ATA) { 1270 if (post_reset && class == ATA_DEV_ATA) {
@@ -1325,6 +1330,19 @@ static void ata_dev_config_ncq(struct ata_device *dev,
1325 snprintf(desc, desc_sz, "NCQ (depth %d/%d)", hdepth, ddepth); 1330 snprintf(desc, desc_sz, "NCQ (depth %d/%d)", hdepth, ddepth);
1326} 1331}
1327 1332
1333static void ata_set_port_max_cmd_len(struct ata_port *ap)
1334{
1335 int i;
1336
1337 if (ap->host) {
1338 ap->host->max_cmd_len = 0;
1339 for (i = 0; i < ATA_MAX_DEVICES; i++)
1340 ap->host->max_cmd_len = max_t(unsigned int,
1341 ap->host->max_cmd_len,
1342 ap->device[i].cdb_len);
1343 }
1344}
1345
1328/** 1346/**
1329 * ata_dev_configure - Configure the specified ATA/ATAPI device 1347 * ata_dev_configure - Configure the specified ATA/ATAPI device
1330 * @dev: Target device to configure 1348 * @dev: Target device to configure
@@ -1344,7 +1362,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
1344 struct ata_port *ap = dev->ap; 1362 struct ata_port *ap = dev->ap;
1345 const u16 *id = dev->id; 1363 const u16 *id = dev->id;
1346 unsigned int xfer_mask; 1364 unsigned int xfer_mask;
1347 int i, rc; 1365 int rc;
1348 1366
1349 if (!ata_dev_enabled(dev) && ata_msg_info(ap)) { 1367 if (!ata_dev_enabled(dev) && ata_msg_info(ap)) {
1350 ata_dev_printk(dev, KERN_INFO, 1368 ata_dev_printk(dev, KERN_INFO,
@@ -1404,7 +1422,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
1404 ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc)); 1422 ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
1405 1423
1406 /* print device info to dmesg */ 1424 /* print device info to dmesg */
1407 if (ata_msg_info(ap)) 1425 if (ata_msg_drv(ap) && print_info)
1408 ata_dev_printk(dev, KERN_INFO, "ATA-%d, " 1426 ata_dev_printk(dev, KERN_INFO, "ATA-%d, "
1409 "max %s, %Lu sectors: %s %s\n", 1427 "max %s, %Lu sectors: %s %s\n",
1410 ata_id_major_version(id), 1428 ata_id_major_version(id),
@@ -1427,7 +1445,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
1427 } 1445 }
1428 1446
1429 /* print device info to dmesg */ 1447 /* print device info to dmesg */
1430 if (ata_msg_info(ap)) 1448 if (ata_msg_drv(ap) && print_info)
1431 ata_dev_printk(dev, KERN_INFO, "ATA-%d, " 1449 ata_dev_printk(dev, KERN_INFO, "ATA-%d, "
1432 "max %s, %Lu sectors: CHS %u/%u/%u\n", 1450 "max %s, %Lu sectors: CHS %u/%u/%u\n",
1433 ata_id_major_version(id), 1451 ata_id_major_version(id),
@@ -1439,7 +1457,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
1439 1457
1440 if (dev->id[59] & 0x100) { 1458 if (dev->id[59] & 0x100) {
1441 dev->multi_count = dev->id[59] & 0xff; 1459 dev->multi_count = dev->id[59] & 0xff;
1442 if (ata_msg_info(ap)) 1460 if (ata_msg_drv(ap) && print_info)
1443 ata_dev_printk(dev, KERN_INFO, 1461 ata_dev_printk(dev, KERN_INFO,
1444 "ata%u: dev %u multi count %u\n", 1462 "ata%u: dev %u multi count %u\n",
1445 ap->id, dev->devno, dev->multi_count); 1463 ap->id, dev->devno, dev->multi_count);
@@ -1468,21 +1486,17 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
1468 } 1486 }
1469 1487
1470 /* print device info to dmesg */ 1488 /* print device info to dmesg */
1471 if (ata_msg_info(ap)) 1489 if (ata_msg_drv(ap) && print_info)
1472 ata_dev_printk(dev, KERN_INFO, "ATAPI, max %s%s\n", 1490 ata_dev_printk(dev, KERN_INFO, "ATAPI, max %s%s\n",
1473 ata_mode_string(xfer_mask), 1491 ata_mode_string(xfer_mask),
1474 cdb_intr_string); 1492 cdb_intr_string);
1475 } 1493 }
1476 1494
1477 ap->host->max_cmd_len = 0; 1495 ata_set_port_max_cmd_len(ap);
1478 for (i = 0; i < ATA_MAX_DEVICES; i++)
1479 ap->host->max_cmd_len = max_t(unsigned int,
1480 ap->host->max_cmd_len,
1481 ap->device[i].cdb_len);
1482 1496
1483 /* limit bridge transfers to udma5, 200 sectors */ 1497 /* limit bridge transfers to udma5, 200 sectors */
1484 if (ata_dev_knobble(dev)) { 1498 if (ata_dev_knobble(dev)) {
1485 if (ata_msg_info(ap)) 1499 if (ata_msg_drv(ap) && print_info)
1486 ata_dev_printk(dev, KERN_INFO, 1500 ata_dev_printk(dev, KERN_INFO,
1487 "applying bridge limits\n"); 1501 "applying bridge limits\n");
1488 dev->udma_mask &= ATA_UDMA5; 1502 dev->udma_mask &= ATA_UDMA5;
@@ -2137,7 +2151,7 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2137 * return error code and failing device on failure. 2151 * return error code and failing device on failure.
2138 */ 2152 */
2139 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2153 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2140 if (ata_dev_enabled(&ap->device[i])) { 2154 if (ata_dev_ready(&ap->device[i])) {
2141 ap->ops->set_mode(ap); 2155 ap->ops->set_mode(ap);
2142 break; 2156 break;
2143 } 2157 }
@@ -2203,7 +2217,8 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2203 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2217 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2204 dev = &ap->device[i]; 2218 dev = &ap->device[i];
2205 2219
2206 if (!ata_dev_enabled(dev)) 2220 /* don't udpate suspended devices' xfer mode */
2221 if (!ata_dev_ready(dev))
2207 continue; 2222 continue;
2208 2223
2209 rc = ata_dev_set_mode(dev); 2224 rc = ata_dev_set_mode(dev);
@@ -2579,7 +2594,7 @@ static void ata_wait_spinup(struct ata_port *ap)
2579 2594
2580 /* first, debounce phy if SATA */ 2595 /* first, debounce phy if SATA */
2581 if (ap->cbl == ATA_CBL_SATA) { 2596 if (ap->cbl == ATA_CBL_SATA) {
2582 rc = sata_phy_debounce(ap, sata_deb_timing_eh); 2597 rc = sata_phy_debounce(ap, sata_deb_timing_hotplug);
2583 2598
2584 /* if debounced successfully and offline, no need to wait */ 2599 /* if debounced successfully and offline, no need to wait */
2585 if ((rc == 0 || rc == -EOPNOTSUPP) && ata_port_offline(ap)) 2600 if ((rc == 0 || rc == -EOPNOTSUPP) && ata_port_offline(ap))
@@ -2615,16 +2630,17 @@ static void ata_wait_spinup(struct ata_port *ap)
2615int ata_std_prereset(struct ata_port *ap) 2630int ata_std_prereset(struct ata_port *ap)
2616{ 2631{
2617 struct ata_eh_context *ehc = &ap->eh_context; 2632 struct ata_eh_context *ehc = &ap->eh_context;
2618 const unsigned long *timing; 2633 const unsigned long *timing = sata_ehc_deb_timing(ehc);
2619 int rc; 2634 int rc;
2620 2635
2621 /* hotplug? */ 2636 /* handle link resume & hotplug spinup */
2622 if (ehc->i.flags & ATA_EHI_HOTPLUGGED) { 2637 if ((ehc->i.flags & ATA_EHI_RESUME_LINK) &&
2623 if (ap->flags & ATA_FLAG_HRST_TO_RESUME) 2638 (ap->flags & ATA_FLAG_HRST_TO_RESUME))
2624 ehc->i.action |= ATA_EH_HARDRESET; 2639 ehc->i.action |= ATA_EH_HARDRESET;
2625 if (ap->flags & ATA_FLAG_SKIP_D2H_BSY) 2640
2626 ata_wait_spinup(ap); 2641 if ((ehc->i.flags & ATA_EHI_HOTPLUGGED) &&
2627 } 2642 (ap->flags & ATA_FLAG_SKIP_D2H_BSY))
2643 ata_wait_spinup(ap);
2628 2644
2629 /* if we're about to do hardreset, nothing more to do */ 2645 /* if we're about to do hardreset, nothing more to do */
2630 if (ehc->i.action & ATA_EH_HARDRESET) 2646 if (ehc->i.action & ATA_EH_HARDRESET)
@@ -2632,11 +2648,6 @@ int ata_std_prereset(struct ata_port *ap)
2632 2648
2633 /* if SATA, resume phy */ 2649 /* if SATA, resume phy */
2634 if (ap->cbl == ATA_CBL_SATA) { 2650 if (ap->cbl == ATA_CBL_SATA) {
2635 if (ap->flags & ATA_FLAG_LOADING)
2636 timing = sata_deb_timing_boot;
2637 else
2638 timing = sata_deb_timing_eh;
2639
2640 rc = sata_phy_resume(ap, timing); 2651 rc = sata_phy_resume(ap, timing);
2641 if (rc && rc != -EOPNOTSUPP) { 2652 if (rc && rc != -EOPNOTSUPP) {
2642 /* phy resume failed */ 2653 /* phy resume failed */
@@ -2724,6 +2735,8 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
2724 */ 2735 */
2725int sata_std_hardreset(struct ata_port *ap, unsigned int *class) 2736int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2726{ 2737{
2738 struct ata_eh_context *ehc = &ap->eh_context;
2739 const unsigned long *timing = sata_ehc_deb_timing(ehc);
2727 u32 scontrol; 2740 u32 scontrol;
2728 int rc; 2741 int rc;
2729 2742
@@ -2738,7 +2751,7 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2738 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol))) 2751 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol)))
2739 return rc; 2752 return rc;
2740 2753
2741 scontrol = (scontrol & 0x0f0) | 0x302; 2754 scontrol = (scontrol & 0x0f0) | 0x304;
2742 2755
2743 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol))) 2756 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol)))
2744 return rc; 2757 return rc;
@@ -2761,7 +2774,7 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2761 msleep(1); 2774 msleep(1);
2762 2775
2763 /* bring phy back */ 2776 /* bring phy back */
2764 sata_phy_resume(ap, sata_deb_timing_eh); 2777 sata_phy_resume(ap, timing);
2765 2778
2766 /* TODO: phy layer with polling, timeouts, etc. */ 2779 /* TODO: phy layer with polling, timeouts, etc. */
2767 if (ata_port_offline(ap)) { 2780 if (ata_port_offline(ap)) {
@@ -4285,7 +4298,7 @@ static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
4285 unsigned int i; 4298 unsigned int i;
4286 4299
4287 /* no command while frozen */ 4300 /* no command while frozen */
4288 if (unlikely(ap->flags & ATA_FLAG_FROZEN)) 4301 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
4289 return NULL; 4302 return NULL;
4290 4303
4291 /* the last tag is reserved for internal command. */ 4304 /* the last tag is reserved for internal command. */
@@ -4407,7 +4420,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
4407 * taken care of. 4420 * taken care of.
4408 */ 4421 */
4409 if (ap->ops->error_handler) { 4422 if (ap->ops->error_handler) {
4410 WARN_ON(ap->flags & ATA_FLAG_FROZEN); 4423 WARN_ON(ap->pflags & ATA_PFLAG_FROZEN);
4411 4424
4412 if (unlikely(qc->err_mask)) 4425 if (unlikely(qc->err_mask))
4413 qc->flags |= ATA_QCFLAG_FAILED; 4426 qc->flags |= ATA_QCFLAG_FAILED;
@@ -5001,86 +5014,120 @@ int ata_flush_cache(struct ata_device *dev)
5001 return 0; 5014 return 0;
5002} 5015}
5003 5016
5004static int ata_standby_drive(struct ata_device *dev) 5017static int ata_host_set_request_pm(struct ata_host_set *host_set,
5018 pm_message_t mesg, unsigned int action,
5019 unsigned int ehi_flags, int wait)
5005{ 5020{
5006 unsigned int err_mask; 5021 unsigned long flags;
5022 int i, rc;
5007 5023
5008 err_mask = ata_do_simple_cmd(dev, ATA_CMD_STANDBYNOW1); 5024 for (i = 0; i < host_set->n_ports; i++) {
5009 if (err_mask) { 5025 struct ata_port *ap = host_set->ports[i];
5010 ata_dev_printk(dev, KERN_ERR, "failed to standby drive "
5011 "(err_mask=0x%x)\n", err_mask);
5012 return -EIO;
5013 }
5014 5026
5015 return 0; 5027 /* Previous resume operation might still be in
5016} 5028 * progress. Wait for PM_PENDING to clear.
5029 */
5030 if (ap->pflags & ATA_PFLAG_PM_PENDING) {
5031 ata_port_wait_eh(ap);
5032 WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING);
5033 }
5017 5034
5018static int ata_start_drive(struct ata_device *dev) 5035 /* request PM ops to EH */
5019{ 5036 spin_lock_irqsave(ap->lock, flags);
5020 unsigned int err_mask;
5021 5037
5022 err_mask = ata_do_simple_cmd(dev, ATA_CMD_IDLEIMMEDIATE); 5038 ap->pm_mesg = mesg;
5023 if (err_mask) { 5039 if (wait) {
5024 ata_dev_printk(dev, KERN_ERR, "failed to start drive " 5040 rc = 0;
5025 "(err_mask=0x%x)\n", err_mask); 5041 ap->pm_result = &rc;
5026 return -EIO; 5042 }
5043
5044 ap->pflags |= ATA_PFLAG_PM_PENDING;
5045 ap->eh_info.action |= action;
5046 ap->eh_info.flags |= ehi_flags;
5047
5048 ata_port_schedule_eh(ap);
5049
5050 spin_unlock_irqrestore(ap->lock, flags);
5051
5052 /* wait and check result */
5053 if (wait) {
5054 ata_port_wait_eh(ap);
5055 WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING);
5056 if (rc)
5057 return rc;
5058 }
5027 } 5059 }
5028 5060
5029 return 0; 5061 return 0;
5030} 5062}
5031 5063
5032/** 5064/**
5033 * ata_device_resume - wakeup a previously suspended devices 5065 * ata_host_set_suspend - suspend host_set
5034 * @dev: the device to resume 5066 * @host_set: host_set to suspend
5067 * @mesg: PM message
5035 * 5068 *
5036 * Kick the drive back into action, by sending it an idle immediate 5069 * Suspend @host_set. Actual operation is performed by EH. This
5037 * command and making sure its transfer mode matches between drive 5070 * function requests EH to perform PM operations and waits for EH
5038 * and host. 5071 * to finish.
5072 *
5073 * LOCKING:
5074 * Kernel thread context (may sleep).
5039 * 5075 *
5076 * RETURNS:
5077 * 0 on success, -errno on failure.
5040 */ 5078 */
5041int ata_device_resume(struct ata_device *dev) 5079int ata_host_set_suspend(struct ata_host_set *host_set, pm_message_t mesg)
5042{ 5080{
5043 struct ata_port *ap = dev->ap; 5081 int i, j, rc;
5044 5082
5045 if (ap->flags & ATA_FLAG_SUSPENDED) { 5083 rc = ata_host_set_request_pm(host_set, mesg, 0, ATA_EHI_QUIET, 1);
5046 struct ata_device *failed_dev; 5084 if (rc)
5085 goto fail;
5047 5086
5048 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 5087 /* EH is quiescent now. Fail if we have any ready device.
5049 ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 200000); 5088 * This happens if hotplug occurs between completion of device
5089 * suspension and here.
5090 */
5091 for (i = 0; i < host_set->n_ports; i++) {
5092 struct ata_port *ap = host_set->ports[i];
5093
5094 for (j = 0; j < ATA_MAX_DEVICES; j++) {
5095 struct ata_device *dev = &ap->device[j];
5050 5096
5051 ap->flags &= ~ATA_FLAG_SUSPENDED; 5097 if (ata_dev_ready(dev)) {
5052 while (ata_set_mode(ap, &failed_dev)) 5098 ata_port_printk(ap, KERN_WARNING,
5053 ata_dev_disable(failed_dev); 5099 "suspend failed, device %d "
5100 "still active\n", dev->devno);
5101 rc = -EBUSY;
5102 goto fail;
5103 }
5104 }
5054 } 5105 }
5055 if (!ata_dev_enabled(dev))
5056 return 0;
5057 if (dev->class == ATA_DEV_ATA)
5058 ata_start_drive(dev);
5059 5106
5107 host_set->dev->power.power_state = mesg;
5060 return 0; 5108 return 0;
5109
5110 fail:
5111 ata_host_set_resume(host_set);
5112 return rc;
5061} 5113}
5062 5114
5063/** 5115/**
5064 * ata_device_suspend - prepare a device for suspend 5116 * ata_host_set_resume - resume host_set
5065 * @dev: the device to suspend 5117 * @host_set: host_set to resume
5066 * @state: target power management state
5067 * 5118 *
5068 * Flush the cache on the drive, if appropriate, then issue a 5119 * Resume @host_set. Actual operation is performed by EH. This
5069 * standbynow command. 5120 * function requests EH to perform PM operations and returns.
5121 * Note that all resume operations are performed parallely.
5122 *
5123 * LOCKING:
5124 * Kernel thread context (may sleep).
5070 */ 5125 */
5071int ata_device_suspend(struct ata_device *dev, pm_message_t state) 5126void ata_host_set_resume(struct ata_host_set *host_set)
5072{ 5127{
5073 struct ata_port *ap = dev->ap; 5128 ata_host_set_request_pm(host_set, PMSG_ON, ATA_EH_SOFTRESET,
5074 5129 ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0);
5075 if (!ata_dev_enabled(dev)) 5130 host_set->dev->power.power_state = PMSG_ON;
5076 return 0;
5077 if (dev->class == ATA_DEV_ATA)
5078 ata_flush_cache(dev);
5079
5080 if (state.event != PM_EVENT_FREEZE)
5081 ata_standby_drive(dev);
5082 ap->flags |= ATA_FLAG_SUSPENDED;
5083 return 0;
5084} 5131}
5085 5132
5086/** 5133/**
@@ -5143,28 +5190,6 @@ void ata_host_stop (struct ata_host_set *host_set)
5143 iounmap(host_set->mmio_base); 5190 iounmap(host_set->mmio_base);
5144} 5191}
5145 5192
5146
5147/**
5148 * ata_host_remove - Unregister SCSI host structure with upper layers
5149 * @ap: Port to unregister
5150 * @do_unregister: 1 if we fully unregister, 0 to just stop the port
5151 *
5152 * LOCKING:
5153 * Inherited from caller.
5154 */
5155
5156static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister)
5157{
5158 struct Scsi_Host *sh = ap->host;
5159
5160 DPRINTK("ENTER\n");
5161
5162 if (do_unregister)
5163 scsi_remove_host(sh);
5164
5165 ap->ops->port_stop(ap);
5166}
5167
5168/** 5193/**
5169 * ata_dev_init - Initialize an ata_device structure 5194 * ata_dev_init - Initialize an ata_device structure
5170 * @dev: Device structure to initialize 5195 * @dev: Device structure to initialize
@@ -5440,6 +5465,7 @@ int ata_device_add(const struct ata_probe_ent *ent)
5440 } 5465 }
5441 5466
5442 if (ap->ops->error_handler) { 5467 if (ap->ops->error_handler) {
5468 struct ata_eh_info *ehi = &ap->eh_info;
5443 unsigned long flags; 5469 unsigned long flags;
5444 5470
5445 ata_port_probe(ap); 5471 ata_port_probe(ap);
@@ -5447,10 +5473,11 @@ int ata_device_add(const struct ata_probe_ent *ent)
5447 /* kick EH for boot probing */ 5473 /* kick EH for boot probing */
5448 spin_lock_irqsave(ap->lock, flags); 5474 spin_lock_irqsave(ap->lock, flags);
5449 5475
5450 ap->eh_info.probe_mask = (1 << ATA_MAX_DEVICES) - 1; 5476 ehi->probe_mask = (1 << ATA_MAX_DEVICES) - 1;
5451 ap->eh_info.action |= ATA_EH_SOFTRESET; 5477 ehi->action |= ATA_EH_SOFTRESET;
5478 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
5452 5479
5453 ap->flags |= ATA_FLAG_LOADING; 5480 ap->pflags |= ATA_PFLAG_LOADING;
5454 ata_port_schedule_eh(ap); 5481 ata_port_schedule_eh(ap);
5455 5482
5456 spin_unlock_irqrestore(ap->lock, flags); 5483 spin_unlock_irqrestore(ap->lock, flags);
@@ -5488,8 +5515,11 @@ int ata_device_add(const struct ata_probe_ent *ent)
5488 5515
5489err_out: 5516err_out:
5490 for (i = 0; i < count; i++) { 5517 for (i = 0; i < count; i++) {
5491 ata_host_remove(host_set->ports[i], 1); 5518 struct ata_port *ap = host_set->ports[i];
5492 scsi_host_put(host_set->ports[i]->host); 5519 if (ap) {
5520 ap->ops->port_stop(ap);
5521 scsi_host_put(ap->host);
5522 }
5493 } 5523 }
5494err_free_ret: 5524err_free_ret:
5495 kfree(host_set); 5525 kfree(host_set);
@@ -5514,11 +5544,11 @@ void ata_port_detach(struct ata_port *ap)
5514 int i; 5544 int i;
5515 5545
5516 if (!ap->ops->error_handler) 5546 if (!ap->ops->error_handler)
5517 return; 5547 goto skip_eh;
5518 5548
5519 /* tell EH we're leaving & flush EH */ 5549 /* tell EH we're leaving & flush EH */
5520 spin_lock_irqsave(ap->lock, flags); 5550 spin_lock_irqsave(ap->lock, flags);
5521 ap->flags |= ATA_FLAG_UNLOADING; 5551 ap->pflags |= ATA_PFLAG_UNLOADING;
5522 spin_unlock_irqrestore(ap->lock, flags); 5552 spin_unlock_irqrestore(ap->lock, flags);
5523 5553
5524 ata_port_wait_eh(ap); 5554 ata_port_wait_eh(ap);
@@ -5550,6 +5580,7 @@ void ata_port_detach(struct ata_port *ap)
5550 cancel_delayed_work(&ap->hotplug_task); 5580 cancel_delayed_work(&ap->hotplug_task);
5551 flush_workqueue(ata_aux_wq); 5581 flush_workqueue(ata_aux_wq);
5552 5582
5583 skip_eh:
5553 /* remove the associated SCSI host */ 5584 /* remove the associated SCSI host */
5554 scsi_remove_host(ap->host); 5585 scsi_remove_host(ap->host);
5555} 5586}
@@ -5618,7 +5649,7 @@ int ata_scsi_release(struct Scsi_Host *host)
5618 DPRINTK("ENTER\n"); 5649 DPRINTK("ENTER\n");
5619 5650
5620 ap->ops->port_disable(ap); 5651 ap->ops->port_disable(ap);
5621 ata_host_remove(ap, 0); 5652 ap->ops->port_stop(ap);
5622 5653
5623 DPRINTK("EXIT\n"); 5654 DPRINTK("EXIT\n");
5624 return 1; 5655 return 1;
@@ -5723,20 +5754,55 @@ int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits)
5723 return (tmp == bits->val) ? 1 : 0; 5754 return (tmp == bits->val) ? 1 : 0;
5724} 5755}
5725 5756
5726int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state) 5757void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t state)
5727{ 5758{
5728 pci_save_state(pdev); 5759 pci_save_state(pdev);
5729 pci_disable_device(pdev); 5760
5730 pci_set_power_state(pdev, PCI_D3hot); 5761 if (state.event == PM_EVENT_SUSPEND) {
5731 return 0; 5762 pci_disable_device(pdev);
5763 pci_set_power_state(pdev, PCI_D3hot);
5764 }
5732} 5765}
5733 5766
5734int ata_pci_device_resume(struct pci_dev *pdev) 5767void ata_pci_device_do_resume(struct pci_dev *pdev)
5735{ 5768{
5736 pci_set_power_state(pdev, PCI_D0); 5769 pci_set_power_state(pdev, PCI_D0);
5737 pci_restore_state(pdev); 5770 pci_restore_state(pdev);
5738 pci_enable_device(pdev); 5771 pci_enable_device(pdev);
5739 pci_set_master(pdev); 5772 pci_set_master(pdev);
5773}
5774
5775int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state)
5776{
5777 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
5778 int rc = 0;
5779
5780 rc = ata_host_set_suspend(host_set, state);
5781 if (rc)
5782 return rc;
5783
5784 if (host_set->next) {
5785 rc = ata_host_set_suspend(host_set->next, state);
5786 if (rc) {
5787 ata_host_set_resume(host_set);
5788 return rc;
5789 }
5790 }
5791
5792 ata_pci_device_do_suspend(pdev, state);
5793
5794 return 0;
5795}
5796
5797int ata_pci_device_resume(struct pci_dev *pdev)
5798{
5799 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
5800
5801 ata_pci_device_do_resume(pdev);
5802 ata_host_set_resume(host_set);
5803 if (host_set->next)
5804 ata_host_set_resume(host_set->next);
5805
5740 return 0; 5806 return 0;
5741} 5807}
5742#endif /* CONFIG_PCI */ 5808#endif /* CONFIG_PCI */
@@ -5842,9 +5908,9 @@ u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
5842 * Do not depend on ABI/API stability. 5908 * Do not depend on ABI/API stability.
5843 */ 5909 */
5844 5910
5845EXPORT_SYMBOL_GPL(sata_deb_timing_boot); 5911EXPORT_SYMBOL_GPL(sata_deb_timing_normal);
5846EXPORT_SYMBOL_GPL(sata_deb_timing_eh); 5912EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug);
5847EXPORT_SYMBOL_GPL(sata_deb_timing_before_fsrst); 5913EXPORT_SYMBOL_GPL(sata_deb_timing_long);
5848EXPORT_SYMBOL_GPL(ata_std_bios_param); 5914EXPORT_SYMBOL_GPL(ata_std_bios_param);
5849EXPORT_SYMBOL_GPL(ata_std_ports); 5915EXPORT_SYMBOL_GPL(ata_std_ports);
5850EXPORT_SYMBOL_GPL(ata_device_add); 5916EXPORT_SYMBOL_GPL(ata_device_add);
@@ -5916,6 +5982,8 @@ EXPORT_SYMBOL_GPL(sata_scr_write);
5916EXPORT_SYMBOL_GPL(sata_scr_write_flush); 5982EXPORT_SYMBOL_GPL(sata_scr_write_flush);
5917EXPORT_SYMBOL_GPL(ata_port_online); 5983EXPORT_SYMBOL_GPL(ata_port_online);
5918EXPORT_SYMBOL_GPL(ata_port_offline); 5984EXPORT_SYMBOL_GPL(ata_port_offline);
5985EXPORT_SYMBOL_GPL(ata_host_set_suspend);
5986EXPORT_SYMBOL_GPL(ata_host_set_resume);
5919EXPORT_SYMBOL_GPL(ata_id_string); 5987EXPORT_SYMBOL_GPL(ata_id_string);
5920EXPORT_SYMBOL_GPL(ata_id_c_string); 5988EXPORT_SYMBOL_GPL(ata_id_c_string);
5921EXPORT_SYMBOL_GPL(ata_scsi_simulate); 5989EXPORT_SYMBOL_GPL(ata_scsi_simulate);
@@ -5930,14 +5998,14 @@ EXPORT_SYMBOL_GPL(ata_pci_host_stop);
5930EXPORT_SYMBOL_GPL(ata_pci_init_native_mode); 5998EXPORT_SYMBOL_GPL(ata_pci_init_native_mode);
5931EXPORT_SYMBOL_GPL(ata_pci_init_one); 5999EXPORT_SYMBOL_GPL(ata_pci_init_one);
5932EXPORT_SYMBOL_GPL(ata_pci_remove_one); 6000EXPORT_SYMBOL_GPL(ata_pci_remove_one);
6001EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend);
6002EXPORT_SYMBOL_GPL(ata_pci_device_do_resume);
5933EXPORT_SYMBOL_GPL(ata_pci_device_suspend); 6003EXPORT_SYMBOL_GPL(ata_pci_device_suspend);
5934EXPORT_SYMBOL_GPL(ata_pci_device_resume); 6004EXPORT_SYMBOL_GPL(ata_pci_device_resume);
5935EXPORT_SYMBOL_GPL(ata_pci_default_filter); 6005EXPORT_SYMBOL_GPL(ata_pci_default_filter);
5936EXPORT_SYMBOL_GPL(ata_pci_clear_simplex); 6006EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
5937#endif /* CONFIG_PCI */ 6007#endif /* CONFIG_PCI */
5938 6008
5939EXPORT_SYMBOL_GPL(ata_device_suspend);
5940EXPORT_SYMBOL_GPL(ata_device_resume);
5941EXPORT_SYMBOL_GPL(ata_scsi_device_suspend); 6009EXPORT_SYMBOL_GPL(ata_scsi_device_suspend);
5942EXPORT_SYMBOL_GPL(ata_scsi_device_resume); 6010EXPORT_SYMBOL_GPL(ata_scsi_device_resume);
5943 6011
diff --git a/drivers/scsi/libata-eh.c b/drivers/scsi/libata-eh.c
index bf5a72aca8a4..29f59345305d 100644
--- a/drivers/scsi/libata-eh.c
+++ b/drivers/scsi/libata-eh.c
@@ -47,6 +47,8 @@
47 47
48static void __ata_port_freeze(struct ata_port *ap); 48static void __ata_port_freeze(struct ata_port *ap);
49static void ata_eh_finish(struct ata_port *ap); 49static void ata_eh_finish(struct ata_port *ap);
50static void ata_eh_handle_port_suspend(struct ata_port *ap);
51static void ata_eh_handle_port_resume(struct ata_port *ap);
50 52
51static void ata_ering_record(struct ata_ering *ering, int is_io, 53static void ata_ering_record(struct ata_ering *ering, int is_io,
52 unsigned int err_mask) 54 unsigned int err_mask)
@@ -190,7 +192,6 @@ enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
190void ata_scsi_error(struct Scsi_Host *host) 192void ata_scsi_error(struct Scsi_Host *host)
191{ 193{
192 struct ata_port *ap = ata_shost_to_port(host); 194 struct ata_port *ap = ata_shost_to_port(host);
193 spinlock_t *ap_lock = ap->lock;
194 int i, repeat_cnt = ATA_EH_MAX_REPEAT; 195 int i, repeat_cnt = ATA_EH_MAX_REPEAT;
195 unsigned long flags; 196 unsigned long flags;
196 197
@@ -217,7 +218,7 @@ void ata_scsi_error(struct Scsi_Host *host)
217 struct scsi_cmnd *scmd, *tmp; 218 struct scsi_cmnd *scmd, *tmp;
218 int nr_timedout = 0; 219 int nr_timedout = 0;
219 220
220 spin_lock_irqsave(ap_lock, flags); 221 spin_lock_irqsave(ap->lock, flags);
221 222
222 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) { 223 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) {
223 struct ata_queued_cmd *qc; 224 struct ata_queued_cmd *qc;
@@ -256,43 +257,49 @@ void ata_scsi_error(struct Scsi_Host *host)
256 if (nr_timedout) 257 if (nr_timedout)
257 __ata_port_freeze(ap); 258 __ata_port_freeze(ap);
258 259
259 spin_unlock_irqrestore(ap_lock, flags); 260 spin_unlock_irqrestore(ap->lock, flags);
260 } else 261 } else
261 spin_unlock_wait(ap_lock); 262 spin_unlock_wait(ap->lock);
262 263
263 repeat: 264 repeat:
264 /* invoke error handler */ 265 /* invoke error handler */
265 if (ap->ops->error_handler) { 266 if (ap->ops->error_handler) {
267 /* process port resume request */
268 ata_eh_handle_port_resume(ap);
269
266 /* fetch & clear EH info */ 270 /* fetch & clear EH info */
267 spin_lock_irqsave(ap_lock, flags); 271 spin_lock_irqsave(ap->lock, flags);
268 272
269 memset(&ap->eh_context, 0, sizeof(ap->eh_context)); 273 memset(&ap->eh_context, 0, sizeof(ap->eh_context));
270 ap->eh_context.i = ap->eh_info; 274 ap->eh_context.i = ap->eh_info;
271 memset(&ap->eh_info, 0, sizeof(ap->eh_info)); 275 memset(&ap->eh_info, 0, sizeof(ap->eh_info));
272 276
273 ap->flags |= ATA_FLAG_EH_IN_PROGRESS; 277 ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS;
274 ap->flags &= ~ATA_FLAG_EH_PENDING; 278 ap->pflags &= ~ATA_PFLAG_EH_PENDING;
275 279
276 spin_unlock_irqrestore(ap_lock, flags); 280 spin_unlock_irqrestore(ap->lock, flags);
277 281
278 /* invoke EH. if unloading, just finish failed qcs */ 282 /* invoke EH, skip if unloading or suspended */
279 if (!(ap->flags & ATA_FLAG_UNLOADING)) 283 if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED)))
280 ap->ops->error_handler(ap); 284 ap->ops->error_handler(ap);
281 else 285 else
282 ata_eh_finish(ap); 286 ata_eh_finish(ap);
283 287
288 /* process port suspend request */
289 ata_eh_handle_port_suspend(ap);
290
284 /* Exception might have happend after ->error_handler 291 /* Exception might have happend after ->error_handler
285 * recovered the port but before this point. Repeat 292 * recovered the port but before this point. Repeat
286 * EH in such case. 293 * EH in such case.
287 */ 294 */
288 spin_lock_irqsave(ap_lock, flags); 295 spin_lock_irqsave(ap->lock, flags);
289 296
290 if (ap->flags & ATA_FLAG_EH_PENDING) { 297 if (ap->pflags & ATA_PFLAG_EH_PENDING) {
291 if (--repeat_cnt) { 298 if (--repeat_cnt) {
292 ata_port_printk(ap, KERN_INFO, 299 ata_port_printk(ap, KERN_INFO,
293 "EH pending after completion, " 300 "EH pending after completion, "
294 "repeating EH (cnt=%d)\n", repeat_cnt); 301 "repeating EH (cnt=%d)\n", repeat_cnt);
295 spin_unlock_irqrestore(ap_lock, flags); 302 spin_unlock_irqrestore(ap->lock, flags);
296 goto repeat; 303 goto repeat;
297 } 304 }
298 ata_port_printk(ap, KERN_ERR, "EH pending after %d " 305 ata_port_printk(ap, KERN_ERR, "EH pending after %d "
@@ -302,14 +309,14 @@ void ata_scsi_error(struct Scsi_Host *host)
302 /* this run is complete, make sure EH info is clear */ 309 /* this run is complete, make sure EH info is clear */
303 memset(&ap->eh_info, 0, sizeof(ap->eh_info)); 310 memset(&ap->eh_info, 0, sizeof(ap->eh_info));
304 311
305 /* Clear host_eh_scheduled while holding ap_lock such 312 /* Clear host_eh_scheduled while holding ap->lock such
306 * that if exception occurs after this point but 313 * that if exception occurs after this point but
307 * before EH completion, SCSI midlayer will 314 * before EH completion, SCSI midlayer will
308 * re-initiate EH. 315 * re-initiate EH.
309 */ 316 */
310 host->host_eh_scheduled = 0; 317 host->host_eh_scheduled = 0;
311 318
312 spin_unlock_irqrestore(ap_lock, flags); 319 spin_unlock_irqrestore(ap->lock, flags);
313 } else { 320 } else {
314 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL); 321 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
315 ap->ops->eng_timeout(ap); 322 ap->ops->eng_timeout(ap);
@@ -321,24 +328,23 @@ void ata_scsi_error(struct Scsi_Host *host)
321 scsi_eh_flush_done_q(&ap->eh_done_q); 328 scsi_eh_flush_done_q(&ap->eh_done_q);
322 329
323 /* clean up */ 330 /* clean up */
324 spin_lock_irqsave(ap_lock, flags); 331 spin_lock_irqsave(ap->lock, flags);
325 332
326 if (ap->flags & ATA_FLAG_LOADING) { 333 if (ap->pflags & ATA_PFLAG_LOADING)
327 ap->flags &= ~ATA_FLAG_LOADING; 334 ap->pflags &= ~ATA_PFLAG_LOADING;
328 } else { 335 else if (ap->pflags & ATA_PFLAG_SCSI_HOTPLUG)
329 if (ap->flags & ATA_FLAG_SCSI_HOTPLUG) 336 queue_work(ata_aux_wq, &ap->hotplug_task);
330 queue_work(ata_aux_wq, &ap->hotplug_task);
331 if (ap->flags & ATA_FLAG_RECOVERED)
332 ata_port_printk(ap, KERN_INFO, "EH complete\n");
333 }
334 337
335 ap->flags &= ~(ATA_FLAG_SCSI_HOTPLUG | ATA_FLAG_RECOVERED); 338 if (ap->pflags & ATA_PFLAG_RECOVERED)
339 ata_port_printk(ap, KERN_INFO, "EH complete\n");
340
341 ap->pflags &= ~(ATA_PFLAG_SCSI_HOTPLUG | ATA_PFLAG_RECOVERED);
336 342
337 /* tell wait_eh that we're done */ 343 /* tell wait_eh that we're done */
338 ap->flags &= ~ATA_FLAG_EH_IN_PROGRESS; 344 ap->pflags &= ~ATA_PFLAG_EH_IN_PROGRESS;
339 wake_up_all(&ap->eh_wait_q); 345 wake_up_all(&ap->eh_wait_q);
340 346
341 spin_unlock_irqrestore(ap_lock, flags); 347 spin_unlock_irqrestore(ap->lock, flags);
342 348
343 DPRINTK("EXIT\n"); 349 DPRINTK("EXIT\n");
344} 350}
@@ -360,7 +366,7 @@ void ata_port_wait_eh(struct ata_port *ap)
360 retry: 366 retry:
361 spin_lock_irqsave(ap->lock, flags); 367 spin_lock_irqsave(ap->lock, flags);
362 368
363 while (ap->flags & (ATA_FLAG_EH_PENDING | ATA_FLAG_EH_IN_PROGRESS)) { 369 while (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) {
364 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE); 370 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE);
365 spin_unlock_irqrestore(ap->lock, flags); 371 spin_unlock_irqrestore(ap->lock, flags);
366 schedule(); 372 schedule();
@@ -489,7 +495,7 @@ void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
489 WARN_ON(!ap->ops->error_handler); 495 WARN_ON(!ap->ops->error_handler);
490 496
491 qc->flags |= ATA_QCFLAG_FAILED; 497 qc->flags |= ATA_QCFLAG_FAILED;
492 qc->ap->flags |= ATA_FLAG_EH_PENDING; 498 qc->ap->pflags |= ATA_PFLAG_EH_PENDING;
493 499
494 /* The following will fail if timeout has already expired. 500 /* The following will fail if timeout has already expired.
495 * ata_scsi_error() takes care of such scmds on EH entry. 501 * ata_scsi_error() takes care of such scmds on EH entry.
@@ -513,7 +519,7 @@ void ata_port_schedule_eh(struct ata_port *ap)
513{ 519{
514 WARN_ON(!ap->ops->error_handler); 520 WARN_ON(!ap->ops->error_handler);
515 521
516 ap->flags |= ATA_FLAG_EH_PENDING; 522 ap->pflags |= ATA_PFLAG_EH_PENDING;
517 scsi_schedule_eh(ap->host); 523 scsi_schedule_eh(ap->host);
518 524
519 DPRINTK("port EH scheduled\n"); 525 DPRINTK("port EH scheduled\n");
@@ -578,7 +584,7 @@ static void __ata_port_freeze(struct ata_port *ap)
578 if (ap->ops->freeze) 584 if (ap->ops->freeze)
579 ap->ops->freeze(ap); 585 ap->ops->freeze(ap);
580 586
581 ap->flags |= ATA_FLAG_FROZEN; 587 ap->pflags |= ATA_PFLAG_FROZEN;
582 588
583 DPRINTK("ata%u port frozen\n", ap->id); 589 DPRINTK("ata%u port frozen\n", ap->id);
584} 590}
@@ -646,7 +652,7 @@ void ata_eh_thaw_port(struct ata_port *ap)
646 652
647 spin_lock_irqsave(ap->lock, flags); 653 spin_lock_irqsave(ap->lock, flags);
648 654
649 ap->flags &= ~ATA_FLAG_FROZEN; 655 ap->pflags &= ~ATA_PFLAG_FROZEN;
650 656
651 if (ap->ops->thaw) 657 if (ap->ops->thaw)
652 ap->ops->thaw(ap); 658 ap->ops->thaw(ap);
@@ -731,7 +737,7 @@ static void ata_eh_detach_dev(struct ata_device *dev)
731 737
732 if (ata_scsi_offline_dev(dev)) { 738 if (ata_scsi_offline_dev(dev)) {
733 dev->flags |= ATA_DFLAG_DETACHED; 739 dev->flags |= ATA_DFLAG_DETACHED;
734 ap->flags |= ATA_FLAG_SCSI_HOTPLUG; 740 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
735 } 741 }
736 742
737 /* clear per-dev EH actions */ 743 /* clear per-dev EH actions */
@@ -758,10 +764,29 @@ static void ata_eh_about_to_do(struct ata_port *ap, struct ata_device *dev,
758 unsigned int action) 764 unsigned int action)
759{ 765{
760 unsigned long flags; 766 unsigned long flags;
767 struct ata_eh_info *ehi = &ap->eh_info;
768 struct ata_eh_context *ehc = &ap->eh_context;
761 769
762 spin_lock_irqsave(ap->lock, flags); 770 spin_lock_irqsave(ap->lock, flags);
763 ata_eh_clear_action(dev, &ap->eh_info, action); 771
764 ap->flags |= ATA_FLAG_RECOVERED; 772 /* Reset is represented by combination of actions and EHI
773 * flags. Suck in all related bits before clearing eh_info to
774 * avoid losing requested action.
775 */
776 if (action & ATA_EH_RESET_MASK) {
777 ehc->i.action |= ehi->action & ATA_EH_RESET_MASK;
778 ehc->i.flags |= ehi->flags & ATA_EHI_RESET_MODIFIER_MASK;
779
780 /* make sure all reset actions are cleared & clear EHI flags */
781 action |= ATA_EH_RESET_MASK;
782 ehi->flags &= ~ATA_EHI_RESET_MODIFIER_MASK;
783 }
784
785 ata_eh_clear_action(dev, ehi, action);
786
787 if (!(ehc->i.flags & ATA_EHI_QUIET))
788 ap->pflags |= ATA_PFLAG_RECOVERED;
789
765 spin_unlock_irqrestore(ap->lock, flags); 790 spin_unlock_irqrestore(ap->lock, flags);
766} 791}
767 792
@@ -780,6 +805,12 @@ static void ata_eh_about_to_do(struct ata_port *ap, struct ata_device *dev,
780static void ata_eh_done(struct ata_port *ap, struct ata_device *dev, 805static void ata_eh_done(struct ata_port *ap, struct ata_device *dev,
781 unsigned int action) 806 unsigned int action)
782{ 807{
808 /* if reset is complete, clear all reset actions & reset modifier */
809 if (action & ATA_EH_RESET_MASK) {
810 action |= ATA_EH_RESET_MASK;
811 ap->eh_context.i.flags &= ~ATA_EHI_RESET_MODIFIER_MASK;
812 }
813
783 ata_eh_clear_action(dev, &ap->eh_context.i, action); 814 ata_eh_clear_action(dev, &ap->eh_context.i, action);
784} 815}
785 816
@@ -1027,7 +1058,7 @@ static void ata_eh_analyze_ncq_error(struct ata_port *ap)
1027 int tag, rc; 1058 int tag, rc;
1028 1059
1029 /* if frozen, we can't do much */ 1060 /* if frozen, we can't do much */
1030 if (ap->flags & ATA_FLAG_FROZEN) 1061 if (ap->pflags & ATA_PFLAG_FROZEN)
1031 return; 1062 return;
1032 1063
1033 /* is it NCQ device error? */ 1064 /* is it NCQ device error? */
@@ -1266,8 +1297,6 @@ static int ata_eh_speed_down(struct ata_device *dev, int is_io,
1266static void ata_eh_autopsy(struct ata_port *ap) 1297static void ata_eh_autopsy(struct ata_port *ap)
1267{ 1298{
1268 struct ata_eh_context *ehc = &ap->eh_context; 1299 struct ata_eh_context *ehc = &ap->eh_context;
1269 unsigned int action = ehc->i.action;
1270 struct ata_device *failed_dev = NULL;
1271 unsigned int all_err_mask = 0; 1300 unsigned int all_err_mask = 0;
1272 int tag, is_io = 0; 1301 int tag, is_io = 0;
1273 u32 serror; 1302 u32 serror;
@@ -1275,13 +1304,16 @@ static void ata_eh_autopsy(struct ata_port *ap)
1275 1304
1276 DPRINTK("ENTER\n"); 1305 DPRINTK("ENTER\n");
1277 1306
1307 if (ehc->i.flags & ATA_EHI_NO_AUTOPSY)
1308 return;
1309
1278 /* obtain and analyze SError */ 1310 /* obtain and analyze SError */
1279 rc = sata_scr_read(ap, SCR_ERROR, &serror); 1311 rc = sata_scr_read(ap, SCR_ERROR, &serror);
1280 if (rc == 0) { 1312 if (rc == 0) {
1281 ehc->i.serror |= serror; 1313 ehc->i.serror |= serror;
1282 ata_eh_analyze_serror(ap); 1314 ata_eh_analyze_serror(ap);
1283 } else if (rc != -EOPNOTSUPP) 1315 } else if (rc != -EOPNOTSUPP)
1284 action |= ATA_EH_HARDRESET; 1316 ehc->i.action |= ATA_EH_HARDRESET;
1285 1317
1286 /* analyze NCQ failure */ 1318 /* analyze NCQ failure */
1287 ata_eh_analyze_ncq_error(ap); 1319 ata_eh_analyze_ncq_error(ap);
@@ -1302,7 +1334,7 @@ static void ata_eh_autopsy(struct ata_port *ap)
1302 qc->err_mask |= ehc->i.err_mask; 1334 qc->err_mask |= ehc->i.err_mask;
1303 1335
1304 /* analyze TF */ 1336 /* analyze TF */
1305 action |= ata_eh_analyze_tf(qc, &qc->result_tf); 1337 ehc->i.action |= ata_eh_analyze_tf(qc, &qc->result_tf);
1306 1338
1307 /* DEV errors are probably spurious in case of ATA_BUS error */ 1339 /* DEV errors are probably spurious in case of ATA_BUS error */
1308 if (qc->err_mask & AC_ERR_ATA_BUS) 1340 if (qc->err_mask & AC_ERR_ATA_BUS)
@@ -1316,38 +1348,35 @@ static void ata_eh_autopsy(struct ata_port *ap)
1316 /* SENSE_VALID trumps dev/unknown error and revalidation */ 1348 /* SENSE_VALID trumps dev/unknown error and revalidation */
1317 if (qc->flags & ATA_QCFLAG_SENSE_VALID) { 1349 if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
1318 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER); 1350 qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER);
1319 action &= ~ATA_EH_REVALIDATE; 1351 ehc->i.action &= ~ATA_EH_REVALIDATE;
1320 } 1352 }
1321 1353
1322 /* accumulate error info */ 1354 /* accumulate error info */
1323 failed_dev = qc->dev; 1355 ehc->i.dev = qc->dev;
1324 all_err_mask |= qc->err_mask; 1356 all_err_mask |= qc->err_mask;
1325 if (qc->flags & ATA_QCFLAG_IO) 1357 if (qc->flags & ATA_QCFLAG_IO)
1326 is_io = 1; 1358 is_io = 1;
1327 } 1359 }
1328 1360
1329 /* enforce default EH actions */ 1361 /* enforce default EH actions */
1330 if (ap->flags & ATA_FLAG_FROZEN || 1362 if (ap->pflags & ATA_PFLAG_FROZEN ||
1331 all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT)) 1363 all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT))
1332 action |= ATA_EH_SOFTRESET; 1364 ehc->i.action |= ATA_EH_SOFTRESET;
1333 else if (all_err_mask) 1365 else if (all_err_mask)
1334 action |= ATA_EH_REVALIDATE; 1366 ehc->i.action |= ATA_EH_REVALIDATE;
1335 1367
1336 /* if we have offending qcs and the associated failed device */ 1368 /* if we have offending qcs and the associated failed device */
1337 if (failed_dev) { 1369 if (ehc->i.dev) {
1338 /* speed down */ 1370 /* speed down */
1339 action |= ata_eh_speed_down(failed_dev, is_io, all_err_mask); 1371 ehc->i.action |= ata_eh_speed_down(ehc->i.dev, is_io,
1372 all_err_mask);
1340 1373
1341 /* perform per-dev EH action only on the offending device */ 1374 /* perform per-dev EH action only on the offending device */
1342 ehc->i.dev_action[failed_dev->devno] |= 1375 ehc->i.dev_action[ehc->i.dev->devno] |=
1343 action & ATA_EH_PERDEV_MASK; 1376 ehc->i.action & ATA_EH_PERDEV_MASK;
1344 action &= ~ATA_EH_PERDEV_MASK; 1377 ehc->i.action &= ~ATA_EH_PERDEV_MASK;
1345 } 1378 }
1346 1379
1347 /* record autopsy result */
1348 ehc->i.dev = failed_dev;
1349 ehc->i.action = action;
1350
1351 DPRINTK("EXIT\n"); 1380 DPRINTK("EXIT\n");
1352} 1381}
1353 1382
@@ -1385,7 +1414,7 @@ static void ata_eh_report(struct ata_port *ap)
1385 return; 1414 return;
1386 1415
1387 frozen = ""; 1416 frozen = "";
1388 if (ap->flags & ATA_FLAG_FROZEN) 1417 if (ap->pflags & ATA_PFLAG_FROZEN)
1389 frozen = " frozen"; 1418 frozen = " frozen";
1390 1419
1391 if (ehc->i.dev) { 1420 if (ehc->i.dev) {
@@ -1465,11 +1494,14 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1465 struct ata_eh_context *ehc = &ap->eh_context; 1494 struct ata_eh_context *ehc = &ap->eh_context;
1466 unsigned int *classes = ehc->classes; 1495 unsigned int *classes = ehc->classes;
1467 int tries = ATA_EH_RESET_TRIES; 1496 int tries = ATA_EH_RESET_TRIES;
1468 int verbose = !(ap->flags & ATA_FLAG_LOADING); 1497 int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
1469 unsigned int action; 1498 unsigned int action;
1470 ata_reset_fn_t reset; 1499 ata_reset_fn_t reset;
1471 int i, did_followup_srst, rc; 1500 int i, did_followup_srst, rc;
1472 1501
1502 /* about to reset */
1503 ata_eh_about_to_do(ap, NULL, ehc->i.action & ATA_EH_RESET_MASK);
1504
1473 /* Determine which reset to use and record in ehc->i.action. 1505 /* Determine which reset to use and record in ehc->i.action.
1474 * prereset() may examine and modify it. 1506 * prereset() may examine and modify it.
1475 */ 1507 */
@@ -1518,8 +1550,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1518 ata_port_printk(ap, KERN_INFO, "%s resetting port\n", 1550 ata_port_printk(ap, KERN_INFO, "%s resetting port\n",
1519 reset == softreset ? "soft" : "hard"); 1551 reset == softreset ? "soft" : "hard");
1520 1552
1521 /* reset */ 1553 /* mark that this EH session started with reset */
1522 ata_eh_about_to_do(ap, NULL, ATA_EH_RESET_MASK);
1523 ehc->i.flags |= ATA_EHI_DID_RESET; 1554 ehc->i.flags |= ATA_EHI_DID_RESET;
1524 1555
1525 rc = ata_do_reset(ap, reset, classes); 1556 rc = ata_do_reset(ap, reset, classes);
@@ -1582,7 +1613,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1582 postreset(ap, classes); 1613 postreset(ap, classes);
1583 1614
1584 /* reset successful, schedule revalidation */ 1615 /* reset successful, schedule revalidation */
1585 ata_eh_done(ap, NULL, ATA_EH_RESET_MASK); 1616 ata_eh_done(ap, NULL, ehc->i.action & ATA_EH_RESET_MASK);
1586 ehc->i.action |= ATA_EH_REVALIDATE; 1617 ehc->i.action |= ATA_EH_REVALIDATE;
1587 } 1618 }
1588 1619
@@ -1605,7 +1636,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1605 dev = &ap->device[i]; 1636 dev = &ap->device[i];
1606 action = ata_eh_dev_action(dev); 1637 action = ata_eh_dev_action(dev);
1607 1638
1608 if (action & ATA_EH_REVALIDATE && ata_dev_enabled(dev)) { 1639 if (action & ATA_EH_REVALIDATE && ata_dev_ready(dev)) {
1609 if (ata_port_offline(ap)) { 1640 if (ata_port_offline(ap)) {
1610 rc = -EIO; 1641 rc = -EIO;
1611 break; 1642 break;
@@ -1636,7 +1667,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1636 } 1667 }
1637 1668
1638 spin_lock_irqsave(ap->lock, flags); 1669 spin_lock_irqsave(ap->lock, flags);
1639 ap->flags |= ATA_FLAG_SCSI_HOTPLUG; 1670 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
1640 spin_unlock_irqrestore(ap->lock, flags); 1671 spin_unlock_irqrestore(ap->lock, flags);
1641 } 1672 }
1642 } 1673 }
@@ -1648,6 +1679,164 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1648 return rc; 1679 return rc;
1649} 1680}
1650 1681
1682/**
1683 * ata_eh_suspend - handle suspend EH action
1684 * @ap: target host port
1685 * @r_failed_dev: result parameter to indicate failing device
1686 *
1687 * Handle suspend EH action. Disk devices are spinned down and
1688 * other types of devices are just marked suspended. Once
1689 * suspended, no EH action to the device is allowed until it is
1690 * resumed.
1691 *
1692 * LOCKING:
1693 * Kernel thread context (may sleep).
1694 *
1695 * RETURNS:
1696 * 0 on success, -errno otherwise
1697 */
1698static int ata_eh_suspend(struct ata_port *ap, struct ata_device **r_failed_dev)
1699{
1700 struct ata_device *dev;
1701 int i, rc = 0;
1702
1703 DPRINTK("ENTER\n");
1704
1705 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1706 unsigned long flags;
1707 unsigned int action, err_mask;
1708
1709 dev = &ap->device[i];
1710 action = ata_eh_dev_action(dev);
1711
1712 if (!ata_dev_enabled(dev) || !(action & ATA_EH_SUSPEND))
1713 continue;
1714
1715 WARN_ON(dev->flags & ATA_DFLAG_SUSPENDED);
1716
1717 ata_eh_about_to_do(ap, dev, ATA_EH_SUSPEND);
1718
1719 if (dev->class == ATA_DEV_ATA && !(action & ATA_EH_PM_FREEZE)) {
1720 /* flush cache */
1721 rc = ata_flush_cache(dev);
1722 if (rc)
1723 break;
1724
1725 /* spin down */
1726 err_mask = ata_do_simple_cmd(dev, ATA_CMD_STANDBYNOW1);
1727 if (err_mask) {
1728 ata_dev_printk(dev, KERN_ERR, "failed to "
1729 "spin down (err_mask=0x%x)\n",
1730 err_mask);
1731 rc = -EIO;
1732 break;
1733 }
1734 }
1735
1736 spin_lock_irqsave(ap->lock, flags);
1737 dev->flags |= ATA_DFLAG_SUSPENDED;
1738 spin_unlock_irqrestore(ap->lock, flags);
1739
1740 ata_eh_done(ap, dev, ATA_EH_SUSPEND);
1741 }
1742
1743 if (rc)
1744 *r_failed_dev = dev;
1745
1746 DPRINTK("EXIT\n");
1747 return 0;
1748}
1749
1750/**
1751 * ata_eh_prep_resume - prep for resume EH action
1752 * @ap: target host port
1753 *
1754 * Clear SUSPENDED in preparation for scheduled resume actions.
1755 * This allows other parts of EH to access the devices being
1756 * resumed.
1757 *
1758 * LOCKING:
1759 * Kernel thread context (may sleep).
1760 */
1761static void ata_eh_prep_resume(struct ata_port *ap)
1762{
1763 struct ata_device *dev;
1764 unsigned long flags;
1765 int i;
1766
1767 DPRINTK("ENTER\n");
1768
1769 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1770 unsigned int action;
1771
1772 dev = &ap->device[i];
1773 action = ata_eh_dev_action(dev);
1774
1775 if (!ata_dev_enabled(dev) || !(action & ATA_EH_RESUME))
1776 continue;
1777
1778 spin_lock_irqsave(ap->lock, flags);
1779 dev->flags &= ~ATA_DFLAG_SUSPENDED;
1780 spin_unlock_irqrestore(ap->lock, flags);
1781 }
1782
1783 DPRINTK("EXIT\n");
1784}
1785
1786/**
1787 * ata_eh_resume - handle resume EH action
1788 * @ap: target host port
1789 * @r_failed_dev: result parameter to indicate failing device
1790 *
1791 * Handle resume EH action. Target devices are already reset and
1792 * revalidated. Spinning up is the only operation left.
1793 *
1794 * LOCKING:
1795 * Kernel thread context (may sleep).
1796 *
1797 * RETURNS:
1798 * 0 on success, -errno otherwise
1799 */
1800static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev)
1801{
1802 struct ata_device *dev;
1803 int i, rc = 0;
1804
1805 DPRINTK("ENTER\n");
1806
1807 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1808 unsigned int action, err_mask;
1809
1810 dev = &ap->device[i];
1811 action = ata_eh_dev_action(dev);
1812
1813 if (!ata_dev_enabled(dev) || !(action & ATA_EH_RESUME))
1814 continue;
1815
1816 ata_eh_about_to_do(ap, dev, ATA_EH_RESUME);
1817
1818 if (dev->class == ATA_DEV_ATA && !(action & ATA_EH_PM_FREEZE)) {
1819 err_mask = ata_do_simple_cmd(dev,
1820 ATA_CMD_IDLEIMMEDIATE);
1821 if (err_mask) {
1822 ata_dev_printk(dev, KERN_ERR, "failed to "
1823 "spin up (err_mask=0x%x)\n",
1824 err_mask);
1825 rc = -EIO;
1826 break;
1827 }
1828 }
1829
1830 ata_eh_done(ap, dev, ATA_EH_RESUME);
1831 }
1832
1833 if (rc)
1834 *r_failed_dev = dev;
1835
1836 DPRINTK("EXIT\n");
1837 return 0;
1838}
1839
1651static int ata_port_nr_enabled(struct ata_port *ap) 1840static int ata_port_nr_enabled(struct ata_port *ap)
1652{ 1841{
1653 int i, cnt = 0; 1842 int i, cnt = 0;
@@ -1673,7 +1862,20 @@ static int ata_eh_skip_recovery(struct ata_port *ap)
1673 struct ata_eh_context *ehc = &ap->eh_context; 1862 struct ata_eh_context *ehc = &ap->eh_context;
1674 int i; 1863 int i;
1675 1864
1676 if (ap->flags & ATA_FLAG_FROZEN || ata_port_nr_enabled(ap)) 1865 /* skip if all possible devices are suspended */
1866 for (i = 0; i < ata_port_max_devices(ap); i++) {
1867 struct ata_device *dev = &ap->device[i];
1868
1869 if (!(dev->flags & ATA_DFLAG_SUSPENDED))
1870 break;
1871 }
1872
1873 if (i == ata_port_max_devices(ap))
1874 return 1;
1875
1876 /* thaw frozen port, resume link and recover failed devices */
1877 if ((ap->pflags & ATA_PFLAG_FROZEN) ||
1878 (ehc->i.flags & ATA_EHI_RESUME_LINK) || ata_port_nr_enabled(ap))
1677 return 0; 1879 return 0;
1678 1880
1679 /* skip if class codes for all vacant slots are ATA_DEV_NONE */ 1881 /* skip if class codes for all vacant slots are ATA_DEV_NONE */
@@ -1744,9 +1946,12 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1744 rc = 0; 1946 rc = 0;
1745 1947
1746 /* if UNLOADING, finish immediately */ 1948 /* if UNLOADING, finish immediately */
1747 if (ap->flags & ATA_FLAG_UNLOADING) 1949 if (ap->pflags & ATA_PFLAG_UNLOADING)
1748 goto out; 1950 goto out;
1749 1951
1952 /* prep for resume */
1953 ata_eh_prep_resume(ap);
1954
1750 /* skip EH if possible. */ 1955 /* skip EH if possible. */
1751 if (ata_eh_skip_recovery(ap)) 1956 if (ata_eh_skip_recovery(ap))
1752 ehc->i.action = 0; 1957 ehc->i.action = 0;
@@ -1774,6 +1979,11 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1774 if (rc) 1979 if (rc)
1775 goto dev_fail; 1980 goto dev_fail;
1776 1981
1982 /* resume devices */
1983 rc = ata_eh_resume(ap, &dev);
1984 if (rc)
1985 goto dev_fail;
1986
1777 /* configure transfer mode if the port has been reset */ 1987 /* configure transfer mode if the port has been reset */
1778 if (ehc->i.flags & ATA_EHI_DID_RESET) { 1988 if (ehc->i.flags & ATA_EHI_DID_RESET) {
1779 rc = ata_set_mode(ap, &dev); 1989 rc = ata_set_mode(ap, &dev);
@@ -1783,6 +1993,11 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1783 } 1993 }
1784 } 1994 }
1785 1995
1996 /* suspend devices */
1997 rc = ata_eh_suspend(ap, &dev);
1998 if (rc)
1999 goto dev_fail;
2000
1786 goto out; 2001 goto out;
1787 2002
1788 dev_fail: 2003 dev_fail:
@@ -1908,11 +2123,124 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
1908 ata_reset_fn_t softreset, ata_reset_fn_t hardreset, 2123 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
1909 ata_postreset_fn_t postreset) 2124 ata_postreset_fn_t postreset)
1910{ 2125{
1911 if (!(ap->flags & ATA_FLAG_LOADING)) { 2126 ata_eh_autopsy(ap);
1912 ata_eh_autopsy(ap); 2127 ata_eh_report(ap);
1913 ata_eh_report(ap);
1914 }
1915
1916 ata_eh_recover(ap, prereset, softreset, hardreset, postreset); 2128 ata_eh_recover(ap, prereset, softreset, hardreset, postreset);
1917 ata_eh_finish(ap); 2129 ata_eh_finish(ap);
1918} 2130}
2131
2132/**
2133 * ata_eh_handle_port_suspend - perform port suspend operation
2134 * @ap: port to suspend
2135 *
2136 * Suspend @ap.
2137 *
2138 * LOCKING:
2139 * Kernel thread context (may sleep).
2140 */
2141static void ata_eh_handle_port_suspend(struct ata_port *ap)
2142{
2143 unsigned long flags;
2144 int rc = 0;
2145
2146 /* are we suspending? */
2147 spin_lock_irqsave(ap->lock, flags);
2148 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) ||
2149 ap->pm_mesg.event == PM_EVENT_ON) {
2150 spin_unlock_irqrestore(ap->lock, flags);
2151 return;
2152 }
2153 spin_unlock_irqrestore(ap->lock, flags);
2154
2155 WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED);
2156
2157 /* suspend */
2158 ata_eh_freeze_port(ap);
2159
2160 if (ap->ops->port_suspend)
2161 rc = ap->ops->port_suspend(ap, ap->pm_mesg);
2162
2163 /* report result */
2164 spin_lock_irqsave(ap->lock, flags);
2165
2166 ap->pflags &= ~ATA_PFLAG_PM_PENDING;
2167 if (rc == 0)
2168 ap->pflags |= ATA_PFLAG_SUSPENDED;
2169 else
2170 ata_port_schedule_eh(ap);
2171
2172 if (ap->pm_result) {
2173 *ap->pm_result = rc;
2174 ap->pm_result = NULL;
2175 }
2176
2177 spin_unlock_irqrestore(ap->lock, flags);
2178
2179 return;
2180}
2181
2182/**
2183 * ata_eh_handle_port_resume - perform port resume operation
2184 * @ap: port to resume
2185 *
2186 * Resume @ap.
2187 *
2188 * This function also waits upto one second until all devices
2189 * hanging off this port requests resume EH action. This is to
2190 * prevent invoking EH and thus reset multiple times on resume.
2191 *
2192 * On DPM resume, where some of devices might not be resumed
2193 * together, this may delay port resume upto one second, but such
2194 * DPM resumes are rare and 1 sec delay isn't too bad.
2195 *
2196 * LOCKING:
2197 * Kernel thread context (may sleep).
2198 */
2199static void ata_eh_handle_port_resume(struct ata_port *ap)
2200{
2201 unsigned long timeout;
2202 unsigned long flags;
2203 int i, rc = 0;
2204
2205 /* are we resuming? */
2206 spin_lock_irqsave(ap->lock, flags);
2207 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) ||
2208 ap->pm_mesg.event != PM_EVENT_ON) {
2209 spin_unlock_irqrestore(ap->lock, flags);
2210 return;
2211 }
2212 spin_unlock_irqrestore(ap->lock, flags);
2213
2214 /* spurious? */
2215 if (!(ap->pflags & ATA_PFLAG_SUSPENDED))
2216 goto done;
2217
2218 if (ap->ops->port_resume)
2219 rc = ap->ops->port_resume(ap);
2220
2221 /* give devices time to request EH */
2222 timeout = jiffies + HZ; /* 1s max */
2223 while (1) {
2224 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2225 struct ata_device *dev = &ap->device[i];
2226 unsigned int action = ata_eh_dev_action(dev);
2227
2228 if ((dev->flags & ATA_DFLAG_SUSPENDED) &&
2229 !(action & ATA_EH_RESUME))
2230 break;
2231 }
2232
2233 if (i == ATA_MAX_DEVICES || time_after(jiffies, timeout))
2234 break;
2235 msleep(10);
2236 }
2237
2238 done:
2239 spin_lock_irqsave(ap->lock, flags);
2240 ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED);
2241 if (ap->pm_result) {
2242 *ap->pm_result = rc;
2243 ap->pm_result = NULL;
2244 }
2245 spin_unlock_irqrestore(ap->lock, flags);
2246}
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 2915bca691e8..e92c31d698ff 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -397,20 +397,129 @@ void ata_dump_status(unsigned id, struct ata_taskfile *tf)
397 } 397 }
398} 398}
399 399
400int ata_scsi_device_resume(struct scsi_device *sdev) 400/**
401 * ata_scsi_device_suspend - suspend ATA device associated with sdev
402 * @sdev: the SCSI device to suspend
403 * @state: target power management state
404 *
405 * Request suspend EH action on the ATA device associated with
406 * @sdev and wait for the operation to complete.
407 *
408 * LOCKING:
409 * Kernel thread context (may sleep).
410 *
411 * RETURNS:
412 * 0 on success, -errno otherwise.
413 */
414int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state)
401{ 415{
402 struct ata_port *ap = ata_shost_to_port(sdev->host); 416 struct ata_port *ap = ata_shost_to_port(sdev->host);
403 struct ata_device *dev = __ata_scsi_find_dev(ap, sdev); 417 struct ata_device *dev = ata_scsi_find_dev(ap, sdev);
418 unsigned long flags;
419 unsigned int action;
420 int rc = 0;
421
422 if (!dev)
423 goto out;
424
425 spin_lock_irqsave(ap->lock, flags);
426
427 /* wait for the previous resume to complete */
428 while (dev->flags & ATA_DFLAG_SUSPENDED) {
429 spin_unlock_irqrestore(ap->lock, flags);
430 ata_port_wait_eh(ap);
431 spin_lock_irqsave(ap->lock, flags);
432 }
433
434 /* if @sdev is already detached, nothing to do */
435 if (sdev->sdev_state == SDEV_OFFLINE ||
436 sdev->sdev_state == SDEV_CANCEL || sdev->sdev_state == SDEV_DEL)
437 goto out_unlock;
438
439 /* request suspend */
440 action = ATA_EH_SUSPEND;
441 if (state.event != PM_EVENT_SUSPEND)
442 action |= ATA_EH_PM_FREEZE;
443 ap->eh_info.dev_action[dev->devno] |= action;
444 ap->eh_info.flags |= ATA_EHI_QUIET;
445 ata_port_schedule_eh(ap);
446
447 spin_unlock_irqrestore(ap->lock, flags);
448
449 /* wait for EH to do the job */
450 ata_port_wait_eh(ap);
451
452 spin_lock_irqsave(ap->lock, flags);
453
454 /* If @sdev is still attached but the associated ATA device
455 * isn't suspended, the operation failed.
456 */
457 if (sdev->sdev_state != SDEV_OFFLINE &&
458 sdev->sdev_state != SDEV_CANCEL && sdev->sdev_state != SDEV_DEL &&
459 !(dev->flags & ATA_DFLAG_SUSPENDED))
460 rc = -EIO;
404 461
405 return ata_device_resume(dev); 462 out_unlock:
463 spin_unlock_irqrestore(ap->lock, flags);
464 out:
465 if (rc == 0)
466 sdev->sdev_gendev.power.power_state = state;
467 return rc;
406} 468}
407 469
408int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state) 470/**
471 * ata_scsi_device_resume - resume ATA device associated with sdev
472 * @sdev: the SCSI device to resume
473 *
474 * Request resume EH action on the ATA device associated with
475 * @sdev and return immediately. This enables parallel
476 * wakeup/spinup of devices.
477 *
478 * LOCKING:
479 * Kernel thread context (may sleep).
480 *
481 * RETURNS:
482 * 0.
483 */
484int ata_scsi_device_resume(struct scsi_device *sdev)
409{ 485{
410 struct ata_port *ap = ata_shost_to_port(sdev->host); 486 struct ata_port *ap = ata_shost_to_port(sdev->host);
411 struct ata_device *dev = __ata_scsi_find_dev(ap, sdev); 487 struct ata_device *dev = ata_scsi_find_dev(ap, sdev);
488 struct ata_eh_info *ehi = &ap->eh_info;
489 unsigned long flags;
490 unsigned int action;
412 491
413 return ata_device_suspend(dev, state); 492 if (!dev)
493 goto out;
494
495 spin_lock_irqsave(ap->lock, flags);
496
497 /* if @sdev is already detached, nothing to do */
498 if (sdev->sdev_state == SDEV_OFFLINE ||
499 sdev->sdev_state == SDEV_CANCEL || sdev->sdev_state == SDEV_DEL)
500 goto out_unlock;
501
502 /* request resume */
503 action = ATA_EH_RESUME;
504 if (sdev->sdev_gendev.power.power_state.event == PM_EVENT_SUSPEND)
505 __ata_ehi_hotplugged(ehi);
506 else
507 action |= ATA_EH_PM_FREEZE | ATA_EH_SOFTRESET;
508 ehi->dev_action[dev->devno] |= action;
509
510 /* We don't want autopsy and verbose EH messages. Disable
511 * those if we're the only device on this link.
512 */
513 if (ata_port_max_devices(ap) == 1)
514 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
515
516 ata_port_schedule_eh(ap);
517
518 out_unlock:
519 spin_unlock_irqrestore(ap->lock, flags);
520 out:
521 sdev->sdev_gendev.power.power_state = PMSG_ON;
522 return 0;
414} 523}
415 524
416/** 525/**
@@ -2244,6 +2353,19 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc)
2244 ata_gen_ata_desc_sense(qc); 2353 ata_gen_ata_desc_sense(qc);
2245 } 2354 }
2246 2355
2356 /* SCSI EH automatically locks door if sdev->locked is
2357 * set. Sometimes door lock request continues to
2358 * fail, for example, when no media is present. This
2359 * creates a loop - SCSI EH issues door lock which
2360 * fails and gets invoked again to acquire sense data
2361 * for the failed command.
2362 *
2363 * If door lock fails, always clear sdev->locked to
2364 * avoid this infinite loop.
2365 */
2366 if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL)
2367 qc->dev->sdev->locked = 0;
2368
2247 qc->scsicmd->result = SAM_STAT_CHECK_CONDITION; 2369 qc->scsicmd->result = SAM_STAT_CHECK_CONDITION;
2248 qc->scsidone(cmd); 2370 qc->scsidone(cmd);
2249 ata_qc_free(qc); 2371 ata_qc_free(qc);
@@ -2930,7 +3052,7 @@ void ata_scsi_hotplug(void *data)
2930 struct ata_port *ap = data; 3052 struct ata_port *ap = data;
2931 int i; 3053 int i;
2932 3054
2933 if (ap->flags & ATA_FLAG_UNLOADING) { 3055 if (ap->pflags & ATA_PFLAG_UNLOADING) {
2934 DPRINTK("ENTER/EXIT - unloading\n"); 3056 DPRINTK("ENTER/EXIT - unloading\n");
2935 return; 3057 return;
2936 } 3058 }
@@ -3011,6 +3133,7 @@ static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
3011 if (dev) { 3133 if (dev) {
3012 ap->eh_info.probe_mask |= 1 << dev->devno; 3134 ap->eh_info.probe_mask |= 1 << dev->devno;
3013 ap->eh_info.action |= ATA_EH_SOFTRESET; 3135 ap->eh_info.action |= ATA_EH_SOFTRESET;
3136 ap->eh_info.flags |= ATA_EHI_RESUME_LINK;
3014 } else 3137 } else
3015 rc = -EINVAL; 3138 rc = -EINVAL;
3016 } 3139 }
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 2673a11a9495..5884cd26d53a 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -189,6 +189,7 @@ static void iscsi_complete_command(struct iscsi_session *session,
189{ 189{
190 struct scsi_cmnd *sc = ctask->sc; 190 struct scsi_cmnd *sc = ctask->sc;
191 191
192 ctask->state = ISCSI_TASK_COMPLETED;
192 ctask->sc = NULL; 193 ctask->sc = NULL;
193 list_del_init(&ctask->running); 194 list_del_init(&ctask->running);
194 __kfifo_put(session->cmdpool.queue, (void*)&ctask, sizeof(void*)); 195 __kfifo_put(session->cmdpool.queue, (void*)&ctask, sizeof(void*));
@@ -275,6 +276,25 @@ out:
275 return rc; 276 return rc;
276} 277}
277 278
279static void iscsi_tmf_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
280{
281 struct iscsi_tm_rsp *tmf = (struct iscsi_tm_rsp *)hdr;
282
283 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
284 conn->tmfrsp_pdus_cnt++;
285
286 if (conn->tmabort_state != TMABORT_INITIAL)
287 return;
288
289 if (tmf->response == ISCSI_TMF_RSP_COMPLETE)
290 conn->tmabort_state = TMABORT_SUCCESS;
291 else if (tmf->response == ISCSI_TMF_RSP_NO_TASK)
292 conn->tmabort_state = TMABORT_NOT_FOUND;
293 else
294 conn->tmabort_state = TMABORT_FAILED;
295 wake_up(&conn->ehwait);
296}
297
278/** 298/**
279 * __iscsi_complete_pdu - complete pdu 299 * __iscsi_complete_pdu - complete pdu
280 * @conn: iscsi conn 300 * @conn: iscsi conn
@@ -340,6 +360,10 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
340 360
341 switch(opcode) { 361 switch(opcode) {
342 case ISCSI_OP_LOGOUT_RSP: 362 case ISCSI_OP_LOGOUT_RSP:
363 if (datalen) {
364 rc = ISCSI_ERR_PROTO;
365 break;
366 }
343 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1; 367 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
344 /* fall through */ 368 /* fall through */
345 case ISCSI_OP_LOGIN_RSP: 369 case ISCSI_OP_LOGIN_RSP:
@@ -348,7 +372,8 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
348 * login related PDU's exp_statsn is handled in 372 * login related PDU's exp_statsn is handled in
349 * userspace 373 * userspace
350 */ 374 */
351 rc = iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen); 375 if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen))
376 rc = ISCSI_ERR_CONN_FAILED;
352 list_del(&mtask->running); 377 list_del(&mtask->running);
353 if (conn->login_mtask != mtask) 378 if (conn->login_mtask != mtask)
354 __kfifo_put(session->mgmtpool.queue, 379 __kfifo_put(session->mgmtpool.queue,
@@ -360,25 +385,17 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
360 break; 385 break;
361 } 386 }
362 387
363 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1; 388 iscsi_tmf_rsp(conn, hdr);
364 conn->tmfrsp_pdus_cnt++;
365 if (conn->tmabort_state == TMABORT_INITIAL) {
366 conn->tmabort_state =
367 ((struct iscsi_tm_rsp *)hdr)->
368 response == ISCSI_TMF_RSP_COMPLETE ?
369 TMABORT_SUCCESS:TMABORT_FAILED;
370 /* unblock eh_abort() */
371 wake_up(&conn->ehwait);
372 }
373 break; 389 break;
374 case ISCSI_OP_NOOP_IN: 390 case ISCSI_OP_NOOP_IN:
375 if (hdr->ttt != ISCSI_RESERVED_TAG) { 391 if (hdr->ttt != ISCSI_RESERVED_TAG || datalen) {
376 rc = ISCSI_ERR_PROTO; 392 rc = ISCSI_ERR_PROTO;
377 break; 393 break;
378 } 394 }
379 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1; 395 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
380 396
381 rc = iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen); 397 if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen))
398 rc = ISCSI_ERR_CONN_FAILED;
382 list_del(&mtask->running); 399 list_del(&mtask->running);
383 if (conn->login_mtask != mtask) 400 if (conn->login_mtask != mtask)
384 __kfifo_put(session->mgmtpool.queue, 401 __kfifo_put(session->mgmtpool.queue,
@@ -391,14 +408,21 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
391 } else if (itt == ISCSI_RESERVED_TAG) { 408 } else if (itt == ISCSI_RESERVED_TAG) {
392 switch(opcode) { 409 switch(opcode) {
393 case ISCSI_OP_NOOP_IN: 410 case ISCSI_OP_NOOP_IN:
394 if (!datalen) { 411 if (datalen) {
395 rc = iscsi_check_assign_cmdsn(session,
396 (struct iscsi_nopin*)hdr);
397 if (!rc && hdr->ttt != ISCSI_RESERVED_TAG)
398 rc = iscsi_recv_pdu(conn->cls_conn,
399 hdr, NULL, 0);
400 } else
401 rc = ISCSI_ERR_PROTO; 412 rc = ISCSI_ERR_PROTO;
413 break;
414 }
415
416 rc = iscsi_check_assign_cmdsn(session,
417 (struct iscsi_nopin*)hdr);
418 if (rc)
419 break;
420
421 if (hdr->ttt == ISCSI_RESERVED_TAG)
422 break;
423
424 if (iscsi_recv_pdu(conn->cls_conn, hdr, NULL, 0))
425 rc = ISCSI_ERR_CONN_FAILED;
402 break; 426 break;
403 case ISCSI_OP_REJECT: 427 case ISCSI_OP_REJECT:
404 /* we need sth like iscsi_reject_rsp()*/ 428 /* we need sth like iscsi_reject_rsp()*/
@@ -568,20 +592,24 @@ static int iscsi_data_xmit(struct iscsi_conn *conn)
568 } 592 }
569 593
570 /* process command queue */ 594 /* process command queue */
571 while (__kfifo_get(conn->xmitqueue, (void*)&conn->ctask, 595 spin_lock_bh(&conn->session->lock);
572 sizeof(void*))) { 596 while (!list_empty(&conn->xmitqueue)) {
573 /* 597 /*
574 * iscsi tcp may readd the task to the xmitqueue to send 598 * iscsi tcp may readd the task to the xmitqueue to send
575 * write data 599 * write data
576 */ 600 */
577 spin_lock_bh(&conn->session->lock); 601 conn->ctask = list_entry(conn->xmitqueue.next,
578 if (list_empty(&conn->ctask->running)) 602 struct iscsi_cmd_task, running);
579 list_add_tail(&conn->ctask->running, &conn->run_list); 603 conn->ctask->state = ISCSI_TASK_RUNNING;
604 list_move_tail(conn->xmitqueue.next, &conn->run_list);
580 spin_unlock_bh(&conn->session->lock); 605 spin_unlock_bh(&conn->session->lock);
606
581 rc = tt->xmit_cmd_task(conn, conn->ctask); 607 rc = tt->xmit_cmd_task(conn, conn->ctask);
582 if (rc) 608 if (rc)
583 goto again; 609 goto again;
610 spin_lock_bh(&conn->session->lock);
584 } 611 }
612 spin_unlock_bh(&conn->session->lock);
585 /* done with this ctask */ 613 /* done with this ctask */
586 conn->ctask = NULL; 614 conn->ctask = NULL;
587 615
@@ -691,6 +719,7 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
691 sc->SCp.phase = session->age; 719 sc->SCp.phase = session->age;
692 sc->SCp.ptr = (char *)ctask; 720 sc->SCp.ptr = (char *)ctask;
693 721
722 ctask->state = ISCSI_TASK_PENDING;
694 ctask->mtask = NULL; 723 ctask->mtask = NULL;
695 ctask->conn = conn; 724 ctask->conn = conn;
696 ctask->sc = sc; 725 ctask->sc = sc;
@@ -700,7 +729,7 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
700 729
701 session->tt->init_cmd_task(ctask); 730 session->tt->init_cmd_task(ctask);
702 731
703 __kfifo_put(conn->xmitqueue, (void*)&ctask, sizeof(void*)); 732 list_add_tail(&ctask->running, &conn->xmitqueue);
704 debug_scsi( 733 debug_scsi(
705 "ctask enq [%s cid %d sc %lx itt 0x%x len %d cmdsn %d win %d]\n", 734 "ctask enq [%s cid %d sc %lx itt 0x%x len %d cmdsn %d win %d]\n",
706 sc->sc_data_direction == DMA_TO_DEVICE ? "write" : "read", 735 sc->sc_data_direction == DMA_TO_DEVICE ? "write" : "read",
@@ -977,31 +1006,27 @@ static int iscsi_exec_abort_task(struct scsi_cmnd *sc,
977/* 1006/*
978 * xmit mutex and session lock must be held 1007 * xmit mutex and session lock must be held
979 */ 1008 */
980#define iscsi_remove_task(tasktype) \ 1009static struct iscsi_mgmt_task *
981static struct iscsi_##tasktype * \ 1010iscsi_remove_mgmt_task(struct kfifo *fifo, uint32_t itt)
982iscsi_remove_##tasktype(struct kfifo *fifo, uint32_t itt) \ 1011{
983{ \ 1012 int i, nr_tasks = __kfifo_len(fifo) / sizeof(void*);
984 int i, nr_tasks = __kfifo_len(fifo) / sizeof(void*); \ 1013 struct iscsi_mgmt_task *task;
985 struct iscsi_##tasktype *task; \ 1014
986 \ 1015 debug_scsi("searching %d tasks\n", nr_tasks);
987 debug_scsi("searching %d tasks\n", nr_tasks); \ 1016
988 \ 1017 for (i = 0; i < nr_tasks; i++) {
989 for (i = 0; i < nr_tasks; i++) { \ 1018 __kfifo_get(fifo, (void*)&task, sizeof(void*));
990 __kfifo_get(fifo, (void*)&task, sizeof(void*)); \ 1019 debug_scsi("check task %u\n", task->itt);
991 debug_scsi("check task %u\n", task->itt); \
992 \
993 if (task->itt == itt) { \
994 debug_scsi("matched task\n"); \
995 return task; \
996 } \
997 \
998 __kfifo_put(fifo, (void*)&task, sizeof(void*)); \
999 } \
1000 return NULL; \
1001}
1002 1020
1003iscsi_remove_task(mgmt_task); 1021 if (task->itt == itt) {
1004iscsi_remove_task(cmd_task); 1022 debug_scsi("matched task\n");
1023 return task;
1024 }
1025
1026 __kfifo_put(fifo, (void*)&task, sizeof(void*));
1027 }
1028 return NULL;
1029}
1005 1030
1006static int iscsi_ctask_mtask_cleanup(struct iscsi_cmd_task *ctask) 1031static int iscsi_ctask_mtask_cleanup(struct iscsi_cmd_task *ctask)
1007{ 1032{
@@ -1027,12 +1052,13 @@ static void fail_command(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
1027{ 1052{
1028 struct scsi_cmnd *sc; 1053 struct scsi_cmnd *sc;
1029 1054
1030 conn->session->tt->cleanup_cmd_task(conn, ctask);
1031 iscsi_ctask_mtask_cleanup(ctask);
1032
1033 sc = ctask->sc; 1055 sc = ctask->sc;
1034 if (!sc) 1056 if (!sc)
1035 return; 1057 return;
1058
1059 conn->session->tt->cleanup_cmd_task(conn, ctask);
1060 iscsi_ctask_mtask_cleanup(ctask);
1061
1036 sc->result = err; 1062 sc->result = err;
1037 sc->resid = sc->request_bufflen; 1063 sc->resid = sc->request_bufflen;
1038 iscsi_complete_command(conn->session, ctask); 1064 iscsi_complete_command(conn->session, ctask);
@@ -1043,7 +1069,6 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1043 struct iscsi_cmd_task *ctask = (struct iscsi_cmd_task *)sc->SCp.ptr; 1069 struct iscsi_cmd_task *ctask = (struct iscsi_cmd_task *)sc->SCp.ptr;
1044 struct iscsi_conn *conn = ctask->conn; 1070 struct iscsi_conn *conn = ctask->conn;
1045 struct iscsi_session *session = conn->session; 1071 struct iscsi_session *session = conn->session;
1046 struct iscsi_cmd_task *pending_ctask;
1047 int rc; 1072 int rc;
1048 1073
1049 conn->eh_abort_cnt++; 1074 conn->eh_abort_cnt++;
@@ -1061,8 +1086,11 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1061 goto failed; 1086 goto failed;
1062 1087
1063 /* ctask completed before time out */ 1088 /* ctask completed before time out */
1064 if (!ctask->sc) 1089 if (!ctask->sc) {
1065 goto success; 1090 spin_unlock_bh(&session->lock);
1091 debug_scsi("sc completed while abort in progress\n");
1092 goto success_rel_mutex;
1093 }
1066 1094
1067 /* what should we do here ? */ 1095 /* what should we do here ? */
1068 if (conn->ctask == ctask) { 1096 if (conn->ctask == ctask) {
@@ -1071,17 +1099,8 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1071 goto failed; 1099 goto failed;
1072 } 1100 }
1073 1101
1074 /* check for the easy pending cmd abort */ 1102 if (ctask->state == ISCSI_TASK_PENDING)
1075 pending_ctask = iscsi_remove_cmd_task(conn->xmitqueue, ctask->itt); 1103 goto success_cleanup;
1076 if (pending_ctask) {
1077 /* iscsi_tcp queues write transfers on the xmitqueue */
1078 if (list_empty(&pending_ctask->running)) {
1079 debug_scsi("found pending task\n");
1080 goto success;
1081 } else
1082 __kfifo_put(conn->xmitqueue, (void*)&pending_ctask,
1083 sizeof(void*));
1084 }
1085 1104
1086 conn->tmabort_state = TMABORT_INITIAL; 1105 conn->tmabort_state = TMABORT_INITIAL;
1087 1106
@@ -1089,25 +1108,31 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1089 rc = iscsi_exec_abort_task(sc, ctask); 1108 rc = iscsi_exec_abort_task(sc, ctask);
1090 spin_lock_bh(&session->lock); 1109 spin_lock_bh(&session->lock);
1091 1110
1092 iscsi_ctask_mtask_cleanup(ctask);
1093 if (rc || sc->SCp.phase != session->age || 1111 if (rc || sc->SCp.phase != session->age ||
1094 session->state != ISCSI_STATE_LOGGED_IN) 1112 session->state != ISCSI_STATE_LOGGED_IN)
1095 goto failed; 1113 goto failed;
1114 iscsi_ctask_mtask_cleanup(ctask);
1096 1115
1097 /* ctask completed before tmf abort response */ 1116 switch (conn->tmabort_state) {
1098 if (!ctask->sc) { 1117 case TMABORT_SUCCESS:
1099 debug_scsi("sc completed while abort in progress\n"); 1118 goto success_cleanup;
1100 goto success; 1119 case TMABORT_NOT_FOUND:
1101 } 1120 if (!ctask->sc) {
1102 1121 /* ctask completed before tmf abort response */
1103 if (conn->tmabort_state != TMABORT_SUCCESS) { 1122 spin_unlock_bh(&session->lock);
1123 debug_scsi("sc completed while abort in progress\n");
1124 goto success_rel_mutex;
1125 }
1126 /* fall through */
1127 default:
1128 /* timedout or failed */
1104 spin_unlock_bh(&session->lock); 1129 spin_unlock_bh(&session->lock);
1105 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); 1130 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1106 spin_lock_bh(&session->lock); 1131 spin_lock_bh(&session->lock);
1107 goto failed; 1132 goto failed;
1108 } 1133 }
1109 1134
1110success: 1135success_cleanup:
1111 debug_scsi("abort success [sc %lx itt 0x%x]\n", (long)sc, ctask->itt); 1136 debug_scsi("abort success [sc %lx itt 0x%x]\n", (long)sc, ctask->itt);
1112 spin_unlock_bh(&session->lock); 1137 spin_unlock_bh(&session->lock);
1113 1138
@@ -1121,6 +1146,7 @@ success:
1121 spin_unlock(&session->lock); 1146 spin_unlock(&session->lock);
1122 write_unlock_bh(conn->recv_lock); 1147 write_unlock_bh(conn->recv_lock);
1123 1148
1149success_rel_mutex:
1124 mutex_unlock(&conn->xmitmutex); 1150 mutex_unlock(&conn->xmitmutex);
1125 return SUCCESS; 1151 return SUCCESS;
1126 1152
@@ -1263,6 +1289,7 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
1263 if (cmd_task_size) 1289 if (cmd_task_size)
1264 ctask->dd_data = &ctask[1]; 1290 ctask->dd_data = &ctask[1];
1265 ctask->itt = cmd_i; 1291 ctask->itt = cmd_i;
1292 INIT_LIST_HEAD(&ctask->running);
1266 } 1293 }
1267 1294
1268 spin_lock_init(&session->lock); 1295 spin_lock_init(&session->lock);
@@ -1282,18 +1309,24 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
1282 if (mgmt_task_size) 1309 if (mgmt_task_size)
1283 mtask->dd_data = &mtask[1]; 1310 mtask->dd_data = &mtask[1];
1284 mtask->itt = ISCSI_MGMT_ITT_OFFSET + cmd_i; 1311 mtask->itt = ISCSI_MGMT_ITT_OFFSET + cmd_i;
1312 INIT_LIST_HEAD(&mtask->running);
1285 } 1313 }
1286 1314
1287 if (scsi_add_host(shost, NULL)) 1315 if (scsi_add_host(shost, NULL))
1288 goto add_host_fail; 1316 goto add_host_fail;
1289 1317
1318 if (!try_module_get(iscsit->owner))
1319 goto cls_session_fail;
1320
1290 cls_session = iscsi_create_session(shost, iscsit, 0); 1321 cls_session = iscsi_create_session(shost, iscsit, 0);
1291 if (!cls_session) 1322 if (!cls_session)
1292 goto cls_session_fail; 1323 goto module_put;
1293 *(unsigned long*)shost->hostdata = (unsigned long)cls_session; 1324 *(unsigned long*)shost->hostdata = (unsigned long)cls_session;
1294 1325
1295 return cls_session; 1326 return cls_session;
1296 1327
1328module_put:
1329 module_put(iscsit->owner);
1297cls_session_fail: 1330cls_session_fail:
1298 scsi_remove_host(shost); 1331 scsi_remove_host(shost);
1299add_host_fail: 1332add_host_fail:
@@ -1317,14 +1350,18 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
1317{ 1350{
1318 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); 1351 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1319 struct iscsi_session *session = iscsi_hostdata(shost->hostdata); 1352 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
1353 struct module *owner = cls_session->transport->owner;
1320 1354
1321 scsi_remove_host(shost); 1355 scsi_remove_host(shost);
1322 1356
1323 iscsi_pool_free(&session->mgmtpool, (void**)session->mgmt_cmds); 1357 iscsi_pool_free(&session->mgmtpool, (void**)session->mgmt_cmds);
1324 iscsi_pool_free(&session->cmdpool, (void**)session->cmds); 1358 iscsi_pool_free(&session->cmdpool, (void**)session->cmds);
1325 1359
1360 kfree(session->targetname);
1361
1326 iscsi_destroy_session(cls_session); 1362 iscsi_destroy_session(cls_session);
1327 scsi_host_put(shost); 1363 scsi_host_put(shost);
1364 module_put(owner);
1328} 1365}
1329EXPORT_SYMBOL_GPL(iscsi_session_teardown); 1366EXPORT_SYMBOL_GPL(iscsi_session_teardown);
1330 1367
@@ -1355,12 +1392,7 @@ iscsi_conn_setup(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
1355 conn->tmabort_state = TMABORT_INITIAL; 1392 conn->tmabort_state = TMABORT_INITIAL;
1356 INIT_LIST_HEAD(&conn->run_list); 1393 INIT_LIST_HEAD(&conn->run_list);
1357 INIT_LIST_HEAD(&conn->mgmt_run_list); 1394 INIT_LIST_HEAD(&conn->mgmt_run_list);
1358 1395 INIT_LIST_HEAD(&conn->xmitqueue);
1359 /* initialize general xmit PDU commands queue */
1360 conn->xmitqueue = kfifo_alloc(session->cmds_max * sizeof(void*),
1361 GFP_KERNEL, NULL);
1362 if (conn->xmitqueue == ERR_PTR(-ENOMEM))
1363 goto xmitqueue_alloc_fail;
1364 1396
1365 /* initialize general immediate & non-immediate PDU commands queue */ 1397 /* initialize general immediate & non-immediate PDU commands queue */
1366 conn->immqueue = kfifo_alloc(session->mgmtpool_max * sizeof(void*), 1398 conn->immqueue = kfifo_alloc(session->mgmtpool_max * sizeof(void*),
@@ -1388,7 +1420,7 @@ iscsi_conn_setup(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
1388 data = kmalloc(DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH, GFP_KERNEL); 1420 data = kmalloc(DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH, GFP_KERNEL);
1389 if (!data) 1421 if (!data)
1390 goto login_mtask_data_alloc_fail; 1422 goto login_mtask_data_alloc_fail;
1391 conn->login_mtask->data = data; 1423 conn->login_mtask->data = conn->data = data;
1392 1424
1393 init_timer(&conn->tmabort_timer); 1425 init_timer(&conn->tmabort_timer);
1394 mutex_init(&conn->xmitmutex); 1426 mutex_init(&conn->xmitmutex);
@@ -1404,8 +1436,6 @@ login_mtask_alloc_fail:
1404mgmtqueue_alloc_fail: 1436mgmtqueue_alloc_fail:
1405 kfifo_free(conn->immqueue); 1437 kfifo_free(conn->immqueue);
1406immqueue_alloc_fail: 1438immqueue_alloc_fail:
1407 kfifo_free(conn->xmitqueue);
1408xmitqueue_alloc_fail:
1409 iscsi_destroy_conn(cls_conn); 1439 iscsi_destroy_conn(cls_conn);
1410 return NULL; 1440 return NULL;
1411} 1441}
@@ -1426,12 +1456,6 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
1426 1456
1427 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx); 1457 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1428 mutex_lock(&conn->xmitmutex); 1458 mutex_lock(&conn->xmitmutex);
1429 if (conn->c_stage == ISCSI_CONN_INITIAL_STAGE) {
1430 if (session->tt->suspend_conn_recv)
1431 session->tt->suspend_conn_recv(conn);
1432
1433 session->tt->terminate_conn(conn);
1434 }
1435 1459
1436 spin_lock_bh(&session->lock); 1460 spin_lock_bh(&session->lock);
1437 conn->c_stage = ISCSI_CONN_CLEANUP_WAIT; 1461 conn->c_stage = ISCSI_CONN_CLEANUP_WAIT;
@@ -1468,7 +1492,8 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
1468 } 1492 }
1469 1493
1470 spin_lock_bh(&session->lock); 1494 spin_lock_bh(&session->lock);
1471 kfree(conn->login_mtask->data); 1495 kfree(conn->data);
1496 kfree(conn->persistent_address);
1472 __kfifo_put(session->mgmtpool.queue, (void*)&conn->login_mtask, 1497 __kfifo_put(session->mgmtpool.queue, (void*)&conn->login_mtask,
1473 sizeof(void*)); 1498 sizeof(void*));
1474 list_del(&conn->item); 1499 list_del(&conn->item);
@@ -1483,7 +1508,6 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
1483 session->cmdsn = session->max_cmdsn = session->exp_cmdsn = 1; 1508 session->cmdsn = session->max_cmdsn = session->exp_cmdsn = 1;
1484 spin_unlock_bh(&session->lock); 1509 spin_unlock_bh(&session->lock);
1485 1510
1486 kfifo_free(conn->xmitqueue);
1487 kfifo_free(conn->immqueue); 1511 kfifo_free(conn->immqueue);
1488 kfifo_free(conn->mgmtqueue); 1512 kfifo_free(conn->mgmtqueue);
1489 1513
@@ -1566,7 +1590,7 @@ static void fail_all_commands(struct iscsi_conn *conn)
1566 struct iscsi_cmd_task *ctask, *tmp; 1590 struct iscsi_cmd_task *ctask, *tmp;
1567 1591
1568 /* flush pending */ 1592 /* flush pending */
1569 while (__kfifo_get(conn->xmitqueue, (void*)&ctask, sizeof(void*))) { 1593 list_for_each_entry_safe(ctask, tmp, &conn->xmitqueue, running) {
1570 debug_scsi("failing pending sc %p itt 0x%x\n", ctask->sc, 1594 debug_scsi("failing pending sc %p itt 0x%x\n", ctask->sc,
1571 ctask->itt); 1595 ctask->itt);
1572 fail_command(conn, ctask, DID_BUS_BUSY << 16); 1596 fail_command(conn, ctask, DID_BUS_BUSY << 16);
@@ -1609,8 +1633,9 @@ static void iscsi_start_session_recovery(struct iscsi_session *session,
1609 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx); 1633 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1610 spin_unlock_bh(&session->lock); 1634 spin_unlock_bh(&session->lock);
1611 1635
1612 if (session->tt->suspend_conn_recv) 1636 write_lock_bh(conn->recv_lock);
1613 session->tt->suspend_conn_recv(conn); 1637 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
1638 write_unlock_bh(conn->recv_lock);
1614 1639
1615 mutex_lock(&conn->xmitmutex); 1640 mutex_lock(&conn->xmitmutex);
1616 /* 1641 /*
@@ -1629,7 +1654,6 @@ static void iscsi_start_session_recovery(struct iscsi_session *session,
1629 } 1654 }
1630 } 1655 }
1631 1656
1632 session->tt->terminate_conn(conn);
1633 /* 1657 /*
1634 * flush queues. 1658 * flush queues.
1635 */ 1659 */
@@ -1697,6 +1721,185 @@ int iscsi_conn_bind(struct iscsi_cls_session *cls_session,
1697} 1721}
1698EXPORT_SYMBOL_GPL(iscsi_conn_bind); 1722EXPORT_SYMBOL_GPL(iscsi_conn_bind);
1699 1723
1724
1725int iscsi_set_param(struct iscsi_cls_conn *cls_conn,
1726 enum iscsi_param param, char *buf, int buflen)
1727{
1728 struct iscsi_conn *conn = cls_conn->dd_data;
1729 struct iscsi_session *session = conn->session;
1730 uint32_t value;
1731
1732 switch(param) {
1733 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1734 sscanf(buf, "%d", &conn->max_recv_dlength);
1735 break;
1736 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1737 sscanf(buf, "%d", &conn->max_xmit_dlength);
1738 break;
1739 case ISCSI_PARAM_HDRDGST_EN:
1740 sscanf(buf, "%d", &conn->hdrdgst_en);
1741 break;
1742 case ISCSI_PARAM_DATADGST_EN:
1743 sscanf(buf, "%d", &conn->datadgst_en);
1744 break;
1745 case ISCSI_PARAM_INITIAL_R2T_EN:
1746 sscanf(buf, "%d", &session->initial_r2t_en);
1747 break;
1748 case ISCSI_PARAM_MAX_R2T:
1749 sscanf(buf, "%d", &session->max_r2t);
1750 break;
1751 case ISCSI_PARAM_IMM_DATA_EN:
1752 sscanf(buf, "%d", &session->imm_data_en);
1753 break;
1754 case ISCSI_PARAM_FIRST_BURST:
1755 sscanf(buf, "%d", &session->first_burst);
1756 break;
1757 case ISCSI_PARAM_MAX_BURST:
1758 sscanf(buf, "%d", &session->max_burst);
1759 break;
1760 case ISCSI_PARAM_PDU_INORDER_EN:
1761 sscanf(buf, "%d", &session->pdu_inorder_en);
1762 break;
1763 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1764 sscanf(buf, "%d", &session->dataseq_inorder_en);
1765 break;
1766 case ISCSI_PARAM_ERL:
1767 sscanf(buf, "%d", &session->erl);
1768 break;
1769 case ISCSI_PARAM_IFMARKER_EN:
1770 sscanf(buf, "%d", &value);
1771 BUG_ON(value);
1772 break;
1773 case ISCSI_PARAM_OFMARKER_EN:
1774 sscanf(buf, "%d", &value);
1775 BUG_ON(value);
1776 break;
1777 case ISCSI_PARAM_EXP_STATSN:
1778 sscanf(buf, "%u", &conn->exp_statsn);
1779 break;
1780 case ISCSI_PARAM_TARGET_NAME:
1781 /* this should not change between logins */
1782 if (session->targetname)
1783 break;
1784
1785 session->targetname = kstrdup(buf, GFP_KERNEL);
1786 if (!session->targetname)
1787 return -ENOMEM;
1788 break;
1789 case ISCSI_PARAM_TPGT:
1790 sscanf(buf, "%d", &session->tpgt);
1791 break;
1792 case ISCSI_PARAM_PERSISTENT_PORT:
1793 sscanf(buf, "%d", &conn->persistent_port);
1794 break;
1795 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1796 /*
1797 * this is the address returned in discovery so it should
1798 * not change between logins.
1799 */
1800 if (conn->persistent_address)
1801 break;
1802
1803 conn->persistent_address = kstrdup(buf, GFP_KERNEL);
1804 if (!conn->persistent_address)
1805 return -ENOMEM;
1806 break;
1807 default:
1808 return -ENOSYS;
1809 }
1810
1811 return 0;
1812}
1813EXPORT_SYMBOL_GPL(iscsi_set_param);
1814
1815int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
1816 enum iscsi_param param, char *buf)
1817{
1818 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1819 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
1820 int len;
1821
1822 switch(param) {
1823 case ISCSI_PARAM_INITIAL_R2T_EN:
1824 len = sprintf(buf, "%d\n", session->initial_r2t_en);
1825 break;
1826 case ISCSI_PARAM_MAX_R2T:
1827 len = sprintf(buf, "%hu\n", session->max_r2t);
1828 break;
1829 case ISCSI_PARAM_IMM_DATA_EN:
1830 len = sprintf(buf, "%d\n", session->imm_data_en);
1831 break;
1832 case ISCSI_PARAM_FIRST_BURST:
1833 len = sprintf(buf, "%u\n", session->first_burst);
1834 break;
1835 case ISCSI_PARAM_MAX_BURST:
1836 len = sprintf(buf, "%u\n", session->max_burst);
1837 break;
1838 case ISCSI_PARAM_PDU_INORDER_EN:
1839 len = sprintf(buf, "%d\n", session->pdu_inorder_en);
1840 break;
1841 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1842 len = sprintf(buf, "%d\n", session->dataseq_inorder_en);
1843 break;
1844 case ISCSI_PARAM_ERL:
1845 len = sprintf(buf, "%d\n", session->erl);
1846 break;
1847 case ISCSI_PARAM_TARGET_NAME:
1848 len = sprintf(buf, "%s\n", session->targetname);
1849 break;
1850 case ISCSI_PARAM_TPGT:
1851 len = sprintf(buf, "%d\n", session->tpgt);
1852 break;
1853 default:
1854 return -ENOSYS;
1855 }
1856
1857 return len;
1858}
1859EXPORT_SYMBOL_GPL(iscsi_session_get_param);
1860
1861int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
1862 enum iscsi_param param, char *buf)
1863{
1864 struct iscsi_conn *conn = cls_conn->dd_data;
1865 int len;
1866
1867 switch(param) {
1868 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1869 len = sprintf(buf, "%u\n", conn->max_recv_dlength);
1870 break;
1871 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1872 len = sprintf(buf, "%u\n", conn->max_xmit_dlength);
1873 break;
1874 case ISCSI_PARAM_HDRDGST_EN:
1875 len = sprintf(buf, "%d\n", conn->hdrdgst_en);
1876 break;
1877 case ISCSI_PARAM_DATADGST_EN:
1878 len = sprintf(buf, "%d\n", conn->datadgst_en);
1879 break;
1880 case ISCSI_PARAM_IFMARKER_EN:
1881 len = sprintf(buf, "%d\n", conn->ifmarker_en);
1882 break;
1883 case ISCSI_PARAM_OFMARKER_EN:
1884 len = sprintf(buf, "%d\n", conn->ofmarker_en);
1885 break;
1886 case ISCSI_PARAM_EXP_STATSN:
1887 len = sprintf(buf, "%u\n", conn->exp_statsn);
1888 break;
1889 case ISCSI_PARAM_PERSISTENT_PORT:
1890 len = sprintf(buf, "%d\n", conn->persistent_port);
1891 break;
1892 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1893 len = sprintf(buf, "%s\n", conn->persistent_address);
1894 break;
1895 default:
1896 return -ENOSYS;
1897 }
1898
1899 return len;
1900}
1901EXPORT_SYMBOL_GPL(iscsi_conn_get_param);
1902
1700MODULE_AUTHOR("Mike Christie"); 1903MODULE_AUTHOR("Mike Christie");
1701MODULE_DESCRIPTION("iSCSI library functions"); 1904MODULE_DESCRIPTION("iSCSI library functions");
1702MODULE_LICENSE("GPL"); 1905MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index 087c44539a16..d44f9aac6b8f 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -21,10 +21,12 @@
21 21
22struct lpfc_sli2_slim; 22struct lpfc_sli2_slim;
23 23
24#define LPFC_MAX_TARGET 256 /* max targets supported */
25#define LPFC_MAX_DISC_THREADS 64 /* max outstanding discovery els req */
26#define LPFC_MAX_NS_RETRY 3 /* max NameServer retries */
27 24
25#define LPFC_MAX_TARGET 256 /* max number of targets supported */
26#define LPFC_MAX_DISC_THREADS 64 /* max outstanding discovery els
27 requests */
28#define LPFC_MAX_NS_RETRY 3 /* Number of retry attempts to contact
29 the NameServer before giving up. */
28#define LPFC_DFT_HBA_Q_DEPTH 2048 /* max cmds per hba */ 30#define LPFC_DFT_HBA_Q_DEPTH 2048 /* max cmds per hba */
29#define LPFC_LC_HBA_Q_DEPTH 1024 /* max cmds per low cost hba */ 31#define LPFC_LC_HBA_Q_DEPTH 1024 /* max cmds per low cost hba */
30#define LPFC_LP101_HBA_Q_DEPTH 128 /* max cmds per low cost hba */ 32#define LPFC_LP101_HBA_Q_DEPTH 128 /* max cmds per low cost hba */
@@ -41,7 +43,6 @@ struct lpfc_sli2_slim;
41 (( (u64)(high)<<16 ) << 16)|( (u64)(low)))) 43 (( (u64)(high)<<16 ) << 16)|( (u64)(low))))
42/* Provide maximum configuration definitions. */ 44/* Provide maximum configuration definitions. */
43#define LPFC_DRVR_TIMEOUT 16 /* driver iocb timeout value in sec */ 45#define LPFC_DRVR_TIMEOUT 16 /* driver iocb timeout value in sec */
44#define MAX_FCP_TARGET 256 /* max num of FCP targets supported */
45#define FC_MAX_ADPTMSG 64 46#define FC_MAX_ADPTMSG 64
46 47
47#define MAX_HBAEVT 32 48#define MAX_HBAEVT 32
@@ -174,7 +175,6 @@ struct lpfc_hba {
174 dma_addr_t slim2p_mapping; 175 dma_addr_t slim2p_mapping;
175 uint16_t pci_cfg_value; 176 uint16_t pci_cfg_value;
176 177
177 struct semaphore hba_can_block;
178 int32_t hba_state; 178 int32_t hba_state;
179 179
180#define LPFC_STATE_UNKNOWN 0 /* HBA state is unknown */ 180#define LPFC_STATE_UNKNOWN 0 /* HBA state is unknown */
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index b62a72dfab29..d384c16f4a87 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -219,8 +219,18 @@ lpfc_issue_lip(struct Scsi_Host *host)
219 return -ENOMEM; 219 return -ENOMEM;
220 220
221 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 221 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
222 lpfc_init_link(phba, pmboxq, phba->cfg_topology, phba->cfg_link_speed); 222 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
223 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 223 pmboxq->mb.mbxOwner = OWN_HOST;
224
225 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
226
227 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
228 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
229 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
230 phba->cfg_link_speed);
231 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
232 phba->fc_ratov * 2);
233 }
224 234
225 if (mbxstatus == MBX_TIMEOUT) 235 if (mbxstatus == MBX_TIMEOUT)
226 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 236 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
@@ -233,51 +243,53 @@ lpfc_issue_lip(struct Scsi_Host *host)
233 return 0; 243 return 0;
234} 244}
235 245
236static ssize_t 246static int
237lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf) 247lpfc_selective_reset(struct lpfc_hba *phba)
238{ 248{
239 struct Scsi_Host *host = class_to_shost(cdev); 249 struct completion online_compl;
240 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 250 int status = 0;
241 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); 251
252 init_completion(&online_compl);
253 lpfc_workq_post_event(phba, &status, &online_compl,
254 LPFC_EVT_OFFLINE);
255 wait_for_completion(&online_compl);
256
257 if (status != 0)
258 return -EIO;
259
260 init_completion(&online_compl);
261 lpfc_workq_post_event(phba, &status, &online_compl,
262 LPFC_EVT_ONLINE);
263 wait_for_completion(&online_compl);
264
265 if (status != 0)
266 return -EIO;
267
268 return 0;
242} 269}
243 270
244static ssize_t 271static ssize_t
245lpfc_board_online_show(struct class_device *cdev, char *buf) 272lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
246{ 273{
247 struct Scsi_Host *host = class_to_shost(cdev); 274 struct Scsi_Host *host = class_to_shost(cdev);
248 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 275 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
276 int status = -EINVAL;
249 277
250 if (phba->fc_flag & FC_OFFLINE_MODE) 278 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
251 return snprintf(buf, PAGE_SIZE, "0\n"); 279 status = lpfc_selective_reset(phba);
280
281 if (status == 0)
282 return strlen(buf);
252 else 283 else
253 return snprintf(buf, PAGE_SIZE, "1\n"); 284 return status;
254} 285}
255 286
256static ssize_t 287static ssize_t
257lpfc_board_online_store(struct class_device *cdev, const char *buf, 288lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
258 size_t count)
259{ 289{
260 struct Scsi_Host *host = class_to_shost(cdev); 290 struct Scsi_Host *host = class_to_shost(cdev);
261 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 291 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
262 struct completion online_compl; 292 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
263 int val=0, status=0;
264
265 if (sscanf(buf, "%d", &val) != 1)
266 return -EINVAL;
267
268 init_completion(&online_compl);
269
270 if (val)
271 lpfc_workq_post_event(phba, &status, &online_compl,
272 LPFC_EVT_ONLINE);
273 else
274 lpfc_workq_post_event(phba, &status, &online_compl,
275 LPFC_EVT_OFFLINE);
276 wait_for_completion(&online_compl);
277 if (!status)
278 return strlen(buf);
279 else
280 return -EIO;
281} 293}
282 294
283static ssize_t 295static ssize_t
@@ -532,10 +544,9 @@ static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
532 NULL); 544 NULL);
533static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show, 545static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
534 NULL); 546 NULL);
535static CLASS_DEVICE_ATTR(board_online, S_IRUGO | S_IWUSR,
536 lpfc_board_online_show, lpfc_board_online_store);
537static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR, 547static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
538 lpfc_board_mode_show, lpfc_board_mode_store); 548 lpfc_board_mode_show, lpfc_board_mode_store);
549static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
539 550
540static int lpfc_poll = 0; 551static int lpfc_poll = 0;
541module_param(lpfc_poll, int, 0); 552module_param(lpfc_poll, int, 0);
@@ -695,12 +706,12 @@ LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
695 "during discovery"); 706 "during discovery");
696 707
697/* 708/*
698# lpfc_max_luns: maximum number of LUNs per target driver will support 709# lpfc_max_luns: maximum allowed LUN.
699# Value range is [1,32768]. Default value is 256. 710# Value range is [0,65535]. Default value is 255.
700# NOTE: The SCSI layer will scan each target for this many luns 711# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
701*/ 712*/
702LPFC_ATTR_R(max_luns, 256, 1, 32768, 713LPFC_ATTR_R(max_luns, 255, 0, 65535,
703 "Maximum number of LUNs per target driver will support"); 714 "Maximum allowed LUN");
704 715
705/* 716/*
706# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring. 717# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
@@ -739,8 +750,8 @@ struct class_device_attribute *lpfc_host_attrs[] = {
739 &class_device_attr_lpfc_max_luns, 750 &class_device_attr_lpfc_max_luns,
740 &class_device_attr_nport_evt_cnt, 751 &class_device_attr_nport_evt_cnt,
741 &class_device_attr_management_version, 752 &class_device_attr_management_version,
742 &class_device_attr_board_online,
743 &class_device_attr_board_mode, 753 &class_device_attr_board_mode,
754 &class_device_attr_issue_reset,
744 &class_device_attr_lpfc_poll, 755 &class_device_attr_lpfc_poll,
745 &class_device_attr_lpfc_poll_tmo, 756 &class_device_attr_lpfc_poll_tmo,
746 NULL, 757 NULL,
@@ -873,7 +884,7 @@ sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
873 phba->sysfs_mbox.mbox == NULL ) { 884 phba->sysfs_mbox.mbox == NULL ) {
874 sysfs_mbox_idle(phba); 885 sysfs_mbox_idle(phba);
875 spin_unlock_irq(host->host_lock); 886 spin_unlock_irq(host->host_lock);
876 return -EINVAL; 887 return -EAGAIN;
877 } 888 }
878 } 889 }
879 890
@@ -989,14 +1000,15 @@ sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
989 spin_unlock_irq(phba->host->host_lock); 1000 spin_unlock_irq(phba->host->host_lock);
990 rc = lpfc_sli_issue_mbox_wait (phba, 1001 rc = lpfc_sli_issue_mbox_wait (phba,
991 phba->sysfs_mbox.mbox, 1002 phba->sysfs_mbox.mbox,
992 phba->fc_ratov * 2); 1003 lpfc_mbox_tmo_val(phba,
1004 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
993 spin_lock_irq(phba->host->host_lock); 1005 spin_lock_irq(phba->host->host_lock);
994 } 1006 }
995 1007
996 if (rc != MBX_SUCCESS) { 1008 if (rc != MBX_SUCCESS) {
997 sysfs_mbox_idle(phba); 1009 sysfs_mbox_idle(phba);
998 spin_unlock_irq(host->host_lock); 1010 spin_unlock_irq(host->host_lock);
999 return -ENODEV; 1011 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
1000 } 1012 }
1001 phba->sysfs_mbox.state = SMBOX_READING; 1013 phba->sysfs_mbox.state = SMBOX_READING;
1002 } 1014 }
@@ -1005,7 +1017,7 @@ sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1005 printk(KERN_WARNING "mbox_read: Bad State\n"); 1017 printk(KERN_WARNING "mbox_read: Bad State\n");
1006 sysfs_mbox_idle(phba); 1018 sysfs_mbox_idle(phba);
1007 spin_unlock_irq(host->host_lock); 1019 spin_unlock_irq(host->host_lock);
1008 return -EINVAL; 1020 return -EAGAIN;
1009 } 1021 }
1010 1022
1011 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count); 1023 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
@@ -1199,8 +1211,10 @@ lpfc_get_stats(struct Scsi_Host *shost)
1199 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; 1211 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
1200 struct lpfc_sli *psli = &phba->sli; 1212 struct lpfc_sli *psli = &phba->sli;
1201 struct fc_host_statistics *hs = &phba->link_stats; 1213 struct fc_host_statistics *hs = &phba->link_stats;
1214 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
1202 LPFC_MBOXQ_t *pmboxq; 1215 LPFC_MBOXQ_t *pmboxq;
1203 MAILBOX_t *pmb; 1216 MAILBOX_t *pmb;
1217 unsigned long seconds;
1204 int rc = 0; 1218 int rc = 0;
1205 1219
1206 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 1220 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
@@ -1261,22 +1275,103 @@ lpfc_get_stats(struct Scsi_Host *shost)
1261 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt; 1275 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1262 hs->error_frames = pmb->un.varRdLnk.crcCnt; 1276 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1263 1277
1278 hs->link_failure_count -= lso->link_failure_count;
1279 hs->loss_of_sync_count -= lso->loss_of_sync_count;
1280 hs->loss_of_signal_count -= lso->loss_of_signal_count;
1281 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
1282 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
1283 hs->invalid_crc_count -= lso->invalid_crc_count;
1284 hs->error_frames -= lso->error_frames;
1285
1264 if (phba->fc_topology == TOPOLOGY_LOOP) { 1286 if (phba->fc_topology == TOPOLOGY_LOOP) {
1265 hs->lip_count = (phba->fc_eventTag >> 1); 1287 hs->lip_count = (phba->fc_eventTag >> 1);
1288 hs->lip_count -= lso->link_events;
1266 hs->nos_count = -1; 1289 hs->nos_count = -1;
1267 } else { 1290 } else {
1268 hs->lip_count = -1; 1291 hs->lip_count = -1;
1269 hs->nos_count = (phba->fc_eventTag >> 1); 1292 hs->nos_count = (phba->fc_eventTag >> 1);
1293 hs->nos_count -= lso->link_events;
1270 } 1294 }
1271 1295
1272 hs->dumped_frames = -1; 1296 hs->dumped_frames = -1;
1273 1297
1274/* FIX ME */ 1298 seconds = get_seconds();
1275 /*hs->SecondsSinceLastReset = (jiffies - lpfc_loadtime) / HZ;*/ 1299 if (seconds < psli->stats_start)
1300 hs->seconds_since_last_reset = seconds +
1301 ((unsigned long)-1 - psli->stats_start);
1302 else
1303 hs->seconds_since_last_reset = seconds - psli->stats_start;
1276 1304
1277 return hs; 1305 return hs;
1278} 1306}
1279 1307
1308static void
1309lpfc_reset_stats(struct Scsi_Host *shost)
1310{
1311 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
1312 struct lpfc_sli *psli = &phba->sli;
1313 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
1314 LPFC_MBOXQ_t *pmboxq;
1315 MAILBOX_t *pmb;
1316 int rc = 0;
1317
1318 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1319 if (!pmboxq)
1320 return;
1321 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1322
1323 pmb = &pmboxq->mb;
1324 pmb->mbxCommand = MBX_READ_STATUS;
1325 pmb->mbxOwner = OWN_HOST;
1326 pmb->un.varWords[0] = 0x1; /* reset request */
1327 pmboxq->context1 = NULL;
1328
1329 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1330 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1331 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1332 else
1333 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1334
1335 if (rc != MBX_SUCCESS) {
1336 if (rc == MBX_TIMEOUT)
1337 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1338 else
1339 mempool_free(pmboxq, phba->mbox_mem_pool);
1340 return;
1341 }
1342
1343 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1344 pmb->mbxCommand = MBX_READ_LNK_STAT;
1345 pmb->mbxOwner = OWN_HOST;
1346 pmboxq->context1 = NULL;
1347
1348 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1349 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1350 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1351 else
1352 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1353
1354 if (rc != MBX_SUCCESS) {
1355 if (rc == MBX_TIMEOUT)
1356 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1357 else
1358 mempool_free( pmboxq, phba->mbox_mem_pool);
1359 return;
1360 }
1361
1362 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1363 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1364 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1365 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1366 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1367 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1368 lso->error_frames = pmb->un.varRdLnk.crcCnt;
1369 lso->link_events = (phba->fc_eventTag >> 1);
1370
1371 psli->stats_start = get_seconds();
1372
1373 return;
1374}
1280 1375
1281/* 1376/*
1282 * The LPFC driver treats linkdown handling as target loss events so there 1377 * The LPFC driver treats linkdown handling as target loss events so there
@@ -1420,8 +1515,7 @@ struct fc_function_template lpfc_transport_functions = {
1420 */ 1515 */
1421 1516
1422 .get_fc_host_stats = lpfc_get_stats, 1517 .get_fc_host_stats = lpfc_get_stats,
1423 1518 .reset_fc_host_stats = lpfc_reset_stats,
1424 /* the LPFC driver doesn't support resetting stats yet */
1425 1519
1426 .dd_fcrport_size = sizeof(struct lpfc_rport_data), 1520 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1427 .show_rport_maxframe_size = 1, 1521 .show_rport_maxframe_size = 1,
diff --git a/drivers/scsi/lpfc/lpfc_crtn.h b/drivers/scsi/lpfc/lpfc_crtn.h
index ee22173fce43..2a176467f71b 100644
--- a/drivers/scsi/lpfc/lpfc_crtn.h
+++ b/drivers/scsi/lpfc/lpfc_crtn.h
@@ -127,6 +127,7 @@ void lpfc_config_port(struct lpfc_hba *, LPFC_MBOXQ_t *);
127void lpfc_kill_board(struct lpfc_hba *, LPFC_MBOXQ_t *); 127void lpfc_kill_board(struct lpfc_hba *, LPFC_MBOXQ_t *);
128void lpfc_mbox_put(struct lpfc_hba *, LPFC_MBOXQ_t *); 128void lpfc_mbox_put(struct lpfc_hba *, LPFC_MBOXQ_t *);
129LPFC_MBOXQ_t *lpfc_mbox_get(struct lpfc_hba *); 129LPFC_MBOXQ_t *lpfc_mbox_get(struct lpfc_hba *);
130int lpfc_mbox_tmo_val(struct lpfc_hba *, int);
130 131
131int lpfc_mem_alloc(struct lpfc_hba *); 132int lpfc_mem_alloc(struct lpfc_hba *);
132void lpfc_mem_free(struct lpfc_hba *); 133void lpfc_mem_free(struct lpfc_hba *);
@@ -147,6 +148,7 @@ int lpfc_sli_hba_setup(struct lpfc_hba *);
147int lpfc_sli_hba_down(struct lpfc_hba *); 148int lpfc_sli_hba_down(struct lpfc_hba *);
148int lpfc_sli_issue_mbox(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t); 149int lpfc_sli_issue_mbox(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t);
149int lpfc_sli_handle_mb_event(struct lpfc_hba *); 150int lpfc_sli_handle_mb_event(struct lpfc_hba *);
151int lpfc_sli_flush_mbox_queue(struct lpfc_hba *);
150int lpfc_sli_handle_slow_ring_event(struct lpfc_hba *, 152int lpfc_sli_handle_slow_ring_event(struct lpfc_hba *,
151 struct lpfc_sli_ring *, uint32_t); 153 struct lpfc_sli_ring *, uint32_t);
152void lpfc_sli_def_mbox_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *); 154void lpfc_sli_def_mbox_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
index b65ee57af53e..bbb7310210b0 100644
--- a/drivers/scsi/lpfc/lpfc_ct.c
+++ b/drivers/scsi/lpfc/lpfc_ct.c
@@ -131,6 +131,7 @@ lpfc_ct_unsol_event(struct lpfc_hba * phba,
131 } 131 }
132 132
133ct_unsol_event_exit_piocbq: 133ct_unsol_event_exit_piocbq:
134 list_del(&head);
134 if (pmbuf) { 135 if (pmbuf) {
135 list_for_each_entry_safe(matp, next_matp, &pmbuf->list, list) { 136 list_for_each_entry_safe(matp, next_matp, &pmbuf->list, list) {
136 lpfc_mbuf_free(phba, matp->virt, matp->phys); 137 lpfc_mbuf_free(phba, matp->virt, matp->phys);
@@ -481,7 +482,7 @@ lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
481 if (CTrsp->CommandResponse.bits.CmdRsp == 482 if (CTrsp->CommandResponse.bits.CmdRsp ==
482 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) { 483 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
483 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 484 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
484 "%d:0239 NameServer Rsp " 485 "%d:0208 NameServer Rsp "
485 "Data: x%x\n", 486 "Data: x%x\n",
486 phba->brd_no, 487 phba->brd_no,
487 phba->fc_flag); 488 phba->fc_flag);
@@ -588,13 +589,9 @@ lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
588 589
589 lpfc_decode_firmware_rev(phba, fwrev, 0); 590 lpfc_decode_firmware_rev(phba, fwrev, 0);
590 591
591 if (phba->Port[0]) { 592 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
592 sprintf(symbp, "Emulex %s Port %s FV%s DV%s", phba->ModelName, 593 fwrev, lpfc_release_version);
593 phba->Port, fwrev, lpfc_release_version); 594 return;
594 } else {
595 sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
596 fwrev, lpfc_release_version);
597 }
598} 595}
599 596
600/* 597/*
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 283b7d824c34..3567de613162 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -648,33 +648,32 @@ lpfc_more_plogi(struct lpfc_hba * phba)
648} 648}
649 649
650static struct lpfc_nodelist * 650static struct lpfc_nodelist *
651lpfc_plogi_confirm_nport(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 651lpfc_plogi_confirm_nport(struct lpfc_hba * phba, struct lpfc_dmabuf *prsp,
652 struct lpfc_nodelist *ndlp) 652 struct lpfc_nodelist *ndlp)
653{ 653{
654 struct lpfc_nodelist *new_ndlp; 654 struct lpfc_nodelist *new_ndlp;
655 struct lpfc_dmabuf *pcmd, *prsp;
656 uint32_t *lp; 655 uint32_t *lp;
657 struct serv_parm *sp; 656 struct serv_parm *sp;
658 uint8_t name[sizeof (struct lpfc_name)]; 657 uint8_t name[sizeof (struct lpfc_name)];
659 uint32_t rc; 658 uint32_t rc;
660 659
661 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
662 prsp = (struct lpfc_dmabuf *) pcmd->list.next;
663 lp = (uint32_t *) prsp->virt; 660 lp = (uint32_t *) prsp->virt;
664 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t)); 661 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
662 memset(name, 0, sizeof (struct lpfc_name));
665 663
666 /* Now we to find out if the NPort we are logging into, matches the WWPN 664 /* Now we to find out if the NPort we are logging into, matches the WWPN
667 * we have for that ndlp. If not, we have some work to do. 665 * we have for that ndlp. If not, we have some work to do.
668 */ 666 */
669 new_ndlp = lpfc_findnode_wwpn(phba, NLP_SEARCH_ALL, &sp->portName); 667 new_ndlp = lpfc_findnode_wwpn(phba, NLP_SEARCH_ALL, &sp->portName);
670 668
671 memset(name, 0, sizeof (struct lpfc_name)); 669 if (new_ndlp == ndlp)
672 rc = memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name));
673 if (!rc || (new_ndlp == ndlp)) {
674 return ndlp; 670 return ndlp;
675 }
676 671
677 if (!new_ndlp) { 672 if (!new_ndlp) {
673 rc =
674 memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name));
675 if (!rc)
676 return ndlp;
678 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); 677 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
679 if (!new_ndlp) 678 if (!new_ndlp)
680 return ndlp; 679 return ndlp;
@@ -683,17 +682,21 @@ lpfc_plogi_confirm_nport(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
683 } 682 }
684 683
685 lpfc_unreg_rpi(phba, new_ndlp); 684 lpfc_unreg_rpi(phba, new_ndlp);
686 new_ndlp->nlp_prev_state = ndlp->nlp_state;
687 new_ndlp->nlp_DID = ndlp->nlp_DID; 685 new_ndlp->nlp_DID = ndlp->nlp_DID;
688 new_ndlp->nlp_state = NLP_STE_PLOGI_ISSUE; 686 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
689 lpfc_nlp_list(phba, new_ndlp, NLP_PLOGI_LIST); 687 new_ndlp->nlp_state = ndlp->nlp_state;
688 lpfc_nlp_list(phba, new_ndlp, ndlp->nlp_flag & NLP_LIST_MASK);
690 689
691 /* Move this back to NPR list */ 690 /* Move this back to NPR list */
692 lpfc_unreg_rpi(phba, ndlp); 691 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
693 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */ 692 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
694 ndlp->nlp_state = NLP_STE_NPR_NODE; 693 }
695 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST); 694 else {
696 695 lpfc_unreg_rpi(phba, ndlp);
696 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
697 ndlp->nlp_state = NLP_STE_NPR_NODE;
698 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
699 }
697 return new_ndlp; 700 return new_ndlp;
698} 701}
699 702
@@ -703,6 +706,7 @@ lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
703{ 706{
704 IOCB_t *irsp; 707 IOCB_t *irsp;
705 struct lpfc_nodelist *ndlp; 708 struct lpfc_nodelist *ndlp;
709 struct lpfc_dmabuf *prsp;
706 int disc, rc, did, type; 710 int disc, rc, did, type;
707 711
708 712
@@ -769,7 +773,10 @@ lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
769 } 773 }
770 } else { 774 } else {
771 /* Good status, call state machine */ 775 /* Good status, call state machine */
772 ndlp = lpfc_plogi_confirm_nport(phba, cmdiocb, ndlp); 776 prsp = list_entry(((struct lpfc_dmabuf *)
777 cmdiocb->context2)->list.next,
778 struct lpfc_dmabuf, list);
779 ndlp = lpfc_plogi_confirm_nport(phba, prsp, ndlp);
773 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb, 780 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
774 NLP_EVT_CMPL_PLOGI); 781 NLP_EVT_CMPL_PLOGI);
775 } 782 }
@@ -821,7 +828,7 @@ lpfc_issue_els_plogi(struct lpfc_hba * phba, uint32_t did, uint8_t retry)
821 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 828 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
822 829
823 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm)); 830 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
824 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, 0, did, 831 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, NULL, did,
825 ELS_CMD_PLOGI); 832 ELS_CMD_PLOGI);
826 if (!elsiocb) 833 if (!elsiocb)
827 return 1; 834 return 1;
@@ -1841,9 +1848,12 @@ static void
1841lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 1848lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1842 struct lpfc_iocbq * rspiocb) 1849 struct lpfc_iocbq * rspiocb)
1843{ 1850{
1851 IOCB_t *irsp;
1844 struct lpfc_nodelist *ndlp; 1852 struct lpfc_nodelist *ndlp;
1845 LPFC_MBOXQ_t *mbox = NULL; 1853 LPFC_MBOXQ_t *mbox = NULL;
1846 1854
1855 irsp = &rspiocb->iocb;
1856
1847 ndlp = (struct lpfc_nodelist *) cmdiocb->context1; 1857 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1848 if (cmdiocb->context_un.mbox) 1858 if (cmdiocb->context_un.mbox)
1849 mbox = cmdiocb->context_un.mbox; 1859 mbox = cmdiocb->context_un.mbox;
@@ -1886,9 +1896,15 @@ lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1886 mempool_free( mbox, phba->mbox_mem_pool); 1896 mempool_free( mbox, phba->mbox_mem_pool);
1887 } else { 1897 } else {
1888 mempool_free( mbox, phba->mbox_mem_pool); 1898 mempool_free( mbox, phba->mbox_mem_pool);
1889 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) { 1899 /* Do not call NO_LIST for lpfc_els_abort'ed ELS cmds */
1890 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 1900 if (!((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1891 ndlp = NULL; 1901 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1902 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
1903 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN)))) {
1904 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1905 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1906 ndlp = NULL;
1907 }
1892 } 1908 }
1893 } 1909 }
1894 } 1910 }
@@ -2791,8 +2807,8 @@ lpfc_els_rsp_rps_acc(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2791 2807
2792 ndlp = (struct lpfc_nodelist *) pmb->context2; 2808 ndlp = (struct lpfc_nodelist *) pmb->context2;
2793 xri = (uint16_t) ((unsigned long)(pmb->context1)); 2809 xri = (uint16_t) ((unsigned long)(pmb->context1));
2794 pmb->context1 = 0; 2810 pmb->context1 = NULL;
2795 pmb->context2 = 0; 2811 pmb->context2 = NULL;
2796 2812
2797 if (mb->mbxStatus) { 2813 if (mb->mbxStatus) {
2798 mempool_free( pmb, phba->mbox_mem_pool); 2814 mempool_free( pmb, phba->mbox_mem_pool);
@@ -2832,7 +2848,7 @@ lpfc_els_rsp_rps_acc(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2832 2848
2833 /* Xmit ELS RPS ACC response tag <ulpIoTag> */ 2849 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
2834 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2850 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2835 "%d:0128 Xmit ELS RPS ACC response tag x%x " 2851 "%d:0118 Xmit ELS RPS ACC response tag x%x "
2836 "Data: x%x x%x x%x x%x x%x\n", 2852 "Data: x%x x%x x%x x%x x%x\n",
2837 phba->brd_no, 2853 phba->brd_no,
2838 elsiocb->iocb.ulpIoTag, 2854 elsiocb->iocb.ulpIoTag,
@@ -2941,7 +2957,7 @@ lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
2941 2957
2942 /* Xmit ELS RPL ACC response tag <ulpIoTag> */ 2958 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
2943 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2959 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2944 "%d:0128 Xmit ELS RPL ACC response tag x%x " 2960 "%d:0120 Xmit ELS RPL ACC response tag x%x "
2945 "Data: x%x x%x x%x x%x x%x\n", 2961 "Data: x%x x%x x%x x%x x%x\n",
2946 phba->brd_no, 2962 phba->brd_no,
2947 elsiocb->iocb.ulpIoTag, 2963 elsiocb->iocb.ulpIoTag,
@@ -3102,7 +3118,7 @@ lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3102 struct lpfc_nodelist *ndlp, *next_ndlp; 3118 struct lpfc_nodelist *ndlp, *next_ndlp;
3103 3119
3104 /* FAN received */ 3120 /* FAN received */
3105 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, "%d:265 FAN received\n", 3121 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, "%d:0265 FAN received\n",
3106 phba->brd_no); 3122 phba->brd_no);
3107 3123
3108 icmd = &cmdiocb->iocb; 3124 icmd = &cmdiocb->iocb;
@@ -3282,10 +3298,9 @@ lpfc_els_timeout_handler(struct lpfc_hba *phba)
3282 } else 3298 } else
3283 lpfc_sli_release_iocbq(phba, piocb); 3299 lpfc_sli_release_iocbq(phba, piocb);
3284 } 3300 }
3285 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) { 3301 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3286 phba->els_tmofunc.expires = jiffies + HZ * timeout; 3302 mod_timer(&phba->els_tmofunc, jiffies + HZ * timeout);
3287 add_timer(&phba->els_tmofunc); 3303
3288 }
3289 spin_unlock_irq(phba->host->host_lock); 3304 spin_unlock_irq(phba->host->host_lock);
3290} 3305}
3291 3306
@@ -3442,6 +3457,8 @@ lpfc_els_unsol_event(struct lpfc_hba * phba,
3442 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) { 3457 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3443 ndlp->nlp_type |= NLP_FABRIC; 3458 ndlp->nlp_type |= NLP_FABRIC;
3444 } 3459 }
3460 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
3461 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
3445 } 3462 }
3446 3463
3447 phba->fc_stat.elsRcvFrame++; 3464 phba->fc_stat.elsRcvFrame++;
@@ -3463,13 +3480,14 @@ lpfc_els_unsol_event(struct lpfc_hba * phba,
3463 rjt_err = 1; 3480 rjt_err = 1;
3464 break; 3481 break;
3465 } 3482 }
3483 ndlp = lpfc_plogi_confirm_nport(phba, mp, ndlp);
3466 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI); 3484 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI);
3467 break; 3485 break;
3468 case ELS_CMD_FLOGI: 3486 case ELS_CMD_FLOGI:
3469 phba->fc_stat.elsRcvFLOGI++; 3487 phba->fc_stat.elsRcvFLOGI++;
3470 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode); 3488 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
3471 if (newnode) { 3489 if (newnode) {
3472 mempool_free( ndlp, phba->nlp_mem_pool); 3490 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3473 } 3491 }
3474 break; 3492 break;
3475 case ELS_CMD_LOGO: 3493 case ELS_CMD_LOGO:
@@ -3492,7 +3510,7 @@ lpfc_els_unsol_event(struct lpfc_hba * phba,
3492 phba->fc_stat.elsRcvRSCN++; 3510 phba->fc_stat.elsRcvRSCN++;
3493 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode); 3511 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
3494 if (newnode) { 3512 if (newnode) {
3495 mempool_free( ndlp, phba->nlp_mem_pool); 3513 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3496 } 3514 }
3497 break; 3515 break;
3498 case ELS_CMD_ADISC: 3516 case ELS_CMD_ADISC:
@@ -3535,28 +3553,28 @@ lpfc_els_unsol_event(struct lpfc_hba * phba,
3535 phba->fc_stat.elsRcvLIRR++; 3553 phba->fc_stat.elsRcvLIRR++;
3536 lpfc_els_rcv_lirr(phba, elsiocb, ndlp); 3554 lpfc_els_rcv_lirr(phba, elsiocb, ndlp);
3537 if (newnode) { 3555 if (newnode) {
3538 mempool_free( ndlp, phba->nlp_mem_pool); 3556 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3539 } 3557 }
3540 break; 3558 break;
3541 case ELS_CMD_RPS: 3559 case ELS_CMD_RPS:
3542 phba->fc_stat.elsRcvRPS++; 3560 phba->fc_stat.elsRcvRPS++;
3543 lpfc_els_rcv_rps(phba, elsiocb, ndlp); 3561 lpfc_els_rcv_rps(phba, elsiocb, ndlp);
3544 if (newnode) { 3562 if (newnode) {
3545 mempool_free( ndlp, phba->nlp_mem_pool); 3563 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3546 } 3564 }
3547 break; 3565 break;
3548 case ELS_CMD_RPL: 3566 case ELS_CMD_RPL:
3549 phba->fc_stat.elsRcvRPL++; 3567 phba->fc_stat.elsRcvRPL++;
3550 lpfc_els_rcv_rpl(phba, elsiocb, ndlp); 3568 lpfc_els_rcv_rpl(phba, elsiocb, ndlp);
3551 if (newnode) { 3569 if (newnode) {
3552 mempool_free( ndlp, phba->nlp_mem_pool); 3570 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3553 } 3571 }
3554 break; 3572 break;
3555 case ELS_CMD_RNID: 3573 case ELS_CMD_RNID:
3556 phba->fc_stat.elsRcvRNID++; 3574 phba->fc_stat.elsRcvRNID++;
3557 lpfc_els_rcv_rnid(phba, elsiocb, ndlp); 3575 lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
3558 if (newnode) { 3576 if (newnode) {
3559 mempool_free( ndlp, phba->nlp_mem_pool); 3577 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3560 } 3578 }
3561 break; 3579 break;
3562 default: 3580 default:
@@ -3568,7 +3586,7 @@ lpfc_els_unsol_event(struct lpfc_hba * phba,
3568 "%d:0115 Unknown ELS command x%x received from " 3586 "%d:0115 Unknown ELS command x%x received from "
3569 "NPORT x%x\n", phba->brd_no, cmd, did); 3587 "NPORT x%x\n", phba->brd_no, cmd, did);
3570 if (newnode) { 3588 if (newnode) {
3571 mempool_free( ndlp, phba->nlp_mem_pool); 3589 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3572 } 3590 }
3573 break; 3591 break;
3574 } 3592 }
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index adb086009ae0..b2f1552f1848 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -1084,7 +1084,7 @@ lpfc_register_remote_port(struct lpfc_hba * phba,
1084 fc_remote_port_rolechg(rport, rport_ids.roles); 1084 fc_remote_port_rolechg(rport, rport_ids.roles);
1085 1085
1086 if ((rport->scsi_target_id != -1) && 1086 if ((rport->scsi_target_id != -1) &&
1087 (rport->scsi_target_id < MAX_FCP_TARGET)) { 1087 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
1088 ndlp->nlp_sid = rport->scsi_target_id; 1088 ndlp->nlp_sid = rport->scsi_target_id;
1089 } 1089 }
1090 1090
@@ -1313,7 +1313,7 @@ lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1313 if ((rport_add == mapped) && 1313 if ((rport_add == mapped) &&
1314 ((!nlp->rport) || 1314 ((!nlp->rport) ||
1315 (nlp->rport->scsi_target_id == -1) || 1315 (nlp->rport->scsi_target_id == -1) ||
1316 (nlp->rport->scsi_target_id >= MAX_FCP_TARGET))) { 1316 (nlp->rport->scsi_target_id >= LPFC_MAX_TARGET))) {
1317 nlp->nlp_state = NLP_STE_UNMAPPED_NODE; 1317 nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1318 spin_lock_irq(phba->host->host_lock); 1318 spin_lock_irq(phba->host->host_lock);
1319 nlp->nlp_flag |= NLP_TGT_NO_SCSIID; 1319 nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
@@ -1557,6 +1557,8 @@ lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1557 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 1557 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1558 } 1558 }
1559 } 1559 }
1560
1561 spin_lock_irq(phba->host->host_lock);
1560 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { 1562 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1561 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) && 1563 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1562 (ndlp == (struct lpfc_nodelist *) mb->context2)) { 1564 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
@@ -1569,6 +1571,7 @@ lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1569 mempool_free(mb, phba->mbox_mem_pool); 1571 mempool_free(mb, phba->mbox_mem_pool);
1570 } 1572 }
1571 } 1573 }
1574 spin_unlock_irq(phba->host->host_lock);
1572 1575
1573 lpfc_els_abort(phba,ndlp,0); 1576 lpfc_els_abort(phba,ndlp,0);
1574 spin_lock_irq(phba->host->host_lock); 1577 spin_lock_irq(phba->host->host_lock);
@@ -1782,7 +1785,7 @@ lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1782 /* LOG change to REGLOGIN */ 1785 /* LOG change to REGLOGIN */
1783 /* FIND node DID reglogin */ 1786 /* FIND node DID reglogin */
1784 lpfc_printf_log(phba, KERN_INFO, LOG_NODE, 1787 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1785 "%d:0931 FIND node DID reglogin" 1788 "%d:0901 FIND node DID reglogin"
1786 " Data: x%p x%x x%x x%x\n", 1789 " Data: x%p x%x x%x x%x\n",
1787 phba->brd_no, 1790 phba->brd_no,
1788 ndlp, ndlp->nlp_DID, 1791 ndlp, ndlp->nlp_DID,
@@ -1805,7 +1808,7 @@ lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1805 /* LOG change to PRLI */ 1808 /* LOG change to PRLI */
1806 /* FIND node DID prli */ 1809 /* FIND node DID prli */
1807 lpfc_printf_log(phba, KERN_INFO, LOG_NODE, 1810 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1808 "%d:0931 FIND node DID prli " 1811 "%d:0902 FIND node DID prli "
1809 "Data: x%p x%x x%x x%x\n", 1812 "Data: x%p x%x x%x x%x\n",
1810 phba->brd_no, 1813 phba->brd_no,
1811 ndlp, ndlp->nlp_DID, 1814 ndlp, ndlp->nlp_DID,
@@ -1828,7 +1831,7 @@ lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1828 /* LOG change to NPR */ 1831 /* LOG change to NPR */
1829 /* FIND node DID npr */ 1832 /* FIND node DID npr */
1830 lpfc_printf_log(phba, KERN_INFO, LOG_NODE, 1833 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1831 "%d:0931 FIND node DID npr " 1834 "%d:0903 FIND node DID npr "
1832 "Data: x%p x%x x%x x%x\n", 1835 "Data: x%p x%x x%x x%x\n",
1833 phba->brd_no, 1836 phba->brd_no,
1834 ndlp, ndlp->nlp_DID, 1837 ndlp, ndlp->nlp_DID,
@@ -1851,7 +1854,7 @@ lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1851 /* LOG change to UNUSED */ 1854 /* LOG change to UNUSED */
1852 /* FIND node DID unused */ 1855 /* FIND node DID unused */
1853 lpfc_printf_log(phba, KERN_INFO, LOG_NODE, 1856 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1854 "%d:0931 FIND node DID unused " 1857 "%d:0905 FIND node DID unused "
1855 "Data: x%p x%x x%x x%x\n", 1858 "Data: x%p x%x x%x x%x\n",
1856 phba->brd_no, 1859 phba->brd_no,
1857 ndlp, ndlp->nlp_DID, 1860 ndlp, ndlp->nlp_DID,
@@ -2335,7 +2338,7 @@ lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2335 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 2338 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2336 if (!initlinkmbox) { 2339 if (!initlinkmbox) {
2337 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, 2340 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2338 "%d:0226 Device Discovery " 2341 "%d:0206 Device Discovery "
2339 "completion error\n", 2342 "completion error\n",
2340 phba->brd_no); 2343 phba->brd_no);
2341 phba->hba_state = LPFC_HBA_ERROR; 2344 phba->hba_state = LPFC_HBA_ERROR;
@@ -2365,7 +2368,7 @@ lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2365 if (!clearlambox) { 2368 if (!clearlambox) {
2366 clrlaerr = 1; 2369 clrlaerr = 1;
2367 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, 2370 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2368 "%d:0226 Device Discovery " 2371 "%d:0207 Device Discovery "
2369 "completion error\n", 2372 "completion error\n",
2370 phba->brd_no); 2373 phba->brd_no);
2371 phba->hba_state = LPFC_HBA_ERROR; 2374 phba->hba_state = LPFC_HBA_ERROR;
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 5a28d9bf8e4d..f6948ffe689a 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -71,6 +71,7 @@ lpfc_config_port_prep(struct lpfc_hba * phba)
71 uint16_t offset = 0; 71 uint16_t offset = 0;
72 static char licensed[56] = 72 static char licensed[56] =
73 "key unlock for use with gnu public licensed code only\0"; 73 "key unlock for use with gnu public licensed code only\0";
74 static int init_key = 1;
74 75
75 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 76 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
76 if (!pmb) { 77 if (!pmb) {
@@ -82,10 +83,13 @@ lpfc_config_port_prep(struct lpfc_hba * phba)
82 phba->hba_state = LPFC_INIT_MBX_CMDS; 83 phba->hba_state = LPFC_INIT_MBX_CMDS;
83 84
84 if (lpfc_is_LC_HBA(phba->pcidev->device)) { 85 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
85 uint32_t *ptext = (uint32_t *) licensed; 86 if (init_key) {
87 uint32_t *ptext = (uint32_t *) licensed;
86 88
87 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) 89 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
88 *ptext = cpu_to_be32(*ptext); 90 *ptext = cpu_to_be32(*ptext);
91 init_key = 0;
92 }
89 93
90 lpfc_read_nv(phba, pmb); 94 lpfc_read_nv(phba, pmb);
91 memset((char*)mb->un.varRDnvp.rsvd3, 0, 95 memset((char*)mb->un.varRDnvp.rsvd3, 0,
@@ -405,19 +409,26 @@ lpfc_config_port_post(struct lpfc_hba * phba)
405 } 409 }
406 /* MBOX buffer will be freed in mbox compl */ 410 /* MBOX buffer will be freed in mbox compl */
407 411
408 i = 0; 412 return (0);
413}
414
415static int
416lpfc_discovery_wait(struct lpfc_hba *phba)
417{
418 int i = 0;
419
409 while ((phba->hba_state != LPFC_HBA_READY) || 420 while ((phba->hba_state != LPFC_HBA_READY) ||
410 (phba->num_disc_nodes) || (phba->fc_prli_sent) || 421 (phba->num_disc_nodes) || (phba->fc_prli_sent) ||
411 ((phba->fc_map_cnt == 0) && (i<2)) || 422 ((phba->fc_map_cnt == 0) && (i<2)) ||
412 (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) { 423 (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE)) {
413 /* Check every second for 30 retries. */ 424 /* Check every second for 30 retries. */
414 i++; 425 i++;
415 if (i > 30) { 426 if (i > 30) {
416 break; 427 return -ETIMEDOUT;
417 } 428 }
418 if ((i >= 15) && (phba->hba_state <= LPFC_LINK_DOWN)) { 429 if ((i >= 15) && (phba->hba_state <= LPFC_LINK_DOWN)) {
419 /* The link is down. Set linkdown timeout */ 430 /* The link is down. Set linkdown timeout */
420 break; 431 return -ETIMEDOUT;
421 } 432 }
422 433
423 /* Delay for 1 second to give discovery time to complete. */ 434 /* Delay for 1 second to give discovery time to complete. */
@@ -425,12 +436,7 @@ lpfc_config_port_post(struct lpfc_hba * phba)
425 436
426 } 437 }
427 438
428 /* Since num_disc_nodes keys off of PLOGI, delay a bit to let 439 return 0;
429 * any potential PRLIs to flush thru the SLI sub-system.
430 */
431 msleep(50);
432
433 return (0);
434} 440}
435 441
436/************************************************************************/ 442/************************************************************************/
@@ -939,12 +945,12 @@ lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp)
939 "10-port ", "PCIe"}; 945 "10-port ", "PCIe"};
940 break; 946 break;
941 default: 947 default:
942 m = (typeof(m)){ 0 }; 948 m = (typeof(m)){ NULL };
943 break; 949 break;
944 } 950 }
945 break; 951 break;
946 default: 952 default:
947 m = (typeof(m)){ 0 }; 953 m = (typeof(m)){ NULL };
948 break; 954 break;
949 } 955 }
950 956
@@ -1339,7 +1345,8 @@ lpfc_offline(struct lpfc_hba * phba)
1339 struct lpfc_sli_ring *pring; 1345 struct lpfc_sli_ring *pring;
1340 struct lpfc_sli *psli; 1346 struct lpfc_sli *psli;
1341 unsigned long iflag; 1347 unsigned long iflag;
1342 int i = 0; 1348 int i;
1349 int cnt = 0;
1343 1350
1344 if (!phba) 1351 if (!phba)
1345 return 0; 1352 return 0;
@@ -1348,20 +1355,31 @@ lpfc_offline(struct lpfc_hba * phba)
1348 return 0; 1355 return 0;
1349 1356
1350 psli = &phba->sli; 1357 psli = &phba->sli;
1351 pring = &psli->ring[psli->fcp_ring];
1352 1358
1353 lpfc_linkdown(phba); 1359 lpfc_linkdown(phba);
1360 lpfc_sli_flush_mbox_queue(phba);
1354 1361
1355 /* The linkdown event takes 30 seconds to timeout. */ 1362 for (i = 0; i < psli->num_rings; i++) {
1356 while (pring->txcmplq_cnt) { 1363 pring = &psli->ring[i];
1357 mdelay(10); 1364 /* The linkdown event takes 30 seconds to timeout. */
1358 if (i++ > 3000) 1365 while (pring->txcmplq_cnt) {
1359 break; 1366 mdelay(10);
1367 if (cnt++ > 3000) {
1368 lpfc_printf_log(phba,
1369 KERN_WARNING, LOG_INIT,
1370 "%d:0466 Outstanding IO when "
1371 "bringing Adapter offline\n",
1372 phba->brd_no);
1373 break;
1374 }
1375 }
1360 } 1376 }
1361 1377
1378
1362 /* stop all timers associated with this hba */ 1379 /* stop all timers associated with this hba */
1363 lpfc_stop_timer(phba); 1380 lpfc_stop_timer(phba);
1364 phba->work_hba_events = 0; 1381 phba->work_hba_events = 0;
1382 phba->work_ha = 0;
1365 1383
1366 lpfc_printf_log(phba, 1384 lpfc_printf_log(phba,
1367 KERN_WARNING, 1385 KERN_WARNING,
@@ -1451,7 +1469,6 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1451 goto out_put_host; 1469 goto out_put_host;
1452 1470
1453 host->unique_id = phba->brd_no; 1471 host->unique_id = phba->brd_no;
1454 init_MUTEX(&phba->hba_can_block);
1455 INIT_LIST_HEAD(&phba->ctrspbuflist); 1472 INIT_LIST_HEAD(&phba->ctrspbuflist);
1456 INIT_LIST_HEAD(&phba->rnidrspbuflist); 1473 INIT_LIST_HEAD(&phba->rnidrspbuflist);
1457 INIT_LIST_HEAD(&phba->freebufList); 1474 INIT_LIST_HEAD(&phba->freebufList);
@@ -1600,7 +1617,11 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1600 goto out_free_iocbq; 1617 goto out_free_iocbq;
1601 } 1618 }
1602 1619
1603 /* We can rely on a queue depth attribute only after SLI HBA setup */ 1620 /*
1621 * Set initial can_queue value since 0 is no longer supported and
1622 * scsi_add_host will fail. This will be adjusted later based on the
1623 * max xri value determined in hba setup.
1624 */
1604 host->can_queue = phba->cfg_hba_queue_depth - 10; 1625 host->can_queue = phba->cfg_hba_queue_depth - 10;
1605 1626
1606 /* Tell the midlayer we support 16 byte commands */ 1627 /* Tell the midlayer we support 16 byte commands */
@@ -1640,6 +1661,14 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1640 goto out_free_irq; 1661 goto out_free_irq;
1641 } 1662 }
1642 1663
1664 /*
1665 * hba setup may have changed the hba_queue_depth so we need to adjust
1666 * the value of can_queue.
1667 */
1668 host->can_queue = phba->cfg_hba_queue_depth - 10;
1669
1670 lpfc_discovery_wait(phba);
1671
1643 if (phba->cfg_poll & DISABLE_FCP_RING_INT) { 1672 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
1644 spin_lock_irq(phba->host->host_lock); 1673 spin_lock_irq(phba->host->host_lock);
1645 lpfc_poll_start_timer(phba); 1674 lpfc_poll_start_timer(phba);
diff --git a/drivers/scsi/lpfc/lpfc_mbox.c b/drivers/scsi/lpfc/lpfc_mbox.c
index e42f22aaf71b..4d016c2a1b26 100644
--- a/drivers/scsi/lpfc/lpfc_mbox.c
+++ b/drivers/scsi/lpfc/lpfc_mbox.c
@@ -651,3 +651,19 @@ lpfc_mbox_get(struct lpfc_hba * phba)
651 651
652 return mbq; 652 return mbq;
653} 653}
654
655int
656lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
657{
658 switch (cmd) {
659 case MBX_WRITE_NV: /* 0x03 */
660 case MBX_UPDATE_CFG: /* 0x1B */
661 case MBX_DOWN_LOAD: /* 0x1C */
662 case MBX_DEL_LD_ENTRY: /* 0x1D */
663 case MBX_LOAD_AREA: /* 0x81 */
664 case MBX_FLASH_WR_ULA: /* 0x98 */
665 case MBX_LOAD_EXP_ROM: /* 0x9C */
666 return LPFC_MBOX_TMO_FLASH_CMD;
667 }
668 return LPFC_MBOX_TMO;
669}
diff --git a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c
index 07017658ac56..066292d3995a 100644
--- a/drivers/scsi/lpfc/lpfc_mem.c
+++ b/drivers/scsi/lpfc/lpfc_mem.c
@@ -133,6 +133,11 @@ lpfc_mem_free(struct lpfc_hba * phba)
133 133
134 pci_pool_destroy(phba->lpfc_scsi_dma_buf_pool); 134 pci_pool_destroy(phba->lpfc_scsi_dma_buf_pool);
135 pci_pool_destroy(phba->lpfc_mbuf_pool); 135 pci_pool_destroy(phba->lpfc_mbuf_pool);
136
137 /* Free the iocb lookup array */
138 kfree(psli->iocbq_lookup);
139 psli->iocbq_lookup = NULL;
140
136} 141}
137 142
138void * 143void *
diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c
index 27d60ad897cd..20449a8dd53d 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -179,7 +179,7 @@ lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
179 179
180 /* Abort outstanding I/O on NPort <nlp_DID> */ 180 /* Abort outstanding I/O on NPort <nlp_DID> */
181 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 181 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
182 "%d:0201 Abort outstanding I/O on NPort x%x " 182 "%d:0205 Abort outstanding I/O on NPort x%x "
183 "Data: x%x x%x x%x\n", 183 "Data: x%x x%x x%x\n",
184 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag, 184 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
185 ndlp->nlp_state, ndlp->nlp_rpi); 185 ndlp->nlp_state, ndlp->nlp_rpi);
@@ -393,6 +393,20 @@ lpfc_rcv_plogi(struct lpfc_hba * phba,
393 mbox->context2 = ndlp; 393 mbox->context2 = ndlp;
394 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI); 394 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
395 395
396 /*
397 * If there is an outstanding PLOGI issued, abort it before
398 * sending ACC rsp for received PLOGI. If pending plogi
399 * is not canceled here, the plogi will be rejected by
400 * remote port and will be retried. On a configuration with
401 * single discovery thread, this will cause a huge delay in
402 * discovery. Also this will cause multiple state machines
403 * running in parallel for this node.
404 */
405 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
406 /* software abort outstanding PLOGI */
407 lpfc_els_abort(phba, ndlp, 1);
408 }
409
396 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0); 410 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
397 return 1; 411 return 1;
398 412
@@ -1110,6 +1124,17 @@ lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1110 phba->brd_no, 1124 phba->brd_no,
1111 did, mb->mbxStatus, phba->hba_state); 1125 did, mb->mbxStatus, phba->hba_state);
1112 1126
1127 /*
1128 * If RegLogin failed due to lack of HBA resources do not
1129 * retry discovery.
1130 */
1131 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1132 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
1133 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
1134 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
1135 return ndlp->nlp_state;
1136 }
1137
1113 /* Put ndlp in npr list set plogi timer for 1 sec */ 1138 /* Put ndlp in npr list set plogi timer for 1 sec */
1114 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1); 1139 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1115 spin_lock_irq(phba->host->host_lock); 1140 spin_lock_irq(phba->host->host_lock);
@@ -1590,7 +1615,13 @@ lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
1590 1615
1591 lpfc_rcv_padisc(phba, ndlp, cmdiocb); 1616 lpfc_rcv_padisc(phba, ndlp, cmdiocb);
1592 1617
1593 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { 1618 /*
1619 * Do not start discovery if discovery is about to start
1620 * or discovery in progress for this node. Starting discovery
1621 * here will affect the counting of discovery threads.
1622 */
1623 if ((!(ndlp->nlp_flag & NLP_DELAY_TMO)) &&
1624 (ndlp->nlp_flag & NLP_NPR_2B_DISC)){
1594 if (ndlp->nlp_flag & NLP_NPR_ADISC) { 1625 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1595 ndlp->nlp_prev_state = NLP_STE_NPR_NODE; 1626 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1596 ndlp->nlp_state = NLP_STE_ADISC_ISSUE; 1627 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 7dc4c2e6bed2..a8816a8738f8 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -21,6 +21,7 @@
21 21
22#include <linux/pci.h> 22#include <linux/pci.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/delay.h>
24 25
25#include <scsi/scsi.h> 26#include <scsi/scsi.h>
26#include <scsi/scsi_device.h> 27#include <scsi/scsi_device.h>
@@ -41,20 +42,6 @@
41#define LPFC_ABORT_WAIT 2 42#define LPFC_ABORT_WAIT 2
42 43
43 44
44static inline void
45lpfc_block_requests(struct lpfc_hba * phba)
46{
47 down(&phba->hba_can_block);
48 scsi_block_requests(phba->host);
49}
50
51static inline void
52lpfc_unblock_requests(struct lpfc_hba * phba)
53{
54 scsi_unblock_requests(phba->host);
55 up(&phba->hba_can_block);
56}
57
58/* 45/*
59 * This routine allocates a scsi buffer, which contains all the necessary 46 * This routine allocates a scsi buffer, which contains all the necessary
60 * information needed to initiate a SCSI I/O. The non-DMAable buffer region 47 * information needed to initiate a SCSI I/O. The non-DMAable buffer region
@@ -167,22 +154,6 @@ static void
167lpfc_release_scsi_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb) 154lpfc_release_scsi_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb)
168{ 155{
169 unsigned long iflag = 0; 156 unsigned long iflag = 0;
170 /*
171 * There are only two special cases to consider. (1) the scsi command
172 * requested scatter-gather usage or (2) the scsi command allocated
173 * a request buffer, but did not request use_sg. There is a third
174 * case, but it does not require resource deallocation.
175 */
176 if ((psb->seg_cnt > 0) && (psb->pCmd->use_sg)) {
177 dma_unmap_sg(&phba->pcidev->dev, psb->pCmd->request_buffer,
178 psb->seg_cnt, psb->pCmd->sc_data_direction);
179 } else {
180 if ((psb->nonsg_phys) && (psb->pCmd->request_bufflen)) {
181 dma_unmap_single(&phba->pcidev->dev, psb->nonsg_phys,
182 psb->pCmd->request_bufflen,
183 psb->pCmd->sc_data_direction);
184 }
185 }
186 157
187 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); 158 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
188 psb->pCmd = NULL; 159 psb->pCmd = NULL;
@@ -296,6 +267,27 @@ lpfc_scsi_prep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * lpfc_cmd)
296} 267}
297 268
298static void 269static void
270lpfc_scsi_unprep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb)
271{
272 /*
273 * There are only two special cases to consider. (1) the scsi command
274 * requested scatter-gather usage or (2) the scsi command allocated
275 * a request buffer, but did not request use_sg. There is a third
276 * case, but it does not require resource deallocation.
277 */
278 if ((psb->seg_cnt > 0) && (psb->pCmd->use_sg)) {
279 dma_unmap_sg(&phba->pcidev->dev, psb->pCmd->request_buffer,
280 psb->seg_cnt, psb->pCmd->sc_data_direction);
281 } else {
282 if ((psb->nonsg_phys) && (psb->pCmd->request_bufflen)) {
283 dma_unmap_single(&phba->pcidev->dev, psb->nonsg_phys,
284 psb->pCmd->request_bufflen,
285 psb->pCmd->sc_data_direction);
286 }
287 }
288}
289
290static void
299lpfc_handle_fcp_err(struct lpfc_scsi_buf *lpfc_cmd) 291lpfc_handle_fcp_err(struct lpfc_scsi_buf *lpfc_cmd)
300{ 292{
301 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; 293 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
@@ -468,6 +460,7 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
468 cmd->scsi_done(cmd); 460 cmd->scsi_done(cmd);
469 461
470 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { 462 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
463 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
471 lpfc_release_scsi_buf(phba, lpfc_cmd); 464 lpfc_release_scsi_buf(phba, lpfc_cmd);
472 return; 465 return;
473 } 466 }
@@ -525,6 +518,7 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
525 } 518 }
526 } 519 }
527 520
521 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
528 lpfc_release_scsi_buf(phba, lpfc_cmd); 522 lpfc_release_scsi_buf(phba, lpfc_cmd);
529} 523}
530 524
@@ -623,6 +617,7 @@ lpfc_scsi_prep_cmnd(struct lpfc_hba * phba, struct lpfc_scsi_buf * lpfc_cmd,
623static int 617static int
624lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba, 618lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba,
625 struct lpfc_scsi_buf *lpfc_cmd, 619 struct lpfc_scsi_buf *lpfc_cmd,
620 unsigned int lun,
626 uint8_t task_mgmt_cmd) 621 uint8_t task_mgmt_cmd)
627{ 622{
628 struct lpfc_sli *psli; 623 struct lpfc_sli *psli;
@@ -641,8 +636,7 @@ lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba,
641 piocb = &piocbq->iocb; 636 piocb = &piocbq->iocb;
642 637
643 fcp_cmnd = lpfc_cmd->fcp_cmnd; 638 fcp_cmnd = lpfc_cmd->fcp_cmnd;
644 int_to_scsilun(lpfc_cmd->pCmd->device->lun, 639 int_to_scsilun(lun, &lpfc_cmd->fcp_cmnd->fcp_lun);
645 &lpfc_cmd->fcp_cmnd->fcp_lun);
646 fcp_cmnd->fcpCntl2 = task_mgmt_cmd; 640 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
647 641
648 piocb->ulpCommand = CMD_FCP_ICMND64_CR; 642 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
@@ -669,14 +663,16 @@ lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba,
669 663
670static int 664static int
671lpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba, 665lpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba,
672 unsigned tgt_id, struct lpfc_rport_data *rdata) 666 unsigned tgt_id, unsigned int lun,
667 struct lpfc_rport_data *rdata)
673{ 668{
674 struct lpfc_iocbq *iocbq; 669 struct lpfc_iocbq *iocbq;
675 struct lpfc_iocbq *iocbqrsp; 670 struct lpfc_iocbq *iocbqrsp;
676 int ret; 671 int ret;
677 672
678 lpfc_cmd->rdata = rdata; 673 lpfc_cmd->rdata = rdata;
679 ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, FCP_TARGET_RESET); 674 ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, lun,
675 FCP_TARGET_RESET);
680 if (!ret) 676 if (!ret)
681 return FAILED; 677 return FAILED;
682 678
@@ -836,6 +832,7 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
836 return 0; 832 return 0;
837 833
838 out_host_busy_free_buf: 834 out_host_busy_free_buf:
835 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
839 lpfc_release_scsi_buf(phba, lpfc_cmd); 836 lpfc_release_scsi_buf(phba, lpfc_cmd);
840 out_host_busy: 837 out_host_busy:
841 return SCSI_MLQUEUE_HOST_BUSY; 838 return SCSI_MLQUEUE_HOST_BUSY;
@@ -845,6 +842,21 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
845 return 0; 842 return 0;
846} 843}
847 844
845static void
846lpfc_block_error_handler(struct scsi_cmnd *cmnd)
847{
848 struct Scsi_Host *shost = cmnd->device->host;
849 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
850
851 spin_lock_irq(shost->host_lock);
852 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
853 spin_unlock_irq(shost->host_lock);
854 msleep(1000);
855 spin_lock_irq(shost->host_lock);
856 }
857 spin_unlock_irq(shost->host_lock);
858 return;
859}
848 860
849static int 861static int
850lpfc_abort_handler(struct scsi_cmnd *cmnd) 862lpfc_abort_handler(struct scsi_cmnd *cmnd)
@@ -859,7 +871,7 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
859 unsigned int loop_count = 0; 871 unsigned int loop_count = 0;
860 int ret = SUCCESS; 872 int ret = SUCCESS;
861 873
862 lpfc_block_requests(phba); 874 lpfc_block_error_handler(cmnd);
863 spin_lock_irq(shost->host_lock); 875 spin_lock_irq(shost->host_lock);
864 876
865 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble; 877 lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
@@ -945,7 +957,6 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
945 cmnd->device->lun, cmnd->serial_number); 957 cmnd->device->lun, cmnd->serial_number);
946 958
947 spin_unlock_irq(shost->host_lock); 959 spin_unlock_irq(shost->host_lock);
948 lpfc_unblock_requests(phba);
949 960
950 return ret; 961 return ret;
951} 962}
@@ -963,7 +974,7 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
963 int ret = FAILED; 974 int ret = FAILED;
964 int cnt, loopcnt; 975 int cnt, loopcnt;
965 976
966 lpfc_block_requests(phba); 977 lpfc_block_error_handler(cmnd);
967 spin_lock_irq(shost->host_lock); 978 spin_lock_irq(shost->host_lock);
968 /* 979 /*
969 * If target is not in a MAPPED state, delay the reset until 980 * If target is not in a MAPPED state, delay the reset until
@@ -986,12 +997,12 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
986 if (lpfc_cmd == NULL) 997 if (lpfc_cmd == NULL)
987 goto out; 998 goto out;
988 999
989 lpfc_cmd->pCmd = cmnd;
990 lpfc_cmd->timeout = 60; 1000 lpfc_cmd->timeout = 60;
991 lpfc_cmd->scsi_hba = phba; 1001 lpfc_cmd->scsi_hba = phba;
992 lpfc_cmd->rdata = rdata; 1002 lpfc_cmd->rdata = rdata;
993 1003
994 ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, FCP_LUN_RESET); 1004 ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, cmnd->device->lun,
1005 FCP_LUN_RESET);
995 if (!ret) 1006 if (!ret)
996 goto out_free_scsi_buf; 1007 goto out_free_scsi_buf;
997 1008
@@ -1018,7 +1029,6 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
1018 cmd_status = iocbqrsp->iocb.ulpStatus; 1029 cmd_status = iocbqrsp->iocb.ulpStatus;
1019 1030
1020 lpfc_sli_release_iocbq(phba, iocbqrsp); 1031 lpfc_sli_release_iocbq(phba, iocbqrsp);
1021 lpfc_release_scsi_buf(phba, lpfc_cmd);
1022 1032
1023 /* 1033 /*
1024 * All outstanding txcmplq I/Os should have been aborted by the device. 1034 * All outstanding txcmplq I/Os should have been aborted by the device.
@@ -1057,6 +1067,8 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
1057 } 1067 }
1058 1068
1059out_free_scsi_buf: 1069out_free_scsi_buf:
1070 lpfc_release_scsi_buf(phba, lpfc_cmd);
1071
1060 lpfc_printf_log(phba, KERN_ERR, LOG_FCP, 1072 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
1061 "%d:0713 SCSI layer issued LUN reset (%d, %d) " 1073 "%d:0713 SCSI layer issued LUN reset (%d, %d) "
1062 "Data: x%x x%x x%x\n", 1074 "Data: x%x x%x x%x\n",
@@ -1065,7 +1077,6 @@ out_free_scsi_buf:
1065 1077
1066out: 1078out:
1067 spin_unlock_irq(shost->host_lock); 1079 spin_unlock_irq(shost->host_lock);
1068 lpfc_unblock_requests(phba);
1069 return ret; 1080 return ret;
1070} 1081}
1071 1082
@@ -1080,7 +1091,7 @@ lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
1080 int cnt, loopcnt; 1091 int cnt, loopcnt;
1081 struct lpfc_scsi_buf * lpfc_cmd; 1092 struct lpfc_scsi_buf * lpfc_cmd;
1082 1093
1083 lpfc_block_requests(phba); 1094 lpfc_block_error_handler(cmnd);
1084 spin_lock_irq(shost->host_lock); 1095 spin_lock_irq(shost->host_lock);
1085 1096
1086 lpfc_cmd = lpfc_get_scsi_buf(phba); 1097 lpfc_cmd = lpfc_get_scsi_buf(phba);
@@ -1089,7 +1100,6 @@ lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
1089 1100
1090 /* The lpfc_cmd storage is reused. Set all loop invariants. */ 1101 /* The lpfc_cmd storage is reused. Set all loop invariants. */
1091 lpfc_cmd->timeout = 60; 1102 lpfc_cmd->timeout = 60;
1092 lpfc_cmd->pCmd = cmnd;
1093 lpfc_cmd->scsi_hba = phba; 1103 lpfc_cmd->scsi_hba = phba;
1094 1104
1095 /* 1105 /*
@@ -1097,7 +1107,7 @@ lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
1097 * targets known to the driver. Should any target reset 1107 * targets known to the driver. Should any target reset
1098 * fail, this routine returns failure to the midlayer. 1108 * fail, this routine returns failure to the midlayer.
1099 */ 1109 */
1100 for (i = 0; i < MAX_FCP_TARGET; i++) { 1110 for (i = 0; i < LPFC_MAX_TARGET; i++) {
1101 /* Search the mapped list for this target ID */ 1111 /* Search the mapped list for this target ID */
1102 match = 0; 1112 match = 0;
1103 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { 1113 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
@@ -1109,11 +1119,11 @@ lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
1109 if (!match) 1119 if (!match)
1110 continue; 1120 continue;
1111 1121
1112 ret = lpfc_scsi_tgt_reset(lpfc_cmd, phba, 1122 ret = lpfc_scsi_tgt_reset(lpfc_cmd, phba, i, cmnd->device->lun,
1113 i, ndlp->rport->dd_data); 1123 ndlp->rport->dd_data);
1114 if (ret != SUCCESS) { 1124 if (ret != SUCCESS) {
1115 lpfc_printf_log(phba, KERN_ERR, LOG_FCP, 1125 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
1116 "%d:0713 Bus Reset on target %d failed\n", 1126 "%d:0700 Bus Reset on target %d failed\n",
1117 phba->brd_no, i); 1127 phba->brd_no, i);
1118 err_count++; 1128 err_count++;
1119 } 1129 }
@@ -1163,7 +1173,6 @@ lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
1163 phba->brd_no, ret); 1173 phba->brd_no, ret);
1164out: 1174out:
1165 spin_unlock_irq(shost->host_lock); 1175 spin_unlock_irq(shost->host_lock);
1166 lpfc_unblock_requests(phba);
1167 return ret; 1176 return ret;
1168} 1177}
1169 1178
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index bb69a7a1ec59..70f4d5a1348e 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -191,35 +191,12 @@ static int
191lpfc_sli_ringtxcmpl_put(struct lpfc_hba * phba, 191lpfc_sli_ringtxcmpl_put(struct lpfc_hba * phba,
192 struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocb) 192 struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocb)
193{ 193{
194 uint16_t iotag;
195
196 list_add_tail(&piocb->list, &pring->txcmplq); 194 list_add_tail(&piocb->list, &pring->txcmplq);
197 pring->txcmplq_cnt++; 195 pring->txcmplq_cnt++;
198 if (unlikely(pring->ringno == LPFC_ELS_RING)) 196 if (unlikely(pring->ringno == LPFC_ELS_RING))
199 mod_timer(&phba->els_tmofunc, 197 mod_timer(&phba->els_tmofunc,
200 jiffies + HZ * (phba->fc_ratov << 1)); 198 jiffies + HZ * (phba->fc_ratov << 1));
201 199
202 if (pring->fast_lookup) {
203 /* Setup fast lookup based on iotag for completion */
204 iotag = piocb->iocb.ulpIoTag;
205 if (iotag && (iotag < pring->fast_iotag))
206 *(pring->fast_lookup + iotag) = piocb;
207 else {
208
209 /* Cmd ring <ringno> put: iotag <iotag> greater then
210 configured max <fast_iotag> wd0 <icmd> */
211 lpfc_printf_log(phba,
212 KERN_ERR,
213 LOG_SLI,
214 "%d:0316 Cmd ring %d put: iotag x%x "
215 "greater then configured max x%x "
216 "wd0 x%x\n",
217 phba->brd_no,
218 pring->ringno, iotag,
219 pring->fast_iotag,
220 *(((uint32_t *)(&piocb->iocb)) + 7));
221 }
222 }
223 return (0); 200 return (0);
224} 201}
225 202
@@ -343,7 +320,8 @@ lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
343 kfree(old_arr); 320 kfree(old_arr);
344 return iotag; 321 return iotag;
345 } 322 }
346 } 323 } else
324 spin_unlock_irq(phba->host->host_lock);
347 325
348 lpfc_printf_log(phba, KERN_ERR,LOG_SLI, 326 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
349 "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n", 327 "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n",
@@ -601,7 +579,7 @@ lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
601 /* Stray Mailbox Interrupt, mbxCommand <cmd> mbxStatus 579 /* Stray Mailbox Interrupt, mbxCommand <cmd> mbxStatus
602 <status> */ 580 <status> */
603 lpfc_printf_log(phba, 581 lpfc_printf_log(phba,
604 KERN_ERR, 582 KERN_WARNING,
605 LOG_MBOX | LOG_SLI, 583 LOG_MBOX | LOG_SLI,
606 "%d:0304 Stray Mailbox Interrupt " 584 "%d:0304 Stray Mailbox Interrupt "
607 "mbxCommand x%x mbxStatus x%x\n", 585 "mbxCommand x%x mbxStatus x%x\n",
@@ -992,9 +970,11 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
992 * resources need to be recovered. 970 * resources need to be recovered.
993 */ 971 */
994 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { 972 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
995 printk(KERN_INFO "%s: IOCB cmd 0x%x processed." 973 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
996 " Skipping completion\n", __FUNCTION__, 974 "%d:0314 IOCB cmd 0x%x"
997 irsp->ulpCommand); 975 " processed. Skipping"
976 " completion", phba->brd_no,
977 irsp->ulpCommand);
998 break; 978 break;
999 } 979 }
1000 980
@@ -1127,7 +1107,7 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
1127 if (unlikely(irsp->ulpStatus)) { 1107 if (unlikely(irsp->ulpStatus)) {
1128 /* Rsp ring <ringno> error: IOCB */ 1108 /* Rsp ring <ringno> error: IOCB */
1129 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, 1109 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1130 "%d:0326 Rsp Ring %d error: IOCB Data: " 1110 "%d:0336 Rsp Ring %d error: IOCB Data: "
1131 "x%x x%x x%x x%x x%x x%x x%x x%x\n", 1111 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1132 phba->brd_no, pring->ringno, 1112 phba->brd_no, pring->ringno,
1133 irsp->un.ulpWord[0], irsp->un.ulpWord[1], 1113 irsp->un.ulpWord[0], irsp->un.ulpWord[1],
@@ -1145,9 +1125,11 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
1145 * resources need to be recovered. 1125 * resources need to be recovered.
1146 */ 1126 */
1147 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { 1127 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1148 printk(KERN_INFO "%s: IOCB cmd 0x%x processed. " 1128 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1149 "Skipping completion\n", __FUNCTION__, 1129 "%d:0333 IOCB cmd 0x%x"
1150 irsp->ulpCommand); 1130 " processed. Skipping"
1131 " completion\n", phba->brd_no,
1132 irsp->ulpCommand);
1151 break; 1133 break;
1152 } 1134 }
1153 1135
@@ -1178,7 +1160,7 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
1178 } else { 1160 } else {
1179 /* Unknown IOCB command */ 1161 /* Unknown IOCB command */
1180 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 1162 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1181 "%d:0321 Unknown IOCB command " 1163 "%d:0334 Unknown IOCB command "
1182 "Data: x%x, x%x x%x x%x x%x\n", 1164 "Data: x%x, x%x x%x x%x x%x\n",
1183 phba->brd_no, type, irsp->ulpCommand, 1165 phba->brd_no, type, irsp->ulpCommand,
1184 irsp->ulpStatus, irsp->ulpIoTag, 1166 irsp->ulpStatus, irsp->ulpIoTag,
@@ -1261,7 +1243,7 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1261 lpfc_printf_log(phba, 1243 lpfc_printf_log(phba,
1262 KERN_ERR, 1244 KERN_ERR,
1263 LOG_SLI, 1245 LOG_SLI,
1264 "%d:0312 Ring %d handler: portRspPut %d " 1246 "%d:0303 Ring %d handler: portRspPut %d "
1265 "is bigger then rsp ring %d\n", 1247 "is bigger then rsp ring %d\n",
1266 phba->brd_no, 1248 phba->brd_no,
1267 pring->ringno, portRspPut, portRspMax); 1249 pring->ringno, portRspPut, portRspMax);
@@ -1406,7 +1388,7 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1406 lpfc_printf_log(phba, 1388 lpfc_printf_log(phba,
1407 KERN_ERR, 1389 KERN_ERR,
1408 LOG_SLI, 1390 LOG_SLI,
1409 "%d:0321 Unknown IOCB command " 1391 "%d:0335 Unknown IOCB command "
1410 "Data: x%x x%x x%x x%x\n", 1392 "Data: x%x x%x x%x x%x\n",
1411 phba->brd_no, 1393 phba->brd_no,
1412 irsp->ulpCommand, 1394 irsp->ulpCommand,
@@ -1422,11 +1404,11 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1422 next_iocb, 1404 next_iocb,
1423 &saveq->list, 1405 &saveq->list,
1424 list) { 1406 list) {
1407 list_del(&rspiocbp->list);
1425 lpfc_sli_release_iocbq(phba, 1408 lpfc_sli_release_iocbq(phba,
1426 rspiocbp); 1409 rspiocbp);
1427 } 1410 }
1428 } 1411 }
1429
1430 lpfc_sli_release_iocbq(phba, saveq); 1412 lpfc_sli_release_iocbq(phba, saveq);
1431 } 1413 }
1432 } 1414 }
@@ -1570,8 +1552,8 @@ lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask)
1570 1552
1571void lpfc_reset_barrier(struct lpfc_hba * phba) 1553void lpfc_reset_barrier(struct lpfc_hba * phba)
1572{ 1554{
1573 uint32_t * resp_buf; 1555 uint32_t __iomem *resp_buf;
1574 uint32_t * mbox_buf; 1556 uint32_t __iomem *mbox_buf;
1575 volatile uint32_t mbox; 1557 volatile uint32_t mbox;
1576 uint32_t hc_copy; 1558 uint32_t hc_copy;
1577 int i; 1559 int i;
@@ -1587,7 +1569,7 @@ void lpfc_reset_barrier(struct lpfc_hba * phba)
1587 * Tell the other part of the chip to suspend temporarily all 1569 * Tell the other part of the chip to suspend temporarily all
1588 * its DMA activity. 1570 * its DMA activity.
1589 */ 1571 */
1590 resp_buf = (uint32_t *)phba->MBslimaddr; 1572 resp_buf = phba->MBslimaddr;
1591 1573
1592 /* Disable the error attention */ 1574 /* Disable the error attention */
1593 hc_copy = readl(phba->HCregaddr); 1575 hc_copy = readl(phba->HCregaddr);
@@ -1605,7 +1587,7 @@ void lpfc_reset_barrier(struct lpfc_hba * phba)
1605 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; 1587 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
1606 1588
1607 writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); 1589 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
1608 mbox_buf = (uint32_t *)phba->MBslimaddr; 1590 mbox_buf = phba->MBslimaddr;
1609 writel(mbox, mbox_buf); 1591 writel(mbox, mbox_buf);
1610 1592
1611 for (i = 0; 1593 for (i = 0;
@@ -1734,15 +1716,13 @@ lpfc_sli_brdreset(struct lpfc_hba * phba)
1734 phba->fc_myDID = 0; 1716 phba->fc_myDID = 0;
1735 phba->fc_prevDID = 0; 1717 phba->fc_prevDID = 0;
1736 1718
1737 psli->sli_flag = 0;
1738
1739 /* Turn off parity checking and serr during the physical reset */ 1719 /* Turn off parity checking and serr during the physical reset */
1740 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); 1720 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
1741 pci_write_config_word(phba->pcidev, PCI_COMMAND, 1721 pci_write_config_word(phba->pcidev, PCI_COMMAND,
1742 (cfg_value & 1722 (cfg_value &
1743 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); 1723 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
1744 1724
1745 psli->sli_flag &= ~LPFC_SLI2_ACTIVE; 1725 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
1746 /* Now toggle INITFF bit in the Host Control Register */ 1726 /* Now toggle INITFF bit in the Host Control Register */
1747 writel(HC_INITFF, phba->HCregaddr); 1727 writel(HC_INITFF, phba->HCregaddr);
1748 mdelay(1); 1728 mdelay(1);
@@ -1783,7 +1763,7 @@ lpfc_sli_brdrestart(struct lpfc_hba * phba)
1783 1763
1784 /* Restart HBA */ 1764 /* Restart HBA */
1785 lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 1765 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1786 "%d:0328 Restart HBA Data: x%x x%x\n", phba->brd_no, 1766 "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no,
1787 phba->hba_state, psli->sli_flag); 1767 phba->hba_state, psli->sli_flag);
1788 1768
1789 word0 = 0; 1769 word0 = 0;
@@ -1805,7 +1785,7 @@ lpfc_sli_brdrestart(struct lpfc_hba * phba)
1805 skip_post = 0; 1785 skip_post = 0;
1806 word0 = 0; /* This is really setting up word1 */ 1786 word0 = 0; /* This is really setting up word1 */
1807 } 1787 }
1808 to_slim = (uint8_t *) phba->MBslimaddr + sizeof (uint32_t); 1788 to_slim = phba->MBslimaddr + sizeof (uint32_t);
1809 writel(*(uint32_t *) mb, to_slim); 1789 writel(*(uint32_t *) mb, to_slim);
1810 readl(to_slim); /* flush */ 1790 readl(to_slim); /* flush */
1811 1791
@@ -1815,6 +1795,9 @@ lpfc_sli_brdrestart(struct lpfc_hba * phba)
1815 1795
1816 spin_unlock_irq(phba->host->host_lock); 1796 spin_unlock_irq(phba->host->host_lock);
1817 1797
1798 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
1799 psli->stats_start = get_seconds();
1800
1818 if (skip_post) 1801 if (skip_post)
1819 mdelay(100); 1802 mdelay(100);
1820 else 1803 else
@@ -1925,6 +1908,9 @@ lpfc_sli_hba_setup(struct lpfc_hba * phba)
1925 } 1908 }
1926 1909
1927 while (resetcount < 2 && !done) { 1910 while (resetcount < 2 && !done) {
1911 spin_lock_irq(phba->host->host_lock);
1912 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
1913 spin_unlock_irq(phba->host->host_lock);
1928 phba->hba_state = LPFC_STATE_UNKNOWN; 1914 phba->hba_state = LPFC_STATE_UNKNOWN;
1929 lpfc_sli_brdrestart(phba); 1915 lpfc_sli_brdrestart(phba);
1930 msleep(2500); 1916 msleep(2500);
@@ -1932,6 +1918,9 @@ lpfc_sli_hba_setup(struct lpfc_hba * phba)
1932 if (rc) 1918 if (rc)
1933 break; 1919 break;
1934 1920
1921 spin_lock_irq(phba->host->host_lock);
1922 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1923 spin_unlock_irq(phba->host->host_lock);
1935 resetcount++; 1924 resetcount++;
1936 1925
1937 /* Call pre CONFIG_PORT mailbox command initialization. A value of 0 1926 /* Call pre CONFIG_PORT mailbox command initialization. A value of 0
@@ -2217,7 +2206,8 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2217 return (MBX_NOT_FINISHED); 2206 return (MBX_NOT_FINISHED);
2218 } 2207 }
2219 /* timeout active mbox command */ 2208 /* timeout active mbox command */
2220 mod_timer(&psli->mbox_tmo, jiffies + HZ * LPFC_MBOX_TMO); 2209 mod_timer(&psli->mbox_tmo, (jiffies +
2210 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
2221 } 2211 }
2222 2212
2223 /* Mailbox cmd <cmd> issue */ 2213 /* Mailbox cmd <cmd> issue */
@@ -2277,7 +2267,6 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2277 break; 2267 break;
2278 2268
2279 case MBX_POLL: 2269 case MBX_POLL:
2280 i = 0;
2281 psli->mbox_active = NULL; 2270 psli->mbox_active = NULL;
2282 if (psli->sli_flag & LPFC_SLI2_ACTIVE) { 2271 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2283 /* First read mbox status word */ 2272 /* First read mbox status word */
@@ -2291,11 +2280,14 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2291 /* Read the HBA Host Attention Register */ 2280 /* Read the HBA Host Attention Register */
2292 ha_copy = readl(phba->HAregaddr); 2281 ha_copy = readl(phba->HAregaddr);
2293 2282
2283 i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
2284 i *= 1000; /* Convert to ms */
2285
2294 /* Wait for command to complete */ 2286 /* Wait for command to complete */
2295 while (((word0 & OWN_CHIP) == OWN_CHIP) || 2287 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2296 (!(ha_copy & HA_MBATT) && 2288 (!(ha_copy & HA_MBATT) &&
2297 (phba->hba_state > LPFC_WARM_START))) { 2289 (phba->hba_state > LPFC_WARM_START))) {
2298 if (i++ >= 100) { 2290 if (i-- <= 0) {
2299 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; 2291 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2300 spin_unlock_irqrestore(phba->host->host_lock, 2292 spin_unlock_irqrestore(phba->host->host_lock,
2301 drvr_flag); 2293 drvr_flag);
@@ -2313,7 +2305,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2313 2305
2314 /* Can be in interrupt context, do not sleep */ 2306 /* Can be in interrupt context, do not sleep */
2315 /* (or might be called with interrupts disabled) */ 2307 /* (or might be called with interrupts disabled) */
2316 mdelay(i); 2308 mdelay(1);
2317 2309
2318 spin_lock_irqsave(phba->host->host_lock, drvr_flag); 2310 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2319 2311
@@ -2659,8 +2651,6 @@ lpfc_sli_hba_down(struct lpfc_hba * phba)
2659 2651
2660 INIT_LIST_HEAD(&(pring->txq)); 2652 INIT_LIST_HEAD(&(pring->txq));
2661 2653
2662 kfree(pring->fast_lookup);
2663 pring->fast_lookup = NULL;
2664 } 2654 }
2665 2655
2666 spin_unlock_irqrestore(phba->host->host_lock, flags); 2656 spin_unlock_irqrestore(phba->host->host_lock, flags);
@@ -3030,7 +3020,7 @@ lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
3030 3020
3031 if (timeleft == 0) { 3021 if (timeleft == 0) {
3032 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 3022 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3033 "%d:0329 IOCB wait timeout error - no " 3023 "%d:0338 IOCB wait timeout error - no "
3034 "wake response Data x%x\n", 3024 "wake response Data x%x\n",
3035 phba->brd_no, timeout); 3025 phba->brd_no, timeout);
3036 retval = IOCB_TIMEDOUT; 3026 retval = IOCB_TIMEDOUT;
@@ -3110,6 +3100,24 @@ lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
3110 return retval; 3100 return retval;
3111} 3101}
3112 3102
3103int
3104lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3105{
3106 int i = 0;
3107
3108 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !phba->stopped) {
3109 if (i++ > LPFC_MBOX_TMO * 1000)
3110 return 1;
3111
3112 if (lpfc_sli_handle_mb_event(phba) == 0)
3113 i = 0;
3114
3115 msleep(1);
3116 }
3117
3118 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
3119}
3120
3113irqreturn_t 3121irqreturn_t
3114lpfc_intr_handler(int irq, void *dev_id, struct pt_regs * regs) 3122lpfc_intr_handler(int irq, void *dev_id, struct pt_regs * regs)
3115{ 3123{
diff --git a/drivers/scsi/lpfc/lpfc_sli.h b/drivers/scsi/lpfc/lpfc_sli.h
index a52d6c6cf083..e26de6809358 100644
--- a/drivers/scsi/lpfc/lpfc_sli.h
+++ b/drivers/scsi/lpfc/lpfc_sli.h
@@ -135,8 +135,6 @@ struct lpfc_sli_ring {
135 uint32_t fast_iotag; /* max fastlookup based iotag */ 135 uint32_t fast_iotag; /* max fastlookup based iotag */
136 uint32_t iotag_ctr; /* keeps track of the next iotag to use */ 136 uint32_t iotag_ctr; /* keeps track of the next iotag to use */
137 uint32_t iotag_max; /* max iotag value to use */ 137 uint32_t iotag_max; /* max iotag value to use */
138 struct lpfc_iocbq ** fast_lookup; /* array of IOCB ptrs indexed by
139 iotag */
140 struct list_head txq; 138 struct list_head txq;
141 uint16_t txq_cnt; /* current length of queue */ 139 uint16_t txq_cnt; /* current length of queue */
142 uint16_t txq_max; /* max length */ 140 uint16_t txq_max; /* max length */
@@ -174,6 +172,18 @@ struct lpfc_sli_stat {
174 uint32_t mbox_busy; /* Mailbox cmd busy */ 172 uint32_t mbox_busy; /* Mailbox cmd busy */
175}; 173};
176 174
175/* Structure to store link status values when port stats are reset */
176struct lpfc_lnk_stat {
177 uint32_t link_failure_count;
178 uint32_t loss_of_sync_count;
179 uint32_t loss_of_signal_count;
180 uint32_t prim_seq_protocol_err_count;
181 uint32_t invalid_tx_word_count;
182 uint32_t invalid_crc_count;
183 uint32_t error_frames;
184 uint32_t link_events;
185};
186
177/* Structure used to hold SLI information */ 187/* Structure used to hold SLI information */
178struct lpfc_sli { 188struct lpfc_sli {
179 uint32_t num_rings; 189 uint32_t num_rings;
@@ -203,6 +213,8 @@ struct lpfc_sli {
203 struct lpfc_iocbq ** iocbq_lookup; /* array to lookup IOCB by IOTAG */ 213 struct lpfc_iocbq ** iocbq_lookup; /* array to lookup IOCB by IOTAG */
204 size_t iocbq_lookup_len; /* current lengs of the array */ 214 size_t iocbq_lookup_len; /* current lengs of the array */
205 uint16_t last_iotag; /* last allocated IOTAG */ 215 uint16_t last_iotag; /* last allocated IOTAG */
216 unsigned long stats_start; /* in seconds */
217 struct lpfc_lnk_stat lnk_stat_offsets;
206}; 218};
207 219
208/* Given a pointer to the start of the ring, and the slot number of 220/* Given a pointer to the start of the ring, and the slot number of
@@ -213,3 +225,9 @@ struct lpfc_sli {
213 225
214#define LPFC_MBOX_TMO 30 /* Sec tmo for outstanding mbox 226#define LPFC_MBOX_TMO 30 /* Sec tmo for outstanding mbox
215 command */ 227 command */
228#define LPFC_MBOX_TMO_FLASH_CMD 300 /* Sec tmo for outstanding FLASH write
229 * or erase cmds. This is especially
230 * long because of the potential of
231 * multiple flash erases that can be
232 * spawned.
233 */
diff --git a/drivers/scsi/lpfc/lpfc_version.h b/drivers/scsi/lpfc/lpfc_version.h
index 6b737568b831..c7091ea29f3f 100644
--- a/drivers/scsi/lpfc/lpfc_version.h
+++ b/drivers/scsi/lpfc/lpfc_version.h
@@ -18,7 +18,7 @@
18 * included with this package. * 18 * included with this package. *
19 *******************************************************************/ 19 *******************************************************************/
20 20
21#define LPFC_DRIVER_VERSION "8.1.6" 21#define LPFC_DRIVER_VERSION "8.1.9"
22 22
23#define LPFC_DRIVER_NAME "lpfc" 23#define LPFC_DRIVER_NAME "lpfc"
24 24
diff --git a/drivers/scsi/mac53c94.c b/drivers/scsi/mac53c94.c
index 93edaa8696cf..89ef34df5a1d 100644
--- a/drivers/scsi/mac53c94.c
+++ b/drivers/scsi/mac53c94.c
@@ -378,7 +378,7 @@ static void set_dma_cmds(struct fsc_state *state, struct scsi_cmnd *cmd)
378 int nseg; 378 int nseg;
379 379
380 total = 0; 380 total = 0;
381 scl = (struct scatterlist *) cmd->buffer; 381 scl = (struct scatterlist *) cmd->request_buffer;
382 nseg = pci_map_sg(state->pdev, scl, cmd->use_sg, 382 nseg = pci_map_sg(state->pdev, scl, cmd->use_sg,
383 cmd->sc_data_direction); 383 cmd->sc_data_direction);
384 for (i = 0; i < nseg; ++i) { 384 for (i = 0; i < nseg; ++i) {
diff --git a/drivers/scsi/megaraid/mega_common.h b/drivers/scsi/megaraid/mega_common.h
index 4675343228ad..8cd0bd1d0f7c 100644
--- a/drivers/scsi/megaraid/mega_common.h
+++ b/drivers/scsi/megaraid/mega_common.h
@@ -37,6 +37,12 @@
37#define LSI_MAX_CHANNELS 16 37#define LSI_MAX_CHANNELS 16
38#define LSI_MAX_LOGICAL_DRIVES_64LD (64+1) 38#define LSI_MAX_LOGICAL_DRIVES_64LD (64+1)
39 39
40#define HBA_SIGNATURE_64_BIT 0x299
41#define PCI_CONF_AMISIG64 0xa4
42
43#define MEGA_SCSI_INQ_EVPD 1
44#define MEGA_INVALID_FIELD_IN_CDB 0x24
45
40 46
41/** 47/**
42 * scb_t - scsi command control block 48 * scb_t - scsi command control block
diff --git a/drivers/scsi/megaraid/megaraid_ioctl.h b/drivers/scsi/megaraid/megaraid_ioctl.h
index bdaee144a1c3..b8aa34202ec3 100644
--- a/drivers/scsi/megaraid/megaraid_ioctl.h
+++ b/drivers/scsi/megaraid/megaraid_ioctl.h
@@ -132,6 +132,10 @@ typedef struct uioc {
132/* Driver Data: */ 132/* Driver Data: */
133 void __user * user_data; 133 void __user * user_data;
134 uint32_t user_data_len; 134 uint32_t user_data_len;
135
136 /* 64bit alignment */
137 uint32_t pad_for_64bit_align;
138
135 mraid_passthru_t __user *user_pthru; 139 mraid_passthru_t __user *user_pthru;
136 140
137 mraid_passthru_t *pthru32; 141 mraid_passthru_t *pthru32;
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index 92715130ac09..cd982c877da0 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -10,7 +10,7 @@
10 * 2 of the License, or (at your option) any later version. 10 * 2 of the License, or (at your option) any later version.
11 * 11 *
12 * FILE : megaraid_mbox.c 12 * FILE : megaraid_mbox.c
13 * Version : v2.20.4.8 (Apr 11 2006) 13 * Version : v2.20.4.9 (Jul 16 2006)
14 * 14 *
15 * Authors: 15 * Authors:
16 * Atul Mukker <Atul.Mukker@lsil.com> 16 * Atul Mukker <Atul.Mukker@lsil.com>
@@ -720,6 +720,7 @@ megaraid_init_mbox(adapter_t *adapter)
720 struct pci_dev *pdev; 720 struct pci_dev *pdev;
721 mraid_device_t *raid_dev; 721 mraid_device_t *raid_dev;
722 int i; 722 int i;
723 uint32_t magic64;
723 724
724 725
725 adapter->ito = MBOX_TIMEOUT; 726 adapter->ito = MBOX_TIMEOUT;
@@ -863,12 +864,33 @@ megaraid_init_mbox(adapter_t *adapter)
863 864
864 // Set the DMA mask to 64-bit. All supported controllers as capable of 865 // Set the DMA mask to 64-bit. All supported controllers as capable of
865 // DMA in this range 866 // DMA in this range
866 if (pci_set_dma_mask(adapter->pdev, DMA_64BIT_MASK) != 0) { 867 pci_read_config_dword(adapter->pdev, PCI_CONF_AMISIG64, &magic64);
867 868
868 con_log(CL_ANN, (KERN_WARNING 869 if (((magic64 == HBA_SIGNATURE_64_BIT) &&
869 "megaraid: could not set DMA mask for 64-bit.\n")); 870 ((adapter->pdev->subsystem_device !=
871 PCI_SUBSYS_ID_MEGARAID_SATA_150_6) ||
872 (adapter->pdev->subsystem_device !=
873 PCI_SUBSYS_ID_MEGARAID_SATA_150_4))) ||
874 (adapter->pdev->vendor == PCI_VENDOR_ID_LSI_LOGIC &&
875 adapter->pdev->device == PCI_DEVICE_ID_VERDE) ||
876 (adapter->pdev->vendor == PCI_VENDOR_ID_LSI_LOGIC &&
877 adapter->pdev->device == PCI_DEVICE_ID_DOBSON) ||
878 (adapter->pdev->vendor == PCI_VENDOR_ID_LSI_LOGIC &&
879 adapter->pdev->device == PCI_DEVICE_ID_LINDSAY) ||
880 (adapter->pdev->vendor == PCI_VENDOR_ID_DELL &&
881 adapter->pdev->device == PCI_DEVICE_ID_PERC4_DI_EVERGLADES) ||
882 (adapter->pdev->vendor == PCI_VENDOR_ID_DELL &&
883 adapter->pdev->device == PCI_DEVICE_ID_PERC4E_DI_KOBUK)) {
884 if (pci_set_dma_mask(adapter->pdev, DMA_64BIT_MASK)) {
885 con_log(CL_ANN, (KERN_WARNING
886 "megaraid: DMA mask for 64-bit failed\n"));
870 887
871 goto out_free_sysfs_res; 888 if (pci_set_dma_mask (adapter->pdev, DMA_32BIT_MASK)) {
889 con_log(CL_ANN, (KERN_WARNING
890 "megaraid: 32-bit DMA mask failed\n"));
891 goto out_free_sysfs_res;
892 }
893 }
872 } 894 }
873 895
874 // setup tasklet for DPC 896 // setup tasklet for DPC
@@ -1622,6 +1644,14 @@ megaraid_mbox_build_cmd(adapter_t *adapter, struct scsi_cmnd *scp, int *busy)
1622 rdev->last_disp |= (1L << SCP2CHANNEL(scp)); 1644 rdev->last_disp |= (1L << SCP2CHANNEL(scp));
1623 } 1645 }
1624 1646
1647 if (scp->cmnd[1] & MEGA_SCSI_INQ_EVPD) {
1648 scp->sense_buffer[0] = 0x70;
1649 scp->sense_buffer[2] = ILLEGAL_REQUEST;
1650 scp->sense_buffer[12] = MEGA_INVALID_FIELD_IN_CDB;
1651 scp->result = CHECK_CONDITION << 1;
1652 return NULL;
1653 }
1654
1625 /* Fall through */ 1655 /* Fall through */
1626 1656
1627 case READ_CAPACITY: 1657 case READ_CAPACITY:
diff --git a/drivers/scsi/megaraid/megaraid_mbox.h b/drivers/scsi/megaraid/megaraid_mbox.h
index 868fb0ec93e7..2b5a3285f799 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.h
+++ b/drivers/scsi/megaraid/megaraid_mbox.h
@@ -21,8 +21,8 @@
21#include "megaraid_ioctl.h" 21#include "megaraid_ioctl.h"
22 22
23 23
24#define MEGARAID_VERSION "2.20.4.8" 24#define MEGARAID_VERSION "2.20.4.9"
25#define MEGARAID_EXT_VERSION "(Release Date: Mon Apr 11 12:27:22 EST 2006)" 25#define MEGARAID_EXT_VERSION "(Release Date: Sun Jul 16 12:27:22 EST 2006)"
26 26
27 27
28/* 28/*
diff --git a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c
index e8f534fb336b..d85b9a8f1b8d 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -10,7 +10,7 @@
10 * 2 of the License, or (at your option) any later version. 10 * 2 of the License, or (at your option) any later version.
11 * 11 *
12 * FILE : megaraid_mm.c 12 * FILE : megaraid_mm.c
13 * Version : v2.20.2.6 (Mar 7 2005) 13 * Version : v2.20.2.7 (Jul 16 2006)
14 * 14 *
15 * Common management module 15 * Common management module
16 */ 16 */
diff --git a/drivers/scsi/megaraid/megaraid_mm.h b/drivers/scsi/megaraid/megaraid_mm.h
index 3d9e67d6849d..c8762b2b8ed1 100644
--- a/drivers/scsi/megaraid/megaraid_mm.h
+++ b/drivers/scsi/megaraid/megaraid_mm.h
@@ -27,9 +27,9 @@
27#include "megaraid_ioctl.h" 27#include "megaraid_ioctl.h"
28 28
29 29
30#define LSI_COMMON_MOD_VERSION "2.20.2.6" 30#define LSI_COMMON_MOD_VERSION "2.20.2.7"
31#define LSI_COMMON_MOD_EXT_VERSION \ 31#define LSI_COMMON_MOD_EXT_VERSION \
32 "(Release Date: Mon Mar 7 00:01:03 EST 2005)" 32 "(Release Date: Sun Jul 16 00:01:03 EST 2006)"
33 33
34 34
35#define LSI_DBGLVL dbglevel 35#define LSI_DBGLVL dbglevel
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index e5c017ccda59..a8c9627a15c4 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -10,7 +10,7 @@
10 * 2 of the License, or (at your option) any later version. 10 * 2 of the License, or (at your option) any later version.
11 * 11 *
12 * FILE : megaraid_sas.c 12 * FILE : megaraid_sas.c
13 * Version : v00.00.02.04 13 * Version : v00.00.03.01
14 * 14 *
15 * Authors: 15 * Authors:
16 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsil.com> 16 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsil.com>
@@ -55,19 +55,25 @@ static struct pci_device_id megasas_pci_table[] = {
55 55
56 { 56 {
57 PCI_VENDOR_ID_LSI_LOGIC, 57 PCI_VENDOR_ID_LSI_LOGIC,
58 PCI_DEVICE_ID_LSI_SAS1064R, // xscale IOP 58 PCI_DEVICE_ID_LSI_SAS1064R, /* xscale IOP */
59 PCI_ANY_ID, 59 PCI_ANY_ID,
60 PCI_ANY_ID, 60 PCI_ANY_ID,
61 }, 61 },
62 { 62 {
63 PCI_VENDOR_ID_LSI_LOGIC, 63 PCI_VENDOR_ID_LSI_LOGIC,
64 PCI_DEVICE_ID_LSI_SAS1078R, // ppc IOP 64 PCI_DEVICE_ID_LSI_SAS1078R, /* ppc IOP */
65 PCI_ANY_ID, 65 PCI_ANY_ID,
66 PCI_ANY_ID, 66 PCI_ANY_ID,
67 }, 67 },
68 { 68 {
69 PCI_VENDOR_ID_LSI_LOGIC,
70 PCI_DEVICE_ID_LSI_VERDE_ZCR, /* xscale IOP, vega */
71 PCI_ANY_ID,
72 PCI_ANY_ID,
73 },
74 {
69 PCI_VENDOR_ID_DELL, 75 PCI_VENDOR_ID_DELL,
70 PCI_DEVICE_ID_DELL_PERC5, // xscale IOP 76 PCI_DEVICE_ID_DELL_PERC5, /* xscale IOP */
71 PCI_ANY_ID, 77 PCI_ANY_ID,
72 PCI_ANY_ID, 78 PCI_ANY_ID,
73 }, 79 },
@@ -289,9 +295,14 @@ static struct megasas_instance_template megasas_instance_template_ppc = {
289 * @regs: MFI register set 295 * @regs: MFI register set
290 */ 296 */
291static inline void 297static inline void
292megasas_disable_intr(struct megasas_register_set __iomem * regs) 298megasas_disable_intr(struct megasas_instance *instance)
293{ 299{
294 u32 mask = 0x1f; 300 u32 mask = 0x1f;
301 struct megasas_register_set __iomem *regs = instance->reg_set;
302
303 if(instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1078R)
304 mask = 0xffffffff;
305
295 writel(mask, &regs->outbound_intr_mask); 306 writel(mask, &regs->outbound_intr_mask);
296 307
297 /* Dummy readl to force pci flush */ 308 /* Dummy readl to force pci flush */
@@ -1260,7 +1271,7 @@ megasas_transition_to_ready(struct megasas_instance* instance)
1260 /* 1271 /*
1261 * Bring it to READY state; assuming max wait 2 secs 1272 * Bring it to READY state; assuming max wait 2 secs
1262 */ 1273 */
1263 megasas_disable_intr(instance->reg_set); 1274 megasas_disable_intr(instance);
1264 writel(MFI_INIT_READY, &instance->reg_set->inbound_doorbell); 1275 writel(MFI_INIT_READY, &instance->reg_set->inbound_doorbell);
1265 1276
1266 max_wait = 10; 1277 max_wait = 10;
@@ -1757,6 +1768,11 @@ static int megasas_init_mfi(struct megasas_instance *instance)
1757 init_frame->data_xfer_len = sizeof(struct megasas_init_queue_info); 1768 init_frame->data_xfer_len = sizeof(struct megasas_init_queue_info);
1758 1769
1759 /* 1770 /*
1771 * disable the intr before firing the init frame to FW
1772 */
1773 megasas_disable_intr(instance);
1774
1775 /*
1760 * Issue the init frame in polled mode 1776 * Issue the init frame in polled mode
1761 */ 1777 */
1762 if (megasas_issue_polled(instance, cmd)) { 1778 if (megasas_issue_polled(instance, cmd)) {
@@ -2234,7 +2250,7 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2234 megasas_mgmt_info.max_index--; 2250 megasas_mgmt_info.max_index--;
2235 2251
2236 pci_set_drvdata(pdev, NULL); 2252 pci_set_drvdata(pdev, NULL);
2237 megasas_disable_intr(instance->reg_set); 2253 megasas_disable_intr(instance);
2238 free_irq(instance->pdev->irq, instance); 2254 free_irq(instance->pdev->irq, instance);
2239 2255
2240 megasas_release_mfi(instance); 2256 megasas_release_mfi(instance);
@@ -2364,7 +2380,7 @@ static void megasas_detach_one(struct pci_dev *pdev)
2364 2380
2365 pci_set_drvdata(instance->pdev, NULL); 2381 pci_set_drvdata(instance->pdev, NULL);
2366 2382
2367 megasas_disable_intr(instance->reg_set); 2383 megasas_disable_intr(instance);
2368 2384
2369 free_irq(instance->pdev->irq, instance); 2385 free_irq(instance->pdev->irq, instance);
2370 2386
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 927d6ffef05f..3531a14222a7 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -18,9 +18,16 @@
18/** 18/**
19 * MegaRAID SAS Driver meta data 19 * MegaRAID SAS Driver meta data
20 */ 20 */
21#define MEGASAS_VERSION "00.00.02.04" 21#define MEGASAS_VERSION "00.00.03.01"
22#define MEGASAS_RELDATE "Feb 03, 2006" 22#define MEGASAS_RELDATE "May 14, 2006"
23#define MEGASAS_EXT_VERSION "Fri Feb 03 14:31:44 PST 2006" 23#define MEGASAS_EXT_VERSION "Sun May 14 22:49:52 PDT 2006"
24
25/*
26 * Device IDs
27 */
28#define PCI_DEVICE_ID_LSI_SAS1078R 0x0060
29#define PCI_DEVICE_ID_LSI_VERDE_ZCR 0x0413
30
24/* 31/*
25 * ===================================== 32 * =====================================
26 * MegaRAID SAS MFI firmware definitions 33 * MegaRAID SAS MFI firmware definitions
@@ -554,7 +561,11 @@ struct megasas_ctrl_info {
554#define MFI_POLL_TIMEOUT_SECS 10 561#define MFI_POLL_TIMEOUT_SECS 10
555 562
556#define MFI_REPLY_1078_MESSAGE_INTERRUPT 0x80000000 563#define MFI_REPLY_1078_MESSAGE_INTERRUPT 0x80000000
557#define PCI_DEVICE_ID_LSI_SAS1078R 0x00000060 564
565/*
566* register set for both 1068 and 1078 controllers
567* structure extended for 1078 registers
568*/
558 569
559struct megasas_register_set { 570struct megasas_register_set {
560 u32 reserved_0[4]; /*0000h*/ 571 u32 reserved_0[4]; /*0000h*/
@@ -1150,10 +1161,10 @@ struct compat_megasas_iocpacket {
1150 struct compat_iovec sgl[MAX_IOCTL_SGE]; 1161 struct compat_iovec sgl[MAX_IOCTL_SGE];
1151} __attribute__ ((packed)); 1162} __attribute__ ((packed));
1152 1163
1164#define MEGASAS_IOC_FIRMWARE32 _IOWR('M', 1, struct compat_megasas_iocpacket)
1153#endif 1165#endif
1154 1166
1155#define MEGASAS_IOC_FIRMWARE _IOWR('M', 1, struct megasas_iocpacket) 1167#define MEGASAS_IOC_FIRMWARE _IOWR('M', 1, struct megasas_iocpacket)
1156#define MEGASAS_IOC_FIRMWARE32 _IOWR('M', 1, struct compat_megasas_iocpacket)
1157#define MEGASAS_IOC_GET_AEN _IOW('M', 3, struct megasas_aen) 1168#define MEGASAS_IOC_GET_AEN _IOW('M', 3, struct megasas_aen)
1158 1169
1159struct megasas_mgmt_info { 1170struct megasas_mgmt_info {
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index c88717727be8..5572981a9f92 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -1268,7 +1268,7 @@ static void set_dma_cmds(struct mesh_state *ms, struct scsi_cmnd *cmd)
1268 if (cmd->use_sg > 0) { 1268 if (cmd->use_sg > 0) {
1269 int nseg; 1269 int nseg;
1270 total = 0; 1270 total = 0;
1271 scl = (struct scatterlist *) cmd->buffer; 1271 scl = (struct scatterlist *) cmd->request_buffer;
1272 off = ms->data_ptr; 1272 off = ms->data_ptr;
1273 nseg = pci_map_sg(ms->pdev, scl, cmd->use_sg, 1273 nseg = pci_map_sg(ms->pdev, scl, cmd->use_sg,
1274 cmd->sc_data_direction); 1274 cmd->sc_data_direction);
diff --git a/drivers/scsi/nsp32.c b/drivers/scsi/nsp32.c
index bd337a914298..bfb4f49e125d 100644
--- a/drivers/scsi/nsp32.c
+++ b/drivers/scsi/nsp32.c
@@ -2866,8 +2866,7 @@ static int nsp32_detect(struct scsi_host_template *sht)
2866 */ 2866 */
2867 nsp32_do_bus_reset(data); 2867 nsp32_do_bus_reset(data);
2868 2868
2869 ret = request_irq(host->irq, do_nsp32_isr, 2869 ret = request_irq(host->irq, do_nsp32_isr, IRQF_SHARED, "nsp32", data);
2870 IRQF_SHARED | IRQF_SAMPLE_RANDOM, "nsp32", data);
2871 if (ret < 0) { 2870 if (ret < 0) {
2872 nsp32_msg(KERN_ERR, "Unable to allocate IRQ for NinjaSCSI32 " 2871 nsp32_msg(KERN_ERR, "Unable to allocate IRQ for NinjaSCSI32 "
2873 "SCSI PCI controller. Interrupt: %d", host->irq); 2872 "SCSI PCI controller. Interrupt: %d", host->irq);
@@ -2886,12 +2885,19 @@ static int nsp32_detect(struct scsi_host_template *sht)
2886 } 2885 }
2887 2886
2888#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,73)) 2887#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,73))
2889 scsi_add_host (host, &PCIDEV->dev); 2888 ret = scsi_add_host(host, &PCIDEV->dev);
2889 if (ret) {
2890 nsp32_msg(KERN_ERR, "failed to add scsi host");
2891 goto free_region;
2892 }
2890 scsi_scan_host(host); 2893 scsi_scan_host(host);
2891#endif 2894#endif
2892 pci_set_drvdata(PCIDEV, host); 2895 pci_set_drvdata(PCIDEV, host);
2893 return DETECT_OK; 2896 return DETECT_OK;
2894 2897
2898 free_region:
2899 release_region(host->io_port, host->n_io_port);
2900
2895 free_irq: 2901 free_irq:
2896 free_irq(host->irq, data); 2902 free_irq(host->irq, data);
2897 2903
diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index 7ff5851c040b..0d4c04e1f3de 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -1623,7 +1623,7 @@ static int nsp_cs_probe(struct pcmcia_device *link)
1623 /* Interrupt handler */ 1623 /* Interrupt handler */
1624 link->irq.Handler = &nspintr; 1624 link->irq.Handler = &nspintr;
1625 link->irq.Instance = info; 1625 link->irq.Instance = info;
1626 link->irq.Attributes |= (IRQF_SHARED | IRQF_SAMPLE_RANDOM); 1626 link->irq.Attributes |= IRQF_SHARED;
1627 1627
1628 /* General socket configuration */ 1628 /* General socket configuration */
1629 link->conf.Attributes = CONF_ENABLE_IRQ; 1629 link->conf.Attributes = CONF_ENABLE_IRQ;
diff --git a/drivers/scsi/pdc_adma.c b/drivers/scsi/pdc_adma.c
index d1f38c32aa15..efc8fff1d250 100644
--- a/drivers/scsi/pdc_adma.c
+++ b/drivers/scsi/pdc_adma.c
@@ -183,7 +183,8 @@ static struct ata_port_info adma_port_info[] = {
183 { 183 {
184 .sht = &adma_ata_sht, 184 .sht = &adma_ata_sht,
185 .host_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | 185 .host_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST |
186 ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO, 186 ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO |
187 ATA_FLAG_PIO_POLLING,
187 .pio_mask = 0x10, /* pio4 */ 188 .pio_mask = 0x10, /* pio4 */
188 .udma_mask = 0x1f, /* udma0-4 */ 189 .udma_mask = 0x1f, /* udma0-4 */
189 .port_ops = &adma_ata_ops, 190 .port_ops = &adma_ata_ops,
diff --git a/drivers/scsi/pluto.c b/drivers/scsi/pluto.c
index 7abf64d1bfc9..0bd9c60e6455 100644
--- a/drivers/scsi/pluto.c
+++ b/drivers/scsi/pluto.c
@@ -169,8 +169,6 @@ int __init pluto_detect(struct scsi_host_template *tpnt)
169 SCpnt->request->rq_status = RQ_SCSI_BUSY; 169 SCpnt->request->rq_status = RQ_SCSI_BUSY;
170 170
171 SCpnt->done = pluto_detect_done; 171 SCpnt->done = pluto_detect_done;
172 SCpnt->bufflen = 256;
173 SCpnt->buffer = fcs[i].inquiry;
174 SCpnt->request_bufflen = 256; 172 SCpnt->request_bufflen = 256;
175 SCpnt->request_buffer = fcs[i].inquiry; 173 SCpnt->request_buffer = fcs[i].inquiry;
176 PLD(("set up %d %08lx\n", i, (long)SCpnt)) 174 PLD(("set up %d %08lx\n", i, (long)SCpnt))
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index b818b9bfe678..8953991462d7 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -4209,7 +4209,7 @@ qla1280_setup(char *s)
4209} 4209}
4210 4210
4211 4211
4212static int 4212static int __init
4213qla1280_get_token(char *str) 4213qla1280_get_token(char *str)
4214{ 4214{
4215 char *sep; 4215 char *sep;
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index e96d58ded57c..87f90c4f08e9 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -16,15 +16,16 @@ qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf, loff_t off,
16{ 16{
17 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, 17 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
18 struct device, kobj))); 18 struct device, kobj)));
19 char *rbuf = (char *)ha->fw_dump;
19 20
20 if (ha->fw_dump_reading == 0) 21 if (ha->fw_dump_reading == 0)
21 return 0; 22 return 0;
22 if (off > ha->fw_dump_buffer_len) 23 if (off > ha->fw_dump_len)
23 return 0; 24 return 0;
24 if (off + count > ha->fw_dump_buffer_len) 25 if (off + count > ha->fw_dump_len)
25 count = ha->fw_dump_buffer_len - off; 26 count = ha->fw_dump_len - off;
26 27
27 memcpy(buf, &ha->fw_dump_buffer[off], count); 28 memcpy(buf, &rbuf[off], count);
28 29
29 return (count); 30 return (count);
30} 31}
@@ -36,7 +37,6 @@ qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off,
36 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, 37 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
37 struct device, kobj))); 38 struct device, kobj)));
38 int reading; 39 int reading;
39 uint32_t dump_size;
40 40
41 if (off != 0) 41 if (off != 0)
42 return (0); 42 return (0);
@@ -44,46 +44,27 @@ qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off,
44 reading = simple_strtol(buf, NULL, 10); 44 reading = simple_strtol(buf, NULL, 10);
45 switch (reading) { 45 switch (reading) {
46 case 0: 46 case 0:
47 if (ha->fw_dump_reading == 1) { 47 if (!ha->fw_dump_reading)
48 qla_printk(KERN_INFO, ha, 48 break;
49 "Firmware dump cleared on (%ld).\n", ha->host_no);
50 49
51 vfree(ha->fw_dump_buffer); 50 qla_printk(KERN_INFO, ha,
52 ha->fw_dump_buffer = NULL; 51 "Firmware dump cleared on (%ld).\n", ha->host_no);
53 ha->fw_dump_reading = 0; 52
54 ha->fw_dumped = 0; 53 ha->fw_dump_reading = 0;
55 } 54 ha->fw_dumped = 0;
56 break; 55 break;
57 case 1: 56 case 1:
58 if (ha->fw_dumped && !ha->fw_dump_reading) { 57 if (ha->fw_dumped && !ha->fw_dump_reading) {
59 ha->fw_dump_reading = 1; 58 ha->fw_dump_reading = 1;
60 59
61 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
62 dump_size = FW_DUMP_SIZE_24XX;
63 else {
64 dump_size = FW_DUMP_SIZE_1M;
65 if (ha->fw_memory_size < 0x20000)
66 dump_size = FW_DUMP_SIZE_128K;
67 else if (ha->fw_memory_size < 0x80000)
68 dump_size = FW_DUMP_SIZE_512K;
69 }
70 ha->fw_dump_buffer = (char *)vmalloc(dump_size);
71 if (ha->fw_dump_buffer == NULL) {
72 qla_printk(KERN_WARNING, ha,
73 "Unable to allocate memory for firmware "
74 "dump buffer (%d).\n", dump_size);
75
76 ha->fw_dump_reading = 0;
77 return (count);
78 }
79 qla_printk(KERN_INFO, ha, 60 qla_printk(KERN_INFO, ha,
80 "Firmware dump ready for read on (%ld).\n", 61 "Raw firmware dump ready for read on (%ld).\n",
81 ha->host_no); 62 ha->host_no);
82 memset(ha->fw_dump_buffer, 0, dump_size);
83 ha->isp_ops.ascii_fw_dump(ha);
84 ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer);
85 } 63 }
86 break; 64 break;
65 case 2:
66 qla2x00_alloc_fw_dump(ha);
67 break;
87 } 68 }
88 return (count); 69 return (count);
89} 70}
@@ -313,9 +294,6 @@ qla2x00_sysfs_read_vpd(struct kobject *kobj, char *buf, loff_t off,
313 if (!capable(CAP_SYS_ADMIN) || off != 0) 294 if (!capable(CAP_SYS_ADMIN) || off != 0)
314 return 0; 295 return 0;
315 296
316 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
317 return -ENOTSUPP;
318
319 /* Read NVRAM. */ 297 /* Read NVRAM. */
320 spin_lock_irqsave(&ha->hardware_lock, flags); 298 spin_lock_irqsave(&ha->hardware_lock, flags);
321 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->vpd_base, ha->vpd_size); 299 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->vpd_base, ha->vpd_size);
@@ -335,9 +313,6 @@ qla2x00_sysfs_write_vpd(struct kobject *kobj, char *buf, loff_t off,
335 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size) 313 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
336 return 0; 314 return 0;
337 315
338 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
339 return -ENOTSUPP;
340
341 /* Write NVRAM. */ 316 /* Write NVRAM. */
342 spin_lock_irqsave(&ha->hardware_lock, flags); 317 spin_lock_irqsave(&ha->hardware_lock, flags);
343 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count); 318 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
@@ -357,6 +332,53 @@ static struct bin_attribute sysfs_vpd_attr = {
357 .write = qla2x00_sysfs_write_vpd, 332 .write = qla2x00_sysfs_write_vpd,
358}; 333};
359 334
335static ssize_t
336qla2x00_sysfs_read_sfp(struct kobject *kobj, char *buf, loff_t off,
337 size_t count)
338{
339 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
340 struct device, kobj)));
341 uint16_t iter, addr, offset;
342 int rval;
343
344 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
345 return 0;
346
347 addr = 0xa0;
348 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
349 iter++, offset += SFP_BLOCK_SIZE) {
350 if (iter == 4) {
351 /* Skip to next device address. */
352 addr = 0xa2;
353 offset = 0;
354 }
355
356 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
357 SFP_BLOCK_SIZE);
358 if (rval != QLA_SUCCESS) {
359 qla_printk(KERN_WARNING, ha,
360 "Unable to read SFP data (%x/%x/%x).\n", rval,
361 addr, offset);
362 count = 0;
363 break;
364 }
365 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
366 buf += SFP_BLOCK_SIZE;
367 }
368
369 return count;
370}
371
372static struct bin_attribute sysfs_sfp_attr = {
373 .attr = {
374 .name = "sfp",
375 .mode = S_IRUSR | S_IWUSR,
376 .owner = THIS_MODULE,
377 },
378 .size = SFP_DEV_SIZE * 2,
379 .read = qla2x00_sysfs_read_sfp,
380};
381
360void 382void
361qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha) 383qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
362{ 384{
@@ -367,7 +389,12 @@ qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
367 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr); 389 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
368 sysfs_create_bin_file(&host->shost_gendev.kobj, 390 sysfs_create_bin_file(&host->shost_gendev.kobj,
369 &sysfs_optrom_ctl_attr); 391 &sysfs_optrom_ctl_attr);
370 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_vpd_attr); 392 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
393 sysfs_create_bin_file(&host->shost_gendev.kobj,
394 &sysfs_vpd_attr);
395 sysfs_create_bin_file(&host->shost_gendev.kobj,
396 &sysfs_sfp_attr);
397 }
371} 398}
372 399
373void 400void
@@ -380,7 +407,12 @@ qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
380 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr); 407 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
381 sysfs_remove_bin_file(&host->shost_gendev.kobj, 408 sysfs_remove_bin_file(&host->shost_gendev.kobj,
382 &sysfs_optrom_ctl_attr); 409 &sysfs_optrom_ctl_attr);
383 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_vpd_attr); 410 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
411 sysfs_remove_bin_file(&host->shost_gendev.kobj,
412 &sysfs_vpd_attr);
413 sysfs_remove_bin_file(&host->shost_gendev.kobj,
414 &sysfs_sfp_attr);
415 }
384 416
385 if (ha->beacon_blink_led == 1) 417 if (ha->beacon_blink_led == 1)
386 ha->isp_ops.beacon_off(ha); 418 ha->isp_ops.beacon_off(ha);
diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
index 74e54713aa7c..f6ed6962bc2b 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.c
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
@@ -8,7 +8,34 @@
8 8
9#include <linux/delay.h> 9#include <linux/delay.h>
10 10
11static int qla_uprintf(char **, char *, ...); 11static inline void
12qla2xxx_prep_dump(scsi_qla_host_t *ha, struct qla2xxx_fw_dump *fw_dump)
13{
14 fw_dump->fw_major_version = htonl(ha->fw_major_version);
15 fw_dump->fw_minor_version = htonl(ha->fw_minor_version);
16 fw_dump->fw_subminor_version = htonl(ha->fw_subminor_version);
17 fw_dump->fw_attributes = htonl(ha->fw_attributes);
18
19 fw_dump->vendor = htonl(ha->pdev->vendor);
20 fw_dump->device = htonl(ha->pdev->device);
21 fw_dump->subsystem_vendor = htonl(ha->pdev->subsystem_vendor);
22 fw_dump->subsystem_device = htonl(ha->pdev->subsystem_device);
23}
24
25static inline void *
26qla2xxx_copy_queues(scsi_qla_host_t *ha, void *ptr)
27{
28 /* Request queue. */
29 memcpy(ptr, ha->request_ring, ha->request_q_length *
30 sizeof(request_t));
31
32 /* Response queue. */
33 ptr += ha->request_q_length * sizeof(request_t);
34 memcpy(ptr, ha->response_ring, ha->response_q_length *
35 sizeof(response_t));
36
37 return ptr + (ha->response_q_length * sizeof(response_t));
38}
12 39
13/** 40/**
14 * qla2300_fw_dump() - Dumps binary data from the 2300 firmware. 41 * qla2300_fw_dump() - Dumps binary data from the 2300 firmware.
@@ -49,10 +76,11 @@ qla2300_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
49 "request...\n", ha->fw_dump); 76 "request...\n", ha->fw_dump);
50 goto qla2300_fw_dump_failed; 77 goto qla2300_fw_dump_failed;
51 } 78 }
52 fw = ha->fw_dump; 79 fw = &ha->fw_dump->isp.isp23;
80 qla2xxx_prep_dump(ha, ha->fw_dump);
53 81
54 rval = QLA_SUCCESS; 82 rval = QLA_SUCCESS;
55 fw->hccr = RD_REG_WORD(&reg->hccr); 83 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
56 84
57 /* Pause RISC. */ 85 /* Pause RISC. */
58 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC); 86 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
@@ -73,85 +101,86 @@ qla2300_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
73 if (rval == QLA_SUCCESS) { 101 if (rval == QLA_SUCCESS) {
74 dmp_reg = (uint16_t __iomem *)(reg + 0); 102 dmp_reg = (uint16_t __iomem *)(reg + 0);
75 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++) 103 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
76 fw->pbiu_reg[cnt] = RD_REG_WORD(dmp_reg++); 104 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
77 105
78 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x10); 106 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x10);
79 for (cnt = 0; cnt < sizeof(fw->risc_host_reg) / 2; cnt++) 107 for (cnt = 0; cnt < sizeof(fw->risc_host_reg) / 2; cnt++)
80 fw->risc_host_reg[cnt] = RD_REG_WORD(dmp_reg++); 108 fw->risc_host_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
81 109
82 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x40); 110 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x40);
83 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++) 111 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
84 fw->mailbox_reg[cnt] = RD_REG_WORD(dmp_reg++); 112 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
85 113
86 WRT_REG_WORD(&reg->ctrl_status, 0x40); 114 WRT_REG_WORD(&reg->ctrl_status, 0x40);
87 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 115 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
88 for (cnt = 0; cnt < sizeof(fw->resp_dma_reg) / 2; cnt++) 116 for (cnt = 0; cnt < sizeof(fw->resp_dma_reg) / 2; cnt++)
89 fw->resp_dma_reg[cnt] = RD_REG_WORD(dmp_reg++); 117 fw->resp_dma_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
90 118
91 WRT_REG_WORD(&reg->ctrl_status, 0x50); 119 WRT_REG_WORD(&reg->ctrl_status, 0x50);
92 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 120 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
93 for (cnt = 0; cnt < sizeof(fw->dma_reg) / 2; cnt++) 121 for (cnt = 0; cnt < sizeof(fw->dma_reg) / 2; cnt++)
94 fw->dma_reg[cnt] = RD_REG_WORD(dmp_reg++); 122 fw->dma_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
95 123
96 WRT_REG_WORD(&reg->ctrl_status, 0x00); 124 WRT_REG_WORD(&reg->ctrl_status, 0x00);
97 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0xA0); 125 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0xA0);
98 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++) 126 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
99 fw->risc_hdw_reg[cnt] = RD_REG_WORD(dmp_reg++); 127 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
100 128
101 WRT_REG_WORD(&reg->pcr, 0x2000); 129 WRT_REG_WORD(&reg->pcr, 0x2000);
102 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 130 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
103 for (cnt = 0; cnt < sizeof(fw->risc_gp0_reg) / 2; cnt++) 131 for (cnt = 0; cnt < sizeof(fw->risc_gp0_reg) / 2; cnt++)
104 fw->risc_gp0_reg[cnt] = RD_REG_WORD(dmp_reg++); 132 fw->risc_gp0_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
105 133
106 WRT_REG_WORD(&reg->pcr, 0x2200); 134 WRT_REG_WORD(&reg->pcr, 0x2200);
107 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 135 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
108 for (cnt = 0; cnt < sizeof(fw->risc_gp1_reg) / 2; cnt++) 136 for (cnt = 0; cnt < sizeof(fw->risc_gp1_reg) / 2; cnt++)
109 fw->risc_gp1_reg[cnt] = RD_REG_WORD(dmp_reg++); 137 fw->risc_gp1_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
110 138
111 WRT_REG_WORD(&reg->pcr, 0x2400); 139 WRT_REG_WORD(&reg->pcr, 0x2400);
112 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 140 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
113 for (cnt = 0; cnt < sizeof(fw->risc_gp2_reg) / 2; cnt++) 141 for (cnt = 0; cnt < sizeof(fw->risc_gp2_reg) / 2; cnt++)
114 fw->risc_gp2_reg[cnt] = RD_REG_WORD(dmp_reg++); 142 fw->risc_gp2_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
115 143
116 WRT_REG_WORD(&reg->pcr, 0x2600); 144 WRT_REG_WORD(&reg->pcr, 0x2600);
117 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 145 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
118 for (cnt = 0; cnt < sizeof(fw->risc_gp3_reg) / 2; cnt++) 146 for (cnt = 0; cnt < sizeof(fw->risc_gp3_reg) / 2; cnt++)
119 fw->risc_gp3_reg[cnt] = RD_REG_WORD(dmp_reg++); 147 fw->risc_gp3_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
120 148
121 WRT_REG_WORD(&reg->pcr, 0x2800); 149 WRT_REG_WORD(&reg->pcr, 0x2800);
122 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 150 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
123 for (cnt = 0; cnt < sizeof(fw->risc_gp4_reg) / 2; cnt++) 151 for (cnt = 0; cnt < sizeof(fw->risc_gp4_reg) / 2; cnt++)
124 fw->risc_gp4_reg[cnt] = RD_REG_WORD(dmp_reg++); 152 fw->risc_gp4_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
125 153
126 WRT_REG_WORD(&reg->pcr, 0x2A00); 154 WRT_REG_WORD(&reg->pcr, 0x2A00);
127 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 155 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
128 for (cnt = 0; cnt < sizeof(fw->risc_gp5_reg) / 2; cnt++) 156 for (cnt = 0; cnt < sizeof(fw->risc_gp5_reg) / 2; cnt++)
129 fw->risc_gp5_reg[cnt] = RD_REG_WORD(dmp_reg++); 157 fw->risc_gp5_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
130 158
131 WRT_REG_WORD(&reg->pcr, 0x2C00); 159 WRT_REG_WORD(&reg->pcr, 0x2C00);
132 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 160 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
133 for (cnt = 0; cnt < sizeof(fw->risc_gp6_reg) / 2; cnt++) 161 for (cnt = 0; cnt < sizeof(fw->risc_gp6_reg) / 2; cnt++)
134 fw->risc_gp6_reg[cnt] = RD_REG_WORD(dmp_reg++); 162 fw->risc_gp6_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
135 163
136 WRT_REG_WORD(&reg->pcr, 0x2E00); 164 WRT_REG_WORD(&reg->pcr, 0x2E00);
137 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 165 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
138 for (cnt = 0; cnt < sizeof(fw->risc_gp7_reg) / 2; cnt++) 166 for (cnt = 0; cnt < sizeof(fw->risc_gp7_reg) / 2; cnt++)
139 fw->risc_gp7_reg[cnt] = RD_REG_WORD(dmp_reg++); 167 fw->risc_gp7_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
140 168
141 WRT_REG_WORD(&reg->ctrl_status, 0x10); 169 WRT_REG_WORD(&reg->ctrl_status, 0x10);
142 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 170 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
143 for (cnt = 0; cnt < sizeof(fw->frame_buf_hdw_reg) / 2; cnt++) 171 for (cnt = 0; cnt < sizeof(fw->frame_buf_hdw_reg) / 2; cnt++)
144 fw->frame_buf_hdw_reg[cnt] = RD_REG_WORD(dmp_reg++); 172 fw->frame_buf_hdw_reg[cnt] =
173 htons(RD_REG_WORD(dmp_reg++));
145 174
146 WRT_REG_WORD(&reg->ctrl_status, 0x20); 175 WRT_REG_WORD(&reg->ctrl_status, 0x20);
147 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 176 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
148 for (cnt = 0; cnt < sizeof(fw->fpm_b0_reg) / 2; cnt++) 177 for (cnt = 0; cnt < sizeof(fw->fpm_b0_reg) / 2; cnt++)
149 fw->fpm_b0_reg[cnt] = RD_REG_WORD(dmp_reg++); 178 fw->fpm_b0_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
150 179
151 WRT_REG_WORD(&reg->ctrl_status, 0x30); 180 WRT_REG_WORD(&reg->ctrl_status, 0x30);
152 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 181 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
153 for (cnt = 0; cnt < sizeof(fw->fpm_b1_reg) / 2; cnt++) 182 for (cnt = 0; cnt < sizeof(fw->fpm_b1_reg) / 2; cnt++)
154 fw->fpm_b1_reg[cnt] = RD_REG_WORD(dmp_reg++); 183 fw->fpm_b1_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
155 184
156 /* Reset RISC. */ 185 /* Reset RISC. */
157 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET); 186 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
@@ -226,7 +255,7 @@ qla2300_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
226 255
227 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) { 256 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
228 rval = mb0 & MBS_MASK; 257 rval = mb0 & MBS_MASK;
229 fw->risc_ram[cnt] = mb2; 258 fw->risc_ram[cnt] = htons(mb2);
230 } else { 259 } else {
231 rval = QLA_FUNCTION_FAILED; 260 rval = QLA_FUNCTION_FAILED;
232 } 261 }
@@ -285,7 +314,7 @@ qla2300_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
285 314
286 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) { 315 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
287 rval = mb0 & MBS_MASK; 316 rval = mb0 & MBS_MASK;
288 fw->stack_ram[cnt] = mb2; 317 fw->stack_ram[cnt] = htons(mb2);
289 } else { 318 } else {
290 rval = QLA_FUNCTION_FAILED; 319 rval = QLA_FUNCTION_FAILED;
291 } 320 }
@@ -345,12 +374,15 @@ qla2300_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
345 374
346 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) { 375 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
347 rval = mb0 & MBS_MASK; 376 rval = mb0 & MBS_MASK;
348 fw->data_ram[cnt] = mb2; 377 fw->data_ram[cnt] = htons(mb2);
349 } else { 378 } else {
350 rval = QLA_FUNCTION_FAILED; 379 rval = QLA_FUNCTION_FAILED;
351 } 380 }
352 } 381 }
353 382
383 if (rval == QLA_SUCCESS)
384 qla2xxx_copy_queues(ha, &fw->data_ram[cnt]);
385
354 if (rval != QLA_SUCCESS) { 386 if (rval != QLA_SUCCESS) {
355 qla_printk(KERN_WARNING, ha, 387 qla_printk(KERN_WARNING, ha,
356 "Failed to dump firmware (%x)!!!\n", rval); 388 "Failed to dump firmware (%x)!!!\n", rval);
@@ -369,193 +401,6 @@ qla2300_fw_dump_failed:
369} 401}
370 402
371/** 403/**
372 * qla2300_ascii_fw_dump() - Converts a binary firmware dump to ASCII.
373 * @ha: HA context
374 */
375void
376qla2300_ascii_fw_dump(scsi_qla_host_t *ha)
377{
378 uint32_t cnt;
379 char *uiter;
380 char fw_info[30];
381 struct qla2300_fw_dump *fw;
382 uint32_t data_ram_cnt;
383
384 uiter = ha->fw_dump_buffer;
385 fw = ha->fw_dump;
386
387 qla_uprintf(&uiter, "%s Firmware Version %s\n", ha->model_number,
388 ha->isp_ops.fw_version_str(ha, fw_info));
389
390 qla_uprintf(&uiter, "\n[==>BEG]\n");
391
392 qla_uprintf(&uiter, "HCCR Register:\n%04x\n\n", fw->hccr);
393
394 qla_uprintf(&uiter, "PBIU Registers:");
395 for (cnt = 0; cnt < sizeof (fw->pbiu_reg) / 2; cnt++) {
396 if (cnt % 8 == 0) {
397 qla_uprintf(&uiter, "\n");
398 }
399 qla_uprintf(&uiter, "%04x ", fw->pbiu_reg[cnt]);
400 }
401
402 qla_uprintf(&uiter, "\n\nReqQ-RspQ-Risc2Host Status registers:");
403 for (cnt = 0; cnt < sizeof (fw->risc_host_reg) / 2; cnt++) {
404 if (cnt % 8 == 0) {
405 qla_uprintf(&uiter, "\n");
406 }
407 qla_uprintf(&uiter, "%04x ", fw->risc_host_reg[cnt]);
408 }
409
410 qla_uprintf(&uiter, "\n\nMailbox Registers:");
411 for (cnt = 0; cnt < sizeof (fw->mailbox_reg) / 2; cnt++) {
412 if (cnt % 8 == 0) {
413 qla_uprintf(&uiter, "\n");
414 }
415 qla_uprintf(&uiter, "%04x ", fw->mailbox_reg[cnt]);
416 }
417
418 qla_uprintf(&uiter, "\n\nAuto Request Response DMA Registers:");
419 for (cnt = 0; cnt < sizeof (fw->resp_dma_reg) / 2; cnt++) {
420 if (cnt % 8 == 0) {
421 qla_uprintf(&uiter, "\n");
422 }
423 qla_uprintf(&uiter, "%04x ", fw->resp_dma_reg[cnt]);
424 }
425
426 qla_uprintf(&uiter, "\n\nDMA Registers:");
427 for (cnt = 0; cnt < sizeof (fw->dma_reg) / 2; cnt++) {
428 if (cnt % 8 == 0) {
429 qla_uprintf(&uiter, "\n");
430 }
431 qla_uprintf(&uiter, "%04x ", fw->dma_reg[cnt]);
432 }
433
434 qla_uprintf(&uiter, "\n\nRISC Hardware Registers:");
435 for (cnt = 0; cnt < sizeof (fw->risc_hdw_reg) / 2; cnt++) {
436 if (cnt % 8 == 0) {
437 qla_uprintf(&uiter, "\n");
438 }
439 qla_uprintf(&uiter, "%04x ", fw->risc_hdw_reg[cnt]);
440 }
441
442 qla_uprintf(&uiter, "\n\nRISC GP0 Registers:");
443 for (cnt = 0; cnt < sizeof (fw->risc_gp0_reg) / 2; cnt++) {
444 if (cnt % 8 == 0) {
445 qla_uprintf(&uiter, "\n");
446 }
447 qla_uprintf(&uiter, "%04x ", fw->risc_gp0_reg[cnt]);
448 }
449
450 qla_uprintf(&uiter, "\n\nRISC GP1 Registers:");
451 for (cnt = 0; cnt < sizeof (fw->risc_gp1_reg) / 2; cnt++) {
452 if (cnt % 8 == 0) {
453 qla_uprintf(&uiter, "\n");
454 }
455 qla_uprintf(&uiter, "%04x ", fw->risc_gp1_reg[cnt]);
456 }
457
458 qla_uprintf(&uiter, "\n\nRISC GP2 Registers:");
459 for (cnt = 0; cnt < sizeof (fw->risc_gp2_reg) / 2; cnt++) {
460 if (cnt % 8 == 0) {
461 qla_uprintf(&uiter, "\n");
462 }
463 qla_uprintf(&uiter, "%04x ", fw->risc_gp2_reg[cnt]);
464 }
465
466 qla_uprintf(&uiter, "\n\nRISC GP3 Registers:");
467 for (cnt = 0; cnt < sizeof (fw->risc_gp3_reg) / 2; cnt++) {
468 if (cnt % 8 == 0) {
469 qla_uprintf(&uiter, "\n");
470 }
471 qla_uprintf(&uiter, "%04x ", fw->risc_gp3_reg[cnt]);
472 }
473
474 qla_uprintf(&uiter, "\n\nRISC GP4 Registers:");
475 for (cnt = 0; cnt < sizeof (fw->risc_gp4_reg) / 2; cnt++) {
476 if (cnt % 8 == 0) {
477 qla_uprintf(&uiter, "\n");
478 }
479 qla_uprintf(&uiter, "%04x ", fw->risc_gp4_reg[cnt]);
480 }
481
482 qla_uprintf(&uiter, "\n\nRISC GP5 Registers:");
483 for (cnt = 0; cnt < sizeof (fw->risc_gp5_reg) / 2; cnt++) {
484 if (cnt % 8 == 0) {
485 qla_uprintf(&uiter, "\n");
486 }
487 qla_uprintf(&uiter, "%04x ", fw->risc_gp5_reg[cnt]);
488 }
489
490 qla_uprintf(&uiter, "\n\nRISC GP6 Registers:");
491 for (cnt = 0; cnt < sizeof (fw->risc_gp6_reg) / 2; cnt++) {
492 if (cnt % 8 == 0) {
493 qla_uprintf(&uiter, "\n");
494 }
495 qla_uprintf(&uiter, "%04x ", fw->risc_gp6_reg[cnt]);
496 }
497
498 qla_uprintf(&uiter, "\n\nRISC GP7 Registers:");
499 for (cnt = 0; cnt < sizeof (fw->risc_gp7_reg) / 2; cnt++) {
500 if (cnt % 8 == 0) {
501 qla_uprintf(&uiter, "\n");
502 }
503 qla_uprintf(&uiter, "%04x ", fw->risc_gp7_reg[cnt]);
504 }
505
506 qla_uprintf(&uiter, "\n\nFrame Buffer Hardware Registers:");
507 for (cnt = 0; cnt < sizeof (fw->frame_buf_hdw_reg) / 2; cnt++) {
508 if (cnt % 8 == 0) {
509 qla_uprintf(&uiter, "\n");
510 }
511 qla_uprintf(&uiter, "%04x ", fw->frame_buf_hdw_reg[cnt]);
512 }
513
514 qla_uprintf(&uiter, "\n\nFPM B0 Registers:");
515 for (cnt = 0; cnt < sizeof (fw->fpm_b0_reg) / 2; cnt++) {
516 if (cnt % 8 == 0) {
517 qla_uprintf(&uiter, "\n");
518 }
519 qla_uprintf(&uiter, "%04x ", fw->fpm_b0_reg[cnt]);
520 }
521
522 qla_uprintf(&uiter, "\n\nFPM B1 Registers:");
523 for (cnt = 0; cnt < sizeof (fw->fpm_b1_reg) / 2; cnt++) {
524 if (cnt % 8 == 0) {
525 qla_uprintf(&uiter, "\n");
526 }
527 qla_uprintf(&uiter, "%04x ", fw->fpm_b1_reg[cnt]);
528 }
529
530 qla_uprintf(&uiter, "\n\nCode RAM Dump:");
531 for (cnt = 0; cnt < sizeof (fw->risc_ram) / 2; cnt++) {
532 if (cnt % 8 == 0) {
533 qla_uprintf(&uiter, "\n%04x: ", cnt + 0x0800);
534 }
535 qla_uprintf(&uiter, "%04x ", fw->risc_ram[cnt]);
536 }
537
538 qla_uprintf(&uiter, "\n\nStack RAM Dump:");
539 for (cnt = 0; cnt < sizeof (fw->stack_ram) / 2; cnt++) {
540 if (cnt % 8 == 0) {
541 qla_uprintf(&uiter, "\n%05x: ", cnt + 0x10000);
542 }
543 qla_uprintf(&uiter, "%04x ", fw->stack_ram[cnt]);
544 }
545
546 qla_uprintf(&uiter, "\n\nData RAM Dump:");
547 data_ram_cnt = ha->fw_memory_size - 0x11000 + 1;
548 for (cnt = 0; cnt < data_ram_cnt; cnt++) {
549 if (cnt % 8 == 0) {
550 qla_uprintf(&uiter, "\n%05x: ", cnt + 0x11000);
551 }
552 qla_uprintf(&uiter, "%04x ", fw->data_ram[cnt]);
553 }
554
555 qla_uprintf(&uiter, "\n\n[<==END] ISP Debug Dump.");
556}
557
558/**
559 * qla2100_fw_dump() - Dumps binary data from the 2100/2200 firmware. 404 * qla2100_fw_dump() - Dumps binary data from the 2100/2200 firmware.
560 * @ha: HA context 405 * @ha: HA context
561 * @hardware_locked: Called with the hardware_lock 406 * @hardware_locked: Called with the hardware_lock
@@ -591,10 +436,11 @@ qla2100_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
591 "request...\n", ha->fw_dump); 436 "request...\n", ha->fw_dump);
592 goto qla2100_fw_dump_failed; 437 goto qla2100_fw_dump_failed;
593 } 438 }
594 fw = ha->fw_dump; 439 fw = &ha->fw_dump->isp.isp21;
440 qla2xxx_prep_dump(ha, ha->fw_dump);
595 441
596 rval = QLA_SUCCESS; 442 rval = QLA_SUCCESS;
597 fw->hccr = RD_REG_WORD(&reg->hccr); 443 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
598 444
599 /* Pause RISC. */ 445 /* Pause RISC. */
600 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC); 446 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
@@ -608,79 +454,81 @@ qla2100_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
608 if (rval == QLA_SUCCESS) { 454 if (rval == QLA_SUCCESS) {
609 dmp_reg = (uint16_t __iomem *)(reg + 0); 455 dmp_reg = (uint16_t __iomem *)(reg + 0);
610 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++) 456 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
611 fw->pbiu_reg[cnt] = RD_REG_WORD(dmp_reg++); 457 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
612 458
613 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x10); 459 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x10);
614 for (cnt = 0; cnt < ha->mbx_count; cnt++) { 460 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
615 if (cnt == 8) { 461 if (cnt == 8) {
616 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0xe0); 462 dmp_reg = (uint16_t __iomem *)
463 ((uint8_t __iomem *)reg + 0xe0);
617 } 464 }
618 fw->mailbox_reg[cnt] = RD_REG_WORD(dmp_reg++); 465 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
619 } 466 }
620 467
621 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x20); 468 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x20);
622 for (cnt = 0; cnt < sizeof(fw->dma_reg) / 2; cnt++) 469 for (cnt = 0; cnt < sizeof(fw->dma_reg) / 2; cnt++)
623 fw->dma_reg[cnt] = RD_REG_WORD(dmp_reg++); 470 fw->dma_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
624 471
625 WRT_REG_WORD(&reg->ctrl_status, 0x00); 472 WRT_REG_WORD(&reg->ctrl_status, 0x00);
626 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0xA0); 473 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0xA0);
627 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++) 474 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
628 fw->risc_hdw_reg[cnt] = RD_REG_WORD(dmp_reg++); 475 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
629 476
630 WRT_REG_WORD(&reg->pcr, 0x2000); 477 WRT_REG_WORD(&reg->pcr, 0x2000);
631 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 478 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
632 for (cnt = 0; cnt < sizeof(fw->risc_gp0_reg) / 2; cnt++) 479 for (cnt = 0; cnt < sizeof(fw->risc_gp0_reg) / 2; cnt++)
633 fw->risc_gp0_reg[cnt] = RD_REG_WORD(dmp_reg++); 480 fw->risc_gp0_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
634 481
635 WRT_REG_WORD(&reg->pcr, 0x2100); 482 WRT_REG_WORD(&reg->pcr, 0x2100);
636 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 483 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
637 for (cnt = 0; cnt < sizeof(fw->risc_gp1_reg) / 2; cnt++) 484 for (cnt = 0; cnt < sizeof(fw->risc_gp1_reg) / 2; cnt++)
638 fw->risc_gp1_reg[cnt] = RD_REG_WORD(dmp_reg++); 485 fw->risc_gp1_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
639 486
640 WRT_REG_WORD(&reg->pcr, 0x2200); 487 WRT_REG_WORD(&reg->pcr, 0x2200);
641 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 488 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
642 for (cnt = 0; cnt < sizeof(fw->risc_gp2_reg) / 2; cnt++) 489 for (cnt = 0; cnt < sizeof(fw->risc_gp2_reg) / 2; cnt++)
643 fw->risc_gp2_reg[cnt] = RD_REG_WORD(dmp_reg++); 490 fw->risc_gp2_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
644 491
645 WRT_REG_WORD(&reg->pcr, 0x2300); 492 WRT_REG_WORD(&reg->pcr, 0x2300);
646 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 493 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
647 for (cnt = 0; cnt < sizeof(fw->risc_gp3_reg) / 2; cnt++) 494 for (cnt = 0; cnt < sizeof(fw->risc_gp3_reg) / 2; cnt++)
648 fw->risc_gp3_reg[cnt] = RD_REG_WORD(dmp_reg++); 495 fw->risc_gp3_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
649 496
650 WRT_REG_WORD(&reg->pcr, 0x2400); 497 WRT_REG_WORD(&reg->pcr, 0x2400);
651 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 498 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
652 for (cnt = 0; cnt < sizeof(fw->risc_gp4_reg) / 2; cnt++) 499 for (cnt = 0; cnt < sizeof(fw->risc_gp4_reg) / 2; cnt++)
653 fw->risc_gp4_reg[cnt] = RD_REG_WORD(dmp_reg++); 500 fw->risc_gp4_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
654 501
655 WRT_REG_WORD(&reg->pcr, 0x2500); 502 WRT_REG_WORD(&reg->pcr, 0x2500);
656 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 503 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
657 for (cnt = 0; cnt < sizeof(fw->risc_gp5_reg) / 2; cnt++) 504 for (cnt = 0; cnt < sizeof(fw->risc_gp5_reg) / 2; cnt++)
658 fw->risc_gp5_reg[cnt] = RD_REG_WORD(dmp_reg++); 505 fw->risc_gp5_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
659 506
660 WRT_REG_WORD(&reg->pcr, 0x2600); 507 WRT_REG_WORD(&reg->pcr, 0x2600);
661 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 508 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
662 for (cnt = 0; cnt < sizeof(fw->risc_gp6_reg) / 2; cnt++) 509 for (cnt = 0; cnt < sizeof(fw->risc_gp6_reg) / 2; cnt++)
663 fw->risc_gp6_reg[cnt] = RD_REG_WORD(dmp_reg++); 510 fw->risc_gp6_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
664 511
665 WRT_REG_WORD(&reg->pcr, 0x2700); 512 WRT_REG_WORD(&reg->pcr, 0x2700);
666 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 513 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
667 for (cnt = 0; cnt < sizeof(fw->risc_gp7_reg) / 2; cnt++) 514 for (cnt = 0; cnt < sizeof(fw->risc_gp7_reg) / 2; cnt++)
668 fw->risc_gp7_reg[cnt] = RD_REG_WORD(dmp_reg++); 515 fw->risc_gp7_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
669 516
670 WRT_REG_WORD(&reg->ctrl_status, 0x10); 517 WRT_REG_WORD(&reg->ctrl_status, 0x10);
671 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 518 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
672 for (cnt = 0; cnt < sizeof(fw->frame_buf_hdw_reg) / 2; cnt++) 519 for (cnt = 0; cnt < sizeof(fw->frame_buf_hdw_reg) / 2; cnt++)
673 fw->frame_buf_hdw_reg[cnt] = RD_REG_WORD(dmp_reg++); 520 fw->frame_buf_hdw_reg[cnt] =
521 htons(RD_REG_WORD(dmp_reg++));
674 522
675 WRT_REG_WORD(&reg->ctrl_status, 0x20); 523 WRT_REG_WORD(&reg->ctrl_status, 0x20);
676 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 524 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
677 for (cnt = 0; cnt < sizeof(fw->fpm_b0_reg) / 2; cnt++) 525 for (cnt = 0; cnt < sizeof(fw->fpm_b0_reg) / 2; cnt++)
678 fw->fpm_b0_reg[cnt] = RD_REG_WORD(dmp_reg++); 526 fw->fpm_b0_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
679 527
680 WRT_REG_WORD(&reg->ctrl_status, 0x30); 528 WRT_REG_WORD(&reg->ctrl_status, 0x30);
681 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 529 dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
682 for (cnt = 0; cnt < sizeof(fw->fpm_b1_reg) / 2; cnt++) 530 for (cnt = 0; cnt < sizeof(fw->fpm_b1_reg) / 2; cnt++)
683 fw->fpm_b1_reg[cnt] = RD_REG_WORD(dmp_reg++); 531 fw->fpm_b1_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
684 532
685 /* Reset the ISP. */ 533 /* Reset the ISP. */
686 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET); 534 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
@@ -755,12 +603,15 @@ qla2100_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
755 603
756 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) { 604 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
757 rval = mb0 & MBS_MASK; 605 rval = mb0 & MBS_MASK;
758 fw->risc_ram[cnt] = mb2; 606 fw->risc_ram[cnt] = htons(mb2);
759 } else { 607 } else {
760 rval = QLA_FUNCTION_FAILED; 608 rval = QLA_FUNCTION_FAILED;
761 } 609 }
762 } 610 }
763 611
612 if (rval == QLA_SUCCESS)
613 qla2xxx_copy_queues(ha, &fw->risc_ram[cnt]);
614
764 if (rval != QLA_SUCCESS) { 615 if (rval != QLA_SUCCESS) {
765 qla_printk(KERN_WARNING, ha, 616 qla_printk(KERN_WARNING, ha,
766 "Failed to dump firmware (%x)!!!\n", rval); 617 "Failed to dump firmware (%x)!!!\n", rval);
@@ -778,179 +629,6 @@ qla2100_fw_dump_failed:
778 spin_unlock_irqrestore(&ha->hardware_lock, flags); 629 spin_unlock_irqrestore(&ha->hardware_lock, flags);
779} 630}
780 631
781/**
782 * qla2100_ascii_fw_dump() - Converts a binary firmware dump to ASCII.
783 * @ha: HA context
784 */
785void
786qla2100_ascii_fw_dump(scsi_qla_host_t *ha)
787{
788 uint32_t cnt;
789 char *uiter;
790 char fw_info[30];
791 struct qla2100_fw_dump *fw;
792
793 uiter = ha->fw_dump_buffer;
794 fw = ha->fw_dump;
795
796 qla_uprintf(&uiter, "%s Firmware Version %s\n", ha->model_number,
797 ha->isp_ops.fw_version_str(ha, fw_info));
798
799 qla_uprintf(&uiter, "\n[==>BEG]\n");
800
801 qla_uprintf(&uiter, "HCCR Register:\n%04x\n\n", fw->hccr);
802
803 qla_uprintf(&uiter, "PBIU Registers:");
804 for (cnt = 0; cnt < sizeof (fw->pbiu_reg) / 2; cnt++) {
805 if (cnt % 8 == 0) {
806 qla_uprintf(&uiter, "\n");
807 }
808 qla_uprintf(&uiter, "%04x ", fw->pbiu_reg[cnt]);
809 }
810
811 qla_uprintf(&uiter, "\n\nMailbox Registers:");
812 for (cnt = 0; cnt < sizeof (fw->mailbox_reg) / 2; cnt++) {
813 if (cnt % 8 == 0) {
814 qla_uprintf(&uiter, "\n");
815 }
816 qla_uprintf(&uiter, "%04x ", fw->mailbox_reg[cnt]);
817 }
818
819 qla_uprintf(&uiter, "\n\nDMA Registers:");
820 for (cnt = 0; cnt < sizeof (fw->dma_reg) / 2; cnt++) {
821 if (cnt % 8 == 0) {
822 qla_uprintf(&uiter, "\n");
823 }
824 qla_uprintf(&uiter, "%04x ", fw->dma_reg[cnt]);
825 }
826
827 qla_uprintf(&uiter, "\n\nRISC Hardware Registers:");
828 for (cnt = 0; cnt < sizeof (fw->risc_hdw_reg) / 2; cnt++) {
829 if (cnt % 8 == 0) {
830 qla_uprintf(&uiter, "\n");
831 }
832 qla_uprintf(&uiter, "%04x ", fw->risc_hdw_reg[cnt]);
833 }
834
835 qla_uprintf(&uiter, "\n\nRISC GP0 Registers:");
836 for (cnt = 0; cnt < sizeof (fw->risc_gp0_reg) / 2; cnt++) {
837 if (cnt % 8 == 0) {
838 qla_uprintf(&uiter, "\n");
839 }
840 qla_uprintf(&uiter, "%04x ", fw->risc_gp0_reg[cnt]);
841 }
842
843 qla_uprintf(&uiter, "\n\nRISC GP1 Registers:");
844 for (cnt = 0; cnt < sizeof (fw->risc_gp1_reg) / 2; cnt++) {
845 if (cnt % 8 == 0) {
846 qla_uprintf(&uiter, "\n");
847 }
848 qla_uprintf(&uiter, "%04x ", fw->risc_gp1_reg[cnt]);
849 }
850
851 qla_uprintf(&uiter, "\n\nRISC GP2 Registers:");
852 for (cnt = 0; cnt < sizeof (fw->risc_gp2_reg) / 2; cnt++) {
853 if (cnt % 8 == 0) {
854 qla_uprintf(&uiter, "\n");
855 }
856 qla_uprintf(&uiter, "%04x ", fw->risc_gp2_reg[cnt]);
857 }
858
859 qla_uprintf(&uiter, "\n\nRISC GP3 Registers:");
860 for (cnt = 0; cnt < sizeof (fw->risc_gp3_reg) / 2; cnt++) {
861 if (cnt % 8 == 0) {
862 qla_uprintf(&uiter, "\n");
863 }
864 qla_uprintf(&uiter, "%04x ", fw->risc_gp3_reg[cnt]);
865 }
866
867 qla_uprintf(&uiter, "\n\nRISC GP4 Registers:");
868 for (cnt = 0; cnt < sizeof (fw->risc_gp4_reg) / 2; cnt++) {
869 if (cnt % 8 == 0) {
870 qla_uprintf(&uiter, "\n");
871 }
872 qla_uprintf(&uiter, "%04x ", fw->risc_gp4_reg[cnt]);
873 }
874
875 qla_uprintf(&uiter, "\n\nRISC GP5 Registers:");
876 for (cnt = 0; cnt < sizeof (fw->risc_gp5_reg) / 2; cnt++) {
877 if (cnt % 8 == 0) {
878 qla_uprintf(&uiter, "\n");
879 }
880 qla_uprintf(&uiter, "%04x ", fw->risc_gp5_reg[cnt]);
881 }
882
883 qla_uprintf(&uiter, "\n\nRISC GP6 Registers:");
884 for (cnt = 0; cnt < sizeof (fw->risc_gp6_reg) / 2; cnt++) {
885 if (cnt % 8 == 0) {
886 qla_uprintf(&uiter, "\n");
887 }
888 qla_uprintf(&uiter, "%04x ", fw->risc_gp6_reg[cnt]);
889 }
890
891 qla_uprintf(&uiter, "\n\nRISC GP7 Registers:");
892 for (cnt = 0; cnt < sizeof (fw->risc_gp7_reg) / 2; cnt++) {
893 if (cnt % 8 == 0) {
894 qla_uprintf(&uiter, "\n");
895 }
896 qla_uprintf(&uiter, "%04x ", fw->risc_gp7_reg[cnt]);
897 }
898
899 qla_uprintf(&uiter, "\n\nFrame Buffer Hardware Registers:");
900 for (cnt = 0; cnt < sizeof (fw->frame_buf_hdw_reg) / 2; cnt++) {
901 if (cnt % 8 == 0) {
902 qla_uprintf(&uiter, "\n");
903 }
904 qla_uprintf(&uiter, "%04x ", fw->frame_buf_hdw_reg[cnt]);
905 }
906
907 qla_uprintf(&uiter, "\n\nFPM B0 Registers:");
908 for (cnt = 0; cnt < sizeof (fw->fpm_b0_reg) / 2; cnt++) {
909 if (cnt % 8 == 0) {
910 qla_uprintf(&uiter, "\n");
911 }
912 qla_uprintf(&uiter, "%04x ", fw->fpm_b0_reg[cnt]);
913 }
914
915 qla_uprintf(&uiter, "\n\nFPM B1 Registers:");
916 for (cnt = 0; cnt < sizeof (fw->fpm_b1_reg) / 2; cnt++) {
917 if (cnt % 8 == 0) {
918 qla_uprintf(&uiter, "\n");
919 }
920 qla_uprintf(&uiter, "%04x ", fw->fpm_b1_reg[cnt]);
921 }
922
923 qla_uprintf(&uiter, "\n\nRISC SRAM:");
924 for (cnt = 0; cnt < sizeof (fw->risc_ram) / 2; cnt++) {
925 if (cnt % 8 == 0) {
926 qla_uprintf(&uiter, "\n%04x: ", cnt + 0x1000);
927 }
928 qla_uprintf(&uiter, "%04x ", fw->risc_ram[cnt]);
929 }
930
931 qla_uprintf(&uiter, "\n\n[<==END] ISP Debug Dump.");
932
933 return;
934}
935
936static int
937qla_uprintf(char **uiter, char *fmt, ...)
938{
939 int iter, len;
940 char buf[128];
941 va_list args;
942
943 va_start(args, fmt);
944 len = vsprintf(buf, fmt, args);
945 va_end(args);
946
947 for (iter = 0; iter < len; iter++, *uiter += 1)
948 *uiter[0] = buf[iter];
949
950 return (len);
951}
952
953
954void 632void
955qla24xx_fw_dump(scsi_qla_host_t *ha, int hardware_locked) 633qla24xx_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
956{ 634{
@@ -967,6 +645,7 @@ qla24xx_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
967 unsigned long flags; 645 unsigned long flags;
968 struct qla24xx_fw_dump *fw; 646 struct qla24xx_fw_dump *fw;
969 uint32_t ext_mem_cnt; 647 uint32_t ext_mem_cnt;
648 void *eft;
970 649
971 risc_address = ext_mem_cnt = 0; 650 risc_address = ext_mem_cnt = 0;
972 memset(mb, 0, sizeof(mb)); 651 memset(mb, 0, sizeof(mb));
@@ -987,10 +666,11 @@ qla24xx_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
987 "request...\n", ha->fw_dump); 666 "request...\n", ha->fw_dump);
988 goto qla24xx_fw_dump_failed; 667 goto qla24xx_fw_dump_failed;
989 } 668 }
990 fw = ha->fw_dump; 669 fw = &ha->fw_dump->isp.isp24;
670 qla2xxx_prep_dump(ha, ha->fw_dump);
991 671
992 rval = QLA_SUCCESS; 672 rval = QLA_SUCCESS;
993 fw->host_status = RD_REG_DWORD(&reg->host_status); 673 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
994 674
995 /* Pause RISC. */ 675 /* Pause RISC. */
996 if ((RD_REG_DWORD(&reg->hccr) & HCCRX_RISC_PAUSE) == 0) { 676 if ((RD_REG_DWORD(&reg->hccr) & HCCRX_RISC_PAUSE) == 0) {
@@ -1012,7 +692,7 @@ qla24xx_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
1012 /* Host interface registers. */ 692 /* Host interface registers. */
1013 dmp_reg = (uint32_t __iomem *)(reg + 0); 693 dmp_reg = (uint32_t __iomem *)(reg + 0);
1014 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++) 694 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1015 fw->host_reg[cnt] = RD_REG_DWORD(dmp_reg++); 695 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1016 696
1017 /* Disable interrupts. */ 697 /* Disable interrupts. */
1018 WRT_REG_DWORD(&reg->ictrl, 0); 698 WRT_REG_DWORD(&reg->ictrl, 0);
@@ -1024,470 +704,471 @@ qla24xx_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
1024 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0); 704 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
1025 WRT_REG_DWORD(dmp_reg, 0xB0000000); 705 WRT_REG_DWORD(dmp_reg, 0xB0000000);
1026 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC); 706 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
1027 fw->shadow_reg[0] = RD_REG_DWORD(dmp_reg); 707 fw->shadow_reg[0] = htonl(RD_REG_DWORD(dmp_reg));
1028 708
1029 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0); 709 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
1030 WRT_REG_DWORD(dmp_reg, 0xB0100000); 710 WRT_REG_DWORD(dmp_reg, 0xB0100000);
1031 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC); 711 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
1032 fw->shadow_reg[1] = RD_REG_DWORD(dmp_reg); 712 fw->shadow_reg[1] = htonl(RD_REG_DWORD(dmp_reg));
1033 713
1034 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0); 714 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
1035 WRT_REG_DWORD(dmp_reg, 0xB0200000); 715 WRT_REG_DWORD(dmp_reg, 0xB0200000);
1036 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC); 716 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
1037 fw->shadow_reg[2] = RD_REG_DWORD(dmp_reg); 717 fw->shadow_reg[2] = htonl(RD_REG_DWORD(dmp_reg));
1038 718
1039 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0); 719 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
1040 WRT_REG_DWORD(dmp_reg, 0xB0300000); 720 WRT_REG_DWORD(dmp_reg, 0xB0300000);
1041 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC); 721 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
1042 fw->shadow_reg[3] = RD_REG_DWORD(dmp_reg); 722 fw->shadow_reg[3] = htonl(RD_REG_DWORD(dmp_reg));
1043 723
1044 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0); 724 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
1045 WRT_REG_DWORD(dmp_reg, 0xB0400000); 725 WRT_REG_DWORD(dmp_reg, 0xB0400000);
1046 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC); 726 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
1047 fw->shadow_reg[4] = RD_REG_DWORD(dmp_reg); 727 fw->shadow_reg[4] = htonl(RD_REG_DWORD(dmp_reg));
1048 728
1049 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0); 729 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
1050 WRT_REG_DWORD(dmp_reg, 0xB0500000); 730 WRT_REG_DWORD(dmp_reg, 0xB0500000);
1051 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC); 731 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
1052 fw->shadow_reg[5] = RD_REG_DWORD(dmp_reg); 732 fw->shadow_reg[5] = htonl(RD_REG_DWORD(dmp_reg));
1053 733
1054 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0); 734 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
1055 WRT_REG_DWORD(dmp_reg, 0xB0600000); 735 WRT_REG_DWORD(dmp_reg, 0xB0600000);
1056 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC); 736 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
1057 fw->shadow_reg[6] = RD_REG_DWORD(dmp_reg); 737 fw->shadow_reg[6] = htonl(RD_REG_DWORD(dmp_reg));
1058 738
1059 /* Mailbox registers. */ 739 /* Mailbox registers. */
1060 mbx_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80); 740 mbx_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
1061 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++) 741 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1062 fw->mailbox_reg[cnt] = RD_REG_WORD(mbx_reg++); 742 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
1063 743
1064 /* Transfer sequence registers. */ 744 /* Transfer sequence registers. */
1065 iter_reg = fw->xseq_gp_reg; 745 iter_reg = fw->xseq_gp_reg;
1066 WRT_REG_DWORD(&reg->iobase_addr, 0xBF00); 746 WRT_REG_DWORD(&reg->iobase_addr, 0xBF00);
1067 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 747 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1068 for (cnt = 0; cnt < 16; cnt++) 748 for (cnt = 0; cnt < 16; cnt++)
1069 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 749 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1070 750
1071 WRT_REG_DWORD(&reg->iobase_addr, 0xBF10); 751 WRT_REG_DWORD(&reg->iobase_addr, 0xBF10);
1072 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 752 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1073 for (cnt = 0; cnt < 16; cnt++) 753 for (cnt = 0; cnt < 16; cnt++)
1074 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 754 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1075 755
1076 WRT_REG_DWORD(&reg->iobase_addr, 0xBF20); 756 WRT_REG_DWORD(&reg->iobase_addr, 0xBF20);
1077 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 757 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1078 for (cnt = 0; cnt < 16; cnt++) 758 for (cnt = 0; cnt < 16; cnt++)
1079 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 759 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1080 760
1081 WRT_REG_DWORD(&reg->iobase_addr, 0xBF30); 761 WRT_REG_DWORD(&reg->iobase_addr, 0xBF30);
1082 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 762 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1083 for (cnt = 0; cnt < 16; cnt++) 763 for (cnt = 0; cnt < 16; cnt++)
1084 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 764 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1085 765
1086 WRT_REG_DWORD(&reg->iobase_addr, 0xBF40); 766 WRT_REG_DWORD(&reg->iobase_addr, 0xBF40);
1087 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 767 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1088 for (cnt = 0; cnt < 16; cnt++) 768 for (cnt = 0; cnt < 16; cnt++)
1089 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 769 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1090 770
1091 WRT_REG_DWORD(&reg->iobase_addr, 0xBF50); 771 WRT_REG_DWORD(&reg->iobase_addr, 0xBF50);
1092 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 772 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1093 for (cnt = 0; cnt < 16; cnt++) 773 for (cnt = 0; cnt < 16; cnt++)
1094 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 774 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1095 775
1096 WRT_REG_DWORD(&reg->iobase_addr, 0xBF60); 776 WRT_REG_DWORD(&reg->iobase_addr, 0xBF60);
1097 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 777 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1098 for (cnt = 0; cnt < 16; cnt++) 778 for (cnt = 0; cnt < 16; cnt++)
1099 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 779 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1100 780
1101 WRT_REG_DWORD(&reg->iobase_addr, 0xBF70); 781 WRT_REG_DWORD(&reg->iobase_addr, 0xBF70);
1102 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 782 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1103 for (cnt = 0; cnt < 16; cnt++) 783 for (cnt = 0; cnt < 16; cnt++)
1104 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 784 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1105 785
1106 WRT_REG_DWORD(&reg->iobase_addr, 0xBFE0); 786 WRT_REG_DWORD(&reg->iobase_addr, 0xBFE0);
1107 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 787 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1108 for (cnt = 0; cnt < sizeof(fw->xseq_0_reg) / 4; cnt++) 788 for (cnt = 0; cnt < sizeof(fw->xseq_0_reg) / 4; cnt++)
1109 fw->xseq_0_reg[cnt] = RD_REG_DWORD(dmp_reg++); 789 fw->xseq_0_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1110 790
1111 WRT_REG_DWORD(&reg->iobase_addr, 0xBFF0); 791 WRT_REG_DWORD(&reg->iobase_addr, 0xBFF0);
1112 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 792 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1113 for (cnt = 0; cnt < sizeof(fw->xseq_1_reg) / 4; cnt++) 793 for (cnt = 0; cnt < sizeof(fw->xseq_1_reg) / 4; cnt++)
1114 fw->xseq_1_reg[cnt] = RD_REG_DWORD(dmp_reg++); 794 fw->xseq_1_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1115 795
1116 /* Receive sequence registers. */ 796 /* Receive sequence registers. */
1117 iter_reg = fw->rseq_gp_reg; 797 iter_reg = fw->rseq_gp_reg;
1118 WRT_REG_DWORD(&reg->iobase_addr, 0xFF00); 798 WRT_REG_DWORD(&reg->iobase_addr, 0xFF00);
1119 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 799 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1120 for (cnt = 0; cnt < 16; cnt++) 800 for (cnt = 0; cnt < 16; cnt++)
1121 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 801 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1122 802
1123 WRT_REG_DWORD(&reg->iobase_addr, 0xFF10); 803 WRT_REG_DWORD(&reg->iobase_addr, 0xFF10);
1124 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 804 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1125 for (cnt = 0; cnt < 16; cnt++) 805 for (cnt = 0; cnt < 16; cnt++)
1126 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 806 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1127 807
1128 WRT_REG_DWORD(&reg->iobase_addr, 0xFF20); 808 WRT_REG_DWORD(&reg->iobase_addr, 0xFF20);
1129 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 809 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1130 for (cnt = 0; cnt < 16; cnt++) 810 for (cnt = 0; cnt < 16; cnt++)
1131 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 811 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1132 812
1133 WRT_REG_DWORD(&reg->iobase_addr, 0xFF30); 813 WRT_REG_DWORD(&reg->iobase_addr, 0xFF30);
1134 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 814 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1135 for (cnt = 0; cnt < 16; cnt++) 815 for (cnt = 0; cnt < 16; cnt++)
1136 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 816 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1137 817
1138 WRT_REG_DWORD(&reg->iobase_addr, 0xFF40); 818 WRT_REG_DWORD(&reg->iobase_addr, 0xFF40);
1139 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 819 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1140 for (cnt = 0; cnt < 16; cnt++) 820 for (cnt = 0; cnt < 16; cnt++)
1141 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 821 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1142 822
1143 WRT_REG_DWORD(&reg->iobase_addr, 0xFF50); 823 WRT_REG_DWORD(&reg->iobase_addr, 0xFF50);
1144 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 824 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1145 for (cnt = 0; cnt < 16; cnt++) 825 for (cnt = 0; cnt < 16; cnt++)
1146 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 826 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1147 827
1148 WRT_REG_DWORD(&reg->iobase_addr, 0xFF60); 828 WRT_REG_DWORD(&reg->iobase_addr, 0xFF60);
1149 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 829 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1150 for (cnt = 0; cnt < 16; cnt++) 830 for (cnt = 0; cnt < 16; cnt++)
1151 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 831 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1152 832
1153 WRT_REG_DWORD(&reg->iobase_addr, 0xFF70); 833 WRT_REG_DWORD(&reg->iobase_addr, 0xFF70);
1154 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 834 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1155 for (cnt = 0; cnt < 16; cnt++) 835 for (cnt = 0; cnt < 16; cnt++)
1156 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 836 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1157 837
1158 WRT_REG_DWORD(&reg->iobase_addr, 0xFFD0); 838 WRT_REG_DWORD(&reg->iobase_addr, 0xFFD0);
1159 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 839 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1160 for (cnt = 0; cnt < sizeof(fw->rseq_0_reg) / 4; cnt++) 840 for (cnt = 0; cnt < sizeof(fw->rseq_0_reg) / 4; cnt++)
1161 fw->rseq_0_reg[cnt] = RD_REG_DWORD(dmp_reg++); 841 fw->rseq_0_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1162 842
1163 WRT_REG_DWORD(&reg->iobase_addr, 0xFFE0); 843 WRT_REG_DWORD(&reg->iobase_addr, 0xFFE0);
1164 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 844 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1165 for (cnt = 0; cnt < sizeof(fw->rseq_1_reg) / 4; cnt++) 845 for (cnt = 0; cnt < sizeof(fw->rseq_1_reg) / 4; cnt++)
1166 fw->rseq_1_reg[cnt] = RD_REG_DWORD(dmp_reg++); 846 fw->rseq_1_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1167 847
1168 WRT_REG_DWORD(&reg->iobase_addr, 0xFFF0); 848 WRT_REG_DWORD(&reg->iobase_addr, 0xFFF0);
1169 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 849 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1170 for (cnt = 0; cnt < sizeof(fw->rseq_2_reg) / 4; cnt++) 850 for (cnt = 0; cnt < sizeof(fw->rseq_2_reg) / 4; cnt++)
1171 fw->rseq_2_reg[cnt] = RD_REG_DWORD(dmp_reg++); 851 fw->rseq_2_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1172 852
1173 /* Command DMA registers. */ 853 /* Command DMA registers. */
1174 WRT_REG_DWORD(&reg->iobase_addr, 0x7100); 854 WRT_REG_DWORD(&reg->iobase_addr, 0x7100);
1175 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 855 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1176 for (cnt = 0; cnt < sizeof(fw->cmd_dma_reg) / 4; cnt++) 856 for (cnt = 0; cnt < sizeof(fw->cmd_dma_reg) / 4; cnt++)
1177 fw->cmd_dma_reg[cnt] = RD_REG_DWORD(dmp_reg++); 857 fw->cmd_dma_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1178 858
1179 /* Queues. */ 859 /* Queues. */
1180 iter_reg = fw->req0_dma_reg; 860 iter_reg = fw->req0_dma_reg;
1181 WRT_REG_DWORD(&reg->iobase_addr, 0x7200); 861 WRT_REG_DWORD(&reg->iobase_addr, 0x7200);
1182 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 862 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1183 for (cnt = 0; cnt < 8; cnt++) 863 for (cnt = 0; cnt < 8; cnt++)
1184 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 864 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1185 865
1186 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xE4); 866 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xE4);
1187 for (cnt = 0; cnt < 7; cnt++) 867 for (cnt = 0; cnt < 7; cnt++)
1188 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 868 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1189 869
1190 iter_reg = fw->resp0_dma_reg; 870 iter_reg = fw->resp0_dma_reg;
1191 WRT_REG_DWORD(&reg->iobase_addr, 0x7300); 871 WRT_REG_DWORD(&reg->iobase_addr, 0x7300);
1192 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 872 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1193 for (cnt = 0; cnt < 8; cnt++) 873 for (cnt = 0; cnt < 8; cnt++)
1194 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 874 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1195 875
1196 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xE4); 876 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xE4);
1197 for (cnt = 0; cnt < 7; cnt++) 877 for (cnt = 0; cnt < 7; cnt++)
1198 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 878 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1199 879
1200 iter_reg = fw->req1_dma_reg; 880 iter_reg = fw->req1_dma_reg;
1201 WRT_REG_DWORD(&reg->iobase_addr, 0x7400); 881 WRT_REG_DWORD(&reg->iobase_addr, 0x7400);
1202 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 882 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1203 for (cnt = 0; cnt < 8; cnt++) 883 for (cnt = 0; cnt < 8; cnt++)
1204 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 884 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1205 885
1206 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xE4); 886 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xE4);
1207 for (cnt = 0; cnt < 7; cnt++) 887 for (cnt = 0; cnt < 7; cnt++)
1208 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 888 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1209 889
1210 /* Transmit DMA registers. */ 890 /* Transmit DMA registers. */
1211 iter_reg = fw->xmt0_dma_reg; 891 iter_reg = fw->xmt0_dma_reg;
1212 WRT_REG_DWORD(&reg->iobase_addr, 0x7600); 892 WRT_REG_DWORD(&reg->iobase_addr, 0x7600);
1213 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 893 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1214 for (cnt = 0; cnt < 16; cnt++) 894 for (cnt = 0; cnt < 16; cnt++)
1215 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 895 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1216 896
1217 WRT_REG_DWORD(&reg->iobase_addr, 0x7610); 897 WRT_REG_DWORD(&reg->iobase_addr, 0x7610);
1218 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 898 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1219 for (cnt = 0; cnt < 16; cnt++) 899 for (cnt = 0; cnt < 16; cnt++)
1220 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 900 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1221 901
1222 iter_reg = fw->xmt1_dma_reg; 902 iter_reg = fw->xmt1_dma_reg;
1223 WRT_REG_DWORD(&reg->iobase_addr, 0x7620); 903 WRT_REG_DWORD(&reg->iobase_addr, 0x7620);
1224 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 904 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1225 for (cnt = 0; cnt < 16; cnt++) 905 for (cnt = 0; cnt < 16; cnt++)
1226 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 906 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1227 907
1228 WRT_REG_DWORD(&reg->iobase_addr, 0x7630); 908 WRT_REG_DWORD(&reg->iobase_addr, 0x7630);
1229 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 909 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1230 for (cnt = 0; cnt < 16; cnt++) 910 for (cnt = 0; cnt < 16; cnt++)
1231 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 911 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1232 912
1233 iter_reg = fw->xmt2_dma_reg; 913 iter_reg = fw->xmt2_dma_reg;
1234 WRT_REG_DWORD(&reg->iobase_addr, 0x7640); 914 WRT_REG_DWORD(&reg->iobase_addr, 0x7640);
1235 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 915 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1236 for (cnt = 0; cnt < 16; cnt++) 916 for (cnt = 0; cnt < 16; cnt++)
1237 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 917 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1238 918
1239 WRT_REG_DWORD(&reg->iobase_addr, 0x7650); 919 WRT_REG_DWORD(&reg->iobase_addr, 0x7650);
1240 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 920 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1241 for (cnt = 0; cnt < 16; cnt++) 921 for (cnt = 0; cnt < 16; cnt++)
1242 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 922 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1243 923
1244 iter_reg = fw->xmt3_dma_reg; 924 iter_reg = fw->xmt3_dma_reg;
1245 WRT_REG_DWORD(&reg->iobase_addr, 0x7660); 925 WRT_REG_DWORD(&reg->iobase_addr, 0x7660);
1246 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 926 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1247 for (cnt = 0; cnt < 16; cnt++) 927 for (cnt = 0; cnt < 16; cnt++)
1248 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 928 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1249 929
1250 WRT_REG_DWORD(&reg->iobase_addr, 0x7670); 930 WRT_REG_DWORD(&reg->iobase_addr, 0x7670);
1251 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 931 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1252 for (cnt = 0; cnt < 16; cnt++) 932 for (cnt = 0; cnt < 16; cnt++)
1253 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 933 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1254 934
1255 iter_reg = fw->xmt4_dma_reg; 935 iter_reg = fw->xmt4_dma_reg;
1256 WRT_REG_DWORD(&reg->iobase_addr, 0x7680); 936 WRT_REG_DWORD(&reg->iobase_addr, 0x7680);
1257 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 937 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1258 for (cnt = 0; cnt < 16; cnt++) 938 for (cnt = 0; cnt < 16; cnt++)
1259 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 939 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1260 940
1261 WRT_REG_DWORD(&reg->iobase_addr, 0x7690); 941 WRT_REG_DWORD(&reg->iobase_addr, 0x7690);
1262 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 942 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1263 for (cnt = 0; cnt < 16; cnt++) 943 for (cnt = 0; cnt < 16; cnt++)
1264 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 944 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1265 945
1266 WRT_REG_DWORD(&reg->iobase_addr, 0x76A0); 946 WRT_REG_DWORD(&reg->iobase_addr, 0x76A0);
1267 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 947 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1268 for (cnt = 0; cnt < sizeof(fw->xmt_data_dma_reg) / 4; cnt++) 948 for (cnt = 0; cnt < sizeof(fw->xmt_data_dma_reg) / 4; cnt++)
1269 fw->xmt_data_dma_reg[cnt] = RD_REG_DWORD(dmp_reg++); 949 fw->xmt_data_dma_reg[cnt] =
950 htonl(RD_REG_DWORD(dmp_reg++));
1270 951
1271 /* Receive DMA registers. */ 952 /* Receive DMA registers. */
1272 iter_reg = fw->rcvt0_data_dma_reg; 953 iter_reg = fw->rcvt0_data_dma_reg;
1273 WRT_REG_DWORD(&reg->iobase_addr, 0x7700); 954 WRT_REG_DWORD(&reg->iobase_addr, 0x7700);
1274 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 955 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1275 for (cnt = 0; cnt < 16; cnt++) 956 for (cnt = 0; cnt < 16; cnt++)
1276 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 957 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1277 958
1278 WRT_REG_DWORD(&reg->iobase_addr, 0x7710); 959 WRT_REG_DWORD(&reg->iobase_addr, 0x7710);
1279 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 960 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1280 for (cnt = 0; cnt < 16; cnt++) 961 for (cnt = 0; cnt < 16; cnt++)
1281 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 962 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1282 963
1283 iter_reg = fw->rcvt1_data_dma_reg; 964 iter_reg = fw->rcvt1_data_dma_reg;
1284 WRT_REG_DWORD(&reg->iobase_addr, 0x7720); 965 WRT_REG_DWORD(&reg->iobase_addr, 0x7720);
1285 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 966 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1286 for (cnt = 0; cnt < 16; cnt++) 967 for (cnt = 0; cnt < 16; cnt++)
1287 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 968 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1288 969
1289 WRT_REG_DWORD(&reg->iobase_addr, 0x7730); 970 WRT_REG_DWORD(&reg->iobase_addr, 0x7730);
1290 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 971 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1291 for (cnt = 0; cnt < 16; cnt++) 972 for (cnt = 0; cnt < 16; cnt++)
1292 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 973 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1293 974
1294 /* RISC registers. */ 975 /* RISC registers. */
1295 iter_reg = fw->risc_gp_reg; 976 iter_reg = fw->risc_gp_reg;
1296 WRT_REG_DWORD(&reg->iobase_addr, 0x0F00); 977 WRT_REG_DWORD(&reg->iobase_addr, 0x0F00);
1297 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 978 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1298 for (cnt = 0; cnt < 16; cnt++) 979 for (cnt = 0; cnt < 16; cnt++)
1299 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 980 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1300 981
1301 WRT_REG_DWORD(&reg->iobase_addr, 0x0F10); 982 WRT_REG_DWORD(&reg->iobase_addr, 0x0F10);
1302 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 983 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1303 for (cnt = 0; cnt < 16; cnt++) 984 for (cnt = 0; cnt < 16; cnt++)
1304 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 985 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1305 986
1306 WRT_REG_DWORD(&reg->iobase_addr, 0x0F20); 987 WRT_REG_DWORD(&reg->iobase_addr, 0x0F20);
1307 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 988 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1308 for (cnt = 0; cnt < 16; cnt++) 989 for (cnt = 0; cnt < 16; cnt++)
1309 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 990 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1310 991
1311 WRT_REG_DWORD(&reg->iobase_addr, 0x0F30); 992 WRT_REG_DWORD(&reg->iobase_addr, 0x0F30);
1312 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 993 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1313 for (cnt = 0; cnt < 16; cnt++) 994 for (cnt = 0; cnt < 16; cnt++)
1314 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 995 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1315 996
1316 WRT_REG_DWORD(&reg->iobase_addr, 0x0F40); 997 WRT_REG_DWORD(&reg->iobase_addr, 0x0F40);
1317 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 998 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1318 for (cnt = 0; cnt < 16; cnt++) 999 for (cnt = 0; cnt < 16; cnt++)
1319 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1000 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1320 1001
1321 WRT_REG_DWORD(&reg->iobase_addr, 0x0F50); 1002 WRT_REG_DWORD(&reg->iobase_addr, 0x0F50);
1322 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1003 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1323 for (cnt = 0; cnt < 16; cnt++) 1004 for (cnt = 0; cnt < 16; cnt++)
1324 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1005 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1325 1006
1326 WRT_REG_DWORD(&reg->iobase_addr, 0x0F60); 1007 WRT_REG_DWORD(&reg->iobase_addr, 0x0F60);
1327 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1008 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1328 for (cnt = 0; cnt < 16; cnt++) 1009 for (cnt = 0; cnt < 16; cnt++)
1329 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1010 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1330 1011
1331 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70); 1012 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1332 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1013 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1333 for (cnt = 0; cnt < 16; cnt++) 1014 for (cnt = 0; cnt < 16; cnt++)
1334 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1015 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1335 1016
1336 /* Local memory controller registers. */ 1017 /* Local memory controller registers. */
1337 iter_reg = fw->lmc_reg; 1018 iter_reg = fw->lmc_reg;
1338 WRT_REG_DWORD(&reg->iobase_addr, 0x3000); 1019 WRT_REG_DWORD(&reg->iobase_addr, 0x3000);
1339 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1020 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1340 for (cnt = 0; cnt < 16; cnt++) 1021 for (cnt = 0; cnt < 16; cnt++)
1341 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1022 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1342 1023
1343 WRT_REG_DWORD(&reg->iobase_addr, 0x3010); 1024 WRT_REG_DWORD(&reg->iobase_addr, 0x3010);
1344 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1025 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1345 for (cnt = 0; cnt < 16; cnt++) 1026 for (cnt = 0; cnt < 16; cnt++)
1346 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1027 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1347 1028
1348 WRT_REG_DWORD(&reg->iobase_addr, 0x3020); 1029 WRT_REG_DWORD(&reg->iobase_addr, 0x3020);
1349 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1030 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1350 for (cnt = 0; cnt < 16; cnt++) 1031 for (cnt = 0; cnt < 16; cnt++)
1351 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1032 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1352 1033
1353 WRT_REG_DWORD(&reg->iobase_addr, 0x3030); 1034 WRT_REG_DWORD(&reg->iobase_addr, 0x3030);
1354 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1035 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1355 for (cnt = 0; cnt < 16; cnt++) 1036 for (cnt = 0; cnt < 16; cnt++)
1356 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1037 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1357 1038
1358 WRT_REG_DWORD(&reg->iobase_addr, 0x3040); 1039 WRT_REG_DWORD(&reg->iobase_addr, 0x3040);
1359 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1040 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1360 for (cnt = 0; cnt < 16; cnt++) 1041 for (cnt = 0; cnt < 16; cnt++)
1361 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1042 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1362 1043
1363 WRT_REG_DWORD(&reg->iobase_addr, 0x3050); 1044 WRT_REG_DWORD(&reg->iobase_addr, 0x3050);
1364 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1045 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1365 for (cnt = 0; cnt < 16; cnt++) 1046 for (cnt = 0; cnt < 16; cnt++)
1366 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1047 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1367 1048
1368 WRT_REG_DWORD(&reg->iobase_addr, 0x3060); 1049 WRT_REG_DWORD(&reg->iobase_addr, 0x3060);
1369 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1050 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1370 for (cnt = 0; cnt < 16; cnt++) 1051 for (cnt = 0; cnt < 16; cnt++)
1371 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1052 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1372 1053
1373 /* Fibre Protocol Module registers. */ 1054 /* Fibre Protocol Module registers. */
1374 iter_reg = fw->fpm_hdw_reg; 1055 iter_reg = fw->fpm_hdw_reg;
1375 WRT_REG_DWORD(&reg->iobase_addr, 0x4000); 1056 WRT_REG_DWORD(&reg->iobase_addr, 0x4000);
1376 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1057 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1377 for (cnt = 0; cnt < 16; cnt++) 1058 for (cnt = 0; cnt < 16; cnt++)
1378 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1059 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1379 1060
1380 WRT_REG_DWORD(&reg->iobase_addr, 0x4010); 1061 WRT_REG_DWORD(&reg->iobase_addr, 0x4010);
1381 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1062 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1382 for (cnt = 0; cnt < 16; cnt++) 1063 for (cnt = 0; cnt < 16; cnt++)
1383 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1064 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1384 1065
1385 WRT_REG_DWORD(&reg->iobase_addr, 0x4020); 1066 WRT_REG_DWORD(&reg->iobase_addr, 0x4020);
1386 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1067 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1387 for (cnt = 0; cnt < 16; cnt++) 1068 for (cnt = 0; cnt < 16; cnt++)
1388 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1069 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1389 1070
1390 WRT_REG_DWORD(&reg->iobase_addr, 0x4030); 1071 WRT_REG_DWORD(&reg->iobase_addr, 0x4030);
1391 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1072 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1392 for (cnt = 0; cnt < 16; cnt++) 1073 for (cnt = 0; cnt < 16; cnt++)
1393 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1074 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1394 1075
1395 WRT_REG_DWORD(&reg->iobase_addr, 0x4040); 1076 WRT_REG_DWORD(&reg->iobase_addr, 0x4040);
1396 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1077 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1397 for (cnt = 0; cnt < 16; cnt++) 1078 for (cnt = 0; cnt < 16; cnt++)
1398 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1079 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1399 1080
1400 WRT_REG_DWORD(&reg->iobase_addr, 0x4050); 1081 WRT_REG_DWORD(&reg->iobase_addr, 0x4050);
1401 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1082 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1402 for (cnt = 0; cnt < 16; cnt++) 1083 for (cnt = 0; cnt < 16; cnt++)
1403 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1084 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1404 1085
1405 WRT_REG_DWORD(&reg->iobase_addr, 0x4060); 1086 WRT_REG_DWORD(&reg->iobase_addr, 0x4060);
1406 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1087 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1407 for (cnt = 0; cnt < 16; cnt++) 1088 for (cnt = 0; cnt < 16; cnt++)
1408 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1089 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1409 1090
1410 WRT_REG_DWORD(&reg->iobase_addr, 0x4070); 1091 WRT_REG_DWORD(&reg->iobase_addr, 0x4070);
1411 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1092 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1412 for (cnt = 0; cnt < 16; cnt++) 1093 for (cnt = 0; cnt < 16; cnt++)
1413 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1094 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1414 1095
1415 WRT_REG_DWORD(&reg->iobase_addr, 0x4080); 1096 WRT_REG_DWORD(&reg->iobase_addr, 0x4080);
1416 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1097 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1417 for (cnt = 0; cnt < 16; cnt++) 1098 for (cnt = 0; cnt < 16; cnt++)
1418 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1099 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1419 1100
1420 WRT_REG_DWORD(&reg->iobase_addr, 0x4090); 1101 WRT_REG_DWORD(&reg->iobase_addr, 0x4090);
1421 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1102 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1422 for (cnt = 0; cnt < 16; cnt++) 1103 for (cnt = 0; cnt < 16; cnt++)
1423 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1104 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1424 1105
1425 WRT_REG_DWORD(&reg->iobase_addr, 0x40A0); 1106 WRT_REG_DWORD(&reg->iobase_addr, 0x40A0);
1426 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1107 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1427 for (cnt = 0; cnt < 16; cnt++) 1108 for (cnt = 0; cnt < 16; cnt++)
1428 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1109 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1429 1110
1430 WRT_REG_DWORD(&reg->iobase_addr, 0x40B0); 1111 WRT_REG_DWORD(&reg->iobase_addr, 0x40B0);
1431 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1112 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1432 for (cnt = 0; cnt < 16; cnt++) 1113 for (cnt = 0; cnt < 16; cnt++)
1433 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1114 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1434 1115
1435 /* Frame Buffer registers. */ 1116 /* Frame Buffer registers. */
1436 iter_reg = fw->fb_hdw_reg; 1117 iter_reg = fw->fb_hdw_reg;
1437 WRT_REG_DWORD(&reg->iobase_addr, 0x6000); 1118 WRT_REG_DWORD(&reg->iobase_addr, 0x6000);
1438 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1119 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1439 for (cnt = 0; cnt < 16; cnt++) 1120 for (cnt = 0; cnt < 16; cnt++)
1440 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1121 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1441 1122
1442 WRT_REG_DWORD(&reg->iobase_addr, 0x6010); 1123 WRT_REG_DWORD(&reg->iobase_addr, 0x6010);
1443 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1124 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1444 for (cnt = 0; cnt < 16; cnt++) 1125 for (cnt = 0; cnt < 16; cnt++)
1445 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1126 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1446 1127
1447 WRT_REG_DWORD(&reg->iobase_addr, 0x6020); 1128 WRT_REG_DWORD(&reg->iobase_addr, 0x6020);
1448 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1129 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1449 for (cnt = 0; cnt < 16; cnt++) 1130 for (cnt = 0; cnt < 16; cnt++)
1450 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1131 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1451 1132
1452 WRT_REG_DWORD(&reg->iobase_addr, 0x6030); 1133 WRT_REG_DWORD(&reg->iobase_addr, 0x6030);
1453 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1134 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1454 for (cnt = 0; cnt < 16; cnt++) 1135 for (cnt = 0; cnt < 16; cnt++)
1455 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1136 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1456 1137
1457 WRT_REG_DWORD(&reg->iobase_addr, 0x6040); 1138 WRT_REG_DWORD(&reg->iobase_addr, 0x6040);
1458 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1139 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1459 for (cnt = 0; cnt < 16; cnt++) 1140 for (cnt = 0; cnt < 16; cnt++)
1460 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1141 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1461 1142
1462 WRT_REG_DWORD(&reg->iobase_addr, 0x6100); 1143 WRT_REG_DWORD(&reg->iobase_addr, 0x6100);
1463 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1144 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1464 for (cnt = 0; cnt < 16; cnt++) 1145 for (cnt = 0; cnt < 16; cnt++)
1465 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1146 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1466 1147
1467 WRT_REG_DWORD(&reg->iobase_addr, 0x6130); 1148 WRT_REG_DWORD(&reg->iobase_addr, 0x6130);
1468 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1149 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1469 for (cnt = 0; cnt < 16; cnt++) 1150 for (cnt = 0; cnt < 16; cnt++)
1470 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1151 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1471 1152
1472 WRT_REG_DWORD(&reg->iobase_addr, 0x6150); 1153 WRT_REG_DWORD(&reg->iobase_addr, 0x6150);
1473 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1154 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1474 for (cnt = 0; cnt < 16; cnt++) 1155 for (cnt = 0; cnt < 16; cnt++)
1475 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1156 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1476 1157
1477 WRT_REG_DWORD(&reg->iobase_addr, 0x6170); 1158 WRT_REG_DWORD(&reg->iobase_addr, 0x6170);
1478 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1159 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1479 for (cnt = 0; cnt < 16; cnt++) 1160 for (cnt = 0; cnt < 16; cnt++)
1480 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1161 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1481 1162
1482 WRT_REG_DWORD(&reg->iobase_addr, 0x6190); 1163 WRT_REG_DWORD(&reg->iobase_addr, 0x6190);
1483 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1164 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1484 for (cnt = 0; cnt < 16; cnt++) 1165 for (cnt = 0; cnt < 16; cnt++)
1485 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1166 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1486 1167
1487 WRT_REG_DWORD(&reg->iobase_addr, 0x61B0); 1168 WRT_REG_DWORD(&reg->iobase_addr, 0x61B0);
1488 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0); 1169 dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
1489 for (cnt = 0; cnt < 16; cnt++) 1170 for (cnt = 0; cnt < 16; cnt++)
1490 *iter_reg++ = RD_REG_DWORD(dmp_reg++); 1171 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1491 1172
1492 /* Reset RISC. */ 1173 /* Reset RISC. */
1493 WRT_REG_DWORD(&reg->ctrl_status, 1174 WRT_REG_DWORD(&reg->ctrl_status,
@@ -1577,7 +1258,7 @@ qla24xx_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
1577 1258
1578 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) { 1259 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
1579 rval = mb[0] & MBS_MASK; 1260 rval = mb[0] & MBS_MASK;
1580 fw->code_ram[cnt] = (mb[3] << 16) | mb[2]; 1261 fw->code_ram[cnt] = htonl((mb[3] << 16) | mb[2]);
1581 } else { 1262 } else {
1582 rval = QLA_FUNCTION_FAILED; 1263 rval = QLA_FUNCTION_FAILED;
1583 } 1264 }
@@ -1627,12 +1308,18 @@ qla24xx_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
1627 1308
1628 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) { 1309 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
1629 rval = mb[0] & MBS_MASK; 1310 rval = mb[0] & MBS_MASK;
1630 fw->ext_mem[cnt] = (mb[3] << 16) | mb[2]; 1311 fw->ext_mem[cnt] = htonl((mb[3] << 16) | mb[2]);
1631 } else { 1312 } else {
1632 rval = QLA_FUNCTION_FAILED; 1313 rval = QLA_FUNCTION_FAILED;
1633 } 1314 }
1634 } 1315 }
1635 1316
1317 if (rval == QLA_SUCCESS) {
1318 eft = qla2xxx_copy_queues(ha, &fw->ext_mem[cnt]);
1319 if (ha->eft)
1320 memcpy(eft, ha->eft, ntohl(ha->fw_dump->eft_size));
1321 }
1322
1636 if (rval != QLA_SUCCESS) { 1323 if (rval != QLA_SUCCESS) {
1637 qla_printk(KERN_WARNING, ha, 1324 qla_printk(KERN_WARNING, ha,
1638 "Failed to dump firmware (%x)!!!\n", rval); 1325 "Failed to dump firmware (%x)!!!\n", rval);
@@ -1650,252 +1337,6 @@ qla24xx_fw_dump_failed:
1650 spin_unlock_irqrestore(&ha->hardware_lock, flags); 1337 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1651} 1338}
1652 1339
1653void
1654qla24xx_ascii_fw_dump(scsi_qla_host_t *ha)
1655{
1656 uint32_t cnt;
1657 char *uiter;
1658 struct qla24xx_fw_dump *fw;
1659 uint32_t ext_mem_cnt;
1660
1661 uiter = ha->fw_dump_buffer;
1662 fw = ha->fw_dump;
1663
1664 qla_uprintf(&uiter, "ISP FW Version %d.%02d.%02d Attributes %04x\n",
1665 ha->fw_major_version, ha->fw_minor_version,
1666 ha->fw_subminor_version, ha->fw_attributes);
1667
1668 qla_uprintf(&uiter, "\nR2H Status Register\n%04x\n", fw->host_status);
1669
1670 qla_uprintf(&uiter, "\nHost Interface Registers");
1671 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++) {
1672 if (cnt % 8 == 0)
1673 qla_uprintf(&uiter, "\n");
1674
1675 qla_uprintf(&uiter, "%08x ", fw->host_reg[cnt]);
1676 }
1677
1678 qla_uprintf(&uiter, "\n\nShadow Registers");
1679 for (cnt = 0; cnt < sizeof(fw->shadow_reg) / 4; cnt++) {
1680 if (cnt % 8 == 0)
1681 qla_uprintf(&uiter, "\n");
1682
1683 qla_uprintf(&uiter, "%08x ", fw->shadow_reg[cnt]);
1684 }
1685
1686 qla_uprintf(&uiter, "\n\nMailbox Registers");
1687 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++) {
1688 if (cnt % 8 == 0)
1689 qla_uprintf(&uiter, "\n");
1690
1691 qla_uprintf(&uiter, "%08x ", fw->mailbox_reg[cnt]);
1692 }
1693
1694 qla_uprintf(&uiter, "\n\nXSEQ GP Registers");
1695 for (cnt = 0; cnt < sizeof(fw->xseq_gp_reg) / 4; cnt++) {
1696 if (cnt % 8 == 0)
1697 qla_uprintf(&uiter, "\n");
1698
1699 qla_uprintf(&uiter, "%08x ", fw->xseq_gp_reg[cnt]);
1700 }
1701
1702 qla_uprintf(&uiter, "\n\nXSEQ-0 Registers");
1703 for (cnt = 0; cnt < sizeof(fw->xseq_0_reg) / 4; cnt++) {
1704 if (cnt % 8 == 0)
1705 qla_uprintf(&uiter, "\n");
1706
1707 qla_uprintf(&uiter, "%08x ", fw->xseq_0_reg[cnt]);
1708 }
1709
1710 qla_uprintf(&uiter, "\n\nXSEQ-1 Registers");
1711 for (cnt = 0; cnt < sizeof(fw->xseq_1_reg) / 4; cnt++) {
1712 if (cnt % 8 == 0)
1713 qla_uprintf(&uiter, "\n");
1714
1715 qla_uprintf(&uiter, "%08x ", fw->xseq_1_reg[cnt]);
1716 }
1717
1718 qla_uprintf(&uiter, "\n\nRSEQ GP Registers");
1719 for (cnt = 0; cnt < sizeof(fw->rseq_gp_reg) / 4; cnt++) {
1720 if (cnt % 8 == 0)
1721 qla_uprintf(&uiter, "\n");
1722
1723 qla_uprintf(&uiter, "%08x ", fw->rseq_gp_reg[cnt]);
1724 }
1725
1726 qla_uprintf(&uiter, "\n\nRSEQ-0 Registers");
1727 for (cnt = 0; cnt < sizeof(fw->rseq_0_reg) / 4; cnt++) {
1728 if (cnt % 8 == 0)
1729 qla_uprintf(&uiter, "\n");
1730
1731 qla_uprintf(&uiter, "%08x ", fw->rseq_0_reg[cnt]);
1732 }
1733
1734 qla_uprintf(&uiter, "\n\nRSEQ-1 Registers");
1735 for (cnt = 0; cnt < sizeof(fw->rseq_1_reg) / 4; cnt++) {
1736 if (cnt % 8 == 0)
1737 qla_uprintf(&uiter, "\n");
1738
1739 qla_uprintf(&uiter, "%08x ", fw->rseq_1_reg[cnt]);
1740 }
1741
1742 qla_uprintf(&uiter, "\n\nRSEQ-2 Registers");
1743 for (cnt = 0; cnt < sizeof(fw->rseq_2_reg) / 4; cnt++) {
1744 if (cnt % 8 == 0)
1745 qla_uprintf(&uiter, "\n");
1746
1747 qla_uprintf(&uiter, "%08x ", fw->rseq_2_reg[cnt]);
1748 }
1749
1750 qla_uprintf(&uiter, "\n\nCommand DMA Registers");
1751 for (cnt = 0; cnt < sizeof(fw->cmd_dma_reg) / 4; cnt++) {
1752 if (cnt % 8 == 0)
1753 qla_uprintf(&uiter, "\n");
1754
1755 qla_uprintf(&uiter, "%08x ", fw->cmd_dma_reg[cnt]);
1756 }
1757
1758 qla_uprintf(&uiter, "\n\nRequest0 Queue DMA Channel Registers");
1759 for (cnt = 0; cnt < sizeof(fw->req0_dma_reg) / 4; cnt++) {
1760 if (cnt % 8 == 0)
1761 qla_uprintf(&uiter, "\n");
1762
1763 qla_uprintf(&uiter, "%08x ", fw->req0_dma_reg[cnt]);
1764 }
1765
1766 qla_uprintf(&uiter, "\n\nResponse0 Queue DMA Channel Registers");
1767 for (cnt = 0; cnt < sizeof(fw->resp0_dma_reg) / 4; cnt++) {
1768 if (cnt % 8 == 0)
1769 qla_uprintf(&uiter, "\n");
1770
1771 qla_uprintf(&uiter, "%08x ", fw->resp0_dma_reg[cnt]);
1772 }
1773
1774 qla_uprintf(&uiter, "\n\nRequest1 Queue DMA Channel Registers");
1775 for (cnt = 0; cnt < sizeof(fw->req1_dma_reg) / 4; cnt++) {
1776 if (cnt % 8 == 0)
1777 qla_uprintf(&uiter, "\n");
1778
1779 qla_uprintf(&uiter, "%08x ", fw->req1_dma_reg[cnt]);
1780 }
1781
1782 qla_uprintf(&uiter, "\n\nXMT0 Data DMA Registers");
1783 for (cnt = 0; cnt < sizeof(fw->xmt0_dma_reg) / 4; cnt++) {
1784 if (cnt % 8 == 0)
1785 qla_uprintf(&uiter, "\n");
1786
1787 qla_uprintf(&uiter, "%08x ", fw->xmt0_dma_reg[cnt]);
1788 }
1789
1790 qla_uprintf(&uiter, "\n\nXMT1 Data DMA Registers");
1791 for (cnt = 0; cnt < sizeof(fw->xmt1_dma_reg) / 4; cnt++) {
1792 if (cnt % 8 == 0)
1793 qla_uprintf(&uiter, "\n");
1794
1795 qla_uprintf(&uiter, "%08x ", fw->xmt1_dma_reg[cnt]);
1796 }
1797
1798 qla_uprintf(&uiter, "\n\nXMT2 Data DMA Registers");
1799 for (cnt = 0; cnt < sizeof(fw->xmt2_dma_reg) / 4; cnt++) {
1800 if (cnt % 8 == 0)
1801 qla_uprintf(&uiter, "\n");
1802
1803 qla_uprintf(&uiter, "%08x ", fw->xmt2_dma_reg[cnt]);
1804 }
1805
1806 qla_uprintf(&uiter, "\n\nXMT3 Data DMA Registers");
1807 for (cnt = 0; cnt < sizeof(fw->xmt3_dma_reg) / 4; cnt++) {
1808 if (cnt % 8 == 0)
1809 qla_uprintf(&uiter, "\n");
1810
1811 qla_uprintf(&uiter, "%08x ", fw->xmt3_dma_reg[cnt]);
1812 }
1813
1814 qla_uprintf(&uiter, "\n\nXMT4 Data DMA Registers");
1815 for (cnt = 0; cnt < sizeof(fw->xmt4_dma_reg) / 4; cnt++) {
1816 if (cnt % 8 == 0)
1817 qla_uprintf(&uiter, "\n");
1818
1819 qla_uprintf(&uiter, "%08x ", fw->xmt4_dma_reg[cnt]);
1820 }
1821
1822 qla_uprintf(&uiter, "\n\nXMT Data DMA Common Registers");
1823 for (cnt = 0; cnt < sizeof(fw->xmt_data_dma_reg) / 4; cnt++) {
1824 if (cnt % 8 == 0)
1825 qla_uprintf(&uiter, "\n");
1826
1827 qla_uprintf(&uiter, "%08x ", fw->xmt_data_dma_reg[cnt]);
1828 }
1829
1830 qla_uprintf(&uiter, "\n\nRCV Thread 0 Data DMA Registers");
1831 for (cnt = 0; cnt < sizeof(fw->rcvt0_data_dma_reg) / 4; cnt++) {
1832 if (cnt % 8 == 0)
1833 qla_uprintf(&uiter, "\n");
1834
1835 qla_uprintf(&uiter, "%08x ", fw->rcvt0_data_dma_reg[cnt]);
1836 }
1837
1838 qla_uprintf(&uiter, "\n\nRCV Thread 1 Data DMA Registers");
1839 for (cnt = 0; cnt < sizeof(fw->rcvt1_data_dma_reg) / 4; cnt++) {
1840 if (cnt % 8 == 0)
1841 qla_uprintf(&uiter, "\n");
1842
1843 qla_uprintf(&uiter, "%08x ", fw->rcvt1_data_dma_reg[cnt]);
1844 }
1845
1846 qla_uprintf(&uiter, "\n\nRISC GP Registers");
1847 for (cnt = 0; cnt < sizeof(fw->risc_gp_reg) / 4; cnt++) {
1848 if (cnt % 8 == 0)
1849 qla_uprintf(&uiter, "\n");
1850
1851 qla_uprintf(&uiter, "%08x ", fw->risc_gp_reg[cnt]);
1852 }
1853
1854 qla_uprintf(&uiter, "\n\nLMC Registers");
1855 for (cnt = 0; cnt < sizeof(fw->lmc_reg) / 4; cnt++) {
1856 if (cnt % 8 == 0)
1857 qla_uprintf(&uiter, "\n");
1858
1859 qla_uprintf(&uiter, "%08x ", fw->lmc_reg[cnt]);
1860 }
1861
1862 qla_uprintf(&uiter, "\n\nFPM Hardware Registers");
1863 for (cnt = 0; cnt < sizeof(fw->fpm_hdw_reg) / 4; cnt++) {
1864 if (cnt % 8 == 0)
1865 qla_uprintf(&uiter, "\n");
1866
1867 qla_uprintf(&uiter, "%08x ", fw->fpm_hdw_reg[cnt]);
1868 }
1869
1870 qla_uprintf(&uiter, "\n\nFB Hardware Registers");
1871 for (cnt = 0; cnt < sizeof(fw->fb_hdw_reg) / 4; cnt++) {
1872 if (cnt % 8 == 0)
1873 qla_uprintf(&uiter, "\n");
1874
1875 qla_uprintf(&uiter, "%08x ", fw->fb_hdw_reg[cnt]);
1876 }
1877
1878 qla_uprintf(&uiter, "\n\nCode RAM");
1879 for (cnt = 0; cnt < sizeof (fw->code_ram) / 4; cnt++) {
1880 if (cnt % 8 == 0) {
1881 qla_uprintf(&uiter, "\n%08x: ", cnt + 0x20000);
1882 }
1883 qla_uprintf(&uiter, "%08x ", fw->code_ram[cnt]);
1884 }
1885
1886 qla_uprintf(&uiter, "\n\nExternal Memory");
1887 ext_mem_cnt = ha->fw_memory_size - 0x100000 + 1;
1888 for (cnt = 0; cnt < ext_mem_cnt; cnt++) {
1889 if (cnt % 8 == 0) {
1890 qla_uprintf(&uiter, "\n%08x: ", cnt + 0x100000);
1891 }
1892 qla_uprintf(&uiter, "%08x ", fw->ext_mem[cnt]);
1893 }
1894
1895 qla_uprintf(&uiter, "\n[<==END] ISP Debug Dump");
1896}
1897
1898
1899/****************************************************************************/ 1340/****************************************************************************/
1900/* Driver Debug Functions. */ 1341/* Driver Debug Functions. */
1901/****************************************************************************/ 1342/****************************************************************************/
diff --git a/drivers/scsi/qla2xxx/qla_dbg.h b/drivers/scsi/qla2xxx/qla_dbg.h
index ab6afeaa2f2c..533425338e05 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.h
+++ b/drivers/scsi/qla2xxx/qla_dbg.h
@@ -37,134 +37,86 @@
37/* 37/*
38* Macros use for debugging the driver. 38* Macros use for debugging the driver.
39*/ 39*/
40#undef ENTER_TRACE
41#if defined(ENTER_TRACE)
42#define ENTER(x) do { printk("qla2100 : Entering %s()\n", x); } while (0)
43#define LEAVE(x) do { printk("qla2100 : Leaving %s()\n", x); } while (0)
44#define ENTER_INTR(x) do { printk("qla2100 : Entering %s()\n", x); } while (0)
45#define LEAVE_INTR(x) do { printk("qla2100 : Leaving %s()\n", x); } while (0)
46#else
47#define ENTER(x) do {} while (0)
48#define LEAVE(x) do {} while (0)
49#define ENTER_INTR(x) do {} while (0)
50#define LEAVE_INTR(x) do {} while (0)
51#endif
52 40
53#if DEBUG_QLA2100 41#define DEBUG(x) do { if (extended_error_logging) { x; } } while (0)
54#define DEBUG(x) do {x;} while (0);
55#else
56#define DEBUG(x) do {} while (0);
57#endif
58 42
59#if defined(QL_DEBUG_LEVEL_1) 43#if defined(QL_DEBUG_LEVEL_1)
60#define DEBUG1(x) do {x;} while (0); 44#define DEBUG1(x) do {x;} while (0)
61#else 45#else
62#define DEBUG1(x) do {} while (0); 46#define DEBUG1(x) do {} while (0)
63#endif 47#endif
64 48
65#if defined(QL_DEBUG_LEVEL_2) 49#define DEBUG2(x) do { if (extended_error_logging) { x; } } while (0)
66#define DEBUG2(x) do {x;} while (0); 50#define DEBUG2_3(x) do { if (extended_error_logging) { x; } } while (0)
67#define DEBUG2_3(x) do {x;} while (0); 51#define DEBUG2_3_11(x) do { if (extended_error_logging) { x; } } while (0)
68#define DEBUG2_3_11(x) do {x;} while (0); 52#define DEBUG2_9_10(x) do { if (extended_error_logging) { x; } } while (0)
69#define DEBUG2_9_10(x) do {x;} while (0); 53#define DEBUG2_11(x) do { if (extended_error_logging) { x; } } while (0)
70#define DEBUG2_11(x) do {x;} while (0); 54#define DEBUG2_13(x) do { if (extended_error_logging) { x; } } while (0)
71#define DEBUG2_13(x) do {x;} while (0);
72#else
73#define DEBUG2(x) do {} while (0);
74#endif
75 55
76#if defined(QL_DEBUG_LEVEL_3) 56#if defined(QL_DEBUG_LEVEL_3)
77#define DEBUG3(x) do {x;} while (0); 57#define DEBUG3(x) do {x;} while (0)
78#define DEBUG2_3(x) do {x;} while (0); 58#define DEBUG3_11(x) do {x;} while (0)
79#define DEBUG2_3_11(x) do {x;} while (0);
80#define DEBUG3_11(x) do {x;} while (0);
81#else 59#else
82#define DEBUG3(x) do {} while (0); 60#define DEBUG3(x) do {} while (0)
83 #if !defined(QL_DEBUG_LEVEL_2)
84 #define DEBUG2_3(x) do {} while (0);
85 #endif
86#endif 61#endif
87 62
88#if defined(QL_DEBUG_LEVEL_4) 63#if defined(QL_DEBUG_LEVEL_4)
89#define DEBUG4(x) do {x;} while (0); 64#define DEBUG4(x) do {x;} while (0)
90#else 65#else
91#define DEBUG4(x) do {} while (0); 66#define DEBUG4(x) do {} while (0)
92#endif 67#endif
93 68
94#if defined(QL_DEBUG_LEVEL_5) 69#if defined(QL_DEBUG_LEVEL_5)
95#define DEBUG5(x) do {x;} while (0); 70#define DEBUG5(x) do {x;} while (0)
96#else 71#else
97#define DEBUG5(x) do {} while (0); 72#define DEBUG5(x) do {} while (0)
98#endif 73#endif
99 74
100#if defined(QL_DEBUG_LEVEL_7) 75#if defined(QL_DEBUG_LEVEL_7)
101#define DEBUG7(x) do {x;} while (0); 76#define DEBUG7(x) do {x;} while (0)
102#else 77#else
103#define DEBUG7(x) do {} while (0); 78#define DEBUG7(x) do {} while (0)
104#endif 79#endif
105 80
106#if defined(QL_DEBUG_LEVEL_9) 81#if defined(QL_DEBUG_LEVEL_9)
107#define DEBUG9(x) do {x;} while (0); 82#define DEBUG9(x) do {x;} while (0)
108#define DEBUG9_10(x) do {x;} while (0); 83#define DEBUG9_10(x) do {x;} while (0)
109#define DEBUG2_9_10(x) do {x;} while (0);
110#else 84#else
111#define DEBUG9(x) do {} while (0); 85#define DEBUG9(x) do {} while (0)
112#endif 86#endif
113 87
114#if defined(QL_DEBUG_LEVEL_10) 88#if defined(QL_DEBUG_LEVEL_10)
115#define DEBUG10(x) do {x;} while (0); 89#define DEBUG10(x) do {x;} while (0)
116#define DEBUG2_9_10(x) do {x;} while (0); 90#define DEBUG9_10(x) do {x;} while (0)
117#define DEBUG9_10(x) do {x;} while (0);
118#else 91#else
119#define DEBUG10(x) do {} while (0); 92#define DEBUG10(x) do {} while (0)
120 #if !defined(DEBUG2_9_10)
121 #define DEBUG2_9_10(x) do {} while (0);
122 #endif
123 #if !defined(DEBUG9_10) 93 #if !defined(DEBUG9_10)
124 #define DEBUG9_10(x) do {} while (0); 94 #define DEBUG9_10(x) do {} while (0)
125 #endif 95 #endif
126#endif 96#endif
127 97
128#if defined(QL_DEBUG_LEVEL_11) 98#if defined(QL_DEBUG_LEVEL_11)
129#define DEBUG11(x) do{x;} while(0); 99#define DEBUG11(x) do{x;} while(0)
130#if !defined(DEBUG2_11)
131#define DEBUG2_11(x) do{x;} while(0);
132#endif
133#if !defined(DEBUG2_3_11)
134#define DEBUG2_3_11(x) do{x;} while(0);
135#endif
136#if !defined(DEBUG3_11) 100#if !defined(DEBUG3_11)
137#define DEBUG3_11(x) do{x;} while(0); 101#define DEBUG3_11(x) do{x;} while(0)
138#endif 102#endif
139#else 103#else
140#define DEBUG11(x) do{} while(0); 104#define DEBUG11(x) do{} while(0)
141 #if !defined(QL_DEBUG_LEVEL_2)
142 #define DEBUG2_11(x) do{} while(0);
143 #if !defined(QL_DEBUG_LEVEL_3)
144 #define DEBUG2_3_11(x) do{} while(0);
145 #endif
146 #endif
147 #if !defined(QL_DEBUG_LEVEL_3) 105 #if !defined(QL_DEBUG_LEVEL_3)
148 #define DEBUG3_11(x) do{} while(0); 106 #define DEBUG3_11(x) do{} while(0)
149 #endif 107 #endif
150#endif 108#endif
151 109
152#if defined(QL_DEBUG_LEVEL_12) 110#if defined(QL_DEBUG_LEVEL_12)
153#define DEBUG12(x) do {x;} while (0); 111#define DEBUG12(x) do {x;} while (0)
154#else 112#else
155#define DEBUG12(x) do {} while (0); 113#define DEBUG12(x) do {} while (0)
156#endif 114#endif
157 115
158#if defined(QL_DEBUG_LEVEL_13) 116#if defined(QL_DEBUG_LEVEL_13)
159#define DEBUG13(x) do {x;} while (0) 117#define DEBUG13(x) do {x;} while (0)
160#if !defined(DEBUG2_13)
161#define DEBUG2_13(x) do {x;} while(0)
162#endif
163#else 118#else
164#define DEBUG13(x) do {} while (0) 119#define DEBUG13(x) do {} while (0)
165#if !defined(QL_DEBUG_LEVEL_2)
166#define DEBUG2_13(x) do {} while(0)
167#endif
168#endif 120#endif
169 121
170#if defined(QL_DEBUG_LEVEL_14) 122#if defined(QL_DEBUG_LEVEL_14)
@@ -176,9 +128,6 @@
176/* 128/*
177 * Firmware Dump structure definition 129 * Firmware Dump structure definition
178 */ 130 */
179#define FW_DUMP_SIZE_128K 0xBC000
180#define FW_DUMP_SIZE_512K 0x2FC000
181#define FW_DUMP_SIZE_1M 0x5FC000
182 131
183struct qla2300_fw_dump { 132struct qla2300_fw_dump {
184 uint16_t hccr; 133 uint16_t hccr;
@@ -224,8 +173,6 @@ struct qla2100_fw_dump {
224 uint16_t risc_ram[0xf000]; 173 uint16_t risc_ram[0xf000];
225}; 174};
226 175
227#define FW_DUMP_SIZE_24XX 0x2B0000
228
229struct qla24xx_fw_dump { 176struct qla24xx_fw_dump {
230 uint32_t host_status; 177 uint32_t host_status;
231 uint32_t host_reg[32]; 178 uint32_t host_reg[32];
@@ -257,3 +204,39 @@ struct qla24xx_fw_dump {
257 uint32_t code_ram[0x2000]; 204 uint32_t code_ram[0x2000];
258 uint32_t ext_mem[1]; 205 uint32_t ext_mem[1];
259}; 206};
207
208#define EFT_NUM_BUFFERS 4
209#define EFT_BYTES_PER_BUFFER 0x4000
210#define EFT_SIZE ((EFT_BYTES_PER_BUFFER) * (EFT_NUM_BUFFERS))
211
212struct qla2xxx_fw_dump {
213 uint8_t signature[4];
214 uint32_t version;
215
216 uint32_t fw_major_version;
217 uint32_t fw_minor_version;
218 uint32_t fw_subminor_version;
219 uint32_t fw_attributes;
220
221 uint32_t vendor;
222 uint32_t device;
223 uint32_t subsystem_vendor;
224 uint32_t subsystem_device;
225
226 uint32_t fixed_size;
227 uint32_t mem_size;
228 uint32_t req_q_size;
229 uint32_t rsp_q_size;
230
231 uint32_t eft_size;
232 uint32_t eft_addr_l;
233 uint32_t eft_addr_h;
234
235 uint32_t header_size;
236
237 union {
238 struct qla2100_fw_dump isp21;
239 struct qla2300_fw_dump isp23;
240 struct qla24xx_fw_dump isp24;
241 } isp;
242};
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 6734453ea28a..0930260aec2c 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -487,6 +487,7 @@ typedef struct {
487#define MBA_IP_RCV_BUFFER_EMPTY 0x8026 /* IP receive buffer queue empty. */ 487#define MBA_IP_RCV_BUFFER_EMPTY 0x8026 /* IP receive buffer queue empty. */
488#define MBA_IP_HDR_DATA_SPLIT 0x8027 /* IP header/data splitting feature */ 488#define MBA_IP_HDR_DATA_SPLIT 0x8027 /* IP header/data splitting feature */
489 /* used. */ 489 /* used. */
490#define MBA_TRACE_NOTIFICATION 0x8028 /* Trace/Diagnostic notification. */
490#define MBA_POINT_TO_POINT 0x8030 /* Point to point mode. */ 491#define MBA_POINT_TO_POINT 0x8030 /* Point to point mode. */
491#define MBA_CMPLT_1_16BIT 0x8031 /* Completion 1 16bit IOSB. */ 492#define MBA_CMPLT_1_16BIT 0x8031 /* Completion 1 16bit IOSB. */
492#define MBA_CMPLT_2_16BIT 0x8032 /* Completion 2 16bit IOSB. */ 493#define MBA_CMPLT_2_16BIT 0x8032 /* Completion 2 16bit IOSB. */
@@ -608,7 +609,9 @@ typedef struct {
608#define MBC_SERDES_PARAMS 0x10 /* Serdes Tx Parameters. */ 609#define MBC_SERDES_PARAMS 0x10 /* Serdes Tx Parameters. */
609#define MBC_GET_IOCB_STATUS 0x12 /* Get IOCB status command. */ 610#define MBC_GET_IOCB_STATUS 0x12 /* Get IOCB status command. */
610#define MBC_GET_TIMEOUT_PARAMS 0x22 /* Get FW timeouts. */ 611#define MBC_GET_TIMEOUT_PARAMS 0x22 /* Get FW timeouts. */
612#define MBC_TRACE_CONTROL 0x27 /* Trace control command. */
611#define MBC_GEN_SYSTEM_ERROR 0x2a /* Generate System Error. */ 613#define MBC_GEN_SYSTEM_ERROR 0x2a /* Generate System Error. */
614#define MBC_READ_SFP 0x31 /* Read SFP Data. */
612#define MBC_SET_TIMEOUT_PARAMS 0x32 /* Set FW timeouts. */ 615#define MBC_SET_TIMEOUT_PARAMS 0x32 /* Set FW timeouts. */
613#define MBC_MID_INITIALIZE_FIRMWARE 0x48 /* MID Initialize firmware. */ 616#define MBC_MID_INITIALIZE_FIRMWARE 0x48 /* MID Initialize firmware. */
614#define MBC_MID_GET_VP_DATABASE 0x49 /* MID Get VP Database. */ 617#define MBC_MID_GET_VP_DATABASE 0x49 /* MID Get VP Database. */
@@ -618,6 +621,9 @@ typedef struct {
618#define MBC_GET_LINK_PRIV_STATS 0x6d /* Get link & private data. */ 621#define MBC_GET_LINK_PRIV_STATS 0x6d /* Get link & private data. */
619#define MBC_SET_VENDOR_ID 0x76 /* Set Vendor ID. */ 622#define MBC_SET_VENDOR_ID 0x76 /* Set Vendor ID. */
620 623
624#define TC_ENABLE 4
625#define TC_DISABLE 5
626
621/* Firmware return data sizes */ 627/* Firmware return data sizes */
622#define FCAL_MAP_SIZE 128 628#define FCAL_MAP_SIZE 128
623 629
@@ -1997,7 +2003,6 @@ struct isp_operations {
1997 uint32_t); 2003 uint32_t);
1998 2004
1999 void (*fw_dump) (struct scsi_qla_host *, int); 2005 void (*fw_dump) (struct scsi_qla_host *, int);
2000 void (*ascii_fw_dump) (struct scsi_qla_host *);
2001 2006
2002 int (*beacon_on) (struct scsi_qla_host *); 2007 int (*beacon_on) (struct scsi_qla_host *);
2003 int (*beacon_off) (struct scsi_qla_host *); 2008 int (*beacon_off) (struct scsi_qla_host *);
@@ -2041,6 +2046,7 @@ typedef struct scsi_qla_host {
2041 uint32_t enable_led_scheme :1; 2046 uint32_t enable_led_scheme :1;
2042 uint32_t msi_enabled :1; 2047 uint32_t msi_enabled :1;
2043 uint32_t msix_enabled :1; 2048 uint32_t msix_enabled :1;
2049 uint32_t disable_serdes :1;
2044 } flags; 2050 } flags;
2045 2051
2046 atomic_t loop_state; 2052 atomic_t loop_state;
@@ -2238,6 +2244,11 @@ typedef struct scsi_qla_host {
2238 struct sns_cmd_pkt *sns_cmd; 2244 struct sns_cmd_pkt *sns_cmd;
2239 dma_addr_t sns_cmd_dma; 2245 dma_addr_t sns_cmd_dma;
2240 2246
2247#define SFP_DEV_SIZE 256
2248#define SFP_BLOCK_SIZE 64
2249 void *sfp_data;
2250 dma_addr_t sfp_data_dma;
2251
2241 struct task_struct *dpc_thread; 2252 struct task_struct *dpc_thread;
2242 uint8_t dpc_active; /* DPC routine is active */ 2253 uint8_t dpc_active; /* DPC routine is active */
2243 2254
@@ -2303,11 +2314,12 @@ typedef struct scsi_qla_host {
2303 uint16_t fw_seriallink_options24[4]; 2314 uint16_t fw_seriallink_options24[4];
2304 2315
2305 /* Firmware dump information. */ 2316 /* Firmware dump information. */
2306 void *fw_dump; 2317 struct qla2xxx_fw_dump *fw_dump;
2318 uint32_t fw_dump_len;
2307 int fw_dumped; 2319 int fw_dumped;
2308 int fw_dump_reading; 2320 int fw_dump_reading;
2309 char *fw_dump_buffer; 2321 dma_addr_t eft_dma;
2310 int fw_dump_buffer_len; 2322 void *eft;
2311 2323
2312 uint8_t host_str[16]; 2324 uint8_t host_str[16];
2313 uint32_t pci_attr; 2325 uint32_t pci_attr;
diff --git a/drivers/scsi/qla2xxx/qla_devtbl.h b/drivers/scsi/qla2xxx/qla_devtbl.h
index a8fc0ffc7fc5..dd435410dfa2 100644
--- a/drivers/scsi/qla2xxx/qla_devtbl.h
+++ b/drivers/scsi/qla2xxx/qla_devtbl.h
@@ -1,4 +1,4 @@
1#define QLA_MODEL_NAMES 0x4A 1#define QLA_MODEL_NAMES 0x57
2 2
3/* 3/*
4 * Adapter model names and descriptions. 4 * Adapter model names and descriptions.
@@ -76,6 +76,19 @@ static char *qla2x00_model_name[QLA_MODEL_NAMES*2] = {
76 "QLE2440", "PCI-Express to 4Gb FC, Single Channel", /* 0x145 */ 76 "QLE2440", "PCI-Express to 4Gb FC, Single Channel", /* 0x145 */
77 "QLE2464", "PCI-Express to 4Gb FC, Quad Channel", /* 0x146 */ 77 "QLE2464", "PCI-Express to 4Gb FC, Quad Channel", /* 0x146 */
78 "QLA2440", "PCI-X 2.0 to 4Gb FC, Single Channel", /* 0x147 */ 78 "QLA2440", "PCI-X 2.0 to 4Gb FC, Single Channel", /* 0x147 */
79 " ", " ", /* 0x148 */ 79 "HP AE369A", "PCI-X 2.0 to 4Gb FC, Dual Channel", /* 0x148 */
80 "QLA2340", "Sun 133MHz PCI-X to 2Gb FC, Single Channel", /* 0x149 */ 80 "QLA2340", "Sun 133MHz PCI-X to 2Gb FC, Single Channel", /* 0x149 */
81 " ", " ", /* 0x14a */
82 " ", " ", /* 0x14b */
83 "QMC2432M", "IBM eServer BC 4Gb FC Expansion Card CFFE", /* 0x14c */
84 "QMC2422M", "IBM eServer BC 4Gb FC Expansion Card CFFX", /* 0x14d */
85 "QLE220", "Sun PCI-Express to 4Gb FC, Single Channel", /* 0x14e */
86 " ", " ", /* 0x14f */
87 " ", " ", /* 0x150 */
88 " ", " ", /* 0x151 */
89 "QME2462", "PCI-Express to 4Gb FC, Dual Channel Mezz HBA", /* 0x152 */
90 "QMH2462", "PCI-Express to 4Gb FC, Dual Channel Mezz HBA", /* 0x153 */
91 " ", " ", /* 0x154 */
92 "QLE220", "PCI-Express to 4Gb FC, Single Channel", /* 0x155 */
93 "QLE220", "PCI-Express to 4Gb FC, Single Channel", /* 0x156 */
81}; 94};
diff --git a/drivers/scsi/qla2xxx/qla_fw.h b/drivers/scsi/qla2xxx/qla_fw.h
index 3af478663be7..a0a722cf4237 100644
--- a/drivers/scsi/qla2xxx/qla_fw.h
+++ b/drivers/scsi/qla2xxx/qla_fw.h
@@ -141,7 +141,7 @@ struct nvram_24xx {
141 * BIT 2 = Enable Memory Map BIOS 141 * BIT 2 = Enable Memory Map BIOS
142 * BIT 3 = Enable Selectable Boot 142 * BIT 3 = Enable Selectable Boot
143 * BIT 4 = Disable RISC code load 143 * BIT 4 = Disable RISC code load
144 * BIT 5 = 144 * BIT 5 = Disable Serdes
145 * BIT 6 = 145 * BIT 6 =
146 * BIT 7 = 146 * BIT 7 =
147 * 147 *
@@ -278,7 +278,7 @@ struct init_cb_24xx {
278 uint16_t response_q_length; 278 uint16_t response_q_length;
279 uint16_t request_q_length; 279 uint16_t request_q_length;
280 280
281 uint16_t link_down_timeout; /* Milliseconds. */ 281 uint16_t link_down_on_nos; /* Milliseconds. */
282 282
283 uint16_t prio_request_q_length; 283 uint16_t prio_request_q_length;
284 284
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index 164d53ccbfd0..8311ac2b93a8 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -31,13 +31,9 @@ extern void qla2x00_update_fw_options(struct scsi_qla_host *);
31extern void qla24xx_update_fw_options(scsi_qla_host_t *); 31extern void qla24xx_update_fw_options(scsi_qla_host_t *);
32extern int qla2x00_load_risc(struct scsi_qla_host *, uint32_t *); 32extern int qla2x00_load_risc(struct scsi_qla_host *, uint32_t *);
33extern int qla24xx_load_risc(scsi_qla_host_t *, uint32_t *); 33extern int qla24xx_load_risc(scsi_qla_host_t *, uint32_t *);
34extern int qla24xx_load_risc_flash(scsi_qla_host_t *, uint32_t *);
35
36extern fc_port_t *qla2x00_alloc_fcport(scsi_qla_host_t *, gfp_t);
37 34
38extern int qla2x00_loop_resync(scsi_qla_host_t *); 35extern int qla2x00_loop_resync(scsi_qla_host_t *);
39 36
40extern int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
41extern int qla2x00_fabric_login(scsi_qla_host_t *, fc_port_t *, uint16_t *); 37extern int qla2x00_fabric_login(scsi_qla_host_t *, fc_port_t *, uint16_t *);
42extern int qla2x00_local_device_login(scsi_qla_host_t *, fc_port_t *); 38extern int qla2x00_local_device_login(scsi_qla_host_t *, fc_port_t *);
43 39
@@ -51,6 +47,8 @@ extern int qla2x00_abort_isp(scsi_qla_host_t *);
51extern void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *); 47extern void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
52extern void qla2x00_reg_remote_port(scsi_qla_host_t *, fc_port_t *); 48extern void qla2x00_reg_remote_port(scsi_qla_host_t *, fc_port_t *);
53 49
50extern void qla2x00_alloc_fw_dump(scsi_qla_host_t *);
51
54/* 52/*
55 * Global Data in qla_os.c source file. 53 * Global Data in qla_os.c source file.
56 */ 54 */
@@ -61,6 +59,8 @@ extern int qlport_down_retry;
61extern int ql2xplogiabsentdevice; 59extern int ql2xplogiabsentdevice;
62extern int ql2xloginretrycount; 60extern int ql2xloginretrycount;
63extern int ql2xfdmienable; 61extern int ql2xfdmienable;
62extern int ql2xallocfwdump;
63extern int extended_error_logging;
64 64
65extern void qla2x00_sp_compl(scsi_qla_host_t *, srb_t *); 65extern void qla2x00_sp_compl(scsi_qla_host_t *, srb_t *);
66 66
@@ -80,8 +80,6 @@ extern void qla2xxx_wake_dpc(scsi_qla_host_t *);
80/* 80/*
81 * Global Function Prototypes in qla_iocb.c source file. 81 * Global Function Prototypes in qla_iocb.c source file.
82 */ 82 */
83extern void qla2x00_isp_cmd(scsi_qla_host_t *);
84
85extern uint16_t qla2x00_calc_iocbs_32(uint16_t); 83extern uint16_t qla2x00_calc_iocbs_32(uint16_t);
86extern uint16_t qla2x00_calc_iocbs_64(uint16_t); 84extern uint16_t qla2x00_calc_iocbs_64(uint16_t);
87extern void qla2x00_build_scsi_iocbs_32(srb_t *, cmd_entry_t *, uint16_t); 85extern void qla2x00_build_scsi_iocbs_32(srb_t *, cmd_entry_t *, uint16_t);
@@ -204,6 +202,12 @@ qla2x00_set_serdes_params(scsi_qla_host_t *, uint16_t, uint16_t, uint16_t);
204extern int 202extern int
205qla2x00_stop_firmware(scsi_qla_host_t *); 203qla2x00_stop_firmware(scsi_qla_host_t *);
206 204
205extern int
206qla2x00_trace_control(scsi_qla_host_t *, uint16_t, dma_addr_t, uint16_t);
207
208extern int
209qla2x00_read_sfp(scsi_qla_host_t *, dma_addr_t, uint16_t, uint16_t, uint16_t);
210
207/* 211/*
208 * Global Function Prototypes in qla_isr.c source file. 212 * Global Function Prototypes in qla_isr.c source file.
209 */ 213 */
@@ -254,9 +258,6 @@ extern int qla24xx_write_optrom_data(struct scsi_qla_host *, uint8_t *,
254extern void qla2100_fw_dump(scsi_qla_host_t *, int); 258extern void qla2100_fw_dump(scsi_qla_host_t *, int);
255extern void qla2300_fw_dump(scsi_qla_host_t *, int); 259extern void qla2300_fw_dump(scsi_qla_host_t *, int);
256extern void qla24xx_fw_dump(scsi_qla_host_t *, int); 260extern void qla24xx_fw_dump(scsi_qla_host_t *, int);
257extern void qla2100_ascii_fw_dump(scsi_qla_host_t *);
258extern void qla2300_ascii_fw_dump(scsi_qla_host_t *);
259extern void qla24xx_ascii_fw_dump(scsi_qla_host_t *);
260extern void qla2x00_dump_regs(scsi_qla_host_t *); 261extern void qla2x00_dump_regs(scsi_qla_host_t *);
261extern void qla2x00_dump_buffer(uint8_t *, uint32_t); 262extern void qla2x00_dump_buffer(uint8_t *, uint32_t);
262extern void qla2x00_print_scsi_cmd(struct scsi_cmnd *); 263extern void qla2x00_print_scsi_cmd(struct scsi_cmnd *);
@@ -280,13 +281,6 @@ extern void *qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *, uint32_t, uint32_t);
280extern int qla2x00_fdmi_register(scsi_qla_host_t *); 281extern int qla2x00_fdmi_register(scsi_qla_host_t *);
281 282
282/* 283/*
283 * Global Function Prototypes in qla_xioctl.c source file.
284 */
285#define qla2x00_enqueue_aen(ha, cmd, mode) do { } while (0)
286#define qla2x00_alloc_ioctl_mem(ha) (0)
287#define qla2x00_free_ioctl_mem(ha) do { } while (0)
288
289/*
290 * Global Function Prototypes in qla_attr.c source file. 284 * Global Function Prototypes in qla_attr.c source file.
291 */ 285 */
292struct class_device_attribute; 286struct class_device_attribute;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 3d4487eac9b7..859649160caa 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -39,6 +39,8 @@ static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
39 39
40static int qla2x00_restart_isp(scsi_qla_host_t *); 40static int qla2x00_restart_isp(scsi_qla_host_t *);
41 41
42static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
43
42/****************************************************************************/ 44/****************************************************************************/
43/* QLogic ISP2x00 Hardware Support Functions. */ 45/* QLogic ISP2x00 Hardware Support Functions. */
44/****************************************************************************/ 46/****************************************************************************/
@@ -89,6 +91,17 @@ qla2x00_initialize_adapter(scsi_qla_host_t *ha)
89 91
90 ha->isp_ops.nvram_config(ha); 92 ha->isp_ops.nvram_config(ha);
91 93
94 if (ha->flags.disable_serdes) {
95 /* Mask HBA via NVRAM settings? */
96 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
97 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
98 ha->port_name[0], ha->port_name[1],
99 ha->port_name[2], ha->port_name[3],
100 ha->port_name[4], ha->port_name[5],
101 ha->port_name[6], ha->port_name[7]);
102 return QLA_FUNCTION_FAILED;
103 }
104
92 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n"); 105 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
93 106
94 retry = 10; 107 retry = 10;
@@ -770,29 +783,104 @@ qla24xx_chip_diag(scsi_qla_host_t *ha)
770 return rval; 783 return rval;
771} 784}
772 785
773static void 786void
774qla2x00_alloc_fw_dump(scsi_qla_host_t *ha) 787qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
775{ 788{
776 uint32_t dump_size = 0; 789 int rval;
790 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
791 eft_size;
792 dma_addr_t eft_dma;
793 void *eft;
794
795 if (ha->fw_dump) {
796 qla_printk(KERN_WARNING, ha,
797 "Firmware dump previously allocated.\n");
798 return;
799 }
777 800
778 ha->fw_dumped = 0; 801 ha->fw_dumped = 0;
802 fixed_size = mem_size = eft_size = 0;
779 if (IS_QLA2100(ha) || IS_QLA2200(ha)) { 803 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
780 dump_size = sizeof(struct qla2100_fw_dump); 804 fixed_size = sizeof(struct qla2100_fw_dump);
781 } else if (IS_QLA23XX(ha)) { 805 } else if (IS_QLA23XX(ha)) {
782 dump_size = sizeof(struct qla2300_fw_dump); 806 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
783 dump_size += (ha->fw_memory_size - 0x11000) * sizeof(uint16_t); 807 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
784 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { 808 sizeof(uint16_t);
785 dump_size = sizeof(struct qla24xx_fw_dump); 809 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
786 dump_size += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t); 810 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
811 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
812 sizeof(uint32_t);
813
814 /* Allocate memory for Extended Trace Buffer. */
815 eft = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &eft_dma,
816 GFP_KERNEL);
817 if (!eft) {
818 qla_printk(KERN_WARNING, ha, "Unable to allocate "
819 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
820 goto cont_alloc;
821 }
822
823 rval = qla2x00_trace_control(ha, TC_ENABLE, eft_dma,
824 EFT_NUM_BUFFERS);
825 if (rval) {
826 qla_printk(KERN_WARNING, ha, "Unable to initialize "
827 "EFT (%d).\n", rval);
828 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
829 eft_dma);
830 goto cont_alloc;
831 }
832
833 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
834 EFT_SIZE / 1024);
835
836 eft_size = EFT_SIZE;
837 memset(eft, 0, eft_size);
838 ha->eft_dma = eft_dma;
839 ha->eft = eft;
787 } 840 }
841cont_alloc:
842 req_q_size = ha->request_q_length * sizeof(request_t);
843 rsp_q_size = ha->response_q_length * sizeof(response_t);
844
845 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
846 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
847 eft_size;
788 848
789 ha->fw_dump = vmalloc(dump_size); 849 ha->fw_dump = vmalloc(dump_size);
790 if (ha->fw_dump) 850 if (!ha->fw_dump) {
791 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
792 "dump...\n", dump_size / 1024);
793 else
794 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for " 851 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
795 "firmware dump!!!\n", dump_size / 1024); 852 "firmware dump!!!\n", dump_size / 1024);
853
854 if (ha->eft) {
855 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
856 ha->eft_dma);
857 ha->eft = NULL;
858 ha->eft_dma = 0;
859 }
860 return;
861 }
862
863 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
864 dump_size / 1024);
865
866 ha->fw_dump_len = dump_size;
867 ha->fw_dump->signature[0] = 'Q';
868 ha->fw_dump->signature[1] = 'L';
869 ha->fw_dump->signature[2] = 'G';
870 ha->fw_dump->signature[3] = 'C';
871 ha->fw_dump->version = __constant_htonl(1);
872
873 ha->fw_dump->fixed_size = htonl(fixed_size);
874 ha->fw_dump->mem_size = htonl(mem_size);
875 ha->fw_dump->req_q_size = htonl(req_q_size);
876 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
877
878 ha->fw_dump->eft_size = htonl(eft_size);
879 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
880 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
881
882 ha->fw_dump->header_size =
883 htonl(offsetof(struct qla2xxx_fw_dump, isp));
796} 884}
797 885
798/** 886/**
@@ -810,8 +898,6 @@ qla2x00_resize_request_q(scsi_qla_host_t *ha)
810 dma_addr_t request_dma; 898 dma_addr_t request_dma;
811 request_t *request_ring; 899 request_t *request_ring;
812 900
813 qla2x00_alloc_fw_dump(ha);
814
815 /* Valid only on recent ISPs. */ 901 /* Valid only on recent ISPs. */
816 if (IS_QLA2100(ha) || IS_QLA2200(ha)) 902 if (IS_QLA2100(ha) || IS_QLA2200(ha))
817 return; 903 return;
@@ -883,6 +969,9 @@ qla2x00_setup_chip(scsi_qla_host_t *ha)
883 &ha->fw_subminor_version, 969 &ha->fw_subminor_version,
884 &ha->fw_attributes, &ha->fw_memory_size); 970 &ha->fw_attributes, &ha->fw_memory_size);
885 qla2x00_resize_request_q(ha); 971 qla2x00_resize_request_q(ha);
972
973 if (ql2xallocfwdump)
974 qla2x00_alloc_fw_dump(ha);
886 } 975 }
887 } else { 976 } else {
888 DEBUG2(printk(KERN_INFO 977 DEBUG2(printk(KERN_INFO
@@ -1186,8 +1275,7 @@ qla2x00_fw_ready(scsi_qla_host_t *ha)
1186 rval = QLA_FUNCTION_FAILED; 1275 rval = QLA_FUNCTION_FAILED;
1187 1276
1188 if (atomic_read(&ha->loop_down_timer) && 1277 if (atomic_read(&ha->loop_down_timer) &&
1189 (fw_state >= FSTATE_LOSS_OF_SYNC || 1278 fw_state != FSTATE_READY) {
1190 fw_state == FSTATE_WAIT_AL_PA)) {
1191 /* Loop down. Timeout on min_wait for states 1279 /* Loop down. Timeout on min_wait for states
1192 * other than Wait for Login. 1280 * other than Wait for Login.
1193 */ 1281 */
@@ -1555,6 +1643,8 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
1555 /* 1643 /*
1556 * Set host adapter parameters. 1644 * Set host adapter parameters.
1557 */ 1645 */
1646 if (nv->host_p[0] & BIT_7)
1647 extended_error_logging = 1;
1558 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); 1648 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1559 /* Always load RISC code on non ISP2[12]00 chips. */ 1649 /* Always load RISC code on non ISP2[12]00 chips. */
1560 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) 1650 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
@@ -1563,6 +1653,7 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
1563 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); 1653 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1564 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0); 1654 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1565 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0; 1655 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1656 ha->flags.disable_serdes = 0;
1566 1657
1567 ha->operating_mode = 1658 ha->operating_mode =
1568 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; 1659 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
@@ -1701,7 +1792,7 @@ qla2x00_rport_del(void *data)
1701 * 1792 *
1702 * Returns a pointer to the allocated fcport, or NULL, if none available. 1793 * Returns a pointer to the allocated fcport, or NULL, if none available.
1703 */ 1794 */
1704fc_port_t * 1795static fc_port_t *
1705qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags) 1796qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1706{ 1797{
1707 fc_port_t *fcport; 1798 fc_port_t *fcport;
@@ -2497,7 +2588,7 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2497 * Context: 2588 * Context:
2498 * Kernel context. 2589 * Kernel context.
2499 */ 2590 */
2500int 2591static int
2501qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev) 2592qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2502{ 2593{
2503 int rval; 2594 int rval;
@@ -2972,6 +3063,7 @@ qla2x00_update_fcports(scsi_qla_host_t *ha)
2972int 3063int
2973qla2x00_abort_isp(scsi_qla_host_t *ha) 3064qla2x00_abort_isp(scsi_qla_host_t *ha)
2974{ 3065{
3066 int rval;
2975 unsigned long flags = 0; 3067 unsigned long flags = 0;
2976 uint16_t cnt; 3068 uint16_t cnt;
2977 srb_t *sp; 3069 srb_t *sp;
@@ -3028,6 +3120,16 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
3028 3120
3029 ha->isp_abort_cnt = 0; 3121 ha->isp_abort_cnt = 0;
3030 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags); 3122 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3123
3124 if (ha->eft) {
3125 rval = qla2x00_trace_control(ha, TC_ENABLE,
3126 ha->eft_dma, EFT_NUM_BUFFERS);
3127 if (rval) {
3128 qla_printk(KERN_WARNING, ha,
3129 "Unable to reinitialize EFT "
3130 "(%d).\n", rval);
3131 }
3132 }
3031 } else { /* failed the ISP abort */ 3133 } else { /* failed the ISP abort */
3032 ha->flags.online = 1; 3134 ha->flags.online = 1;
3033 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) { 3135 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
@@ -3048,14 +3150,14 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
3048 ha->isp_abort_cnt--; 3150 ha->isp_abort_cnt--;
3049 DEBUG(printk("qla%ld: ISP abort - " 3151 DEBUG(printk("qla%ld: ISP abort - "
3050 "retry remaining %d\n", 3152 "retry remaining %d\n",
3051 ha->host_no, ha->isp_abort_cnt);) 3153 ha->host_no, ha->isp_abort_cnt));
3052 status = 1; 3154 status = 1;
3053 } 3155 }
3054 } else { 3156 } else {
3055 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; 3157 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3056 DEBUG(printk("qla2x00(%ld): ISP error recovery " 3158 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3057 "- retrying (%d) more times\n", 3159 "- retrying (%d) more times\n",
3058 ha->host_no, ha->isp_abort_cnt);) 3160 ha->host_no, ha->isp_abort_cnt));
3059 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags); 3161 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3060 status = 1; 3162 status = 1;
3061 } 3163 }
@@ -3069,7 +3171,7 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
3069 } else { 3171 } else {
3070 DEBUG(printk(KERN_INFO 3172 DEBUG(printk(KERN_INFO
3071 "qla2x00_abort_isp(%ld): exiting.\n", 3173 "qla2x00_abort_isp(%ld): exiting.\n",
3072 ha->host_no);) 3174 ha->host_no));
3073 } 3175 }
3074 3176
3075 return(status); 3177 return(status);
@@ -3145,7 +3247,7 @@ qla2x00_restart_isp(scsi_qla_host_t *ha)
3145 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); 3247 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3146 if (!(status = qla2x00_fw_ready(ha))) { 3248 if (!(status = qla2x00_fw_ready(ha))) {
3147 DEBUG(printk("%s(): Start configure loop, " 3249 DEBUG(printk("%s(): Start configure loop, "
3148 "status = %d\n", __func__, status);) 3250 "status = %d\n", __func__, status));
3149 3251
3150 /* Issue a marker after FW becomes ready. */ 3252 /* Issue a marker after FW becomes ready. */
3151 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL); 3253 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
@@ -3169,7 +3271,7 @@ qla2x00_restart_isp(scsi_qla_host_t *ha)
3169 3271
3170 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n", 3272 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3171 __func__, 3273 __func__,
3172 status);) 3274 status));
3173 } 3275 }
3174 return (status); 3276 return (status);
3175} 3277}
@@ -3289,7 +3391,6 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
3289 nv->node_name[6] = 0x55; 3391 nv->node_name[6] = 0x55;
3290 nv->node_name[7] = 0x86; 3392 nv->node_name[7] = 0x86;
3291 nv->login_retry_count = __constant_cpu_to_le16(8); 3393 nv->login_retry_count = __constant_cpu_to_le16(8);
3292 nv->link_down_timeout = __constant_cpu_to_le16(200);
3293 nv->interrupt_delay_timer = __constant_cpu_to_le16(0); 3394 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3294 nv->login_timeout = __constant_cpu_to_le16(0); 3395 nv->login_timeout = __constant_cpu_to_le16(0);
3295 nv->firmware_options_1 = 3396 nv->firmware_options_1 =
@@ -3318,7 +3419,7 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
3318 *dptr1++ = *dptr2++; 3419 *dptr1++ = *dptr2++;
3319 3420
3320 icb->login_retry_count = nv->login_retry_count; 3421 icb->login_retry_count = nv->login_retry_count;
3321 icb->link_down_timeout = nv->link_down_timeout; 3422 icb->link_down_on_nos = nv->link_down_on_nos;
3322 3423
3323 /* Copy 2nd segment. */ 3424 /* Copy 2nd segment. */
3324 dptr1 = (uint8_t *)&icb->interrupt_delay_timer; 3425 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
@@ -3373,6 +3474,7 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
3373 ha->flags.enable_lip_full_login = 1; 3474 ha->flags.enable_lip_full_login = 1;
3374 ha->flags.enable_target_reset = 1; 3475 ha->flags.enable_target_reset = 1;
3375 ha->flags.enable_led_scheme = 0; 3476 ha->flags.enable_led_scheme = 0;
3477 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3376 3478
3377 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & 3479 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3378 (BIT_6 | BIT_5 | BIT_4)) >> 4; 3480 (BIT_6 | BIT_5 | BIT_4)) >> 4;
@@ -3472,7 +3574,7 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
3472 return (rval); 3574 return (rval);
3473} 3575}
3474 3576
3475int 3577static int
3476qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr) 3578qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3477{ 3579{
3478 int rval; 3580 int rval;
diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index 8c769cfaa14c..c5b3c610a32a 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -15,6 +15,7 @@ static inline uint16_t qla2x00_get_cmd_direction(struct scsi_cmnd *cmd);
15static inline cont_entry_t *qla2x00_prep_cont_type0_iocb(scsi_qla_host_t *); 15static inline cont_entry_t *qla2x00_prep_cont_type0_iocb(scsi_qla_host_t *);
16static inline cont_a64_entry_t *qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *); 16static inline cont_a64_entry_t *qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *);
17static request_t *qla2x00_req_pkt(scsi_qla_host_t *ha); 17static request_t *qla2x00_req_pkt(scsi_qla_host_t *ha);
18static void qla2x00_isp_cmd(scsi_qla_host_t *ha);
18 19
19/** 20/**
20 * qla2x00_get_cmd_direction() - Determine control_flag data direction. 21 * qla2x00_get_cmd_direction() - Determine control_flag data direction.
@@ -470,6 +471,7 @@ __qla2x00_marker(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun,
470 mrk24->nport_handle = cpu_to_le16(loop_id); 471 mrk24->nport_handle = cpu_to_le16(loop_id);
471 mrk24->lun[1] = LSB(lun); 472 mrk24->lun[1] = LSB(lun);
472 mrk24->lun[2] = MSB(lun); 473 mrk24->lun[2] = MSB(lun);
474 host_to_fcp_swap(mrk24->lun, sizeof(mrk24->lun));
473 } else { 475 } else {
474 SET_TARGET_ID(ha, mrk->target, loop_id); 476 SET_TARGET_ID(ha, mrk->target, loop_id);
475 mrk->lun = cpu_to_le16(lun); 477 mrk->lun = cpu_to_le16(lun);
@@ -574,7 +576,7 @@ qla2x00_req_pkt(scsi_qla_host_t *ha)
574 * 576 *
575 * Note: The caller must hold the hardware lock before calling this routine. 577 * Note: The caller must hold the hardware lock before calling this routine.
576 */ 578 */
577void 579static void
578qla2x00_isp_cmd(scsi_qla_host_t *ha) 580qla2x00_isp_cmd(scsi_qla_host_t *ha)
579{ 581{
580 device_reg_t __iomem *reg = ha->iobase; 582 device_reg_t __iomem *reg = ha->iobase;
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index b28ac0a27e25..de0613135f70 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -395,10 +395,6 @@ qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
395 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); 395 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
396 396
397 ha->flags.management_server_logged_in = 0; 397 ha->flags.management_server_logged_in = 0;
398
399 /* Update AEN queue. */
400 qla2x00_enqueue_aen(ha, MBA_LIP_OCCURRED, NULL);
401
402 break; 398 break;
403 399
404 case MBA_LOOP_UP: /* Loop Up Event */ 400 case MBA_LOOP_UP: /* Loop Up Event */
@@ -418,9 +414,6 @@ qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
418 link_speed); 414 link_speed);
419 415
420 ha->flags.management_server_logged_in = 0; 416 ha->flags.management_server_logged_in = 0;
421
422 /* Update AEN queue. */
423 qla2x00_enqueue_aen(ha, MBA_LOOP_UP, NULL);
424 break; 417 break;
425 418
426 case MBA_LOOP_DOWN: /* Loop Down Event */ 419 case MBA_LOOP_DOWN: /* Loop Down Event */
@@ -439,9 +432,6 @@ qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
439 ha->link_data_rate = LDR_UNKNOWN; 432 ha->link_data_rate = LDR_UNKNOWN;
440 if (ql2xfdmienable) 433 if (ql2xfdmienable)
441 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags); 434 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
442
443 /* Update AEN queue. */
444 qla2x00_enqueue_aen(ha, MBA_LOOP_DOWN, NULL);
445 break; 435 break;
446 436
447 case MBA_LIP_RESET: /* LIP reset occurred */ 437 case MBA_LIP_RESET: /* LIP reset occurred */
@@ -460,10 +450,6 @@ qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
460 450
461 ha->operating_mode = LOOP; 451 ha->operating_mode = LOOP;
462 ha->flags.management_server_logged_in = 0; 452 ha->flags.management_server_logged_in = 0;
463
464 /* Update AEN queue. */
465 qla2x00_enqueue_aen(ha, MBA_LIP_RESET, NULL);
466
467 break; 453 break;
468 454
469 case MBA_POINT_TO_POINT: /* Point-to-Point */ 455 case MBA_POINT_TO_POINT: /* Point-to-Point */
@@ -545,9 +531,6 @@ qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
545 531
546 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); 532 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
547 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); 533 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
548
549 /* Update AEN queue. */
550 qla2x00_enqueue_aen(ha, MBA_PORT_UPDATE, NULL);
551 break; 534 break;
552 535
553 case MBA_RSCN_UPDATE: /* State Change Registration */ 536 case MBA_RSCN_UPDATE: /* State Change Registration */
@@ -584,9 +567,6 @@ qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
584 567
585 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); 568 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
586 set_bit(RSCN_UPDATE, &ha->dpc_flags); 569 set_bit(RSCN_UPDATE, &ha->dpc_flags);
587
588 /* Update AEN queue. */
589 qla2x00_enqueue_aen(ha, MBA_RSCN_UPDATE, &mb[0]);
590 break; 570 break;
591 571
592 /* case MBA_RIO_RESPONSE: */ 572 /* case MBA_RIO_RESPONSE: */
@@ -607,6 +587,11 @@ qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
607 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x " 587 DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
608 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3])); 588 "%04x.\n", ha->host_no, mb[1], mb[2], mb[3]));
609 break; 589 break;
590
591 case MBA_TRACE_NOTIFICATION:
592 DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
593 ha->host_no, mb[1], mb[2]));
594 break;
610 } 595 }
611} 596}
612 597
@@ -1452,8 +1437,8 @@ qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1452 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n", 1437 DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n",
1453 __func__, ha->host_no, pkt, pkt->handle)); 1438 __func__, ha->host_no, pkt, pkt->handle));
1454 1439
1455 DEBUG9(printk("%s: ct pkt dump:\n", __func__);) 1440 DEBUG9(printk("%s: ct pkt dump:\n", __func__));
1456 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx));) 1441 DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx)));
1457 1442
1458 /* Validate handle. */ 1443 /* Validate handle. */
1459 if (pkt->handle < MAX_OUTSTANDING_COMMANDS) 1444 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index d6cb3bd1a29a..879f281e2ea2 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -13,13 +13,13 @@ qla2x00_mbx_sem_timeout(unsigned long data)
13{ 13{
14 struct semaphore *sem_ptr = (struct semaphore *)data; 14 struct semaphore *sem_ptr = (struct semaphore *)data;
15 15
16 DEBUG11(printk("qla2x00_sem_timeout: entered.\n");) 16 DEBUG11(printk("qla2x00_sem_timeout: entered.\n"));
17 17
18 if (sem_ptr != NULL) { 18 if (sem_ptr != NULL) {
19 up(sem_ptr); 19 up(sem_ptr);
20 } 20 }
21 21
22 DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n");) 22 DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n"));
23} 23}
24 24
25/* 25/*
@@ -61,7 +61,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
61 rval = QLA_SUCCESS; 61 rval = QLA_SUCCESS;
62 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); 62 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
63 63
64 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);) 64 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
65 65
66 /* 66 /*
67 * Wait for active mailbox commands to finish by waiting at most tov 67 * Wait for active mailbox commands to finish by waiting at most tov
@@ -72,7 +72,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
72 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) { 72 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
73 /* Timeout occurred. Return error. */ 73 /* Timeout occurred. Return error. */
74 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. " 74 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
75 "Exiting.\n", __func__, ha->host_no);) 75 "Exiting.\n", __func__, ha->host_no));
76 return QLA_FUNCTION_TIMEOUT; 76 return QLA_FUNCTION_TIMEOUT;
77 } 77 }
78 } 78 }
@@ -86,7 +86,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
86 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags); 86 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
87 87
88 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n", 88 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
89 ha->host_no, mcp->mb[0]);) 89 ha->host_no, mcp->mb[0]));
90 90
91 spin_lock_irqsave(&ha->hardware_lock, flags); 91 spin_lock_irqsave(&ha->hardware_lock, flags);
92 92
@@ -131,14 +131,14 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
131 131
132 /* Unlock mbx registers and wait for interrupt */ 132 /* Unlock mbx registers and wait for interrupt */
133 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. " 133 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
134 "jiffies=%lx.\n", __func__, ha->host_no, jiffies);) 134 "jiffies=%lx.\n", __func__, ha->host_no, jiffies));
135 135
136 /* Wait for mbx cmd completion until timeout */ 136 /* Wait for mbx cmd completion until timeout */
137 137
138 if (!abort_active && io_lock_on) { 138 if (!abort_active && io_lock_on) {
139 /* sleep on completion semaphore */ 139 /* sleep on completion semaphore */
140 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n", 140 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
141 __func__, ha->host_no);) 141 __func__, ha->host_no));
142 142
143 init_timer(&tmp_intr_timer); 143 init_timer(&tmp_intr_timer);
144 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem; 144 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
@@ -147,11 +147,11 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
147 (void (*)(unsigned long))qla2x00_mbx_sem_timeout; 147 (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
148 148
149 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__, 149 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__,
150 ha->host_no);) 150 ha->host_no));
151 add_timer(&tmp_intr_timer); 151 add_timer(&tmp_intr_timer);
152 152
153 DEBUG11(printk("%s(%ld): going to unlock & sleep. " 153 DEBUG11(printk("%s(%ld): going to unlock & sleep. "
154 "time=0x%lx.\n", __func__, ha->host_no, jiffies);) 154 "time=0x%lx.\n", __func__, ha->host_no, jiffies));
155 155
156 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); 156 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
157 157
@@ -170,14 +170,14 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
170 down(&ha->mbx_intr_sem); 170 down(&ha->mbx_intr_sem);
171 171
172 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__, 172 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__,
173 ha->host_no, jiffies);) 173 ha->host_no, jiffies));
174 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); 174 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
175 175
176 /* delete the timer */ 176 /* delete the timer */
177 del_timer(&tmp_intr_timer); 177 del_timer(&tmp_intr_timer);
178 } else { 178 } else {
179 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__, 179 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
180 ha->host_no, command);) 180 ha->host_no, command));
181 181
182 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) 182 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
183 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT); 183 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
@@ -209,7 +209,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
209 uint16_t *iptr2; 209 uint16_t *iptr2;
210 210
211 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__, 211 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
212 ha->host_no, command);) 212 ha->host_no, command));
213 213
214 /* Got interrupt. Clear the flag. */ 214 /* Got interrupt. Clear the flag. */
215 ha->flags.mbox_int = 0; 215 ha->flags.mbox_int = 0;
@@ -266,7 +266,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
266 266
267 if (!abort_active) { 267 if (!abort_active) {
268 DEBUG11(printk("%s(%ld): checking for additional resp " 268 DEBUG11(printk("%s(%ld): checking for additional resp "
269 "interrupt.\n", __func__, ha->host_no);) 269 "interrupt.\n", __func__, ha->host_no));
270 270
271 /* polling mode for non isp_abort commands. */ 271 /* polling mode for non isp_abort commands. */
272 qla2x00_poll(ha); 272 qla2x00_poll(ha);
@@ -277,9 +277,9 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
277 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) { 277 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
278 /* not in dpc. schedule it for dpc to take over. */ 278 /* not in dpc. schedule it for dpc to take over. */
279 DEBUG(printk("%s(%ld): timeout schedule " 279 DEBUG(printk("%s(%ld): timeout schedule "
280 "isp_abort_needed.\n", __func__, ha->host_no);) 280 "isp_abort_needed.\n", __func__, ha->host_no));
281 DEBUG2_3_11(printk("%s(%ld): timeout schedule " 281 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
282 "isp_abort_needed.\n", __func__, ha->host_no);) 282 "isp_abort_needed.\n", __func__, ha->host_no));
283 qla_printk(KERN_WARNING, ha, 283 qla_printk(KERN_WARNING, ha,
284 "Mailbox command timeout occured. Scheduling ISP " 284 "Mailbox command timeout occured. Scheduling ISP "
285 "abort.\n"); 285 "abort.\n");
@@ -288,9 +288,9 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
288 } else if (!abort_active) { 288 } else if (!abort_active) {
289 /* call abort directly since we are in the DPC thread */ 289 /* call abort directly since we are in the DPC thread */
290 DEBUG(printk("%s(%ld): timeout calling abort_isp\n", 290 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
291 __func__, ha->host_no);) 291 __func__, ha->host_no));
292 DEBUG2_3_11(printk("%s(%ld): timeout calling " 292 DEBUG2_3_11(printk("%s(%ld): timeout calling "
293 "abort_isp\n", __func__, ha->host_no);) 293 "abort_isp\n", __func__, ha->host_no));
294 qla_printk(KERN_WARNING, ha, 294 qla_printk(KERN_WARNING, ha,
295 "Mailbox command timeout occured. Issuing ISP " 295 "Mailbox command timeout occured. Issuing ISP "
296 "abort.\n"); 296 "abort.\n");
@@ -303,9 +303,9 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
303 } 303 }
304 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); 304 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
305 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__, 305 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
306 ha->host_no);) 306 ha->host_no));
307 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n", 307 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
308 __func__, ha->host_no);) 308 __func__, ha->host_no));
309 } 309 }
310 } 310 }
311 311
@@ -316,9 +316,9 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
316 if (rval) { 316 if (rval) {
317 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, " 317 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
318 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no, 318 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
319 mcp->mb[0], mcp->mb[1], mcp->mb[2], command);) 319 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
320 } else { 320 } else {
321 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);) 321 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
322 } 322 }
323 323
324 return rval; 324 return rval;
@@ -394,7 +394,7 @@ qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
394 mbx_cmd_t mc; 394 mbx_cmd_t mc;
395 mbx_cmd_t *mcp = &mc; 395 mbx_cmd_t *mcp = &mc;
396 396
397 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);) 397 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
398 398
399 mcp->mb[0] = MBC_EXECUTE_FIRMWARE; 399 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
400 mcp->out_mb = MBX_0; 400 mcp->out_mb = MBX_0;
@@ -424,10 +424,10 @@ qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
424 } else { 424 } else {
425 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { 425 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
426 DEBUG11(printk("%s(%ld): done exchanges=%x.\n", 426 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
427 __func__, ha->host_no, mcp->mb[1]);) 427 __func__, ha->host_no, mcp->mb[1]));
428 } else { 428 } else {
429 DEBUG11(printk("%s(%ld): done.\n", __func__, 429 DEBUG11(printk("%s(%ld): done.\n", __func__,
430 ha->host_no);) 430 ha->host_no));
431 } 431 }
432 } 432 }
433 433
@@ -611,7 +611,7 @@ qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
611 mbx_cmd_t mc; 611 mbx_cmd_t mc;
612 mbx_cmd_t *mcp = &mc; 612 mbx_cmd_t *mcp = &mc;
613 613
614 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no);) 614 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no));
615 615
616 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST; 616 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
617 mcp->mb[1] = 0xAAAA; 617 mcp->mb[1] = 0xAAAA;
@@ -639,11 +639,11 @@ qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
639 if (rval != QLA_SUCCESS) { 639 if (rval != QLA_SUCCESS) {
640 /*EMPTY*/ 640 /*EMPTY*/
641 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n", 641 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
642 ha->host_no, rval);) 642 ha->host_no, rval));
643 } else { 643 } else {
644 /*EMPTY*/ 644 /*EMPTY*/
645 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n", 645 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
646 ha->host_no);) 646 ha->host_no));
647 } 647 }
648 648
649 return rval; 649 return rval;
@@ -671,7 +671,7 @@ qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
671 mbx_cmd_t mc; 671 mbx_cmd_t mc;
672 mbx_cmd_t *mcp = &mc; 672 mbx_cmd_t *mcp = &mc;
673 673
674 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);) 674 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
675 675
676 mcp->mb[0] = MBC_VERIFY_CHECKSUM; 676 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
677 mcp->out_mb = MBX_0; 677 mcp->out_mb = MBX_0;
@@ -694,9 +694,9 @@ qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
694 if (rval != QLA_SUCCESS) { 694 if (rval != QLA_SUCCESS) {
695 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__, 695 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
696 ha->host_no, rval, (IS_QLA24XX(ha) || IS_QLA54XX(ha) ? 696 ha->host_no, rval, (IS_QLA24XX(ha) || IS_QLA54XX(ha) ?
697 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));) 697 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1])));
698 } else { 698 } else {
699 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);) 699 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
700 } 700 }
701 701
702 return rval; 702 return rval;
@@ -743,9 +743,9 @@ qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
743 if (rval != QLA_SUCCESS) { 743 if (rval != QLA_SUCCESS) {
744 /*EMPTY*/ 744 /*EMPTY*/
745 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n", 745 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
746 ha->host_no, rval);) 746 ha->host_no, rval));
747 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n", 747 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
748 ha->host_no, rval);) 748 ha->host_no, rval));
749 } else { 749 } else {
750 sts_entry_t *sts_entry = (sts_entry_t *) buffer; 750 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
751 751
@@ -781,7 +781,7 @@ qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
781 mbx_cmd_t mc; 781 mbx_cmd_t mc;
782 mbx_cmd_t *mcp = &mc; 782 mbx_cmd_t *mcp = &mc;
783 783
784 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no);) 784 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no));
785 785
786 fcport = sp->fcport; 786 fcport = sp->fcport;
787 787
@@ -813,11 +813,11 @@ qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
813 813
814 if (rval != QLA_SUCCESS) { 814 if (rval != QLA_SUCCESS) {
815 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n", 815 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
816 ha->host_no, rval);) 816 ha->host_no, rval));
817 } else { 817 } else {
818 sp->flags |= SRB_ABORT_PENDING; 818 sp->flags |= SRB_ABORT_PENDING;
819 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n", 819 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
820 ha->host_no);) 820 ha->host_no));
821 } 821 }
822 822
823 return rval; 823 return rval;
@@ -848,7 +848,7 @@ qla2x00_abort_target(fc_port_t *fcport)
848 if (fcport == NULL) 848 if (fcport == NULL)
849 return 0; 849 return 0;
850 850
851 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);) 851 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
852 852
853 ha = fcport->ha; 853 ha = fcport->ha;
854 mcp->mb[0] = MBC_ABORT_TARGET; 854 mcp->mb[0] = MBC_ABORT_TARGET;
@@ -872,11 +872,11 @@ qla2x00_abort_target(fc_port_t *fcport)
872 872
873 if (rval != QLA_SUCCESS) { 873 if (rval != QLA_SUCCESS) {
874 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n", 874 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
875 ha->host_no, rval);) 875 ha->host_no, rval));
876 } else { 876 } else {
877 /*EMPTY*/ 877 /*EMPTY*/
878 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n", 878 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
879 ha->host_no);) 879 ha->host_no));
880 } 880 }
881 881
882 return rval; 882 return rval;
@@ -912,7 +912,7 @@ qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
912 mbx_cmd_t *mcp = &mc; 912 mbx_cmd_t *mcp = &mc;
913 913
914 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n", 914 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
915 ha->host_no);) 915 ha->host_no));
916 916
917 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID; 917 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
918 mcp->out_mb = MBX_0; 918 mcp->out_mb = MBX_0;
@@ -933,11 +933,11 @@ qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
933 if (rval != QLA_SUCCESS) { 933 if (rval != QLA_SUCCESS) {
934 /*EMPTY*/ 934 /*EMPTY*/
935 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n", 935 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
936 ha->host_no, rval);) 936 ha->host_no, rval));
937 } else { 937 } else {
938 /*EMPTY*/ 938 /*EMPTY*/
939 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n", 939 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
940 ha->host_no);) 940 ha->host_no));
941 } 941 }
942 942
943 return rval; 943 return rval;
@@ -968,7 +968,7 @@ qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
968 mbx_cmd_t *mcp = &mc; 968 mbx_cmd_t *mcp = &mc;
969 969
970 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n", 970 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
971 ha->host_no);) 971 ha->host_no));
972 972
973 mcp->mb[0] = MBC_GET_RETRY_COUNT; 973 mcp->mb[0] = MBC_GET_RETRY_COUNT;
974 mcp->out_mb = MBX_0; 974 mcp->out_mb = MBX_0;
@@ -980,7 +980,7 @@ qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
980 if (rval != QLA_SUCCESS) { 980 if (rval != QLA_SUCCESS) {
981 /*EMPTY*/ 981 /*EMPTY*/
982 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n", 982 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
983 ha->host_no, mcp->mb[0]);) 983 ha->host_no, mcp->mb[0]));
984 } else { 984 } else {
985 /* Convert returned data and check our values. */ 985 /* Convert returned data and check our values. */
986 *r_a_tov = mcp->mb[3] / 2; 986 *r_a_tov = mcp->mb[3] / 2;
@@ -992,7 +992,7 @@ qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
992 } 992 }
993 993
994 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d " 994 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
995 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov);) 995 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov));
996 } 996 }
997 997
998 return rval; 998 return rval;
@@ -1023,7 +1023,7 @@ qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1023 mbx_cmd_t *mcp = &mc; 1023 mbx_cmd_t *mcp = &mc;
1024 1024
1025 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n", 1025 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1026 ha->host_no);) 1026 ha->host_no));
1027 1027
1028 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE; 1028 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1029 mcp->mb[2] = MSW(ha->init_cb_dma); 1029 mcp->mb[2] = MSW(ha->init_cb_dma);
@@ -1043,11 +1043,11 @@ qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1043 /*EMPTY*/ 1043 /*EMPTY*/
1044 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x " 1044 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1045 "mb0=%x.\n", 1045 "mb0=%x.\n",
1046 ha->host_no, rval, mcp->mb[0]);) 1046 ha->host_no, rval, mcp->mb[0]));
1047 } else { 1047 } else {
1048 /*EMPTY*/ 1048 /*EMPTY*/
1049 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n", 1049 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1050 ha->host_no);) 1050 ha->host_no));
1051 } 1051 }
1052 1052
1053 return rval; 1053 return rval;
@@ -1079,7 +1079,7 @@ qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1079 struct port_database_24xx *pd24; 1079 struct port_database_24xx *pd24;
1080 dma_addr_t pd_dma; 1080 dma_addr_t pd_dma;
1081 1081
1082 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);) 1082 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1083 1083
1084 pd24 = NULL; 1084 pd24 = NULL;
1085 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma); 1085 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
@@ -1220,7 +1220,7 @@ qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1220 mbx_cmd_t *mcp = &mc; 1220 mbx_cmd_t *mcp = &mc;
1221 1221
1222 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n", 1222 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1223 ha->host_no);) 1223 ha->host_no));
1224 1224
1225 mcp->mb[0] = MBC_GET_FIRMWARE_STATE; 1225 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1226 mcp->out_mb = MBX_0; 1226 mcp->out_mb = MBX_0;
@@ -1235,11 +1235,11 @@ qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1235 if (rval != QLA_SUCCESS) { 1235 if (rval != QLA_SUCCESS) {
1236 /*EMPTY*/ 1236 /*EMPTY*/
1237 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): " 1237 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1238 "failed=%x.\n", ha->host_no, rval);) 1238 "failed=%x.\n", ha->host_no, rval));
1239 } else { 1239 } else {
1240 /*EMPTY*/ 1240 /*EMPTY*/
1241 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n", 1241 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1242 ha->host_no);) 1242 ha->host_no));
1243 } 1243 }
1244 1244
1245 return rval; 1245 return rval;
@@ -1272,7 +1272,7 @@ qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1272 mbx_cmd_t *mcp = &mc; 1272 mbx_cmd_t *mcp = &mc;
1273 1273
1274 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n", 1274 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1275 ha->host_no);) 1275 ha->host_no));
1276 1276
1277 mcp->mb[0] = MBC_GET_PORT_NAME; 1277 mcp->mb[0] = MBC_GET_PORT_NAME;
1278 mcp->out_mb = MBX_1|MBX_0; 1278 mcp->out_mb = MBX_1|MBX_0;
@@ -1292,7 +1292,7 @@ qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1292 if (rval != QLA_SUCCESS) { 1292 if (rval != QLA_SUCCESS) {
1293 /*EMPTY*/ 1293 /*EMPTY*/
1294 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n", 1294 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1295 ha->host_no, rval);) 1295 ha->host_no, rval));
1296 } else { 1296 } else {
1297 if (name != NULL) { 1297 if (name != NULL) {
1298 /* This function returns name in big endian. */ 1298 /* This function returns name in big endian. */
@@ -1307,7 +1307,7 @@ qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1307 } 1307 }
1308 1308
1309 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n", 1309 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1310 ha->host_no);) 1310 ha->host_no));
1311 } 1311 }
1312 1312
1313 return rval; 1313 return rval;
@@ -1335,7 +1335,7 @@ qla2x00_lip_reset(scsi_qla_host_t *ha)
1335 mbx_cmd_t mc; 1335 mbx_cmd_t mc;
1336 mbx_cmd_t *mcp = &mc; 1336 mbx_cmd_t *mcp = &mc;
1337 1337
1338 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);) 1338 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1339 1339
1340 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { 1340 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1341 mcp->mb[0] = MBC_LIP_FULL_LOGIN; 1341 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
@@ -1364,10 +1364,10 @@ qla2x00_lip_reset(scsi_qla_host_t *ha)
1364 if (rval != QLA_SUCCESS) { 1364 if (rval != QLA_SUCCESS) {
1365 /*EMPTY*/ 1365 /*EMPTY*/
1366 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", 1366 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1367 __func__, ha->host_no, rval);) 1367 __func__, ha->host_no, rval));
1368 } else { 1368 } else {
1369 /*EMPTY*/ 1369 /*EMPTY*/
1370 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);) 1370 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1371 } 1371 }
1372 1372
1373 return rval; 1373 return rval;
@@ -1400,10 +1400,10 @@ qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1400 mbx_cmd_t *mcp = &mc; 1400 mbx_cmd_t *mcp = &mc;
1401 1401
1402 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n", 1402 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1403 ha->host_no);) 1403 ha->host_no));
1404 1404
1405 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total " 1405 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1406 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov);) 1406 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov));
1407 1407
1408 mcp->mb[0] = MBC_SEND_SNS_COMMAND; 1408 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1409 mcp->mb[1] = cmd_size; 1409 mcp->mb[1] = cmd_size;
@@ -1421,12 +1421,12 @@ qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1421 if (rval != QLA_SUCCESS) { 1421 if (rval != QLA_SUCCESS) {
1422 /*EMPTY*/ 1422 /*EMPTY*/
1423 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x " 1423 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1424 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);) 1424 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1425 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x " 1425 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1426 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);) 1426 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1427 } else { 1427 } else {
1428 /*EMPTY*/ 1428 /*EMPTY*/
1429 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no);) 1429 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no));
1430 } 1430 }
1431 1431
1432 return rval; 1432 return rval;
@@ -1442,7 +1442,7 @@ qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1442 dma_addr_t lg_dma; 1442 dma_addr_t lg_dma;
1443 uint32_t iop[2]; 1443 uint32_t iop[2];
1444 1444
1445 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);) 1445 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1446 1446
1447 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma); 1447 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1448 if (lg == NULL) { 1448 if (lg == NULL) {
@@ -1458,13 +1458,15 @@ qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1458 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI); 1458 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1459 if (opt & BIT_0) 1459 if (opt & BIT_0)
1460 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI); 1460 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1461 if (opt & BIT_1)
1462 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1461 lg->port_id[0] = al_pa; 1463 lg->port_id[0] = al_pa;
1462 lg->port_id[1] = area; 1464 lg->port_id[1] = area;
1463 lg->port_id[2] = domain; 1465 lg->port_id[2] = domain;
1464 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0); 1466 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1465 if (rval != QLA_SUCCESS) { 1467 if (rval != QLA_SUCCESS) {
1466 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB " 1468 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1467 "(%x).\n", __func__, ha->host_no, rval);) 1469 "(%x).\n", __func__, ha->host_no, rval));
1468 } else if (lg->entry_status != 0) { 1470 } else if (lg->entry_status != 0) {
1469 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " 1471 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1470 "-- error status (%x).\n", __func__, ha->host_no, 1472 "-- error status (%x).\n", __func__, ha->host_no,
@@ -1505,7 +1507,7 @@ qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1505 break; 1507 break;
1506 } 1508 }
1507 } else { 1509 } else {
1508 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);) 1510 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1509 1511
1510 iop[0] = le32_to_cpu(lg->io_parameter[0]); 1512 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1511 1513
@@ -1559,7 +1561,7 @@ qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1559 mbx_cmd_t mc; 1561 mbx_cmd_t mc;
1560 mbx_cmd_t *mcp = &mc; 1562 mbx_cmd_t *mcp = &mc;
1561 1563
1562 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no);) 1564 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no));
1563 1565
1564 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT; 1566 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1565 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; 1567 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
@@ -1604,11 +1606,11 @@ qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1604 /*EMPTY*/ 1606 /*EMPTY*/
1605 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x " 1607 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1606 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval, 1608 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
1607 mcp->mb[0], mcp->mb[1], mcp->mb[2]);) 1609 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1608 } else { 1610 } else {
1609 /*EMPTY*/ 1611 /*EMPTY*/
1610 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n", 1612 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1611 ha->host_no);) 1613 ha->host_no));
1612 } 1614 }
1613 1615
1614 return rval; 1616 return rval;
@@ -1643,7 +1645,7 @@ qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
1643 fcport->d_id.b.domain, fcport->d_id.b.area, 1645 fcport->d_id.b.domain, fcport->d_id.b.area,
1644 fcport->d_id.b.al_pa, mb_ret, opt); 1646 fcport->d_id.b.al_pa, mb_ret, opt);
1645 1647
1646 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no);) 1648 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1647 1649
1648 mcp->mb[0] = MBC_LOGIN_LOOP_PORT; 1650 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1649 if (HAS_EXTENDED_IDS(ha)) 1651 if (HAS_EXTENDED_IDS(ha))
@@ -1677,13 +1679,13 @@ qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
1677 1679
1678 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x " 1680 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1679 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval, 1681 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1680 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);) 1682 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1681 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x " 1683 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1682 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval, 1684 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1683 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);) 1685 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1684 } else { 1686 } else {
1685 /*EMPTY*/ 1687 /*EMPTY*/
1686 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no);) 1688 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no));
1687 } 1689 }
1688 1690
1689 return (rval); 1691 return (rval);
@@ -1697,7 +1699,7 @@ qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1697 struct logio_entry_24xx *lg; 1699 struct logio_entry_24xx *lg;
1698 dma_addr_t lg_dma; 1700 dma_addr_t lg_dma;
1699 1701
1700 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);) 1702 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1701 1703
1702 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma); 1704 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1703 if (lg == NULL) { 1705 if (lg == NULL) {
@@ -1718,7 +1720,7 @@ qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1718 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0); 1720 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1719 if (rval != QLA_SUCCESS) { 1721 if (rval != QLA_SUCCESS) {
1720 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB " 1722 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1721 "(%x).\n", __func__, ha->host_no, rval);) 1723 "(%x).\n", __func__, ha->host_no, rval));
1722 } else if (lg->entry_status != 0) { 1724 } else if (lg->entry_status != 0) {
1723 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " 1725 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1724 "-- error status (%x).\n", __func__, ha->host_no, 1726 "-- error status (%x).\n", __func__, ha->host_no,
@@ -1729,10 +1731,10 @@ qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1729 "-- completion status (%x) ioparam=%x/%x.\n", __func__, 1731 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1730 ha->host_no, le16_to_cpu(lg->comp_status), 1732 ha->host_no, le16_to_cpu(lg->comp_status),
1731 le32_to_cpu(lg->io_parameter[0]), 1733 le32_to_cpu(lg->io_parameter[0]),
1732 le32_to_cpu(lg->io_parameter[1]));) 1734 le32_to_cpu(lg->io_parameter[1])));
1733 } else { 1735 } else {
1734 /*EMPTY*/ 1736 /*EMPTY*/
1735 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);) 1737 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1736 } 1738 }
1737 1739
1738 dma_pool_free(ha->s_dma_pool, lg, lg_dma); 1740 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
@@ -1765,7 +1767,7 @@ qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1765 mbx_cmd_t *mcp = &mc; 1767 mbx_cmd_t *mcp = &mc;
1766 1768
1767 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n", 1769 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1768 ha->host_no);) 1770 ha->host_no));
1769 1771
1770 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT; 1772 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1771 mcp->out_mb = MBX_1|MBX_0; 1773 mcp->out_mb = MBX_1|MBX_0;
@@ -1785,11 +1787,11 @@ qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1785 if (rval != QLA_SUCCESS) { 1787 if (rval != QLA_SUCCESS) {
1786 /*EMPTY*/ 1788 /*EMPTY*/
1787 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x " 1789 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1788 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]);) 1790 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]));
1789 } else { 1791 } else {
1790 /*EMPTY*/ 1792 /*EMPTY*/
1791 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n", 1793 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1792 ha->host_no);) 1794 ha->host_no));
1793 } 1795 }
1794 1796
1795 return rval; 1797 return rval;
@@ -1818,7 +1820,7 @@ qla2x00_full_login_lip(scsi_qla_host_t *ha)
1818 mbx_cmd_t *mcp = &mc; 1820 mbx_cmd_t *mcp = &mc;
1819 1821
1820 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n", 1822 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1821 ha->host_no);) 1823 ha->host_no));
1822 1824
1823 mcp->mb[0] = MBC_LIP_FULL_LOGIN; 1825 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1824 mcp->mb[1] = 0; 1826 mcp->mb[1] = 0;
@@ -1833,11 +1835,11 @@ qla2x00_full_login_lip(scsi_qla_host_t *ha)
1833 if (rval != QLA_SUCCESS) { 1835 if (rval != QLA_SUCCESS) {
1834 /*EMPTY*/ 1836 /*EMPTY*/
1835 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n", 1837 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1836 ha->host_no, rval);) 1838 ha->host_no, rval));
1837 } else { 1839 } else {
1838 /*EMPTY*/ 1840 /*EMPTY*/
1839 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n", 1841 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1840 ha->host_no);) 1842 ha->host_no));
1841 } 1843 }
1842 1844
1843 return rval; 1845 return rval;
@@ -1864,7 +1866,7 @@ qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1864 mbx_cmd_t *mcp = &mc; 1866 mbx_cmd_t *mcp = &mc;
1865 1867
1866 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n", 1868 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1867 ha->host_no);) 1869 ha->host_no));
1868 1870
1869 if (id_list == NULL) 1871 if (id_list == NULL)
1870 return QLA_FUNCTION_FAILED; 1872 return QLA_FUNCTION_FAILED;
@@ -1893,11 +1895,11 @@ qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1893 if (rval != QLA_SUCCESS) { 1895 if (rval != QLA_SUCCESS) {
1894 /*EMPTY*/ 1896 /*EMPTY*/
1895 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n", 1897 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1896 ha->host_no, rval);) 1898 ha->host_no, rval));
1897 } else { 1899 } else {
1898 *entries = mcp->mb[1]; 1900 *entries = mcp->mb[1];
1899 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n", 1901 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1900 ha->host_no);) 1902 ha->host_no));
1901 } 1903 }
1902 1904
1903 return rval; 1905 return rval;
@@ -1936,7 +1938,7 @@ qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
1936 if (rval != QLA_SUCCESS) { 1938 if (rval != QLA_SUCCESS) {
1937 /*EMPTY*/ 1939 /*EMPTY*/
1938 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__, 1940 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
1939 ha->host_no, mcp->mb[0]);) 1941 ha->host_no, mcp->mb[0]));
1940 } else { 1942 } else {
1941 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x " 1943 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1942 "mb7=%x mb10=%x.\n", __func__, ha->host_no, 1944 "mb7=%x mb10=%x.\n", __func__, ha->host_no,
@@ -2045,7 +2047,7 @@ qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
2045 link_stat_t *stat_buf; 2047 link_stat_t *stat_buf;
2046 dma_addr_t stat_buf_dma; 2048 dma_addr_t stat_buf_dma;
2047 2049
2048 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);) 2050 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2049 2051
2050 stat_buf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &stat_buf_dma); 2052 stat_buf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &stat_buf_dma);
2051 if (stat_buf == NULL) { 2053 if (stat_buf == NULL) {
@@ -2083,7 +2085,7 @@ qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
2083 if (rval == QLA_SUCCESS) { 2085 if (rval == QLA_SUCCESS) {
2084 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) { 2086 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2085 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n", 2087 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2086 __func__, ha->host_no, mcp->mb[0]);) 2088 __func__, ha->host_no, mcp->mb[0]));
2087 status[0] = mcp->mb[0]; 2089 status[0] = mcp->mb[0];
2088 rval = BIT_1; 2090 rval = BIT_1;
2089 } else { 2091 } else {
@@ -2108,12 +2110,12 @@ qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
2108 stat_buf->loss_sync_cnt, stat_buf->loss_sig_cnt, 2110 stat_buf->loss_sync_cnt, stat_buf->loss_sig_cnt,
2109 stat_buf->prim_seq_err_cnt, 2111 stat_buf->prim_seq_err_cnt,
2110 stat_buf->inval_xmit_word_cnt, 2112 stat_buf->inval_xmit_word_cnt,
2111 stat_buf->inval_crc_cnt);) 2113 stat_buf->inval_crc_cnt));
2112 } 2114 }
2113 } else { 2115 } else {
2114 /* Failed. */ 2116 /* Failed. */
2115 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, 2117 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2116 ha->host_no, rval);) 2118 ha->host_no, rval));
2117 rval = BIT_1; 2119 rval = BIT_1;
2118 } 2120 }
2119 2121
@@ -2132,7 +2134,7 @@ qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
2132 uint32_t *sbuf, *siter; 2134 uint32_t *sbuf, *siter;
2133 dma_addr_t sbuf_dma; 2135 dma_addr_t sbuf_dma;
2134 2136
2135 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);) 2137 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2136 2138
2137 if (dwords > (DMA_POOL_SIZE / 4)) { 2139 if (dwords > (DMA_POOL_SIZE / 4)) {
2138 DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs " 2140 DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
@@ -2196,7 +2198,7 @@ qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2196 dma_addr_t abt_dma; 2198 dma_addr_t abt_dma;
2197 uint32_t handle; 2199 uint32_t handle;
2198 2200
2199 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);) 2201 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2200 2202
2201 fcport = sp->fcport; 2203 fcport = sp->fcport;
2202 2204
@@ -2229,7 +2231,7 @@ qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2229 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0); 2231 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2230 if (rval != QLA_SUCCESS) { 2232 if (rval != QLA_SUCCESS) {
2231 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n", 2233 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2232 __func__, ha->host_no, rval);) 2234 __func__, ha->host_no, rval));
2233 } else if (abt->entry_status != 0) { 2235 } else if (abt->entry_status != 0) {
2234 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " 2236 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2235 "-- error status (%x).\n", __func__, ha->host_no, 2237 "-- error status (%x).\n", __func__, ha->host_no,
@@ -2238,10 +2240,10 @@ qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2238 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) { 2240 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2239 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " 2241 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2240 "-- completion status (%x).\n", __func__, ha->host_no, 2242 "-- completion status (%x).\n", __func__, ha->host_no,
2241 le16_to_cpu(abt->nport_handle));) 2243 le16_to_cpu(abt->nport_handle)));
2242 rval = QLA_FUNCTION_FAILED; 2244 rval = QLA_FUNCTION_FAILED;
2243 } else { 2245 } else {
2244 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);) 2246 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2245 sp->flags |= SRB_ABORT_PENDING; 2247 sp->flags |= SRB_ABORT_PENDING;
2246 } 2248 }
2247 2249
@@ -2268,7 +2270,7 @@ qla24xx_abort_target(fc_port_t *fcport)
2268 if (fcport == NULL) 2270 if (fcport == NULL)
2269 return 0; 2271 return 0;
2270 2272
2271 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);) 2273 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
2272 2274
2273 ha = fcport->ha; 2275 ha = fcport->ha;
2274 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma); 2276 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
@@ -2290,7 +2292,7 @@ qla24xx_abort_target(fc_port_t *fcport)
2290 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0); 2292 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2291 if (rval != QLA_SUCCESS) { 2293 if (rval != QLA_SUCCESS) {
2292 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB " 2294 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
2293 "(%x).\n", __func__, ha->host_no, rval);) 2295 "(%x).\n", __func__, ha->host_no, rval));
2294 goto atarget_done; 2296 goto atarget_done;
2295 } else if (tsk->p.sts.entry_status != 0) { 2297 } else if (tsk->p.sts.entry_status != 0) {
2296 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " 2298 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
@@ -2302,7 +2304,7 @@ qla24xx_abort_target(fc_port_t *fcport)
2302 __constant_cpu_to_le16(CS_COMPLETE)) { 2304 __constant_cpu_to_le16(CS_COMPLETE)) {
2303 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " 2305 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2304 "-- completion status (%x).\n", __func__, 2306 "-- completion status (%x).\n", __func__,
2305 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status));) 2307 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
2306 rval = QLA_FUNCTION_FAILED; 2308 rval = QLA_FUNCTION_FAILED;
2307 goto atarget_done; 2309 goto atarget_done;
2308 } 2310 }
@@ -2311,9 +2313,9 @@ qla24xx_abort_target(fc_port_t *fcport)
2311 rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID); 2313 rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
2312 if (rval != QLA_SUCCESS) { 2314 if (rval != QLA_SUCCESS) {
2313 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB " 2315 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2314 "(%x).\n", __func__, ha->host_no, rval);) 2316 "(%x).\n", __func__, ha->host_no, rval));
2315 } else { 2317 } else {
2316 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);) 2318 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2317 } 2319 }
2318 2320
2319atarget_done: 2321atarget_done:
@@ -2460,3 +2462,81 @@ qla2x00_stop_firmware(scsi_qla_host_t *ha)
2460 2462
2461 return rval; 2463 return rval;
2462} 2464}
2465
2466int
2467qla2x00_trace_control(scsi_qla_host_t *ha, uint16_t ctrl, dma_addr_t eft_dma,
2468 uint16_t buffers)
2469{
2470 int rval;
2471 mbx_cmd_t mc;
2472 mbx_cmd_t *mcp = &mc;
2473
2474 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
2475 return QLA_FUNCTION_FAILED;
2476
2477 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2478
2479 mcp->mb[0] = MBC_TRACE_CONTROL;
2480 mcp->mb[1] = ctrl;
2481 mcp->out_mb = MBX_1|MBX_0;
2482 mcp->in_mb = MBX_1|MBX_0;
2483 if (ctrl == TC_ENABLE) {
2484 mcp->mb[2] = LSW(eft_dma);
2485 mcp->mb[3] = MSW(eft_dma);
2486 mcp->mb[4] = LSW(MSD(eft_dma));
2487 mcp->mb[5] = MSW(MSD(eft_dma));
2488 mcp->mb[6] = buffers;
2489 mcp->mb[7] = buffers;
2490 mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2;
2491 }
2492 mcp->tov = 30;
2493 mcp->flags = 0;
2494 rval = qla2x00_mailbox_command(ha, mcp);
2495
2496 if (rval != QLA_SUCCESS) {
2497 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2498 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2499 } else {
2500 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2501 }
2502
2503 return rval;
2504}
2505
2506int
2507qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr,
2508 uint16_t off, uint16_t count)
2509{
2510 int rval;
2511 mbx_cmd_t mc;
2512 mbx_cmd_t *mcp = &mc;
2513
2514 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
2515 return QLA_FUNCTION_FAILED;
2516
2517 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2518
2519 mcp->mb[0] = MBC_READ_SFP;
2520 mcp->mb[1] = addr;
2521 mcp->mb[2] = MSW(sfp_dma);
2522 mcp->mb[3] = LSW(sfp_dma);
2523 mcp->mb[6] = MSW(MSD(sfp_dma));
2524 mcp->mb[7] = LSW(MSD(sfp_dma));
2525 mcp->mb[8] = count;
2526 mcp->mb[9] = off;
2527 mcp->mb[10] = 0;
2528 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2529 mcp->in_mb = MBX_0;
2530 mcp->tov = 30;
2531 mcp->flags = 0;
2532 rval = qla2x00_mailbox_command(ha, mcp);
2533
2534 if (rval != QLA_SUCCESS) {
2535 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2536 ha->host_no, rval, mcp->mb[0]));
2537 } else {
2538 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2539 }
2540
2541 return rval;
2542}
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 93062593ebe7..65cbe2f5eea2 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -39,14 +39,14 @@ MODULE_PARM_DESC(ql2xlogintimeout,
39int qlport_down_retry = 30; 39int qlport_down_retry = 30;
40module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR); 40module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
41MODULE_PARM_DESC(qlport_down_retry, 41MODULE_PARM_DESC(qlport_down_retry,
42 "Maximum number of command retries to a port that returns" 42 "Maximum number of command retries to a port that returns "
43 "a PORT-DOWN status."); 43 "a PORT-DOWN status.");
44 44
45int ql2xplogiabsentdevice; 45int ql2xplogiabsentdevice;
46module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR); 46module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
47MODULE_PARM_DESC(ql2xplogiabsentdevice, 47MODULE_PARM_DESC(ql2xplogiabsentdevice,
48 "Option to enable PLOGI to devices that are not present after " 48 "Option to enable PLOGI to devices that are not present after "
49 "a Fabric scan. This is needed for several broken switches." 49 "a Fabric scan. This is needed for several broken switches. "
50 "Default is 0 - no PLOGI. 1 - perfom PLOGI."); 50 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
51 51
52int ql2xloginretrycount = 0; 52int ql2xloginretrycount = 0;
@@ -54,6 +54,19 @@ module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
54MODULE_PARM_DESC(ql2xloginretrycount, 54MODULE_PARM_DESC(ql2xloginretrycount,
55 "Specify an alternate value for the NVRAM login retry count."); 55 "Specify an alternate value for the NVRAM login retry count.");
56 56
57int ql2xallocfwdump = 1;
58module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
59MODULE_PARM_DESC(ql2xallocfwdump,
60 "Option to enable allocation of memory for a firmware dump "
61 "during HBA initialization. Memory allocation requirements "
62 "vary by ISP type. Default is 1 - allocate memory.");
63
64int extended_error_logging;
65module_param(extended_error_logging, int, S_IRUGO|S_IRUSR);
66MODULE_PARM_DESC(extended_error_logging,
67 "Option to enable extended error logging, "
68 "Default is 0 - no logging. 1 - log errors.");
69
57static void qla2x00_free_device(scsi_qla_host_t *); 70static void qla2x00_free_device(scsi_qla_host_t *);
58 71
59static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha); 72static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
@@ -624,7 +637,7 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
624 637
625 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n", 638 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n",
626 __func__, ha->host_no, sp, serial)); 639 __func__, ha->host_no, sp, serial));
627 DEBUG3(qla2x00_print_scsi_cmd(cmd);) 640 DEBUG3(qla2x00_print_scsi_cmd(cmd));
628 641
629 spin_unlock_irqrestore(&ha->hardware_lock, flags); 642 spin_unlock_irqrestore(&ha->hardware_lock, flags);
630 if (ha->isp_ops.abort_command(ha, sp)) { 643 if (ha->isp_ops.abort_command(ha, sp)) {
@@ -731,7 +744,6 @@ qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
731{ 744{
732 scsi_qla_host_t *ha = to_qla_host(cmd->device->host); 745 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
733 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; 746 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
734 srb_t *sp;
735 int ret; 747 int ret;
736 unsigned int id, lun; 748 unsigned int id, lun;
737 unsigned long serial; 749 unsigned long serial;
@@ -742,8 +754,7 @@ qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
742 lun = cmd->device->lun; 754 lun = cmd->device->lun;
743 serial = cmd->serial_number; 755 serial = cmd->serial_number;
744 756
745 sp = (srb_t *) CMD_SP(cmd); 757 if (!fcport)
746 if (!sp || !fcport)
747 return ret; 758 return ret;
748 759
749 qla_printk(KERN_INFO, ha, 760 qla_printk(KERN_INFO, ha,
@@ -766,7 +777,7 @@ qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
766#endif 777#endif
767 } else { 778 } else {
768 DEBUG2(printk(KERN_INFO 779 DEBUG2(printk(KERN_INFO
769 "%s failed: loop not ready\n",__func__);) 780 "%s failed: loop not ready\n",__func__));
770 } 781 }
771 782
772 if (ret == FAILED) { 783 if (ret == FAILED) {
@@ -862,7 +873,6 @@ qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
862{ 873{
863 scsi_qla_host_t *ha = to_qla_host(cmd->device->host); 874 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
864 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; 875 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
865 srb_t *sp;
866 int ret; 876 int ret;
867 unsigned int id, lun; 877 unsigned int id, lun;
868 unsigned long serial; 878 unsigned long serial;
@@ -873,8 +883,7 @@ qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
873 lun = cmd->device->lun; 883 lun = cmd->device->lun;
874 serial = cmd->serial_number; 884 serial = cmd->serial_number;
875 885
876 sp = (srb_t *) CMD_SP(cmd); 886 if (!fcport)
877 if (!sp || !fcport)
878 return ret; 887 return ret;
879 888
880 qla_printk(KERN_INFO, ha, 889 qla_printk(KERN_INFO, ha,
@@ -923,7 +932,6 @@ qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
923{ 932{
924 scsi_qla_host_t *ha = to_qla_host(cmd->device->host); 933 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
925 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; 934 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
926 srb_t *sp;
927 int ret; 935 int ret;
928 unsigned int id, lun; 936 unsigned int id, lun;
929 unsigned long serial; 937 unsigned long serial;
@@ -934,8 +942,7 @@ qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
934 lun = cmd->device->lun; 942 lun = cmd->device->lun;
935 serial = cmd->serial_number; 943 serial = cmd->serial_number;
936 944
937 sp = (srb_t *) CMD_SP(cmd); 945 if (!fcport)
938 if (!sp || !fcport)
939 return ret; 946 return ret;
940 947
941 qla_printk(KERN_INFO, ha, 948 qla_printk(KERN_INFO, ha,
@@ -1021,12 +1028,12 @@ qla2x00_loop_reset(scsi_qla_host_t *ha)
1021 /* Empty */ 1028 /* Empty */
1022 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n", 1029 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1023 __func__, 1030 __func__,
1024 ha->host_no);) 1031 ha->host_no));
1025 } else { 1032 } else {
1026 /* Empty */ 1033 /* Empty */
1027 DEBUG3(printk("%s(%ld): exiting normally.\n", 1034 DEBUG3(printk("%s(%ld): exiting normally.\n",
1028 __func__, 1035 __func__,
1029 ha->host_no);) 1036 ha->host_no));
1030 } 1037 }
1031 1038
1032 return(status); 1039 return(status);
@@ -1324,7 +1331,8 @@ qla24xx_disable_intrs(scsi_qla_host_t *ha)
1324/* 1331/*
1325 * PCI driver interface 1332 * PCI driver interface
1326 */ 1333 */
1327static int qla2x00_probe_one(struct pci_dev *pdev) 1334static int __devinit
1335qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1328{ 1336{
1329 int ret = -ENODEV; 1337 int ret = -ENODEV;
1330 device_reg_t __iomem *reg; 1338 device_reg_t __iomem *reg;
@@ -1405,7 +1413,6 @@ static int qla2x00_probe_one(struct pci_dev *pdev)
1405 ha->isp_ops.read_nvram = qla2x00_read_nvram_data; 1413 ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
1406 ha->isp_ops.write_nvram = qla2x00_write_nvram_data; 1414 ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
1407 ha->isp_ops.fw_dump = qla2100_fw_dump; 1415 ha->isp_ops.fw_dump = qla2100_fw_dump;
1408 ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
1409 ha->isp_ops.read_optrom = qla2x00_read_optrom_data; 1416 ha->isp_ops.read_optrom = qla2x00_read_optrom_data;
1410 ha->isp_ops.write_optrom = qla2x00_write_optrom_data; 1417 ha->isp_ops.write_optrom = qla2x00_write_optrom_data;
1411 if (IS_QLA2100(ha)) { 1418 if (IS_QLA2100(ha)) {
@@ -1432,7 +1439,6 @@ static int qla2x00_probe_one(struct pci_dev *pdev)
1432 ha->isp_ops.pci_config = qla2300_pci_config; 1439 ha->isp_ops.pci_config = qla2300_pci_config;
1433 ha->isp_ops.intr_handler = qla2300_intr_handler; 1440 ha->isp_ops.intr_handler = qla2300_intr_handler;
1434 ha->isp_ops.fw_dump = qla2300_fw_dump; 1441 ha->isp_ops.fw_dump = qla2300_fw_dump;
1435 ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
1436 ha->isp_ops.beacon_on = qla2x00_beacon_on; 1442 ha->isp_ops.beacon_on = qla2x00_beacon_on;
1437 ha->isp_ops.beacon_off = qla2x00_beacon_off; 1443 ha->isp_ops.beacon_off = qla2x00_beacon_off;
1438 ha->isp_ops.beacon_blink = qla2x00_beacon_blink; 1444 ha->isp_ops.beacon_blink = qla2x00_beacon_blink;
@@ -1469,7 +1475,6 @@ static int qla2x00_probe_one(struct pci_dev *pdev)
1469 ha->isp_ops.read_nvram = qla24xx_read_nvram_data; 1475 ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
1470 ha->isp_ops.write_nvram = qla24xx_write_nvram_data; 1476 ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
1471 ha->isp_ops.fw_dump = qla24xx_fw_dump; 1477 ha->isp_ops.fw_dump = qla24xx_fw_dump;
1472 ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
1473 ha->isp_ops.read_optrom = qla24xx_read_optrom_data; 1478 ha->isp_ops.read_optrom = qla24xx_read_optrom_data;
1474 ha->isp_ops.write_optrom = qla24xx_write_optrom_data; 1479 ha->isp_ops.write_optrom = qla24xx_write_optrom_data;
1475 ha->isp_ops.beacon_on = qla24xx_beacon_on; 1480 ha->isp_ops.beacon_on = qla24xx_beacon_on;
@@ -1640,7 +1645,8 @@ probe_out:
1640 return ret; 1645 return ret;
1641} 1646}
1642 1647
1643static void qla2x00_remove_one(struct pci_dev *pdev) 1648static void __devexit
1649qla2x00_remove_one(struct pci_dev *pdev)
1644{ 1650{
1645 scsi_qla_host_t *ha; 1651 scsi_qla_host_t *ha;
1646 1652
@@ -1678,6 +1684,9 @@ qla2x00_free_device(scsi_qla_host_t *ha)
1678 kthread_stop(t); 1684 kthread_stop(t);
1679 } 1685 }
1680 1686
1687 if (ha->eft)
1688 qla2x00_trace_control(ha, TC_DISABLE, 0, 0);
1689
1681 /* Stop currently executing firmware. */ 1690 /* Stop currently executing firmware. */
1682 qla2x00_stop_firmware(ha); 1691 qla2x00_stop_firmware(ha);
1683 1692
@@ -1899,17 +1908,6 @@ qla2x00_mem_alloc(scsi_qla_host_t *ha)
1899 } 1908 }
1900 memset(ha->init_cb, 0, ha->init_cb_size); 1909 memset(ha->init_cb, 0, ha->init_cb_size);
1901 1910
1902 /* Allocate ioctl related memory. */
1903 if (qla2x00_alloc_ioctl_mem(ha)) {
1904 qla_printk(KERN_WARNING, ha,
1905 "Memory Allocation failed - ioctl_mem\n");
1906
1907 qla2x00_mem_free(ha);
1908 msleep(100);
1909
1910 continue;
1911 }
1912
1913 if (qla2x00_allocate_sp_pool(ha)) { 1911 if (qla2x00_allocate_sp_pool(ha)) {
1914 qla_printk(KERN_WARNING, ha, 1912 qla_printk(KERN_WARNING, ha,
1915 "Memory Allocation failed - " 1913 "Memory Allocation failed - "
@@ -1972,6 +1970,26 @@ qla2x00_mem_alloc(scsi_qla_host_t *ha)
1972 continue; 1970 continue;
1973 } 1971 }
1974 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt)); 1972 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
1973
1974 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1975 /*
1976 * Get consistent memory allocated for SFP
1977 * block.
1978 */
1979 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool,
1980 GFP_KERNEL, &ha->sfp_data_dma);
1981 if (ha->sfp_data == NULL) {
1982 qla_printk(KERN_WARNING, ha,
1983 "Memory Allocation failed - "
1984 "sfp_data\n");
1985
1986 qla2x00_mem_free(ha);
1987 msleep(100);
1988
1989 continue;
1990 }
1991 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
1992 }
1975 } 1993 }
1976 1994
1977 /* Done all allocations without any error. */ 1995 /* Done all allocations without any error. */
@@ -2006,12 +2024,16 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
2006 return; 2024 return;
2007 } 2025 }
2008 2026
2009 /* free ioctl memory */
2010 qla2x00_free_ioctl_mem(ha);
2011
2012 /* free sp pool */ 2027 /* free sp pool */
2013 qla2x00_free_sp_pool(ha); 2028 qla2x00_free_sp_pool(ha);
2014 2029
2030 if (ha->fw_dump) {
2031 if (ha->eft)
2032 dma_free_coherent(&ha->pdev->dev,
2033 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2034 vfree(ha->fw_dump);
2035 }
2036
2015 if (ha->sns_cmd) 2037 if (ha->sns_cmd)
2016 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt), 2038 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2017 ha->sns_cmd, ha->sns_cmd_dma); 2039 ha->sns_cmd, ha->sns_cmd_dma);
@@ -2020,6 +2042,9 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
2020 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), 2042 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2021 ha->ct_sns, ha->ct_sns_dma); 2043 ha->ct_sns, ha->ct_sns_dma);
2022 2044
2045 if (ha->sfp_data)
2046 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2047
2023 if (ha->ms_iocb) 2048 if (ha->ms_iocb)
2024 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); 2049 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2025 2050
@@ -2043,6 +2068,8 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
2043 (ha->request_q_length + 1) * sizeof(request_t), 2068 (ha->request_q_length + 1) * sizeof(request_t),
2044 ha->request_ring, ha->request_dma); 2069 ha->request_ring, ha->request_dma);
2045 2070
2071 ha->eft = NULL;
2072 ha->eft_dma = 0;
2046 ha->sns_cmd = NULL; 2073 ha->sns_cmd = NULL;
2047 ha->sns_cmd_dma = 0; 2074 ha->sns_cmd_dma = 0;
2048 ha->ct_sns = NULL; 2075 ha->ct_sns = NULL;
@@ -2071,13 +2098,9 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
2071 } 2098 }
2072 INIT_LIST_HEAD(&ha->fcports); 2099 INIT_LIST_HEAD(&ha->fcports);
2073 2100
2074 vfree(ha->fw_dump);
2075 vfree(ha->fw_dump_buffer);
2076
2077 ha->fw_dump = NULL; 2101 ha->fw_dump = NULL;
2078 ha->fw_dumped = 0; 2102 ha->fw_dumped = 0;
2079 ha->fw_dump_reading = 0; 2103 ha->fw_dump_reading = 0;
2080 ha->fw_dump_buffer = NULL;
2081 2104
2082 vfree(ha->optrom_buffer); 2105 vfree(ha->optrom_buffer);
2083} 2106}
@@ -2215,9 +2238,6 @@ qla2x00_do_dpc(void *data)
2215 2238
2216 next_loopid = 0; 2239 next_loopid = 0;
2217 list_for_each_entry(fcport, &ha->fcports, list) { 2240 list_for_each_entry(fcport, &ha->fcports, list) {
2218 if (fcport->port_type != FCT_TARGET)
2219 continue;
2220
2221 /* 2241 /*
2222 * If the port is not ONLINE then try to login 2242 * If the port is not ONLINE then try to login
2223 * to it if we haven't run out of retries. 2243 * to it if we haven't run out of retries.
@@ -2617,40 +2637,16 @@ static struct pci_device_id qla2xxx_pci_tbl[] = {
2617}; 2637};
2618MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl); 2638MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2619 2639
2620static int __devinit
2621qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2622{
2623 return qla2x00_probe_one(pdev);
2624}
2625
2626static void __devexit
2627qla2xxx_remove_one(struct pci_dev *pdev)
2628{
2629 qla2x00_remove_one(pdev);
2630}
2631
2632static struct pci_driver qla2xxx_pci_driver = { 2640static struct pci_driver qla2xxx_pci_driver = {
2633 .name = QLA2XXX_DRIVER_NAME, 2641 .name = QLA2XXX_DRIVER_NAME,
2634 .driver = { 2642 .driver = {
2635 .owner = THIS_MODULE, 2643 .owner = THIS_MODULE,
2636 }, 2644 },
2637 .id_table = qla2xxx_pci_tbl, 2645 .id_table = qla2xxx_pci_tbl,
2638 .probe = qla2xxx_probe_one, 2646 .probe = qla2x00_probe_one,
2639 .remove = __devexit_p(qla2xxx_remove_one), 2647 .remove = __devexit_p(qla2x00_remove_one),
2640}; 2648};
2641 2649
2642static inline int
2643qla2x00_pci_module_init(void)
2644{
2645 return pci_module_init(&qla2xxx_pci_driver);
2646}
2647
2648static inline void
2649qla2x00_pci_module_exit(void)
2650{
2651 pci_unregister_driver(&qla2xxx_pci_driver);
2652}
2653
2654/** 2650/**
2655 * qla2x00_module_init - Module initialization. 2651 * qla2x00_module_init - Module initialization.
2656 **/ 2652 **/
@@ -2670,16 +2666,16 @@ qla2x00_module_init(void)
2670 2666
2671 /* Derive version string. */ 2667 /* Derive version string. */
2672 strcpy(qla2x00_version_str, QLA2XXX_VERSION); 2668 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2673#if DEBUG_QLA2100 2669 if (extended_error_logging)
2674 strcat(qla2x00_version_str, "-debug"); 2670 strcat(qla2x00_version_str, "-debug");
2675#endif 2671
2676 qla2xxx_transport_template = 2672 qla2xxx_transport_template =
2677 fc_attach_transport(&qla2xxx_transport_functions); 2673 fc_attach_transport(&qla2xxx_transport_functions);
2678 if (!qla2xxx_transport_template) 2674 if (!qla2xxx_transport_template)
2679 return -ENODEV; 2675 return -ENODEV;
2680 2676
2681 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n"); 2677 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
2682 ret = qla2x00_pci_module_init(); 2678 ret = pci_register_driver(&qla2xxx_pci_driver);
2683 if (ret) { 2679 if (ret) {
2684 kmem_cache_destroy(srb_cachep); 2680 kmem_cache_destroy(srb_cachep);
2685 fc_release_transport(qla2xxx_transport_template); 2681 fc_release_transport(qla2xxx_transport_template);
@@ -2693,7 +2689,7 @@ qla2x00_module_init(void)
2693static void __exit 2689static void __exit
2694qla2x00_module_exit(void) 2690qla2x00_module_exit(void)
2695{ 2691{
2696 qla2x00_pci_module_exit(); 2692 pci_unregister_driver(&qla2xxx_pci_driver);
2697 qla2x00_release_firmware(); 2693 qla2x00_release_firmware();
2698 kmem_cache_destroy(srb_cachep); 2694 kmem_cache_destroy(srb_cachep);
2699 fc_release_transport(qla2xxx_transport_template); 2695 fc_release_transport(qla2xxx_transport_template);
diff --git a/drivers/scsi/qla2xxx/qla_version.h b/drivers/scsi/qla2xxx/qla_version.h
index 6b315521bd89..971259032ef7 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,9 +7,9 @@
7/* 7/*
8 * Driver version 8 * Driver version
9 */ 9 */
10#define QLA2XXX_VERSION "8.01.05-k2" 10#define QLA2XXX_VERSION "8.01.07-k1"
11 11
12#define QLA_DRIVER_MAJOR_VER 8 12#define QLA_DRIVER_MAJOR_VER 8
13#define QLA_DRIVER_MINOR_VER 1 13#define QLA_DRIVER_MINOR_VER 1
14#define QLA_DRIVER_PATCH_VER 5 14#define QLA_DRIVER_PATCH_VER 7
15#define QLA_DRIVER_BETA_VER 0 15#define QLA_DRIVER_BETA_VER 0
diff --git a/drivers/scsi/qlogicpti.c b/drivers/scsi/qlogicpti.c
index 69e0551a81d2..5b2f0741a55b 100644
--- a/drivers/scsi/qlogicpti.c
+++ b/drivers/scsi/qlogicpti.c
@@ -874,7 +874,7 @@ static inline int load_cmd(struct scsi_cmnd *Cmnd, struct Command_Entry *cmd,
874 if (Cmnd->use_sg) { 874 if (Cmnd->use_sg) {
875 int sg_count; 875 int sg_count;
876 876
877 sg = (struct scatterlist *) Cmnd->buffer; 877 sg = (struct scatterlist *) Cmnd->request_buffer;
878 sg_count = sbus_map_sg(qpti->sdev, sg, Cmnd->use_sg, Cmnd->sc_data_direction); 878 sg_count = sbus_map_sg(qpti->sdev, sg, Cmnd->use_sg, Cmnd->sc_data_direction);
879 879
880 ds = cmd->dataseg; 880 ds = cmd->dataseg;
@@ -1278,7 +1278,7 @@ static struct scsi_cmnd *qlogicpti_intr_handler(struct qlogicpti *qpti)
1278 1278
1279 if (Cmnd->use_sg) { 1279 if (Cmnd->use_sg) {
1280 sbus_unmap_sg(qpti->sdev, 1280 sbus_unmap_sg(qpti->sdev,
1281 (struct scatterlist *)Cmnd->buffer, 1281 (struct scatterlist *)Cmnd->request_buffer,
1282 Cmnd->use_sg, 1282 Cmnd->use_sg,
1283 Cmnd->sc_data_direction); 1283 Cmnd->sc_data_direction);
1284 } else { 1284 } else {
diff --git a/drivers/scsi/sata_mv.c b/drivers/scsi/sata_mv.c
index 1053c7c76b7d..fa38a413d16b 100644
--- a/drivers/scsi/sata_mv.c
+++ b/drivers/scsi/sata_mv.c
@@ -1961,8 +1961,7 @@ comreset_retry:
1961 timeout = jiffies + msecs_to_jiffies(200); 1961 timeout = jiffies + msecs_to_jiffies(200);
1962 do { 1962 do {
1963 sata_scr_read(ap, SCR_STATUS, &sstatus); 1963 sata_scr_read(ap, SCR_STATUS, &sstatus);
1964 sstatus &= 0x3; 1964 if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0))
1965 if ((sstatus == 3) || (sstatus == 0))
1966 break; 1965 break;
1967 1966
1968 __msleep(1, can_sleep); 1967 __msleep(1, can_sleep);
diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c
index 64631bd38952..4776f4e55839 100644
--- a/drivers/scsi/sata_promise.c
+++ b/drivers/scsi/sata_promise.c
@@ -269,8 +269,15 @@ static const struct pci_device_id pdc_ata_pci_tbl[] = {
269 { PCI_VENDOR_ID_PROMISE, 0x6629, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 269 { PCI_VENDOR_ID_PROMISE, 0x6629, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
270 board_20619 }, 270 board_20619 },
271 271
272/* TODO: remove all associated board_20771 code, as it completely
273 * duplicates board_2037x code, unless reason for separation can be
274 * divined.
275 */
276#if 0
272 { PCI_VENDOR_ID_PROMISE, 0x3570, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 277 { PCI_VENDOR_ID_PROMISE, 0x3570, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
273 board_20771 }, 278 board_20771 },
279#endif
280
274 { } /* terminate list */ 281 { } /* terminate list */
275}; 282};
276 283
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index 7aabb45c35e5..d0a85073ebf7 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -109,6 +109,7 @@ enum {
109}; 109};
110 110
111static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 111static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
112static int sil_pci_device_resume(struct pci_dev *pdev);
112static void sil_dev_config(struct ata_port *ap, struct ata_device *dev); 113static void sil_dev_config(struct ata_port *ap, struct ata_device *dev);
113static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg); 114static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg);
114static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 115static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
@@ -160,6 +161,8 @@ static struct pci_driver sil_pci_driver = {
160 .id_table = sil_pci_tbl, 161 .id_table = sil_pci_tbl,
161 .probe = sil_init_one, 162 .probe = sil_init_one,
162 .remove = ata_pci_remove_one, 163 .remove = ata_pci_remove_one,
164 .suspend = ata_pci_device_suspend,
165 .resume = sil_pci_device_resume,
163}; 166};
164 167
165static struct scsi_host_template sil_sht = { 168static struct scsi_host_template sil_sht = {
@@ -178,6 +181,8 @@ static struct scsi_host_template sil_sht = {
178 .slave_configure = ata_scsi_slave_config, 181 .slave_configure = ata_scsi_slave_config,
179 .slave_destroy = ata_scsi_slave_destroy, 182 .slave_destroy = ata_scsi_slave_destroy,
180 .bios_param = ata_std_bios_param, 183 .bios_param = ata_std_bios_param,
184 .suspend = ata_scsi_device_suspend,
185 .resume = ata_scsi_device_resume,
181}; 186};
182 187
183static const struct ata_port_operations sil_ops = { 188static const struct ata_port_operations sil_ops = {
@@ -370,7 +375,7 @@ static void sil_host_intr(struct ata_port *ap, u32 bmdma2)
370 * during hardreset makes controllers with broken SIEN 375 * during hardreset makes controllers with broken SIEN
371 * repeat probing needlessly. 376 * repeat probing needlessly.
372 */ 377 */
373 if (!(ap->flags & ATA_FLAG_FROZEN)) { 378 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
374 ata_ehi_hotplugged(&ap->eh_info); 379 ata_ehi_hotplugged(&ap->eh_info);
375 ap->eh_info.serror |= serror; 380 ap->eh_info.serror |= serror;
376 } 381 }
@@ -561,6 +566,52 @@ static void sil_dev_config(struct ata_port *ap, struct ata_device *dev)
561 } 566 }
562} 567}
563 568
569static void sil_init_controller(struct pci_dev *pdev,
570 int n_ports, unsigned long host_flags,
571 void __iomem *mmio_base)
572{
573 u8 cls;
574 u32 tmp;
575 int i;
576
577 /* Initialize FIFO PCI bus arbitration */
578 cls = sil_get_device_cache_line(pdev);
579 if (cls) {
580 cls >>= 3;
581 cls++; /* cls = (line_size/8)+1 */
582 for (i = 0; i < n_ports; i++)
583 writew(cls << 8 | cls,
584 mmio_base + sil_port[i].fifo_cfg);
585 } else
586 dev_printk(KERN_WARNING, &pdev->dev,
587 "cache line size not set. Driver may not function\n");
588
589 /* Apply R_ERR on DMA activate FIS errata workaround */
590 if (host_flags & SIL_FLAG_RERR_ON_DMA_ACT) {
591 int cnt;
592
593 for (i = 0, cnt = 0; i < n_ports; i++) {
594 tmp = readl(mmio_base + sil_port[i].sfis_cfg);
595 if ((tmp & 0x3) != 0x01)
596 continue;
597 if (!cnt)
598 dev_printk(KERN_INFO, &pdev->dev,
599 "Applying R_ERR on DMA activate "
600 "FIS errata fix\n");
601 writel(tmp & ~0x3, mmio_base + sil_port[i].sfis_cfg);
602 cnt++;
603 }
604 }
605
606 if (n_ports == 4) {
607 /* flip the magic "make 4 ports work" bit */
608 tmp = readl(mmio_base + sil_port[2].bmdma);
609 if ((tmp & SIL_INTR_STEERING) == 0)
610 writel(tmp | SIL_INTR_STEERING,
611 mmio_base + sil_port[2].bmdma);
612 }
613}
614
564static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 615static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
565{ 616{
566 static int printed_version; 617 static int printed_version;
@@ -570,8 +621,6 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
570 int rc; 621 int rc;
571 unsigned int i; 622 unsigned int i;
572 int pci_dev_busy = 0; 623 int pci_dev_busy = 0;
573 u32 tmp;
574 u8 cls;
575 624
576 if (!printed_version++) 625 if (!printed_version++)
577 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 626 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
@@ -630,42 +679,8 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
630 ata_std_ports(&probe_ent->port[i]); 679 ata_std_ports(&probe_ent->port[i]);
631 } 680 }
632 681
633 /* Initialize FIFO PCI bus arbitration */ 682 sil_init_controller(pdev, probe_ent->n_ports, probe_ent->host_flags,
634 cls = sil_get_device_cache_line(pdev); 683 mmio_base);
635 if (cls) {
636 cls >>= 3;
637 cls++; /* cls = (line_size/8)+1 */
638 for (i = 0; i < probe_ent->n_ports; i++)
639 writew(cls << 8 | cls,
640 mmio_base + sil_port[i].fifo_cfg);
641 } else
642 dev_printk(KERN_WARNING, &pdev->dev,
643 "cache line size not set. Driver may not function\n");
644
645 /* Apply R_ERR on DMA activate FIS errata workaround */
646 if (probe_ent->host_flags & SIL_FLAG_RERR_ON_DMA_ACT) {
647 int cnt;
648
649 for (i = 0, cnt = 0; i < probe_ent->n_ports; i++) {
650 tmp = readl(mmio_base + sil_port[i].sfis_cfg);
651 if ((tmp & 0x3) != 0x01)
652 continue;
653 if (!cnt)
654 dev_printk(KERN_INFO, &pdev->dev,
655 "Applying R_ERR on DMA activate "
656 "FIS errata fix\n");
657 writel(tmp & ~0x3, mmio_base + sil_port[i].sfis_cfg);
658 cnt++;
659 }
660 }
661
662 if (ent->driver_data == sil_3114) {
663 /* flip the magic "make 4 ports work" bit */
664 tmp = readl(mmio_base + sil_port[2].bmdma);
665 if ((tmp & SIL_INTR_STEERING) == 0)
666 writel(tmp | SIL_INTR_STEERING,
667 mmio_base + sil_port[2].bmdma);
668 }
669 684
670 pci_set_master(pdev); 685 pci_set_master(pdev);
671 686
@@ -685,6 +700,18 @@ err_out:
685 return rc; 700 return rc;
686} 701}
687 702
703static int sil_pci_device_resume(struct pci_dev *pdev)
704{
705 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
706
707 ata_pci_device_do_resume(pdev);
708 sil_init_controller(pdev, host_set->n_ports, host_set->ports[0]->flags,
709 host_set->mmio_base);
710 ata_host_set_resume(host_set);
711
712 return 0;
713}
714
688static int __init sil_init(void) 715static int __init sil_init(void)
689{ 716{
690 return pci_module_init(&sil_pci_driver); 717 return pci_module_init(&sil_pci_driver);
diff --git a/drivers/scsi/sata_sil24.c b/drivers/scsi/sata_sil24.c
index 07a1c6a8a414..3f368c7d3ef9 100644
--- a/drivers/scsi/sata_sil24.c
+++ b/drivers/scsi/sata_sil24.c
@@ -92,6 +92,7 @@ enum {
92 HOST_CTRL_STOP = (1 << 18), /* latched PCI STOP */ 92 HOST_CTRL_STOP = (1 << 18), /* latched PCI STOP */
93 HOST_CTRL_DEVSEL = (1 << 19), /* latched PCI DEVSEL */ 93 HOST_CTRL_DEVSEL = (1 << 19), /* latched PCI DEVSEL */
94 HOST_CTRL_REQ64 = (1 << 20), /* latched PCI REQ64 */ 94 HOST_CTRL_REQ64 = (1 << 20), /* latched PCI REQ64 */
95 HOST_CTRL_GLOBAL_RST = (1 << 31), /* global reset */
95 96
96 /* 97 /*
97 * Port registers 98 * Port registers
@@ -338,6 +339,7 @@ static int sil24_port_start(struct ata_port *ap);
338static void sil24_port_stop(struct ata_port *ap); 339static void sil24_port_stop(struct ata_port *ap);
339static void sil24_host_stop(struct ata_host_set *host_set); 340static void sil24_host_stop(struct ata_host_set *host_set);
340static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 341static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
342static int sil24_pci_device_resume(struct pci_dev *pdev);
341 343
342static const struct pci_device_id sil24_pci_tbl[] = { 344static const struct pci_device_id sil24_pci_tbl[] = {
343 { 0x1095, 0x3124, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3124 }, 345 { 0x1095, 0x3124, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3124 },
@@ -353,6 +355,8 @@ static struct pci_driver sil24_pci_driver = {
353 .id_table = sil24_pci_tbl, 355 .id_table = sil24_pci_tbl,
354 .probe = sil24_init_one, 356 .probe = sil24_init_one,
355 .remove = ata_pci_remove_one, /* safe? */ 357 .remove = ata_pci_remove_one, /* safe? */
358 .suspend = ata_pci_device_suspend,
359 .resume = sil24_pci_device_resume,
356}; 360};
357 361
358static struct scsi_host_template sil24_sht = { 362static struct scsi_host_template sil24_sht = {
@@ -372,6 +376,8 @@ static struct scsi_host_template sil24_sht = {
372 .slave_configure = ata_scsi_slave_config, 376 .slave_configure = ata_scsi_slave_config,
373 .slave_destroy = ata_scsi_slave_destroy, 377 .slave_destroy = ata_scsi_slave_destroy,
374 .bios_param = ata_std_bios_param, 378 .bios_param = ata_std_bios_param,
379 .suspend = ata_scsi_device_suspend,
380 .resume = ata_scsi_device_resume,
375}; 381};
376 382
377static const struct ata_port_operations sil24_ops = { 383static const struct ata_port_operations sil24_ops = {
@@ -607,7 +613,7 @@ static int sil24_hardreset(struct ata_port *ap, unsigned int *class)
607 /* SStatus oscillates between zero and valid status after 613 /* SStatus oscillates between zero and valid status after
608 * DEV_RST, debounce it. 614 * DEV_RST, debounce it.
609 */ 615 */
610 rc = sata_phy_debounce(ap, sata_deb_timing_before_fsrst); 616 rc = sata_phy_debounce(ap, sata_deb_timing_long);
611 if (rc) { 617 if (rc) {
612 reason = "PHY debouncing failed"; 618 reason = "PHY debouncing failed";
613 goto err; 619 goto err;
@@ -988,6 +994,64 @@ static void sil24_host_stop(struct ata_host_set *host_set)
988 kfree(hpriv); 994 kfree(hpriv);
989} 995}
990 996
997static void sil24_init_controller(struct pci_dev *pdev, int n_ports,
998 unsigned long host_flags,
999 void __iomem *host_base,
1000 void __iomem *port_base)
1001{
1002 u32 tmp;
1003 int i;
1004
1005 /* GPIO off */
1006 writel(0, host_base + HOST_FLASH_CMD);
1007
1008 /* clear global reset & mask interrupts during initialization */
1009 writel(0, host_base + HOST_CTRL);
1010
1011 /* init ports */
1012 for (i = 0; i < n_ports; i++) {
1013 void __iomem *port = port_base + i * PORT_REGS_SIZE;
1014
1015 /* Initial PHY setting */
1016 writel(0x20c, port + PORT_PHY_CFG);
1017
1018 /* Clear port RST */
1019 tmp = readl(port + PORT_CTRL_STAT);
1020 if (tmp & PORT_CS_PORT_RST) {
1021 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR);
1022 tmp = ata_wait_register(port + PORT_CTRL_STAT,
1023 PORT_CS_PORT_RST,
1024 PORT_CS_PORT_RST, 10, 100);
1025 if (tmp & PORT_CS_PORT_RST)
1026 dev_printk(KERN_ERR, &pdev->dev,
1027 "failed to clear port RST\n");
1028 }
1029
1030 /* Configure IRQ WoC */
1031 if (host_flags & SIL24_FLAG_PCIX_IRQ_WOC)
1032 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_STAT);
1033 else
1034 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
1035
1036 /* Zero error counters. */
1037 writel(0x8000, port + PORT_DECODE_ERR_THRESH);
1038 writel(0x8000, port + PORT_CRC_ERR_THRESH);
1039 writel(0x8000, port + PORT_HSHK_ERR_THRESH);
1040 writel(0x0000, port + PORT_DECODE_ERR_CNT);
1041 writel(0x0000, port + PORT_CRC_ERR_CNT);
1042 writel(0x0000, port + PORT_HSHK_ERR_CNT);
1043
1044 /* Always use 64bit activation */
1045 writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_CLR);
1046
1047 /* Clear port multiplier enable and resume bits */
1048 writel(PORT_CS_PM_EN | PORT_CS_RESUME, port + PORT_CTRL_CLR);
1049 }
1050
1051 /* Turn on interrupts */
1052 writel(IRQ_STAT_4PORTS, host_base + HOST_CTRL);
1053}
1054
991static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 1055static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
992{ 1056{
993 static int printed_version = 0; 1057 static int printed_version = 0;
@@ -1042,7 +1106,6 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1042 1106
1043 probe_ent->irq = pdev->irq; 1107 probe_ent->irq = pdev->irq;
1044 probe_ent->irq_flags = IRQF_SHARED; 1108 probe_ent->irq_flags = IRQF_SHARED;
1045 probe_ent->mmio_base = port_base;
1046 probe_ent->private_data = hpriv; 1109 probe_ent->private_data = hpriv;
1047 1110
1048 hpriv->host_base = host_base; 1111 hpriv->host_base = host_base;
@@ -1076,9 +1139,6 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1076 } 1139 }
1077 } 1140 }
1078 1141
1079 /* GPIO off */
1080 writel(0, host_base + HOST_FLASH_CMD);
1081
1082 /* Apply workaround for completion IRQ loss on PCI-X errata */ 1142 /* Apply workaround for completion IRQ loss on PCI-X errata */
1083 if (probe_ent->host_flags & SIL24_FLAG_PCIX_IRQ_WOC) { 1143 if (probe_ent->host_flags & SIL24_FLAG_PCIX_IRQ_WOC) {
1084 tmp = readl(host_base + HOST_CTRL); 1144 tmp = readl(host_base + HOST_CTRL);
@@ -1090,56 +1150,18 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1090 probe_ent->host_flags &= ~SIL24_FLAG_PCIX_IRQ_WOC; 1150 probe_ent->host_flags &= ~SIL24_FLAG_PCIX_IRQ_WOC;
1091 } 1151 }
1092 1152
1093 /* clear global reset & mask interrupts during initialization */
1094 writel(0, host_base + HOST_CTRL);
1095
1096 for (i = 0; i < probe_ent->n_ports; i++) { 1153 for (i = 0; i < probe_ent->n_ports; i++) {
1097 void __iomem *port = port_base + i * PORT_REGS_SIZE; 1154 unsigned long portu =
1098 unsigned long portu = (unsigned long)port; 1155 (unsigned long)port_base + i * PORT_REGS_SIZE;
1099 1156
1100 probe_ent->port[i].cmd_addr = portu; 1157 probe_ent->port[i].cmd_addr = portu;
1101 probe_ent->port[i].scr_addr = portu + PORT_SCONTROL; 1158 probe_ent->port[i].scr_addr = portu + PORT_SCONTROL;
1102 1159
1103 ata_std_ports(&probe_ent->port[i]); 1160 ata_std_ports(&probe_ent->port[i]);
1104
1105 /* Initial PHY setting */
1106 writel(0x20c, port + PORT_PHY_CFG);
1107
1108 /* Clear port RST */
1109 tmp = readl(port + PORT_CTRL_STAT);
1110 if (tmp & PORT_CS_PORT_RST) {
1111 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR);
1112 tmp = ata_wait_register(port + PORT_CTRL_STAT,
1113 PORT_CS_PORT_RST,
1114 PORT_CS_PORT_RST, 10, 100);
1115 if (tmp & PORT_CS_PORT_RST)
1116 dev_printk(KERN_ERR, &pdev->dev,
1117 "failed to clear port RST\n");
1118 }
1119
1120 /* Configure IRQ WoC */
1121 if (probe_ent->host_flags & SIL24_FLAG_PCIX_IRQ_WOC)
1122 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_STAT);
1123 else
1124 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
1125
1126 /* Zero error counters. */
1127 writel(0x8000, port + PORT_DECODE_ERR_THRESH);
1128 writel(0x8000, port + PORT_CRC_ERR_THRESH);
1129 writel(0x8000, port + PORT_HSHK_ERR_THRESH);
1130 writel(0x0000, port + PORT_DECODE_ERR_CNT);
1131 writel(0x0000, port + PORT_CRC_ERR_CNT);
1132 writel(0x0000, port + PORT_HSHK_ERR_CNT);
1133
1134 /* Always use 64bit activation */
1135 writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_CLR);
1136
1137 /* Clear port multiplier enable and resume bits */
1138 writel(PORT_CS_PM_EN | PORT_CS_RESUME, port + PORT_CTRL_CLR);
1139 } 1161 }
1140 1162
1141 /* Turn on interrupts */ 1163 sil24_init_controller(pdev, probe_ent->n_ports, probe_ent->host_flags,
1142 writel(IRQ_STAT_4PORTS, host_base + HOST_CTRL); 1164 host_base, port_base);
1143 1165
1144 pci_set_master(pdev); 1166 pci_set_master(pdev);
1145 1167
@@ -1162,6 +1184,25 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1162 return rc; 1184 return rc;
1163} 1185}
1164 1186
1187static int sil24_pci_device_resume(struct pci_dev *pdev)
1188{
1189 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
1190 struct sil24_host_priv *hpriv = host_set->private_data;
1191
1192 ata_pci_device_do_resume(pdev);
1193
1194 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND)
1195 writel(HOST_CTRL_GLOBAL_RST, hpriv->host_base + HOST_CTRL);
1196
1197 sil24_init_controller(pdev, host_set->n_ports,
1198 host_set->ports[0]->flags,
1199 hpriv->host_base, hpriv->port_base);
1200
1201 ata_host_set_resume(host_set);
1202
1203 return 0;
1204}
1205
1165static int __init sil24_init(void) 1206static int __init sil24_init(void)
1166{ 1207{
1167 return pci_module_init(&sil24_pci_driver); 1208 return pci_module_init(&sil24_pci_driver);
diff --git a/drivers/scsi/sata_via.c b/drivers/scsi/sata_via.c
index 03baec2191bf..a3727af8b9c1 100644
--- a/drivers/scsi/sata_via.c
+++ b/drivers/scsi/sata_via.c
@@ -74,8 +74,10 @@ enum {
74static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 74static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
75static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg); 75static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg);
76static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 76static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
77static void vt6420_error_handler(struct ata_port *ap);
77 78
78static const struct pci_device_id svia_pci_tbl[] = { 79static const struct pci_device_id svia_pci_tbl[] = {
80 { 0x1106, 0x0591, PCI_ANY_ID, PCI_ANY_ID, 0, 0, vt6420 },
79 { 0x1106, 0x3149, PCI_ANY_ID, PCI_ANY_ID, 0, 0, vt6420 }, 81 { 0x1106, 0x3149, PCI_ANY_ID, PCI_ANY_ID, 0, 0, vt6420 },
80 { 0x1106, 0x3249, PCI_ANY_ID, PCI_ANY_ID, 0, 0, vt6421 }, 82 { 0x1106, 0x3249, PCI_ANY_ID, PCI_ANY_ID, 0, 0, vt6421 },
81 83
@@ -107,7 +109,38 @@ static struct scsi_host_template svia_sht = {
107 .bios_param = ata_std_bios_param, 109 .bios_param = ata_std_bios_param,
108}; 110};
109 111
110static const struct ata_port_operations svia_sata_ops = { 112static const struct ata_port_operations vt6420_sata_ops = {
113 .port_disable = ata_port_disable,
114
115 .tf_load = ata_tf_load,
116 .tf_read = ata_tf_read,
117 .check_status = ata_check_status,
118 .exec_command = ata_exec_command,
119 .dev_select = ata_std_dev_select,
120
121 .bmdma_setup = ata_bmdma_setup,
122 .bmdma_start = ata_bmdma_start,
123 .bmdma_stop = ata_bmdma_stop,
124 .bmdma_status = ata_bmdma_status,
125
126 .qc_prep = ata_qc_prep,
127 .qc_issue = ata_qc_issue_prot,
128 .data_xfer = ata_pio_data_xfer,
129
130 .freeze = ata_bmdma_freeze,
131 .thaw = ata_bmdma_thaw,
132 .error_handler = vt6420_error_handler,
133 .post_internal_cmd = ata_bmdma_post_internal_cmd,
134
135 .irq_handler = ata_interrupt,
136 .irq_clear = ata_bmdma_irq_clear,
137
138 .port_start = ata_port_start,
139 .port_stop = ata_port_stop,
140 .host_stop = ata_host_stop,
141};
142
143static const struct ata_port_operations vt6421_sata_ops = {
111 .port_disable = ata_port_disable, 144 .port_disable = ata_port_disable,
112 145
113 .tf_load = ata_tf_load, 146 .tf_load = ata_tf_load,
@@ -141,13 +174,13 @@ static const struct ata_port_operations svia_sata_ops = {
141 .host_stop = ata_host_stop, 174 .host_stop = ata_host_stop,
142}; 175};
143 176
144static struct ata_port_info svia_port_info = { 177static struct ata_port_info vt6420_port_info = {
145 .sht = &svia_sht, 178 .sht = &svia_sht,
146 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, 179 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
147 .pio_mask = 0x1f, 180 .pio_mask = 0x1f,
148 .mwdma_mask = 0x07, 181 .mwdma_mask = 0x07,
149 .udma_mask = 0x7f, 182 .udma_mask = 0x7f,
150 .port_ops = &svia_sata_ops, 183 .port_ops = &vt6420_sata_ops,
151}; 184};
152 185
153MODULE_AUTHOR("Jeff Garzik"); 186MODULE_AUTHOR("Jeff Garzik");
@@ -170,6 +203,81 @@ static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
170 outl(val, ap->ioaddr.scr_addr + (4 * sc_reg)); 203 outl(val, ap->ioaddr.scr_addr + (4 * sc_reg));
171} 204}
172 205
206/**
207 * vt6420_prereset - prereset for vt6420
208 * @ap: target ATA port
209 *
210 * SCR registers on vt6420 are pieces of shit and may hang the
211 * whole machine completely if accessed with the wrong timing.
212 * To avoid such catastrophe, vt6420 doesn't provide generic SCR
213 * access operations, but uses SStatus and SControl only during
214 * boot probing in controlled way.
215 *
216 * As the old (pre EH update) probing code is proven to work, we
217 * strictly follow the access pattern.
218 *
219 * LOCKING:
220 * Kernel thread context (may sleep)
221 *
222 * RETURNS:
223 * 0 on success, -errno otherwise.
224 */
225static int vt6420_prereset(struct ata_port *ap)
226{
227 struct ata_eh_context *ehc = &ap->eh_context;
228 unsigned long timeout = jiffies + (HZ * 5);
229 u32 sstatus, scontrol;
230 int online;
231
232 /* don't do any SCR stuff if we're not loading */
233 if (!ATA_PFLAG_LOADING)
234 goto skip_scr;
235
236 /* Resume phy. This is the old resume sequence from
237 * __sata_phy_reset().
238 */
239 svia_scr_write(ap, SCR_CONTROL, 0x300);
240 svia_scr_read(ap, SCR_CONTROL); /* flush */
241
242 /* wait for phy to become ready, if necessary */
243 do {
244 msleep(200);
245 if ((svia_scr_read(ap, SCR_STATUS) & 0xf) != 1)
246 break;
247 } while (time_before(jiffies, timeout));
248
249 /* open code sata_print_link_status() */
250 sstatus = svia_scr_read(ap, SCR_STATUS);
251 scontrol = svia_scr_read(ap, SCR_CONTROL);
252
253 online = (sstatus & 0xf) == 0x3;
254
255 ata_port_printk(ap, KERN_INFO,
256 "SATA link %s 1.5 Gbps (SStatus %X SControl %X)\n",
257 online ? "up" : "down", sstatus, scontrol);
258
259 /* SStatus is read one more time */
260 svia_scr_read(ap, SCR_STATUS);
261
262 if (!online) {
263 /* tell EH to bail */
264 ehc->i.action &= ~ATA_EH_RESET_MASK;
265 return 0;
266 }
267
268 skip_scr:
269 /* wait for !BSY */
270 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
271
272 return 0;
273}
274
275static void vt6420_error_handler(struct ata_port *ap)
276{
277 return ata_bmdma_drive_eh(ap, vt6420_prereset, ata_std_softreset,
278 NULL, ata_std_postreset);
279}
280
173static const unsigned int svia_bar_sizes[] = { 281static const unsigned int svia_bar_sizes[] = {
174 8, 4, 8, 4, 16, 256 282 8, 4, 8, 4, 16, 256
175}; 283};
@@ -210,7 +318,7 @@ static void vt6421_init_addrs(struct ata_probe_ent *probe_ent,
210static struct ata_probe_ent *vt6420_init_probe_ent(struct pci_dev *pdev) 318static struct ata_probe_ent *vt6420_init_probe_ent(struct pci_dev *pdev)
211{ 319{
212 struct ata_probe_ent *probe_ent; 320 struct ata_probe_ent *probe_ent;
213 struct ata_port_info *ppi = &svia_port_info; 321 struct ata_port_info *ppi = &vt6420_port_info;
214 322
215 probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 323 probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
216 if (!probe_ent) 324 if (!probe_ent)
@@ -239,7 +347,7 @@ static struct ata_probe_ent *vt6421_init_probe_ent(struct pci_dev *pdev)
239 347
240 probe_ent->sht = &svia_sht; 348 probe_ent->sht = &svia_sht;
241 probe_ent->host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY; 349 probe_ent->host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY;
242 probe_ent->port_ops = &svia_sata_ops; 350 probe_ent->port_ops = &vt6421_sata_ops;
243 probe_ent->n_ports = N_PORTS; 351 probe_ent->n_ports = N_PORTS;
244 probe_ent->irq = pdev->irq; 352 probe_ent->irq = pdev->irq;
245 probe_ent->irq_flags = IRQF_SHARED; 353 probe_ent->irq_flags = IRQF_SHARED;
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index 916fe6fba756..ad37871594f5 100644
--- a/drivers/scsi/sata_vsc.c
+++ b/drivers/scsi/sata_vsc.c
@@ -297,7 +297,7 @@ static const struct ata_port_operations vsc_sata_ops = {
297 .bmdma_status = ata_bmdma_status, 297 .bmdma_status = ata_bmdma_status,
298 .qc_prep = ata_qc_prep, 298 .qc_prep = ata_qc_prep,
299 .qc_issue = ata_qc_issue_prot, 299 .qc_issue = ata_qc_issue_prot,
300 .data_xfer = ata_pio_data_xfer, 300 .data_xfer = ata_mmio_data_xfer,
301 .freeze = ata_bmdma_freeze, 301 .freeze = ata_bmdma_freeze,
302 .thaw = ata_bmdma_thaw, 302 .thaw = ata_bmdma_thaw,
303 .error_handler = ata_bmdma_error_handler, 303 .error_handler = ata_bmdma_error_handler,
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 2ab7df0dcfe8..b332caddd5b3 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -346,7 +346,7 @@ void scsi_log_send(struct scsi_cmnd *cmd)
346 if (level > 3) { 346 if (level > 3) {
347 printk(KERN_INFO "buffer = 0x%p, bufflen = %d," 347 printk(KERN_INFO "buffer = 0x%p, bufflen = %d,"
348 " done = 0x%p, queuecommand 0x%p\n", 348 " done = 0x%p, queuecommand 0x%p\n",
349 cmd->buffer, cmd->bufflen, 349 cmd->request_buffer, cmd->request_bufflen,
350 cmd->done, 350 cmd->done,
351 sdev->host->hostt->queuecommand); 351 sdev->host->hostt->queuecommand);
352 352
@@ -661,11 +661,6 @@ void __scsi_done(struct scsi_cmnd *cmd)
661 */ 661 */
662int scsi_retry_command(struct scsi_cmnd *cmd) 662int scsi_retry_command(struct scsi_cmnd *cmd)
663{ 663{
664 /*
665 * Restore the SCSI command state.
666 */
667 scsi_setup_cmd_retry(cmd);
668
669 /* 664 /*
670 * Zero the sense information from the last time we tried 665 * Zero the sense information from the last time we tried
671 * this command. 666 * this command.
@@ -711,10 +706,6 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
711 "Notifying upper driver of completion " 706 "Notifying upper driver of completion "
712 "(result %x)\n", cmd->result)); 707 "(result %x)\n", cmd->result));
713 708
714 /*
715 * We can get here with use_sg=0, causing a panic in the upper level
716 */
717 cmd->use_sg = cmd->old_use_sg;
718 cmd->done(cmd); 709 cmd->done(cmd);
719} 710}
720EXPORT_SYMBOL(scsi_finish_command); 711EXPORT_SYMBOL(scsi_finish_command);
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index e1168860045c..a80303c6b3fd 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -50,18 +50,22 @@
50#include "scsi_logging.h" 50#include "scsi_logging.h"
51#include "scsi_debug.h" 51#include "scsi_debug.h"
52 52
53#define SCSI_DEBUG_VERSION "1.75" 53#define SCSI_DEBUG_VERSION "1.79"
54static const char * scsi_debug_version_date = "20050113"; 54static const char * scsi_debug_version_date = "20060604";
55 55
56/* Additional Sense Code (ASC) used */ 56/* Additional Sense Code (ASC) used */
57#define NO_ADDED_SENSE 0x0 57#define NO_ADDITIONAL_SENSE 0x0
58#define LOGICAL_UNIT_NOT_READY 0x4
58#define UNRECOVERED_READ_ERR 0x11 59#define UNRECOVERED_READ_ERR 0x11
60#define PARAMETER_LIST_LENGTH_ERR 0x1a
59#define INVALID_OPCODE 0x20 61#define INVALID_OPCODE 0x20
60#define ADDR_OUT_OF_RANGE 0x21 62#define ADDR_OUT_OF_RANGE 0x21
61#define INVALID_FIELD_IN_CDB 0x24 63#define INVALID_FIELD_IN_CDB 0x24
64#define INVALID_FIELD_IN_PARAM_LIST 0x26
62#define POWERON_RESET 0x29 65#define POWERON_RESET 0x29
63#define SAVING_PARAMS_UNSUP 0x39 66#define SAVING_PARAMS_UNSUP 0x39
64#define THRESHHOLD_EXCEEDED 0x5d 67#define THRESHOLD_EXCEEDED 0x5d
68#define LOW_POWER_COND_ON 0x5e
65 69
66#define SDEBUG_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */ 70#define SDEBUG_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */
67 71
@@ -80,6 +84,8 @@ static const char * scsi_debug_version_date = "20050113";
80#define DEF_SCSI_LEVEL 5 /* INQUIRY, byte2 [5->SPC-3] */ 84#define DEF_SCSI_LEVEL 5 /* INQUIRY, byte2 [5->SPC-3] */
81#define DEF_PTYPE 0 85#define DEF_PTYPE 0
82#define DEF_D_SENSE 0 86#define DEF_D_SENSE 0
87#define DEF_NO_LUN_0 0
88#define DEF_VIRTUAL_GB 0
83 89
84/* bit mask values for scsi_debug_opts */ 90/* bit mask values for scsi_debug_opts */
85#define SCSI_DEBUG_OPT_NOISE 1 91#define SCSI_DEBUG_OPT_NOISE 1
@@ -106,6 +112,7 @@ static const char * scsi_debug_version_date = "20050113";
106/* If REPORT LUNS has luns >= 256 it can choose "flat space" (value 1) 112/* If REPORT LUNS has luns >= 256 it can choose "flat space" (value 1)
107 * or "peripheral device" addressing (value 0) */ 113 * or "peripheral device" addressing (value 0) */
108#define SAM2_LUN_ADDRESS_METHOD 0 114#define SAM2_LUN_ADDRESS_METHOD 0
115#define SAM2_WLUN_REPORT_LUNS 0xc101
109 116
110static int scsi_debug_add_host = DEF_NUM_HOST; 117static int scsi_debug_add_host = DEF_NUM_HOST;
111static int scsi_debug_delay = DEF_DELAY; 118static int scsi_debug_delay = DEF_DELAY;
@@ -118,13 +125,16 @@ static int scsi_debug_opts = DEF_OPTS;
118static int scsi_debug_scsi_level = DEF_SCSI_LEVEL; 125static int scsi_debug_scsi_level = DEF_SCSI_LEVEL;
119static int scsi_debug_ptype = DEF_PTYPE; /* SCSI peripheral type (0==disk) */ 126static int scsi_debug_ptype = DEF_PTYPE; /* SCSI peripheral type (0==disk) */
120static int scsi_debug_dsense = DEF_D_SENSE; 127static int scsi_debug_dsense = DEF_D_SENSE;
128static int scsi_debug_no_lun_0 = DEF_NO_LUN_0;
129static int scsi_debug_virtual_gb = DEF_VIRTUAL_GB;
121 130
122static int scsi_debug_cmnd_count = 0; 131static int scsi_debug_cmnd_count = 0;
123 132
124#define DEV_READONLY(TGT) (0) 133#define DEV_READONLY(TGT) (0)
125#define DEV_REMOVEABLE(TGT) (0) 134#define DEV_REMOVEABLE(TGT) (0)
126 135
127static unsigned long sdebug_store_size; /* in bytes */ 136static unsigned int sdebug_store_size; /* in bytes */
137static unsigned int sdebug_store_sectors;
128static sector_t sdebug_capacity; /* in sectors */ 138static sector_t sdebug_capacity; /* in sectors */
129 139
130/* old BIOS stuff, kernel may get rid of them but some mode sense pages 140/* old BIOS stuff, kernel may get rid of them but some mode sense pages
@@ -149,7 +159,9 @@ struct sdebug_dev_info {
149 unsigned int target; 159 unsigned int target;
150 unsigned int lun; 160 unsigned int lun;
151 struct sdebug_host_info *sdbg_host; 161 struct sdebug_host_info *sdbg_host;
162 unsigned int wlun;
152 char reset; 163 char reset;
164 char stopped;
153 char used; 165 char used;
154}; 166};
155 167
@@ -193,11 +205,11 @@ static struct scsi_host_template sdebug_driver_template = {
193 .bios_param = scsi_debug_biosparam, 205 .bios_param = scsi_debug_biosparam,
194 .can_queue = SCSI_DEBUG_CANQUEUE, 206 .can_queue = SCSI_DEBUG_CANQUEUE,
195 .this_id = 7, 207 .this_id = 7,
196 .sg_tablesize = 64, 208 .sg_tablesize = 256,
197 .cmd_per_lun = 3, 209 .cmd_per_lun = 16,
198 .max_sectors = 4096, 210 .max_sectors = 0xffff,
199 .unchecked_isa_dma = 0, 211 .unchecked_isa_dma = 0,
200 .use_clustering = DISABLE_CLUSTERING, 212 .use_clustering = ENABLE_CLUSTERING,
201 .module = THIS_MODULE, 213 .module = THIS_MODULE,
202}; 214};
203 215
@@ -225,19 +237,32 @@ static struct device_driver sdebug_driverfs_driver = {
225static const int check_condition_result = 237static const int check_condition_result =
226 (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; 238 (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
227 239
240static unsigned char ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0,
241 0, 0, 0x2, 0x4b};
242static unsigned char iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0,
243 0, 0, 0x0, 0x0};
244
228/* function declarations */ 245/* function declarations */
229static int resp_inquiry(struct scsi_cmnd * SCpnt, int target, 246static int resp_inquiry(struct scsi_cmnd * SCpnt, int target,
230 struct sdebug_dev_info * devip); 247 struct sdebug_dev_info * devip);
231static int resp_requests(struct scsi_cmnd * SCpnt, 248static int resp_requests(struct scsi_cmnd * SCpnt,
232 struct sdebug_dev_info * devip); 249 struct sdebug_dev_info * devip);
250static int resp_start_stop(struct scsi_cmnd * scp,
251 struct sdebug_dev_info * devip);
233static int resp_readcap(struct scsi_cmnd * SCpnt, 252static int resp_readcap(struct scsi_cmnd * SCpnt,
234 struct sdebug_dev_info * devip); 253 struct sdebug_dev_info * devip);
235static int resp_mode_sense(struct scsi_cmnd * SCpnt, int target, 254static int resp_readcap16(struct scsi_cmnd * SCpnt,
255 struct sdebug_dev_info * devip);
256static int resp_mode_sense(struct scsi_cmnd * scp, int target,
236 struct sdebug_dev_info * devip); 257 struct sdebug_dev_info * devip);
237static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block, 258static int resp_mode_select(struct scsi_cmnd * scp, int mselect6,
238 int num, struct sdebug_dev_info * devip); 259 struct sdebug_dev_info * devip);
239static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block, 260static int resp_log_sense(struct scsi_cmnd * scp,
240 int num, struct sdebug_dev_info * devip); 261 struct sdebug_dev_info * devip);
262static int resp_read(struct scsi_cmnd * SCpnt, unsigned long long lba,
263 unsigned int num, struct sdebug_dev_info * devip);
264static int resp_write(struct scsi_cmnd * SCpnt, unsigned long long lba,
265 unsigned int num, struct sdebug_dev_info * devip);
241static int resp_report_luns(struct scsi_cmnd * SCpnt, 266static int resp_report_luns(struct scsi_cmnd * SCpnt,
242 struct sdebug_dev_info * devip); 267 struct sdebug_dev_info * devip);
243static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, 268static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
@@ -248,8 +273,8 @@ static void timer_intr_handler(unsigned long);
248static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev); 273static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev);
249static void mk_sense_buffer(struct sdebug_dev_info * devip, int key, 274static void mk_sense_buffer(struct sdebug_dev_info * devip, int key,
250 int asc, int asq); 275 int asc, int asq);
251static int check_reset(struct scsi_cmnd * SCpnt, 276static int check_readiness(struct scsi_cmnd * SCpnt, int reset_only,
252 struct sdebug_dev_info * devip); 277 struct sdebug_dev_info * devip);
253static int schedule_resp(struct scsi_cmnd * cmnd, 278static int schedule_resp(struct scsi_cmnd * cmnd,
254 struct sdebug_dev_info * devip, 279 struct sdebug_dev_info * devip,
255 done_funct_t done, int scsi_result, int delta_jiff); 280 done_funct_t done, int scsi_result, int delta_jiff);
@@ -257,9 +282,11 @@ static void __init sdebug_build_parts(unsigned char * ramp);
257static void __init init_all_queued(void); 282static void __init init_all_queued(void);
258static void stop_all_queued(void); 283static void stop_all_queued(void);
259static int stop_queued_cmnd(struct scsi_cmnd * cmnd); 284static int stop_queued_cmnd(struct scsi_cmnd * cmnd);
260static int inquiry_evpd_83(unsigned char * arr, int dev_id_num, 285static int inquiry_evpd_83(unsigned char * arr, int target_dev_id,
261 const char * dev_id_str, int dev_id_str_len); 286 int dev_id_num, const char * dev_id_str,
262static void do_create_driverfs_files(void); 287 int dev_id_str_len);
288static int inquiry_evpd_88(unsigned char * arr, int target_dev_id);
289static int do_create_driverfs_files(void);
263static void do_remove_driverfs_files(void); 290static void do_remove_driverfs_files(void);
264 291
265static int sdebug_add_adapter(void); 292static int sdebug_add_adapter(void);
@@ -274,18 +301,22 @@ static
274int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done) 301int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
275{ 302{
276 unsigned char *cmd = (unsigned char *) SCpnt->cmnd; 303 unsigned char *cmd = (unsigned char *) SCpnt->cmnd;
277 int block, upper_blk, num, k; 304 int len, k, j;
305 unsigned int num;
306 unsigned long long lba;
278 int errsts = 0; 307 int errsts = 0;
279 int target = scmd_id(SCpnt); 308 int target = SCpnt->device->id;
280 struct sdebug_dev_info * devip = NULL; 309 struct sdebug_dev_info * devip = NULL;
281 int inj_recovered = 0; 310 int inj_recovered = 0;
311 int delay_override = 0;
282 312
283 if (done == NULL) 313 if (done == NULL)
284 return 0; /* assume mid level reprocessing command */ 314 return 0; /* assume mid level reprocessing command */
285 315
316 SCpnt->resid = 0;
286 if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmd) { 317 if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) && cmd) {
287 printk(KERN_INFO "scsi_debug: cmd "); 318 printk(KERN_INFO "scsi_debug: cmd ");
288 for (k = 0, num = SCpnt->cmd_len; k < num; ++k) 319 for (k = 0, len = SCpnt->cmd_len; k < len; ++k)
289 printk("%02x ", (int)cmd[k]); 320 printk("%02x ", (int)cmd[k]);
290 printk("\n"); 321 printk("\n");
291 } 322 }
@@ -296,7 +327,8 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
296 DID_NO_CONNECT << 16, 0); 327 DID_NO_CONNECT << 16, 0);
297 } 328 }
298 329
299 if (SCpnt->device->lun >= scsi_debug_max_luns) 330 if ((SCpnt->device->lun >= scsi_debug_max_luns) &&
331 (SCpnt->device->lun != SAM2_WLUN_REPORT_LUNS))
300 return schedule_resp(SCpnt, NULL, done, 332 return schedule_resp(SCpnt, NULL, done,
301 DID_NO_CONNECT << 16, 0); 333 DID_NO_CONNECT << 16, 0);
302 devip = devInfoReg(SCpnt->device); 334 devip = devInfoReg(SCpnt->device);
@@ -315,118 +347,150 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
315 inj_recovered = 1; /* to reads and writes below */ 347 inj_recovered = 1; /* to reads and writes below */
316 } 348 }
317 349
350 if (devip->wlun) {
351 switch (*cmd) {
352 case INQUIRY:
353 case REQUEST_SENSE:
354 case TEST_UNIT_READY:
355 case REPORT_LUNS:
356 break; /* only allowable wlun commands */
357 default:
358 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
359 printk(KERN_INFO "scsi_debug: Opcode: 0x%x "
360 "not supported for wlun\n", *cmd);
361 mk_sense_buffer(devip, ILLEGAL_REQUEST,
362 INVALID_OPCODE, 0);
363 errsts = check_condition_result;
364 return schedule_resp(SCpnt, devip, done, errsts,
365 0);
366 }
367 }
368
318 switch (*cmd) { 369 switch (*cmd) {
319 case INQUIRY: /* mandatory, ignore unit attention */ 370 case INQUIRY: /* mandatory, ignore unit attention */
371 delay_override = 1;
320 errsts = resp_inquiry(SCpnt, target, devip); 372 errsts = resp_inquiry(SCpnt, target, devip);
321 break; 373 break;
322 case REQUEST_SENSE: /* mandatory, ignore unit attention */ 374 case REQUEST_SENSE: /* mandatory, ignore unit attention */
375 delay_override = 1;
323 errsts = resp_requests(SCpnt, devip); 376 errsts = resp_requests(SCpnt, devip);
324 break; 377 break;
325 case REZERO_UNIT: /* actually this is REWIND for SSC */ 378 case REZERO_UNIT: /* actually this is REWIND for SSC */
326 case START_STOP: 379 case START_STOP:
327 errsts = check_reset(SCpnt, devip); 380 errsts = resp_start_stop(SCpnt, devip);
328 break; 381 break;
329 case ALLOW_MEDIUM_REMOVAL: 382 case ALLOW_MEDIUM_REMOVAL:
330 if ((errsts = check_reset(SCpnt, devip))) 383 if ((errsts = check_readiness(SCpnt, 1, devip)))
331 break; 384 break;
332 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 385 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
333 printk(KERN_INFO "scsi_debug: Medium removal %s\n", 386 printk(KERN_INFO "scsi_debug: Medium removal %s\n",
334 cmd[4] ? "inhibited" : "enabled"); 387 cmd[4] ? "inhibited" : "enabled");
335 break; 388 break;
336 case SEND_DIAGNOSTIC: /* mandatory */ 389 case SEND_DIAGNOSTIC: /* mandatory */
337 errsts = check_reset(SCpnt, devip); 390 errsts = check_readiness(SCpnt, 1, devip);
338 break; 391 break;
339 case TEST_UNIT_READY: /* mandatory */ 392 case TEST_UNIT_READY: /* mandatory */
340 errsts = check_reset(SCpnt, devip); 393 delay_override = 1;
394 errsts = check_readiness(SCpnt, 0, devip);
341 break; 395 break;
342 case RESERVE: 396 case RESERVE:
343 errsts = check_reset(SCpnt, devip); 397 errsts = check_readiness(SCpnt, 1, devip);
344 break; 398 break;
345 case RESERVE_10: 399 case RESERVE_10:
346 errsts = check_reset(SCpnt, devip); 400 errsts = check_readiness(SCpnt, 1, devip);
347 break; 401 break;
348 case RELEASE: 402 case RELEASE:
349 errsts = check_reset(SCpnt, devip); 403 errsts = check_readiness(SCpnt, 1, devip);
350 break; 404 break;
351 case RELEASE_10: 405 case RELEASE_10:
352 errsts = check_reset(SCpnt, devip); 406 errsts = check_readiness(SCpnt, 1, devip);
353 break; 407 break;
354 case READ_CAPACITY: 408 case READ_CAPACITY:
355 errsts = resp_readcap(SCpnt, devip); 409 errsts = resp_readcap(SCpnt, devip);
356 break; 410 break;
411 case SERVICE_ACTION_IN:
412 if (SAI_READ_CAPACITY_16 != cmd[1]) {
413 mk_sense_buffer(devip, ILLEGAL_REQUEST,
414 INVALID_OPCODE, 0);
415 errsts = check_condition_result;
416 break;
417 }
418 errsts = resp_readcap16(SCpnt, devip);
419 break;
357 case READ_16: 420 case READ_16:
358 case READ_12: 421 case READ_12:
359 case READ_10: 422 case READ_10:
360 case READ_6: 423 case READ_6:
361 if ((errsts = check_reset(SCpnt, devip))) 424 if ((errsts = check_readiness(SCpnt, 0, devip)))
362 break; 425 break;
363 upper_blk = 0;
364 if ((*cmd) == READ_16) { 426 if ((*cmd) == READ_16) {
365 upper_blk = cmd[5] + (cmd[4] << 8) + 427 for (lba = 0, j = 0; j < 8; ++j) {
366 (cmd[3] << 16) + (cmd[2] << 24); 428 if (j > 0)
367 block = cmd[9] + (cmd[8] << 8) + 429 lba <<= 8;
368 (cmd[7] << 16) + (cmd[6] << 24); 430 lba += cmd[2 + j];
431 }
369 num = cmd[13] + (cmd[12] << 8) + 432 num = cmd[13] + (cmd[12] << 8) +
370 (cmd[11] << 16) + (cmd[10] << 24); 433 (cmd[11] << 16) + (cmd[10] << 24);
371 } else if ((*cmd) == READ_12) { 434 } else if ((*cmd) == READ_12) {
372 block = cmd[5] + (cmd[4] << 8) + 435 lba = cmd[5] + (cmd[4] << 8) +
373 (cmd[3] << 16) + (cmd[2] << 24); 436 (cmd[3] << 16) + (cmd[2] << 24);
374 num = cmd[9] + (cmd[8] << 8) + 437 num = cmd[9] + (cmd[8] << 8) +
375 (cmd[7] << 16) + (cmd[6] << 24); 438 (cmd[7] << 16) + (cmd[6] << 24);
376 } else if ((*cmd) == READ_10) { 439 } else if ((*cmd) == READ_10) {
377 block = cmd[5] + (cmd[4] << 8) + 440 lba = cmd[5] + (cmd[4] << 8) +
378 (cmd[3] << 16) + (cmd[2] << 24); 441 (cmd[3] << 16) + (cmd[2] << 24);
379 num = cmd[8] + (cmd[7] << 8); 442 num = cmd[8] + (cmd[7] << 8);
380 } else { 443 } else { /* READ (6) */
381 block = cmd[3] + (cmd[2] << 8) + 444 lba = cmd[3] + (cmd[2] << 8) +
382 ((cmd[1] & 0x1f) << 16); 445 ((cmd[1] & 0x1f) << 16);
383 num = cmd[4]; 446 num = (0 == cmd[4]) ? 256 : cmd[4];
384 } 447 }
385 errsts = resp_read(SCpnt, upper_blk, block, num, devip); 448 errsts = resp_read(SCpnt, lba, num, devip);
386 if (inj_recovered && (0 == errsts)) { 449 if (inj_recovered && (0 == errsts)) {
387 mk_sense_buffer(devip, RECOVERED_ERROR, 450 mk_sense_buffer(devip, RECOVERED_ERROR,
388 THRESHHOLD_EXCEEDED, 0); 451 THRESHOLD_EXCEEDED, 0);
389 errsts = check_condition_result; 452 errsts = check_condition_result;
390 } 453 }
391 break; 454 break;
392 case REPORT_LUNS: /* mandatory, ignore unit attention */ 455 case REPORT_LUNS: /* mandatory, ignore unit attention */
456 delay_override = 1;
393 errsts = resp_report_luns(SCpnt, devip); 457 errsts = resp_report_luns(SCpnt, devip);
394 break; 458 break;
395 case VERIFY: /* 10 byte SBC-2 command */ 459 case VERIFY: /* 10 byte SBC-2 command */
396 errsts = check_reset(SCpnt, devip); 460 errsts = check_readiness(SCpnt, 0, devip);
397 break; 461 break;
398 case WRITE_16: 462 case WRITE_16:
399 case WRITE_12: 463 case WRITE_12:
400 case WRITE_10: 464 case WRITE_10:
401 case WRITE_6: 465 case WRITE_6:
402 if ((errsts = check_reset(SCpnt, devip))) 466 if ((errsts = check_readiness(SCpnt, 0, devip)))
403 break; 467 break;
404 upper_blk = 0;
405 if ((*cmd) == WRITE_16) { 468 if ((*cmd) == WRITE_16) {
406 upper_blk = cmd[5] + (cmd[4] << 8) + 469 for (lba = 0, j = 0; j < 8; ++j) {
407 (cmd[3] << 16) + (cmd[2] << 24); 470 if (j > 0)
408 block = cmd[9] + (cmd[8] << 8) + 471 lba <<= 8;
409 (cmd[7] << 16) + (cmd[6] << 24); 472 lba += cmd[2 + j];
473 }
410 num = cmd[13] + (cmd[12] << 8) + 474 num = cmd[13] + (cmd[12] << 8) +
411 (cmd[11] << 16) + (cmd[10] << 24); 475 (cmd[11] << 16) + (cmd[10] << 24);
412 } else if ((*cmd) == WRITE_12) { 476 } else if ((*cmd) == WRITE_12) {
413 block = cmd[5] + (cmd[4] << 8) + 477 lba = cmd[5] + (cmd[4] << 8) +
414 (cmd[3] << 16) + (cmd[2] << 24); 478 (cmd[3] << 16) + (cmd[2] << 24);
415 num = cmd[9] + (cmd[8] << 8) + 479 num = cmd[9] + (cmd[8] << 8) +
416 (cmd[7] << 16) + (cmd[6] << 24); 480 (cmd[7] << 16) + (cmd[6] << 24);
417 } else if ((*cmd) == WRITE_10) { 481 } else if ((*cmd) == WRITE_10) {
418 block = cmd[5] + (cmd[4] << 8) + 482 lba = cmd[5] + (cmd[4] << 8) +
419 (cmd[3] << 16) + (cmd[2] << 24); 483 (cmd[3] << 16) + (cmd[2] << 24);
420 num = cmd[8] + (cmd[7] << 8); 484 num = cmd[8] + (cmd[7] << 8);
421 } else { 485 } else { /* WRITE (6) */
422 block = cmd[3] + (cmd[2] << 8) + 486 lba = cmd[3] + (cmd[2] << 8) +
423 ((cmd[1] & 0x1f) << 16); 487 ((cmd[1] & 0x1f) << 16);
424 num = cmd[4]; 488 num = (0 == cmd[4]) ? 256 : cmd[4];
425 } 489 }
426 errsts = resp_write(SCpnt, upper_blk, block, num, devip); 490 errsts = resp_write(SCpnt, lba, num, devip);
427 if (inj_recovered && (0 == errsts)) { 491 if (inj_recovered && (0 == errsts)) {
428 mk_sense_buffer(devip, RECOVERED_ERROR, 492 mk_sense_buffer(devip, RECOVERED_ERROR,
429 THRESHHOLD_EXCEEDED, 0); 493 THRESHOLD_EXCEEDED, 0);
430 errsts = check_condition_result; 494 errsts = check_condition_result;
431 } 495 }
432 break; 496 break;
@@ -434,20 +498,31 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
434 case MODE_SENSE_10: 498 case MODE_SENSE_10:
435 errsts = resp_mode_sense(SCpnt, target, devip); 499 errsts = resp_mode_sense(SCpnt, target, devip);
436 break; 500 break;
501 case MODE_SELECT:
502 errsts = resp_mode_select(SCpnt, 1, devip);
503 break;
504 case MODE_SELECT_10:
505 errsts = resp_mode_select(SCpnt, 0, devip);
506 break;
507 case LOG_SENSE:
508 errsts = resp_log_sense(SCpnt, devip);
509 break;
437 case SYNCHRONIZE_CACHE: 510 case SYNCHRONIZE_CACHE:
438 errsts = check_reset(SCpnt, devip); 511 delay_override = 1;
512 errsts = check_readiness(SCpnt, 0, devip);
439 break; 513 break;
440 default: 514 default:
441 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 515 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
442 printk(KERN_INFO "scsi_debug: Opcode: 0x%x not " 516 printk(KERN_INFO "scsi_debug: Opcode: 0x%x not "
443 "supported\n", *cmd); 517 "supported\n", *cmd);
444 if ((errsts = check_reset(SCpnt, devip))) 518 if ((errsts = check_readiness(SCpnt, 1, devip)))
445 break; /* Unit attention takes precedence */ 519 break; /* Unit attention takes precedence */
446 mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_OPCODE, 0); 520 mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_OPCODE, 0);
447 errsts = check_condition_result; 521 errsts = check_condition_result;
448 break; 522 break;
449 } 523 }
450 return schedule_resp(SCpnt, devip, done, errsts, scsi_debug_delay); 524 return schedule_resp(SCpnt, devip, done, errsts,
525 (delay_override ? 0 : scsi_debug_delay));
451} 526}
452 527
453static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg) 528static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg)
@@ -459,7 +534,8 @@ static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg)
459 /* return -ENOTTY; // correct return but upsets fdisk */ 534 /* return -ENOTTY; // correct return but upsets fdisk */
460} 535}
461 536
462static int check_reset(struct scsi_cmnd * SCpnt, struct sdebug_dev_info * devip) 537static int check_readiness(struct scsi_cmnd * SCpnt, int reset_only,
538 struct sdebug_dev_info * devip)
463{ 539{
464 if (devip->reset) { 540 if (devip->reset) {
465 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 541 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
@@ -469,6 +545,14 @@ static int check_reset(struct scsi_cmnd * SCpnt, struct sdebug_dev_info * devip)
469 mk_sense_buffer(devip, UNIT_ATTENTION, POWERON_RESET, 0); 545 mk_sense_buffer(devip, UNIT_ATTENTION, POWERON_RESET, 0);
470 return check_condition_result; 546 return check_condition_result;
471 } 547 }
548 if ((0 == reset_only) && devip->stopped) {
549 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
550 printk(KERN_INFO "scsi_debug: Reporting Not "
551 "ready: initializing command required\n");
552 mk_sense_buffer(devip, NOT_READY, LOGICAL_UNIT_NOT_READY,
553 0x2);
554 return check_condition_result;
555 }
472 return 0; 556 return 0;
473} 557}
474 558
@@ -492,7 +576,10 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
492 req_len = scp->request_bufflen; 576 req_len = scp->request_bufflen;
493 act_len = (req_len < arr_len) ? req_len : arr_len; 577 act_len = (req_len < arr_len) ? req_len : arr_len;
494 memcpy(scp->request_buffer, arr, act_len); 578 memcpy(scp->request_buffer, arr, act_len);
495 scp->resid = req_len - act_len; 579 if (scp->resid)
580 scp->resid -= act_len;
581 else
582 scp->resid = req_len - act_len;
496 return 0; 583 return 0;
497 } 584 }
498 sgpnt = (struct scatterlist *)scp->request_buffer; 585 sgpnt = (struct scatterlist *)scp->request_buffer;
@@ -515,7 +602,10 @@ static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr,
515 } 602 }
516 req_len += sgpnt->length; 603 req_len += sgpnt->length;
517 } 604 }
518 scp->resid = req_len - act_len; 605 if (scp->resid)
606 scp->resid -= act_len;
607 else
608 scp->resid = req_len - act_len;
519 return 0; 609 return 0;
520} 610}
521 611
@@ -566,12 +656,14 @@ static const char * inq_vendor_id = "Linux ";
566static const char * inq_product_id = "scsi_debug "; 656static const char * inq_product_id = "scsi_debug ";
567static const char * inq_product_rev = "0004"; 657static const char * inq_product_rev = "0004";
568 658
569static int inquiry_evpd_83(unsigned char * arr, int dev_id_num, 659static int inquiry_evpd_83(unsigned char * arr, int target_dev_id,
570 const char * dev_id_str, int dev_id_str_len) 660 int dev_id_num, const char * dev_id_str,
661 int dev_id_str_len)
571{ 662{
572 int num; 663 int num, port_a;
664 char b[32];
573 665
574 /* Two identification descriptors: */ 666 port_a = target_dev_id + 1;
575 /* T10 vendor identifier field format (faked) */ 667 /* T10 vendor identifier field format (faked) */
576 arr[0] = 0x2; /* ASCII */ 668 arr[0] = 0x2; /* ASCII */
577 arr[1] = 0x1; 669 arr[1] = 0x1;
@@ -582,25 +674,246 @@ static int inquiry_evpd_83(unsigned char * arr, int dev_id_num,
582 num = 8 + 16 + dev_id_str_len; 674 num = 8 + 16 + dev_id_str_len;
583 arr[3] = num; 675 arr[3] = num;
584 num += 4; 676 num += 4;
585 /* NAA IEEE registered identifier (faked) */ 677 if (dev_id_num >= 0) {
586 arr[num] = 0x1; /* binary */ 678 /* NAA-5, Logical unit identifier (binary) */
587 arr[num + 1] = 0x3; 679 arr[num++] = 0x1; /* binary (not necessarily sas) */
588 arr[num + 2] = 0x0; 680 arr[num++] = 0x3; /* PIV=0, lu, naa */
589 arr[num + 3] = 0x8; 681 arr[num++] = 0x0;
590 arr[num + 4] = 0x51; /* ieee company id=0x123456 (faked) */ 682 arr[num++] = 0x8;
591 arr[num + 5] = 0x23; 683 arr[num++] = 0x53; /* naa-5 ieee company id=0x333333 (fake) */
592 arr[num + 6] = 0x45; 684 arr[num++] = 0x33;
593 arr[num + 7] = 0x60; 685 arr[num++] = 0x33;
594 arr[num + 8] = (dev_id_num >> 24); 686 arr[num++] = 0x30;
595 arr[num + 9] = (dev_id_num >> 16) & 0xff; 687 arr[num++] = (dev_id_num >> 24);
596 arr[num + 10] = (dev_id_num >> 8) & 0xff; 688 arr[num++] = (dev_id_num >> 16) & 0xff;
597 arr[num + 11] = dev_id_num & 0xff; 689 arr[num++] = (dev_id_num >> 8) & 0xff;
598 return num + 12; 690 arr[num++] = dev_id_num & 0xff;
691 /* Target relative port number */
692 arr[num++] = 0x61; /* proto=sas, binary */
693 arr[num++] = 0x94; /* PIV=1, target port, rel port */
694 arr[num++] = 0x0; /* reserved */
695 arr[num++] = 0x4; /* length */
696 arr[num++] = 0x0; /* reserved */
697 arr[num++] = 0x0; /* reserved */
698 arr[num++] = 0x0;
699 arr[num++] = 0x1; /* relative port A */
700 }
701 /* NAA-5, Target port identifier */
702 arr[num++] = 0x61; /* proto=sas, binary */
703 arr[num++] = 0x93; /* piv=1, target port, naa */
704 arr[num++] = 0x0;
705 arr[num++] = 0x8;
706 arr[num++] = 0x52; /* naa-5, company id=0x222222 (fake) */
707 arr[num++] = 0x22;
708 arr[num++] = 0x22;
709 arr[num++] = 0x20;
710 arr[num++] = (port_a >> 24);
711 arr[num++] = (port_a >> 16) & 0xff;
712 arr[num++] = (port_a >> 8) & 0xff;
713 arr[num++] = port_a & 0xff;
714 /* NAA-5, Target device identifier */
715 arr[num++] = 0x61; /* proto=sas, binary */
716 arr[num++] = 0xa3; /* piv=1, target device, naa */
717 arr[num++] = 0x0;
718 arr[num++] = 0x8;
719 arr[num++] = 0x52; /* naa-5, company id=0x222222 (fake) */
720 arr[num++] = 0x22;
721 arr[num++] = 0x22;
722 arr[num++] = 0x20;
723 arr[num++] = (target_dev_id >> 24);
724 arr[num++] = (target_dev_id >> 16) & 0xff;
725 arr[num++] = (target_dev_id >> 8) & 0xff;
726 arr[num++] = target_dev_id & 0xff;
727 /* SCSI name string: Target device identifier */
728 arr[num++] = 0x63; /* proto=sas, UTF-8 */
729 arr[num++] = 0xa8; /* piv=1, target device, SCSI name string */
730 arr[num++] = 0x0;
731 arr[num++] = 24;
732 memcpy(arr + num, "naa.52222220", 12);
733 num += 12;
734 snprintf(b, sizeof(b), "%08X", target_dev_id);
735 memcpy(arr + num, b, 8);
736 num += 8;
737 memset(arr + num, 0, 4);
738 num += 4;
739 return num;
740}
741
742
743static unsigned char vpd84_data[] = {
744/* from 4th byte */ 0x22,0x22,0x22,0x0,0xbb,0x0,
745 0x22,0x22,0x22,0x0,0xbb,0x1,
746 0x22,0x22,0x22,0x0,0xbb,0x2,
747};
748
749static int inquiry_evpd_84(unsigned char * arr)
750{
751 memcpy(arr, vpd84_data, sizeof(vpd84_data));
752 return sizeof(vpd84_data);
753}
754
755static int inquiry_evpd_85(unsigned char * arr)
756{
757 int num = 0;
758 const char * na1 = "https://www.kernel.org/config";
759 const char * na2 = "http://www.kernel.org/log";
760 int plen, olen;
761
762 arr[num++] = 0x1; /* lu, storage config */
763 arr[num++] = 0x0; /* reserved */
764 arr[num++] = 0x0;
765 olen = strlen(na1);
766 plen = olen + 1;
767 if (plen % 4)
768 plen = ((plen / 4) + 1) * 4;
769 arr[num++] = plen; /* length, null termianted, padded */
770 memcpy(arr + num, na1, olen);
771 memset(arr + num + olen, 0, plen - olen);
772 num += plen;
773
774 arr[num++] = 0x4; /* lu, logging */
775 arr[num++] = 0x0; /* reserved */
776 arr[num++] = 0x0;
777 olen = strlen(na2);
778 plen = olen + 1;
779 if (plen % 4)
780 plen = ((plen / 4) + 1) * 4;
781 arr[num++] = plen; /* length, null terminated, padded */
782 memcpy(arr + num, na2, olen);
783 memset(arr + num + olen, 0, plen - olen);
784 num += plen;
785
786 return num;
787}
788
789/* SCSI ports VPD page */
790static int inquiry_evpd_88(unsigned char * arr, int target_dev_id)
791{
792 int num = 0;
793 int port_a, port_b;
794
795 port_a = target_dev_id + 1;
796 port_b = port_a + 1;
797 arr[num++] = 0x0; /* reserved */
798 arr[num++] = 0x0; /* reserved */
799 arr[num++] = 0x0;
800 arr[num++] = 0x1; /* relative port 1 (primary) */
801 memset(arr + num, 0, 6);
802 num += 6;
803 arr[num++] = 0x0;
804 arr[num++] = 12; /* length tp descriptor */
805 /* naa-5 target port identifier (A) */
806 arr[num++] = 0x61; /* proto=sas, binary */
807 arr[num++] = 0x93; /* PIV=1, target port, NAA */
808 arr[num++] = 0x0; /* reserved */
809 arr[num++] = 0x8; /* length */
810 arr[num++] = 0x52; /* NAA-5, company_id=0x222222 (fake) */
811 arr[num++] = 0x22;
812 arr[num++] = 0x22;
813 arr[num++] = 0x20;
814 arr[num++] = (port_a >> 24);
815 arr[num++] = (port_a >> 16) & 0xff;
816 arr[num++] = (port_a >> 8) & 0xff;
817 arr[num++] = port_a & 0xff;
818
819 arr[num++] = 0x0; /* reserved */
820 arr[num++] = 0x0; /* reserved */
821 arr[num++] = 0x0;
822 arr[num++] = 0x2; /* relative port 2 (secondary) */
823 memset(arr + num, 0, 6);
824 num += 6;
825 arr[num++] = 0x0;
826 arr[num++] = 12; /* length tp descriptor */
827 /* naa-5 target port identifier (B) */
828 arr[num++] = 0x61; /* proto=sas, binary */
829 arr[num++] = 0x93; /* PIV=1, target port, NAA */
830 arr[num++] = 0x0; /* reserved */
831 arr[num++] = 0x8; /* length */
832 arr[num++] = 0x52; /* NAA-5, company_id=0x222222 (fake) */
833 arr[num++] = 0x22;
834 arr[num++] = 0x22;
835 arr[num++] = 0x20;
836 arr[num++] = (port_b >> 24);
837 arr[num++] = (port_b >> 16) & 0xff;
838 arr[num++] = (port_b >> 8) & 0xff;
839 arr[num++] = port_b & 0xff;
840
841 return num;
842}
843
844
845static unsigned char vpd89_data[] = {
846/* from 4th byte */ 0,0,0,0,
847'l','i','n','u','x',' ',' ',' ',
848'S','A','T',' ','s','c','s','i','_','d','e','b','u','g',' ',' ',
849'1','2','3','4',
8500x34,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,
8510xec,0,0,0,
8520x5a,0xc,0xff,0x3f,0x37,0xc8,0x10,0,0,0,0,0,0x3f,0,0,0,
8530,0,0,0,0x58,0x58,0x58,0x58,0x58,0x58,0x58,0x58,0x20,0x20,0x20,0x20,
8540x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0,0,0,0x40,0x4,0,0x2e,0x33,
8550x38,0x31,0x20,0x20,0x20,0x20,0x54,0x53,0x38,0x33,0x30,0x30,0x33,0x31,
8560x53,0x41,
8570x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
8580x20,0x20,
8590x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
8600x10,0x80,
8610,0,0,0x2f,0,0,0,0x2,0,0x2,0x7,0,0xff,0xff,0x1,0,
8620x3f,0,0xc1,0xff,0x3e,0,0x10,0x1,0xb0,0xf8,0x50,0x9,0,0,0x7,0,
8630x3,0,0x78,0,0x78,0,0xf0,0,0x78,0,0,0,0,0,0,0,
8640,0,0,0,0,0,0,0,0x2,0,0,0,0,0,0,0,
8650x7e,0,0x1b,0,0x6b,0x34,0x1,0x7d,0x3,0x40,0x69,0x34,0x1,0x3c,0x3,0x40,
8660x7f,0x40,0,0,0,0,0xfe,0xfe,0,0,0,0,0,0xfe,0,0,
8670,0,0,0,0,0,0,0,0xb0,0xf8,0x50,0x9,0,0,0,0,
8680,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8690,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8700,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8710x1,0,0xb0,0xf8,0x50,0x9,0xb0,0xf8,0x50,0x9,0x20,0x20,0x2,0,0xb6,0x42,
8720,0x80,0x8a,0,0x6,0x3c,0xa,0x3c,0xff,0xff,0xc6,0x7,0,0x1,0,0x8,
8730xf0,0xf,0,0x10,0x2,0,0x30,0,0,0,0,0,0,0,0x6,0xfe,
8740,0,0x2,0,0x50,0,0x8a,0,0x4f,0x95,0,0,0x21,0,0xb,0,
8750,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8760,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8770,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8780,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8790,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8800,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8810,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8820,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8830,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8840,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8850,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
8860,0,0,0,0,0,0,0,0,0,0,0,0,0,0xa5,0x51,
887};
888
889static int inquiry_evpd_89(unsigned char * arr)
890{
891 memcpy(arr, vpd89_data, sizeof(vpd89_data));
892 return sizeof(vpd89_data);
893}
894
895
896static unsigned char vpdb0_data[] = {
897 /* from 4th byte */ 0,0,0,4,
898 0,0,0x4,0,
899 0,0,0,64,
900};
901
902static int inquiry_evpd_b0(unsigned char * arr)
903{
904 memcpy(arr, vpdb0_data, sizeof(vpdb0_data));
905 if (sdebug_store_sectors > 0x400) {
906 arr[4] = (sdebug_store_sectors >> 24) & 0xff;
907 arr[5] = (sdebug_store_sectors >> 16) & 0xff;
908 arr[6] = (sdebug_store_sectors >> 8) & 0xff;
909 arr[7] = sdebug_store_sectors & 0xff;
910 }
911 return sizeof(vpdb0_data);
599} 912}
600 913
601 914
602#define SDEBUG_LONG_INQ_SZ 96 915#define SDEBUG_LONG_INQ_SZ 96
603#define SDEBUG_MAX_INQ_ARR_SZ 128 916#define SDEBUG_MAX_INQ_ARR_SZ 584
604 917
605static int resp_inquiry(struct scsi_cmnd * scp, int target, 918static int resp_inquiry(struct scsi_cmnd * scp, int target,
606 struct sdebug_dev_info * devip) 919 struct sdebug_dev_info * devip)
@@ -608,64 +921,113 @@ static int resp_inquiry(struct scsi_cmnd * scp, int target,
608 unsigned char pq_pdt; 921 unsigned char pq_pdt;
609 unsigned char arr[SDEBUG_MAX_INQ_ARR_SZ]; 922 unsigned char arr[SDEBUG_MAX_INQ_ARR_SZ];
610 unsigned char *cmd = (unsigned char *)scp->cmnd; 923 unsigned char *cmd = (unsigned char *)scp->cmnd;
611 int alloc_len; 924 int alloc_len, n;
612 925
613 alloc_len = (cmd[3] << 8) + cmd[4]; 926 alloc_len = (cmd[3] << 8) + cmd[4];
614 memset(arr, 0, SDEBUG_MAX_INQ_ARR_SZ); 927 memset(arr, 0, SDEBUG_MAX_INQ_ARR_SZ);
615 pq_pdt = (scsi_debug_ptype & 0x1f); 928 if (devip->wlun)
929 pq_pdt = 0x1e; /* present, wlun */
930 else if (scsi_debug_no_lun_0 && (0 == devip->lun))
931 pq_pdt = 0x7f; /* not present, no device type */
932 else
933 pq_pdt = (scsi_debug_ptype & 0x1f);
616 arr[0] = pq_pdt; 934 arr[0] = pq_pdt;
617 if (0x2 & cmd[1]) { /* CMDDT bit set */ 935 if (0x2 & cmd[1]) { /* CMDDT bit set */
618 mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 936 mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
619 0); 937 0);
620 return check_condition_result; 938 return check_condition_result;
621 } else if (0x1 & cmd[1]) { /* EVPD bit set */ 939 } else if (0x1 & cmd[1]) { /* EVPD bit set */
622 int dev_id_num, len; 940 int lu_id_num, target_dev_id, len;
623 char dev_id_str[6]; 941 char lu_id_str[6];
942 int host_no = devip->sdbg_host->shost->host_no;
624 943
625 dev_id_num = ((devip->sdbg_host->shost->host_no + 1) * 2000) + 944 lu_id_num = devip->wlun ? -1 : (((host_no + 1) * 2000) +
626 (devip->target * 1000) + devip->lun; 945 (devip->target * 1000) + devip->lun);
627 len = scnprintf(dev_id_str, 6, "%d", dev_id_num); 946 target_dev_id = ((host_no + 1) * 2000) +
947 (devip->target * 1000) - 3;
948 len = scnprintf(lu_id_str, 6, "%d", lu_id_num);
628 if (0 == cmd[2]) { /* supported vital product data pages */ 949 if (0 == cmd[2]) { /* supported vital product data pages */
629 arr[3] = 3; 950 arr[1] = cmd[2]; /*sanity */
630 arr[4] = 0x0; /* this page */ 951 n = 4;
631 arr[5] = 0x80; /* unit serial number */ 952 arr[n++] = 0x0; /* this page */
632 arr[6] = 0x83; /* device identification */ 953 arr[n++] = 0x80; /* unit serial number */
954 arr[n++] = 0x83; /* device identification */
955 arr[n++] = 0x84; /* software interface ident. */
956 arr[n++] = 0x85; /* management network addresses */
957 arr[n++] = 0x86; /* extended inquiry */
958 arr[n++] = 0x87; /* mode page policy */
959 arr[n++] = 0x88; /* SCSI ports */
960 arr[n++] = 0x89; /* ATA information */
961 arr[n++] = 0xb0; /* Block limits (SBC) */
962 arr[3] = n - 4; /* number of supported VPD pages */
633 } else if (0x80 == cmd[2]) { /* unit serial number */ 963 } else if (0x80 == cmd[2]) { /* unit serial number */
634 arr[1] = 0x80; 964 arr[1] = cmd[2]; /*sanity */
635 arr[3] = len; 965 arr[3] = len;
636 memcpy(&arr[4], dev_id_str, len); 966 memcpy(&arr[4], lu_id_str, len);
637 } else if (0x83 == cmd[2]) { /* device identification */ 967 } else if (0x83 == cmd[2]) { /* device identification */
638 arr[1] = 0x83; 968 arr[1] = cmd[2]; /*sanity */
639 arr[3] = inquiry_evpd_83(&arr[4], dev_id_num, 969 arr[3] = inquiry_evpd_83(&arr[4], target_dev_id,
640 dev_id_str, len); 970 lu_id_num, lu_id_str, len);
971 } else if (0x84 == cmd[2]) { /* Software interface ident. */
972 arr[1] = cmd[2]; /*sanity */
973 arr[3] = inquiry_evpd_84(&arr[4]);
974 } else if (0x85 == cmd[2]) { /* Management network addresses */
975 arr[1] = cmd[2]; /*sanity */
976 arr[3] = inquiry_evpd_85(&arr[4]);
977 } else if (0x86 == cmd[2]) { /* extended inquiry */
978 arr[1] = cmd[2]; /*sanity */
979 arr[3] = 0x3c; /* number of following entries */
980 arr[4] = 0x0; /* no protection stuff */
981 arr[5] = 0x7; /* head of q, ordered + simple q's */
982 } else if (0x87 == cmd[2]) { /* mode page policy */
983 arr[1] = cmd[2]; /*sanity */
984 arr[3] = 0x8; /* number of following entries */
985 arr[4] = 0x2; /* disconnect-reconnect mp */
986 arr[6] = 0x80; /* mlus, shared */
987 arr[8] = 0x18; /* protocol specific lu */
988 arr[10] = 0x82; /* mlus, per initiator port */
989 } else if (0x88 == cmd[2]) { /* SCSI Ports */
990 arr[1] = cmd[2]; /*sanity */
991 arr[3] = inquiry_evpd_88(&arr[4], target_dev_id);
992 } else if (0x89 == cmd[2]) { /* ATA information */
993 arr[1] = cmd[2]; /*sanity */
994 n = inquiry_evpd_89(&arr[4]);
995 arr[2] = (n >> 8);
996 arr[3] = (n & 0xff);
997 } else if (0xb0 == cmd[2]) { /* Block limits (SBC) */
998 arr[1] = cmd[2]; /*sanity */
999 arr[3] = inquiry_evpd_b0(&arr[4]);
641 } else { 1000 } else {
642 /* Illegal request, invalid field in cdb */ 1001 /* Illegal request, invalid field in cdb */
643 mk_sense_buffer(devip, ILLEGAL_REQUEST, 1002 mk_sense_buffer(devip, ILLEGAL_REQUEST,
644 INVALID_FIELD_IN_CDB, 0); 1003 INVALID_FIELD_IN_CDB, 0);
645 return check_condition_result; 1004 return check_condition_result;
646 } 1005 }
1006 len = min(((arr[2] << 8) + arr[3]) + 4, alloc_len);
647 return fill_from_dev_buffer(scp, arr, 1007 return fill_from_dev_buffer(scp, arr,
648 min(alloc_len, SDEBUG_MAX_INQ_ARR_SZ)); 1008 min(len, SDEBUG_MAX_INQ_ARR_SZ));
649 } 1009 }
650 /* drops through here for a standard inquiry */ 1010 /* drops through here for a standard inquiry */
651 arr[1] = DEV_REMOVEABLE(target) ? 0x80 : 0; /* Removable disk */ 1011 arr[1] = DEV_REMOVEABLE(target) ? 0x80 : 0; /* Removable disk */
652 arr[2] = scsi_debug_scsi_level; 1012 arr[2] = scsi_debug_scsi_level;
653 arr[3] = 2; /* response_data_format==2 */ 1013 arr[3] = 2; /* response_data_format==2 */
654 arr[4] = SDEBUG_LONG_INQ_SZ - 5; 1014 arr[4] = SDEBUG_LONG_INQ_SZ - 5;
655 arr[6] = 0x1; /* claim: ADDR16 */ 1015 arr[6] = 0x10; /* claim: MultiP */
656 /* arr[6] |= 0x40; ... claim: EncServ (enclosure services) */ 1016 /* arr[6] |= 0x40; ... claim: EncServ (enclosure services) */
657 arr[7] = 0x3a; /* claim: WBUS16, SYNC, LINKED + CMDQUE */ 1017 arr[7] = 0xa; /* claim: LINKED + CMDQUE */
658 memcpy(&arr[8], inq_vendor_id, 8); 1018 memcpy(&arr[8], inq_vendor_id, 8);
659 memcpy(&arr[16], inq_product_id, 16); 1019 memcpy(&arr[16], inq_product_id, 16);
660 memcpy(&arr[32], inq_product_rev, 4); 1020 memcpy(&arr[32], inq_product_rev, 4);
661 /* version descriptors (2 bytes each) follow */ 1021 /* version descriptors (2 bytes each) follow */
662 arr[58] = 0x0; arr[59] = 0x40; /* SAM-2 */ 1022 arr[58] = 0x0; arr[59] = 0x77; /* SAM-3 ANSI */
663 arr[60] = 0x3; arr[61] = 0x0; /* SPC-3 */ 1023 arr[60] = 0x3; arr[61] = 0x14; /* SPC-3 ANSI */
1024 n = 62;
664 if (scsi_debug_ptype == 0) { 1025 if (scsi_debug_ptype == 0) {
665 arr[62] = 0x1; arr[63] = 0x80; /* SBC */ 1026 arr[n++] = 0x3; arr[n++] = 0x3d; /* SBC-2 ANSI */
666 } else if (scsi_debug_ptype == 1) { 1027 } else if (scsi_debug_ptype == 1) {
667 arr[62] = 0x2; arr[63] = 0x00; /* SSC */ 1028 arr[n++] = 0x3; arr[n++] = 0x60; /* SSC-2 no version */
668 } 1029 }
1030 arr[n++] = 0xc; arr[n++] = 0xf; /* SAS-1.1 rev 10 */
669 return fill_from_dev_buffer(scp, arr, 1031 return fill_from_dev_buffer(scp, arr,
670 min(alloc_len, SDEBUG_LONG_INQ_SZ)); 1032 min(alloc_len, SDEBUG_LONG_INQ_SZ));
671} 1033}
@@ -676,46 +1038,141 @@ static int resp_requests(struct scsi_cmnd * scp,
676 unsigned char * sbuff; 1038 unsigned char * sbuff;
677 unsigned char *cmd = (unsigned char *)scp->cmnd; 1039 unsigned char *cmd = (unsigned char *)scp->cmnd;
678 unsigned char arr[SDEBUG_SENSE_LEN]; 1040 unsigned char arr[SDEBUG_SENSE_LEN];
1041 int want_dsense;
679 int len = 18; 1042 int len = 18;
680 1043
681 memset(arr, 0, SDEBUG_SENSE_LEN); 1044 memset(arr, 0, sizeof(arr));
682 if (devip->reset == 1) 1045 if (devip->reset == 1)
683 mk_sense_buffer(devip, 0, NO_ADDED_SENSE, 0); 1046 mk_sense_buffer(devip, 0, NO_ADDITIONAL_SENSE, 0);
1047 want_dsense = !!(cmd[1] & 1) || scsi_debug_dsense;
684 sbuff = devip->sense_buff; 1048 sbuff = devip->sense_buff;
685 if ((cmd[1] & 1) && (! scsi_debug_dsense)) { 1049 if ((iec_m_pg[2] & 0x4) && (6 == (iec_m_pg[3] & 0xf))) {
686 /* DESC bit set and sense_buff in fixed format */ 1050 if (want_dsense) {
687 arr[0] = 0x72; 1051 arr[0] = 0x72;
688 arr[1] = sbuff[2]; /* sense key */ 1052 arr[1] = 0x0; /* NO_SENSE in sense_key */
689 arr[2] = sbuff[12]; /* asc */ 1053 arr[2] = THRESHOLD_EXCEEDED;
690 arr[3] = sbuff[13]; /* ascq */ 1054 arr[3] = 0xff; /* TEST set and MRIE==6 */
691 len = 8; 1055 } else {
692 } else 1056 arr[0] = 0x70;
1057 arr[2] = 0x0; /* NO_SENSE in sense_key */
1058 arr[7] = 0xa; /* 18 byte sense buffer */
1059 arr[12] = THRESHOLD_EXCEEDED;
1060 arr[13] = 0xff; /* TEST set and MRIE==6 */
1061 }
1062 } else if (devip->stopped) {
1063 if (want_dsense) {
1064 arr[0] = 0x72;
1065 arr[1] = 0x0; /* NO_SENSE in sense_key */
1066 arr[2] = LOW_POWER_COND_ON;
1067 arr[3] = 0x0; /* TEST set and MRIE==6 */
1068 } else {
1069 arr[0] = 0x70;
1070 arr[2] = 0x0; /* NO_SENSE in sense_key */
1071 arr[7] = 0xa; /* 18 byte sense buffer */
1072 arr[12] = LOW_POWER_COND_ON;
1073 arr[13] = 0x0; /* TEST set and MRIE==6 */
1074 }
1075 } else {
693 memcpy(arr, sbuff, SDEBUG_SENSE_LEN); 1076 memcpy(arr, sbuff, SDEBUG_SENSE_LEN);
694 mk_sense_buffer(devip, 0, NO_ADDED_SENSE, 0); 1077 if ((cmd[1] & 1) && (! scsi_debug_dsense)) {
1078 /* DESC bit set and sense_buff in fixed format */
1079 memset(arr, 0, sizeof(arr));
1080 arr[0] = 0x72;
1081 arr[1] = sbuff[2]; /* sense key */
1082 arr[2] = sbuff[12]; /* asc */
1083 arr[3] = sbuff[13]; /* ascq */
1084 len = 8;
1085 }
1086 }
1087 mk_sense_buffer(devip, 0, NO_ADDITIONAL_SENSE, 0);
695 return fill_from_dev_buffer(scp, arr, len); 1088 return fill_from_dev_buffer(scp, arr, len);
696} 1089}
697 1090
1091static int resp_start_stop(struct scsi_cmnd * scp,
1092 struct sdebug_dev_info * devip)
1093{
1094 unsigned char *cmd = (unsigned char *)scp->cmnd;
1095 int power_cond, errsts, start;
1096
1097 if ((errsts = check_readiness(scp, 1, devip)))
1098 return errsts;
1099 power_cond = (cmd[4] & 0xf0) >> 4;
1100 if (power_cond) {
1101 mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
1102 0);
1103 return check_condition_result;
1104 }
1105 start = cmd[4] & 1;
1106 if (start == devip->stopped)
1107 devip->stopped = !start;
1108 return 0;
1109}
1110
698#define SDEBUG_READCAP_ARR_SZ 8 1111#define SDEBUG_READCAP_ARR_SZ 8
699static int resp_readcap(struct scsi_cmnd * scp, 1112static int resp_readcap(struct scsi_cmnd * scp,
700 struct sdebug_dev_info * devip) 1113 struct sdebug_dev_info * devip)
701{ 1114{
702 unsigned char arr[SDEBUG_READCAP_ARR_SZ]; 1115 unsigned char arr[SDEBUG_READCAP_ARR_SZ];
703 unsigned long capac; 1116 unsigned int capac;
704 int errsts; 1117 int errsts;
705 1118
706 if ((errsts = check_reset(scp, devip))) 1119 if ((errsts = check_readiness(scp, 1, devip)))
707 return errsts; 1120 return errsts;
1121 /* following just in case virtual_gb changed */
1122 if (scsi_debug_virtual_gb > 0) {
1123 sdebug_capacity = 2048 * 1024;
1124 sdebug_capacity *= scsi_debug_virtual_gb;
1125 } else
1126 sdebug_capacity = sdebug_store_sectors;
708 memset(arr, 0, SDEBUG_READCAP_ARR_SZ); 1127 memset(arr, 0, SDEBUG_READCAP_ARR_SZ);
709 capac = (unsigned long)sdebug_capacity - 1; 1128 if (sdebug_capacity < 0xffffffff) {
710 arr[0] = (capac >> 24); 1129 capac = (unsigned int)sdebug_capacity - 1;
711 arr[1] = (capac >> 16) & 0xff; 1130 arr[0] = (capac >> 24);
712 arr[2] = (capac >> 8) & 0xff; 1131 arr[1] = (capac >> 16) & 0xff;
713 arr[3] = capac & 0xff; 1132 arr[2] = (capac >> 8) & 0xff;
1133 arr[3] = capac & 0xff;
1134 } else {
1135 arr[0] = 0xff;
1136 arr[1] = 0xff;
1137 arr[2] = 0xff;
1138 arr[3] = 0xff;
1139 }
714 arr[6] = (SECT_SIZE_PER(target) >> 8) & 0xff; 1140 arr[6] = (SECT_SIZE_PER(target) >> 8) & 0xff;
715 arr[7] = SECT_SIZE_PER(target) & 0xff; 1141 arr[7] = SECT_SIZE_PER(target) & 0xff;
716 return fill_from_dev_buffer(scp, arr, SDEBUG_READCAP_ARR_SZ); 1142 return fill_from_dev_buffer(scp, arr, SDEBUG_READCAP_ARR_SZ);
717} 1143}
718 1144
1145#define SDEBUG_READCAP16_ARR_SZ 32
1146static int resp_readcap16(struct scsi_cmnd * scp,
1147 struct sdebug_dev_info * devip)
1148{
1149 unsigned char *cmd = (unsigned char *)scp->cmnd;
1150 unsigned char arr[SDEBUG_READCAP16_ARR_SZ];
1151 unsigned long long capac;
1152 int errsts, k, alloc_len;
1153
1154 if ((errsts = check_readiness(scp, 1, devip)))
1155 return errsts;
1156 alloc_len = ((cmd[10] << 24) + (cmd[11] << 16) + (cmd[12] << 8)
1157 + cmd[13]);
1158 /* following just in case virtual_gb changed */
1159 if (scsi_debug_virtual_gb > 0) {
1160 sdebug_capacity = 2048 * 1024;
1161 sdebug_capacity *= scsi_debug_virtual_gb;
1162 } else
1163 sdebug_capacity = sdebug_store_sectors;
1164 memset(arr, 0, SDEBUG_READCAP16_ARR_SZ);
1165 capac = sdebug_capacity - 1;
1166 for (k = 0; k < 8; ++k, capac >>= 8)
1167 arr[7 - k] = capac & 0xff;
1168 arr[8] = (SECT_SIZE_PER(target) >> 24) & 0xff;
1169 arr[9] = (SECT_SIZE_PER(target) >> 16) & 0xff;
1170 arr[10] = (SECT_SIZE_PER(target) >> 8) & 0xff;
1171 arr[11] = SECT_SIZE_PER(target) & 0xff;
1172 return fill_from_dev_buffer(scp, arr,
1173 min(alloc_len, SDEBUG_READCAP16_ARR_SZ));
1174}
1175
719/* <<Following mode page info copied from ST318451LW>> */ 1176/* <<Following mode page info copied from ST318451LW>> */
720 1177
721static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target) 1178static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target)
@@ -771,27 +1228,98 @@ static int resp_caching_pg(unsigned char * p, int pcontrol, int target)
771 1228
772static int resp_ctrl_m_pg(unsigned char * p, int pcontrol, int target) 1229static int resp_ctrl_m_pg(unsigned char * p, int pcontrol, int target)
773{ /* Control mode page for mode_sense */ 1230{ /* Control mode page for mode_sense */
774 unsigned char ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, 1231 unsigned char ch_ctrl_m_pg[] = {/* 0xa, 10, */ 0x6, 0, 0, 0, 0, 0,
1232 0, 0, 0, 0};
1233 unsigned char d_ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0,
775 0, 0, 0x2, 0x4b}; 1234 0, 0, 0x2, 0x4b};
776 1235
777 if (scsi_debug_dsense) 1236 if (scsi_debug_dsense)
778 ctrl_m_pg[2] |= 0x4; 1237 ctrl_m_pg[2] |= 0x4;
1238 else
1239 ctrl_m_pg[2] &= ~0x4;
779 memcpy(p, ctrl_m_pg, sizeof(ctrl_m_pg)); 1240 memcpy(p, ctrl_m_pg, sizeof(ctrl_m_pg));
780 if (1 == pcontrol) 1241 if (1 == pcontrol)
781 memset(p + 2, 0, sizeof(ctrl_m_pg) - 2); 1242 memcpy(p + 2, ch_ctrl_m_pg, sizeof(ch_ctrl_m_pg));
1243 else if (2 == pcontrol)
1244 memcpy(p, d_ctrl_m_pg, sizeof(d_ctrl_m_pg));
782 return sizeof(ctrl_m_pg); 1245 return sizeof(ctrl_m_pg);
783} 1246}
784 1247
1248
785static int resp_iec_m_pg(unsigned char * p, int pcontrol, int target) 1249static int resp_iec_m_pg(unsigned char * p, int pcontrol, int target)
786{ /* Informational Exceptions control mode page for mode_sense */ 1250{ /* Informational Exceptions control mode page for mode_sense */
787 unsigned char iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0, 1251 unsigned char ch_iec_m_pg[] = {/* 0x1c, 0xa, */ 0x4, 0xf, 0, 0, 0, 0,
788 0, 0, 0x0, 0x0}; 1252 0, 0, 0x0, 0x0};
1253 unsigned char d_iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0,
1254 0, 0, 0x0, 0x0};
1255
789 memcpy(p, iec_m_pg, sizeof(iec_m_pg)); 1256 memcpy(p, iec_m_pg, sizeof(iec_m_pg));
790 if (1 == pcontrol) 1257 if (1 == pcontrol)
791 memset(p + 2, 0, sizeof(iec_m_pg) - 2); 1258 memcpy(p + 2, ch_iec_m_pg, sizeof(ch_iec_m_pg));
1259 else if (2 == pcontrol)
1260 memcpy(p, d_iec_m_pg, sizeof(d_iec_m_pg));
792 return sizeof(iec_m_pg); 1261 return sizeof(iec_m_pg);
793} 1262}
794 1263
1264static int resp_sas_sf_m_pg(unsigned char * p, int pcontrol, int target)
1265{ /* SAS SSP mode page - short format for mode_sense */
1266 unsigned char sas_sf_m_pg[] = {0x19, 0x6,
1267 0x6, 0x0, 0x7, 0xd0, 0x0, 0x0};
1268
1269 memcpy(p, sas_sf_m_pg, sizeof(sas_sf_m_pg));
1270 if (1 == pcontrol)
1271 memset(p + 2, 0, sizeof(sas_sf_m_pg) - 2);
1272 return sizeof(sas_sf_m_pg);
1273}
1274
1275
1276static int resp_sas_pcd_m_spg(unsigned char * p, int pcontrol, int target,
1277 int target_dev_id)
1278{ /* SAS phy control and discover mode page for mode_sense */
1279 unsigned char sas_pcd_m_pg[] = {0x59, 0x1, 0, 0x64, 0, 0x6, 0, 2,
1280 0, 0, 0, 0, 0x10, 0x9, 0x8, 0x0,
1281 0x52, 0x22, 0x22, 0x20, 0x0, 0x0, 0x0, 0x0,
1282 0x51, 0x11, 0x11, 0x10, 0x0, 0x0, 0x0, 0x1,
1283 0x2, 0, 0, 0, 0, 0, 0, 0,
1284 0x88, 0x99, 0, 0, 0, 0, 0, 0,
1285 0, 0, 0, 0, 0, 0, 0, 0,
1286 0, 1, 0, 0, 0x10, 0x9, 0x8, 0x0,
1287 0x52, 0x22, 0x22, 0x20, 0x0, 0x0, 0x0, 0x0,
1288 0x51, 0x11, 0x11, 0x10, 0x0, 0x0, 0x0, 0x1,
1289 0x3, 0, 0, 0, 0, 0, 0, 0,
1290 0x88, 0x99, 0, 0, 0, 0, 0, 0,
1291 0, 0, 0, 0, 0, 0, 0, 0,
1292 };
1293 int port_a, port_b;
1294
1295 port_a = target_dev_id + 1;
1296 port_b = port_a + 1;
1297 memcpy(p, sas_pcd_m_pg, sizeof(sas_pcd_m_pg));
1298 p[20] = (port_a >> 24);
1299 p[21] = (port_a >> 16) & 0xff;
1300 p[22] = (port_a >> 8) & 0xff;
1301 p[23] = port_a & 0xff;
1302 p[48 + 20] = (port_b >> 24);
1303 p[48 + 21] = (port_b >> 16) & 0xff;
1304 p[48 + 22] = (port_b >> 8) & 0xff;
1305 p[48 + 23] = port_b & 0xff;
1306 if (1 == pcontrol)
1307 memset(p + 4, 0, sizeof(sas_pcd_m_pg) - 4);
1308 return sizeof(sas_pcd_m_pg);
1309}
1310
1311static int resp_sas_sha_m_spg(unsigned char * p, int pcontrol)
1312{ /* SAS SSP shared protocol specific port mode subpage */
1313 unsigned char sas_sha_m_pg[] = {0x59, 0x2, 0, 0xc, 0, 0x6, 0x10, 0,
1314 0, 0, 0, 0, 0, 0, 0, 0,
1315 };
1316
1317 memcpy(p, sas_sha_m_pg, sizeof(sas_sha_m_pg));
1318 if (1 == pcontrol)
1319 memset(p + 4, 0, sizeof(sas_sha_m_pg) - 4);
1320 return sizeof(sas_sha_m_pg);
1321}
1322
795#define SDEBUG_MAX_MSENSE_SZ 256 1323#define SDEBUG_MAX_MSENSE_SZ 256
796 1324
797static int resp_mode_sense(struct scsi_cmnd * scp, int target, 1325static int resp_mode_sense(struct scsi_cmnd * scp, int target,
@@ -800,12 +1328,12 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target,
800 unsigned char dbd; 1328 unsigned char dbd;
801 int pcontrol, pcode, subpcode; 1329 int pcontrol, pcode, subpcode;
802 unsigned char dev_spec; 1330 unsigned char dev_spec;
803 int alloc_len, msense_6, offset, len, errsts; 1331 int alloc_len, msense_6, offset, len, errsts, target_dev_id;
804 unsigned char * ap; 1332 unsigned char * ap;
805 unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; 1333 unsigned char arr[SDEBUG_MAX_MSENSE_SZ];
806 unsigned char *cmd = (unsigned char *)scp->cmnd; 1334 unsigned char *cmd = (unsigned char *)scp->cmnd;
807 1335
808 if ((errsts = check_reset(scp, devip))) 1336 if ((errsts = check_readiness(scp, 1, devip)))
809 return errsts; 1337 return errsts;
810 dbd = cmd[1] & 0x8; 1338 dbd = cmd[1] & 0x8;
811 pcontrol = (cmd[2] & 0xc0) >> 6; 1339 pcontrol = (cmd[2] & 0xc0) >> 6;
@@ -819,6 +1347,8 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target,
819 0); 1347 0);
820 return check_condition_result; 1348 return check_condition_result;
821 } 1349 }
1350 target_dev_id = ((devip->sdbg_host->shost->host_no + 1) * 2000) +
1351 (devip->target * 1000) - 3;
822 dev_spec = DEV_READONLY(target) ? 0x80 : 0x0; 1352 dev_spec = DEV_READONLY(target) ? 0x80 : 0x0;
823 if (msense_6) { 1353 if (msense_6) {
824 arr[2] = dev_spec; 1354 arr[2] = dev_spec;
@@ -829,7 +1359,8 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target,
829 } 1359 }
830 ap = arr + offset; 1360 ap = arr + offset;
831 1361
832 if (0 != subpcode) { /* TODO: Control Extension page */ 1362 if ((subpcode > 0x0) && (subpcode < 0xff) && (0x19 != pcode)) {
1363 /* TODO: Control Extension page */
833 mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 1364 mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
834 0); 1365 0);
835 return check_condition_result; 1366 return check_condition_result;
@@ -855,17 +1386,45 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target,
855 len = resp_ctrl_m_pg(ap, pcontrol, target); 1386 len = resp_ctrl_m_pg(ap, pcontrol, target);
856 offset += len; 1387 offset += len;
857 break; 1388 break;
1389 case 0x19: /* if spc==1 then sas phy, control+discover */
1390 if ((subpcode > 0x2) && (subpcode < 0xff)) {
1391 mk_sense_buffer(devip, ILLEGAL_REQUEST,
1392 INVALID_FIELD_IN_CDB, 0);
1393 return check_condition_result;
1394 }
1395 len = 0;
1396 if ((0x0 == subpcode) || (0xff == subpcode))
1397 len += resp_sas_sf_m_pg(ap + len, pcontrol, target);
1398 if ((0x1 == subpcode) || (0xff == subpcode))
1399 len += resp_sas_pcd_m_spg(ap + len, pcontrol, target,
1400 target_dev_id);
1401 if ((0x2 == subpcode) || (0xff == subpcode))
1402 len += resp_sas_sha_m_spg(ap + len, pcontrol);
1403 offset += len;
1404 break;
858 case 0x1c: /* Informational Exceptions Mode page, all devices */ 1405 case 0x1c: /* Informational Exceptions Mode page, all devices */
859 len = resp_iec_m_pg(ap, pcontrol, target); 1406 len = resp_iec_m_pg(ap, pcontrol, target);
860 offset += len; 1407 offset += len;
861 break; 1408 break;
862 case 0x3f: /* Read all Mode pages */ 1409 case 0x3f: /* Read all Mode pages */
863 len = resp_err_recov_pg(ap, pcontrol, target); 1410 if ((0 == subpcode) || (0xff == subpcode)) {
864 len += resp_disconnect_pg(ap + len, pcontrol, target); 1411 len = resp_err_recov_pg(ap, pcontrol, target);
865 len += resp_format_pg(ap + len, pcontrol, target); 1412 len += resp_disconnect_pg(ap + len, pcontrol, target);
866 len += resp_caching_pg(ap + len, pcontrol, target); 1413 len += resp_format_pg(ap + len, pcontrol, target);
867 len += resp_ctrl_m_pg(ap + len, pcontrol, target); 1414 len += resp_caching_pg(ap + len, pcontrol, target);
868 len += resp_iec_m_pg(ap + len, pcontrol, target); 1415 len += resp_ctrl_m_pg(ap + len, pcontrol, target);
1416 len += resp_sas_sf_m_pg(ap + len, pcontrol, target);
1417 if (0xff == subpcode) {
1418 len += resp_sas_pcd_m_spg(ap + len, pcontrol,
1419 target, target_dev_id);
1420 len += resp_sas_sha_m_spg(ap + len, pcontrol);
1421 }
1422 len += resp_iec_m_pg(ap + len, pcontrol, target);
1423 } else {
1424 mk_sense_buffer(devip, ILLEGAL_REQUEST,
1425 INVALID_FIELD_IN_CDB, 0);
1426 return check_condition_result;
1427 }
869 offset += len; 1428 offset += len;
870 break; 1429 break;
871 default: 1430 default:
@@ -882,71 +1441,274 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target,
882 return fill_from_dev_buffer(scp, arr, min(alloc_len, offset)); 1441 return fill_from_dev_buffer(scp, arr, min(alloc_len, offset));
883} 1442}
884 1443
885static int resp_read(struct scsi_cmnd * SCpnt, int upper_blk, int block, 1444#define SDEBUG_MAX_MSELECT_SZ 512
886 int num, struct sdebug_dev_info * devip) 1445
1446static int resp_mode_select(struct scsi_cmnd * scp, int mselect6,
1447 struct sdebug_dev_info * devip)
1448{
1449 int pf, sp, ps, md_len, bd_len, off, spf, pg_len;
1450 int param_len, res, errsts, mpage;
1451 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
1452 unsigned char *cmd = (unsigned char *)scp->cmnd;
1453
1454 if ((errsts = check_readiness(scp, 1, devip)))
1455 return errsts;
1456 memset(arr, 0, sizeof(arr));
1457 pf = cmd[1] & 0x10;
1458 sp = cmd[1] & 0x1;
1459 param_len = mselect6 ? cmd[4] : ((cmd[7] << 8) + cmd[8]);
1460 if ((0 == pf) || sp || (param_len > SDEBUG_MAX_MSELECT_SZ)) {
1461 mk_sense_buffer(devip, ILLEGAL_REQUEST,
1462 INVALID_FIELD_IN_CDB, 0);
1463 return check_condition_result;
1464 }
1465 res = fetch_to_dev_buffer(scp, arr, param_len);
1466 if (-1 == res)
1467 return (DID_ERROR << 16);
1468 else if ((res < param_len) &&
1469 (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts))
1470 printk(KERN_INFO "scsi_debug: mode_select: cdb indicated=%d, "
1471 " IO sent=%d bytes\n", param_len, res);
1472 md_len = mselect6 ? (arr[0] + 1) : ((arr[0] << 8) + arr[1] + 2);
1473 bd_len = mselect6 ? arr[3] : ((arr[6] << 8) + arr[7]);
1474 if ((md_len > 2) || (0 != bd_len)) {
1475 mk_sense_buffer(devip, ILLEGAL_REQUEST,
1476 INVALID_FIELD_IN_PARAM_LIST, 0);
1477 return check_condition_result;
1478 }
1479 off = bd_len + (mselect6 ? 4 : 8);
1480 mpage = arr[off] & 0x3f;
1481 ps = !!(arr[off] & 0x80);
1482 if (ps) {
1483 mk_sense_buffer(devip, ILLEGAL_REQUEST,
1484 INVALID_FIELD_IN_PARAM_LIST, 0);
1485 return check_condition_result;
1486 }
1487 spf = !!(arr[off] & 0x40);
1488 pg_len = spf ? ((arr[off + 2] << 8) + arr[off + 3] + 4) :
1489 (arr[off + 1] + 2);
1490 if ((pg_len + off) > param_len) {
1491 mk_sense_buffer(devip, ILLEGAL_REQUEST,
1492 PARAMETER_LIST_LENGTH_ERR, 0);
1493 return check_condition_result;
1494 }
1495 switch (mpage) {
1496 case 0xa: /* Control Mode page */
1497 if (ctrl_m_pg[1] == arr[off + 1]) {
1498 memcpy(ctrl_m_pg + 2, arr + off + 2,
1499 sizeof(ctrl_m_pg) - 2);
1500 scsi_debug_dsense = !!(ctrl_m_pg[2] & 0x4);
1501 return 0;
1502 }
1503 break;
1504 case 0x1c: /* Informational Exceptions Mode page */
1505 if (iec_m_pg[1] == arr[off + 1]) {
1506 memcpy(iec_m_pg + 2, arr + off + 2,
1507 sizeof(iec_m_pg) - 2);
1508 return 0;
1509 }
1510 break;
1511 default:
1512 break;
1513 }
1514 mk_sense_buffer(devip, ILLEGAL_REQUEST,
1515 INVALID_FIELD_IN_PARAM_LIST, 0);
1516 return check_condition_result;
1517}
1518
1519static int resp_temp_l_pg(unsigned char * arr)
1520{
1521 unsigned char temp_l_pg[] = {0x0, 0x0, 0x3, 0x2, 0x0, 38,
1522 0x0, 0x1, 0x3, 0x2, 0x0, 65,
1523 };
1524
1525 memcpy(arr, temp_l_pg, sizeof(temp_l_pg));
1526 return sizeof(temp_l_pg);
1527}
1528
1529static int resp_ie_l_pg(unsigned char * arr)
1530{
1531 unsigned char ie_l_pg[] = {0x0, 0x0, 0x3, 0x3, 0x0, 0x0, 38,
1532 };
1533
1534 memcpy(arr, ie_l_pg, sizeof(ie_l_pg));
1535 if (iec_m_pg[2] & 0x4) { /* TEST bit set */
1536 arr[4] = THRESHOLD_EXCEEDED;
1537 arr[5] = 0xff;
1538 }
1539 return sizeof(ie_l_pg);
1540}
1541
1542#define SDEBUG_MAX_LSENSE_SZ 512
1543
1544static int resp_log_sense(struct scsi_cmnd * scp,
1545 struct sdebug_dev_info * devip)
1546{
1547 int ppc, sp, pcontrol, pcode, alloc_len, errsts, len, n;
1548 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
1549 unsigned char *cmd = (unsigned char *)scp->cmnd;
1550
1551 if ((errsts = check_readiness(scp, 1, devip)))
1552 return errsts;
1553 memset(arr, 0, sizeof(arr));
1554 ppc = cmd[1] & 0x2;
1555 sp = cmd[1] & 0x1;
1556 if (ppc || sp) {
1557 mk_sense_buffer(devip, ILLEGAL_REQUEST,
1558 INVALID_FIELD_IN_CDB, 0);
1559 return check_condition_result;
1560 }
1561 pcontrol = (cmd[2] & 0xc0) >> 6;
1562 pcode = cmd[2] & 0x3f;
1563 alloc_len = (cmd[7] << 8) + cmd[8];
1564 arr[0] = pcode;
1565 switch (pcode) {
1566 case 0x0: /* Supported log pages log page */
1567 n = 4;
1568 arr[n++] = 0x0; /* this page */
1569 arr[n++] = 0xd; /* Temperature */
1570 arr[n++] = 0x2f; /* Informational exceptions */
1571 arr[3] = n - 4;
1572 break;
1573 case 0xd: /* Temperature log page */
1574 arr[3] = resp_temp_l_pg(arr + 4);
1575 break;
1576 case 0x2f: /* Informational exceptions log page */
1577 arr[3] = resp_ie_l_pg(arr + 4);
1578 break;
1579 default:
1580 mk_sense_buffer(devip, ILLEGAL_REQUEST,
1581 INVALID_FIELD_IN_CDB, 0);
1582 return check_condition_result;
1583 }
1584 len = min(((arr[2] << 8) + arr[3]) + 4, alloc_len);
1585 return fill_from_dev_buffer(scp, arr,
1586 min(len, SDEBUG_MAX_INQ_ARR_SZ));
1587}
1588
1589static int resp_read(struct scsi_cmnd * SCpnt, unsigned long long lba,
1590 unsigned int num, struct sdebug_dev_info * devip)
887{ 1591{
888 unsigned long iflags; 1592 unsigned long iflags;
1593 unsigned int block, from_bottom;
1594 unsigned long long u;
889 int ret; 1595 int ret;
890 1596
891 if (upper_blk || (block + num > sdebug_capacity)) { 1597 if (lba + num > sdebug_capacity) {
892 mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, 1598 mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE,
893 0); 1599 0);
894 return check_condition_result; 1600 return check_condition_result;
895 } 1601 }
1602 /* transfer length excessive (tie in to block limits VPD page) */
1603 if (num > sdebug_store_sectors) {
1604 mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
1605 0);
1606 return check_condition_result;
1607 }
896 if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) && 1608 if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) &&
897 (block <= OPT_MEDIUM_ERR_ADDR) && 1609 (lba <= OPT_MEDIUM_ERR_ADDR) &&
898 ((block + num) > OPT_MEDIUM_ERR_ADDR)) { 1610 ((lba + num) > OPT_MEDIUM_ERR_ADDR)) {
1611 /* claim unrecoverable read error */
899 mk_sense_buffer(devip, MEDIUM_ERROR, UNRECOVERED_READ_ERR, 1612 mk_sense_buffer(devip, MEDIUM_ERROR, UNRECOVERED_READ_ERR,
900 0); 1613 0);
901 /* claim unrecoverable read error */ 1614 /* set info field and valid bit for fixed descriptor */
1615 if (0x70 == (devip->sense_buff[0] & 0x7f)) {
1616 devip->sense_buff[0] |= 0x80; /* Valid bit */
1617 ret = OPT_MEDIUM_ERR_ADDR;
1618 devip->sense_buff[3] = (ret >> 24) & 0xff;
1619 devip->sense_buff[4] = (ret >> 16) & 0xff;
1620 devip->sense_buff[5] = (ret >> 8) & 0xff;
1621 devip->sense_buff[6] = ret & 0xff;
1622 }
902 return check_condition_result; 1623 return check_condition_result;
903 } 1624 }
904 read_lock_irqsave(&atomic_rw, iflags); 1625 read_lock_irqsave(&atomic_rw, iflags);
905 ret = fill_from_dev_buffer(SCpnt, fake_storep + (block * SECT_SIZE), 1626 if ((lba + num) <= sdebug_store_sectors)
906 num * SECT_SIZE); 1627 ret = fill_from_dev_buffer(SCpnt,
1628 fake_storep + (lba * SECT_SIZE),
1629 num * SECT_SIZE);
1630 else {
1631 /* modulo when one arg is 64 bits needs do_div() */
1632 u = lba;
1633 block = do_div(u, sdebug_store_sectors);
1634 from_bottom = 0;
1635 if ((block + num) > sdebug_store_sectors)
1636 from_bottom = (block + num) - sdebug_store_sectors;
1637 ret = fill_from_dev_buffer(SCpnt,
1638 fake_storep + (block * SECT_SIZE),
1639 (num - from_bottom) * SECT_SIZE);
1640 if ((0 == ret) && (from_bottom > 0))
1641 ret = fill_from_dev_buffer(SCpnt, fake_storep,
1642 from_bottom * SECT_SIZE);
1643 }
907 read_unlock_irqrestore(&atomic_rw, iflags); 1644 read_unlock_irqrestore(&atomic_rw, iflags);
908 return ret; 1645 return ret;
909} 1646}
910 1647
911static int resp_write(struct scsi_cmnd * SCpnt, int upper_blk, int block, 1648static int resp_write(struct scsi_cmnd * SCpnt, unsigned long long lba,
912 int num, struct sdebug_dev_info * devip) 1649 unsigned int num, struct sdebug_dev_info * devip)
913{ 1650{
914 unsigned long iflags; 1651 unsigned long iflags;
1652 unsigned int block, to_bottom;
1653 unsigned long long u;
915 int res; 1654 int res;
916 1655
917 if (upper_blk || (block + num > sdebug_capacity)) { 1656 if (lba + num > sdebug_capacity) {
918 mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, 1657 mk_sense_buffer(devip, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE,
919 0); 1658 0);
920 return check_condition_result; 1659 return check_condition_result;
921 } 1660 }
1661 /* transfer length excessive (tie in to block limits VPD page) */
1662 if (num > sdebug_store_sectors) {
1663 mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
1664 0);
1665 return check_condition_result;
1666 }
922 1667
923 write_lock_irqsave(&atomic_rw, iflags); 1668 write_lock_irqsave(&atomic_rw, iflags);
924 res = fetch_to_dev_buffer(SCpnt, fake_storep + (block * SECT_SIZE), 1669 if ((lba + num) <= sdebug_store_sectors)
925 num * SECT_SIZE); 1670 res = fetch_to_dev_buffer(SCpnt,
1671 fake_storep + (lba * SECT_SIZE),
1672 num * SECT_SIZE);
1673 else {
1674 /* modulo when one arg is 64 bits needs do_div() */
1675 u = lba;
1676 block = do_div(u, sdebug_store_sectors);
1677 to_bottom = 0;
1678 if ((block + num) > sdebug_store_sectors)
1679 to_bottom = (block + num) - sdebug_store_sectors;
1680 res = fetch_to_dev_buffer(SCpnt,
1681 fake_storep + (block * SECT_SIZE),
1682 (num - to_bottom) * SECT_SIZE);
1683 if ((0 == res) && (to_bottom > 0))
1684 res = fetch_to_dev_buffer(SCpnt, fake_storep,
1685 to_bottom * SECT_SIZE);
1686 }
926 write_unlock_irqrestore(&atomic_rw, iflags); 1687 write_unlock_irqrestore(&atomic_rw, iflags);
927 if (-1 == res) 1688 if (-1 == res)
928 return (DID_ERROR << 16); 1689 return (DID_ERROR << 16);
929 else if ((res < (num * SECT_SIZE)) && 1690 else if ((res < (num * SECT_SIZE)) &&
930 (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)) 1691 (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts))
931 printk(KERN_INFO "scsi_debug: write: cdb indicated=%d, " 1692 printk(KERN_INFO "scsi_debug: write: cdb indicated=%u, "
932 " IO sent=%d bytes\n", num * SECT_SIZE, res); 1693 " IO sent=%d bytes\n", num * SECT_SIZE, res);
933 return 0; 1694 return 0;
934} 1695}
935 1696
936#define SDEBUG_RLUN_ARR_SZ 128 1697#define SDEBUG_RLUN_ARR_SZ 256
937 1698
938static int resp_report_luns(struct scsi_cmnd * scp, 1699static int resp_report_luns(struct scsi_cmnd * scp,
939 struct sdebug_dev_info * devip) 1700 struct sdebug_dev_info * devip)
940{ 1701{
941 unsigned int alloc_len; 1702 unsigned int alloc_len;
942 int lun_cnt, i, upper; 1703 int lun_cnt, i, upper, num, n, wlun, lun;
943 unsigned char *cmd = (unsigned char *)scp->cmnd; 1704 unsigned char *cmd = (unsigned char *)scp->cmnd;
944 int select_report = (int)cmd[2]; 1705 int select_report = (int)cmd[2];
945 struct scsi_lun *one_lun; 1706 struct scsi_lun *one_lun;
946 unsigned char arr[SDEBUG_RLUN_ARR_SZ]; 1707 unsigned char arr[SDEBUG_RLUN_ARR_SZ];
1708 unsigned char * max_addr;
947 1709
948 alloc_len = cmd[9] + (cmd[8] << 8) + (cmd[7] << 16) + (cmd[6] << 24); 1710 alloc_len = cmd[9] + (cmd[8] << 8) + (cmd[7] << 16) + (cmd[6] << 24);
949 if ((alloc_len < 16) || (select_report > 2)) { 1711 if ((alloc_len < 4) || (select_report > 2)) {
950 mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 1712 mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
951 0); 1713 0);
952 return check_condition_result; 1714 return check_condition_result;
@@ -954,18 +1716,37 @@ static int resp_report_luns(struct scsi_cmnd * scp,
954 /* can produce response with up to 16k luns (lun 0 to lun 16383) */ 1716 /* can produce response with up to 16k luns (lun 0 to lun 16383) */
955 memset(arr, 0, SDEBUG_RLUN_ARR_SZ); 1717 memset(arr, 0, SDEBUG_RLUN_ARR_SZ);
956 lun_cnt = scsi_debug_max_luns; 1718 lun_cnt = scsi_debug_max_luns;
957 arr[2] = ((sizeof(struct scsi_lun) * lun_cnt) >> 8) & 0xff; 1719 if (1 == select_report)
958 arr[3] = (sizeof(struct scsi_lun) * lun_cnt) & 0xff; 1720 lun_cnt = 0;
959 lun_cnt = min((int)((SDEBUG_RLUN_ARR_SZ - 8) / 1721 else if (scsi_debug_no_lun_0 && (lun_cnt > 0))
960 sizeof(struct scsi_lun)), lun_cnt); 1722 --lun_cnt;
1723 wlun = (select_report > 0) ? 1 : 0;
1724 num = lun_cnt + wlun;
1725 arr[2] = ((sizeof(struct scsi_lun) * num) >> 8) & 0xff;
1726 arr[3] = (sizeof(struct scsi_lun) * num) & 0xff;
1727 n = min((int)((SDEBUG_RLUN_ARR_SZ - 8) /
1728 sizeof(struct scsi_lun)), num);
1729 if (n < num) {
1730 wlun = 0;
1731 lun_cnt = n;
1732 }
961 one_lun = (struct scsi_lun *) &arr[8]; 1733 one_lun = (struct scsi_lun *) &arr[8];
962 for (i = 0; i < lun_cnt; i++) { 1734 max_addr = arr + SDEBUG_RLUN_ARR_SZ;
963 upper = (i >> 8) & 0x3f; 1735 for (i = 0, lun = (scsi_debug_no_lun_0 ? 1 : 0);
1736 ((i < lun_cnt) && ((unsigned char *)(one_lun + i) < max_addr));
1737 i++, lun++) {
1738 upper = (lun >> 8) & 0x3f;
964 if (upper) 1739 if (upper)
965 one_lun[i].scsi_lun[0] = 1740 one_lun[i].scsi_lun[0] =
966 (upper | (SAM2_LUN_ADDRESS_METHOD << 6)); 1741 (upper | (SAM2_LUN_ADDRESS_METHOD << 6));
967 one_lun[i].scsi_lun[1] = i & 0xff; 1742 one_lun[i].scsi_lun[1] = lun & 0xff;
968 } 1743 }
1744 if (wlun) {
1745 one_lun[i].scsi_lun[0] = (SAM2_WLUN_REPORT_LUNS >> 8) & 0xff;
1746 one_lun[i].scsi_lun[1] = SAM2_WLUN_REPORT_LUNS & 0xff;
1747 i++;
1748 }
1749 alloc_len = (unsigned char *)(one_lun + i) - arr;
969 return fill_from_dev_buffer(scp, arr, 1750 return fill_from_dev_buffer(scp, arr,
970 min((int)alloc_len, SDEBUG_RLUN_ARR_SZ)); 1751 min((int)alloc_len, SDEBUG_RLUN_ARR_SZ));
971} 1752}
@@ -1001,7 +1782,8 @@ static void timer_intr_handler(unsigned long indx)
1001static int scsi_debug_slave_alloc(struct scsi_device * sdp) 1782static int scsi_debug_slave_alloc(struct scsi_device * sdp)
1002{ 1783{
1003 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 1784 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
1004 sdev_printk(KERN_INFO, sdp, "scsi_debug: slave_alloc\n"); 1785 printk(KERN_INFO "scsi_debug: slave_alloc <%u %u %u %u>\n",
1786 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
1005 return 0; 1787 return 0;
1006} 1788}
1007 1789
@@ -1010,7 +1792,8 @@ static int scsi_debug_slave_configure(struct scsi_device * sdp)
1010 struct sdebug_dev_info * devip; 1792 struct sdebug_dev_info * devip;
1011 1793
1012 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 1794 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
1013 sdev_printk(KERN_INFO, sdp, "scsi_debug: slave_configure\n"); 1795 printk(KERN_INFO "scsi_debug: slave_configure <%u %u %u %u>\n",
1796 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
1014 if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN) 1797 if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN)
1015 sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN; 1798 sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN;
1016 devip = devInfoReg(sdp); 1799 devip = devInfoReg(sdp);
@@ -1018,6 +1801,7 @@ static int scsi_debug_slave_configure(struct scsi_device * sdp)
1018 if (sdp->host->cmd_per_lun) 1801 if (sdp->host->cmd_per_lun)
1019 scsi_adjust_queue_depth(sdp, SDEBUG_TAGGED_QUEUING, 1802 scsi_adjust_queue_depth(sdp, SDEBUG_TAGGED_QUEUING,
1020 sdp->host->cmd_per_lun); 1803 sdp->host->cmd_per_lun);
1804 blk_queue_max_segment_size(sdp->request_queue, 256 * 1024);
1021 return 0; 1805 return 0;
1022} 1806}
1023 1807
@@ -1027,7 +1811,8 @@ static void scsi_debug_slave_destroy(struct scsi_device * sdp)
1027 (struct sdebug_dev_info *)sdp->hostdata; 1811 (struct sdebug_dev_info *)sdp->hostdata;
1028 1812
1029 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 1813 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
1030 sdev_printk(KERN_INFO, sdp, "scsi_debug: slave_destroy\n"); 1814 printk(KERN_INFO "scsi_debug: slave_destroy <%u %u %u %u>\n",
1815 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
1031 if (devip) { 1816 if (devip) {
1032 /* make this slot avaliable for re-use */ 1817 /* make this slot avaliable for re-use */
1033 devip->used = 0; 1818 devip->used = 0;
@@ -1084,6 +1869,8 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
1084 open_devip->sense_buff[0] = 0x70; 1869 open_devip->sense_buff[0] = 0x70;
1085 open_devip->sense_buff[7] = 0xa; 1870 open_devip->sense_buff[7] = 0xa;
1086 } 1871 }
1872 if (sdev->lun == SAM2_WLUN_REPORT_LUNS)
1873 open_devip->wlun = SAM2_WLUN_REPORT_LUNS & 0xff;
1087 return open_devip; 1874 return open_devip;
1088 } 1875 }
1089 return NULL; 1876 return NULL;
@@ -1272,7 +2059,7 @@ static void __init sdebug_build_parts(unsigned char * ramp)
1272 printk(KERN_WARNING "scsi_debug:build_parts: reducing " 2059 printk(KERN_WARNING "scsi_debug:build_parts: reducing "
1273 "partitions to %d\n", SDEBUG_MAX_PARTS); 2060 "partitions to %d\n", SDEBUG_MAX_PARTS);
1274 } 2061 }
1275 num_sectors = (int)(sdebug_store_size / SECT_SIZE); 2062 num_sectors = (int)sdebug_store_sectors;
1276 sectors_per_part = (num_sectors - sdebug_sectors_per) 2063 sectors_per_part = (num_sectors - sdebug_sectors_per)
1277 / scsi_debug_num_parts; 2064 / scsi_debug_num_parts;
1278 heads_by_sects = sdebug_heads * sdebug_sectors_per; 2065 heads_by_sects = sdebug_heads * sdebug_sectors_per;
@@ -1315,9 +2102,9 @@ static int schedule_resp(struct scsi_cmnd * cmnd,
1315 if (scsi_result) { 2102 if (scsi_result) {
1316 struct scsi_device * sdp = cmnd->device; 2103 struct scsi_device * sdp = cmnd->device;
1317 2104
1318 sdev_printk(KERN_INFO, sdp, 2105 printk(KERN_INFO "scsi_debug: <%u %u %u %u> "
1319 "non-zero result=0x%x\n", 2106 "non-zero result=0x%x\n", sdp->host->host_no,
1320 scsi_result); 2107 sdp->channel, sdp->id, sdp->lun, scsi_result);
1321 } 2108 }
1322 } 2109 }
1323 if (cmnd && devip) { 2110 if (cmnd && devip) {
@@ -1364,21 +2151,19 @@ static int schedule_resp(struct scsi_cmnd * cmnd,
1364 } 2151 }
1365} 2152}
1366 2153
1367/* Set 'perm' (4th argument) to 0 to disable module_param's definition 2154module_param_named(add_host, scsi_debug_add_host, int, S_IRUGO | S_IWUSR);
1368 * of sysfs parameters (which module_param doesn't yet support). 2155module_param_named(delay, scsi_debug_delay, int, S_IRUGO | S_IWUSR);
1369 * Sysfs parameters defined explicitly below. 2156module_param_named(dev_size_mb, scsi_debug_dev_size_mb, int, S_IRUGO);
1370 */ 2157module_param_named(dsense, scsi_debug_dsense, int, S_IRUGO | S_IWUSR);
1371module_param_named(add_host, scsi_debug_add_host, int, 0); /* perm=0644 */ 2158module_param_named(every_nth, scsi_debug_every_nth, int, S_IRUGO | S_IWUSR);
1372module_param_named(delay, scsi_debug_delay, int, 0); /* perm=0644 */ 2159module_param_named(max_luns, scsi_debug_max_luns, int, S_IRUGO | S_IWUSR);
1373module_param_named(dev_size_mb, scsi_debug_dev_size_mb, int, 0); 2160module_param_named(no_lun_0, scsi_debug_no_lun_0, int, S_IRUGO | S_IWUSR);
1374module_param_named(dsense, scsi_debug_dsense, int, 0); 2161module_param_named(num_parts, scsi_debug_num_parts, int, S_IRUGO);
1375module_param_named(every_nth, scsi_debug_every_nth, int, 0); 2162module_param_named(num_tgts, scsi_debug_num_tgts, int, S_IRUGO | S_IWUSR);
1376module_param_named(max_luns, scsi_debug_max_luns, int, 0); 2163module_param_named(opts, scsi_debug_opts, int, S_IRUGO | S_IWUSR);
1377module_param_named(num_parts, scsi_debug_num_parts, int, 0); 2164module_param_named(ptype, scsi_debug_ptype, int, S_IRUGO | S_IWUSR);
1378module_param_named(num_tgts, scsi_debug_num_tgts, int, 0); 2165module_param_named(scsi_level, scsi_debug_scsi_level, int, S_IRUGO);
1379module_param_named(opts, scsi_debug_opts, int, 0); /* perm=0644 */ 2166module_param_named(virtual_gb, scsi_debug_virtual_gb, int, S_IRUGO | S_IWUSR);
1380module_param_named(ptype, scsi_debug_ptype, int, 0);
1381module_param_named(scsi_level, scsi_debug_scsi_level, int, 0);
1382 2167
1383MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert"); 2168MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert");
1384MODULE_DESCRIPTION("SCSI debug adapter driver"); 2169MODULE_DESCRIPTION("SCSI debug adapter driver");
@@ -1387,15 +2172,17 @@ MODULE_VERSION(SCSI_DEBUG_VERSION);
1387 2172
1388MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)"); 2173MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)");
1389MODULE_PARM_DESC(delay, "# of jiffies to delay response(def=1)"); 2174MODULE_PARM_DESC(delay, "# of jiffies to delay response(def=1)");
1390MODULE_PARM_DESC(dev_size_mb, "size in MB of ram shared by devs"); 2175MODULE_PARM_DESC(dev_size_mb, "size in MB of ram shared by devs(def=8)");
1391MODULE_PARM_DESC(dsense, "use descriptor sense format(def: fixed)"); 2176MODULE_PARM_DESC(dsense, "use descriptor sense format(def=0 -> fixed)");
1392MODULE_PARM_DESC(every_nth, "timeout every nth command(def=100)"); 2177MODULE_PARM_DESC(every_nth, "timeout every nth command(def=100)");
1393MODULE_PARM_DESC(max_luns, "number of SCSI LUNs per target to simulate"); 2178MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)");
2179MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)");
1394MODULE_PARM_DESC(num_parts, "number of partitions(def=0)"); 2180MODULE_PARM_DESC(num_parts, "number of partitions(def=0)");
1395MODULE_PARM_DESC(num_tgts, "number of SCSI targets per host to simulate"); 2181MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)");
1396MODULE_PARM_DESC(opts, "1->noise, 2->medium_error, 4->..."); 2182MODULE_PARM_DESC(opts, "1->noise, 2->medium_error, 4->... (def=0)");
1397MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])"); 2183MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])");
1398MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=5[SPC-3])"); 2184MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=5[SPC-3])");
2185MODULE_PARM_DESC(virtual_gb, "virtual gigabyte size (def=0 -> use dev_size_mb)");
1399 2186
1400 2187
1401static char sdebug_info[256]; 2188static char sdebug_info[256];
@@ -1547,6 +2334,24 @@ static ssize_t sdebug_dsense_store(struct device_driver * ddp,
1547DRIVER_ATTR(dsense, S_IRUGO | S_IWUSR, sdebug_dsense_show, 2334DRIVER_ATTR(dsense, S_IRUGO | S_IWUSR, sdebug_dsense_show,
1548 sdebug_dsense_store); 2335 sdebug_dsense_store);
1549 2336
2337static ssize_t sdebug_no_lun_0_show(struct device_driver * ddp, char * buf)
2338{
2339 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_no_lun_0);
2340}
2341static ssize_t sdebug_no_lun_0_store(struct device_driver * ddp,
2342 const char * buf, size_t count)
2343{
2344 int n;
2345
2346 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
2347 scsi_debug_no_lun_0 = n;
2348 return count;
2349 }
2350 return -EINVAL;
2351}
2352DRIVER_ATTR(no_lun_0, S_IRUGO | S_IWUSR, sdebug_no_lun_0_show,
2353 sdebug_no_lun_0_store);
2354
1550static ssize_t sdebug_num_tgts_show(struct device_driver * ddp, char * buf) 2355static ssize_t sdebug_num_tgts_show(struct device_driver * ddp, char * buf)
1551{ 2356{
1552 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_tgts); 2357 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_num_tgts);
@@ -1622,6 +2427,29 @@ static ssize_t sdebug_scsi_level_show(struct device_driver * ddp, char * buf)
1622} 2427}
1623DRIVER_ATTR(scsi_level, S_IRUGO, sdebug_scsi_level_show, NULL); 2428DRIVER_ATTR(scsi_level, S_IRUGO, sdebug_scsi_level_show, NULL);
1624 2429
2430static ssize_t sdebug_virtual_gb_show(struct device_driver * ddp, char * buf)
2431{
2432 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_virtual_gb);
2433}
2434static ssize_t sdebug_virtual_gb_store(struct device_driver * ddp,
2435 const char * buf, size_t count)
2436{
2437 int n;
2438
2439 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
2440 scsi_debug_virtual_gb = n;
2441 if (scsi_debug_virtual_gb > 0) {
2442 sdebug_capacity = 2048 * 1024;
2443 sdebug_capacity *= scsi_debug_virtual_gb;
2444 } else
2445 sdebug_capacity = sdebug_store_sectors;
2446 return count;
2447 }
2448 return -EINVAL;
2449}
2450DRIVER_ATTR(virtual_gb, S_IRUGO | S_IWUSR, sdebug_virtual_gb_show,
2451 sdebug_virtual_gb_store);
2452
1625static ssize_t sdebug_add_host_show(struct device_driver * ddp, char * buf) 2453static ssize_t sdebug_add_host_show(struct device_driver * ddp, char * buf)
1626{ 2454{
1627 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_add_host); 2455 return scnprintf(buf, PAGE_SIZE, "%d\n", scsi_debug_add_host);
@@ -1659,19 +2487,22 @@ static ssize_t sdebug_add_host_store(struct device_driver * ddp,
1659DRIVER_ATTR(add_host, S_IRUGO | S_IWUSR, sdebug_add_host_show, 2487DRIVER_ATTR(add_host, S_IRUGO | S_IWUSR, sdebug_add_host_show,
1660 sdebug_add_host_store); 2488 sdebug_add_host_store);
1661 2489
1662static void do_create_driverfs_files(void) 2490static int do_create_driverfs_files(void)
1663{ 2491{
1664 driver_create_file(&sdebug_driverfs_driver, &driver_attr_add_host); 2492 int ret;
1665 driver_create_file(&sdebug_driverfs_driver, &driver_attr_delay); 2493
1666 driver_create_file(&sdebug_driverfs_driver, &driver_attr_dev_size_mb); 2494 ret = driver_create_file(&sdebug_driverfs_driver, &driver_attr_add_host);
1667 driver_create_file(&sdebug_driverfs_driver, &driver_attr_dsense); 2495 ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_delay);
1668 driver_create_file(&sdebug_driverfs_driver, &driver_attr_every_nth); 2496 ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_dev_size_mb);
1669 driver_create_file(&sdebug_driverfs_driver, &driver_attr_max_luns); 2497 ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_dsense);
1670 driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_tgts); 2498 ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_every_nth);
1671 driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_parts); 2499 ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_max_luns);
1672 driver_create_file(&sdebug_driverfs_driver, &driver_attr_ptype); 2500 ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_tgts);
1673 driver_create_file(&sdebug_driverfs_driver, &driver_attr_opts); 2501 ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_num_parts);
1674 driver_create_file(&sdebug_driverfs_driver, &driver_attr_scsi_level); 2502 ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_ptype);
2503 ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_opts);
2504 ret |= driver_create_file(&sdebug_driverfs_driver, &driver_attr_scsi_level);
2505 return ret;
1675} 2506}
1676 2507
1677static void do_remove_driverfs_files(void) 2508static void do_remove_driverfs_files(void)
@@ -1691,14 +2522,20 @@ static void do_remove_driverfs_files(void)
1691 2522
1692static int __init scsi_debug_init(void) 2523static int __init scsi_debug_init(void)
1693{ 2524{
1694 unsigned long sz; 2525 unsigned int sz;
1695 int host_to_add; 2526 int host_to_add;
1696 int k; 2527 int k;
2528 int ret;
1697 2529
1698 if (scsi_debug_dev_size_mb < 1) 2530 if (scsi_debug_dev_size_mb < 1)
1699 scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */ 2531 scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */
1700 sdebug_store_size = (unsigned long)scsi_debug_dev_size_mb * 1048576; 2532 sdebug_store_size = (unsigned int)scsi_debug_dev_size_mb * 1048576;
1701 sdebug_capacity = sdebug_store_size / SECT_SIZE; 2533 sdebug_store_sectors = sdebug_store_size / SECT_SIZE;
2534 if (scsi_debug_virtual_gb > 0) {
2535 sdebug_capacity = 2048 * 1024;
2536 sdebug_capacity *= scsi_debug_virtual_gb;
2537 } else
2538 sdebug_capacity = sdebug_store_sectors;
1702 2539
1703 /* play around with geometry, don't waste too much on track 0 */ 2540 /* play around with geometry, don't waste too much on track 0 */
1704 sdebug_heads = 8; 2541 sdebug_heads = 8;
@@ -1727,12 +2564,32 @@ static int __init scsi_debug_init(void)
1727 if (scsi_debug_num_parts > 0) 2564 if (scsi_debug_num_parts > 0)
1728 sdebug_build_parts(fake_storep); 2565 sdebug_build_parts(fake_storep);
1729 2566
1730 init_all_queued(); 2567 ret = device_register(&pseudo_primary);
2568 if (ret < 0) {
2569 printk(KERN_WARNING "scsi_debug: device_register error: %d\n",
2570 ret);
2571 goto free_vm;
2572 }
2573 ret = bus_register(&pseudo_lld_bus);
2574 if (ret < 0) {
2575 printk(KERN_WARNING "scsi_debug: bus_register error: %d\n",
2576 ret);
2577 goto dev_unreg;
2578 }
2579 ret = driver_register(&sdebug_driverfs_driver);
2580 if (ret < 0) {
2581 printk(KERN_WARNING "scsi_debug: driver_register error: %d\n",
2582 ret);
2583 goto bus_unreg;
2584 }
2585 ret = do_create_driverfs_files();
2586 if (ret < 0) {
2587 printk(KERN_WARNING "scsi_debug: driver_create_file error: %d\n",
2588 ret);
2589 goto del_files;
2590 }
1731 2591
1732 device_register(&pseudo_primary); 2592 init_all_queued();
1733 bus_register(&pseudo_lld_bus);
1734 driver_register(&sdebug_driverfs_driver);
1735 do_create_driverfs_files();
1736 2593
1737 sdebug_driver_template.proc_name = (char *)sdebug_proc_name; 2594 sdebug_driver_template.proc_name = (char *)sdebug_proc_name;
1738 2595
@@ -1752,6 +2609,18 @@ static int __init scsi_debug_init(void)
1752 scsi_debug_add_host); 2609 scsi_debug_add_host);
1753 } 2610 }
1754 return 0; 2611 return 0;
2612
2613del_files:
2614 do_remove_driverfs_files();
2615 driver_unregister(&sdebug_driverfs_driver);
2616bus_unreg:
2617 bus_unregister(&pseudo_lld_bus);
2618dev_unreg:
2619 device_unregister(&pseudo_primary);
2620free_vm:
2621 vfree(fake_storep);
2622
2623 return ret;
1755} 2624}
1756 2625
1757static void __exit scsi_debug_exit(void) 2626static void __exit scsi_debug_exit(void)
@@ -1812,7 +2681,7 @@ static int sdebug_add_adapter(void)
1812 struct sdebug_dev_info *sdbg_devinfo; 2681 struct sdebug_dev_info *sdbg_devinfo;
1813 struct list_head *lh, *lh_sf; 2682 struct list_head *lh, *lh_sf;
1814 2683
1815 sdbg_host = kzalloc(sizeof(*sdbg_host), GFP_KERNEL); 2684 sdbg_host = kzalloc(sizeof(*sdbg_host),GFP_KERNEL);
1816 2685
1817 if (NULL == sdbg_host) { 2686 if (NULL == sdbg_host) {
1818 printk(KERN_ERR "%s: out of memory at line %d\n", 2687 printk(KERN_ERR "%s: out of memory at line %d\n",
@@ -1824,7 +2693,7 @@ static int sdebug_add_adapter(void)
1824 2693
1825 devs_per_host = scsi_debug_num_tgts * scsi_debug_max_luns; 2694 devs_per_host = scsi_debug_num_tgts * scsi_debug_max_luns;
1826 for (k = 0; k < devs_per_host; k++) { 2695 for (k = 0; k < devs_per_host; k++) {
1827 sdbg_devinfo = kzalloc(sizeof(*sdbg_devinfo), GFP_KERNEL); 2696 sdbg_devinfo = kzalloc(sizeof(*sdbg_devinfo),GFP_KERNEL);
1828 if (NULL == sdbg_devinfo) { 2697 if (NULL == sdbg_devinfo) {
1829 printk(KERN_ERR "%s: out of memory at line %d\n", 2698 printk(KERN_ERR "%s: out of memory at line %d\n",
1830 __FUNCTION__, __LINE__); 2699 __FUNCTION__, __LINE__);
@@ -1905,7 +2774,7 @@ static int sdebug_driver_probe(struct device * dev)
1905 hpnt->max_id = scsi_debug_num_tgts + 1; 2774 hpnt->max_id = scsi_debug_num_tgts + 1;
1906 else 2775 else
1907 hpnt->max_id = scsi_debug_num_tgts; 2776 hpnt->max_id = scsi_debug_num_tgts;
1908 hpnt->max_lun = scsi_debug_max_luns; 2777 hpnt->max_lun = SAM2_WLUN_REPORT_LUNS; /* = scsi_debug_max_luns; */
1909 2778
1910 error = scsi_add_host(hpnt, &sdbg_host->dev); 2779 error = scsi_add_host(hpnt, &sdbg_host->dev);
1911 if (error) { 2780 if (error) {
@@ -1959,7 +2828,7 @@ static void sdebug_max_tgts_luns(void)
1959 hpnt->max_id = scsi_debug_num_tgts + 1; 2828 hpnt->max_id = scsi_debug_num_tgts + 1;
1960 else 2829 else
1961 hpnt->max_id = scsi_debug_num_tgts; 2830 hpnt->max_id = scsi_debug_num_tgts;
1962 hpnt->max_lun = scsi_debug_max_luns; 2831 hpnt->max_lun = SAM2_WLUN_REPORT_LUNS; /* scsi_debug_max_luns; */
1963 } 2832 }
1964 spin_unlock(&sdebug_host_list_lock); 2833 spin_unlock(&sdebug_host_list_lock);
1965} 2834}
diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index fb5cb4c9ac65..3d0429bc14ab 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -162,7 +162,7 @@ static struct {
162 {"HITACHI", "DISK-SUBSYSTEM", "*", BLIST_ATTACH_PQ3 | BLIST_SPARSELUN | BLIST_LARGELUN}, 162 {"HITACHI", "DISK-SUBSYSTEM", "*", BLIST_ATTACH_PQ3 | BLIST_SPARSELUN | BLIST_LARGELUN},
163 {"HITACHI", "OPEN-E", "*", BLIST_ATTACH_PQ3 | BLIST_SPARSELUN | BLIST_LARGELUN}, 163 {"HITACHI", "OPEN-E", "*", BLIST_ATTACH_PQ3 | BLIST_SPARSELUN | BLIST_LARGELUN},
164 {"HP", "A6189A", NULL, BLIST_SPARSELUN | BLIST_LARGELUN}, /* HP VA7400 */ 164 {"HP", "A6189A", NULL, BLIST_SPARSELUN | BLIST_LARGELUN}, /* HP VA7400 */
165 {"HP", "OPEN-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, /* HP XP Arrays */ 165 {"HP", "OPEN-", "*", BLIST_REPORTLUN2}, /* HP XP Arrays */
166 {"HP", "NetRAID-4M", NULL, BLIST_FORCELUN}, 166 {"HP", "NetRAID-4M", NULL, BLIST_FORCELUN},
167 {"HP", "HSV100", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD}, 167 {"HP", "HSV100", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
168 {"HP", "C1557A", NULL, BLIST_FORCELUN}, 168 {"HP", "C1557A", NULL, BLIST_FORCELUN},
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 6a7a60fc0a4e..3d355d054612 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -460,19 +460,71 @@ static void scsi_eh_done(struct scsi_cmnd *scmd)
460 * Return value: 460 * Return value:
461 * SUCCESS or FAILED or NEEDS_RETRY 461 * SUCCESS or FAILED or NEEDS_RETRY
462 **/ 462 **/
463static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, int timeout) 463static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, unsigned char *cmnd,
464 int cmnd_size, int timeout, int copy_sense)
464{ 465{
465 struct scsi_device *sdev = scmd->device; 466 struct scsi_device *sdev = scmd->device;
466 struct Scsi_Host *shost = sdev->host; 467 struct Scsi_Host *shost = sdev->host;
467 DECLARE_COMPLETION(done); 468 int old_result = scmd->result;
469 DECLARE_COMPLETION_ONSTACK(done);
468 unsigned long timeleft; 470 unsigned long timeleft;
469 unsigned long flags; 471 unsigned long flags;
472 unsigned char old_cmnd[MAX_COMMAND_SIZE];
473 enum dma_data_direction old_data_direction;
474 unsigned short old_use_sg;
475 unsigned char old_cmd_len;
476 unsigned old_bufflen;
477 void *old_buffer;
470 int rtn; 478 int rtn;
471 479
480 /*
481 * We need saved copies of a number of fields - this is because
482 * error handling may need to overwrite these with different values
483 * to run different commands, and once error handling is complete,
484 * we will need to restore these values prior to running the actual
485 * command.
486 */
487 old_buffer = scmd->request_buffer;
488 old_bufflen = scmd->request_bufflen;
489 memcpy(old_cmnd, scmd->cmnd, sizeof(scmd->cmnd));
490 old_data_direction = scmd->sc_data_direction;
491 old_cmd_len = scmd->cmd_len;
492 old_use_sg = scmd->use_sg;
493
494 memset(scmd->cmnd, 0, sizeof(scmd->cmnd));
495 memcpy(scmd->cmnd, cmnd, cmnd_size);
496
497 if (copy_sense) {
498 int gfp_mask = GFP_ATOMIC;
499
500 if (shost->hostt->unchecked_isa_dma)
501 gfp_mask |= __GFP_DMA;
502
503 scmd->sc_data_direction = DMA_FROM_DEVICE;
504 scmd->request_bufflen = 252;
505 scmd->request_buffer = kzalloc(scmd->request_bufflen, gfp_mask);
506 if (!scmd->request_buffer)
507 return FAILED;
508 } else {
509 scmd->request_buffer = NULL;
510 scmd->request_bufflen = 0;
511 scmd->sc_data_direction = DMA_NONE;
512 }
513
514 scmd->underflow = 0;
515 scmd->use_sg = 0;
516 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
517
472 if (sdev->scsi_level <= SCSI_2) 518 if (sdev->scsi_level <= SCSI_2)
473 scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) | 519 scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) |
474 (sdev->lun << 5 & 0xe0); 520 (sdev->lun << 5 & 0xe0);
475 521
522 /*
523 * Zero the sense buffer. The scsi spec mandates that any
524 * untransferred sense data should be interpreted as being zero.
525 */
526 memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
527
476 shost->eh_action = &done; 528 shost->eh_action = &done;
477 529
478 spin_lock_irqsave(shost->host_lock, flags); 530 spin_lock_irqsave(shost->host_lock, flags);
@@ -522,6 +574,29 @@ static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, int timeout)
522 rtn = FAILED; 574 rtn = FAILED;
523 } 575 }
524 576
577
578 /*
579 * Last chance to have valid sense data.
580 */
581 if (copy_sense) {
582 if (!SCSI_SENSE_VALID(scmd)) {
583 memcpy(scmd->sense_buffer, scmd->request_buffer,
584 sizeof(scmd->sense_buffer));
585 }
586 kfree(scmd->request_buffer);
587 }
588
589
590 /*
591 * Restore original data
592 */
593 scmd->request_buffer = old_buffer;
594 scmd->request_bufflen = old_bufflen;
595 memcpy(scmd->cmnd, old_cmnd, sizeof(scmd->cmnd));
596 scmd->sc_data_direction = old_data_direction;
597 scmd->cmd_len = old_cmd_len;
598 scmd->use_sg = old_use_sg;
599 scmd->result = old_result;
525 return rtn; 600 return rtn;
526} 601}
527 602
@@ -537,56 +612,9 @@ static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, int timeout)
537static int scsi_request_sense(struct scsi_cmnd *scmd) 612static int scsi_request_sense(struct scsi_cmnd *scmd)
538{ 613{
539 static unsigned char generic_sense[6] = 614 static unsigned char generic_sense[6] =
540 {REQUEST_SENSE, 0, 0, 0, 252, 0}; 615 {REQUEST_SENSE, 0, 0, 0, 252, 0};
541 unsigned char *scsi_result;
542 int saved_result;
543 int rtn;
544
545 memcpy(scmd->cmnd, generic_sense, sizeof(generic_sense));
546
547 scsi_result = kmalloc(252, GFP_ATOMIC | ((scmd->device->host->hostt->unchecked_isa_dma) ? __GFP_DMA : 0));
548 616
549 617 return scsi_send_eh_cmnd(scmd, generic_sense, 6, SENSE_TIMEOUT, 1);
550 if (unlikely(!scsi_result)) {
551 printk(KERN_ERR "%s: cannot allocate scsi_result.\n",
552 __FUNCTION__);
553 return FAILED;
554 }
555
556 /*
557 * zero the sense buffer. some host adapters automatically always
558 * request sense, so it is not a good idea that
559 * scmd->request_buffer and scmd->sense_buffer point to the same
560 * address (db). 0 is not a valid sense code.
561 */
562 memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
563 memset(scsi_result, 0, 252);
564
565 saved_result = scmd->result;
566 scmd->request_buffer = scsi_result;
567 scmd->request_bufflen = 252;
568 scmd->use_sg = 0;
569 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
570 scmd->sc_data_direction = DMA_FROM_DEVICE;
571 scmd->underflow = 0;
572
573 rtn = scsi_send_eh_cmnd(scmd, SENSE_TIMEOUT);
574
575 /* last chance to have valid sense data */
576 if(!SCSI_SENSE_VALID(scmd)) {
577 memcpy(scmd->sense_buffer, scmd->request_buffer,
578 sizeof(scmd->sense_buffer));
579 }
580
581 kfree(scsi_result);
582
583 /*
584 * when we eventually call scsi_finish, we really wish to complete
585 * the original request, so let's restore the original data. (db)
586 */
587 scsi_setup_cmd_retry(scmd);
588 scmd->result = saved_result;
589 return rtn;
590} 618}
591 619
592/** 620/**
@@ -605,12 +633,6 @@ void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, struct list_head *done_q)
605{ 633{
606 scmd->device->host->host_failed--; 634 scmd->device->host->host_failed--;
607 scmd->eh_eflags = 0; 635 scmd->eh_eflags = 0;
608
609 /*
610 * set this back so that the upper level can correctly free up
611 * things.
612 */
613 scsi_setup_cmd_retry(scmd);
614 list_move_tail(&scmd->eh_entry, done_q); 636 list_move_tail(&scmd->eh_entry, done_q);
615} 637}
616EXPORT_SYMBOL(scsi_eh_finish_cmd); 638EXPORT_SYMBOL(scsi_eh_finish_cmd);
@@ -715,47 +737,23 @@ static int scsi_eh_tur(struct scsi_cmnd *scmd)
715{ 737{
716 static unsigned char tur_command[6] = {TEST_UNIT_READY, 0, 0, 0, 0, 0}; 738 static unsigned char tur_command[6] = {TEST_UNIT_READY, 0, 0, 0, 0, 0};
717 int retry_cnt = 1, rtn; 739 int retry_cnt = 1, rtn;
718 int saved_result;
719 740
720retry_tur: 741retry_tur:
721 memcpy(scmd->cmnd, tur_command, sizeof(tur_command)); 742 rtn = scsi_send_eh_cmnd(scmd, tur_command, 6, SENSE_TIMEOUT, 0);
722
723 /*
724 * zero the sense buffer. the scsi spec mandates that any
725 * untransferred sense data should be interpreted as being zero.
726 */
727 memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
728 743
729 saved_result = scmd->result;
730 scmd->request_buffer = NULL;
731 scmd->request_bufflen = 0;
732 scmd->use_sg = 0;
733 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
734 scmd->underflow = 0;
735 scmd->sc_data_direction = DMA_NONE;
736
737 rtn = scsi_send_eh_cmnd(scmd, SENSE_TIMEOUT);
738
739 /*
740 * when we eventually call scsi_finish, we really wish to complete
741 * the original request, so let's restore the original data. (db)
742 */
743 scsi_setup_cmd_retry(scmd);
744 scmd->result = saved_result;
745
746 /*
747 * hey, we are done. let's look to see what happened.
748 */
749 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n", 744 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n",
750 __FUNCTION__, scmd, rtn)); 745 __FUNCTION__, scmd, rtn));
751 if (rtn == SUCCESS) 746
752 return 0; 747 switch (rtn) {
753 else if (rtn == NEEDS_RETRY) { 748 case NEEDS_RETRY:
754 if (retry_cnt--) 749 if (retry_cnt--)
755 goto retry_tur; 750 goto retry_tur;
751 /*FALLTHRU*/
752 case SUCCESS:
756 return 0; 753 return 0;
754 default:
755 return 1;
757 } 756 }
758 return 1;
759} 757}
760 758
761/** 759/**
@@ -837,44 +835,16 @@ static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
837static int scsi_eh_try_stu(struct scsi_cmnd *scmd) 835static int scsi_eh_try_stu(struct scsi_cmnd *scmd)
838{ 836{
839 static unsigned char stu_command[6] = {START_STOP, 0, 0, 0, 1, 0}; 837 static unsigned char stu_command[6] = {START_STOP, 0, 0, 0, 1, 0};
840 int rtn;
841 int saved_result;
842
843 if (!scmd->device->allow_restart)
844 return 1;
845 838
846 memcpy(scmd->cmnd, stu_command, sizeof(stu_command)); 839 if (scmd->device->allow_restart) {
847 840 int rtn;
848 /*
849 * zero the sense buffer. the scsi spec mandates that any
850 * untransferred sense data should be interpreted as being zero.
851 */
852 memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
853
854 saved_result = scmd->result;
855 scmd->request_buffer = NULL;
856 scmd->request_bufflen = 0;
857 scmd->use_sg = 0;
858 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
859 scmd->underflow = 0;
860 scmd->sc_data_direction = DMA_NONE;
861 841
862 rtn = scsi_send_eh_cmnd(scmd, START_UNIT_TIMEOUT); 842 rtn = scsi_send_eh_cmnd(scmd, stu_command, 6,
863 843 START_UNIT_TIMEOUT, 0);
864 /* 844 if (rtn == SUCCESS)
865 * when we eventually call scsi_finish, we really wish to complete 845 return 0;
866 * the original request, so let's restore the original data. (db) 846 }
867 */
868 scsi_setup_cmd_retry(scmd);
869 scmd->result = saved_result;
870 847
871 /*
872 * hey, we are done. let's look to see what happened.
873 */
874 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n",
875 __FUNCTION__, scmd, rtn));
876 if (rtn == SUCCESS)
877 return 0;
878 return 1; 848 return 1;
879} 849}
880 850
@@ -1672,7 +1642,9 @@ int
1672scsi_reset_provider(struct scsi_device *dev, int flag) 1642scsi_reset_provider(struct scsi_device *dev, int flag)
1673{ 1643{
1674 struct scsi_cmnd *scmd = scsi_get_command(dev, GFP_KERNEL); 1644 struct scsi_cmnd *scmd = scsi_get_command(dev, GFP_KERNEL);
1645 struct Scsi_Host *shost = dev->host;
1675 struct request req; 1646 struct request req;
1647 unsigned long flags;
1676 int rtn; 1648 int rtn;
1677 1649
1678 scmd->request = &req; 1650 scmd->request = &req;
@@ -1682,8 +1654,6 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
1682 1654
1683 scmd->scsi_done = scsi_reset_provider_done_command; 1655 scmd->scsi_done = scsi_reset_provider_done_command;
1684 scmd->done = NULL; 1656 scmd->done = NULL;
1685 scmd->buffer = NULL;
1686 scmd->bufflen = 0;
1687 scmd->request_buffer = NULL; 1657 scmd->request_buffer = NULL;
1688 scmd->request_bufflen = 0; 1658 scmd->request_bufflen = 0;
1689 1659
@@ -1699,6 +1669,10 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
1699 */ 1669 */
1700 scmd->pid = 0; 1670 scmd->pid = 0;
1701 1671
1672 spin_lock_irqsave(shost->host_lock, flags);
1673 shost->tmf_in_progress = 1;
1674 spin_unlock_irqrestore(shost->host_lock, flags);
1675
1702 switch (flag) { 1676 switch (flag) {
1703 case SCSI_TRY_RESET_DEVICE: 1677 case SCSI_TRY_RESET_DEVICE:
1704 rtn = scsi_try_bus_device_reset(scmd); 1678 rtn = scsi_try_bus_device_reset(scmd);
@@ -1717,6 +1691,22 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
1717 rtn = FAILED; 1691 rtn = FAILED;
1718 } 1692 }
1719 1693
1694 spin_lock_irqsave(shost->host_lock, flags);
1695 shost->tmf_in_progress = 0;
1696 spin_unlock_irqrestore(shost->host_lock, flags);
1697
1698 /*
1699 * be sure to wake up anyone who was sleeping or had their queue
1700 * suspended while we performed the TMF.
1701 */
1702 SCSI_LOG_ERROR_RECOVERY(3,
1703 printk("%s: waking up host to restart after TMF\n",
1704 __FUNCTION__));
1705
1706 wake_up(&shost->host_wait);
1707
1708 scsi_run_host_queues(shost);
1709
1720 scsi_next_command(scmd); 1710 scsi_next_command(scmd);
1721 return rtn; 1711 return rtn;
1722} 1712}
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index a89c4115cfba..32293f451669 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -110,11 +110,8 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
110 sshdr.asc, sshdr.ascq); 110 sshdr.asc, sshdr.ascq);
111 break; 111 break;
112 case NOT_READY: /* This happens if there is no disc in drive */ 112 case NOT_READY: /* This happens if there is no disc in drive */
113 if (sdev->removable && (cmd[0] != TEST_UNIT_READY)) { 113 if (sdev->removable)
114 printk(KERN_INFO "Device not ready. Make sure"
115 " there is a disc in the drive.\n");
116 break; 114 break;
117 }
118 case UNIT_ATTENTION: 115 case UNIT_ATTENTION:
119 if (sdev->removable) { 116 if (sdev->removable) {
120 sdev->changed = 1; 117 sdev->changed = 1;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 3d04a9f386ac..077c1c691210 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -436,60 +436,16 @@ EXPORT_SYMBOL_GPL(scsi_execute_async);
436 * 436 *
437 * Arguments: cmd - command that is ready to be queued. 437 * Arguments: cmd - command that is ready to be queued.
438 * 438 *
439 * Returns: Nothing
440 *
441 * Notes: This function has the job of initializing a number of 439 * Notes: This function has the job of initializing a number of
442 * fields related to error handling. Typically this will 440 * fields related to error handling. Typically this will
443 * be called once for each command, as required. 441 * be called once for each command, as required.
444 */ 442 */
445static int scsi_init_cmd_errh(struct scsi_cmnd *cmd) 443static void scsi_init_cmd_errh(struct scsi_cmnd *cmd)
446{ 444{
447 cmd->serial_number = 0; 445 cmd->serial_number = 0;
448
449 memset(cmd->sense_buffer, 0, sizeof cmd->sense_buffer); 446 memset(cmd->sense_buffer, 0, sizeof cmd->sense_buffer);
450
451 if (cmd->cmd_len == 0) 447 if (cmd->cmd_len == 0)
452 cmd->cmd_len = COMMAND_SIZE(cmd->cmnd[0]); 448 cmd->cmd_len = COMMAND_SIZE(cmd->cmnd[0]);
453
454 /*
455 * We need saved copies of a number of fields - this is because
456 * error handling may need to overwrite these with different values
457 * to run different commands, and once error handling is complete,
458 * we will need to restore these values prior to running the actual
459 * command.
460 */
461 cmd->old_use_sg = cmd->use_sg;
462 cmd->old_cmd_len = cmd->cmd_len;
463 cmd->sc_old_data_direction = cmd->sc_data_direction;
464 cmd->old_underflow = cmd->underflow;
465 memcpy(cmd->data_cmnd, cmd->cmnd, sizeof(cmd->cmnd));
466 cmd->buffer = cmd->request_buffer;
467 cmd->bufflen = cmd->request_bufflen;
468
469 return 1;
470}
471
472/*
473 * Function: scsi_setup_cmd_retry()
474 *
475 * Purpose: Restore the command state for a retry
476 *
477 * Arguments: cmd - command to be restored
478 *
479 * Returns: Nothing
480 *
481 * Notes: Immediately prior to retrying a command, we need
482 * to restore certain fields that we saved above.
483 */
484void scsi_setup_cmd_retry(struct scsi_cmnd *cmd)
485{
486 memcpy(cmd->cmnd, cmd->data_cmnd, sizeof(cmd->data_cmnd));
487 cmd->request_buffer = cmd->buffer;
488 cmd->request_bufflen = cmd->bufflen;
489 cmd->use_sg = cmd->old_use_sg;
490 cmd->cmd_len = cmd->old_cmd_len;
491 cmd->sc_data_direction = cmd->sc_old_data_direction;
492 cmd->underflow = cmd->old_underflow;
493} 449}
494 450
495void scsi_device_unbusy(struct scsi_device *sdev) 451void scsi_device_unbusy(struct scsi_device *sdev)
@@ -807,22 +763,13 @@ static void scsi_free_sgtable(struct scatterlist *sgl, int index)
807 */ 763 */
808static void scsi_release_buffers(struct scsi_cmnd *cmd) 764static void scsi_release_buffers(struct scsi_cmnd *cmd)
809{ 765{
810 struct request *req = cmd->request;
811
812 /*
813 * Free up any indirection buffers we allocated for DMA purposes.
814 */
815 if (cmd->use_sg) 766 if (cmd->use_sg)
816 scsi_free_sgtable(cmd->request_buffer, cmd->sglist_len); 767 scsi_free_sgtable(cmd->request_buffer, cmd->sglist_len);
817 else if (cmd->request_buffer != req->buffer)
818 kfree(cmd->request_buffer);
819 768
820 /* 769 /*
821 * Zero these out. They now point to freed memory, and it is 770 * Zero these out. They now point to freed memory, and it is
822 * dangerous to hang onto the pointers. 771 * dangerous to hang onto the pointers.
823 */ 772 */
824 cmd->buffer = NULL;
825 cmd->bufflen = 0;
826 cmd->request_buffer = NULL; 773 cmd->request_buffer = NULL;
827 cmd->request_bufflen = 0; 774 cmd->request_bufflen = 0;
828} 775}
@@ -855,11 +802,10 @@ static void scsi_release_buffers(struct scsi_cmnd *cmd)
855 * b) We can just use scsi_requeue_command() here. This would 802 * b) We can just use scsi_requeue_command() here. This would
856 * be used if we just wanted to retry, for example. 803 * be used if we just wanted to retry, for example.
857 */ 804 */
858void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, 805void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
859 unsigned int block_bytes)
860{ 806{
861 int result = cmd->result; 807 int result = cmd->result;
862 int this_count = cmd->bufflen; 808 int this_count = cmd->request_bufflen;
863 request_queue_t *q = cmd->device->request_queue; 809 request_queue_t *q = cmd->device->request_queue;
864 struct request *req = cmd->request; 810 struct request *req = cmd->request;
865 int clear_errors = 1; 811 int clear_errors = 1;
@@ -867,28 +813,14 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
867 int sense_valid = 0; 813 int sense_valid = 0;
868 int sense_deferred = 0; 814 int sense_deferred = 0;
869 815
870 /* 816 scsi_release_buffers(cmd);
871 * Free up any indirection buffers we allocated for DMA purposes.
872 * For the case of a READ, we need to copy the data out of the
873 * bounce buffer and into the real buffer.
874 */
875 if (cmd->use_sg)
876 scsi_free_sgtable(cmd->buffer, cmd->sglist_len);
877 else if (cmd->buffer != req->buffer) {
878 if (rq_data_dir(req) == READ) {
879 unsigned long flags;
880 char *to = bio_kmap_irq(req->bio, &flags);
881 memcpy(to, cmd->buffer, cmd->bufflen);
882 bio_kunmap_irq(to, &flags);
883 }
884 kfree(cmd->buffer);
885 }
886 817
887 if (result) { 818 if (result) {
888 sense_valid = scsi_command_normalize_sense(cmd, &sshdr); 819 sense_valid = scsi_command_normalize_sense(cmd, &sshdr);
889 if (sense_valid) 820 if (sense_valid)
890 sense_deferred = scsi_sense_is_deferred(&sshdr); 821 sense_deferred = scsi_sense_is_deferred(&sshdr);
891 } 822 }
823
892 if (blk_pc_request(req)) { /* SG_IO ioctl from block level */ 824 if (blk_pc_request(req)) { /* SG_IO ioctl from block level */
893 req->errors = result; 825 req->errors = result;
894 if (result) { 826 if (result) {
@@ -909,99 +841,73 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
909 } 841 }
910 842
911 /* 843 /*
912 * Zero these out. They now point to freed memory, and it is
913 * dangerous to hang onto the pointers.
914 */
915 cmd->buffer = NULL;
916 cmd->bufflen = 0;
917 cmd->request_buffer = NULL;
918 cmd->request_bufflen = 0;
919
920 /*
921 * Next deal with any sectors which we were able to correctly 844 * Next deal with any sectors which we were able to correctly
922 * handle. 845 * handle.
923 */ 846 */
924 if (good_bytes >= 0) { 847 SCSI_LOG_HLCOMPLETE(1, printk("%ld sectors total, "
925 SCSI_LOG_HLCOMPLETE(1, printk("%ld sectors total, %d bytes done.\n", 848 "%d bytes done.\n",
926 req->nr_sectors, good_bytes)); 849 req->nr_sectors, good_bytes));
927 SCSI_LOG_HLCOMPLETE(1, printk("use_sg is %d\n", cmd->use_sg)); 850 SCSI_LOG_HLCOMPLETE(1, printk("use_sg is %d\n", cmd->use_sg));
928 851
929 if (clear_errors) 852 if (clear_errors)
930 req->errors = 0; 853 req->errors = 0;
931 /*
932 * If multiple sectors are requested in one buffer, then
933 * they will have been finished off by the first command.
934 * If not, then we have a multi-buffer command.
935 *
936 * If block_bytes != 0, it means we had a medium error
937 * of some sort, and that we want to mark some number of
938 * sectors as not uptodate. Thus we want to inhibit
939 * requeueing right here - we will requeue down below
940 * when we handle the bad sectors.
941 */
942 854
943 /* 855 /* A number of bytes were successfully read. If there
944 * If the command completed without error, then either 856 * are leftovers and there is some kind of error
945 * finish off the rest of the command, or start a new one. 857 * (result != 0), retry the rest.
946 */ 858 */
947 if (scsi_end_request(cmd, 1, good_bytes, result == 0) == NULL) 859 if (scsi_end_request(cmd, 1, good_bytes, result == 0) == NULL)
948 return; 860 return;
949 } 861
950 /* 862 /* good_bytes = 0, or (inclusive) there were leftovers and
951 * Now, if we were good little boys and girls, Santa left us a request 863 * result = 0, so scsi_end_request couldn't retry.
952 * sense buffer. We can extract information from this, so we
953 * can choose a block to remap, etc.
954 */ 864 */
955 if (sense_valid && !sense_deferred) { 865 if (sense_valid && !sense_deferred) {
956 switch (sshdr.sense_key) { 866 switch (sshdr.sense_key) {
957 case UNIT_ATTENTION: 867 case UNIT_ATTENTION:
958 if (cmd->device->removable) { 868 if (cmd->device->removable) {
959 /* detected disc change. set a bit 869 /* Detected disc change. Set a bit
960 * and quietly refuse further access. 870 * and quietly refuse further access.
961 */ 871 */
962 cmd->device->changed = 1; 872 cmd->device->changed = 1;
963 scsi_end_request(cmd, 0, 873 scsi_end_request(cmd, 0, this_count, 1);
964 this_count, 1);
965 return; 874 return;
966 } else { 875 } else {
967 /* 876 /* Must have been a power glitch, or a
968 * Must have been a power glitch, or a 877 * bus reset. Could not have been a
969 * bus reset. Could not have been a 878 * media change, so we just retry the
970 * media change, so we just retry the 879 * request and see what happens.
971 * request and see what happens. 880 */
972 */
973 scsi_requeue_command(q, cmd); 881 scsi_requeue_command(q, cmd);
974 return; 882 return;
975 } 883 }
976 break; 884 break;
977 case ILLEGAL_REQUEST: 885 case ILLEGAL_REQUEST:
978 /* 886 /* If we had an ILLEGAL REQUEST returned, then
979 * If we had an ILLEGAL REQUEST returned, then we may 887 * we may have performed an unsupported
980 * have performed an unsupported command. The only 888 * command. The only thing this should be
981 * thing this should be would be a ten byte read where 889 * would be a ten byte read where only a six
982 * only a six byte read was supported. Also, on a 890 * byte read was supported. Also, on a system
983 * system where READ CAPACITY failed, we may have read 891 * where READ CAPACITY failed, we may have
984 * past the end of the disk. 892 * read past the end of the disk.
985 */ 893 */
986 if ((cmd->device->use_10_for_rw && 894 if ((cmd->device->use_10_for_rw &&
987 sshdr.asc == 0x20 && sshdr.ascq == 0x00) && 895 sshdr.asc == 0x20 && sshdr.ascq == 0x00) &&
988 (cmd->cmnd[0] == READ_10 || 896 (cmd->cmnd[0] == READ_10 ||
989 cmd->cmnd[0] == WRITE_10)) { 897 cmd->cmnd[0] == WRITE_10)) {
990 cmd->device->use_10_for_rw = 0; 898 cmd->device->use_10_for_rw = 0;
991 /* 899 /* This will cause a retry with a
992 * This will cause a retry with a 6-byte 900 * 6-byte command.
993 * command.
994 */ 901 */
995 scsi_requeue_command(q, cmd); 902 scsi_requeue_command(q, cmd);
996 result = 0; 903 return;
997 } else { 904 } else {
998 scsi_end_request(cmd, 0, this_count, 1); 905 scsi_end_request(cmd, 0, this_count, 1);
999 return; 906 return;
1000 } 907 }
1001 break; 908 break;
1002 case NOT_READY: 909 case NOT_READY:
1003 /* 910 /* If the device is in the process of becoming
1004 * If the device is in the process of becoming
1005 * ready, or has a temporary blockage, retry. 911 * ready, or has a temporary blockage, retry.
1006 */ 912 */
1007 if (sshdr.asc == 0x04) { 913 if (sshdr.asc == 0x04) {
@@ -1021,7 +927,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
1021 } 927 }
1022 if (!(req->flags & REQ_QUIET)) { 928 if (!(req->flags & REQ_QUIET)) {
1023 scmd_printk(KERN_INFO, cmd, 929 scmd_printk(KERN_INFO, cmd,
1024 "Device not ready: "); 930 "Device not ready: ");
1025 scsi_print_sense_hdr("", &sshdr); 931 scsi_print_sense_hdr("", &sshdr);
1026 } 932 }
1027 scsi_end_request(cmd, 0, this_count, 1); 933 scsi_end_request(cmd, 0, this_count, 1);
@@ -1029,21 +935,21 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
1029 case VOLUME_OVERFLOW: 935 case VOLUME_OVERFLOW:
1030 if (!(req->flags & REQ_QUIET)) { 936 if (!(req->flags & REQ_QUIET)) {
1031 scmd_printk(KERN_INFO, cmd, 937 scmd_printk(KERN_INFO, cmd,
1032 "Volume overflow, CDB: "); 938 "Volume overflow, CDB: ");
1033 __scsi_print_command(cmd->data_cmnd); 939 __scsi_print_command(cmd->cmnd);
1034 scsi_print_sense("", cmd); 940 scsi_print_sense("", cmd);
1035 } 941 }
1036 scsi_end_request(cmd, 0, block_bytes, 1); 942 /* See SSC3rXX or current. */
943 scsi_end_request(cmd, 0, this_count, 1);
1037 return; 944 return;
1038 default: 945 default:
1039 break; 946 break;
1040 } 947 }
1041 } /* driver byte != 0 */ 948 }
1042 if (host_byte(result) == DID_RESET) { 949 if (host_byte(result) == DID_RESET) {
1043 /* 950 /* Third party bus reset or reset for error recovery
1044 * Third party bus reset or reset for error 951 * reasons. Just retry the request and see what
1045 * recovery reasons. Just retry the request 952 * happens.
1046 * and see what happens.
1047 */ 953 */
1048 scsi_requeue_command(q, cmd); 954 scsi_requeue_command(q, cmd);
1049 return; 955 return;
@@ -1051,21 +957,13 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
1051 if (result) { 957 if (result) {
1052 if (!(req->flags & REQ_QUIET)) { 958 if (!(req->flags & REQ_QUIET)) {
1053 scmd_printk(KERN_INFO, cmd, 959 scmd_printk(KERN_INFO, cmd,
1054 "SCSI error: return code = 0x%x\n", result); 960 "SCSI error: return code = 0x%08x\n",
1055 961 result);
1056 if (driver_byte(result) & DRIVER_SENSE) 962 if (driver_byte(result) & DRIVER_SENSE)
1057 scsi_print_sense("", cmd); 963 scsi_print_sense("", cmd);
1058 } 964 }
1059 /*
1060 * Mark a single buffer as not uptodate. Queue the remainder.
1061 * We sometimes get this cruft in the event that a medium error
1062 * isn't properly reported.
1063 */
1064 block_bytes = req->hard_cur_sectors << 9;
1065 if (!block_bytes)
1066 block_bytes = req->data_len;
1067 scsi_end_request(cmd, 0, block_bytes, 1);
1068 } 965 }
966 scsi_end_request(cmd, 0, this_count, !result);
1069} 967}
1070EXPORT_SYMBOL(scsi_io_completion); 968EXPORT_SYMBOL(scsi_io_completion);
1071 969
@@ -1169,7 +1067,7 @@ static void scsi_blk_pc_done(struct scsi_cmnd *cmd)
1169 * successfully. Since this is a REQ_BLOCK_PC command the 1067 * successfully. Since this is a REQ_BLOCK_PC command the
1170 * caller should check the request's errors value 1068 * caller should check the request's errors value
1171 */ 1069 */
1172 scsi_io_completion(cmd, cmd->bufflen, 0); 1070 scsi_io_completion(cmd, cmd->request_bufflen);
1173} 1071}
1174 1072
1175static void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd) 1073static void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd)
@@ -2050,6 +1948,7 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)
2050 switch (oldstate) { 1948 switch (oldstate) {
2051 case SDEV_CREATED: 1949 case SDEV_CREATED:
2052 case SDEV_RUNNING: 1950 case SDEV_RUNNING:
1951 case SDEV_QUIESCE:
2053 case SDEV_OFFLINE: 1952 case SDEV_OFFLINE:
2054 case SDEV_BLOCK: 1953 case SDEV_BLOCK:
2055 break; 1954 break;
@@ -2060,6 +1959,9 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)
2060 1959
2061 case SDEV_DEL: 1960 case SDEV_DEL:
2062 switch (oldstate) { 1961 switch (oldstate) {
1962 case SDEV_CREATED:
1963 case SDEV_RUNNING:
1964 case SDEV_OFFLINE:
2063 case SDEV_CANCEL: 1965 case SDEV_CANCEL:
2064 break; 1966 break;
2065 default: 1967 default:
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index 015c90cf3abc..ae24c85aaeea 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -57,7 +57,6 @@ extern int scsi_eh_scmd_add(struct scsi_cmnd *, int);
57 57
58/* scsi_lib.c */ 58/* scsi_lib.c */
59extern int scsi_maybe_unblock_host(struct scsi_device *sdev); 59extern int scsi_maybe_unblock_host(struct scsi_device *sdev);
60extern void scsi_setup_cmd_retry(struct scsi_cmnd *cmd);
61extern void scsi_device_unbusy(struct scsi_device *sdev); 60extern void scsi_device_unbusy(struct scsi_device *sdev);
62extern int scsi_queue_insert(struct scsi_cmnd *cmd, int reason); 61extern int scsi_queue_insert(struct scsi_cmnd *cmd, int reason);
63extern void scsi_next_command(struct scsi_cmnd *cmd); 62extern void scsi_next_command(struct scsi_cmnd *cmd);
@@ -116,7 +115,7 @@ extern struct bus_type scsi_bus_type;
116 * classes. 115 * classes.
117 */ 116 */
118 117
119#define SCSI_DEVICE_BLOCK_MAX_TIMEOUT (HZ*60) 118#define SCSI_DEVICE_BLOCK_MAX_TIMEOUT 600 /* units in seconds */
120extern int scsi_internal_device_block(struct scsi_device *sdev); 119extern int scsi_internal_device_block(struct scsi_device *sdev);
121extern int scsi_internal_device_unblock(struct scsi_device *sdev); 120extern int scsi_internal_device_unblock(struct scsi_device *sdev);
122 121
diff --git a/drivers/scsi/scsi_sas_internal.h b/drivers/scsi/scsi_sas_internal.h
index d76e6e3d8ca5..e1edab45a37b 100644
--- a/drivers/scsi/scsi_sas_internal.h
+++ b/drivers/scsi/scsi_sas_internal.h
@@ -2,7 +2,8 @@
2#define _SCSI_SAS_INTERNAL_H 2#define _SCSI_SAS_INTERNAL_H
3 3
4#define SAS_HOST_ATTRS 0 4#define SAS_HOST_ATTRS 0
5#define SAS_PORT_ATTRS 17 5#define SAS_PHY_ATTRS 17
6#define SAS_PORT_ATTRS 1
6#define SAS_RPORT_ATTRS 7 7#define SAS_RPORT_ATTRS 7
7#define SAS_END_DEV_ATTRS 3 8#define SAS_END_DEV_ATTRS 3
8#define SAS_EXPANDER_ATTRS 7 9#define SAS_EXPANDER_ATTRS 7
@@ -13,12 +14,14 @@ struct sas_internal {
13 struct sas_domain_function_template *dft; 14 struct sas_domain_function_template *dft;
14 15
15 struct class_device_attribute private_host_attrs[SAS_HOST_ATTRS]; 16 struct class_device_attribute private_host_attrs[SAS_HOST_ATTRS];
16 struct class_device_attribute private_phy_attrs[SAS_PORT_ATTRS]; 17 struct class_device_attribute private_phy_attrs[SAS_PHY_ATTRS];
18 struct class_device_attribute private_port_attrs[SAS_PORT_ATTRS];
17 struct class_device_attribute private_rphy_attrs[SAS_RPORT_ATTRS]; 19 struct class_device_attribute private_rphy_attrs[SAS_RPORT_ATTRS];
18 struct class_device_attribute private_end_dev_attrs[SAS_END_DEV_ATTRS]; 20 struct class_device_attribute private_end_dev_attrs[SAS_END_DEV_ATTRS];
19 struct class_device_attribute private_expander_attrs[SAS_EXPANDER_ATTRS]; 21 struct class_device_attribute private_expander_attrs[SAS_EXPANDER_ATTRS];
20 22
21 struct transport_container phy_attr_cont; 23 struct transport_container phy_attr_cont;
24 struct transport_container port_attr_cont;
22 struct transport_container rphy_attr_cont; 25 struct transport_container rphy_attr_cont;
23 struct transport_container end_dev_attr_cont; 26 struct transport_container end_dev_attr_cont;
24 struct transport_container expander_attr_cont; 27 struct transport_container expander_attr_cont;
@@ -28,7 +31,8 @@ struct sas_internal {
28 * needed by scsi_sysfs.c 31 * needed by scsi_sysfs.c
29 */ 32 */
30 struct class_device_attribute *host_attrs[SAS_HOST_ATTRS + 1]; 33 struct class_device_attribute *host_attrs[SAS_HOST_ATTRS + 1];
31 struct class_device_attribute *phy_attrs[SAS_PORT_ATTRS + 1]; 34 struct class_device_attribute *phy_attrs[SAS_PHY_ATTRS + 1];
35 struct class_device_attribute *port_attrs[SAS_PORT_ATTRS + 1];
32 struct class_device_attribute *rphy_attrs[SAS_RPORT_ATTRS + 1]; 36 struct class_device_attribute *rphy_attrs[SAS_RPORT_ATTRS + 1];
33 struct class_device_attribute *end_dev_attrs[SAS_END_DEV_ATTRS + 1]; 37 struct class_device_attribute *end_dev_attrs[SAS_END_DEV_ATTRS + 1];
34 struct class_device_attribute *expander_attrs[SAS_EXPANDER_ATTRS + 1]; 38 struct class_device_attribute *expander_attrs[SAS_EXPANDER_ATTRS + 1];
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 1341608e9e3b..1bd92b9b46d9 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -809,6 +809,7 @@ static int scsi_add_lun(struct scsi_device *sdev, char *inq_result, int *bflags)
809 809
810static inline void scsi_destroy_sdev(struct scsi_device *sdev) 810static inline void scsi_destroy_sdev(struct scsi_device *sdev)
811{ 811{
812 scsi_device_set_state(sdev, SDEV_DEL);
812 if (sdev->host->hostt->slave_destroy) 813 if (sdev->host->hostt->slave_destroy)
813 sdev->host->hostt->slave_destroy(sdev); 814 sdev->host->hostt->slave_destroy(sdev);
814 transport_destroy_device(&sdev->sdev_gendev); 815 transport_destroy_device(&sdev->sdev_gendev);
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index f2db7a41cf1d..b03aa85108e5 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -368,7 +368,7 @@ static DECLARE_TRANSPORT_CLASS(fc_rport_class,
368 * should insulate the loss of a remote port. 368 * should insulate the loss of a remote port.
369 * The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT. 369 * The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT.
370 */ 370 */
371static unsigned int fc_dev_loss_tmo = SCSI_DEVICE_BLOCK_MAX_TIMEOUT; 371static unsigned int fc_dev_loss_tmo = 60; /* seconds */
372 372
373module_param_named(dev_loss_tmo, fc_dev_loss_tmo, int, S_IRUGO|S_IWUSR); 373module_param_named(dev_loss_tmo, fc_dev_loss_tmo, int, S_IRUGO|S_IWUSR);
374MODULE_PARM_DESC(dev_loss_tmo, 374MODULE_PARM_DESC(dev_loss_tmo,
@@ -1284,7 +1284,9 @@ EXPORT_SYMBOL(fc_release_transport);
1284 * @work: Work to queue for execution. 1284 * @work: Work to queue for execution.
1285 * 1285 *
1286 * Return value: 1286 * Return value:
1287 * 0 on success / != 0 for error 1287 * 1 - work queued for execution
1288 * 0 - work is already queued
1289 * -EINVAL - work queue doesn't exist
1288 **/ 1290 **/
1289static int 1291static int
1290fc_queue_work(struct Scsi_Host *shost, struct work_struct *work) 1292fc_queue_work(struct Scsi_Host *shost, struct work_struct *work)
@@ -1434,8 +1436,6 @@ fc_starget_delete(void *data)
1434 struct Scsi_Host *shost = rport_to_shost(rport); 1436 struct Scsi_Host *shost = rport_to_shost(rport);
1435 unsigned long flags; 1437 unsigned long flags;
1436 1438
1437 scsi_target_unblock(&rport->dev);
1438
1439 spin_lock_irqsave(shost->host_lock, flags); 1439 spin_lock_irqsave(shost->host_lock, flags);
1440 if (rport->flags & FC_RPORT_DEVLOSS_PENDING) { 1440 if (rport->flags & FC_RPORT_DEVLOSS_PENDING) {
1441 spin_unlock_irqrestore(shost->host_lock, flags); 1441 spin_unlock_irqrestore(shost->host_lock, flags);
@@ -1476,7 +1476,8 @@ fc_rport_final_delete(void *data)
1476 transport_remove_device(dev); 1476 transport_remove_device(dev);
1477 device_del(dev); 1477 device_del(dev);
1478 transport_destroy_device(dev); 1478 transport_destroy_device(dev);
1479 put_device(&shost->shost_gendev); 1479 put_device(&shost->shost_gendev); /* for fc_host->rport list */
1480 put_device(dev); /* for self-reference */
1480} 1481}
1481 1482
1482 1483
@@ -1537,13 +1538,13 @@ fc_rport_create(struct Scsi_Host *shost, int channel,
1537 else 1538 else
1538 rport->scsi_target_id = -1; 1539 rport->scsi_target_id = -1;
1539 list_add_tail(&rport->peers, &fc_host->rports); 1540 list_add_tail(&rport->peers, &fc_host->rports);
1540 get_device(&shost->shost_gendev); 1541 get_device(&shost->shost_gendev); /* for fc_host->rport list */
1541 1542
1542 spin_unlock_irqrestore(shost->host_lock, flags); 1543 spin_unlock_irqrestore(shost->host_lock, flags);
1543 1544
1544 dev = &rport->dev; 1545 dev = &rport->dev;
1545 device_initialize(dev); 1546 device_initialize(dev); /* takes self reference */
1546 dev->parent = get_device(&shost->shost_gendev); 1547 dev->parent = get_device(&shost->shost_gendev); /* parent reference */
1547 dev->release = fc_rport_dev_release; 1548 dev->release = fc_rport_dev_release;
1548 sprintf(dev->bus_id, "rport-%d:%d-%d", 1549 sprintf(dev->bus_id, "rport-%d:%d-%d",
1549 shost->host_no, channel, rport->number); 1550 shost->host_no, channel, rport->number);
@@ -1567,10 +1568,9 @@ fc_rport_create(struct Scsi_Host *shost, int channel,
1567 1568
1568delete_rport: 1569delete_rport:
1569 transport_destroy_device(dev); 1570 transport_destroy_device(dev);
1570 put_device(dev->parent);
1571 spin_lock_irqsave(shost->host_lock, flags); 1571 spin_lock_irqsave(shost->host_lock, flags);
1572 list_del(&rport->peers); 1572 list_del(&rport->peers);
1573 put_device(&shost->shost_gendev); 1573 put_device(&shost->shost_gendev); /* for fc_host->rport list */
1574 spin_unlock_irqrestore(shost->host_lock, flags); 1574 spin_unlock_irqrestore(shost->host_lock, flags);
1575 put_device(dev->parent); 1575 put_device(dev->parent);
1576 kfree(rport); 1576 kfree(rport);
@@ -1707,6 +1707,8 @@ fc_remote_port_add(struct Scsi_Host *shost, int channel,
1707 1707
1708 spin_unlock_irqrestore(shost->host_lock, flags); 1708 spin_unlock_irqrestore(shost->host_lock, flags);
1709 1709
1710 scsi_target_unblock(&rport->dev);
1711
1710 return rport; 1712 return rport;
1711 } 1713 }
1712 } 1714 }
@@ -1762,9 +1764,10 @@ fc_remote_port_add(struct Scsi_Host *shost, int channel,
1762 /* initiate a scan of the target */ 1764 /* initiate a scan of the target */
1763 rport->flags |= FC_RPORT_SCAN_PENDING; 1765 rport->flags |= FC_RPORT_SCAN_PENDING;
1764 scsi_queue_work(shost, &rport->scan_work); 1766 scsi_queue_work(shost, &rport->scan_work);
1765 } 1767 spin_unlock_irqrestore(shost->host_lock, flags);
1766 1768 scsi_target_unblock(&rport->dev);
1767 spin_unlock_irqrestore(shost->host_lock, flags); 1769 } else
1770 spin_unlock_irqrestore(shost->host_lock, flags);
1768 1771
1769 return rport; 1772 return rport;
1770 } 1773 }
@@ -1938,6 +1941,7 @@ fc_remote_port_rolechg(struct fc_rport *rport, u32 roles)
1938 rport->flags |= FC_RPORT_SCAN_PENDING; 1941 rport->flags |= FC_RPORT_SCAN_PENDING;
1939 scsi_queue_work(shost, &rport->scan_work); 1942 scsi_queue_work(shost, &rport->scan_work);
1940 spin_unlock_irqrestore(shost->host_lock, flags); 1943 spin_unlock_irqrestore(shost->host_lock, flags);
1944 scsi_target_unblock(&rport->dev);
1941 } 1945 }
1942} 1946}
1943EXPORT_SYMBOL(fc_remote_port_rolechg); 1947EXPORT_SYMBOL(fc_remote_port_rolechg);
@@ -1970,8 +1974,9 @@ fc_timeout_deleted_rport(void *data)
1970 dev_printk(KERN_ERR, &rport->dev, 1974 dev_printk(KERN_ERR, &rport->dev,
1971 "blocked FC remote port time out: no longer" 1975 "blocked FC remote port time out: no longer"
1972 " a FCP target, removing starget\n"); 1976 " a FCP target, removing starget\n");
1973 fc_queue_work(shost, &rport->stgt_delete_work);
1974 spin_unlock_irqrestore(shost->host_lock, flags); 1977 spin_unlock_irqrestore(shost->host_lock, flags);
1978 scsi_target_unblock(&rport->dev);
1979 fc_queue_work(shost, &rport->stgt_delete_work);
1975 return; 1980 return;
1976 } 1981 }
1977 1982
@@ -2035,17 +2040,15 @@ fc_timeout_deleted_rport(void *data)
2035 * went away and didn't come back - we'll remove 2040 * went away and didn't come back - we'll remove
2036 * all attached scsi devices. 2041 * all attached scsi devices.
2037 */ 2042 */
2038 fc_queue_work(shost, &rport->stgt_delete_work);
2039
2040 spin_unlock_irqrestore(shost->host_lock, flags); 2043 spin_unlock_irqrestore(shost->host_lock, flags);
2044
2045 scsi_target_unblock(&rport->dev);
2046 fc_queue_work(shost, &rport->stgt_delete_work);
2041} 2047}
2042 2048
2043/** 2049/**
2044 * fc_scsi_scan_rport - called to perform a scsi scan on a remote port. 2050 * fc_scsi_scan_rport - called to perform a scsi scan on a remote port.
2045 * 2051 *
2046 * Will unblock the target (in case it went away and has now come back),
2047 * then invoke a scan.
2048 *
2049 * @data: remote port to be scanned. 2052 * @data: remote port to be scanned.
2050 **/ 2053 **/
2051static void 2054static void
@@ -2057,7 +2060,6 @@ fc_scsi_scan_rport(void *data)
2057 2060
2058 if ((rport->port_state == FC_PORTSTATE_ONLINE) && 2061 if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
2059 (rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { 2062 (rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
2060 scsi_target_unblock(&rport->dev);
2061 scsi_scan_target(&rport->dev, rport->channel, 2063 scsi_scan_target(&rport->dev, rport->channel,
2062 rport->scsi_target_id, SCAN_WILD_CARD, 1); 2064 rport->scsi_target_id, SCAN_WILD_CARD, 1);
2063 } 2065 }
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 5569fdcfd621..2ecd14188574 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -34,6 +34,7 @@
34#define ISCSI_SESSION_ATTRS 11 34#define ISCSI_SESSION_ATTRS 11
35#define ISCSI_CONN_ATTRS 11 35#define ISCSI_CONN_ATTRS 11
36#define ISCSI_HOST_ATTRS 0 36#define ISCSI_HOST_ATTRS 0
37#define ISCSI_TRANSPORT_VERSION "1.1-646"
37 38
38struct iscsi_internal { 39struct iscsi_internal {
39 int daemon_pid; 40 int daemon_pid;
@@ -228,14 +229,11 @@ static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid)
228static void iscsi_session_release(struct device *dev) 229static void iscsi_session_release(struct device *dev)
229{ 230{
230 struct iscsi_cls_session *session = iscsi_dev_to_session(dev); 231 struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
231 struct iscsi_transport *transport = session->transport;
232 struct Scsi_Host *shost; 232 struct Scsi_Host *shost;
233 233
234 shost = iscsi_session_to_shost(session); 234 shost = iscsi_session_to_shost(session);
235 scsi_host_put(shost); 235 scsi_host_put(shost);
236 kfree(session->targetname);
237 kfree(session); 236 kfree(session);
238 module_put(transport->owner);
239} 237}
240 238
241static int iscsi_is_session_dev(const struct device *dev) 239static int iscsi_is_session_dev(const struct device *dev)
@@ -251,10 +249,9 @@ static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
251 249
252 mutex_lock(&ihost->mutex); 250 mutex_lock(&ihost->mutex);
253 list_for_each_entry(session, &ihost->sessions, host_list) { 251 list_for_each_entry(session, &ihost->sessions, host_list) {
254 if ((channel == SCAN_WILD_CARD || 252 if ((channel == SCAN_WILD_CARD || channel == 0) &&
255 channel == session->channel) &&
256 (id == SCAN_WILD_CARD || id == session->target_id)) 253 (id == SCAN_WILD_CARD || id == session->target_id))
257 scsi_scan_target(&session->dev, session->channel, 254 scsi_scan_target(&session->dev, 0,
258 session->target_id, lun, 1); 255 session->target_id, lun, 1);
259 } 256 }
260 mutex_unlock(&ihost->mutex); 257 mutex_unlock(&ihost->mutex);
@@ -291,80 +288,92 @@ void iscsi_block_session(struct iscsi_cls_session *session)
291} 288}
292EXPORT_SYMBOL_GPL(iscsi_block_session); 289EXPORT_SYMBOL_GPL(iscsi_block_session);
293 290
294/**
295 * iscsi_create_session - create iscsi class session
296 * @shost: scsi host
297 * @transport: iscsi transport
298 *
299 * This can be called from a LLD or iscsi_transport.
300 **/
301struct iscsi_cls_session * 291struct iscsi_cls_session *
302iscsi_create_session(struct Scsi_Host *shost, 292iscsi_alloc_session(struct Scsi_Host *shost,
303 struct iscsi_transport *transport, int channel) 293 struct iscsi_transport *transport)
304{ 294{
305 struct iscsi_host *ihost;
306 struct iscsi_cls_session *session; 295 struct iscsi_cls_session *session;
307 int err;
308
309 if (!try_module_get(transport->owner))
310 return NULL;
311 296
312 session = kzalloc(sizeof(*session) + transport->sessiondata_size, 297 session = kzalloc(sizeof(*session) + transport->sessiondata_size,
313 GFP_KERNEL); 298 GFP_KERNEL);
314 if (!session) 299 if (!session)
315 goto module_put; 300 return NULL;
301
316 session->transport = transport; 302 session->transport = transport;
317 session->recovery_tmo = 120; 303 session->recovery_tmo = 120;
318 INIT_WORK(&session->recovery_work, session_recovery_timedout, session); 304 INIT_WORK(&session->recovery_work, session_recovery_timedout, session);
319 INIT_LIST_HEAD(&session->host_list); 305 INIT_LIST_HEAD(&session->host_list);
320 INIT_LIST_HEAD(&session->sess_list); 306 INIT_LIST_HEAD(&session->sess_list);
321 307
308 /* this is released in the dev's release function */
309 scsi_host_get(shost);
310 session->dev.parent = &shost->shost_gendev;
311 session->dev.release = iscsi_session_release;
312 device_initialize(&session->dev);
322 if (transport->sessiondata_size) 313 if (transport->sessiondata_size)
323 session->dd_data = &session[1]; 314 session->dd_data = &session[1];
315 return session;
316}
317EXPORT_SYMBOL_GPL(iscsi_alloc_session);
324 318
325 /* this is released in the dev's release function */ 319int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
326 scsi_host_get(shost); 320{
327 ihost = shost->shost_data; 321 struct Scsi_Host *shost = iscsi_session_to_shost(session);
322 struct iscsi_host *ihost;
323 int err;
328 324
325 ihost = shost->shost_data;
329 session->sid = iscsi_session_nr++; 326 session->sid = iscsi_session_nr++;
330 session->channel = channel; 327 session->target_id = target_id;
331 session->target_id = ihost->next_target_id++;
332 328
333 snprintf(session->dev.bus_id, BUS_ID_SIZE, "session%u", 329 snprintf(session->dev.bus_id, BUS_ID_SIZE, "session%u",
334 session->sid); 330 session->sid);
335 session->dev.parent = &shost->shost_gendev; 331 err = device_add(&session->dev);
336 session->dev.release = iscsi_session_release;
337 err = device_register(&session->dev);
338 if (err) { 332 if (err) {
339 dev_printk(KERN_ERR, &session->dev, "iscsi: could not " 333 dev_printk(KERN_ERR, &session->dev, "iscsi: could not "
340 "register session's dev\n"); 334 "register session's dev\n");
341 goto free_session; 335 goto release_host;
342 } 336 }
343 transport_register_device(&session->dev); 337 transport_register_device(&session->dev);
344 338
345 mutex_lock(&ihost->mutex); 339 mutex_lock(&ihost->mutex);
346 list_add(&session->host_list, &ihost->sessions); 340 list_add(&session->host_list, &ihost->sessions);
347 mutex_unlock(&ihost->mutex); 341 mutex_unlock(&ihost->mutex);
342 return 0;
348 343
349 return session; 344release_host:
350 345 scsi_host_put(shost);
351free_session: 346 return err;
352 kfree(session);
353module_put:
354 module_put(transport->owner);
355 return NULL;
356} 347}
357 348EXPORT_SYMBOL_GPL(iscsi_add_session);
358EXPORT_SYMBOL_GPL(iscsi_create_session);
359 349
360/** 350/**
361 * iscsi_destroy_session - destroy iscsi session 351 * iscsi_create_session - create iscsi class session
362 * @session: iscsi_session 352 * @shost: scsi host
353 * @transport: iscsi transport
363 * 354 *
364 * Can be called by a LLD or iscsi_transport. There must not be 355 * This can be called from a LLD or iscsi_transport.
365 * any running connections.
366 **/ 356 **/
367int iscsi_destroy_session(struct iscsi_cls_session *session) 357struct iscsi_cls_session *
358iscsi_create_session(struct Scsi_Host *shost,
359 struct iscsi_transport *transport,
360 unsigned int target_id)
361{
362 struct iscsi_cls_session *session;
363
364 session = iscsi_alloc_session(shost, transport);
365 if (!session)
366 return NULL;
367
368 if (iscsi_add_session(session, target_id)) {
369 iscsi_free_session(session);
370 return NULL;
371 }
372 return session;
373}
374EXPORT_SYMBOL_GPL(iscsi_create_session);
375
376void iscsi_remove_session(struct iscsi_cls_session *session)
368{ 377{
369 struct Scsi_Host *shost = iscsi_session_to_shost(session); 378 struct Scsi_Host *shost = iscsi_session_to_shost(session);
370 struct iscsi_host *ihost = shost->shost_data; 379 struct iscsi_host *ihost = shost->shost_data;
@@ -376,19 +385,88 @@ int iscsi_destroy_session(struct iscsi_cls_session *session)
376 list_del(&session->host_list); 385 list_del(&session->host_list);
377 mutex_unlock(&ihost->mutex); 386 mutex_unlock(&ihost->mutex);
378 387
388 scsi_remove_target(&session->dev);
389
379 transport_unregister_device(&session->dev); 390 transport_unregister_device(&session->dev);
380 device_unregister(&session->dev); 391 device_del(&session->dev);
381 return 0; 392}
393EXPORT_SYMBOL_GPL(iscsi_remove_session);
394
395void iscsi_free_session(struct iscsi_cls_session *session)
396{
397 put_device(&session->dev);
382} 398}
383 399
400EXPORT_SYMBOL_GPL(iscsi_free_session);
401
402/**
403 * iscsi_destroy_session - destroy iscsi session
404 * @session: iscsi_session
405 *
406 * Can be called by a LLD or iscsi_transport. There must not be
407 * any running connections.
408 **/
409int iscsi_destroy_session(struct iscsi_cls_session *session)
410{
411 iscsi_remove_session(session);
412 iscsi_free_session(session);
413 return 0;
414}
384EXPORT_SYMBOL_GPL(iscsi_destroy_session); 415EXPORT_SYMBOL_GPL(iscsi_destroy_session);
385 416
417static void mempool_zone_destroy(struct mempool_zone *zp)
418{
419 mempool_destroy(zp->pool);
420 kfree(zp);
421}
422
423static void*
424mempool_zone_alloc_skb(gfp_t gfp_mask, void *pool_data)
425{
426 struct mempool_zone *zone = pool_data;
427
428 return alloc_skb(zone->size, gfp_mask);
429}
430
431static void
432mempool_zone_free_skb(void *element, void *pool_data)
433{
434 kfree_skb(element);
435}
436
437static struct mempool_zone *
438mempool_zone_init(unsigned max, unsigned size, unsigned hiwat)
439{
440 struct mempool_zone *zp;
441
442 zp = kzalloc(sizeof(*zp), GFP_KERNEL);
443 if (!zp)
444 return NULL;
445
446 zp->size = size;
447 zp->hiwat = hiwat;
448 INIT_LIST_HEAD(&zp->freequeue);
449 spin_lock_init(&zp->freelock);
450 atomic_set(&zp->allocated, 0);
451
452 zp->pool = mempool_create(max, mempool_zone_alloc_skb,
453 mempool_zone_free_skb, zp);
454 if (!zp->pool) {
455 kfree(zp);
456 return NULL;
457 }
458
459 return zp;
460}
461
386static void iscsi_conn_release(struct device *dev) 462static void iscsi_conn_release(struct device *dev)
387{ 463{
388 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev); 464 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev);
389 struct device *parent = conn->dev.parent; 465 struct device *parent = conn->dev.parent;
390 466
391 kfree(conn->persistent_address); 467 mempool_zone_destroy(conn->z_pdu);
468 mempool_zone_destroy(conn->z_error);
469
392 kfree(conn); 470 kfree(conn);
393 put_device(parent); 471 put_device(parent);
394} 472}
@@ -398,6 +476,31 @@ static int iscsi_is_conn_dev(const struct device *dev)
398 return dev->release == iscsi_conn_release; 476 return dev->release == iscsi_conn_release;
399} 477}
400 478
479static int iscsi_create_event_pools(struct iscsi_cls_conn *conn)
480{
481 conn->z_pdu = mempool_zone_init(Z_MAX_PDU,
482 NLMSG_SPACE(sizeof(struct iscsi_uevent) +
483 sizeof(struct iscsi_hdr) +
484 DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH),
485 Z_HIWAT_PDU);
486 if (!conn->z_pdu) {
487 dev_printk(KERN_ERR, &conn->dev, "iscsi: can not allocate "
488 "pdu zone for new conn\n");
489 return -ENOMEM;
490 }
491
492 conn->z_error = mempool_zone_init(Z_MAX_ERROR,
493 NLMSG_SPACE(sizeof(struct iscsi_uevent)),
494 Z_HIWAT_ERROR);
495 if (!conn->z_error) {
496 dev_printk(KERN_ERR, &conn->dev, "iscsi: can not allocate "
497 "error zone for new conn\n");
498 mempool_zone_destroy(conn->z_pdu);
499 return -ENOMEM;
500 }
501 return 0;
502}
503
401/** 504/**
402 * iscsi_create_conn - create iscsi class connection 505 * iscsi_create_conn - create iscsi class connection
403 * @session: iscsi cls session 506 * @session: iscsi cls session
@@ -430,9 +533,12 @@ iscsi_create_conn(struct iscsi_cls_session *session, uint32_t cid)
430 conn->transport = transport; 533 conn->transport = transport;
431 conn->cid = cid; 534 conn->cid = cid;
432 535
536 if (iscsi_create_event_pools(conn))
537 goto free_conn;
538
433 /* this is released in the dev's release function */ 539 /* this is released in the dev's release function */
434 if (!get_device(&session->dev)) 540 if (!get_device(&session->dev))
435 goto free_conn; 541 goto free_conn_pools;
436 542
437 snprintf(conn->dev.bus_id, BUS_ID_SIZE, "connection%d:%u", 543 snprintf(conn->dev.bus_id, BUS_ID_SIZE, "connection%d:%u",
438 session->sid, cid); 544 session->sid, cid);
@@ -449,6 +555,8 @@ iscsi_create_conn(struct iscsi_cls_session *session, uint32_t cid)
449 555
450release_parent_ref: 556release_parent_ref:
451 put_device(&session->dev); 557 put_device(&session->dev);
558free_conn_pools:
559
452free_conn: 560free_conn:
453 kfree(conn); 561 kfree(conn);
454 return NULL; 562 return NULL;
@@ -496,20 +604,6 @@ static inline struct list_head *skb_to_lh(struct sk_buff *skb)
496 return (struct list_head *)&skb->cb; 604 return (struct list_head *)&skb->cb;
497} 605}
498 606
499static void*
500mempool_zone_alloc_skb(gfp_t gfp_mask, void *pool_data)
501{
502 struct mempool_zone *zone = pool_data;
503
504 return alloc_skb(zone->size, gfp_mask);
505}
506
507static void
508mempool_zone_free_skb(void *element, void *pool_data)
509{
510 kfree_skb(element);
511}
512
513static void 607static void
514mempool_zone_complete(struct mempool_zone *zone) 608mempool_zone_complete(struct mempool_zone *zone)
515{ 609{
@@ -529,37 +623,6 @@ mempool_zone_complete(struct mempool_zone *zone)
529 spin_unlock_irqrestore(&zone->freelock, flags); 623 spin_unlock_irqrestore(&zone->freelock, flags);
530} 624}
531 625
532static struct mempool_zone *
533mempool_zone_init(unsigned max, unsigned size, unsigned hiwat)
534{
535 struct mempool_zone *zp;
536
537 zp = kzalloc(sizeof(*zp), GFP_KERNEL);
538 if (!zp)
539 return NULL;
540
541 zp->size = size;
542 zp->hiwat = hiwat;
543 INIT_LIST_HEAD(&zp->freequeue);
544 spin_lock_init(&zp->freelock);
545 atomic_set(&zp->allocated, 0);
546
547 zp->pool = mempool_create(max, mempool_zone_alloc_skb,
548 mempool_zone_free_skb, zp);
549 if (!zp->pool) {
550 kfree(zp);
551 return NULL;
552 }
553
554 return zp;
555}
556
557static void mempool_zone_destroy(struct mempool_zone *zp)
558{
559 mempool_destroy(zp->pool);
560 kfree(zp);
561}
562
563static struct sk_buff* 626static struct sk_buff*
564mempool_zone_get_skb(struct mempool_zone *zone) 627mempool_zone_get_skb(struct mempool_zone *zone)
565{ 628{
@@ -572,6 +635,27 @@ mempool_zone_get_skb(struct mempool_zone *zone)
572} 635}
573 636
574static int 637static int
638iscsi_broadcast_skb(struct mempool_zone *zone, struct sk_buff *skb, gfp_t gfp)
639{
640 unsigned long flags;
641 int rc;
642
643 skb_get(skb);
644 rc = netlink_broadcast(nls, skb, 0, 1, gfp);
645 if (rc < 0) {
646 mempool_free(skb, zone->pool);
647 printk(KERN_ERR "iscsi: can not broadcast skb (%d)\n", rc);
648 return rc;
649 }
650
651 spin_lock_irqsave(&zone->freelock, flags);
652 INIT_LIST_HEAD(skb_to_lh(skb));
653 list_add(skb_to_lh(skb), &zone->freequeue);
654 spin_unlock_irqrestore(&zone->freelock, flags);
655 return 0;
656}
657
658static int
575iscsi_unicast_skb(struct mempool_zone *zone, struct sk_buff *skb, int pid) 659iscsi_unicast_skb(struct mempool_zone *zone, struct sk_buff *skb, int pid)
576{ 660{
577 unsigned long flags; 661 unsigned long flags;
@@ -666,7 +750,7 @@ void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error)
666 ev->r.connerror.cid = conn->cid; 750 ev->r.connerror.cid = conn->cid;
667 ev->r.connerror.sid = iscsi_conn_get_sid(conn); 751 ev->r.connerror.sid = iscsi_conn_get_sid(conn);
668 752
669 iscsi_unicast_skb(conn->z_error, skb, priv->daemon_pid); 753 iscsi_broadcast_skb(conn->z_error, skb, GFP_ATOMIC);
670 754
671 dev_printk(KERN_INFO, &conn->dev, "iscsi: detected conn error (%d)\n", 755 dev_printk(KERN_INFO, &conn->dev, "iscsi: detected conn error (%d)\n",
672 error); 756 error);
@@ -767,6 +851,131 @@ iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
767 return err; 851 return err;
768} 852}
769 853
854/**
855 * iscsi_if_destroy_session_done - send session destr. completion event
856 * @conn: last connection for session
857 *
858 * This is called by HW iscsi LLDs to notify userpsace that its HW has
859 * removed a session.
860 **/
861int iscsi_if_destroy_session_done(struct iscsi_cls_conn *conn)
862{
863 struct iscsi_internal *priv;
864 struct iscsi_cls_session *session;
865 struct Scsi_Host *shost;
866 struct iscsi_uevent *ev;
867 struct sk_buff *skb;
868 struct nlmsghdr *nlh;
869 unsigned long flags;
870 int rc, len = NLMSG_SPACE(sizeof(*ev));
871
872 priv = iscsi_if_transport_lookup(conn->transport);
873 if (!priv)
874 return -EINVAL;
875
876 session = iscsi_dev_to_session(conn->dev.parent);
877 shost = iscsi_session_to_shost(session);
878
879 mempool_zone_complete(conn->z_pdu);
880
881 skb = mempool_zone_get_skb(conn->z_pdu);
882 if (!skb) {
883 dev_printk(KERN_ERR, &conn->dev, "Cannot notify userspace of "
884 "session creation event\n");
885 return -ENOMEM;
886 }
887
888 nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
889 ev = NLMSG_DATA(nlh);
890 ev->transport_handle = iscsi_handle(conn->transport);
891 ev->type = ISCSI_KEVENT_DESTROY_SESSION;
892 ev->r.d_session.host_no = shost->host_no;
893 ev->r.d_session.sid = session->sid;
894
895 /*
896 * this will occur if the daemon is not up, so we just warn
897 * the user and when the daemon is restarted it will handle it
898 */
899 rc = iscsi_broadcast_skb(conn->z_pdu, skb, GFP_KERNEL);
900 if (rc < 0)
901 dev_printk(KERN_ERR, &conn->dev, "Cannot notify userspace of "
902 "session destruction event. Check iscsi daemon\n");
903
904 spin_lock_irqsave(&sesslock, flags);
905 list_del(&session->sess_list);
906 spin_unlock_irqrestore(&sesslock, flags);
907
908 spin_lock_irqsave(&connlock, flags);
909 conn->active = 0;
910 list_del(&conn->conn_list);
911 spin_unlock_irqrestore(&connlock, flags);
912
913 return rc;
914}
915EXPORT_SYMBOL_GPL(iscsi_if_destroy_session_done);
916
917/**
918 * iscsi_if_create_session_done - send session creation completion event
919 * @conn: leading connection for session
920 *
921 * This is called by HW iscsi LLDs to notify userpsace that its HW has
922 * created a session or a existing session is back in the logged in state.
923 **/
924int iscsi_if_create_session_done(struct iscsi_cls_conn *conn)
925{
926 struct iscsi_internal *priv;
927 struct iscsi_cls_session *session;
928 struct Scsi_Host *shost;
929 struct iscsi_uevent *ev;
930 struct sk_buff *skb;
931 struct nlmsghdr *nlh;
932 unsigned long flags;
933 int rc, len = NLMSG_SPACE(sizeof(*ev));
934
935 priv = iscsi_if_transport_lookup(conn->transport);
936 if (!priv)
937 return -EINVAL;
938
939 session = iscsi_dev_to_session(conn->dev.parent);
940 shost = iscsi_session_to_shost(session);
941
942 mempool_zone_complete(conn->z_pdu);
943
944 skb = mempool_zone_get_skb(conn->z_pdu);
945 if (!skb) {
946 dev_printk(KERN_ERR, &conn->dev, "Cannot notify userspace of "
947 "session creation event\n");
948 return -ENOMEM;
949 }
950
951 nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
952 ev = NLMSG_DATA(nlh);
953 ev->transport_handle = iscsi_handle(conn->transport);
954 ev->type = ISCSI_UEVENT_CREATE_SESSION;
955 ev->r.c_session_ret.host_no = shost->host_no;
956 ev->r.c_session_ret.sid = session->sid;
957
958 /*
959 * this will occur if the daemon is not up, so we just warn
960 * the user and when the daemon is restarted it will handle it
961 */
962 rc = iscsi_broadcast_skb(conn->z_pdu, skb, GFP_KERNEL);
963 if (rc < 0)
964 dev_printk(KERN_ERR, &conn->dev, "Cannot notify userspace of "
965 "session creation event. Check iscsi daemon\n");
966
967 spin_lock_irqsave(&sesslock, flags);
968 list_add(&session->sess_list, &sesslist);
969 spin_unlock_irqrestore(&sesslock, flags);
970
971 spin_lock_irqsave(&connlock, flags);
972 list_add(&conn->conn_list, &connlist);
973 conn->active = 1;
974 spin_unlock_irqrestore(&connlock, flags);
975 return rc;
976}
977EXPORT_SYMBOL_GPL(iscsi_if_create_session_done);
978
770static int 979static int
771iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_uevent *ev) 980iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_uevent *ev)
772{ 981{
@@ -812,26 +1021,6 @@ iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
812 return -ENOMEM; 1021 return -ENOMEM;
813 } 1022 }
814 1023
815 conn->z_pdu = mempool_zone_init(Z_MAX_PDU,
816 NLMSG_SPACE(sizeof(struct iscsi_uevent) +
817 sizeof(struct iscsi_hdr) +
818 DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH),
819 Z_HIWAT_PDU);
820 if (!conn->z_pdu) {
821 dev_printk(KERN_ERR, &conn->dev, "iscsi: can not allocate "
822 "pdu zone for new conn\n");
823 goto destroy_conn;
824 }
825
826 conn->z_error = mempool_zone_init(Z_MAX_ERROR,
827 NLMSG_SPACE(sizeof(struct iscsi_uevent)),
828 Z_HIWAT_ERROR);
829 if (!conn->z_error) {
830 dev_printk(KERN_ERR, &conn->dev, "iscsi: can not allocate "
831 "error zone for new conn\n");
832 goto free_pdu_pool;
833 }
834
835 ev->r.c_conn_ret.sid = session->sid; 1024 ev->r.c_conn_ret.sid = session->sid;
836 ev->r.c_conn_ret.cid = conn->cid; 1025 ev->r.c_conn_ret.cid = conn->cid;
837 1026
@@ -841,13 +1030,6 @@ iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
841 spin_unlock_irqrestore(&connlock, flags); 1030 spin_unlock_irqrestore(&connlock, flags);
842 1031
843 return 0; 1032 return 0;
844
845free_pdu_pool:
846 mempool_zone_destroy(conn->z_pdu);
847destroy_conn:
848 if (transport->destroy_conn)
849 transport->destroy_conn(conn->dd_data);
850 return -ENOMEM;
851} 1033}
852 1034
853static int 1035static int
@@ -855,7 +1037,6 @@ iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev
855{ 1037{
856 unsigned long flags; 1038 unsigned long flags;
857 struct iscsi_cls_conn *conn; 1039 struct iscsi_cls_conn *conn;
858 struct mempool_zone *z_error, *z_pdu;
859 1040
860 conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid); 1041 conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid);
861 if (!conn) 1042 if (!conn)
@@ -865,35 +1046,18 @@ iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev
865 list_del(&conn->conn_list); 1046 list_del(&conn->conn_list);
866 spin_unlock_irqrestore(&connlock, flags); 1047 spin_unlock_irqrestore(&connlock, flags);
867 1048
868 z_pdu = conn->z_pdu;
869 z_error = conn->z_error;
870
871 if (transport->destroy_conn) 1049 if (transport->destroy_conn)
872 transport->destroy_conn(conn); 1050 transport->destroy_conn(conn);
873
874 mempool_zone_destroy(z_pdu);
875 mempool_zone_destroy(z_error);
876
877 return 0; 1051 return 0;
878} 1052}
879 1053
880static void
881iscsi_copy_param(struct iscsi_uevent *ev, uint32_t *value, char *data)
882{
883 if (ev->u.set_param.len != sizeof(uint32_t))
884 BUG();
885 memcpy(value, data, min_t(uint32_t, sizeof(uint32_t),
886 ev->u.set_param.len));
887}
888
889static int 1054static int
890iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev) 1055iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
891{ 1056{
892 char *data = (char*)ev + sizeof(*ev); 1057 char *data = (char*)ev + sizeof(*ev);
893 struct iscsi_cls_conn *conn; 1058 struct iscsi_cls_conn *conn;
894 struct iscsi_cls_session *session; 1059 struct iscsi_cls_session *session;
895 int err = 0; 1060 int err = 0, value = 0;
896 uint32_t value = 0;
897 1061
898 session = iscsi_session_lookup(ev->u.set_param.sid); 1062 session = iscsi_session_lookup(ev->u.set_param.sid);
899 conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid); 1063 conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
@@ -902,42 +1066,13 @@ iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
902 1066
903 switch (ev->u.set_param.param) { 1067 switch (ev->u.set_param.param) {
904 case ISCSI_PARAM_SESS_RECOVERY_TMO: 1068 case ISCSI_PARAM_SESS_RECOVERY_TMO:
905 iscsi_copy_param(ev, &value, data); 1069 sscanf(data, "%d", &value);
906 if (value != 0) 1070 if (value != 0)
907 session->recovery_tmo = value; 1071 session->recovery_tmo = value;
908 break; 1072 break;
909 case ISCSI_PARAM_TARGET_NAME:
910 /* this should not change between logins */
911 if (session->targetname)
912 return 0;
913
914 session->targetname = kstrdup(data, GFP_KERNEL);
915 if (!session->targetname)
916 return -ENOMEM;
917 break;
918 case ISCSI_PARAM_TPGT:
919 iscsi_copy_param(ev, &value, data);
920 session->tpgt = value;
921 break;
922 case ISCSI_PARAM_PERSISTENT_PORT:
923 iscsi_copy_param(ev, &value, data);
924 conn->persistent_port = value;
925 break;
926 case ISCSI_PARAM_PERSISTENT_ADDRESS:
927 /*
928 * this is the address returned in discovery so it should
929 * not change between logins.
930 */
931 if (conn->persistent_address)
932 return 0;
933
934 conn->persistent_address = kstrdup(data, GFP_KERNEL);
935 if (!conn->persistent_address)
936 return -ENOMEM;
937 break;
938 default: 1073 default:
939 iscsi_copy_param(ev, &value, data); 1074 err = transport->set_param(conn, ev->u.set_param.param,
940 err = transport->set_param(conn, ev->u.set_param.param, value); 1075 data, ev->u.set_param.len);
941 } 1076 }
942 1077
943 return err; 1078 return err;
@@ -978,6 +1113,21 @@ iscsi_if_transport_ep(struct iscsi_transport *transport,
978} 1113}
979 1114
980static int 1115static int
1116iscsi_tgt_dscvr(struct iscsi_transport *transport,
1117 struct iscsi_uevent *ev)
1118{
1119 struct sockaddr *dst_addr;
1120
1121 if (!transport->tgt_dscvr)
1122 return -EINVAL;
1123
1124 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
1125 return transport->tgt_dscvr(ev->u.tgt_dscvr.type,
1126 ev->u.tgt_dscvr.host_no,
1127 ev->u.tgt_dscvr.enable, dst_addr);
1128}
1129
1130static int
981iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) 1131iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
982{ 1132{
983 int err = 0; 1133 int err = 0;
@@ -1065,6 +1215,9 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1065 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT: 1215 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
1066 err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type); 1216 err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type);
1067 break; 1217 break;
1218 case ISCSI_UEVENT_TGT_DSCVR:
1219 err = iscsi_tgt_dscvr(transport, ev);
1220 break;
1068 default: 1221 default:
1069 err = -EINVAL; 1222 err = -EINVAL;
1070 break; 1223 break;
@@ -1147,49 +1300,31 @@ struct class_device_attribute class_device_attr_##_prefix##_##_name = \
1147/* 1300/*
1148 * iSCSI connection attrs 1301 * iSCSI connection attrs
1149 */ 1302 */
1150#define iscsi_conn_int_attr_show(param, format) \ 1303#define iscsi_conn_attr_show(param) \
1151static ssize_t \
1152show_conn_int_param_##param(struct class_device *cdev, char *buf) \
1153{ \
1154 uint32_t value = 0; \
1155 struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev); \
1156 struct iscsi_transport *t = conn->transport; \
1157 \
1158 t->get_conn_param(conn, param, &value); \
1159 return snprintf(buf, 20, format"\n", value); \
1160}
1161
1162#define iscsi_conn_int_attr(field, param, format) \
1163 iscsi_conn_int_attr_show(param, format) \
1164static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_int_param_##param, \
1165 NULL);
1166
1167iscsi_conn_int_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH, "%u");
1168iscsi_conn_int_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH, "%u");
1169iscsi_conn_int_attr(header_digest, ISCSI_PARAM_HDRDGST_EN, "%d");
1170iscsi_conn_int_attr(data_digest, ISCSI_PARAM_DATADGST_EN, "%d");
1171iscsi_conn_int_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN, "%d");
1172iscsi_conn_int_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN, "%d");
1173iscsi_conn_int_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT, "%d");
1174iscsi_conn_int_attr(port, ISCSI_PARAM_CONN_PORT, "%d");
1175iscsi_conn_int_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN, "%u");
1176
1177#define iscsi_conn_str_attr_show(param) \
1178static ssize_t \ 1304static ssize_t \
1179show_conn_str_param_##param(struct class_device *cdev, char *buf) \ 1305show_conn_param_##param(struct class_device *cdev, char *buf) \
1180{ \ 1306{ \
1181 struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev); \ 1307 struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev); \
1182 struct iscsi_transport *t = conn->transport; \ 1308 struct iscsi_transport *t = conn->transport; \
1183 return t->get_conn_str_param(conn, param, buf); \ 1309 return t->get_conn_param(conn, param, buf); \
1184} 1310}
1185 1311
1186#define iscsi_conn_str_attr(field, param) \ 1312#define iscsi_conn_attr(field, param) \
1187 iscsi_conn_str_attr_show(param) \ 1313 iscsi_conn_attr_show(param) \
1188static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_str_param_##param, \ 1314static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
1189 NULL); 1315 NULL);
1190 1316
1191iscsi_conn_str_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS); 1317iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH);
1192iscsi_conn_str_attr(address, ISCSI_PARAM_CONN_ADDRESS); 1318iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH);
1319iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN);
1320iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN);
1321iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN);
1322iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN);
1323iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT);
1324iscsi_conn_attr(port, ISCSI_PARAM_CONN_PORT);
1325iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN);
1326iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
1327iscsi_conn_attr(address, ISCSI_PARAM_CONN_ADDRESS);
1193 1328
1194#define iscsi_cdev_to_session(_cdev) \ 1329#define iscsi_cdev_to_session(_cdev) \
1195 iscsi_dev_to_session(_cdev->dev) 1330 iscsi_dev_to_session(_cdev->dev)
@@ -1197,61 +1332,36 @@ iscsi_conn_str_attr(address, ISCSI_PARAM_CONN_ADDRESS);
1197/* 1332/*
1198 * iSCSI session attrs 1333 * iSCSI session attrs
1199 */ 1334 */
1200#define iscsi_session_int_attr_show(param, format) \ 1335#define iscsi_session_attr_show(param) \
1201static ssize_t \
1202show_session_int_param_##param(struct class_device *cdev, char *buf) \
1203{ \
1204 uint32_t value = 0; \
1205 struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev); \
1206 struct iscsi_transport *t = session->transport; \
1207 \
1208 t->get_session_param(session, param, &value); \
1209 return snprintf(buf, 20, format"\n", value); \
1210}
1211
1212#define iscsi_session_int_attr(field, param, format) \
1213 iscsi_session_int_attr_show(param, format) \
1214static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_int_param_##param, \
1215 NULL);
1216
1217iscsi_session_int_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, "%d");
1218iscsi_session_int_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, "%hu");
1219iscsi_session_int_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, "%d");
1220iscsi_session_int_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, "%u");
1221iscsi_session_int_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, "%u");
1222iscsi_session_int_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, "%d");
1223iscsi_session_int_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, "%d");
1224iscsi_session_int_attr(erl, ISCSI_PARAM_ERL, "%d");
1225iscsi_session_int_attr(tpgt, ISCSI_PARAM_TPGT, "%d");
1226
1227#define iscsi_session_str_attr_show(param) \
1228static ssize_t \ 1336static ssize_t \
1229show_session_str_param_##param(struct class_device *cdev, char *buf) \ 1337show_session_param_##param(struct class_device *cdev, char *buf) \
1230{ \ 1338{ \
1231 struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev); \ 1339 struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev); \
1232 struct iscsi_transport *t = session->transport; \ 1340 struct iscsi_transport *t = session->transport; \
1233 return t->get_session_str_param(session, param, buf); \ 1341 return t->get_session_param(session, param, buf); \
1234} 1342}
1235 1343
1236#define iscsi_session_str_attr(field, param) \ 1344#define iscsi_session_attr(field, param) \
1237 iscsi_session_str_attr_show(param) \ 1345 iscsi_session_attr_show(param) \
1238static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_str_param_##param, \ 1346static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
1239 NULL); 1347 NULL);
1240 1348
1241iscsi_session_str_attr(targetname, ISCSI_PARAM_TARGET_NAME); 1349iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME);
1350iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN);
1351iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T);
1352iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN);
1353iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST);
1354iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST);
1355iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN);
1356iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN);
1357iscsi_session_attr(erl, ISCSI_PARAM_ERL);
1358iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT);
1242 1359
1243/*
1244 * Private session and conn attrs. userspace uses several iscsi values
1245 * to identify each session between reboots. Some of these values may not
1246 * be present in the iscsi_transport/LLD driver becuase userspace handles
1247 * login (and failback for login redirect) so for these type of drivers
1248 * the class manages the attrs and values for the iscsi_transport/LLD
1249 */
1250#define iscsi_priv_session_attr_show(field, format) \ 1360#define iscsi_priv_session_attr_show(field, format) \
1251static ssize_t \ 1361static ssize_t \
1252show_priv_session_##field(struct class_device *cdev, char *buf) \ 1362show_priv_session_##field(struct class_device *cdev, char *buf) \
1253{ \ 1363{ \
1254 struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev); \ 1364 struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev);\
1255 return sprintf(buf, format"\n", session->field); \ 1365 return sprintf(buf, format"\n", session->field); \
1256} 1366}
1257 1367
@@ -1259,31 +1369,15 @@ show_priv_session_##field(struct class_device *cdev, char *buf) \
1259 iscsi_priv_session_attr_show(field, format) \ 1369 iscsi_priv_session_attr_show(field, format) \
1260static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO, show_priv_session_##field, \ 1370static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO, show_priv_session_##field, \
1261 NULL) 1371 NULL)
1262iscsi_priv_session_attr(targetname, "%s");
1263iscsi_priv_session_attr(tpgt, "%d");
1264iscsi_priv_session_attr(recovery_tmo, "%d"); 1372iscsi_priv_session_attr(recovery_tmo, "%d");
1265 1373
1266#define iscsi_priv_conn_attr_show(field, format) \
1267static ssize_t \
1268show_priv_conn_##field(struct class_device *cdev, char *buf) \
1269{ \
1270 struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev); \
1271 return sprintf(buf, format"\n", conn->field); \
1272}
1273
1274#define iscsi_priv_conn_attr(field, format) \
1275 iscsi_priv_conn_attr_show(field, format) \
1276static ISCSI_CLASS_ATTR(priv_conn, field, S_IRUGO, show_priv_conn_##field, \
1277 NULL)
1278iscsi_priv_conn_attr(persistent_address, "%s");
1279iscsi_priv_conn_attr(persistent_port, "%d");
1280
1281#define SETUP_PRIV_SESSION_RD_ATTR(field) \ 1374#define SETUP_PRIV_SESSION_RD_ATTR(field) \
1282do { \ 1375do { \
1283 priv->session_attrs[count] = &class_device_attr_priv_sess_##field; \ 1376 priv->session_attrs[count] = &class_device_attr_priv_sess_##field; \
1284 count++; \ 1377 count++; \
1285} while (0) 1378} while (0)
1286 1379
1380
1287#define SETUP_SESSION_RD_ATTR(field, param_flag) \ 1381#define SETUP_SESSION_RD_ATTR(field, param_flag) \
1288do { \ 1382do { \
1289 if (tt->param_mask & param_flag) { \ 1383 if (tt->param_mask & param_flag) { \
@@ -1292,12 +1386,6 @@ do { \
1292 } \ 1386 } \
1293} while (0) 1387} while (0)
1294 1388
1295#define SETUP_PRIV_CONN_RD_ATTR(field) \
1296do { \
1297 priv->conn_attrs[count] = &class_device_attr_priv_conn_##field; \
1298 count++; \
1299} while (0)
1300
1301#define SETUP_CONN_RD_ATTR(field, param_flag) \ 1389#define SETUP_CONN_RD_ATTR(field, param_flag) \
1302do { \ 1390do { \
1303 if (tt->param_mask & param_flag) { \ 1391 if (tt->param_mask & param_flag) { \
@@ -1388,6 +1476,7 @@ iscsi_register_transport(struct iscsi_transport *tt)
1388 if (!priv) 1476 if (!priv)
1389 return NULL; 1477 return NULL;
1390 INIT_LIST_HEAD(&priv->list); 1478 INIT_LIST_HEAD(&priv->list);
1479 priv->daemon_pid = -1;
1391 priv->iscsi_transport = tt; 1480 priv->iscsi_transport = tt;
1392 priv->t.user_scan = iscsi_user_scan; 1481 priv->t.user_scan = iscsi_user_scan;
1393 1482
@@ -1424,16 +1513,8 @@ iscsi_register_transport(struct iscsi_transport *tt)
1424 SETUP_CONN_RD_ATTR(address, ISCSI_CONN_ADDRESS); 1513 SETUP_CONN_RD_ATTR(address, ISCSI_CONN_ADDRESS);
1425 SETUP_CONN_RD_ATTR(port, ISCSI_CONN_PORT); 1514 SETUP_CONN_RD_ATTR(port, ISCSI_CONN_PORT);
1426 SETUP_CONN_RD_ATTR(exp_statsn, ISCSI_EXP_STATSN); 1515 SETUP_CONN_RD_ATTR(exp_statsn, ISCSI_EXP_STATSN);
1427 1516 SETUP_CONN_RD_ATTR(persistent_address, ISCSI_PERSISTENT_ADDRESS);
1428 if (tt->param_mask & ISCSI_PERSISTENT_ADDRESS) 1517 SETUP_CONN_RD_ATTR(persistent_port, ISCSI_PERSISTENT_PORT);
1429 SETUP_CONN_RD_ATTR(persistent_address, ISCSI_PERSISTENT_ADDRESS);
1430 else
1431 SETUP_PRIV_CONN_RD_ATTR(persistent_address);
1432
1433 if (tt->param_mask & ISCSI_PERSISTENT_PORT)
1434 SETUP_CONN_RD_ATTR(persistent_port, ISCSI_PERSISTENT_PORT);
1435 else
1436 SETUP_PRIV_CONN_RD_ATTR(persistent_port);
1437 1518
1438 BUG_ON(count > ISCSI_CONN_ATTRS); 1519 BUG_ON(count > ISCSI_CONN_ATTRS);
1439 priv->conn_attrs[count] = NULL; 1520 priv->conn_attrs[count] = NULL;
@@ -1453,18 +1534,10 @@ iscsi_register_transport(struct iscsi_transport *tt)
1453 SETUP_SESSION_RD_ATTR(data_pdu_in_order, ISCSI_PDU_INORDER_EN); 1534 SETUP_SESSION_RD_ATTR(data_pdu_in_order, ISCSI_PDU_INORDER_EN);
1454 SETUP_SESSION_RD_ATTR(data_seq_in_order, ISCSI_DATASEQ_INORDER_EN); 1535 SETUP_SESSION_RD_ATTR(data_seq_in_order, ISCSI_DATASEQ_INORDER_EN);
1455 SETUP_SESSION_RD_ATTR(erl, ISCSI_ERL); 1536 SETUP_SESSION_RD_ATTR(erl, ISCSI_ERL);
1537 SETUP_SESSION_RD_ATTR(targetname, ISCSI_TARGET_NAME);
1538 SETUP_SESSION_RD_ATTR(tpgt, ISCSI_TPGT);
1456 SETUP_PRIV_SESSION_RD_ATTR(recovery_tmo); 1539 SETUP_PRIV_SESSION_RD_ATTR(recovery_tmo);
1457 1540
1458 if (tt->param_mask & ISCSI_TARGET_NAME)
1459 SETUP_SESSION_RD_ATTR(targetname, ISCSI_TARGET_NAME);
1460 else
1461 SETUP_PRIV_SESSION_RD_ATTR(targetname);
1462
1463 if (tt->param_mask & ISCSI_TPGT)
1464 SETUP_SESSION_RD_ATTR(tpgt, ISCSI_TPGT);
1465 else
1466 SETUP_PRIV_SESSION_RD_ATTR(tpgt);
1467
1468 BUG_ON(count > ISCSI_SESSION_ATTRS); 1541 BUG_ON(count > ISCSI_SESSION_ATTRS);
1469 priv->session_attrs[count] = NULL; 1542 priv->session_attrs[count] = NULL;
1470 1543
@@ -1541,6 +1614,9 @@ static __init int iscsi_transport_init(void)
1541{ 1614{
1542 int err; 1615 int err;
1543 1616
1617 printk(KERN_INFO "Loading iSCSI transport class v%s.",
1618 ISCSI_TRANSPORT_VERSION);
1619
1544 err = class_register(&iscsi_transport_class); 1620 err = class_register(&iscsi_transport_class);
1545 if (err) 1621 if (err)
1546 return err; 1622 return err;
@@ -1606,3 +1682,4 @@ MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
1606 "Alex Aizman <itn780@yahoo.com>"); 1682 "Alex Aizman <itn780@yahoo.com>");
1607MODULE_DESCRIPTION("iSCSI Transport Interface"); 1683MODULE_DESCRIPTION("iSCSI Transport Interface");
1608MODULE_LICENSE("GPL"); 1684MODULE_LICENSE("GPL");
1685MODULE_VERSION(ISCSI_TRANSPORT_VERSION);
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index 1fe6b2d01853..5a625c3fddae 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -41,6 +41,7 @@ struct sas_host_attrs {
41 struct mutex lock; 41 struct mutex lock;
42 u32 next_target_id; 42 u32 next_target_id;
43 u32 next_expander_id; 43 u32 next_expander_id;
44 int next_port_id;
44}; 45};
45#define to_sas_host_attrs(host) ((struct sas_host_attrs *)(host)->shost_data) 46#define to_sas_host_attrs(host) ((struct sas_host_attrs *)(host)->shost_data)
46 47
@@ -146,6 +147,7 @@ static int sas_host_setup(struct transport_container *tc, struct device *dev,
146 mutex_init(&sas_host->lock); 147 mutex_init(&sas_host->lock);
147 sas_host->next_target_id = 0; 148 sas_host->next_target_id = 0;
148 sas_host->next_expander_id = 0; 149 sas_host->next_expander_id = 0;
150 sas_host->next_port_id = 0;
149 return 0; 151 return 0;
150} 152}
151 153
@@ -174,12 +176,29 @@ static int sas_host_match(struct attribute_container *cont,
174 176
175static int do_sas_phy_delete(struct device *dev, void *data) 177static int do_sas_phy_delete(struct device *dev, void *data)
176{ 178{
177 if (scsi_is_sas_phy(dev)) 179 int pass = (int)(unsigned long)data;
180
181 if (pass == 0 && scsi_is_sas_port(dev))
182 sas_port_delete(dev_to_sas_port(dev));
183 else if (pass == 1 && scsi_is_sas_phy(dev))
178 sas_phy_delete(dev_to_phy(dev)); 184 sas_phy_delete(dev_to_phy(dev));
179 return 0; 185 return 0;
180} 186}
181 187
182/** 188/**
189 * sas_remove_children -- tear down a devices SAS data structures
190 * @dev: device belonging to the sas object
191 *
192 * Removes all SAS PHYs and remote PHYs for a given object
193 */
194void sas_remove_children(struct device *dev)
195{
196 device_for_each_child(dev, (void *)0, do_sas_phy_delete);
197 device_for_each_child(dev, (void *)1, do_sas_phy_delete);
198}
199EXPORT_SYMBOL(sas_remove_children);
200
201/**
183 * sas_remove_host -- tear down a Scsi_Host's SAS data structures 202 * sas_remove_host -- tear down a Scsi_Host's SAS data structures
184 * @shost: Scsi Host that is torn down 203 * @shost: Scsi Host that is torn down
185 * 204 *
@@ -188,13 +207,13 @@ static int do_sas_phy_delete(struct device *dev, void *data)
188 */ 207 */
189void sas_remove_host(struct Scsi_Host *shost) 208void sas_remove_host(struct Scsi_Host *shost)
190{ 209{
191 device_for_each_child(&shost->shost_gendev, NULL, do_sas_phy_delete); 210 sas_remove_children(&shost->shost_gendev);
192} 211}
193EXPORT_SYMBOL(sas_remove_host); 212EXPORT_SYMBOL(sas_remove_host);
194 213
195 214
196/* 215/*
197 * SAS Port attributes 216 * SAS Phy attributes
198 */ 217 */
199 218
200#define sas_phy_show_simple(field, name, format_string, cast) \ 219#define sas_phy_show_simple(field, name, format_string, cast) \
@@ -310,7 +329,7 @@ sas_phy_protocol_attr(identify.target_port_protocols,
310sas_phy_simple_attr(identify.sas_address, sas_address, "0x%016llx\n", 329sas_phy_simple_attr(identify.sas_address, sas_address, "0x%016llx\n",
311 unsigned long long); 330 unsigned long long);
312sas_phy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8); 331sas_phy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8);
313sas_phy_simple_attr(port_identifier, port_identifier, "%d\n", u8); 332//sas_phy_simple_attr(port_identifier, port_identifier, "%d\n", int);
314sas_phy_linkspeed_attr(negotiated_linkrate); 333sas_phy_linkspeed_attr(negotiated_linkrate);
315sas_phy_linkspeed_attr(minimum_linkrate_hw); 334sas_phy_linkspeed_attr(minimum_linkrate_hw);
316sas_phy_linkspeed_attr(minimum_linkrate); 335sas_phy_linkspeed_attr(minimum_linkrate);
@@ -378,9 +397,10 @@ struct sas_phy *sas_phy_alloc(struct device *parent, int number)
378 device_initialize(&phy->dev); 397 device_initialize(&phy->dev);
379 phy->dev.parent = get_device(parent); 398 phy->dev.parent = get_device(parent);
380 phy->dev.release = sas_phy_release; 399 phy->dev.release = sas_phy_release;
400 INIT_LIST_HEAD(&phy->port_siblings);
381 if (scsi_is_sas_expander_device(parent)) { 401 if (scsi_is_sas_expander_device(parent)) {
382 struct sas_rphy *rphy = dev_to_rphy(parent); 402 struct sas_rphy *rphy = dev_to_rphy(parent);
383 sprintf(phy->dev.bus_id, "phy-%d-%d:%d", shost->host_no, 403 sprintf(phy->dev.bus_id, "phy-%d:%d:%d", shost->host_no,
384 rphy->scsi_target_id, number); 404 rphy->scsi_target_id, number);
385 } else 405 } else
386 sprintf(phy->dev.bus_id, "phy-%d:%d", shost->host_no, number); 406 sprintf(phy->dev.bus_id, "phy-%d:%d", shost->host_no, number);
@@ -440,8 +460,8 @@ sas_phy_delete(struct sas_phy *phy)
440{ 460{
441 struct device *dev = &phy->dev; 461 struct device *dev = &phy->dev;
442 462
443 if (phy->rphy) 463 /* this happens if the phy is still part of a port when deleted */
444 sas_rphy_delete(phy->rphy); 464 BUG_ON(!list_empty(&phy->port_siblings));
445 465
446 transport_remove_device(dev); 466 transport_remove_device(dev);
447 device_del(dev); 467 device_del(dev);
@@ -464,6 +484,310 @@ int scsi_is_sas_phy(const struct device *dev)
464EXPORT_SYMBOL(scsi_is_sas_phy); 484EXPORT_SYMBOL(scsi_is_sas_phy);
465 485
466/* 486/*
487 * SAS Port attributes
488 */
489#define sas_port_show_simple(field, name, format_string, cast) \
490static ssize_t \
491show_sas_port_##name(struct class_device *cdev, char *buf) \
492{ \
493 struct sas_port *port = transport_class_to_sas_port(cdev); \
494 \
495 return snprintf(buf, 20, format_string, cast port->field); \
496}
497
498#define sas_port_simple_attr(field, name, format_string, type) \
499 sas_port_show_simple(field, name, format_string, (type)) \
500static CLASS_DEVICE_ATTR(name, S_IRUGO, show_sas_port_##name, NULL)
501
502sas_port_simple_attr(num_phys, num_phys, "%d\n", int);
503
504static DECLARE_TRANSPORT_CLASS(sas_port_class,
505 "sas_port", NULL, NULL, NULL);
506
507static int sas_port_match(struct attribute_container *cont, struct device *dev)
508{
509 struct Scsi_Host *shost;
510 struct sas_internal *i;
511
512 if (!scsi_is_sas_port(dev))
513 return 0;
514 shost = dev_to_shost(dev->parent);
515
516 if (!shost->transportt)
517 return 0;
518 if (shost->transportt->host_attrs.ac.class !=
519 &sas_host_class.class)
520 return 0;
521
522 i = to_sas_internal(shost->transportt);
523 return &i->port_attr_cont.ac == cont;
524}
525
526
527static void sas_port_release(struct device *dev)
528{
529 struct sas_port *port = dev_to_sas_port(dev);
530
531 BUG_ON(!list_empty(&port->phy_list));
532
533 put_device(dev->parent);
534 kfree(port);
535}
536
537static void sas_port_create_link(struct sas_port *port,
538 struct sas_phy *phy)
539{
540 sysfs_create_link(&port->dev.kobj, &phy->dev.kobj, phy->dev.bus_id);
541 sysfs_create_link(&phy->dev.kobj, &port->dev.kobj, "port");
542}
543
544static void sas_port_delete_link(struct sas_port *port,
545 struct sas_phy *phy)
546{
547 sysfs_remove_link(&port->dev.kobj, phy->dev.bus_id);
548 sysfs_remove_link(&phy->dev.kobj, "port");
549}
550
551/** sas_port_alloc - allocate and initialize a SAS port structure
552 *
553 * @parent: parent device
554 * @port_id: port number
555 *
556 * Allocates a SAS port structure. It will be added to the device tree
557 * below the device specified by @parent which must be either a Scsi_Host
558 * or a sas_expander_device.
559 *
560 * Returns %NULL on error
561 */
562struct sas_port *sas_port_alloc(struct device *parent, int port_id)
563{
564 struct Scsi_Host *shost = dev_to_shost(parent);
565 struct sas_port *port;
566
567 port = kzalloc(sizeof(*port), GFP_KERNEL);
568 if (!port)
569 return NULL;
570
571 port->port_identifier = port_id;
572
573 device_initialize(&port->dev);
574
575 port->dev.parent = get_device(parent);
576 port->dev.release = sas_port_release;
577
578 mutex_init(&port->phy_list_mutex);
579 INIT_LIST_HEAD(&port->phy_list);
580
581 if (scsi_is_sas_expander_device(parent)) {
582 struct sas_rphy *rphy = dev_to_rphy(parent);
583 sprintf(port->dev.bus_id, "port-%d:%d:%d", shost->host_no,
584 rphy->scsi_target_id, port->port_identifier);
585 } else
586 sprintf(port->dev.bus_id, "port-%d:%d", shost->host_no,
587 port->port_identifier);
588
589 transport_setup_device(&port->dev);
590
591 return port;
592}
593EXPORT_SYMBOL(sas_port_alloc);
594
595/** sas_port_alloc_num - allocate and initialize a SAS port structure
596 *
597 * @parent: parent device
598 *
599 * Allocates a SAS port structure and a number to go with it. This
600 * interface is really for adapters where the port number has no
601 * meansing, so the sas class should manage them. It will be added to
602 * the device tree below the device specified by @parent which must be
603 * either a Scsi_Host or a sas_expander_device.
604 *
605 * Returns %NULL on error
606 */
607struct sas_port *sas_port_alloc_num(struct device *parent)
608{
609 int index;
610 struct Scsi_Host *shost = dev_to_shost(parent);
611 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
612
613 /* FIXME: use idr for this eventually */
614 mutex_lock(&sas_host->lock);
615 if (scsi_is_sas_expander_device(parent)) {
616 struct sas_rphy *rphy = dev_to_rphy(parent);
617 struct sas_expander_device *exp = rphy_to_expander_device(rphy);
618
619 index = exp->next_port_id++;
620 } else
621 index = sas_host->next_port_id++;
622 mutex_unlock(&sas_host->lock);
623 return sas_port_alloc(parent, index);
624}
625EXPORT_SYMBOL(sas_port_alloc_num);
626
627/**
628 * sas_port_add - add a SAS port to the device hierarchy
629 *
630 * @port: port to be added
631 *
632 * publishes a port to the rest of the system
633 */
634int sas_port_add(struct sas_port *port)
635{
636 int error;
637
638 /* No phys should be added until this is made visible */
639 BUG_ON(!list_empty(&port->phy_list));
640
641 error = device_add(&port->dev);
642
643 if (error)
644 return error;
645
646 transport_add_device(&port->dev);
647 transport_configure_device(&port->dev);
648
649 return 0;
650}
651EXPORT_SYMBOL(sas_port_add);
652
653/**
654 * sas_port_free -- free a SAS PORT
655 * @port: SAS PORT to free
656 *
657 * Frees the specified SAS PORT.
658 *
659 * Note:
660 * This function must only be called on a PORT that has not
661 * sucessfully been added using sas_port_add().
662 */
663void sas_port_free(struct sas_port *port)
664{
665 transport_destroy_device(&port->dev);
666 put_device(&port->dev);
667}
668EXPORT_SYMBOL(sas_port_free);
669
670/**
671 * sas_port_delete -- remove SAS PORT
672 * @port: SAS PORT to remove
673 *
674 * Removes the specified SAS PORT. If the SAS PORT has an
675 * associated phys, unlink them from the port as well.
676 */
677void sas_port_delete(struct sas_port *port)
678{
679 struct device *dev = &port->dev;
680 struct sas_phy *phy, *tmp_phy;
681
682 if (port->rphy) {
683 sas_rphy_delete(port->rphy);
684 port->rphy = NULL;
685 }
686
687 mutex_lock(&port->phy_list_mutex);
688 list_for_each_entry_safe(phy, tmp_phy, &port->phy_list,
689 port_siblings) {
690 sas_port_delete_link(port, phy);
691 list_del_init(&phy->port_siblings);
692 }
693 mutex_unlock(&port->phy_list_mutex);
694
695 if (port->is_backlink) {
696 struct device *parent = port->dev.parent;
697
698 sysfs_remove_link(&port->dev.kobj, parent->bus_id);
699 port->is_backlink = 0;
700 }
701
702 transport_remove_device(dev);
703 device_del(dev);
704 transport_destroy_device(dev);
705 put_device(dev);
706}
707EXPORT_SYMBOL(sas_port_delete);
708
709/**
710 * scsi_is_sas_port -- check if a struct device represents a SAS port
711 * @dev: device to check
712 *
713 * Returns:
714 * %1 if the device represents a SAS Port, %0 else
715 */
716int scsi_is_sas_port(const struct device *dev)
717{
718 return dev->release == sas_port_release;
719}
720EXPORT_SYMBOL(scsi_is_sas_port);
721
722/**
723 * sas_port_add_phy - add another phy to a port to form a wide port
724 * @port: port to add the phy to
725 * @phy: phy to add
726 *
727 * When a port is initially created, it is empty (has no phys). All
728 * ports must have at least one phy to operated, and all wide ports
729 * must have at least two. The current code makes no difference
730 * between ports and wide ports, but the only object that can be
731 * connected to a remote device is a port, so ports must be formed on
732 * all devices with phys if they're connected to anything.
733 */
734void sas_port_add_phy(struct sas_port *port, struct sas_phy *phy)
735{
736 mutex_lock(&port->phy_list_mutex);
737 if (unlikely(!list_empty(&phy->port_siblings))) {
738 /* make sure we're already on this port */
739 struct sas_phy *tmp;
740
741 list_for_each_entry(tmp, &port->phy_list, port_siblings)
742 if (tmp == phy)
743 break;
744 /* If this trips, you added a phy that was already
745 * part of a different port */
746 if (unlikely(tmp != phy)) {
747 dev_printk(KERN_ERR, &port->dev, "trying to add phy %s fails: it's already part of another port\n", phy->dev.bus_id);
748 BUG();
749 }
750 } else {
751 sas_port_create_link(port, phy);
752 list_add_tail(&phy->port_siblings, &port->phy_list);
753 port->num_phys++;
754 }
755 mutex_unlock(&port->phy_list_mutex);
756}
757EXPORT_SYMBOL(sas_port_add_phy);
758
759/**
760 * sas_port_delete_phy - remove a phy from a port or wide port
761 * @port: port to remove the phy from
762 * @phy: phy to remove
763 *
764 * This operation is used for tearing down ports again. It must be
765 * done to every port or wide port before calling sas_port_delete.
766 */
767void sas_port_delete_phy(struct sas_port *port, struct sas_phy *phy)
768{
769 mutex_lock(&port->phy_list_mutex);
770 sas_port_delete_link(port, phy);
771 list_del_init(&phy->port_siblings);
772 port->num_phys--;
773 mutex_unlock(&port->phy_list_mutex);
774}
775EXPORT_SYMBOL(sas_port_delete_phy);
776
777void sas_port_mark_backlink(struct sas_port *port)
778{
779 struct device *parent = port->dev.parent->parent->parent;
780
781 if (port->is_backlink)
782 return;
783 port->is_backlink = 1;
784 sysfs_create_link(&port->dev.kobj, &parent->kobj,
785 parent->bus_id);
786
787}
788EXPORT_SYMBOL(sas_port_mark_backlink);
789
790/*
467 * SAS remote PHY attributes. 791 * SAS remote PHY attributes.
468 */ 792 */
469 793
@@ -767,7 +1091,7 @@ static void sas_rphy_initialize(struct sas_rphy *rphy)
767 * Returns: 1091 * Returns:
768 * SAS PHY allocated or %NULL if the allocation failed. 1092 * SAS PHY allocated or %NULL if the allocation failed.
769 */ 1093 */
770struct sas_rphy *sas_end_device_alloc(struct sas_phy *parent) 1094struct sas_rphy *sas_end_device_alloc(struct sas_port *parent)
771{ 1095{
772 struct Scsi_Host *shost = dev_to_shost(&parent->dev); 1096 struct Scsi_Host *shost = dev_to_shost(&parent->dev);
773 struct sas_end_device *rdev; 1097 struct sas_end_device *rdev;
@@ -780,8 +1104,13 @@ struct sas_rphy *sas_end_device_alloc(struct sas_phy *parent)
780 device_initialize(&rdev->rphy.dev); 1104 device_initialize(&rdev->rphy.dev);
781 rdev->rphy.dev.parent = get_device(&parent->dev); 1105 rdev->rphy.dev.parent = get_device(&parent->dev);
782 rdev->rphy.dev.release = sas_end_device_release; 1106 rdev->rphy.dev.release = sas_end_device_release;
783 sprintf(rdev->rphy.dev.bus_id, "end_device-%d:%d-%d", 1107 if (scsi_is_sas_expander_device(parent->dev.parent)) {
784 shost->host_no, parent->port_identifier, parent->number); 1108 struct sas_rphy *rphy = dev_to_rphy(parent->dev.parent);
1109 sprintf(rdev->rphy.dev.bus_id, "end_device-%d:%d:%d",
1110 shost->host_no, rphy->scsi_target_id, parent->port_identifier);
1111 } else
1112 sprintf(rdev->rphy.dev.bus_id, "end_device-%d:%d",
1113 shost->host_no, parent->port_identifier);
785 rdev->rphy.identify.device_type = SAS_END_DEVICE; 1114 rdev->rphy.identify.device_type = SAS_END_DEVICE;
786 sas_rphy_initialize(&rdev->rphy); 1115 sas_rphy_initialize(&rdev->rphy);
787 transport_setup_device(&rdev->rphy.dev); 1116 transport_setup_device(&rdev->rphy.dev);
@@ -798,7 +1127,7 @@ EXPORT_SYMBOL(sas_end_device_alloc);
798 * Returns: 1127 * Returns:
799 * SAS PHY allocated or %NULL if the allocation failed. 1128 * SAS PHY allocated or %NULL if the allocation failed.
800 */ 1129 */
801struct sas_rphy *sas_expander_alloc(struct sas_phy *parent, 1130struct sas_rphy *sas_expander_alloc(struct sas_port *parent,
802 enum sas_device_type type) 1131 enum sas_device_type type)
803{ 1132{
804 struct Scsi_Host *shost = dev_to_shost(&parent->dev); 1133 struct Scsi_Host *shost = dev_to_shost(&parent->dev);
@@ -837,7 +1166,7 @@ EXPORT_SYMBOL(sas_expander_alloc);
837 */ 1166 */
838int sas_rphy_add(struct sas_rphy *rphy) 1167int sas_rphy_add(struct sas_rphy *rphy)
839{ 1168{
840 struct sas_phy *parent = dev_to_phy(rphy->dev.parent); 1169 struct sas_port *parent = dev_to_sas_port(rphy->dev.parent);
841 struct Scsi_Host *shost = dev_to_shost(parent->dev.parent); 1170 struct Scsi_Host *shost = dev_to_shost(parent->dev.parent);
842 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); 1171 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
843 struct sas_identify *identify = &rphy->identify; 1172 struct sas_identify *identify = &rphy->identify;
@@ -865,7 +1194,7 @@ int sas_rphy_add(struct sas_rphy *rphy)
865 1194
866 if (identify->device_type == SAS_END_DEVICE && 1195 if (identify->device_type == SAS_END_DEVICE &&
867 rphy->scsi_target_id != -1) { 1196 rphy->scsi_target_id != -1) {
868 scsi_scan_target(&rphy->dev, parent->port_identifier, 1197 scsi_scan_target(&rphy->dev, 0,
869 rphy->scsi_target_id, ~0, 0); 1198 rphy->scsi_target_id, ~0, 0);
870 } 1199 }
871 1200
@@ -910,7 +1239,7 @@ void
910sas_rphy_delete(struct sas_rphy *rphy) 1239sas_rphy_delete(struct sas_rphy *rphy)
911{ 1240{
912 struct device *dev = &rphy->dev; 1241 struct device *dev = &rphy->dev;
913 struct sas_phy *parent = dev_to_phy(dev->parent); 1242 struct sas_port *parent = dev_to_sas_port(dev->parent);
914 struct Scsi_Host *shost = dev_to_shost(parent->dev.parent); 1243 struct Scsi_Host *shost = dev_to_shost(parent->dev.parent);
915 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); 1244 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
916 1245
@@ -920,7 +1249,7 @@ sas_rphy_delete(struct sas_rphy *rphy)
920 break; 1249 break;
921 case SAS_EDGE_EXPANDER_DEVICE: 1250 case SAS_EDGE_EXPANDER_DEVICE:
922 case SAS_FANOUT_EXPANDER_DEVICE: 1251 case SAS_FANOUT_EXPANDER_DEVICE:
923 device_for_each_child(dev, NULL, do_sas_phy_delete); 1252 sas_remove_children(dev);
924 break; 1253 break;
925 default: 1254 default:
926 break; 1255 break;
@@ -967,15 +1296,13 @@ static int sas_user_scan(struct Scsi_Host *shost, uint channel,
967 1296
968 mutex_lock(&sas_host->lock); 1297 mutex_lock(&sas_host->lock);
969 list_for_each_entry(rphy, &sas_host->rphy_list, list) { 1298 list_for_each_entry(rphy, &sas_host->rphy_list, list) {
970 struct sas_phy *parent = dev_to_phy(rphy->dev.parent);
971
972 if (rphy->identify.device_type != SAS_END_DEVICE || 1299 if (rphy->identify.device_type != SAS_END_DEVICE ||
973 rphy->scsi_target_id == -1) 1300 rphy->scsi_target_id == -1)
974 continue; 1301 continue;
975 1302
976 if ((channel == SCAN_WILD_CARD || channel == parent->port_identifier) && 1303 if ((channel == SCAN_WILD_CARD || channel == 0) &&
977 (id == SCAN_WILD_CARD || id == rphy->scsi_target_id)) { 1304 (id == SCAN_WILD_CARD || id == rphy->scsi_target_id)) {
978 scsi_scan_target(&rphy->dev, parent->port_identifier, 1305 scsi_scan_target(&rphy->dev, 0,
979 rphy->scsi_target_id, lun, 1); 1306 rphy->scsi_target_id, lun, 1);
980 } 1307 }
981 } 1308 }
@@ -1003,16 +1330,19 @@ static int sas_user_scan(struct Scsi_Host *shost, uint channel,
1003#define SETUP_OPTIONAL_RPORT_ATTRIBUTE(field, func) \ 1330#define SETUP_OPTIONAL_RPORT_ATTRIBUTE(field, func) \
1004 SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, i->f->func) 1331 SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, i->f->func)
1005 1332
1006#define SETUP_PORT_ATTRIBUTE(field) \ 1333#define SETUP_PHY_ATTRIBUTE(field) \
1007 SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, 1) 1334 SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, 1)
1008 1335
1009#define SETUP_OPTIONAL_PORT_ATTRIBUTE(field, func) \ 1336#define SETUP_PORT_ATTRIBUTE(field) \
1337 SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1)
1338
1339#define SETUP_OPTIONAL_PHY_ATTRIBUTE(field, func) \
1010 SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func) 1340 SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func)
1011 1341
1012#define SETUP_PORT_ATTRIBUTE_WRONLY(field) \ 1342#define SETUP_PHY_ATTRIBUTE_WRONLY(field) \
1013 SETUP_TEMPLATE(phy_attrs, field, S_IWUGO, 1) 1343 SETUP_TEMPLATE(phy_attrs, field, S_IWUGO, 1)
1014 1344
1015#define SETUP_OPTIONAL_PORT_ATTRIBUTE_WRONLY(field, func) \ 1345#define SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(field, func) \
1016 SETUP_TEMPLATE(phy_attrs, field, S_IWUGO, i->f->func) 1346 SETUP_TEMPLATE(phy_attrs, field, S_IWUGO, i->f->func)
1017 1347
1018#define SETUP_END_DEV_ATTRIBUTE(field) \ 1348#define SETUP_END_DEV_ATTRIBUTE(field) \
@@ -1048,6 +1378,11 @@ sas_attach_transport(struct sas_function_template *ft)
1048 i->phy_attr_cont.ac.match = sas_phy_match; 1378 i->phy_attr_cont.ac.match = sas_phy_match;
1049 transport_container_register(&i->phy_attr_cont); 1379 transport_container_register(&i->phy_attr_cont);
1050 1380
1381 i->port_attr_cont.ac.class = &sas_port_class.class;
1382 i->port_attr_cont.ac.attrs = &i->port_attrs[0];
1383 i->port_attr_cont.ac.match = sas_port_match;
1384 transport_container_register(&i->port_attr_cont);
1385
1051 i->rphy_attr_cont.ac.class = &sas_rphy_class.class; 1386 i->rphy_attr_cont.ac.class = &sas_rphy_class.class;
1052 i->rphy_attr_cont.ac.attrs = &i->rphy_attrs[0]; 1387 i->rphy_attr_cont.ac.attrs = &i->rphy_attrs[0];
1053 i->rphy_attr_cont.ac.match = sas_rphy_match; 1388 i->rphy_attr_cont.ac.match = sas_rphy_match;
@@ -1066,30 +1401,35 @@ sas_attach_transport(struct sas_function_template *ft)
1066 i->f = ft; 1401 i->f = ft;
1067 1402
1068 count = 0; 1403 count = 0;
1404 SETUP_PORT_ATTRIBUTE(num_phys);
1069 i->host_attrs[count] = NULL; 1405 i->host_attrs[count] = NULL;
1070 1406
1071 count = 0; 1407 count = 0;
1072 SETUP_PORT_ATTRIBUTE(initiator_port_protocols); 1408 SETUP_PHY_ATTRIBUTE(initiator_port_protocols);
1073 SETUP_PORT_ATTRIBUTE(target_port_protocols); 1409 SETUP_PHY_ATTRIBUTE(target_port_protocols);
1074 SETUP_PORT_ATTRIBUTE(device_type); 1410 SETUP_PHY_ATTRIBUTE(device_type);
1075 SETUP_PORT_ATTRIBUTE(sas_address); 1411 SETUP_PHY_ATTRIBUTE(sas_address);
1076 SETUP_PORT_ATTRIBUTE(phy_identifier); 1412 SETUP_PHY_ATTRIBUTE(phy_identifier);
1077 SETUP_PORT_ATTRIBUTE(port_identifier); 1413 //SETUP_PHY_ATTRIBUTE(port_identifier);
1078 SETUP_PORT_ATTRIBUTE(negotiated_linkrate); 1414 SETUP_PHY_ATTRIBUTE(negotiated_linkrate);
1079 SETUP_PORT_ATTRIBUTE(minimum_linkrate_hw); 1415 SETUP_PHY_ATTRIBUTE(minimum_linkrate_hw);
1080 SETUP_PORT_ATTRIBUTE(minimum_linkrate); 1416 SETUP_PHY_ATTRIBUTE(minimum_linkrate);
1081 SETUP_PORT_ATTRIBUTE(maximum_linkrate_hw); 1417 SETUP_PHY_ATTRIBUTE(maximum_linkrate_hw);
1082 SETUP_PORT_ATTRIBUTE(maximum_linkrate); 1418 SETUP_PHY_ATTRIBUTE(maximum_linkrate);
1083 1419
1084 SETUP_PORT_ATTRIBUTE(invalid_dword_count); 1420 SETUP_PHY_ATTRIBUTE(invalid_dword_count);
1085 SETUP_PORT_ATTRIBUTE(running_disparity_error_count); 1421 SETUP_PHY_ATTRIBUTE(running_disparity_error_count);
1086 SETUP_PORT_ATTRIBUTE(loss_of_dword_sync_count); 1422 SETUP_PHY_ATTRIBUTE(loss_of_dword_sync_count);
1087 SETUP_PORT_ATTRIBUTE(phy_reset_problem_count); 1423 SETUP_PHY_ATTRIBUTE(phy_reset_problem_count);
1088 SETUP_OPTIONAL_PORT_ATTRIBUTE_WRONLY(link_reset, phy_reset); 1424 SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(link_reset, phy_reset);
1089 SETUP_OPTIONAL_PORT_ATTRIBUTE_WRONLY(hard_reset, phy_reset); 1425 SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(hard_reset, phy_reset);
1090 i->phy_attrs[count] = NULL; 1426 i->phy_attrs[count] = NULL;
1091 1427
1092 count = 0; 1428 count = 0;
1429 SETUP_PORT_ATTRIBUTE(num_phys);
1430 i->port_attrs[count] = NULL;
1431
1432 count = 0;
1093 SETUP_RPORT_ATTRIBUTE(rphy_initiator_port_protocols); 1433 SETUP_RPORT_ATTRIBUTE(rphy_initiator_port_protocols);
1094 SETUP_RPORT_ATTRIBUTE(rphy_target_port_protocols); 1434 SETUP_RPORT_ATTRIBUTE(rphy_target_port_protocols);
1095 SETUP_RPORT_ATTRIBUTE(rphy_device_type); 1435 SETUP_RPORT_ATTRIBUTE(rphy_device_type);
@@ -1131,6 +1471,7 @@ void sas_release_transport(struct scsi_transport_template *t)
1131 1471
1132 transport_container_unregister(&i->t.host_attrs); 1472 transport_container_unregister(&i->t.host_attrs);
1133 transport_container_unregister(&i->phy_attr_cont); 1473 transport_container_unregister(&i->phy_attr_cont);
1474 transport_container_unregister(&i->port_attr_cont);
1134 transport_container_unregister(&i->rphy_attr_cont); 1475 transport_container_unregister(&i->rphy_attr_cont);
1135 transport_container_unregister(&i->end_dev_attr_cont); 1476 transport_container_unregister(&i->end_dev_attr_cont);
1136 transport_container_unregister(&i->expander_attr_cont); 1477 transport_container_unregister(&i->expander_attr_cont);
@@ -1149,9 +1490,12 @@ static __init int sas_transport_init(void)
1149 error = transport_class_register(&sas_phy_class); 1490 error = transport_class_register(&sas_phy_class);
1150 if (error) 1491 if (error)
1151 goto out_unregister_transport; 1492 goto out_unregister_transport;
1152 error = transport_class_register(&sas_rphy_class); 1493 error = transport_class_register(&sas_port_class);
1153 if (error) 1494 if (error)
1154 goto out_unregister_phy; 1495 goto out_unregister_phy;
1496 error = transport_class_register(&sas_rphy_class);
1497 if (error)
1498 goto out_unregister_port;
1155 error = transport_class_register(&sas_end_dev_class); 1499 error = transport_class_register(&sas_end_dev_class);
1156 if (error) 1500 if (error)
1157 goto out_unregister_rphy; 1501 goto out_unregister_rphy;
@@ -1165,6 +1509,8 @@ static __init int sas_transport_init(void)
1165 transport_class_unregister(&sas_end_dev_class); 1509 transport_class_unregister(&sas_end_dev_class);
1166 out_unregister_rphy: 1510 out_unregister_rphy:
1167 transport_class_unregister(&sas_rphy_class); 1511 transport_class_unregister(&sas_rphy_class);
1512 out_unregister_port:
1513 transport_class_unregister(&sas_port_class);
1168 out_unregister_phy: 1514 out_unregister_phy:
1169 transport_class_unregister(&sas_phy_class); 1515 transport_class_unregister(&sas_phy_class);
1170 out_unregister_transport: 1516 out_unregister_transport:
@@ -1178,6 +1524,7 @@ static void __exit sas_transport_exit(void)
1178{ 1524{
1179 transport_class_unregister(&sas_host_class); 1525 transport_class_unregister(&sas_host_class);
1180 transport_class_unregister(&sas_phy_class); 1526 transport_class_unregister(&sas_phy_class);
1527 transport_class_unregister(&sas_port_class);
1181 transport_class_unregister(&sas_rphy_class); 1528 transport_class_unregister(&sas_rphy_class);
1182 transport_class_unregister(&sas_end_dev_class); 1529 transport_class_unregister(&sas_end_dev_class);
1183 transport_class_unregister(&sas_expander_class); 1530 transport_class_unregister(&sas_expander_class);
diff --git a/drivers/scsi/scsicam.c b/drivers/scsi/scsicam.c
index b78354fc4b17..cd68a66c7bb3 100644
--- a/drivers/scsi/scsicam.c
+++ b/drivers/scsi/scsicam.c
@@ -57,6 +57,7 @@ EXPORT_SYMBOL(scsi_bios_ptable);
57int scsicam_bios_param(struct block_device *bdev, sector_t capacity, int *ip) 57int scsicam_bios_param(struct block_device *bdev, sector_t capacity, int *ip)
58{ 58{
59 unsigned char *p; 59 unsigned char *p;
60 u64 capacity64 = capacity; /* Suppress gcc warning */
60 int ret; 61 int ret;
61 62
62 p = scsi_bios_ptable(bdev); 63 p = scsi_bios_ptable(bdev);
@@ -68,7 +69,7 @@ int scsicam_bios_param(struct block_device *bdev, sector_t capacity, int *ip)
68 (unsigned int *)ip + 0, (unsigned int *)ip + 1); 69 (unsigned int *)ip + 0, (unsigned int *)ip + 1);
69 kfree(p); 70 kfree(p);
70 71
71 if (ret == -1) { 72 if (ret == -1 && capacity64 < (1ULL << 32)) {
72 /* pick some standard mapping with at most 1024 cylinders, 73 /* pick some standard mapping with at most 1024 cylinders,
73 and at most 62 sectors per track - this works up to 74 and at most 62 sectors per track - this works up to
74 7905 MB */ 75 7905 MB */
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index ea38757d12e5..98bd3aab9739 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -207,6 +207,23 @@ static ssize_t sd_store_cache_type(struct class_device *cdev, const char *buf,
207 return count; 207 return count;
208} 208}
209 209
210static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf,
211 size_t count)
212{
213 struct scsi_disk *sdkp = to_scsi_disk(cdev);
214 struct scsi_device *sdp = sdkp->device;
215
216 if (!capable(CAP_SYS_ADMIN))
217 return -EACCES;
218
219 if (sdp->type != TYPE_DISK)
220 return -EINVAL;
221
222 sdp->allow_restart = simple_strtoul(buf, NULL, 10);
223
224 return count;
225}
226
210static ssize_t sd_show_cache_type(struct class_device *cdev, char *buf) 227static ssize_t sd_show_cache_type(struct class_device *cdev, char *buf)
211{ 228{
212 struct scsi_disk *sdkp = to_scsi_disk(cdev); 229 struct scsi_disk *sdkp = to_scsi_disk(cdev);
@@ -222,10 +239,19 @@ static ssize_t sd_show_fua(struct class_device *cdev, char *buf)
222 return snprintf(buf, 20, "%u\n", sdkp->DPOFUA); 239 return snprintf(buf, 20, "%u\n", sdkp->DPOFUA);
223} 240}
224 241
242static ssize_t sd_show_allow_restart(struct class_device *cdev, char *buf)
243{
244 struct scsi_disk *sdkp = to_scsi_disk(cdev);
245
246 return snprintf(buf, 40, "%d\n", sdkp->device->allow_restart);
247}
248
225static struct class_device_attribute sd_disk_attrs[] = { 249static struct class_device_attribute sd_disk_attrs[] = {
226 __ATTR(cache_type, S_IRUGO|S_IWUSR, sd_show_cache_type, 250 __ATTR(cache_type, S_IRUGO|S_IWUSR, sd_show_cache_type,
227 sd_store_cache_type), 251 sd_store_cache_type),
228 __ATTR(FUA, S_IRUGO, sd_show_fua, NULL), 252 __ATTR(FUA, S_IRUGO, sd_show_fua, NULL),
253 __ATTR(allow_restart, S_IRUGO|S_IWUSR, sd_show_allow_restart,
254 sd_store_allow_restart),
229 __ATTR_NULL, 255 __ATTR_NULL,
230}; 256};
231 257
@@ -476,8 +502,7 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
476 SCpnt->cmnd[4] = (unsigned char) this_count; 502 SCpnt->cmnd[4] = (unsigned char) this_count;
477 SCpnt->cmnd[5] = 0; 503 SCpnt->cmnd[5] = 0;
478 } 504 }
479 SCpnt->request_bufflen = SCpnt->bufflen = 505 SCpnt->request_bufflen = this_count * sdp->sector_size;
480 this_count * sdp->sector_size;
481 506
482 /* 507 /*
483 * We shouldn't disconnect in the middle of a sector, so with a dumb 508 * We shouldn't disconnect in the middle of a sector, so with a dumb
@@ -890,11 +915,10 @@ static struct block_device_operations sd_fops = {
890static void sd_rw_intr(struct scsi_cmnd * SCpnt) 915static void sd_rw_intr(struct scsi_cmnd * SCpnt)
891{ 916{
892 int result = SCpnt->result; 917 int result = SCpnt->result;
893 int this_count = SCpnt->request_bufflen; 918 unsigned int xfer_size = SCpnt->request_bufflen;
894 int good_bytes = (result == 0 ? this_count : 0); 919 unsigned int good_bytes = result ? 0 : xfer_size;
895 sector_t block_sectors = 1; 920 u64 start_lba = SCpnt->request->sector;
896 u64 first_err_block; 921 u64 bad_lba;
897 sector_t error_sector;
898 struct scsi_sense_hdr sshdr; 922 struct scsi_sense_hdr sshdr;
899 int sense_valid = 0; 923 int sense_valid = 0;
900 int sense_deferred = 0; 924 int sense_deferred = 0;
@@ -905,7 +929,6 @@ static void sd_rw_intr(struct scsi_cmnd * SCpnt)
905 if (sense_valid) 929 if (sense_valid)
906 sense_deferred = scsi_sense_is_deferred(&sshdr); 930 sense_deferred = scsi_sense_is_deferred(&sshdr);
907 } 931 }
908
909#ifdef CONFIG_SCSI_LOGGING 932#ifdef CONFIG_SCSI_LOGGING
910 SCSI_LOG_HLCOMPLETE(1, printk("sd_rw_intr: %s: res=0x%x\n", 933 SCSI_LOG_HLCOMPLETE(1, printk("sd_rw_intr: %s: res=0x%x\n",
911 SCpnt->request->rq_disk->disk_name, result)); 934 SCpnt->request->rq_disk->disk_name, result));
@@ -915,89 +938,72 @@ static void sd_rw_intr(struct scsi_cmnd * SCpnt)
915 sshdr.sense_key, sshdr.asc, sshdr.ascq)); 938 sshdr.sense_key, sshdr.asc, sshdr.ascq));
916 } 939 }
917#endif 940#endif
918 /* 941 if (driver_byte(result) != DRIVER_SENSE &&
919 Handle MEDIUM ERRORs that indicate partial success. Since this is a 942 (!sense_valid || sense_deferred))
920 relatively rare error condition, no care is taken to avoid 943 goto out;
921 unnecessary additional work such as memcpy's that could be avoided.
922 */
923 if (driver_byte(result) != 0 &&
924 sense_valid && !sense_deferred) {
925 switch (sshdr.sense_key) {
926 case MEDIUM_ERROR:
927 if (!blk_fs_request(SCpnt->request))
928 break;
929 info_valid = scsi_get_sense_info_fld(
930 SCpnt->sense_buffer, SCSI_SENSE_BUFFERSIZE,
931 &first_err_block);
932 /*
933 * May want to warn and skip if following cast results
934 * in actual truncation (if sector_t < 64 bits)
935 */
936 error_sector = (sector_t)first_err_block;
937 if (SCpnt->request->bio != NULL)
938 block_sectors = bio_sectors(SCpnt->request->bio);
939 switch (SCpnt->device->sector_size) {
940 case 1024:
941 error_sector <<= 1;
942 if (block_sectors < 2)
943 block_sectors = 2;
944 break;
945 case 2048:
946 error_sector <<= 2;
947 if (block_sectors < 4)
948 block_sectors = 4;
949 break;
950 case 4096:
951 error_sector <<=3;
952 if (block_sectors < 8)
953 block_sectors = 8;
954 break;
955 case 256:
956 error_sector >>= 1;
957 break;
958 default:
959 break;
960 }
961 944
962 error_sector &= ~(block_sectors - 1); 945 switch (sshdr.sense_key) {
963 good_bytes = (error_sector - SCpnt->request->sector) << 9; 946 case HARDWARE_ERROR:
964 if (good_bytes < 0 || good_bytes >= this_count) 947 case MEDIUM_ERROR:
965 good_bytes = 0; 948 if (!blk_fs_request(SCpnt->request))
949 goto out;
950 info_valid = scsi_get_sense_info_fld(SCpnt->sense_buffer,
951 SCSI_SENSE_BUFFERSIZE,
952 &bad_lba);
953 if (!info_valid)
954 goto out;
955 if (xfer_size <= SCpnt->device->sector_size)
956 goto out;
957 switch (SCpnt->device->sector_size) {
958 case 256:
959 start_lba <<= 1;
966 break; 960 break;
967 961 case 512:
968 case RECOVERED_ERROR: /* an error occurred, but it recovered */
969 case NO_SENSE: /* LLDD got sense data */
970 /*
971 * Inform the user, but make sure that it's not treated
972 * as a hard error.
973 */
974 scsi_print_sense("sd", SCpnt);
975 SCpnt->result = 0;
976 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
977 good_bytes = this_count;
978 break; 962 break;
979 963 case 1024:
980 case ILLEGAL_REQUEST: 964 start_lba >>= 1;
981 if (SCpnt->device->use_10_for_rw && 965 break;
982 (SCpnt->cmnd[0] == READ_10 || 966 case 2048:
983 SCpnt->cmnd[0] == WRITE_10)) 967 start_lba >>= 2;
984 SCpnt->device->use_10_for_rw = 0; 968 break;
985 if (SCpnt->device->use_10_for_ms && 969 case 4096:
986 (SCpnt->cmnd[0] == MODE_SENSE_10 || 970 start_lba >>= 3;
987 SCpnt->cmnd[0] == MODE_SELECT_10))
988 SCpnt->device->use_10_for_ms = 0;
989 break; 971 break;
990
991 default: 972 default:
973 /* Print something here with limiting frequency. */
974 goto out;
992 break; 975 break;
993 } 976 }
977 /* This computation should always be done in terms of
978 * the resolution of the device's medium.
979 */
980 good_bytes = (bad_lba - start_lba)*SCpnt->device->sector_size;
981 break;
982 case RECOVERED_ERROR:
983 case NO_SENSE:
984 /* Inform the user, but make sure that it's not treated
985 * as a hard error.
986 */
987 scsi_print_sense("sd", SCpnt);
988 SCpnt->result = 0;
989 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
990 good_bytes = xfer_size;
991 break;
992 case ILLEGAL_REQUEST:
993 if (SCpnt->device->use_10_for_rw &&
994 (SCpnt->cmnd[0] == READ_10 ||
995 SCpnt->cmnd[0] == WRITE_10))
996 SCpnt->device->use_10_for_rw = 0;
997 if (SCpnt->device->use_10_for_ms &&
998 (SCpnt->cmnd[0] == MODE_SENSE_10 ||
999 SCpnt->cmnd[0] == MODE_SELECT_10))
1000 SCpnt->device->use_10_for_ms = 0;
1001 break;
1002 default:
1003 break;
994 } 1004 }
995 /* 1005 out:
996 * This calls the generic completion function, now that we know 1006 scsi_io_completion(SCpnt, good_bytes);
997 * how many actual sectors finished, and how many sectors we need
998 * to say have failed.
999 */
1000 scsi_io_completion(SCpnt, good_bytes, block_sectors << 9);
1001} 1007}
1002 1008
1003static int media_not_present(struct scsi_disk *sdkp, 1009static int media_not_present(struct scsi_disk *sdkp,
diff --git a/drivers/scsi/seagate.c b/drivers/scsi/seagate.c
index 3f312a84c6a7..2679ea8bff1a 100644
--- a/drivers/scsi/seagate.c
+++ b/drivers/scsi/seagate.c
@@ -1002,7 +1002,7 @@ connect_loop:
1002 } 1002 }
1003#endif 1003#endif
1004 1004
1005 buffer = (struct scatterlist *) SCint->buffer; 1005 buffer = (struct scatterlist *) SCint->request_buffer;
1006 len = buffer->length; 1006 len = buffer->length;
1007 data = page_address(buffer->page) + buffer->offset; 1007 data = page_address(buffer->page) + buffer->offset;
1008 } else { 1008 } else {
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 4e607d3065bc..34f9343ed0af 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -18,8 +18,8 @@
18 * 18 *
19 */ 19 */
20 20
21static int sg_version_num = 30533; /* 2 digits for each component */ 21static int sg_version_num = 30534; /* 2 digits for each component */
22#define SG_VERSION_STR "3.5.33" 22#define SG_VERSION_STR "3.5.34"
23 23
24/* 24/*
25 * D. P. Gilbert (dgilbert@interlog.com, dougg@triode.net.au), notes: 25 * D. P. Gilbert (dgilbert@interlog.com, dougg@triode.net.au), notes:
@@ -60,7 +60,7 @@ static int sg_version_num = 30533; /* 2 digits for each component */
60 60
61#ifdef CONFIG_SCSI_PROC_FS 61#ifdef CONFIG_SCSI_PROC_FS
62#include <linux/proc_fs.h> 62#include <linux/proc_fs.h>
63static char *sg_version_date = "20050908"; 63static char *sg_version_date = "20060818";
64 64
65static int sg_proc_init(void); 65static int sg_proc_init(void);
66static void sg_proc_cleanup(void); 66static void sg_proc_cleanup(void);
@@ -1164,7 +1164,7 @@ sg_vma_nopage(struct vm_area_struct *vma, unsigned long addr, int *type)
1164 len = vma->vm_end - sa; 1164 len = vma->vm_end - sa;
1165 len = (len < sg->length) ? len : sg->length; 1165 len = (len < sg->length) ? len : sg->length;
1166 if (offset < len) { 1166 if (offset < len) {
1167 page = sg->page; 1167 page = virt_to_page(page_address(sg->page) + offset);
1168 get_page(page); /* increment page count */ 1168 get_page(page); /* increment page count */
1169 break; 1169 break;
1170 } 1170 }
@@ -1401,6 +1401,7 @@ sg_add(struct class_device *cl_dev, struct class_interface *cl_intf)
1401 Sg_device *sdp = NULL; 1401 Sg_device *sdp = NULL;
1402 struct cdev * cdev = NULL; 1402 struct cdev * cdev = NULL;
1403 int error, k; 1403 int error, k;
1404 unsigned long iflags;
1404 1405
1405 disk = alloc_disk(1); 1406 disk = alloc_disk(1);
1406 if (!disk) { 1407 if (!disk) {
@@ -1428,7 +1429,7 @@ sg_add(struct class_device *cl_dev, struct class_interface *cl_intf)
1428 1429
1429 error = cdev_add(cdev, MKDEV(SCSI_GENERIC_MAJOR, k), 1); 1430 error = cdev_add(cdev, MKDEV(SCSI_GENERIC_MAJOR, k), 1);
1430 if (error) 1431 if (error)
1431 goto out; 1432 goto cdev_add_err;
1432 1433
1433 sdp->cdev = cdev; 1434 sdp->cdev = cdev;
1434 if (sg_sysfs_valid) { 1435 if (sg_sysfs_valid) {
@@ -1455,6 +1456,13 @@ sg_add(struct class_device *cl_dev, struct class_interface *cl_intf)
1455 1456
1456 return 0; 1457 return 0;
1457 1458
1459cdev_add_err:
1460 write_lock_irqsave(&sg_dev_arr_lock, iflags);
1461 kfree(sg_dev_arr[k]);
1462 sg_dev_arr[k] = NULL;
1463 sg_nr_dev--;
1464 write_unlock_irqrestore(&sg_dev_arr_lock, iflags);
1465
1458out: 1466out:
1459 put_disk(disk); 1467 put_disk(disk);
1460 if (cdev) 1468 if (cdev)
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index ebf6579ed698..fae6e95a6298 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -292,7 +292,7 @@ static void rw_intr(struct scsi_cmnd * SCpnt)
292 * how many actual sectors finished, and how many sectors we need 292 * how many actual sectors finished, and how many sectors we need
293 * to say have failed. 293 * to say have failed.
294 */ 294 */
295 scsi_io_completion(SCpnt, good_bytes, block_sectors << 9); 295 scsi_io_completion(SCpnt, good_bytes);
296} 296}
297 297
298static int sr_init_command(struct scsi_cmnd * SCpnt) 298static int sr_init_command(struct scsi_cmnd * SCpnt)
@@ -360,7 +360,7 @@ static int sr_init_command(struct scsi_cmnd * SCpnt)
360 "mismatch count %d, bytes %d\n", 360 "mismatch count %d, bytes %d\n",
361 size, SCpnt->request_bufflen); 361 size, SCpnt->request_bufflen);
362 if (SCpnt->request_bufflen > size) 362 if (SCpnt->request_bufflen > size)
363 SCpnt->request_bufflen = SCpnt->bufflen = size; 363 SCpnt->request_bufflen = size;
364 } 364 }
365 } 365 }
366 366
@@ -387,8 +387,7 @@ static int sr_init_command(struct scsi_cmnd * SCpnt)
387 387
388 if (this_count > 0xffff) { 388 if (this_count > 0xffff) {
389 this_count = 0xffff; 389 this_count = 0xffff;
390 SCpnt->request_bufflen = SCpnt->bufflen = 390 SCpnt->request_bufflen = this_count * s_size;
391 this_count * s_size;
392 } 391 }
393 392
394 SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff; 393 SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff;
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index b5218fc0ac86..7f669b600677 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -368,7 +368,7 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
368 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2], 368 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2],
369 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]); 369 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]);
370 if (cmdstatp->have_sense) 370 if (cmdstatp->have_sense)
371 __scsi_print_sense("st", SRpnt->sense, SCSI_SENSE_BUFFERSIZE); 371 __scsi_print_sense(name, SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
372 } ) /* end DEB */ 372 } ) /* end DEB */
373 if (!debugging) { /* Abnormal conditions for tape */ 373 if (!debugging) { /* Abnormal conditions for tape */
374 if (!cmdstatp->have_sense) 374 if (!cmdstatp->have_sense)
@@ -384,9 +384,8 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
384 scode != VOLUME_OVERFLOW && 384 scode != VOLUME_OVERFLOW &&
385 SRpnt->cmd[0] != MODE_SENSE && 385 SRpnt->cmd[0] != MODE_SENSE &&
386 SRpnt->cmd[0] != TEST_UNIT_READY) { 386 SRpnt->cmd[0] != TEST_UNIT_READY) {
387 printk(KERN_WARNING "%s: Error with sense data: ", name); 387
388 __scsi_print_sense("st", SRpnt->sense, 388 __scsi_print_sense(name, SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
389 SCSI_SENSE_BUFFERSIZE);
390 } 389 }
391 } 390 }
392 391
@@ -3599,7 +3598,6 @@ static struct st_buffer *
3599 tb->use_sg = max_sg; 3598 tb->use_sg = max_sg;
3600 tb->frp = (struct st_buf_fragment *)(&(tb->sg[0]) + max_sg); 3599 tb->frp = (struct st_buf_fragment *)(&(tb->sg[0]) + max_sg);
3601 3600
3602 tb->in_use = 1;
3603 tb->dma = need_dma; 3601 tb->dma = need_dma;
3604 tb->buffer_size = got; 3602 tb->buffer_size = got;
3605 3603
diff --git a/drivers/scsi/st.h b/drivers/scsi/st.h
index 411209048d74..05a5cae126ec 100644
--- a/drivers/scsi/st.h
+++ b/drivers/scsi/st.h
@@ -31,7 +31,6 @@ struct st_request {
31 31
32/* The tape buffer descriptor. */ 32/* The tape buffer descriptor. */
33struct st_buffer { 33struct st_buffer {
34 unsigned char in_use;
35 unsigned char dma; /* DMA-able buffer */ 34 unsigned char dma; /* DMA-able buffer */
36 unsigned char do_dio; /* direct i/o set up? */ 35 unsigned char do_dio; /* direct i/o set up? */
37 int buffer_size; 36 int buffer_size;
diff --git a/drivers/scsi/sun3_NCR5380.c b/drivers/scsi/sun3_NCR5380.c
index 2ebe0d663899..2f8073b73bf3 100644
--- a/drivers/scsi/sun3_NCR5380.c
+++ b/drivers/scsi/sun3_NCR5380.c
@@ -517,7 +517,7 @@ static __inline__ void initialize_SCp(Scsi_Cmnd *cmd)
517 */ 517 */
518 518
519 if (cmd->use_sg) { 519 if (cmd->use_sg) {
520 cmd->SCp.buffer = (struct scatterlist *) cmd->buffer; 520 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
521 cmd->SCp.buffers_residual = cmd->use_sg - 1; 521 cmd->SCp.buffers_residual = cmd->use_sg - 1;
522 cmd->SCp.ptr = (char *) SGADDR(cmd->SCp.buffer); 522 cmd->SCp.ptr = (char *) SGADDR(cmd->SCp.buffer);
523 cmd->SCp.this_residual = cmd->SCp.buffer->length; 523 cmd->SCp.this_residual = cmd->SCp.buffer->length;
diff --git a/drivers/scsi/sun3x_esp.c b/drivers/scsi/sun3x_esp.c
index 1f328cae5c05..6b60536ac92b 100644
--- a/drivers/scsi/sun3x_esp.c
+++ b/drivers/scsi/sun3x_esp.c
@@ -347,7 +347,7 @@ static void dma_mmu_release_scsi_one (struct NCR_ESP *esp, Scsi_Cmnd *sp)
347static void dma_mmu_release_scsi_sgl (struct NCR_ESP *esp, Scsi_Cmnd *sp) 347static void dma_mmu_release_scsi_sgl (struct NCR_ESP *esp, Scsi_Cmnd *sp)
348{ 348{
349 int sz = sp->use_sg - 1; 349 int sz = sp->use_sg - 1;
350 struct scatterlist *sg = (struct scatterlist *)sp->buffer; 350 struct scatterlist *sg = (struct scatterlist *)sp->request_buffer;
351 351
352 while(sz >= 0) { 352 while(sz >= 0) {
353 dvma_unmap((char *)sg[sz].dma_address); 353 dvma_unmap((char *)sg[sz].dma_address);
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
index 8c505076c0eb..739d3ef46a40 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -2084,7 +2084,7 @@ static struct pci_device_id sym2_id_table[] __devinitdata = {
2084 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860, 2084 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
2085 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 2085 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2086 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510, 2086 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
2087 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 2087 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL },
2088 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896, 2088 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
2089 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 2089 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
2090 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895, 2090 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
index 680f38ab60d8..2083454db511 100644
--- a/drivers/scsi/wd33c93.c
+++ b/drivers/scsi/wd33c93.c
@@ -373,7 +373,7 @@ wd33c93_queuecommand(struct scsi_cmnd *cmd,
373 */ 373 */
374 374
375 if (cmd->use_sg) { 375 if (cmd->use_sg) {
376 cmd->SCp.buffer = (struct scatterlist *) cmd->buffer; 376 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
377 cmd->SCp.buffers_residual = cmd->use_sg - 1; 377 cmd->SCp.buffers_residual = cmd->use_sg - 1;
378 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + 378 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) +
379 cmd->SCp.buffer->offset; 379 cmd->SCp.buffer->offset;
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 0995430e4cf1..0ae9ced00ed4 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -299,6 +299,7 @@ static inline int map_8250_out_reg(struct uart_8250_port *up, int offset)
299 299
300static unsigned int serial_in(struct uart_8250_port *up, int offset) 300static unsigned int serial_in(struct uart_8250_port *up, int offset)
301{ 301{
302 unsigned int tmp;
302 offset = map_8250_in_reg(up, offset) << up->port.regshift; 303 offset = map_8250_in_reg(up, offset) << up->port.regshift;
303 304
304 switch (up->port.iotype) { 305 switch (up->port.iotype) {
@@ -317,6 +318,13 @@ static unsigned int serial_in(struct uart_8250_port *up, int offset)
317 return __raw_readl(up->port.membase + offset); 318 return __raw_readl(up->port.membase + offset);
318#endif 319#endif
319 320
321 case UPIO_TSI:
322 if (offset == UART_IIR) {
323 tmp = readl((u32 *)(up->port.membase + UART_RX));
324 return (cpu_to_le32(tmp) >> 8) & 0xff;
325 } else
326 return readb(up->port.membase + offset);
327
320 default: 328 default:
321 return inb(up->port.iobase + offset); 329 return inb(up->port.iobase + offset);
322 } 330 }
@@ -346,6 +354,10 @@ serial_out(struct uart_8250_port *up, int offset, int value)
346 __raw_writel(value, up->port.membase + offset); 354 __raw_writel(value, up->port.membase + offset);
347 break; 355 break;
348#endif 356#endif
357 case UPIO_TSI:
358 if (!((offset == UART_IER) && (value & UART_IER_UUE)))
359 writeb(value, up->port.membase + offset);
360 break;
349 361
350 default: 362 default:
351 outb(value, up->port.iobase + offset); 363 outb(value, up->port.iobase + offset);
@@ -2240,10 +2252,14 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count)
2240 2252
2241 touch_nmi_watchdog(); 2253 touch_nmi_watchdog();
2242 2254
2243 if (oops_in_progress) { 2255 local_irq_save(flags);
2244 locked = spin_trylock_irqsave(&up->port.lock, flags); 2256 if (up->port.sysrq) {
2257 /* serial8250_handle_port() already took the lock */
2258 locked = 0;
2259 } else if (oops_in_progress) {
2260 locked = spin_trylock(&up->port.lock);
2245 } else 2261 } else
2246 spin_lock_irqsave(&up->port.lock, flags); 2262 spin_lock(&up->port.lock);
2247 2263
2248 /* 2264 /*
2249 * First save the IER then disable the interrupts 2265 * First save the IER then disable the interrupts
@@ -2265,7 +2281,8 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count)
2265 serial_out(up, UART_IER, ier); 2281 serial_out(up, UART_IER, ier);
2266 2282
2267 if (locked) 2283 if (locked)
2268 spin_unlock_irqrestore(&up->port.lock, flags); 2284 spin_unlock(&up->port.lock);
2285 local_irq_restore(flags);
2269} 2286}
2270 2287
2271static int serial8250_console_setup(struct console *co, char *options) 2288static int serial8250_console_setup(struct console *co, char *options)
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
index 864ef859be56..851e4839d6d9 100644
--- a/drivers/serial/8250_pci.c
+++ b/drivers/serial/8250_pci.c
@@ -134,7 +134,7 @@ afavlab_setup(struct serial_private *priv, struct pciserial_board *board,
134 * and Keystone have one Diva chip with 3 UARTs. Some later machines have 134 * and Keystone have one Diva chip with 3 UARTs. Some later machines have
135 * one Diva chip, but it has been expanded to 5 UARTs. 135 * one Diva chip, but it has been expanded to 5 UARTs.
136 */ 136 */
137static int __devinit pci_hp_diva_init(struct pci_dev *dev) 137static int pci_hp_diva_init(struct pci_dev *dev)
138{ 138{
139 int rc = 0; 139 int rc = 0;
140 140
@@ -194,7 +194,7 @@ pci_hp_diva_setup(struct serial_private *priv, struct pciserial_board *board,
194/* 194/*
195 * Added for EKF Intel i960 serial boards 195 * Added for EKF Intel i960 serial boards
196 */ 196 */
197static int __devinit pci_inteli960ni_init(struct pci_dev *dev) 197static int pci_inteli960ni_init(struct pci_dev *dev)
198{ 198{
199 unsigned long oldval; 199 unsigned long oldval;
200 200
@@ -216,7 +216,7 @@ static int __devinit pci_inteli960ni_init(struct pci_dev *dev)
216 * seems to be mainly needed on card using the PLX which also use I/O 216 * seems to be mainly needed on card using the PLX which also use I/O
217 * mapped memory. 217 * mapped memory.
218 */ 218 */
219static int __devinit pci_plx9050_init(struct pci_dev *dev) 219static int pci_plx9050_init(struct pci_dev *dev)
220{ 220{
221 u8 irq_config; 221 u8 irq_config;
222 void __iomem *p; 222 void __iomem *p;
@@ -314,7 +314,7 @@ sbs_setup(struct serial_private *priv, struct pciserial_board *board,
314/* global control register offset for SBS PMC-OctalPro */ 314/* global control register offset for SBS PMC-OctalPro */
315#define OCT_REG_CR_OFF 0x500 315#define OCT_REG_CR_OFF 0x500
316 316
317static int __devinit sbs_init(struct pci_dev *dev) 317static int sbs_init(struct pci_dev *dev)
318{ 318{
319 u8 __iomem *p; 319 u8 __iomem *p;
320 320
@@ -458,11 +458,11 @@ static int pci_siig_setup(struct serial_private *priv,
458 * growing *huge*, we use this function to collapse some 70 entries 458 * growing *huge*, we use this function to collapse some 70 entries
459 * in the PCI table into one, for sanity's and compactness's sake. 459 * in the PCI table into one, for sanity's and compactness's sake.
460 */ 460 */
461static unsigned short timedia_single_port[] = { 461static const unsigned short timedia_single_port[] = {
462 0x4025, 0x4027, 0x4028, 0x5025, 0x5027, 0 462 0x4025, 0x4027, 0x4028, 0x5025, 0x5027, 0
463}; 463};
464 464
465static unsigned short timedia_dual_port[] = { 465static const unsigned short timedia_dual_port[] = {
466 0x0002, 0x4036, 0x4037, 0x4038, 0x4078, 0x4079, 0x4085, 466 0x0002, 0x4036, 0x4037, 0x4038, 0x4078, 0x4079, 0x4085,
467 0x4088, 0x4089, 0x5037, 0x5078, 0x5079, 0x5085, 0x6079, 467 0x4088, 0x4089, 0x5037, 0x5078, 0x5079, 0x5085, 0x6079,
468 0x7079, 0x8079, 0x8137, 0x8138, 0x8237, 0x8238, 0x9079, 468 0x7079, 0x8079, 0x8137, 0x8138, 0x8237, 0x8238, 0x9079,
@@ -470,35 +470,34 @@ static unsigned short timedia_dual_port[] = {
470 0xD079, 0 470 0xD079, 0
471}; 471};
472 472
473static unsigned short timedia_quad_port[] = { 473static const unsigned short timedia_quad_port[] = {
474 0x4055, 0x4056, 0x4095, 0x4096, 0x5056, 0x8156, 0x8157, 474 0x4055, 0x4056, 0x4095, 0x4096, 0x5056, 0x8156, 0x8157,
475 0x8256, 0x8257, 0x9056, 0x9156, 0x9157, 0x9158, 0x9159, 475 0x8256, 0x8257, 0x9056, 0x9156, 0x9157, 0x9158, 0x9159,
476 0x9256, 0x9257, 0xA056, 0xA157, 0xA158, 0xA159, 0xB056, 476 0x9256, 0x9257, 0xA056, 0xA157, 0xA158, 0xA159, 0xB056,
477 0xB157, 0 477 0xB157, 0
478}; 478};
479 479
480static unsigned short timedia_eight_port[] = { 480static const unsigned short timedia_eight_port[] = {
481 0x4065, 0x4066, 0x5065, 0x5066, 0x8166, 0x9066, 0x9166, 481 0x4065, 0x4066, 0x5065, 0x5066, 0x8166, 0x9066, 0x9166,
482 0x9167, 0x9168, 0xA066, 0xA167, 0xA168, 0 482 0x9167, 0x9168, 0xA066, 0xA167, 0xA168, 0
483}; 483};
484 484
485static const struct timedia_struct { 485static const struct timedia_struct {
486 int num; 486 int num;
487 unsigned short *ids; 487 const unsigned short *ids;
488} timedia_data[] = { 488} timedia_data[] = {
489 { 1, timedia_single_port }, 489 { 1, timedia_single_port },
490 { 2, timedia_dual_port }, 490 { 2, timedia_dual_port },
491 { 4, timedia_quad_port }, 491 { 4, timedia_quad_port },
492 { 8, timedia_eight_port }, 492 { 8, timedia_eight_port }
493 { 0, NULL }
494}; 493};
495 494
496static int __devinit pci_timedia_init(struct pci_dev *dev) 495static int pci_timedia_init(struct pci_dev *dev)
497{ 496{
498 unsigned short *ids; 497 const unsigned short *ids;
499 int i, j; 498 int i, j;
500 499
501 for (i = 0; timedia_data[i].num; i++) { 500 for (i = 0; i < ARRAY_SIZE(timedia_data); i++) {
502 ids = timedia_data[i].ids; 501 ids = timedia_data[i].ids;
503 for (j = 0; ids[j]; j++) 502 for (j = 0; ids[j]; j++)
504 if (dev->subsystem_device == ids[j]) 503 if (dev->subsystem_device == ids[j])
@@ -566,13 +565,13 @@ titan_400l_800l_setup(struct serial_private *priv,
566 return setup_port(priv, port, bar, offset, board->reg_shift); 565 return setup_port(priv, port, bar, offset, board->reg_shift);
567} 566}
568 567
569static int __devinit pci_xircom_init(struct pci_dev *dev) 568static int pci_xircom_init(struct pci_dev *dev)
570{ 569{
571 msleep(100); 570 msleep(100);
572 return 0; 571 return 0;
573} 572}
574 573
575static int __devinit pci_netmos_init(struct pci_dev *dev) 574static int pci_netmos_init(struct pci_dev *dev)
576{ 575{
577 /* subdevice 0x00PS means <P> parallel, <S> serial */ 576 /* subdevice 0x00PS means <P> parallel, <S> serial */
578 unsigned int num_serial = dev->subsystem_device & 0xf; 577 unsigned int num_serial = dev->subsystem_device & 0xf;
@@ -622,7 +621,7 @@ pci_default_setup(struct serial_private *priv, struct pciserial_board *board,
622 */ 621 */
623static struct pci_serial_quirk pci_serial_quirks[] = { 622static struct pci_serial_quirk pci_serial_quirks[] = {
624 /* 623 /*
625 * AFAVLAB cards. 624 * AFAVLAB cards - these may be called via parport_serial
626 * It is not clear whether this applies to all products. 625 * It is not clear whether this applies to all products.
627 */ 626 */
628 { 627 {
@@ -754,7 +753,7 @@ static struct pci_serial_quirk pci_serial_quirks[] = {
754 .exit = __devexit_p(sbs_exit), 753 .exit = __devexit_p(sbs_exit),
755 }, 754 },
756 /* 755 /*
757 * SIIG cards. 756 * SIIG cards - these may be called via parport_serial
758 */ 757 */
759 { 758 {
760 .vendor = PCI_VENDOR_ID_SIIG, 759 .vendor = PCI_VENDOR_ID_SIIG,
@@ -811,7 +810,7 @@ static struct pci_serial_quirk pci_serial_quirks[] = {
811 .setup = pci_default_setup, 810 .setup = pci_default_setup,
812 }, 811 },
813 /* 812 /*
814 * Netmos cards 813 * Netmos cards - these may be called via parport_serial
815 */ 814 */
816 { 815 {
817 .vendor = PCI_VENDOR_ID_NETMOS, 816 .vendor = PCI_VENDOR_ID_NETMOS,
@@ -936,6 +935,7 @@ enum pci_board_num_t {
936 pbn_b1_8_1382400, 935 pbn_b1_8_1382400,
937 936
938 pbn_b2_1_115200, 937 pbn_b2_1_115200,
938 pbn_b2_2_115200,
939 pbn_b2_8_115200, 939 pbn_b2_8_115200,
940 940
941 pbn_b2_1_460800, 941 pbn_b2_1_460800,
@@ -1243,6 +1243,12 @@ static struct pciserial_board pci_boards[] __devinitdata = {
1243 .base_baud = 115200, 1243 .base_baud = 115200,
1244 .uart_offset = 8, 1244 .uart_offset = 8,
1245 }, 1245 },
1246 [pbn_b2_2_115200] = {
1247 .flags = FL_BASE2,
1248 .num_ports = 2,
1249 .base_baud = 115200,
1250 .uart_offset = 8,
1251 },
1246 [pbn_b2_8_115200] = { 1252 [pbn_b2_8_115200] = {
1247 .flags = FL_BASE2, 1253 .flags = FL_BASE2,
1248 .num_ports = 8, 1254 .num_ports = 8,
@@ -2340,6 +2346,13 @@ static struct pci_device_id serial_pci_tbl[] = {
2340 pbn_b0_1_115200 }, 2346 pbn_b0_1_115200 },
2341 2347
2342 /* 2348 /*
2349 * IntaShield IS-200
2350 */
2351 { PCI_VENDOR_ID_INTASHIELD, PCI_DEVICE_ID_INTASHIELD_IS200,
2352 PCI_ANY_ID, PCI_ANY_ID, 0, 0, /* 135a.0811 */
2353 pbn_b2_2_115200 },
2354
2355 /*
2343 * These entries match devices with class COMMUNICATION_SERIAL, 2356 * These entries match devices with class COMMUNICATION_SERIAL,
2344 * COMMUNICATION_MODEM or COMMUNICATION_MULTISERIAL 2357 * COMMUNICATION_MODEM or COMMUNICATION_MULTISERIAL
2345 */ 2358 */
diff --git a/drivers/serial/8250_pnp.c b/drivers/serial/8250_pnp.c
index 739bc84f91e9..632f62d6ec7e 100644
--- a/drivers/serial/8250_pnp.c
+++ b/drivers/serial/8250_pnp.c
@@ -431,6 +431,8 @@ serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
431#endif 431#endif
432 432
433 port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; 433 port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
434 if (pnp_irq_flags(dev, 0) & IORESOURCE_IRQ_SHAREABLE)
435 port.flags |= UPF_SHARE_IRQ;
434 port.uartclk = 1843200; 436 port.uartclk = 1843200;
435 port.dev = &dev->dev; 437 port.dev = &dev->dev;
436 438
diff --git a/drivers/serial/at91_serial.c b/drivers/serial/at91_serial.c
index a7d664383dae..54c6b2adf7b7 100644
--- a/drivers/serial/at91_serial.c
+++ b/drivers/serial/at91_serial.c
@@ -41,6 +41,7 @@
41#include <asm/mach/serial_at91.h> 41#include <asm/mach/serial_at91.h>
42#include <asm/arch/board.h> 42#include <asm/arch/board.h>
43#include <asm/arch/system.h> 43#include <asm/arch/system.h>
44#include <asm/arch/gpio.h>
44 45
45#if defined(CONFIG_SERIAL_AT91_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 46#if defined(CONFIG_SERIAL_AT91_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
46#define SUPPORT_SYSRQ 47#define SUPPORT_SYSRQ
@@ -140,9 +141,9 @@ static void at91_set_mctrl(struct uart_port *port, u_int mctrl)
140 */ 141 */
141 if (port->mapbase == AT91_BASE_US0) { 142 if (port->mapbase == AT91_BASE_US0) {
142 if (mctrl & TIOCM_RTS) 143 if (mctrl & TIOCM_RTS)
143 at91_sys_write(AT91_PIOA + PIO_CODR, AT91_PA21_RTS0); 144 at91_set_gpio_value(AT91_PIN_PA21, 0);
144 else 145 else
145 at91_sys_write(AT91_PIOA + PIO_SODR, AT91_PA21_RTS0); 146 at91_set_gpio_value(AT91_PIN_PA21, 1);
146 } 147 }
147 } 148 }
148 149
diff --git a/drivers/serial/dz.c b/drivers/serial/dz.c
index d119c8296a78..8a98aae80e22 100644
--- a/drivers/serial/dz.c
+++ b/drivers/serial/dz.c
@@ -673,7 +673,7 @@ static void dz_reset(struct dz_port *dport)
673} 673}
674 674
675#ifdef CONFIG_SERIAL_DZ_CONSOLE 675#ifdef CONFIG_SERIAL_DZ_CONSOLE
676static void dz_console_putchar(struct uart_port *port, int ch) 676static void dz_console_putchar(struct uart_port *uport, int ch)
677{ 677{
678 struct dz_port *dport = (struct dz_port *)uport; 678 struct dz_port *dport = (struct dz_port *)uport;
679 unsigned long flags; 679 unsigned long flags;
diff --git a/drivers/serial/ip22zilog.c b/drivers/serial/ip22zilog.c
index 342042889f6e..5ff269fb604c 100644
--- a/drivers/serial/ip22zilog.c
+++ b/drivers/serial/ip22zilog.c
@@ -1143,9 +1143,8 @@ static void __init ip22zilog_prepare(void)
1143 up[(chip * 2) + 1].port.fifosize = 1; 1143 up[(chip * 2) + 1].port.fifosize = 1;
1144 up[(chip * 2) + 1].port.ops = &ip22zilog_pops; 1144 up[(chip * 2) + 1].port.ops = &ip22zilog_pops;
1145 up[(chip * 2) + 1].port.type = PORT_IP22ZILOG; 1145 up[(chip * 2) + 1].port.type = PORT_IP22ZILOG;
1146 up[(chip * 2) + 1].port.flags |= IP22ZILOG_FLAG_IS_CHANNEL_A;
1147 up[(chip * 2) + 1].port.line = (chip * 2) + 1; 1146 up[(chip * 2) + 1].port.line = (chip * 2) + 1;
1148 up[(chip * 2) + 1].flags = 0; 1147 up[(chip * 2) + 1].flags |= IP22ZILOG_FLAG_IS_CHANNEL_A;
1149 } 1148 }
1150} 1149}
1151 1150
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 48eb22d3a63e..7708e5dd3656 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -726,8 +726,7 @@ mpc52xx_uart_probe(struct platform_device *dev)
726 726
727 spin_lock_init(&port->lock); 727 spin_lock_init(&port->lock);
728 port->uartclk = __res.bi_ipbfreq / 2; /* Look at CTLR doc */ 728 port->uartclk = __res.bi_ipbfreq / 2; /* Look at CTLR doc */
729 port->fifosize = 255; /* Should be 512 ! But it can't be */ 729 port->fifosize = 512;
730 /* stored in a unsigned char */
731 port->iotype = UPIO_MEM; 730 port->iotype = UPIO_MEM;
732 port->flags = UPF_BOOT_AUTOCONF | 731 port->flags = UPF_BOOT_AUTOCONF |
733 ( uart_console(port) ? 0 : UPF_IOREMAP ); 732 ( uart_console(port) ? 0 : UPF_IOREMAP );
diff --git a/drivers/serial/pmac_zilog.c b/drivers/serial/pmac_zilog.c
index 459c0231aef3..bfd2a22759eb 100644
--- a/drivers/serial/pmac_zilog.c
+++ b/drivers/serial/pmac_zilog.c
@@ -1443,8 +1443,8 @@ static int __init pmz_init_port(struct uart_pmac_port *uap)
1443 uap->flags &= ~PMACZILOG_FLAG_HAS_DMA; 1443 uap->flags &= ~PMACZILOG_FLAG_HAS_DMA;
1444 goto no_dma; 1444 goto no_dma;
1445 } 1445 }
1446 uap->tx_dma_irq = np->intrs[1].line; 1446 uap->tx_dma_irq = irq_of_parse_and_map(np, 1);
1447 uap->rx_dma_irq = np->intrs[2].line; 1447 uap->rx_dma_irq = irq_of_parse_and_map(np, 2);
1448 } 1448 }
1449no_dma: 1449no_dma:
1450 1450
@@ -1491,7 +1491,7 @@ no_dma:
1491 * Init remaining bits of "port" structure 1491 * Init remaining bits of "port" structure
1492 */ 1492 */
1493 uap->port.iotype = UPIO_MEM; 1493 uap->port.iotype = UPIO_MEM;
1494 uap->port.irq = np->intrs[0].line; 1494 uap->port.irq = irq_of_parse_and_map(np, 0);
1495 uap->port.uartclk = ZS_CLOCK; 1495 uap->port.uartclk = ZS_CLOCK;
1496 uap->port.fifosize = 1; 1496 uap->port.fifosize = 1;
1497 uap->port.ops = &pmz_pops; 1497 uap->port.ops = &pmz_pops;
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index c54af8774393..372e47f7d596 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -49,6 +49,12 @@
49 */ 49 */
50static DEFINE_MUTEX(port_mutex); 50static DEFINE_MUTEX(port_mutex);
51 51
52/*
53 * lockdep: port->lock is initialized in two places, but we
54 * want only one lock-class:
55 */
56static struct lock_class_key port_lock_key;
57
52#define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8) 58#define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
53 59
54#define uart_users(state) ((state)->count + ((state)->info ? (state)->info->blocked_open : 0)) 60#define uart_users(state) ((state)->count + ((state)->info ? (state)->info->blocked_open : 0))
@@ -690,7 +696,8 @@ static int uart_set_info(struct uart_state *state,
690 (new_serial.baud_base != port->uartclk / 16) || 696 (new_serial.baud_base != port->uartclk / 16) ||
691 (close_delay != state->close_delay) || 697 (close_delay != state->close_delay) ||
692 (closing_wait != state->closing_wait) || 698 (closing_wait != state->closing_wait) ||
693 (new_serial.xmit_fifo_size != port->fifosize) || 699 (new_serial.xmit_fifo_size &&
700 new_serial.xmit_fifo_size != port->fifosize) ||
694 (((new_flags ^ old_flags) & ~UPF_USR_MASK) != 0)) 701 (((new_flags ^ old_flags) & ~UPF_USR_MASK) != 0))
695 goto exit; 702 goto exit;
696 port->flags = ((port->flags & ~UPF_USR_MASK) | 703 port->flags = ((port->flags & ~UPF_USR_MASK) |
@@ -795,7 +802,8 @@ static int uart_set_info(struct uart_state *state,
795 port->custom_divisor = new_serial.custom_divisor; 802 port->custom_divisor = new_serial.custom_divisor;
796 state->close_delay = close_delay; 803 state->close_delay = close_delay;
797 state->closing_wait = closing_wait; 804 state->closing_wait = closing_wait;
798 port->fifosize = new_serial.xmit_fifo_size; 805 if (new_serial.xmit_fifo_size)
806 port->fifosize = new_serial.xmit_fifo_size;
799 if (state->info->tty) 807 if (state->info->tty)
800 state->info->tty->low_latency = 808 state->info->tty->low_latency =
801 (port->flags & UPF_LOW_LATENCY) ? 1 : 0; 809 (port->flags & UPF_LOW_LATENCY) ? 1 : 0;
@@ -1865,6 +1873,7 @@ uart_set_options(struct uart_port *port, struct console *co,
1865 * early. 1873 * early.
1866 */ 1874 */
1867 spin_lock_init(&port->lock); 1875 spin_lock_init(&port->lock);
1876 lockdep_set_class(&port->lock, &port_lock_key);
1868 1877
1869 memset(&termios, 0, sizeof(struct termios)); 1878 memset(&termios, 0, sizeof(struct termios));
1870 1879
@@ -2027,6 +2036,7 @@ uart_report_port(struct uart_driver *drv, struct uart_port *port)
2027 case UPIO_MEM: 2036 case UPIO_MEM:
2028 case UPIO_MEM32: 2037 case UPIO_MEM32:
2029 case UPIO_AU: 2038 case UPIO_AU:
2039 case UPIO_TSI:
2030 snprintf(address, sizeof(address), 2040 snprintf(address, sizeof(address),
2031 "MMIO 0x%lx", port->mapbase); 2041 "MMIO 0x%lx", port->mapbase);
2032 break; 2042 break;
@@ -2247,8 +2257,10 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *port)
2247 * If this port is a console, then the spinlock is already 2257 * If this port is a console, then the spinlock is already
2248 * initialised. 2258 * initialised.
2249 */ 2259 */
2250 if (!(uart_console(port) && (port->cons->flags & CON_ENABLED))) 2260 if (!(uart_console(port) && (port->cons->flags & CON_ENABLED))) {
2251 spin_lock_init(&port->lock); 2261 spin_lock_init(&port->lock);
2262 lockdep_set_class(&port->lock, &port_lock_key);
2263 }
2252 2264
2253 uart_configure_port(drv, state, port); 2265 uart_configure_port(drv, state, port);
2254 2266
@@ -2365,6 +2377,9 @@ int uart_match_port(struct uart_port *port1, struct uart_port *port2)
2365 return (port1->iobase == port2->iobase) && 2377 return (port1->iobase == port2->iobase) &&
2366 (port1->hub6 == port2->hub6); 2378 (port1->hub6 == port2->hub6);
2367 case UPIO_MEM: 2379 case UPIO_MEM:
2380 case UPIO_MEM32:
2381 case UPIO_AU:
2382 case UPIO_TSI:
2368 return (port1->mapbase == port2->mapbase); 2383 return (port1->mapbase == port2->mapbase);
2369 } 2384 }
2370 return 0; 2385 return 0;
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c
index 301573373c30..cbede06cac27 100644
--- a/drivers/serial/sh-sci.c
+++ b/drivers/serial/sh-sci.c
@@ -1579,7 +1579,7 @@ static int __init serial_console_setup(struct console *co, char *options)
1579 h8300_sci_enable(port, sci_enable); 1579 h8300_sci_enable(port, sci_enable);
1580#endif 1580#endif
1581#elif defined(CONFIG_SUPERH64) 1581#elif defined(CONFIG_SUPERH64)
1582 port->uartclk = current_cpu_info.module_clock * 16; 1582 port->uartclk = current_cpu_data.module_clock * 16;
1583#else 1583#else
1584 { 1584 {
1585 struct clk *clk = clk_get("module_clk"); 1585 struct clk *clk = clk_get("module_clk");
@@ -1720,7 +1720,7 @@ static int __init sci_init(void)
1720#if defined(__H8300H__) || defined(__H8300S__) 1720#if defined(__H8300H__) || defined(__H8300S__)
1721 sciport->port.uartclk = CONFIG_CPU_CLOCK; 1721 sciport->port.uartclk = CONFIG_CPU_CLOCK;
1722#elif defined(CONFIG_SUPERH64) 1722#elif defined(CONFIG_SUPERH64)
1723 sciport->port.uartclk = current_cpu_info.module_clock * 16; 1723 sciport->port.uartclk = current_cpu_data.module_clock * 16;
1724#else 1724#else
1725 struct clk *clk = clk_get("module_clk"); 1725 struct clk *clk = clk_get("module_clk");
1726 sciport->port.uartclk = clk_get_rate(clk) * 16; 1726 sciport->port.uartclk = clk_get_rate(clk) * 16;
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c
index 0dbd4df44c05..cfe20f730436 100644
--- a/drivers/serial/sunsab.c
+++ b/drivers/serial/sunsab.c
@@ -886,6 +886,15 @@ static int sunsab_console_setup(struct console *con, char *options)
886 unsigned long flags; 886 unsigned long flags;
887 unsigned int baud, quot; 887 unsigned int baud, quot;
888 888
889 /*
890 * The console framework calls us for each and every port
891 * registered. Defer the console setup until the requested
892 * port has been properly discovered. A bit of a hack,
893 * though...
894 */
895 if (up->port.type != PORT_SUNSAB)
896 return -1;
897
889 printk("Console: ttyS%d (SAB82532)\n", 898 printk("Console: ttyS%d (SAB82532)\n",
890 (sunsab_reg.minor - 64) + con->index); 899 (sunsab_reg.minor - 64) + con->index);
891 900
@@ -1047,12 +1056,13 @@ static int __devinit sab_probe(struct of_device *op, const struct of_device_id *
1047 up = &sunsab_ports[inst * 2]; 1056 up = &sunsab_ports[inst * 2];
1048 1057
1049 err = sunsab_init_one(&up[0], op, 1058 err = sunsab_init_one(&up[0], op,
1050 sizeof(union sab82532_async_regs), 1059 0,
1051 (inst * 2) + 0); 1060 (inst * 2) + 0);
1052 if (err) 1061 if (err)
1053 return err; 1062 return err;
1054 1063
1055 err = sunsab_init_one(&up[0], op, 0, 1064 err = sunsab_init_one(&up[1], op,
1065 sizeof(union sab82532_async_regs),
1056 (inst * 2) + 1); 1066 (inst * 2) + 1);
1057 if (err) { 1067 if (err) {
1058 of_iounmap(up[0].port.membase, 1068 of_iounmap(up[0].port.membase,
@@ -1117,7 +1127,7 @@ static int __init sunsab_init(void)
1117 int err; 1127 int err;
1118 1128
1119 num_channels = 0; 1129 num_channels = 0;
1120 for_each_node_by_name(dp, "su") 1130 for_each_node_by_name(dp, "se")
1121 num_channels += 2; 1131 num_channels += 2;
1122 for_each_node_by_name(dp, "serial") { 1132 for_each_node_by_name(dp, "serial") {
1123 if (of_device_is_compatible(dp, "sab82532")) 1133 if (of_device_is_compatible(dp, "sab82532"))
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index f9013baba05b..d3a5aeee73a3 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -1200,6 +1200,11 @@ static int __init sunsu_kbd_ms_init(struct uart_sunsu_port *up)
1200 if (up->port.type == PORT_UNKNOWN) 1200 if (up->port.type == PORT_UNKNOWN)
1201 return -ENODEV; 1201 return -ENODEV;
1202 1202
1203 printk("%s: %s port at %lx, irq %u\n",
1204 to_of_device(up->port.dev)->node->full_name,
1205 (up->su_type == SU_PORT_KBD) ? "Keyboard" : "Mouse",
1206 up->port.mapbase, up->port.irq);
1207
1203#ifdef CONFIG_SERIO 1208#ifdef CONFIG_SERIO
1204 serio = &up->serio; 1209 serio = &up->serio;
1205 serio->port_data = up; 1210 serio->port_data = up;
@@ -1406,25 +1411,35 @@ static int __devinit su_probe(struct of_device *op, const struct of_device_id *m
1406 struct device_node *dp = op->node; 1411 struct device_node *dp = op->node;
1407 struct uart_sunsu_port *up; 1412 struct uart_sunsu_port *up;
1408 struct resource *rp; 1413 struct resource *rp;
1414 enum su_type type;
1409 int err; 1415 int err;
1410 1416
1411 if (inst >= UART_NR) 1417 type = su_get_type(dp);
1412 return -EINVAL; 1418 if (type == SU_PORT_PORT) {
1419 if (inst >= UART_NR)
1420 return -EINVAL;
1421 up = &sunsu_ports[inst];
1422 } else {
1423 up = kzalloc(sizeof(*up), GFP_KERNEL);
1424 if (!up)
1425 return -ENOMEM;
1426 }
1413 1427
1414 up = &sunsu_ports[inst];
1415 up->port.line = inst; 1428 up->port.line = inst;
1416 1429
1417 spin_lock_init(&up->port.lock); 1430 spin_lock_init(&up->port.lock);
1418 1431
1419 up->su_type = su_get_type(dp); 1432 up->su_type = type;
1420 1433
1421 rp = &op->resource[0]; 1434 rp = &op->resource[0];
1422 up->port.mapbase = op->resource[0].start; 1435 up->port.mapbase = rp->start;
1423
1424 up->reg_size = (rp->end - rp->start) + 1; 1436 up->reg_size = (rp->end - rp->start) + 1;
1425 up->port.membase = of_ioremap(rp, 0, up->reg_size, "su"); 1437 up->port.membase = of_ioremap(rp, 0, up->reg_size, "su");
1426 if (!up->port.membase) 1438 if (!up->port.membase) {
1439 if (type != SU_PORT_PORT)
1440 kfree(up);
1427 return -ENOMEM; 1441 return -ENOMEM;
1442 }
1428 1443
1429 up->port.irq = op->irqs[0]; 1444 up->port.irq = op->irqs[0];
1430 1445
@@ -1436,8 +1451,11 @@ static int __devinit su_probe(struct of_device *op, const struct of_device_id *m
1436 err = 0; 1451 err = 0;
1437 if (up->su_type == SU_PORT_KBD || up->su_type == SU_PORT_MS) { 1452 if (up->su_type == SU_PORT_KBD || up->su_type == SU_PORT_MS) {
1438 err = sunsu_kbd_ms_init(up); 1453 err = sunsu_kbd_ms_init(up);
1439 if (err) 1454 if (err) {
1455 kfree(up);
1440 goto out_unmap; 1456 goto out_unmap;
1457 }
1458 dev_set_drvdata(&op->dev, up);
1441 1459
1442 return 0; 1460 return 0;
1443 } 1461 }
@@ -1476,8 +1494,12 @@ static int __devexit su_remove(struct of_device *dev)
1476#ifdef CONFIG_SERIO 1494#ifdef CONFIG_SERIO
1477 serio_unregister_port(&up->serio); 1495 serio_unregister_port(&up->serio);
1478#endif 1496#endif
1479 } else if (up->port.type != PORT_UNKNOWN) 1497 kfree(up);
1498 } else if (up->port.type != PORT_UNKNOWN) {
1480 uart_remove_one_port(&sunsu_reg, &up->port); 1499 uart_remove_one_port(&sunsu_reg, &up->port);
1500 }
1501
1502 dev_set_drvdata(&dev->dev, NULL);
1481 1503
1482 return 0; 1504 return 0;
1483} 1505}
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index a1456d9352cb..d34f336d53d8 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -68,9 +68,6 @@ static int num_sunzilog;
68#define NUM_SUNZILOG num_sunzilog 68#define NUM_SUNZILOG num_sunzilog
69#define NUM_CHANNELS (NUM_SUNZILOG * 2) 69#define NUM_CHANNELS (NUM_SUNZILOG * 2)
70 70
71#define KEYBOARD_LINE 0x2
72#define MOUSE_LINE 0x3
73
74#define ZS_CLOCK 4915200 /* Zilog input clock rate. */ 71#define ZS_CLOCK 4915200 /* Zilog input clock rate. */
75#define ZS_CLOCK_DIVISOR 16 /* Divisor this driver uses. */ 72#define ZS_CLOCK_DIVISOR 16 /* Divisor this driver uses. */
76 73
@@ -1149,6 +1146,9 @@ static int __init sunzilog_console_setup(struct console *con, char *options)
1149 unsigned long flags; 1146 unsigned long flags;
1150 int baud, brg; 1147 int baud, brg;
1151 1148
1149 if (up->port.type != PORT_SUNZILOG)
1150 return -1;
1151
1152 printk(KERN_INFO "Console: ttyS%d (SunZilog zs%d)\n", 1152 printk(KERN_INFO "Console: ttyS%d (SunZilog zs%d)\n",
1153 (sunzilog_reg.minor - 64) + con->index, con->index); 1153 (sunzilog_reg.minor - 64) + con->index, con->index);
1154 1154
@@ -1225,12 +1225,10 @@ static void __init sunzilog_init_kbdms(struct uart_sunzilog_port *up, int channe
1225{ 1225{
1226 int baud, brg; 1226 int baud, brg;
1227 1227
1228 if (channel == KEYBOARD_LINE) { 1228 if (up->flags & SUNZILOG_FLAG_CONS_KEYB) {
1229 up->flags |= SUNZILOG_FLAG_CONS_KEYB;
1230 up->cflag = B1200 | CS8 | CLOCAL | CREAD; 1229 up->cflag = B1200 | CS8 | CLOCAL | CREAD;
1231 baud = 1200; 1230 baud = 1200;
1232 } else { 1231 } else {
1233 up->flags |= SUNZILOG_FLAG_CONS_MOUSE;
1234 up->cflag = B4800 | CS8 | CLOCAL | CREAD; 1232 up->cflag = B4800 | CS8 | CLOCAL | CREAD;
1235 baud = 4800; 1233 baud = 4800;
1236 } 1234 }
@@ -1243,14 +1241,14 @@ static void __init sunzilog_init_kbdms(struct uart_sunzilog_port *up, int channe
1243} 1241}
1244 1242
1245#ifdef CONFIG_SERIO 1243#ifdef CONFIG_SERIO
1246static void __init sunzilog_register_serio(struct uart_sunzilog_port *up, int channel) 1244static void __init sunzilog_register_serio(struct uart_sunzilog_port *up)
1247{ 1245{
1248 struct serio *serio = &up->serio; 1246 struct serio *serio = &up->serio;
1249 1247
1250 serio->port_data = up; 1248 serio->port_data = up;
1251 1249
1252 serio->id.type = SERIO_RS232; 1250 serio->id.type = SERIO_RS232;
1253 if (channel == KEYBOARD_LINE) { 1251 if (up->flags & SUNZILOG_FLAG_CONS_KEYB) {
1254 serio->id.proto = SERIO_SUNKBD; 1252 serio->id.proto = SERIO_SUNKBD;
1255 strlcpy(serio->name, "zskbd", sizeof(serio->name)); 1253 strlcpy(serio->name, "zskbd", sizeof(serio->name));
1256 } else { 1254 } else {
@@ -1259,7 +1257,8 @@ static void __init sunzilog_register_serio(struct uart_sunzilog_port *up, int ch
1259 strlcpy(serio->name, "zsms", sizeof(serio->name)); 1257 strlcpy(serio->name, "zsms", sizeof(serio->name));
1260 } 1258 }
1261 strlcpy(serio->phys, 1259 strlcpy(serio->phys,
1262 (channel == KEYBOARD_LINE ? "zs/serio0" : "zs/serio1"), 1260 ((up->flags & SUNZILOG_FLAG_CONS_KEYB) ?
1261 "zs/serio0" : "zs/serio1"),
1263 sizeof(serio->phys)); 1262 sizeof(serio->phys));
1264 1263
1265 serio->write = sunzilog_serio_write; 1264 serio->write = sunzilog_serio_write;
@@ -1286,8 +1285,8 @@ static void __init sunzilog_init_hw(struct uart_sunzilog_port *up)
1286 (void) read_zsreg(channel, R0); 1285 (void) read_zsreg(channel, R0);
1287 } 1286 }
1288 1287
1289 if (up->port.line == KEYBOARD_LINE || 1288 if (up->flags & (SUNZILOG_FLAG_CONS_KEYB |
1290 up->port.line == MOUSE_LINE) { 1289 SUNZILOG_FLAG_CONS_MOUSE)) {
1291 sunzilog_init_kbdms(up, up->port.line); 1290 sunzilog_init_kbdms(up, up->port.line);
1292 up->curregs[R9] |= (NV | MIE); 1291 up->curregs[R9] |= (NV | MIE);
1293 write_zsreg(channel, R9, up->curregs[R9]); 1292 write_zsreg(channel, R9, up->curregs[R9]);
@@ -1313,37 +1312,26 @@ static void __init sunzilog_init_hw(struct uart_sunzilog_port *up)
1313 spin_unlock_irqrestore(&up->port.lock, flags); 1312 spin_unlock_irqrestore(&up->port.lock, flags);
1314 1313
1315#ifdef CONFIG_SERIO 1314#ifdef CONFIG_SERIO
1316 if (up->port.line == KEYBOARD_LINE || up->port.line == MOUSE_LINE) 1315 if (up->flags & (SUNZILOG_FLAG_CONS_KEYB |
1317 sunzilog_register_serio(up, up->port.line); 1316 SUNZILOG_FLAG_CONS_MOUSE))
1317 sunzilog_register_serio(up);
1318#endif 1318#endif
1319} 1319}
1320 1320
1321static int __devinit zs_get_instance(struct device_node *dp)
1322{
1323 int ret;
1324
1325 ret = of_getintprop_default(dp, "slave", -1);
1326 if (ret != -1)
1327 return ret;
1328
1329 if (of_find_property(dp, "keyboard", NULL))
1330 ret = 1;
1331 else
1332 ret = 0;
1333
1334 return ret;
1335}
1336
1337static int zilog_irq = -1; 1321static int zilog_irq = -1;
1338 1322
1339static int __devinit zs_probe(struct of_device *dev, const struct of_device_id *match) 1323static int __devinit zs_probe(struct of_device *op, const struct of_device_id *match)
1340{ 1324{
1341 struct of_device *op = to_of_device(&dev->dev); 1325 static int inst;
1342 struct uart_sunzilog_port *up; 1326 struct uart_sunzilog_port *up;
1343 struct zilog_layout __iomem *rp; 1327 struct zilog_layout __iomem *rp;
1344 int inst = zs_get_instance(dev->node); 1328 int keyboard_mouse;
1345 int err; 1329 int err;
1346 1330
1331 keyboard_mouse = 0;
1332 if (of_find_property(op->node, "keyboard", NULL))
1333 keyboard_mouse = 1;
1334
1347 sunzilog_chip_regs[inst] = of_ioremap(&op->resource[0], 0, 1335 sunzilog_chip_regs[inst] = of_ioremap(&op->resource[0], 0,
1348 sizeof(struct zilog_layout), 1336 sizeof(struct zilog_layout),
1349 "zs"); 1337 "zs");
@@ -1352,16 +1340,8 @@ static int __devinit zs_probe(struct of_device *dev, const struct of_device_id *
1352 1340
1353 rp = sunzilog_chip_regs[inst]; 1341 rp = sunzilog_chip_regs[inst];
1354 1342
1355 if (zilog_irq == -1) { 1343 if (zilog_irq == -1)
1356 zilog_irq = op->irqs[0]; 1344 zilog_irq = op->irqs[0];
1357 err = request_irq(zilog_irq, sunzilog_interrupt, IRQF_SHARED,
1358 "zs", sunzilog_irq_chain);
1359 if (err) {
1360 of_iounmap(rp, sizeof(struct zilog_layout));
1361
1362 return err;
1363 }
1364 }
1365 1345
1366 up = &sunzilog_port_table[inst * 2]; 1346 up = &sunzilog_port_table[inst * 2];
1367 1347
@@ -1378,7 +1358,7 @@ static int __devinit zs_probe(struct of_device *dev, const struct of_device_id *
1378 up[0].port.line = (inst * 2) + 0; 1358 up[0].port.line = (inst * 2) + 0;
1379 up[0].port.dev = &op->dev; 1359 up[0].port.dev = &op->dev;
1380 up[0].flags |= SUNZILOG_FLAG_IS_CHANNEL_A; 1360 up[0].flags |= SUNZILOG_FLAG_IS_CHANNEL_A;
1381 if (inst == 1) 1361 if (keyboard_mouse)
1382 up[0].flags |= SUNZILOG_FLAG_CONS_KEYB; 1362 up[0].flags |= SUNZILOG_FLAG_CONS_KEYB;
1383 sunzilog_init_hw(&up[0]); 1363 sunzilog_init_hw(&up[0]);
1384 1364
@@ -1395,11 +1375,11 @@ static int __devinit zs_probe(struct of_device *dev, const struct of_device_id *
1395 up[1].port.line = (inst * 2) + 1; 1375 up[1].port.line = (inst * 2) + 1;
1396 up[1].port.dev = &op->dev; 1376 up[1].port.dev = &op->dev;
1397 up[1].flags |= 0; 1377 up[1].flags |= 0;
1398 if (inst == 1) 1378 if (keyboard_mouse)
1399 up[1].flags |= SUNZILOG_FLAG_CONS_MOUSE; 1379 up[1].flags |= SUNZILOG_FLAG_CONS_MOUSE;
1400 sunzilog_init_hw(&up[1]); 1380 sunzilog_init_hw(&up[1]);
1401 1381
1402 if (inst != 1) { 1382 if (!keyboard_mouse) {
1403 err = uart_add_one_port(&sunzilog_reg, &up[0].port); 1383 err = uart_add_one_port(&sunzilog_reg, &up[0].port);
1404 if (err) { 1384 if (err) {
1405 of_iounmap(rp, sizeof(struct zilog_layout)); 1385 of_iounmap(rp, sizeof(struct zilog_layout));
@@ -1411,9 +1391,18 @@ static int __devinit zs_probe(struct of_device *dev, const struct of_device_id *
1411 of_iounmap(rp, sizeof(struct zilog_layout)); 1391 of_iounmap(rp, sizeof(struct zilog_layout));
1412 return err; 1392 return err;
1413 } 1393 }
1394 } else {
1395 printk(KERN_INFO "%s: Keyboard at MMIO %lx (irq = %d) "
1396 "is a zs\n",
1397 op->dev.bus_id, up[0].port.mapbase, op->irqs[0]);
1398 printk(KERN_INFO "%s: Mouse at MMIO %lx (irq = %d) "
1399 "is a zs\n",
1400 op->dev.bus_id, up[1].port.mapbase, op->irqs[0]);
1414 } 1401 }
1415 1402
1416 dev_set_drvdata(&dev->dev, &up[0]); 1403 dev_set_drvdata(&op->dev, &up[0]);
1404
1405 inst++;
1417 1406
1418 return 0; 1407 return 0;
1419} 1408}
@@ -1462,36 +1451,65 @@ static struct of_platform_driver zs_driver = {
1462static int __init sunzilog_init(void) 1451static int __init sunzilog_init(void)
1463{ 1452{
1464 struct device_node *dp; 1453 struct device_node *dp;
1465 int err; 1454 int err, uart_count;
1455 int num_keybms;
1466 1456
1467 NUM_SUNZILOG = 0; 1457 NUM_SUNZILOG = 0;
1468 for_each_node_by_name(dp, "zs") 1458 num_keybms = 0;
1459 for_each_node_by_name(dp, "zs") {
1469 NUM_SUNZILOG++; 1460 NUM_SUNZILOG++;
1461 if (of_find_property(dp, "keyboard", NULL))
1462 num_keybms++;
1463 }
1470 1464
1465 uart_count = 0;
1471 if (NUM_SUNZILOG) { 1466 if (NUM_SUNZILOG) {
1472 int uart_count; 1467 int uart_count;
1473 1468
1474 err = sunzilog_alloc_tables(); 1469 err = sunzilog_alloc_tables();
1475 if (err) 1470 if (err)
1476 return err; 1471 goto out;
1477 1472
1478 /* Subtract 1 for keyboard, 1 for mouse. */ 1473 uart_count = (NUM_SUNZILOG * 2) - (2 * num_keybms);
1479 uart_count = (NUM_SUNZILOG * 2) - 2;
1480 1474
1481 sunzilog_reg.nr = uart_count; 1475 sunzilog_reg.nr = uart_count;
1482 sunzilog_reg.minor = sunserial_current_minor; 1476 sunzilog_reg.minor = sunserial_current_minor;
1483 err = uart_register_driver(&sunzilog_reg); 1477 err = uart_register_driver(&sunzilog_reg);
1484 if (err) { 1478 if (err)
1485 sunzilog_free_tables(); 1479 goto out_free_tables;
1486 return err; 1480
1487 }
1488 sunzilog_reg.tty_driver->name_base = sunzilog_reg.minor - 64; 1481 sunzilog_reg.tty_driver->name_base = sunzilog_reg.minor - 64;
1489 sunzilog_reg.cons = SUNZILOG_CONSOLE(); 1482 sunzilog_reg.cons = SUNZILOG_CONSOLE();
1490 1483
1491 sunserial_current_minor += uart_count; 1484 sunserial_current_minor += uart_count;
1492 } 1485 }
1493 1486
1494 return of_register_driver(&zs_driver, &of_bus_type); 1487 err = of_register_driver(&zs_driver, &of_bus_type);
1488 if (err)
1489 goto out_unregister_uart;
1490
1491 if (zilog_irq != -1) {
1492 err = request_irq(zilog_irq, sunzilog_interrupt, IRQF_SHARED,
1493 "zs", sunzilog_irq_chain);
1494 if (err)
1495 goto out_unregister_driver;
1496 }
1497
1498out:
1499 return err;
1500
1501out_unregister_driver:
1502 of_unregister_driver(&zs_driver);
1503
1504out_unregister_uart:
1505 if (NUM_SUNZILOG) {
1506 uart_unregister_driver(&sunzilog_reg);
1507 sunzilog_reg.cons = NULL;
1508 }
1509
1510out_free_tables:
1511 sunzilog_free_tables();
1512 goto out;
1495} 1513}
1496 1514
1497static void __exit sunzilog_exit(void) 1515static void __exit sunzilog_exit(void)
diff --git a/drivers/serial/vr41xx_siu.c b/drivers/serial/vr41xx_siu.c
index e93d0edc2e08..6c8b0ea83c3c 100644
--- a/drivers/serial/vr41xx_siu.c
+++ b/drivers/serial/vr41xx_siu.c
@@ -38,6 +38,7 @@
38#include <linux/tty_flip.h> 38#include <linux/tty_flip.h>
39 39
40#include <asm/io.h> 40#include <asm/io.h>
41#include <asm/vr41xx/irq.h>
41#include <asm/vr41xx/siu.h> 42#include <asm/vr41xx/siu.h>
42#include <asm/vr41xx/vr41xx.h> 43#include <asm/vr41xx/vr41xx.h>
43 44
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ed1cdf6ac8f3..146298ad7371 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -510,7 +510,7 @@ static void spi_complete(void *arg)
510 */ 510 */
511int spi_sync(struct spi_device *spi, struct spi_message *message) 511int spi_sync(struct spi_device *spi, struct spi_message *message)
512{ 512{
513 DECLARE_COMPLETION(done); 513 DECLARE_COMPLETION_ONSTACK(done);
514 int status; 514 int status;
515 515
516 message->complete = spi_complete; 516 message->complete = spi_complete;
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 7fdbc5dad5fd..005043197527 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -23,7 +23,8 @@ config USB_ARCH_HAS_OHCI
23 default y if ARCH_LH7A404 23 default y if ARCH_LH7A404
24 default y if ARCH_S3C2410 24 default y if ARCH_S3C2410
25 default y if PXA27x 25 default y if PXA27x
26 default y if ARCH_AT91RM9200 26 default y if ARCH_EP93XX
27 default y if (ARCH_AT91RM9200 || ARCH_AT91SAM9261)
27 # PPC: 28 # PPC:
28 default y if STB03xxx 29 default y if STB03xxx
29 default y if PPC_MPC52xx 30 default y if PPC_MPC52xx
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index c7123bf71c58..4710eb02ed64 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -48,7 +48,7 @@ obj-$(CONFIG_USB_MICROTEK) += image/
48obj-$(CONFIG_USB_SERIAL) += serial/ 48obj-$(CONFIG_USB_SERIAL) += serial/
49 49
50obj-$(CONFIG_USB_AUERSWALD) += misc/ 50obj-$(CONFIG_USB_AUERSWALD) += misc/
51obj-$(CONFIG_USB_CY7C63) += misc/ 51obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/
52obj-$(CONFIG_USB_CYTHERM) += misc/ 52obj-$(CONFIG_USB_CYTHERM) += misc/
53obj-$(CONFIG_USB_EMI26) += misc/ 53obj-$(CONFIG_USB_EMI26) += misc/
54obj-$(CONFIG_USB_EMI62) += misc/ 54obj-$(CONFIG_USB_EMI62) += misc/
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 3670d77e912c..ca90326f2f5c 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -291,13 +291,13 @@ static void acm_read_bulk(struct urb *urb, struct pt_regs *regs)
291 struct acm_ru *rcv = urb->context; 291 struct acm_ru *rcv = urb->context;
292 struct acm *acm = rcv->instance; 292 struct acm *acm = rcv->instance;
293 int status = urb->status; 293 int status = urb->status;
294 dbg("Entering acm_read_bulk with status %d\n", urb->status); 294 dbg("Entering acm_read_bulk with status %d", urb->status);
295 295
296 if (!ACM_READY(acm)) 296 if (!ACM_READY(acm))
297 return; 297 return;
298 298
299 if (status) 299 if (status)
300 dev_dbg(&acm->data->dev, "bulk rx status %d\n", status); 300 dev_dbg(&acm->data->dev, "bulk rx status %d", status);
301 301
302 buf = rcv->buffer; 302 buf = rcv->buffer;
303 buf->size = urb->actual_length; 303 buf->size = urb->actual_length;
@@ -343,7 +343,7 @@ next_buffer:
343 list_del(&buf->list); 343 list_del(&buf->list);
344 spin_unlock(&acm->read_lock); 344 spin_unlock(&acm->read_lock);
345 345
346 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d\n", buf, buf->size); 346 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size);
347 347
348 tty_buffer_request_room(tty, buf->size); 348 tty_buffer_request_room(tty, buf->size);
349 if (!acm->throttle) 349 if (!acm->throttle)
@@ -394,7 +394,7 @@ urbs:
394 rcv->urb->transfer_dma = buf->dma; 394 rcv->urb->transfer_dma = buf->dma;
395 rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 395 rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
396 396
397 dbg("acm_rx_tasklet: sending urb 0x%p, rcv 0x%p, buf 0x%p\n", rcv->urb, rcv, buf); 397 dbg("acm_rx_tasklet: sending urb 0x%p, rcv 0x%p, buf 0x%p", rcv->urb, rcv, buf);
398 398
399 /* This shouldn't kill the driver as unsuccessful URBs are returned to the 399 /* This shouldn't kill the driver as unsuccessful URBs are returned to the
400 free-urbs-pool and resubmited ASAP */ 400 free-urbs-pool and resubmited ASAP */
@@ -413,7 +413,7 @@ static void acm_write_bulk(struct urb *urb, struct pt_regs *regs)
413{ 413{
414 struct acm *acm = (struct acm *)urb->context; 414 struct acm *acm = (struct acm *)urb->context;
415 415
416 dbg("Entering acm_write_bulk with status %d\n", urb->status); 416 dbg("Entering acm_write_bulk with status %d", urb->status);
417 417
418 acm_write_done(acm); 418 acm_write_done(acm);
419 acm_write_start(acm); 419 acm_write_start(acm);
@@ -424,7 +424,7 @@ static void acm_write_bulk(struct urb *urb, struct pt_regs *regs)
424static void acm_softint(void *private) 424static void acm_softint(void *private)
425{ 425{
426 struct acm *acm = private; 426 struct acm *acm = private;
427 dbg("Entering acm_softint.\n"); 427 dbg("Entering acm_softint.");
428 428
429 if (!ACM_READY(acm)) 429 if (!ACM_READY(acm))
430 return; 430 return;
@@ -440,7 +440,7 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
440 struct acm *acm; 440 struct acm *acm;
441 int rv = -EINVAL; 441 int rv = -EINVAL;
442 int i; 442 int i;
443 dbg("Entering acm_tty_open.\n"); 443 dbg("Entering acm_tty_open.");
444 444
445 mutex_lock(&open_mutex); 445 mutex_lock(&open_mutex);
446 446
@@ -541,7 +541,7 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c
541 int wbn; 541 int wbn;
542 struct acm_wb *wb; 542 struct acm_wb *wb;
543 543
544 dbg("Entering acm_tty_write to write %d bytes,\n", count); 544 dbg("Entering acm_tty_write to write %d bytes,", count);
545 545
546 if (!ACM_READY(acm)) 546 if (!ACM_READY(acm))
547 return -EINVAL; 547 return -EINVAL;
@@ -793,7 +793,7 @@ static int acm_probe (struct usb_interface *intf,
793 793
794 if (!buflen) { 794 if (!buflen) {
795 if (intf->cur_altsetting->endpoint->extralen && intf->cur_altsetting->endpoint->extra) { 795 if (intf->cur_altsetting->endpoint->extralen && intf->cur_altsetting->endpoint->extra) {
796 dev_dbg(&intf->dev,"Seeking extra descriptors on endpoint\n"); 796 dev_dbg(&intf->dev,"Seeking extra descriptors on endpoint");
797 buflen = intf->cur_altsetting->endpoint->extralen; 797 buflen = intf->cur_altsetting->endpoint->extralen;
798 buffer = intf->cur_altsetting->endpoint->extra; 798 buffer = intf->cur_altsetting->endpoint->extra;
799 } else { 799 } else {
@@ -842,24 +842,24 @@ next_desc:
842 842
843 if (!union_header) { 843 if (!union_header) {
844 if (call_interface_num > 0) { 844 if (call_interface_num > 0) {
845 dev_dbg(&intf->dev,"No union descriptor, using call management descriptor\n"); 845 dev_dbg(&intf->dev,"No union descriptor, using call management descriptor");
846 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); 846 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num));
847 control_interface = intf; 847 control_interface = intf;
848 } else { 848 } else {
849 dev_dbg(&intf->dev,"No union descriptor, giving up\n"); 849 dev_dbg(&intf->dev,"No union descriptor, giving up");
850 return -ENODEV; 850 return -ENODEV;
851 } 851 }
852 } else { 852 } else {
853 control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); 853 control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0);
854 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); 854 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0));
855 if (!control_interface || !data_interface) { 855 if (!control_interface || !data_interface) {
856 dev_dbg(&intf->dev,"no interfaces\n"); 856 dev_dbg(&intf->dev,"no interfaces");
857 return -ENODEV; 857 return -ENODEV;
858 } 858 }
859 } 859 }
860 860
861 if (data_interface_num != call_interface_num) 861 if (data_interface_num != call_interface_num)
862 dev_dbg(&intf->dev,"Seperate call control interface. That is not fully supported.\n"); 862 dev_dbg(&intf->dev,"Seperate call control interface. That is not fully supported.");
863 863
864skip_normal_probe: 864skip_normal_probe:
865 865
@@ -867,7 +867,7 @@ skip_normal_probe:
867 if (data_interface->cur_altsetting->desc.bInterfaceClass != CDC_DATA_INTERFACE_TYPE) { 867 if (data_interface->cur_altsetting->desc.bInterfaceClass != CDC_DATA_INTERFACE_TYPE) {
868 if (control_interface->cur_altsetting->desc.bInterfaceClass == CDC_DATA_INTERFACE_TYPE) { 868 if (control_interface->cur_altsetting->desc.bInterfaceClass == CDC_DATA_INTERFACE_TYPE) {
869 struct usb_interface *t; 869 struct usb_interface *t;
870 dev_dbg(&intf->dev,"Your device has switched interfaces.\n"); 870 dev_dbg(&intf->dev,"Your device has switched interfaces.");
871 871
872 t = control_interface; 872 t = control_interface;
873 control_interface = data_interface; 873 control_interface = data_interface;
@@ -878,7 +878,7 @@ skip_normal_probe:
878 } 878 }
879 879
880 if (usb_interface_claimed(data_interface)) { /* valid in this context */ 880 if (usb_interface_claimed(data_interface)) { /* valid in this context */
881 dev_dbg(&intf->dev,"The data interface isn't available\n"); 881 dev_dbg(&intf->dev,"The data interface isn't available");
882 return -EBUSY; 882 return -EBUSY;
883 } 883 }
884 884
@@ -895,7 +895,7 @@ skip_normal_probe:
895 if ((epread->bEndpointAddress & USB_DIR_IN) != USB_DIR_IN) { 895 if ((epread->bEndpointAddress & USB_DIR_IN) != USB_DIR_IN) {
896 /* descriptors are swapped */ 896 /* descriptors are swapped */
897 struct usb_endpoint_descriptor *t; 897 struct usb_endpoint_descriptor *t;
898 dev_dbg(&intf->dev,"The data interface has switched endpoints\n"); 898 dev_dbg(&intf->dev,"The data interface has switched endpoints");
899 899
900 t = epread; 900 t = epread;
901 epread = epwrite; 901 epread = epwrite;
@@ -910,7 +910,7 @@ skip_normal_probe:
910 } 910 }
911 911
912 if (!(acm = kzalloc(sizeof(struct acm), GFP_KERNEL))) { 912 if (!(acm = kzalloc(sizeof(struct acm), GFP_KERNEL))) {
913 dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); 913 dev_dbg(&intf->dev, "out of memory (acm kzalloc)");
914 goto alloc_fail; 914 goto alloc_fail;
915 } 915 }
916 916
@@ -936,26 +936,26 @@ skip_normal_probe:
936 936
937 buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); 937 buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
938 if (!buf) { 938 if (!buf) {
939 dev_dbg(&intf->dev, "out of memory (ctrl buffer alloc)\n"); 939 dev_dbg(&intf->dev, "out of memory (ctrl buffer alloc)");
940 goto alloc_fail2; 940 goto alloc_fail2;
941 } 941 }
942 acm->ctrl_buffer = buf; 942 acm->ctrl_buffer = buf;
943 943
944 if (acm_write_buffers_alloc(acm) < 0) { 944 if (acm_write_buffers_alloc(acm) < 0) {
945 dev_dbg(&intf->dev, "out of memory (write buffer alloc)\n"); 945 dev_dbg(&intf->dev, "out of memory (write buffer alloc)");
946 goto alloc_fail4; 946 goto alloc_fail4;
947 } 947 }
948 948
949 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); 949 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);
950 if (!acm->ctrlurb) { 950 if (!acm->ctrlurb) {
951 dev_dbg(&intf->dev, "out of memory (ctrlurb kmalloc)\n"); 951 dev_dbg(&intf->dev, "out of memory (ctrlurb kmalloc)");
952 goto alloc_fail5; 952 goto alloc_fail5;
953 } 953 }
954 for (i = 0; i < num_rx_buf; i++) { 954 for (i = 0; i < num_rx_buf; i++) {
955 struct acm_ru *rcv = &(acm->ru[i]); 955 struct acm_ru *rcv = &(acm->ru[i]);
956 956
957 if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) { 957 if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) {
958 dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)\n"); 958 dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)");
959 goto alloc_fail7; 959 goto alloc_fail7;
960 } 960 }
961 961
@@ -966,13 +966,13 @@ skip_normal_probe:
966 struct acm_rb *buf = &(acm->rb[i]); 966 struct acm_rb *buf = &(acm->rb[i]);
967 967
968 if (!(buf->base = usb_buffer_alloc(acm->dev, readsize, GFP_KERNEL, &buf->dma))) { 968 if (!(buf->base = usb_buffer_alloc(acm->dev, readsize, GFP_KERNEL, &buf->dma))) {
969 dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)\n"); 969 dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)");
970 goto alloc_fail7; 970 goto alloc_fail7;
971 } 971 }
972 } 972 }
973 acm->writeurb = usb_alloc_urb(0, GFP_KERNEL); 973 acm->writeurb = usb_alloc_urb(0, GFP_KERNEL);
974 if (!acm->writeurb) { 974 if (!acm->writeurb) {
975 dev_dbg(&intf->dev, "out of memory (writeurb kmalloc)\n"); 975 dev_dbg(&intf->dev, "out of memory (writeurb kmalloc)");
976 goto alloc_fail7; 976 goto alloc_fail7;
977 } 977 }
978 978
@@ -1086,6 +1086,9 @@ static struct usb_device_id acm_ids[] = {
1086 { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */ 1086 { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */
1087 .driver_info = SINGLE_RX_URB, /* firmware bug */ 1087 .driver_info = SINGLE_RX_URB, /* firmware bug */
1088 }, 1088 },
1089 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
1090 .driver_info = SINGLE_RX_URB, /* firmware bug */
1091 },
1089 /* control interfaces with various AT-command sets */ 1092 /* control interfaces with various AT-command sets */
1090 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1093 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1091 USB_CDC_ACM_PROTO_AT_V25TER) }, 1094 USB_CDC_ACM_PROTO_AT_V25TER) },
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index a08787e253aa..6e3b5358a760 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -31,9 +31,6 @@ config USB_DEVICEFS
31 For the format of the various /proc/bus/usb/ files, please read 31 For the format of the various /proc/bus/usb/ files, please read
32 <file:Documentation/usb/proc_usb_info.txt>. 32 <file:Documentation/usb/proc_usb_info.txt>.
33 33
34 Please note that this code is completely unrelated to devfs, the
35 "/dev file system support".
36
37 Most users want to say Y here. 34 Most users want to say Y here.
38 35
39config USB_BANDWIDTH 36config USB_BANDWIDTH
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index f7bdd94b3aa8..218621b9958e 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -517,19 +517,19 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, unsig
517 517
518static struct usb_device *usbdev_lookup_minor(int minor) 518static struct usb_device *usbdev_lookup_minor(int minor)
519{ 519{
520 struct device *device; 520 struct class_device *class_dev;
521 struct usb_device *udev = NULL; 521 struct usb_device *dev = NULL;
522 522
523 down(&usb_device_class->sem); 523 down(&usb_device_class->sem);
524 list_for_each_entry(device, &usb_device_class->devices, node) { 524 list_for_each_entry(class_dev, &usb_device_class->children, node) {
525 if (device->devt == MKDEV(USB_DEVICE_MAJOR, minor)) { 525 if (class_dev->devt == MKDEV(USB_DEVICE_MAJOR, minor)) {
526 udev = device->platform_data; 526 dev = class_dev->class_data;
527 break; 527 break;
528 } 528 }
529 } 529 }
530 up(&usb_device_class->sem); 530 up(&usb_device_class->sem);
531 531
532 return udev; 532 return dev;
533}; 533};
534 534
535/* 535/*
@@ -1580,16 +1580,16 @@ static void usbdev_add(struct usb_device *dev)
1580{ 1580{
1581 int minor = ((dev->bus->busnum-1) * 128) + (dev->devnum-1); 1581 int minor = ((dev->bus->busnum-1) * 128) + (dev->devnum-1);
1582 1582
1583 dev->usbfs_dev = device_create(usb_device_class, &dev->dev, 1583 dev->class_dev = class_device_create(usb_device_class, NULL,
1584 MKDEV(USB_DEVICE_MAJOR, minor), 1584 MKDEV(USB_DEVICE_MAJOR, minor), &dev->dev,
1585 "usbdev%d.%d", dev->bus->busnum, dev->devnum); 1585 "usbdev%d.%d", dev->bus->busnum, dev->devnum);
1586 1586
1587 dev->usbfs_dev->platform_data = dev; 1587 dev->class_dev->class_data = dev;
1588} 1588}
1589 1589
1590static void usbdev_remove(struct usb_device *dev) 1590static void usbdev_remove(struct usb_device *dev)
1591{ 1591{
1592 device_unregister(dev->usbfs_dev); 1592 class_device_unregister(dev->class_dev);
1593} 1593}
1594 1594
1595static int usbdev_notify(struct notifier_block *self, unsigned long action, 1595static int usbdev_notify(struct notifier_block *self, unsigned long action,
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index abee0f5b6a66..8de4f8c99d61 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -194,13 +194,14 @@ int usb_register_dev(struct usb_interface *intf,
194 ++temp; 194 ++temp;
195 else 195 else
196 temp = name; 196 temp = name;
197 intf->usb_dev = device_create(usb_class->class, &intf->dev, 197 intf->class_dev = class_device_create(usb_class->class, NULL,
198 MKDEV(USB_MAJOR, minor), "%s", temp); 198 MKDEV(USB_MAJOR, minor),
199 if (IS_ERR(intf->usb_dev)) { 199 &intf->dev, "%s", temp);
200 if (IS_ERR(intf->class_dev)) {
200 spin_lock (&minor_lock); 201 spin_lock (&minor_lock);
201 usb_minors[intf->minor] = NULL; 202 usb_minors[intf->minor] = NULL;
202 spin_unlock (&minor_lock); 203 spin_unlock (&minor_lock);
203 retval = PTR_ERR(intf->usb_dev); 204 retval = PTR_ERR(intf->class_dev);
204 } 205 }
205exit: 206exit:
206 return retval; 207 return retval;
@@ -241,8 +242,8 @@ void usb_deregister_dev(struct usb_interface *intf,
241 spin_unlock (&minor_lock); 242 spin_unlock (&minor_lock);
242 243
243 snprintf(name, BUS_ID_SIZE, class_driver->name, intf->minor - minor_base); 244 snprintf(name, BUS_ID_SIZE, class_driver->name, intf->minor - minor_base);
244 device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor)); 245 class_device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor));
245 intf->usb_dev = NULL; 246 intf->class_dev = NULL;
246 intf->minor = -1; 247 intf->minor = -1;
247 destroy_usb_class(); 248 destroy_usb_class();
248} 249}
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 875596e98e42..26c8cb5f3e67 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1790,7 +1790,10 @@ static int finish_device_resume(struct usb_device *udev)
1790 * and device drivers will know about any resume quirks. 1790 * and device drivers will know about any resume quirks.
1791 */ 1791 */
1792 status = usb_get_status(udev, USB_RECIP_DEVICE, 0, &devstatus); 1792 status = usb_get_status(udev, USB_RECIP_DEVICE, 0, &devstatus);
1793 if (status < 2) 1793 if (status >= 0)
1794 status = (status == 2 ? 0 : -ENODEV);
1795
1796 if (status)
1794 dev_dbg(&udev->dev, 1797 dev_dbg(&udev->dev,
1795 "gone after usb resume? status %d\n", 1798 "gone after usb resume? status %d\n",
1796 status); 1799 status);
@@ -1879,7 +1882,12 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev)
1879 dev_dbg(hub->intfdev, 1882 dev_dbg(hub->intfdev,
1880 "port %d status %04x.%04x after resume, %d\n", 1883 "port %d status %04x.%04x after resume, %d\n",
1881 port1, portchange, devstatus, status); 1884 port1, portchange, devstatus, status);
1885 if (status >= 0)
1886 status = -ENODEV;
1882 } else { 1887 } else {
1888 if (portchange & USB_PORT_STAT_C_SUSPEND)
1889 clear_port_feature(hub->hdev, port1,
1890 USB_PORT_FEAT_C_SUSPEND);
1883 /* TRSMRCY = 10 msec */ 1891 /* TRSMRCY = 10 msec */
1884 msleep(10); 1892 msleep(10);
1885 if (udev) 1893 if (udev)
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index e47e3a8ed6e4..3182c2224ba2 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -200,7 +200,7 @@ static void update_sb(struct super_block *sb)
200 if (!root) 200 if (!root)
201 return; 201 return;
202 202
203 mutex_lock(&root->d_inode->i_mutex); 203 mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_PARENT);
204 204
205 list_for_each_entry(bus, &root->d_subdirs, d_u.d_child) { 205 list_for_each_entry(bus, &root->d_subdirs, d_u.d_child) {
206 if (bus->d_inode) { 206 if (bus->d_inode) {
@@ -527,7 +527,7 @@ static void fs_remove_file (struct dentry *dentry)
527 if (!parent || !parent->d_inode) 527 if (!parent || !parent->d_inode)
528 return; 528 return;
529 529
530 mutex_lock(&parent->d_inode->i_mutex); 530 mutex_lock_nested(&parent->d_inode->i_mutex, I_MUTEX_PARENT);
531 if (usbfs_positive(dentry)) { 531 if (usbfs_positive(dentry)) {
532 if (dentry->d_inode) { 532 if (dentry->d_inode) {
533 if (S_ISDIR(dentry->d_inode->i_mode)) 533 if (S_ISDIR(dentry->d_inode->i_mode))
@@ -695,7 +695,7 @@ static void usbfs_remove_device(struct usb_device *dev)
695 wake_up_all(&ds->wait); 695 wake_up_all(&ds->wait);
696 list_del_init(&ds->list); 696 list_del_init(&ds->list);
697 if (ds->discsignr) { 697 if (ds->discsignr) {
698 sinfo.si_signo = SIGPIPE; 698 sinfo.si_signo = ds->discsignr;
699 sinfo.si_errno = EPIPE; 699 sinfo.si_errno = EPIPE;
700 sinfo.si_code = SI_ASYNCIO; 700 sinfo.si_code = SI_ASYNCIO;
701 sinfo.si_addr = ds->disccontext; 701 sinfo.si_addr = ds->disccontext;
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 363b2ad74ae6..1a32d96774b4 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -207,7 +207,7 @@ config USB_AT91
207 207
208config USB_GADGET_DUMMY_HCD 208config USB_GADGET_DUMMY_HCD
209 boolean "Dummy HCD (DEVELOPMENT)" 209 boolean "Dummy HCD (DEVELOPMENT)"
210 depends on USB && EXPERIMENTAL 210 depends on (USB=y || (USB=m && USB_GADGET=m)) && EXPERIMENTAL
211 select USB_GADGET_DUALSPEED 211 select USB_GADGET_DUALSPEED
212 help 212 help
213 This host controller driver emulates USB, looping all data transfer 213 This host controller driver emulates USB, looping all data transfer
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 1c459ff037ce..cfebca05ead5 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -57,19 +57,23 @@
57 57
58/* 58/*
59 * This controller is simple and PIO-only. It's used in many AT91-series 59 * This controller is simple and PIO-only. It's used in many AT91-series
60 * ARMv4T controllers, including the at91rm9200 (arm920T, with MMU), 60 * full speed USB controllers, including the at91rm9200 (arm920T, with MMU),
61 * at91sam9261 (arm926ejs, with MMU), and several no-mmu versions. 61 * at91sam926x (arm926ejs, with MMU), and several no-mmu versions.
62 * 62 *
63 * This driver expects the board has been wired with two GPIOs suppporting 63 * This driver expects the board has been wired with two GPIOs suppporting
64 * a VBUS sensing IRQ, and a D+ pullup. (They may be omitted, but the 64 * a VBUS sensing IRQ, and a D+ pullup. (They may be omitted, but the
65 * testing hasn't covered such cases.) The pullup is most important; it 65 * testing hasn't covered such cases.)
66 *
67 * The pullup is most important (so it's integrated on sam926x parts). It
66 * provides software control over whether the host enumerates the device. 68 * provides software control over whether the host enumerates the device.
69 *
67 * The VBUS sensing helps during enumeration, and allows both USB clocks 70 * The VBUS sensing helps during enumeration, and allows both USB clocks
68 * (and the transceiver) to stay gated off until they're necessary, saving 71 * (and the transceiver) to stay gated off until they're necessary, saving
69 * power. During USB suspend, the 48 MHz clock is gated off. 72 * power. During USB suspend, the 48 MHz clock is gated off in hardware;
73 * it may also be gated off by software during some Linux sleep states.
70 */ 74 */
71 75
72#define DRIVER_VERSION "8 March 2005" 76#define DRIVER_VERSION "3 May 2006"
73 77
74static const char driver_name [] = "at91_udc"; 78static const char driver_name [] = "at91_udc";
75static const char ep0name[] = "ep0"; 79static const char ep0name[] = "ep0";
@@ -316,9 +320,15 @@ static void done(struct at91_ep *ep, struct at91_request *req, int status)
316 * 320 *
317 * There are also state bits like FORCESTALL, EPEDS, DIR, and EPTYPE 321 * There are also state bits like FORCESTALL, EPEDS, DIR, and EPTYPE
318 * that shouldn't normally be changed. 322 * that shouldn't normally be changed.
323 *
324 * NOTE at91sam9260 docs mention synch between UDPCK and MCK clock domains,
325 * implying a need to wait for one write to complete (test relevant bits)
326 * before starting the next write. This shouldn't be an issue given how
327 * infrequently we write, except maybe for write-then-read idioms.
319 */ 328 */
320#define SET_FX (AT91_UDP_TXPKTRDY) 329#define SET_FX (AT91_UDP_TXPKTRDY)
321#define CLR_FX (RX_DATA_READY | AT91_UDP_RXSETUP | AT91_UDP_STALLSENT | AT91_UDP_TXCOMP) 330#define CLR_FX (RX_DATA_READY | AT91_UDP_RXSETUP \
331 | AT91_UDP_STALLSENT | AT91_UDP_TXCOMP)
322 332
323/* pull OUT packet data from the endpoint's fifo */ 333/* pull OUT packet data from the endpoint's fifo */
324static int read_fifo (struct at91_ep *ep, struct at91_request *req) 334static int read_fifo (struct at91_ep *ep, struct at91_request *req)
@@ -472,7 +482,8 @@ static void nuke(struct at91_ep *ep, int status)
472 482
473/*-------------------------------------------------------------------------*/ 483/*-------------------------------------------------------------------------*/
474 484
475static int at91_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) 485static int at91_ep_enable(struct usb_ep *_ep,
486 const struct usb_endpoint_descriptor *desc)
476{ 487{
477 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); 488 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep);
478 struct at91_udc *dev = ep->udc; 489 struct at91_udc *dev = ep->udc;
@@ -582,11 +593,12 @@ static int at91_ep_disable (struct usb_ep * _ep)
582 * interesting for request or buffer allocation. 593 * interesting for request or buffer allocation.
583 */ 594 */
584 595
585static struct usb_request *at91_ep_alloc_request (struct usb_ep *_ep, unsigned int gfp_flags) 596static struct usb_request *
597at91_ep_alloc_request(struct usb_ep *_ep, unsigned int gfp_flags)
586{ 598{
587 struct at91_request *req; 599 struct at91_request *req;
588 600
589 req = kcalloc(1, sizeof (struct at91_request), SLAB_KERNEL); 601 req = kcalloc(1, sizeof (struct at91_request), gfp_flags);
590 if (!req) 602 if (!req)
591 return NULL; 603 return NULL;
592 604
@@ -862,6 +874,7 @@ static void stop_activity(struct at91_udc *udc)
862 if (udc->gadget.speed == USB_SPEED_UNKNOWN) 874 if (udc->gadget.speed == USB_SPEED_UNKNOWN)
863 driver = NULL; 875 driver = NULL;
864 udc->gadget.speed = USB_SPEED_UNKNOWN; 876 udc->gadget.speed = USB_SPEED_UNKNOWN;
877 udc->suspended = 0;
865 878
866 for (i = 0; i < NUM_ENDPOINTS; i++) { 879 for (i = 0; i < NUM_ENDPOINTS; i++) {
867 struct at91_ep *ep = &udc->ep[i]; 880 struct at91_ep *ep = &udc->ep[i];
@@ -889,8 +902,8 @@ static void clk_off(struct at91_udc *udc)
889 return; 902 return;
890 udc->clocked = 0; 903 udc->clocked = 0;
891 udc->gadget.speed = USB_SPEED_UNKNOWN; 904 udc->gadget.speed = USB_SPEED_UNKNOWN;
892 clk_disable(udc->iclk);
893 clk_disable(udc->fclk); 905 clk_disable(udc->fclk);
906 clk_disable(udc->iclk);
894} 907}
895 908
896/* 909/*
@@ -911,9 +924,6 @@ static void pullup(struct at91_udc *udc, int is_on)
911 at91_udp_write(AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); 924 at91_udp_write(AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
912 at91_set_gpio_value(udc->board.pullup_pin, 0); 925 at91_set_gpio_value(udc->board.pullup_pin, 0);
913 clk_off(udc); 926 clk_off(udc);
914
915 // REVISIT: with transceiver disabled, will D- float
916 // so that a host would falsely detect a device?
917 } 927 }
918} 928}
919 929
@@ -1290,7 +1300,8 @@ static void handle_ep0(struct at91_udc *udc)
1290 if (udc->wait_for_addr_ack) { 1300 if (udc->wait_for_addr_ack) {
1291 u32 tmp; 1301 u32 tmp;
1292 1302
1293 at91_udp_write(AT91_UDP_FADDR, AT91_UDP_FEN | udc->addr); 1303 at91_udp_write(AT91_UDP_FADDR,
1304 AT91_UDP_FEN | udc->addr);
1294 tmp = at91_udp_read(AT91_UDP_GLB_STAT); 1305 tmp = at91_udp_read(AT91_UDP_GLB_STAT);
1295 tmp &= ~AT91_UDP_FADDEN; 1306 tmp &= ~AT91_UDP_FADDEN;
1296 if (udc->addr) 1307 if (udc->addr)
@@ -1361,9 +1372,10 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc, struct pt_regs *r)
1361 u32 rescans = 5; 1372 u32 rescans = 5;
1362 1373
1363 while (rescans--) { 1374 while (rescans--) {
1364 u32 status = at91_udp_read(AT91_UDP_ISR); 1375 u32 status;
1365 1376
1366 status &= at91_udp_read(AT91_UDP_IMR); 1377 status = at91_udp_read(AT91_UDP_ISR)
1378 & at91_udp_read(AT91_UDP_IMR);
1367 if (!status) 1379 if (!status)
1368 break; 1380 break;
1369 1381
@@ -1379,18 +1391,17 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc, struct pt_regs *r)
1379 stop_activity(udc); 1391 stop_activity(udc);
1380 1392
1381 /* enable ep0 */ 1393 /* enable ep0 */
1382 at91_udp_write(AT91_UDP_CSR(0), AT91_UDP_EPEDS | AT91_UDP_EPTYPE_CTRL); 1394 at91_udp_write(AT91_UDP_CSR(0),
1395 AT91_UDP_EPEDS | AT91_UDP_EPTYPE_CTRL);
1383 udc->gadget.speed = USB_SPEED_FULL; 1396 udc->gadget.speed = USB_SPEED_FULL;
1384 udc->suspended = 0; 1397 udc->suspended = 0;
1385 at91_udp_write(AT91_UDP_IER, AT91_UDP_EP(0)); 1398 at91_udp_write(AT91_UDP_IER, AT91_UDP_EP(0));
1386 1399
1387 /* 1400 /*
1388 * NOTE: this driver keeps clocks off unless the 1401 * NOTE: this driver keeps clocks off unless the
1389 * USB host is present. That saves power, and also 1402 * USB host is present. That saves power, but for
1390 * eliminates IRQs (reset, resume, suspend) that can 1403 * boards that don't support VBUS detection, both
1391 * otherwise flood from the controller. If your 1404 * clocks need to be active most of the time.
1392 * board doesn't support VBUS detection, suspend and
1393 * resume irq logic may need more attention...
1394 */ 1405 */
1395 1406
1396 /* host initiated suspend (3+ms bus idle) */ 1407 /* host initiated suspend (3+ms bus idle) */
@@ -1452,13 +1463,19 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc, struct pt_regs *r)
1452 1463
1453/*-------------------------------------------------------------------------*/ 1464/*-------------------------------------------------------------------------*/
1454 1465
1466static void nop_release(struct device *dev)
1467{
1468 /* nothing to free */
1469}
1470
1455static struct at91_udc controller = { 1471static struct at91_udc controller = {
1456 .gadget = { 1472 .gadget = {
1457 .ops = &at91_udc_ops, 1473 .ops = &at91_udc_ops,
1458 .ep0 = &controller.ep[0].ep, 1474 .ep0 = &controller.ep[0].ep,
1459 .name = driver_name, 1475 .name = driver_name,
1460 .dev = { 1476 .dev = {
1461 .bus_id = "gadget" 1477 .bus_id = "gadget",
1478 .release = nop_release,
1462 } 1479 }
1463 }, 1480 },
1464 .ep[0] = { 1481 .ep[0] = {
@@ -1468,7 +1485,8 @@ static struct at91_udc controller = {
1468 }, 1485 },
1469 .udc = &controller, 1486 .udc = &controller,
1470 .maxpacket = 8, 1487 .maxpacket = 8,
1471 .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(0)), 1488 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1489 + AT91_UDP_CSR(0)),
1472 .int_mask = 1 << 0, 1490 .int_mask = 1 << 0,
1473 }, 1491 },
1474 .ep[1] = { 1492 .ep[1] = {
@@ -1479,7 +1497,8 @@ static struct at91_udc controller = {
1479 .udc = &controller, 1497 .udc = &controller,
1480 .is_pingpong = 1, 1498 .is_pingpong = 1,
1481 .maxpacket = 64, 1499 .maxpacket = 64,
1482 .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(1)), 1500 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1501 + AT91_UDP_CSR(1)),
1483 .int_mask = 1 << 1, 1502 .int_mask = 1 << 1,
1484 }, 1503 },
1485 .ep[2] = { 1504 .ep[2] = {
@@ -1490,7 +1509,8 @@ static struct at91_udc controller = {
1490 .udc = &controller, 1509 .udc = &controller,
1491 .is_pingpong = 1, 1510 .is_pingpong = 1,
1492 .maxpacket = 64, 1511 .maxpacket = 64,
1493 .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(2)), 1512 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1513 + AT91_UDP_CSR(2)),
1494 .int_mask = 1 << 2, 1514 .int_mask = 1 << 2,
1495 }, 1515 },
1496 .ep[3] = { 1516 .ep[3] = {
@@ -1501,7 +1521,8 @@ static struct at91_udc controller = {
1501 }, 1521 },
1502 .udc = &controller, 1522 .udc = &controller,
1503 .maxpacket = 8, 1523 .maxpacket = 8,
1504 .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(3)), 1524 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1525 + AT91_UDP_CSR(3)),
1505 .int_mask = 1 << 3, 1526 .int_mask = 1 << 3,
1506 }, 1527 },
1507 .ep[4] = { 1528 .ep[4] = {
@@ -1512,7 +1533,8 @@ static struct at91_udc controller = {
1512 .udc = &controller, 1533 .udc = &controller,
1513 .is_pingpong = 1, 1534 .is_pingpong = 1,
1514 .maxpacket = 256, 1535 .maxpacket = 256,
1515 .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(4)), 1536 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1537 + AT91_UDP_CSR(4)),
1516 .int_mask = 1 << 4, 1538 .int_mask = 1 << 4,
1517 }, 1539 },
1518 .ep[5] = { 1540 .ep[5] = {
@@ -1523,10 +1545,11 @@ static struct at91_udc controller = {
1523 .udc = &controller, 1545 .udc = &controller,
1524 .is_pingpong = 1, 1546 .is_pingpong = 1,
1525 .maxpacket = 256, 1547 .maxpacket = 256,
1526 .creg = (void __iomem *)(AT91_VA_BASE_UDP + AT91_UDP_CSR(5)), 1548 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1549 + AT91_UDP_CSR(5)),
1527 .int_mask = 1 << 5, 1550 .int_mask = 1 << 5,
1528 }, 1551 },
1529 /* ep6 and ep7 are also reserved */ 1552 /* ep6 and ep7 are also reserved (custom silicon might use them) */
1530}; 1553};
1531 1554
1532static irqreturn_t at91_vbus_irq(int irq, void *_udc, struct pt_regs *r) 1555static irqreturn_t at91_vbus_irq(int irq, void *_udc, struct pt_regs *r)
@@ -1593,6 +1616,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
1593 1616
1594 local_irq_disable(); 1617 local_irq_disable();
1595 udc->enabled = 0; 1618 udc->enabled = 0;
1619 at91_udp_write(AT91_UDP_IDR, ~0);
1596 pullup(udc, 0); 1620 pullup(udc, 0);
1597 local_irq_enable(); 1621 local_irq_enable();
1598 1622
@@ -1624,6 +1648,16 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1624 return -ENODEV; 1648 return -ENODEV;
1625 } 1649 }
1626 1650
1651 if (pdev->num_resources != 2) {
1652 DBG("invalid num_resources");
1653 return -ENODEV;
1654 }
1655 if ((pdev->resource[0].flags != IORESOURCE_MEM)
1656 || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
1657 DBG("invalid resource type");
1658 return -ENODEV;
1659 }
1660
1627 if (!request_mem_region(AT91_BASE_UDP, SZ_16K, driver_name)) { 1661 if (!request_mem_region(AT91_BASE_UDP, SZ_16K, driver_name)) {
1628 DBG("someone's using UDC memory\n"); 1662 DBG("someone's using UDC memory\n");
1629 return -EBUSY; 1663 return -EBUSY;
@@ -1649,19 +1683,26 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1649 if (retval < 0) 1683 if (retval < 0)
1650 goto fail0; 1684 goto fail0;
1651 1685
1652 /* disable everything until there's a gadget driver and vbus */ 1686 /* don't do anything until we have both gadget driver and VBUS */
1653 pullup(udc, 0); 1687 clk_enable(udc->iclk);
1688 at91_udp_write(AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
1689 at91_udp_write(AT91_UDP_IDR, 0xffffffff);
1690 clk_disable(udc->iclk);
1654 1691
1655 /* request UDC and maybe VBUS irqs */ 1692 /* request UDC and maybe VBUS irqs */
1656 if (request_irq(AT91_ID_UDP, at91_udc_irq, IRQF_DISABLED, driver_name, udc)) { 1693 udc->udp_irq = platform_get_irq(pdev, 0);
1657 DBG("request irq %d failed\n", AT91_ID_UDP); 1694 if (request_irq(udc->udp_irq, at91_udc_irq,
1695 IRQF_DISABLED, driver_name, udc)) {
1696 DBG("request irq %d failed\n", udc->udp_irq);
1658 retval = -EBUSY; 1697 retval = -EBUSY;
1659 goto fail1; 1698 goto fail1;
1660 } 1699 }
1661 if (udc->board.vbus_pin > 0) { 1700 if (udc->board.vbus_pin > 0) {
1662 if (request_irq(udc->board.vbus_pin, at91_vbus_irq, IRQF_DISABLED, driver_name, udc)) { 1701 if (request_irq(udc->board.vbus_pin, at91_vbus_irq,
1663 DBG("request vbus irq %d failed\n", udc->board.vbus_pin); 1702 IRQF_DISABLED, driver_name, udc)) {
1664 free_irq(AT91_ID_UDP, udc); 1703 DBG("request vbus irq %d failed\n",
1704 udc->board.vbus_pin);
1705 free_irq(udc->udp_irq, udc);
1665 retval = -EBUSY; 1706 retval = -EBUSY;
1666 goto fail1; 1707 goto fail1;
1667 } 1708 }
@@ -1670,6 +1711,7 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1670 udc->vbus = 1; 1711 udc->vbus = 1;
1671 } 1712 }
1672 dev_set_drvdata(dev, udc); 1713 dev_set_drvdata(dev, udc);
1714 device_init_wakeup(dev, 1);
1673 create_debug_file(udc); 1715 create_debug_file(udc);
1674 1716
1675 INFO("%s version %s\n", driver_name, DRIVER_VERSION); 1717 INFO("%s version %s\n", driver_name, DRIVER_VERSION);
@@ -1678,14 +1720,14 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1678fail1: 1720fail1:
1679 device_unregister(&udc->gadget.dev); 1721 device_unregister(&udc->gadget.dev);
1680fail0: 1722fail0:
1681 release_mem_region(AT91_VA_BASE_UDP, SZ_16K); 1723 release_mem_region(AT91_BASE_UDP, SZ_16K);
1682 DBG("%s probe failed, %d\n", driver_name, retval); 1724 DBG("%s probe failed, %d\n", driver_name, retval);
1683 return retval; 1725 return retval;
1684} 1726}
1685 1727
1686static int __devexit at91udc_remove(struct platform_device *dev) 1728static int __devexit at91udc_remove(struct platform_device *pdev)
1687{ 1729{
1688 struct at91_udc *udc = platform_get_drvdata(dev); 1730 struct at91_udc *udc = platform_get_drvdata(pdev);
1689 1731
1690 DBG("remove\n"); 1732 DBG("remove\n");
1691 1733
@@ -1694,10 +1736,11 @@ static int __devexit at91udc_remove(struct platform_device *dev)
1694 if (udc->driver != 0) 1736 if (udc->driver != 0)
1695 usb_gadget_unregister_driver(udc->driver); 1737 usb_gadget_unregister_driver(udc->driver);
1696 1738
1739 device_init_wakeup(&pdev->dev, 0);
1697 remove_debug_file(udc); 1740 remove_debug_file(udc);
1698 if (udc->board.vbus_pin > 0) 1741 if (udc->board.vbus_pin > 0)
1699 free_irq(udc->board.vbus_pin, udc); 1742 free_irq(udc->board.vbus_pin, udc);
1700 free_irq(AT91_ID_UDP, udc); 1743 free_irq(udc->udp_irq, udc);
1701 device_unregister(&udc->gadget.dev); 1744 device_unregister(&udc->gadget.dev);
1702 release_mem_region(AT91_BASE_UDP, SZ_16K); 1745 release_mem_region(AT91_BASE_UDP, SZ_16K);
1703 1746
@@ -1708,31 +1751,36 @@ static int __devexit at91udc_remove(struct platform_device *dev)
1708} 1751}
1709 1752
1710#ifdef CONFIG_PM 1753#ifdef CONFIG_PM
1711static int at91udc_suspend(struct platform_device *dev, pm_message_t mesg) 1754static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg)
1712{ 1755{
1713 struct at91_udc *udc = platform_get_drvdata(dev); 1756 struct at91_udc *udc = platform_get_drvdata(pdev);
1757 int wake = udc->driver && device_may_wakeup(&pdev->dev);
1714 1758
1715 /* 1759 /* Unless we can act normally to the host (letting it wake us up
1716 * The "safe" suspend transitions are opportunistic ... e.g. when 1760 * whenever it has work for us) force disconnect. Wakeup requires
1717 * the USB link is suspended (48MHz clock autogated off), or when 1761 * PLLB for USB events (signaling for reset, wakeup, or incoming
1718 * it's disconnected (programmatically gated off, elsewhere). 1762 * tokens) and VBUS irqs (on systems which support them).
1719 * Then we can suspend, and the chip can enter slow clock mode.
1720 *
1721 * The problem case is some component (user mode?) suspending this
1722 * device while it's active, with the 48 MHz clock in use. There
1723 * are two basic approaches: (a) veto suspend levels involving slow
1724 * clock mode, (b) disconnect, so 48 MHz will no longer be in use
1725 * and we can enter slow clock mode. This uses (b) for now, since
1726 * it's simplest until AT91 PM exists and supports the other option.
1727 */ 1763 */
1728 if (udc->vbus && !udc->suspended) 1764 if ((!udc->suspended && udc->addr)
1765 || !wake
1766 || at91_suspend_entering_slow_clock()) {
1729 pullup(udc, 0); 1767 pullup(udc, 0);
1768 disable_irq_wake(udc->udp_irq);
1769 } else
1770 enable_irq_wake(udc->udp_irq);
1771
1772 if (udc->board.vbus_pin > 0) {
1773 if (wake)
1774 enable_irq_wake(udc->board.vbus_pin);
1775 else
1776 disable_irq_wake(udc->board.vbus_pin);
1777 }
1730 return 0; 1778 return 0;
1731} 1779}
1732 1780
1733static int at91udc_resume(struct platform_device *dev) 1781static int at91udc_resume(struct platform_device *pdev)
1734{ 1782{
1735 struct at91_udc *udc = platform_get_drvdata(dev); 1783 struct at91_udc *udc = platform_get_drvdata(pdev);
1736 1784
1737 /* maybe reconnect to host; if so, clocks on */ 1785 /* maybe reconnect to host; if so, clocks on */
1738 pullup(udc, 1); 1786 pullup(udc, 1);
@@ -1748,7 +1796,7 @@ static struct platform_driver at91_udc = {
1748 .remove = __devexit_p(at91udc_remove), 1796 .remove = __devexit_p(at91udc_remove),
1749 .shutdown = at91udc_shutdown, 1797 .shutdown = at91udc_shutdown,
1750 .suspend = at91udc_suspend, 1798 .suspend = at91udc_suspend,
1751 .resume = at91udc_resume, 1799 .resume = at91udc_resume,
1752 .driver = { 1800 .driver = {
1753 .name = (char *) driver_name, 1801 .name = (char *) driver_name,
1754 .owner = THIS_MODULE, 1802 .owner = THIS_MODULE,
@@ -1767,6 +1815,6 @@ static void __devexit udc_exit_module(void)
1767} 1815}
1768module_exit(udc_exit_module); 1816module_exit(udc_exit_module);
1769 1817
1770MODULE_DESCRIPTION("AT91RM9200 udc driver"); 1818MODULE_DESCRIPTION("AT91 udc driver");
1771MODULE_AUTHOR("Thomas Rathbone, David Brownell"); 1819MODULE_AUTHOR("Thomas Rathbone, David Brownell");
1772MODULE_LICENSE("GPL"); 1820MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h
index 5a4799cedd19..882af42e86cc 100644
--- a/drivers/usb/gadget/at91_udc.h
+++ b/drivers/usb/gadget/at91_udc.h
@@ -141,6 +141,7 @@ struct at91_udc {
141 struct clk *iclk, *fclk; 141 struct clk *iclk, *fclk;
142 struct platform_device *pdev; 142 struct platform_device *pdev;
143 struct proc_dir_entry *pde; 143 struct proc_dir_entry *pde;
144 int udp_irq;
144}; 145};
145 146
146static inline struct at91_udc *to_udc(struct usb_gadget *g) 147static inline struct at91_udc *to_udc(struct usb_gadget *g)
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 4be47195bd38..7d1c22c34957 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -609,7 +609,8 @@ static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req)
609 if (!dum->driver) 609 if (!dum->driver)
610 return -ESHUTDOWN; 610 return -ESHUTDOWN;
611 611
612 spin_lock_irqsave (&dum->lock, flags); 612 local_irq_save (flags);
613 spin_lock (&dum->lock);
613 list_for_each_entry (req, &ep->queue, queue) { 614 list_for_each_entry (req, &ep->queue, queue) {
614 if (&req->req == _req) { 615 if (&req->req == _req) {
615 list_del_init (&req->queue); 616 list_del_init (&req->queue);
@@ -618,7 +619,7 @@ static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req)
618 break; 619 break;
619 } 620 }
620 } 621 }
621 spin_unlock_irqrestore (&dum->lock, flags); 622 spin_unlock (&dum->lock);
622 623
623 if (retval == 0) { 624 if (retval == 0) {
624 dev_dbg (udc_dev(dum), 625 dev_dbg (udc_dev(dum),
@@ -626,6 +627,7 @@ static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req)
626 req, _ep->name, _req->length, _req->buf); 627 req, _ep->name, _req->length, _req->buf);
627 _req->complete (_ep, _req); 628 _req->complete (_ep, _req);
628 } 629 }
630 local_irq_restore (flags);
629 return retval; 631 return retval;
630} 632}
631 633
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index f7c6d758e1b0..53d584589c26 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -34,12 +34,12 @@
34 34
35 35
36/* we must assign addresses for configurable endpoints (like net2280) */ 36/* we must assign addresses for configurable endpoints (like net2280) */
37static __initdata unsigned epnum; 37static __devinitdata unsigned epnum;
38 38
39// #define MANY_ENDPOINTS 39// #define MANY_ENDPOINTS
40#ifdef MANY_ENDPOINTS 40#ifdef MANY_ENDPOINTS
41/* more than 15 configurable endpoints */ 41/* more than 15 configurable endpoints */
42static __initdata unsigned in_epnum; 42static __devinitdata unsigned in_epnum;
43#endif 43#endif
44 44
45 45
@@ -59,7 +59,7 @@ static __initdata unsigned in_epnum;
59 * NOTE: each endpoint is unidirectional, as specified by its USB 59 * NOTE: each endpoint is unidirectional, as specified by its USB
60 * descriptor; and isn't specific to a configuration or altsetting. 60 * descriptor; and isn't specific to a configuration or altsetting.
61 */ 61 */
62static int __init 62static int __devinit
63ep_matches ( 63ep_matches (
64 struct usb_gadget *gadget, 64 struct usb_gadget *gadget,
65 struct usb_ep *ep, 65 struct usb_ep *ep,
@@ -73,7 +73,7 @@ ep_matches (
73 /* endpoint already claimed? */ 73 /* endpoint already claimed? */
74 if (0 != ep->driver_data) 74 if (0 != ep->driver_data)
75 return 0; 75 return 0;
76 76
77 /* only support ep0 for portable CONTROL traffic */ 77 /* only support ep0 for portable CONTROL traffic */
78 type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; 78 type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
79 if (USB_ENDPOINT_XFER_CONTROL == type) 79 if (USB_ENDPOINT_XFER_CONTROL == type)
@@ -186,7 +186,7 @@ ep_matches (
186 return 1; 186 return 1;
187} 187}
188 188
189static struct usb_ep * __init 189static struct usb_ep * __devinit
190find_ep (struct usb_gadget *gadget, const char *name) 190find_ep (struct usb_gadget *gadget, const char *name)
191{ 191{
192 struct usb_ep *ep; 192 struct usb_ep *ep;
@@ -228,7 +228,7 @@ find_ep (struct usb_gadget *gadget, const char *name)
228 * 228 *
229 * On failure, this returns a null endpoint descriptor. 229 * On failure, this returns a null endpoint descriptor.
230 */ 230 */
231struct usb_ep * __init usb_ep_autoconfig ( 231struct usb_ep * __devinit usb_ep_autoconfig (
232 struct usb_gadget *gadget, 232 struct usb_gadget *gadget,
233 struct usb_endpoint_descriptor *desc 233 struct usb_endpoint_descriptor *desc
234) 234)
@@ -276,7 +276,7 @@ struct usb_ep * __init usb_ep_autoconfig (
276 return ep; 276 return ep;
277 } 277 }
278 278
279 /* Second, look at endpoints until an unclaimed one looks usable */ 279 /* Second, look at endpoints until an unclaimed one looks usable */
280 list_for_each_entry (ep, &gadget->ep_list, ep_list) { 280 list_for_each_entry (ep, &gadget->ep_list, ep_list) {
281 if (ep_matches (gadget, ep, desc)) 281 if (ep_matches (gadget, ep, desc))
282 return ep; 282 return ep;
@@ -295,7 +295,7 @@ struct usb_ep * __init usb_ep_autoconfig (
295 * state such as ep->driver_data and the record of assigned endpoints 295 * state such as ep->driver_data and the record of assigned endpoints
296 * used by usb_ep_autoconfig(). 296 * used by usb_ep_autoconfig().
297 */ 297 */
298void __init usb_ep_autoconfig_reset (struct usb_gadget *gadget) 298void __devinit usb_ep_autoconfig_reset (struct usb_gadget *gadget)
299{ 299{
300 struct usb_ep *ep; 300 struct usb_ep *ep;
301 301
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 8320fcef0425..30299c620d97 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -117,6 +117,8 @@ struct eth_dev {
117 struct usb_ep *in_ep, *out_ep, *status_ep; 117 struct usb_ep *in_ep, *out_ep, *status_ep;
118 const struct usb_endpoint_descriptor 118 const struct usb_endpoint_descriptor
119 *in, *out, *status; 119 *in, *out, *status;
120
121 spinlock_t req_lock;
120 struct list_head tx_reqs, rx_reqs; 122 struct list_head tx_reqs, rx_reqs;
121 123
122 struct net_device *net; 124 struct net_device *net;
@@ -1066,21 +1068,31 @@ static void eth_reset_config (struct eth_dev *dev)
1066 */ 1068 */
1067 if (dev->in) { 1069 if (dev->in) {
1068 usb_ep_disable (dev->in_ep); 1070 usb_ep_disable (dev->in_ep);
1071 spin_lock(&dev->req_lock);
1069 while (likely (!list_empty (&dev->tx_reqs))) { 1072 while (likely (!list_empty (&dev->tx_reqs))) {
1070 req = container_of (dev->tx_reqs.next, 1073 req = container_of (dev->tx_reqs.next,
1071 struct usb_request, list); 1074 struct usb_request, list);
1072 list_del (&req->list); 1075 list_del (&req->list);
1076
1077 spin_unlock(&dev->req_lock);
1073 usb_ep_free_request (dev->in_ep, req); 1078 usb_ep_free_request (dev->in_ep, req);
1079 spin_lock(&dev->req_lock);
1074 } 1080 }
1081 spin_unlock(&dev->req_lock);
1075 } 1082 }
1076 if (dev->out) { 1083 if (dev->out) {
1077 usb_ep_disable (dev->out_ep); 1084 usb_ep_disable (dev->out_ep);
1085 spin_lock(&dev->req_lock);
1078 while (likely (!list_empty (&dev->rx_reqs))) { 1086 while (likely (!list_empty (&dev->rx_reqs))) {
1079 req = container_of (dev->rx_reqs.next, 1087 req = container_of (dev->rx_reqs.next,
1080 struct usb_request, list); 1088 struct usb_request, list);
1081 list_del (&req->list); 1089 list_del (&req->list);
1090
1091 spin_unlock(&dev->req_lock);
1082 usb_ep_free_request (dev->out_ep, req); 1092 usb_ep_free_request (dev->out_ep, req);
1093 spin_lock(&dev->req_lock);
1083 } 1094 }
1095 spin_unlock(&dev->req_lock);
1084 } 1096 }
1085 1097
1086 if (dev->status) { 1098 if (dev->status) {
@@ -1659,9 +1671,9 @@ enomem:
1659 if (retval) { 1671 if (retval) {
1660 DEBUG (dev, "rx submit --> %d\n", retval); 1672 DEBUG (dev, "rx submit --> %d\n", retval);
1661 dev_kfree_skb_any (skb); 1673 dev_kfree_skb_any (skb);
1662 spin_lock (&dev->lock); 1674 spin_lock(&dev->req_lock);
1663 list_add (&req->list, &dev->rx_reqs); 1675 list_add (&req->list, &dev->rx_reqs);
1664 spin_unlock (&dev->lock); 1676 spin_unlock(&dev->req_lock);
1665 } 1677 }
1666 return retval; 1678 return retval;
1667} 1679}
@@ -1730,8 +1742,9 @@ quiesce:
1730 dev_kfree_skb_any (skb); 1742 dev_kfree_skb_any (skb);
1731 if (!netif_running (dev->net)) { 1743 if (!netif_running (dev->net)) {
1732clean: 1744clean:
1733 /* nobody reading rx_reqs, so no dev->lock */ 1745 spin_lock(&dev->req_lock);
1734 list_add (&req->list, &dev->rx_reqs); 1746 list_add (&req->list, &dev->rx_reqs);
1747 spin_unlock(&dev->req_lock);
1735 req = NULL; 1748 req = NULL;
1736 } 1749 }
1737 if (req) 1750 if (req)
@@ -1782,15 +1795,18 @@ static int alloc_requests (struct eth_dev *dev, unsigned n, gfp_t gfp_flags)
1782{ 1795{
1783 int status; 1796 int status;
1784 1797
1798 spin_lock(&dev->req_lock);
1785 status = prealloc (&dev->tx_reqs, dev->in_ep, n, gfp_flags); 1799 status = prealloc (&dev->tx_reqs, dev->in_ep, n, gfp_flags);
1786 if (status < 0) 1800 if (status < 0)
1787 goto fail; 1801 goto fail;
1788 status = prealloc (&dev->rx_reqs, dev->out_ep, n, gfp_flags); 1802 status = prealloc (&dev->rx_reqs, dev->out_ep, n, gfp_flags);
1789 if (status < 0) 1803 if (status < 0)
1790 goto fail; 1804 goto fail;
1791 return 0; 1805 goto done;
1792fail: 1806fail:
1793 DEBUG (dev, "can't alloc requests\n"); 1807 DEBUG (dev, "can't alloc requests\n");
1808done:
1809 spin_unlock(&dev->req_lock);
1794 return status; 1810 return status;
1795} 1811}
1796 1812
@@ -1800,21 +1816,21 @@ static void rx_fill (struct eth_dev *dev, gfp_t gfp_flags)
1800 unsigned long flags; 1816 unsigned long flags;
1801 1817
1802 /* fill unused rxq slots with some skb */ 1818 /* fill unused rxq slots with some skb */
1803 spin_lock_irqsave (&dev->lock, flags); 1819 spin_lock_irqsave(&dev->req_lock, flags);
1804 while (!list_empty (&dev->rx_reqs)) { 1820 while (!list_empty (&dev->rx_reqs)) {
1805 req = container_of (dev->rx_reqs.next, 1821 req = container_of (dev->rx_reqs.next,
1806 struct usb_request, list); 1822 struct usb_request, list);
1807 list_del_init (&req->list); 1823 list_del_init (&req->list);
1808 spin_unlock_irqrestore (&dev->lock, flags); 1824 spin_unlock_irqrestore(&dev->req_lock, flags);
1809 1825
1810 if (rx_submit (dev, req, gfp_flags) < 0) { 1826 if (rx_submit (dev, req, gfp_flags) < 0) {
1811 defer_kevent (dev, WORK_RX_MEMORY); 1827 defer_kevent (dev, WORK_RX_MEMORY);
1812 return; 1828 return;
1813 } 1829 }
1814 1830
1815 spin_lock_irqsave (&dev->lock, flags); 1831 spin_lock_irqsave(&dev->req_lock, flags);
1816 } 1832 }
1817 spin_unlock_irqrestore (&dev->lock, flags); 1833 spin_unlock_irqrestore(&dev->req_lock, flags);
1818} 1834}
1819 1835
1820static void eth_work (void *_dev) 1836static void eth_work (void *_dev)
@@ -1848,9 +1864,9 @@ static void tx_complete (struct usb_ep *ep, struct usb_request *req)
1848 } 1864 }
1849 dev->stats.tx_packets++; 1865 dev->stats.tx_packets++;
1850 1866
1851 spin_lock (&dev->lock); 1867 spin_lock(&dev->req_lock);
1852 list_add (&req->list, &dev->tx_reqs); 1868 list_add (&req->list, &dev->tx_reqs);
1853 spin_unlock (&dev->lock); 1869 spin_unlock(&dev->req_lock);
1854 dev_kfree_skb_any (skb); 1870 dev_kfree_skb_any (skb);
1855 1871
1856 atomic_dec (&dev->tx_qlen); 1872 atomic_dec (&dev->tx_qlen);
@@ -1896,12 +1912,12 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1896 /* ignores USB_CDC_PACKET_TYPE_DIRECTED */ 1912 /* ignores USB_CDC_PACKET_TYPE_DIRECTED */
1897 } 1913 }
1898 1914
1899 spin_lock_irqsave (&dev->lock, flags); 1915 spin_lock_irqsave(&dev->req_lock, flags);
1900 req = container_of (dev->tx_reqs.next, struct usb_request, list); 1916 req = container_of (dev->tx_reqs.next, struct usb_request, list);
1901 list_del (&req->list); 1917 list_del (&req->list);
1902 if (list_empty (&dev->tx_reqs)) 1918 if (list_empty (&dev->tx_reqs))
1903 netif_stop_queue (net); 1919 netif_stop_queue (net);
1904 spin_unlock_irqrestore (&dev->lock, flags); 1920 spin_unlock_irqrestore(&dev->req_lock, flags);
1905 1921
1906 /* no buffer copies needed, unless the network stack did it 1922 /* no buffer copies needed, unless the network stack did it
1907 * or the hardware can't use skb buffers. 1923 * or the hardware can't use skb buffers.
@@ -1955,11 +1971,11 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1955drop: 1971drop:
1956 dev->stats.tx_dropped++; 1972 dev->stats.tx_dropped++;
1957 dev_kfree_skb_any (skb); 1973 dev_kfree_skb_any (skb);
1958 spin_lock_irqsave (&dev->lock, flags); 1974 spin_lock_irqsave(&dev->req_lock, flags);
1959 if (list_empty (&dev->tx_reqs)) 1975 if (list_empty (&dev->tx_reqs))
1960 netif_start_queue (net); 1976 netif_start_queue (net);
1961 list_add (&req->list, &dev->tx_reqs); 1977 list_add (&req->list, &dev->tx_reqs);
1962 spin_unlock_irqrestore (&dev->lock, flags); 1978 spin_unlock_irqrestore(&dev->req_lock, flags);
1963 } 1979 }
1964 return 0; 1980 return 0;
1965} 1981}
@@ -2131,7 +2147,7 @@ eth_req_free (struct usb_ep *ep, struct usb_request *req)
2131} 2147}
2132 2148
2133 2149
2134static void __exit 2150static void /* __init_or_exit */
2135eth_unbind (struct usb_gadget *gadget) 2151eth_unbind (struct usb_gadget *gadget)
2136{ 2152{
2137 struct eth_dev *dev = get_gadget_data (gadget); 2153 struct eth_dev *dev = get_gadget_data (gadget);
@@ -2158,7 +2174,7 @@ eth_unbind (struct usb_gadget *gadget)
2158 set_gadget_data (gadget, NULL); 2174 set_gadget_data (gadget, NULL);
2159} 2175}
2160 2176
2161static u8 __init nibble (unsigned char c) 2177static u8 __devinit nibble (unsigned char c)
2162{ 2178{
2163 if (likely (isdigit (c))) 2179 if (likely (isdigit (c)))
2164 return c - '0'; 2180 return c - '0';
@@ -2168,7 +2184,7 @@ static u8 __init nibble (unsigned char c)
2168 return 0; 2184 return 0;
2169} 2185}
2170 2186
2171static int __init get_ether_addr(const char *str, u8 *dev_addr) 2187static int __devinit get_ether_addr(const char *str, u8 *dev_addr)
2172{ 2188{
2173 if (str) { 2189 if (str) {
2174 unsigned i; 2190 unsigned i;
@@ -2189,7 +2205,7 @@ static int __init get_ether_addr(const char *str, u8 *dev_addr)
2189 return 1; 2205 return 1;
2190} 2206}
2191 2207
2192static int __init 2208static int __devinit
2193eth_bind (struct usb_gadget *gadget) 2209eth_bind (struct usb_gadget *gadget)
2194{ 2210{
2195 struct eth_dev *dev; 2211 struct eth_dev *dev;
@@ -2378,6 +2394,7 @@ autoconf_fail:
2378 return status; 2394 return status;
2379 dev = netdev_priv(net); 2395 dev = netdev_priv(net);
2380 spin_lock_init (&dev->lock); 2396 spin_lock_init (&dev->lock);
2397 spin_lock_init (&dev->req_lock);
2381 INIT_WORK (&dev->work, eth_work, dev); 2398 INIT_WORK (&dev->work, eth_work, dev);
2382 INIT_LIST_HEAD (&dev->tx_reqs); 2399 INIT_LIST_HEAD (&dev->tx_reqs);
2383 INIT_LIST_HEAD (&dev->rx_reqs); 2400 INIT_LIST_HEAD (&dev->rx_reqs);
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index b1a9cf06f3e6..8d7f1e84cd7b 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -3691,7 +3691,7 @@ static void lun_release(struct device *dev)
3691 kref_put(&fsg->ref, fsg_release); 3691 kref_put(&fsg->ref, fsg_release);
3692} 3692}
3693 3693
3694static void __exit fsg_unbind(struct usb_gadget *gadget) 3694static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3695{ 3695{
3696 struct fsg_dev *fsg = get_gadget_data(gadget); 3696 struct fsg_dev *fsg = get_gadget_data(gadget);
3697 int i; 3697 int i;
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index bb22b7e82877..36db72579377 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -2143,7 +2143,7 @@ static int lh7a40x_udc_remove(struct platform_device *pdev)
2143 2143
2144static struct platform_driver udc_driver = { 2144static struct platform_driver udc_driver = {
2145 .probe = lh7a40x_udc_probe, 2145 .probe = lh7a40x_udc_probe,
2146 .remove = lh7a40x_udc_remove 2146 .remove = lh7a40x_udc_remove,
2147 /* FIXME power management support */ 2147 /* FIXME power management support */
2148 /* .suspend = ... disable UDC */ 2148 /* .suspend = ... disable UDC */
2149 /* .resume = ... re-enable UDC */ 2149 /* .resume = ... re-enable UDC */
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 354670d12308..408c3380d602 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -1398,7 +1398,7 @@ static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
1398#endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 1398#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1399 1399
1400 1400
1401int __init rndis_init (void) 1401int __devinit rndis_init (void)
1402{ 1402{
1403 u8 i; 1403 u8 i;
1404 1404
diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h
index 2956608be751..4c3c7259f019 100644
--- a/drivers/usb/gadget/rndis.h
+++ b/drivers/usb/gadget/rndis.h
@@ -264,7 +264,7 @@ int rndis_signal_disconnect (int configNr);
264int rndis_state (int configNr); 264int rndis_state (int configNr);
265extern void rndis_set_host_mac (int configNr, const u8 *addr); 265extern void rndis_set_host_mac (int configNr, const u8 *addr);
266 266
267int __init rndis_init (void); 267int __devinit rndis_init (void);
268void rndis_exit (void); 268void rndis_exit (void);
269 269
270#endif /* _LINUX_RNDIS_H */ 270#endif /* _LINUX_RNDIS_H */
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 30d7664d449d..e762aa19ab0a 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -1473,7 +1473,7 @@ autoconf_fail:
1473 * Called on module unload. Frees the control request and device 1473 * Called on module unload. Frees the control request and device
1474 * structure. 1474 * structure.
1475 */ 1475 */
1476static void __exit gs_unbind(struct usb_gadget *gadget) 1476static void /* __init_or_exit */ gs_unbind(struct usb_gadget *gadget)
1477{ 1477{
1478 struct gs_dev *dev = get_gadget_data(gadget); 1478 struct gs_dev *dev = get_gadget_data(gadget);
1479 1479
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 3a08a7ab4ce0..b7018ee487ea 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -1121,7 +1121,7 @@ zero_autoresume (unsigned long _dev)
1121 1121
1122/*-------------------------------------------------------------------------*/ 1122/*-------------------------------------------------------------------------*/
1123 1123
1124static void __exit 1124static void /* __init_or_exit */
1125zero_unbind (struct usb_gadget *gadget) 1125zero_unbind (struct usb_gadget *gadget)
1126{ 1126{
1127 struct zero_dev *dev = get_gadget_data (gadget); 1127 struct zero_dev *dev = get_gadget_data (gadget);
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index d66867aa527e..26ed757d22a6 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -41,8 +41,6 @@
41#endif 41#endif
42#define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN) 42#define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
43 43
44#endif /* Au1200 */
45
46extern int usb_disabled(void); 44extern int usb_disabled(void);
47 45
48/*-------------------------------------------------------------------------*/ 46/*-------------------------------------------------------------------------*/
@@ -107,9 +105,9 @@ int usb_ehci_au1xxx_probe(const struct hc_driver *driver,
107 105
108 /* Au1200 AB USB does not support coherent memory */ 106 /* Au1200 AB USB does not support coherent memory */
109 if (!(read_c0_prid() & 0xff)) { 107 if (!(read_c0_prid() & 0xff)) {
110 pr_info("%s: this is chip revision AB!\n", dev->dev.name); 108 pr_info("%s: this is chip revision AB!\n", dev->name);
111 pr_info("%s: update your board or re-configure the kernel\n", 109 pr_info("%s: update your board or re-configure the kernel\n",
112 dev->dev.name); 110 dev->name);
113 return -ENODEV; 111 return -ENODEV;
114 } 112 }
115#endif 113#endif
@@ -228,9 +226,8 @@ static const struct hc_driver ehci_au1xxx_hc_driver = {
228 226
229/*-------------------------------------------------------------------------*/ 227/*-------------------------------------------------------------------------*/
230 228
231static int ehci_hcd_au1xxx_drv_probe(struct device *dev) 229static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
232{ 230{
233 struct platform_device *pdev = to_platform_device(dev);
234 struct usb_hcd *hcd = NULL; 231 struct usb_hcd *hcd = NULL;
235 int ret; 232 int ret;
236 233
@@ -243,10 +240,9 @@ static int ehci_hcd_au1xxx_drv_probe(struct device *dev)
243 return ret; 240 return ret;
244} 241}
245 242
246static int ehci_hcd_au1xxx_drv_remove(struct device *dev) 243static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
247{ 244{
248 struct platform_device *pdev = to_platform_device(dev); 245 struct usb_hcd *hcd = platform_get_drvdata(pdev);
249 struct usb_hcd *hcd = dev_get_drvdata(dev);
250 246
251 usb_ehci_au1xxx_remove(hcd, pdev); 247 usb_ehci_au1xxx_remove(hcd, pdev);
252 return 0; 248 return 0;
@@ -269,12 +265,13 @@ static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
269} 265}
270*/ 266*/
271MODULE_ALIAS("au1xxx-ehci"); 267MODULE_ALIAS("au1xxx-ehci");
272/* FIXME use "struct platform_driver" */ 268static struct platform_driver ehci_hcd_au1xxx_driver = {
273static struct device_driver ehci_hcd_au1xxx_driver = {
274 .name = "au1xxx-ehci",
275 .bus = &platform_bus_type,
276 .probe = ehci_hcd_au1xxx_drv_probe, 269 .probe = ehci_hcd_au1xxx_drv_probe,
277 .remove = ehci_hcd_au1xxx_drv_remove, 270 .remove = ehci_hcd_au1xxx_drv_remove,
278 /*.suspend = ehci_hcd_au1xxx_drv_suspend, */ 271 /*.suspend = ehci_hcd_au1xxx_drv_suspend, */
279 /*.resume = ehci_hcd_au1xxx_drv_resume, */ 272 /*.resume = ehci_hcd_au1xxx_drv_resume, */
273 .driver = {
274 .name = "au1xxx-ehci",
275 .bus = &platform_bus_type
276 }
280}; 277};
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index cee6f538de0a..d63177a8eaea 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -625,10 +625,11 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd, struct pt_regs *regs)
625 writel (status | CMD_RUN, &ehci->regs->command); 625 writel (status | CMD_RUN, &ehci->regs->command);
626 626
627 while (i--) { 627 while (i--) {
628 status = readl (&ehci->regs->port_status [i]); 628 int pstatus = readl (&ehci->regs->port_status [i]);
629 if (status & PORT_OWNER) 629
630 if (pstatus & PORT_OWNER)
630 continue; 631 continue;
631 if (!(status & PORT_RESUME) 632 if (!(pstatus & PORT_RESUME)
632 || ehci->reset_done [i] != 0) 633 || ehci->reset_done [i] != 0)
633 continue; 634 continue;
634 635
@@ -891,7 +892,7 @@ MODULE_LICENSE ("GPL");
891#define PCI_DRIVER ehci_pci_driver 892#define PCI_DRIVER ehci_pci_driver
892#endif 893#endif
893 894
894#ifdef CONFIG_PPC_83xx 895#ifdef CONFIG_MPC834x
895#include "ehci-fsl.c" 896#include "ehci-fsl.c"
896#define PLATFORM_DRIVER ehci_fsl_driver 897#define PLATFORM_DRIVER ehci_fsl_driver
897#endif 898#endif
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index cdbafb710000..85cc059705a6 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -4,7 +4,7 @@
4 * Copyright (C) 2004 SAN People (Pty) Ltd. 4 * Copyright (C) 2004 SAN People (Pty) Ltd.
5 * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org> 5 * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
6 * 6 *
7 * AT91RM9200 Bus Glue 7 * AT91 Bus Glue
8 * 8 *
9 * Based on fragments of 2.4 driver by Rick Bronson. 9 * Based on fragments of 2.4 driver by Rick Bronson.
10 * Based on ohci-omap.c 10 * Based on ohci-omap.c
@@ -19,12 +19,13 @@
19#include <asm/hardware.h> 19#include <asm/hardware.h>
20#include <asm/arch/board.h> 20#include <asm/arch/board.h>
21 21
22#ifndef CONFIG_ARCH_AT91RM9200 22#ifndef CONFIG_ARCH_AT91
23#error "CONFIG_ARCH_AT91RM9200 must be defined." 23#error "CONFIG_ARCH_AT91 must be defined."
24#endif 24#endif
25 25
26/* interface and function clocks */ 26/* interface and function clocks */
27static struct clk *iclk, *fclk; 27static struct clk *iclk, *fclk;
28static int clocked;
28 29
29extern int usb_disabled(void); 30extern int usb_disabled(void);
30 31
@@ -35,13 +36,14 @@ static void at91_start_hc(struct platform_device *pdev)
35 struct usb_hcd *hcd = platform_get_drvdata(pdev); 36 struct usb_hcd *hcd = platform_get_drvdata(pdev);
36 struct ohci_regs __iomem *regs = hcd->regs; 37 struct ohci_regs __iomem *regs = hcd->regs;
37 38
38 dev_dbg(&pdev->dev, "starting AT91RM9200 OHCI USB Controller\n"); 39 dev_dbg(&pdev->dev, "start\n");
39 40
40 /* 41 /*
41 * Start the USB clocks. 42 * Start the USB clocks.
42 */ 43 */
43 clk_enable(iclk); 44 clk_enable(iclk);
44 clk_enable(fclk); 45 clk_enable(fclk);
46 clocked = 1;
45 47
46 /* 48 /*
47 * The USB host controller must remain in reset. 49 * The USB host controller must remain in reset.
@@ -54,7 +56,7 @@ static void at91_stop_hc(struct platform_device *pdev)
54 struct usb_hcd *hcd = platform_get_drvdata(pdev); 56 struct usb_hcd *hcd = platform_get_drvdata(pdev);
55 struct ohci_regs __iomem *regs = hcd->regs; 57 struct ohci_regs __iomem *regs = hcd->regs;
56 58
57 dev_dbg(&pdev->dev, "stopping AT91RM9200 OHCI USB Controller\n"); 59 dev_dbg(&pdev->dev, "stop\n");
58 60
59 /* 61 /*
60 * Put the USB host controller into reset. 62 * Put the USB host controller into reset.
@@ -66,6 +68,7 @@ static void at91_stop_hc(struct platform_device *pdev)
66 */ 68 */
67 clk_disable(fclk); 69 clk_disable(fclk);
68 clk_disable(iclk); 70 clk_disable(iclk);
71 clocked = 0;
69} 72}
70 73
71 74
@@ -78,14 +81,15 @@ static int usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
78 81
79 82
80/** 83/**
81 * usb_hcd_at91_probe - initialize AT91RM9200-based HCDs 84 * usb_hcd_at91_probe - initialize AT91-based HCDs
82 * Context: !in_interrupt() 85 * Context: !in_interrupt()
83 * 86 *
84 * Allocates basic resources for this USB host controller, and 87 * Allocates basic resources for this USB host controller, and
85 * then invokes the start() method for the HCD associated with it 88 * then invokes the start() method for the HCD associated with it
86 * through the hotplug entry's driver_data. 89 * through the hotplug entry's driver_data.
87 */ 90 */
88int usb_hcd_at91_probe (const struct hc_driver *driver, struct platform_device *pdev) 91static int usb_hcd_at91_probe(const struct hc_driver *driver,
92 struct platform_device *pdev)
89{ 93{
90 int retval; 94 int retval;
91 struct usb_hcd *hcd = NULL; 95 struct usb_hcd *hcd = NULL;
@@ -95,12 +99,13 @@ int usb_hcd_at91_probe (const struct hc_driver *driver, struct platform_device *
95 return -ENODEV; 99 return -ENODEV;
96 } 100 }
97 101
98 if ((pdev->resource[0].flags != IORESOURCE_MEM) || (pdev->resource[1].flags != IORESOURCE_IRQ)) { 102 if ((pdev->resource[0].flags != IORESOURCE_MEM)
103 || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
99 pr_debug("hcd probe: invalid resource type\n"); 104 pr_debug("hcd probe: invalid resource type\n");
100 return -ENODEV; 105 return -ENODEV;
101 } 106 }
102 107
103 hcd = usb_create_hcd(driver, &pdev->dev, "at91rm9200"); 108 hcd = usb_create_hcd(driver, &pdev->dev, "at91");
104 if (!hcd) 109 if (!hcd)
105 return -ENOMEM; 110 return -ENOMEM;
106 hcd->rsrc_start = pdev->resource[0].start; 111 hcd->rsrc_start = pdev->resource[0].start;
@@ -149,21 +154,23 @@ int usb_hcd_at91_probe (const struct hc_driver *driver, struct platform_device *
149/* may be called with controller, bus, and devices active */ 154/* may be called with controller, bus, and devices active */
150 155
151/** 156/**
152 * usb_hcd_at91_remove - shutdown processing for AT91RM9200-based HCDs 157 * usb_hcd_at91_remove - shutdown processing for AT91-based HCDs
153 * @dev: USB Host Controller being removed 158 * @dev: USB Host Controller being removed
154 * Context: !in_interrupt() 159 * Context: !in_interrupt()
155 * 160 *
156 * Reverses the effect of usb_hcd_at91_probe(), first invoking 161 * Reverses the effect of usb_hcd_at91_probe(), first invoking
157 * the HCD's stop() method. It is always called from a thread 162 * the HCD's stop() method. It is always called from a thread
158 * context, normally "rmmod", "apmd", or something similar. 163 * context, "rmmod" or something similar.
159 * 164 *
160 */ 165 */
161static int usb_hcd_at91_remove (struct usb_hcd *hcd, struct platform_device *pdev) 166static int usb_hcd_at91_remove(struct usb_hcd *hcd,
167 struct platform_device *pdev)
162{ 168{
163 usb_remove_hcd(hcd); 169 usb_remove_hcd(hcd);
164 at91_stop_hc(pdev); 170 at91_stop_hc(pdev);
165 iounmap(hcd->regs); 171 iounmap(hcd->regs);
166 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 172 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
173 disable_irq_wake(hcd->irq);
167 174
168 clk_put(fclk); 175 clk_put(fclk);
169 clk_put(iclk); 176 clk_put(iclk);
@@ -178,19 +185,21 @@ static int usb_hcd_at91_remove (struct usb_hcd *hcd, struct platform_device *pde
178static int __devinit 185static int __devinit
179ohci_at91_start (struct usb_hcd *hcd) 186ohci_at91_start (struct usb_hcd *hcd)
180{ 187{
181// struct at91_ohci_data *board = hcd->self.controller->platform_data; 188 struct at91_usbh_data *board = hcd->self.controller->platform_data;
182 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 189 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
190 struct usb_device *root = hcd->self.root_hub;
183 int ret; 191 int ret;
184 192
185 if ((ret = ohci_init(ohci)) < 0) 193 if ((ret = ohci_init(ohci)) < 0)
186 return ret; 194 return ret;
187 195
196 root->maxchild = board->ports;
197
188 if ((ret = ohci_run(ohci)) < 0) { 198 if ((ret = ohci_run(ohci)) < 0) {
189 err("can't start %s", hcd->self.bus_name); 199 err("can't start %s", hcd->self.bus_name);
190 ohci_stop(hcd); 200 ohci_stop(hcd);
191 return ret; 201 return ret;
192 } 202 }
193// hcd->self.root_hub->maxchild = board->ports;
194 return 0; 203 return 0;
195} 204}
196 205
@@ -198,7 +207,7 @@ ohci_at91_start (struct usb_hcd *hcd)
198 207
199static const struct hc_driver ohci_at91_hc_driver = { 208static const struct hc_driver ohci_at91_hc_driver = {
200 .description = hcd_name, 209 .description = hcd_name,
201 .product_desc = "AT91RM9200 OHCI", 210 .product_desc = "AT91 OHCI",
202 .hcd_priv_size = sizeof(struct ohci_hcd), 211 .hcd_priv_size = sizeof(struct ohci_hcd),
203 212
204 /* 213 /*
@@ -240,33 +249,54 @@ static const struct hc_driver ohci_at91_hc_driver = {
240 249
241/*-------------------------------------------------------------------------*/ 250/*-------------------------------------------------------------------------*/
242 251
243static int ohci_hcd_at91_drv_probe(struct platform_device *dev) 252static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
244{ 253{
245 return usb_hcd_at91_probe(&ohci_at91_hc_driver, dev); 254 device_init_wakeup(&pdev->dev, 1);
255 return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
246} 256}
247 257
248static int ohci_hcd_at91_drv_remove(struct platform_device *dev) 258static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
249{ 259{
250 return usb_hcd_at91_remove(platform_get_drvdata(dev), dev); 260 device_init_wakeup(&pdev->dev, 0);
261 return usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
251} 262}
252 263
253#ifdef CONFIG_PM 264#ifdef CONFIG_PM
254 265
255/* REVISIT suspend/resume look "too" simple here */
256
257static int 266static int
258ohci_hcd_at91_drv_suspend(struct platform_device *dev, pm_message_t mesg) 267ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
259{ 268{
260 clk_disable(fclk); 269 struct usb_hcd *hcd = platform_get_drvdata(pdev);
261 clk_disable(iclk); 270 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
271
272 if (device_may_wakeup(&pdev->dev))
273 enable_irq_wake(hcd->irq);
274 else
275 disable_irq_wake(hcd->irq);
276
277 /*
278 * The integrated transceivers seem unable to notice disconnect,
279 * reconnect, or wakeup without the 48 MHz clock active. so for
280 * correctness, always discard connection state (using reset).
281 *
282 * REVISIT: some boards will be able to turn VBUS off...
283 */
284 if (at91_suspend_entering_slow_clock()) {
285 ohci_usb_reset (ohci);
286 clk_disable(fclk);
287 clk_disable(iclk);
288 clocked = 0;
289 }
262 290
263 return 0; 291 return 0;
264} 292}
265 293
266static int ohci_hcd_at91_drv_resume(struct platform_device *dev) 294static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
267{ 295{
268 clk_enable(iclk); 296 if (!clocked) {
269 clk_enable(fclk); 297 clk_enable(iclk);
298 clk_enable(fclk);
299 }
270 300
271 return 0; 301 return 0;
272} 302}
@@ -275,7 +305,7 @@ static int ohci_hcd_at91_drv_resume(struct platform_device *dev)
275#define ohci_hcd_at91_drv_resume NULL 305#define ohci_hcd_at91_drv_resume NULL
276#endif 306#endif
277 307
278MODULE_ALIAS("at91rm9200-ohci"); 308MODULE_ALIAS("at91_ohci");
279 309
280static struct platform_driver ohci_hcd_at91_driver = { 310static struct platform_driver ohci_hcd_at91_driver = {
281 .probe = ohci_hcd_at91_drv_probe, 311 .probe = ohci_hcd_at91_drv_probe,
@@ -283,7 +313,7 @@ static struct platform_driver ohci_hcd_at91_driver = {
283 .suspend = ohci_hcd_at91_drv_suspend, 313 .suspend = ohci_hcd_at91_drv_suspend,
284 .resume = ohci_hcd_at91_drv_resume, 314 .resume = ohci_hcd_at91_drv_resume,
285 .driver = { 315 .driver = {
286 .name = "at91rm9200-ohci", 316 .name = "at91_ohci",
287 .owner = THIS_MODULE, 317 .owner = THIS_MODULE,
288 }, 318 },
289}; 319};
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index 689261e44018..f7a975d5db09 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -101,9 +101,11 @@ static void au1xxx_start_ohc(struct platform_device *dev)
101 101
102#endif /* Au1200 */ 102#endif /* Au1200 */
103 103
104#ifndef CONFIG_SOC_AU1200
104 /* wait for reset complete (read register twice; see au1500 errata) */ 105 /* wait for reset complete (read register twice; see au1500 errata) */
105 while (au_readl(USB_HOST_CONFIG), 106 while (au_readl(USB_HOST_CONFIG),
106 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD)) 107 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
108#endif
107 udelay(1000); 109 udelay(1000);
108 110
109 printk(KERN_DEBUG __FILE__ 111 printk(KERN_DEBUG __FILE__
@@ -157,9 +159,9 @@ static int usb_ohci_au1xxx_probe(const struct hc_driver *driver,
157 /* Au1200 AB USB does not support coherent memory */ 159 /* Au1200 AB USB does not support coherent memory */
158 if (!(read_c0_prid() & 0xff)) { 160 if (!(read_c0_prid() & 0xff)) {
159 pr_info("%s: this is chip revision AB !!\n", 161 pr_info("%s: this is chip revision AB !!\n",
160 dev->dev.name); 162 dev->name);
161 pr_info("%s: update your board or re-configure the kernel\n", 163 pr_info("%s: update your board or re-configure the kernel\n",
162 dev->dev.name); 164 dev->name);
163 return -ENODEV; 165 return -ENODEV;
164 } 166 }
165#endif 167#endif
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c
new file mode 100644
index 000000000000..6531c4d26527
--- /dev/null
+++ b/drivers/usb/host/ohci-ep93xx.c
@@ -0,0 +1,225 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company
7 *
8 * Bus Glue for ep93xx.
9 *
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Russell King et al.
12 *
13 * Modified for LH7A404 from ohci-sa1111.c
14 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
15 *
16 * Modified for pxa27x from ohci-lh7a404.c
17 * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
18 *
19 * Modified for ep93xx from ohci-pxa27x.c
20 * by Lennert Buytenhek <buytenh@wantstofly.org> 28-2-2006
21 * Based on an earlier driver by Ray Lehtiniemi
22 *
23 * This file is licenced under the GPL.
24 */
25
26#include <linux/clk.h>
27#include <linux/device.h>
28#include <linux/signal.h>
29#include <linux/platform_device.h>
30
31#include <asm/mach-types.h>
32#include <asm/hardware.h>
33
34static struct clk *usb_host_clock;
35
36static void ep93xx_start_hc(struct device *dev)
37{
38 clk_enable(usb_host_clock);
39}
40
41static void ep93xx_stop_hc(struct device *dev)
42{
43 clk_disable(usb_host_clock);
44}
45
46static int usb_hcd_ep93xx_probe(const struct hc_driver *driver,
47 struct platform_device *pdev)
48{
49 int retval;
50 struct usb_hcd *hcd;
51
52 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
53 pr_debug("resource[1] is not IORESOURCE_IRQ");
54 return -ENOMEM;
55 }
56
57 hcd = usb_create_hcd(driver, &pdev->dev, "ep93xx");
58 if (hcd == NULL)
59 return -ENOMEM;
60
61 hcd->rsrc_start = pdev->resource[0].start;
62 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
63 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
64 usb_put_hcd(hcd);
65 retval = -EBUSY;
66 goto err1;
67 }
68
69 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
70 if (hcd->regs == NULL) {
71 pr_debug("ioremap failed");
72 retval = -ENOMEM;
73 goto err2;
74 }
75
76 usb_host_clock = clk_get(&pdev->dev, "usb_host");
77 ep93xx_start_hc(&pdev->dev);
78
79 ohci_hcd_init(hcd_to_ohci(hcd));
80
81 retval = usb_add_hcd(hcd, pdev->resource[1].start, SA_INTERRUPT);
82 if (retval == 0)
83 return retval;
84
85 ep93xx_stop_hc(&pdev->dev);
86 iounmap(hcd->regs);
87err2:
88 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
89err1:
90 usb_put_hcd(hcd);
91
92 return retval;
93}
94
95static void usb_hcd_ep93xx_remove(struct usb_hcd *hcd,
96 struct platform_device *pdev)
97{
98 usb_remove_hcd(hcd);
99 ep93xx_stop_hc(&pdev->dev);
100 clk_put(usb_host_clock);
101 iounmap(hcd->regs);
102 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
103 usb_put_hcd(hcd);
104}
105
106static int __devinit ohci_ep93xx_start(struct usb_hcd *hcd)
107{
108 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
109 int ret;
110
111 if ((ret = ohci_init(ohci)) < 0)
112 return ret;
113
114 if ((ret = ohci_run(ohci)) < 0) {
115 err("can't start %s", hcd->self.bus_name);
116 ohci_stop(hcd);
117 return ret;
118 }
119
120 return 0;
121}
122
123static struct hc_driver ohci_ep93xx_hc_driver = {
124 .description = hcd_name,
125 .product_desc = "EP93xx OHCI",
126 .hcd_priv_size = sizeof(struct ohci_hcd),
127 .irq = ohci_irq,
128 .flags = HCD_USB11 | HCD_MEMORY,
129 .start = ohci_ep93xx_start,
130 .stop = ohci_stop,
131 .urb_enqueue = ohci_urb_enqueue,
132 .urb_dequeue = ohci_urb_dequeue,
133 .endpoint_disable = ohci_endpoint_disable,
134 .get_frame_number = ohci_get_frame,
135 .hub_status_data = ohci_hub_status_data,
136 .hub_control = ohci_hub_control,
137#ifdef CONFIG_PM
138 .bus_suspend = ohci_bus_suspend,
139 .bus_resume = ohci_bus_resume,
140#endif
141 .start_port_reset = ohci_start_port_reset,
142};
143
144extern int usb_disabled(void);
145
146static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
147{
148 int ret;
149
150 ret = -ENODEV;
151 if (!usb_disabled())
152 ret = usb_hcd_ep93xx_probe(&ohci_ep93xx_hc_driver, pdev);
153
154 return ret;
155}
156
157static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
158{
159 struct usb_hcd *hcd = platform_get_drvdata(pdev);
160
161 usb_hcd_ep93xx_remove(hcd, pdev);
162
163 return 0;
164}
165
166#ifdef CONFIG_PM
167static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
168{
169 struct usb_hcd *hcd = platform_get_drvdata(pdev);
170 struct ochi_hcd *ohci = hcd_to_ohci(hcd);
171
172 if (time_before(jiffies, ohci->next_statechange))
173 msleep(5);
174 ohci->next_statechange = jiffies;
175
176 ep93xx_stop_hc(&pdev->dev);
177 hcd->state = HC_STATE_SUSPENDED;
178 pdev->dev.power.power_state = PMSG_SUSPEND;
179
180 return 0;
181}
182
183static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
184{
185 struct usb_hcd *hcd = platform_get_drvdata(pdev);
186 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
187 int status;
188
189 if (time_before(jiffies, ohci->next_statechange))
190 msleep(5);
191 ohci->next_statechange = jiffies;
192
193 ep93xx_start_hc(&pdev->dev);
194 pdev->dev.power.power_state = PMSG_ON;
195 usb_hcd_resume_root_hub(hcd);
196
197 return 0;
198}
199#endif
200
201
202static struct platform_driver ohci_hcd_ep93xx_driver = {
203 .probe = ohci_hcd_ep93xx_drv_probe,
204 .remove = ohci_hcd_ep93xx_drv_remove,
205#ifdef CONFIG_PM
206 .suspend = ohci_hcd_ep93xx_drv_suspend,
207 .resume = ohci_hcd_ep93xx_drv_resume,
208#endif
209 .driver = {
210 .name = "ep93xx-ohci",
211 },
212};
213
214static int __init ohci_hcd_ep93xx_init(void)
215{
216 return platform_driver_register(&ohci_hcd_ep93xx_driver);
217}
218
219static void __exit ohci_hcd_ep93xx_cleanup(void)
220{
221 platform_driver_unregister(&ohci_hcd_ep93xx_driver);
222}
223
224module_init(ohci_hcd_ep93xx_init);
225module_exit(ohci_hcd_ep93xx_cleanup);
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 8fb842ed5f6e..94d8cf4b36c1 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -901,6 +901,10 @@ MODULE_LICENSE ("GPL");
901#include "ohci-pxa27x.c" 901#include "ohci-pxa27x.c"
902#endif 902#endif
903 903
904#ifdef CONFIG_ARCH_EP93XX
905#include "ohci-ep93xx.c"
906#endif
907
904#ifdef CONFIG_SOC_AU1X00 908#ifdef CONFIG_SOC_AU1X00
905#include "ohci-au1xxx.c" 909#include "ohci-au1xxx.c"
906#endif 910#endif
@@ -909,7 +913,7 @@ MODULE_LICENSE ("GPL");
909#include "ohci-ppc-soc.c" 913#include "ohci-ppc-soc.c"
910#endif 914#endif
911 915
912#ifdef CONFIG_ARCH_AT91RM9200 916#if defined(CONFIG_ARCH_AT91RM9200) || defined(CONFIG_ARCH_AT91SAM9261)
913#include "ohci-at91.c" 917#include "ohci-at91.c"
914#endif 918#endif
915 919
@@ -919,9 +923,11 @@ MODULE_LICENSE ("GPL");
919 || defined(CONFIG_ARCH_OMAP) \ 923 || defined(CONFIG_ARCH_OMAP) \
920 || defined (CONFIG_ARCH_LH7A404) \ 924 || defined (CONFIG_ARCH_LH7A404) \
921 || defined (CONFIG_PXA27x) \ 925 || defined (CONFIG_PXA27x) \
926 || defined (CONFIG_ARCH_EP93XX) \
922 || defined (CONFIG_SOC_AU1X00) \ 927 || defined (CONFIG_SOC_AU1X00) \
923 || defined (CONFIG_USB_OHCI_HCD_PPC_SOC) \ 928 || defined (CONFIG_USB_OHCI_HCD_PPC_SOC) \
924 || defined (CONFIG_ARCH_AT91RM9200) \ 929 || defined (CONFIG_ARCH_AT91RM9200) \
930 || defined (CONFIG_ARCH_AT91SAM9261) \
925 ) 931 )
926#error "missing bus glue for ohci-hcd" 932#error "missing bus glue for ohci-hcd"
927#endif 933#endif
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 0bb972b58336..5b0a23fd798b 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -581,14 +581,14 @@ static int ohci_hub_control (
581 break; 581 break;
582 case GetHubStatus: 582 case GetHubStatus:
583 temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE); 583 temp = roothub_status (ohci) & ~(RH_HS_CRWE | RH_HS_DRWE);
584 *(__le32 *) buf = cpu_to_le32 (temp); 584 put_unaligned(cpu_to_le32 (temp), (__le32 *) buf);
585 break; 585 break;
586 case GetPortStatus: 586 case GetPortStatus:
587 if (!wIndex || wIndex > ports) 587 if (!wIndex || wIndex > ports)
588 goto error; 588 goto error;
589 wIndex--; 589 wIndex--;
590 temp = roothub_portstatus (ohci, wIndex); 590 temp = roothub_portstatus (ohci, wIndex);
591 *(__le32 *) buf = cpu_to_le32 (temp); 591 put_unaligned(cpu_to_le32 (temp), (__le32 *) buf);
592 592
593#ifndef OHCI_VERBOSE_DEBUG 593#ifndef OHCI_VERBOSE_DEBUG
594 if (*(u16*)(buf+2)) /* only if wPortChange is interesting */ 594 if (*(u16*)(buf+2)) /* only if wPortChange is interesting */
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index dff60568b4a1..20861650905e 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -167,8 +167,6 @@ static int __devinit mmio_resource_enabled(struct pci_dev *pdev, int idx)
167static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev) 167static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
168{ 168{
169 void __iomem *base; 169 void __iomem *base;
170 int wait_time;
171 u32 control;
172 170
173 if (!mmio_resource_enabled(pdev, 0)) 171 if (!mmio_resource_enabled(pdev, 0))
174 return; 172 return;
@@ -179,9 +177,10 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
179 177
180/* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */ 178/* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
181#ifndef __hppa__ 179#ifndef __hppa__
182 control = readl(base + OHCI_CONTROL); 180{
181 u32 control = readl(base + OHCI_CONTROL);
183 if (control & OHCI_CTRL_IR) { 182 if (control & OHCI_CTRL_IR) {
184 wait_time = 500; /* arbitrary; 5 seconds */ 183 int wait_time = 500; /* arbitrary; 5 seconds */
185 writel(OHCI_INTR_OC, base + OHCI_INTRENABLE); 184 writel(OHCI_INTR_OC, base + OHCI_INTRENABLE);
186 writel(OHCI_OCR, base + OHCI_CMDSTATUS); 185 writel(OHCI_OCR, base + OHCI_CMDSTATUS);
187 while (wait_time > 0 && 186 while (wait_time > 0 &&
@@ -198,6 +197,7 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
198 /* reset controller, preserving RWC */ 197 /* reset controller, preserving RWC */
199 writel(control & OHCI_CTRL_RWC, base + OHCI_CONTROL); 198 writel(control & OHCI_CTRL_RWC, base + OHCI_CONTROL);
200 } 199 }
200}
201#endif 201#endif
202 202
203 /* 203 /*
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index c9d72ac0a1d7..431e8f31f1a9 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -372,7 +372,7 @@ static void uhci_fixup_toggles(struct uhci_qh *qh, int skip_first)
372 * need to change any toggles in this URB */ 372 * need to change any toggles in this URB */
373 td = list_entry(urbp->td_list.next, struct uhci_td, list); 373 td = list_entry(urbp->td_list.next, struct uhci_td, list);
374 if (toggle > 1 || uhci_toggle(td_token(td)) == toggle) { 374 if (toggle > 1 || uhci_toggle(td_token(td)) == toggle) {
375 td = list_entry(urbp->td_list.next, struct uhci_td, 375 td = list_entry(urbp->td_list.prev, struct uhci_td,
376 list); 376 list);
377 toggle = uhci_toggle(td_token(td)) ^ 1; 377 toggle = uhci_toggle(td_token(td)) ^ 1;
378 378
@@ -943,7 +943,9 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb)
943 /* We received a short packet */ 943 /* We received a short packet */
944 if (urb->transfer_flags & URB_SHORT_NOT_OK) 944 if (urb->transfer_flags & URB_SHORT_NOT_OK)
945 ret = -EREMOTEIO; 945 ret = -EREMOTEIO;
946 else if (ctrlstat & TD_CTRL_SPD) 946
947 /* Fixup needed only if this isn't the URB's last TD */
948 else if (&td->list != urbp->td_list.prev)
947 ret = 1; 949 ret = 1;
948 } 950 }
949 951
@@ -1346,7 +1348,7 @@ static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh,
1346 } 1348 }
1347 1349
1348 uhci_giveback_urb(uhci, qh, urb, regs); 1350 uhci_giveback_urb(uhci, qh, urb, regs);
1349 if (status < 0) 1351 if (status < 0 && qh->type != USB_ENDPOINT_XFER_ISOC)
1350 break; 1352 break;
1351 } 1353 }
1352 1354
diff --git a/drivers/usb/input/appletouch.c b/drivers/usb/input/appletouch.c
index 9e3f13903371..044faa07e297 100644
--- a/drivers/usb/input/appletouch.c
+++ b/drivers/usb/input/appletouch.c
@@ -597,9 +597,9 @@ static void atp_disconnect(struct usb_interface *iface)
597 if (dev) { 597 if (dev) {
598 usb_kill_urb(dev->urb); 598 usb_kill_urb(dev->urb);
599 input_unregister_device(dev->input); 599 input_unregister_device(dev->input);
600 usb_free_urb(dev->urb);
601 usb_buffer_free(dev->udev, dev->datalen, 600 usb_buffer_free(dev->udev, dev->datalen,
602 dev->data, dev->urb->transfer_dma); 601 dev->data, dev->urb->transfer_dma);
602 usb_free_urb(dev->urb);
603 kfree(dev); 603 kfree(dev);
604 } 604 }
605 printk(KERN_INFO "input: appletouch disconnected\n"); 605 printk(KERN_INFO "input: appletouch disconnected\n");
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c
index 05d2d6012eb2..3719fcb04b8f 100644
--- a/drivers/usb/input/ati_remote.c
+++ b/drivers/usb/input/ati_remote.c
@@ -111,14 +111,28 @@
111#define NAME_BUFSIZE 80 /* size of product name, path buffers */ 111#define NAME_BUFSIZE 80 /* size of product name, path buffers */
112#define DATA_BUFSIZE 63 /* size of URB data buffers */ 112#define DATA_BUFSIZE 63 /* size of URB data buffers */
113 113
114/*
115 * Duplicate event filtering time.
116 * Sequential, identical KIND_FILTERED inputs with less than
117 * FILTER_TIME milliseconds between them are considered as repeat
118 * events. The hardware generates 5 events for the first keypress
119 * and we have to take this into account for an accurate repeat
120 * behaviour.
121 */
122#define FILTER_TIME 60 /* msec */
123
114static unsigned long channel_mask; 124static unsigned long channel_mask;
115module_param(channel_mask, ulong, 0444); 125module_param(channel_mask, ulong, 0644);
116MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore"); 126MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore");
117 127
118static int debug; 128static int debug;
119module_param(debug, int, 0444); 129module_param(debug, int, 0644);
120MODULE_PARM_DESC(debug, "Enable extra debug messages and information"); 130MODULE_PARM_DESC(debug, "Enable extra debug messages and information");
121 131
132static int repeat_filter = FILTER_TIME;
133module_param(repeat_filter, int, 0644);
134MODULE_PARM_DESC(repeat_filter, "Repeat filter time, default = 60 msec");
135
122#define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0) 136#define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0)
123#undef err 137#undef err
124#define err(format, arg...) printk(KERN_ERR format , ## arg) 138#define err(format, arg...) printk(KERN_ERR format , ## arg)
@@ -143,19 +157,6 @@ MODULE_DEVICE_TABLE(usb, ati_remote_table);
143static char init1[] = { 0x01, 0x00, 0x20, 0x14 }; 157static char init1[] = { 0x01, 0x00, 0x20, 0x14 };
144static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 }; 158static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 };
145 159
146/* Acceleration curve for directional control pad */
147static const char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
148
149/* Duplicate event filtering time.
150 * Sequential, identical KIND_FILTERED inputs with less than
151 * FILTER_TIME jiffies between them are considered as repeat
152 * events. The hardware generates 5 events for the first keypress
153 * and we have to take this into account for an accurate repeat
154 * behaviour.
155 * (HZ / 20) == 50 ms and works well for me.
156 */
157#define FILTER_TIME (HZ / 20)
158
159struct ati_remote { 160struct ati_remote {
160 struct input_dev *idev; 161 struct input_dev *idev;
161 struct usb_device *udev; 162 struct usb_device *udev;
@@ -413,6 +414,43 @@ static int ati_remote_event_lookup(int rem, unsigned char d1, unsigned char d2)
413} 414}
414 415
415/* 416/*
417 * ati_remote_compute_accel
418 *
419 * Implements acceleration curve for directional control pad
420 * If elapsed time since last event is > 1/4 second, user "stopped",
421 * so reset acceleration. Otherwise, user is probably holding the control
422 * pad down, so we increase acceleration, ramping up over two seconds to
423 * a maximum speed.
424 */
425static int ati_remote_compute_accel(struct ati_remote *ati_remote)
426{
427 static const char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
428 unsigned long now = jiffies;
429 int acc;
430
431 if (time_after(now, ati_remote->old_jiffies + msecs_to_jiffies(250))) {
432 acc = 1;
433 ati_remote->acc_jiffies = now;
434 }
435 else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(125)))
436 acc = accel[0];
437 else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(250)))
438 acc = accel[1];
439 else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(500)))
440 acc = accel[2];
441 else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(1000)))
442 acc = accel[3];
443 else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(1500)))
444 acc = accel[4];
445 else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(2000)))
446 acc = accel[5];
447 else
448 acc = accel[6];
449
450 return acc;
451}
452
453/*
416 * ati_remote_report_input 454 * ati_remote_report_input
417 */ 455 */
418static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs) 456static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
@@ -465,9 +503,9 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
465 503
466 if (ati_remote_tbl[index].kind == KIND_FILTERED) { 504 if (ati_remote_tbl[index].kind == KIND_FILTERED) {
467 /* Filter duplicate events which happen "too close" together. */ 505 /* Filter duplicate events which happen "too close" together. */
468 if ((ati_remote->old_data[0] == data[1]) && 506 if (ati_remote->old_data[0] == data[1] &&
469 (ati_remote->old_data[1] == data[2]) && 507 ati_remote->old_data[1] == data[2] &&
470 time_before(jiffies, ati_remote->old_jiffies + FILTER_TIME)) { 508 time_before(jiffies, ati_remote->old_jiffies + msecs_to_jiffies(repeat_filter))) {
471 ati_remote->repeat_count++; 509 ati_remote->repeat_count++;
472 } else { 510 } else {
473 ati_remote->repeat_count = 0; 511 ati_remote->repeat_count = 0;
@@ -477,75 +515,61 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
477 ati_remote->old_data[1] = data[2]; 515 ati_remote->old_data[1] = data[2];
478 ati_remote->old_jiffies = jiffies; 516 ati_remote->old_jiffies = jiffies;
479 517
480 if ((ati_remote->repeat_count > 0) 518 if (ati_remote->repeat_count > 0 &&
481 && (ati_remote->repeat_count < 5)) 519 ati_remote->repeat_count < 5)
482 return; 520 return;
483 521
484 522
485 input_regs(dev, regs); 523 input_regs(dev, regs);
486 input_event(dev, ati_remote_tbl[index].type, 524 input_event(dev, ati_remote_tbl[index].type,
487 ati_remote_tbl[index].code, 1); 525 ati_remote_tbl[index].code, 1);
526 input_sync(dev);
488 input_event(dev, ati_remote_tbl[index].type, 527 input_event(dev, ati_remote_tbl[index].type,
489 ati_remote_tbl[index].code, 0); 528 ati_remote_tbl[index].code, 0);
490 input_sync(dev); 529 input_sync(dev);
491 530
492 return; 531 } else {
493 }
494 532
495 /* 533 /*
496 * Other event kinds are from the directional control pad, and have an 534 * Other event kinds are from the directional control pad, and have an
497 * acceleration factor applied to them. Without this acceleration, the 535 * acceleration factor applied to them. Without this acceleration, the
498 * control pad is mostly unusable. 536 * control pad is mostly unusable.
499 * 537 */
500 * If elapsed time since last event is > 1/4 second, user "stopped", 538 acc = ati_remote_compute_accel(ati_remote);
501 * so reset acceleration. Otherwise, user is probably holding the control 539
502 * pad down, so we increase acceleration, ramping up over two seconds to 540 input_regs(dev, regs);
503 * a maximum speed. The acceleration curve is #defined above. 541 switch (ati_remote_tbl[index].kind) {
504 */ 542 case KIND_ACCEL:
505 if (time_after(jiffies, ati_remote->old_jiffies + (HZ >> 2))) { 543 input_event(dev, ati_remote_tbl[index].type,
506 acc = 1; 544 ati_remote_tbl[index].code,
507 ati_remote->acc_jiffies = jiffies; 545 ati_remote_tbl[index].value * acc);
508 } 546 break;
509 else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ >> 3))) acc = accel[0]; 547 case KIND_LU:
510 else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ >> 2))) acc = accel[1]; 548 input_report_rel(dev, REL_X, -acc);
511 else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ >> 1))) acc = accel[2]; 549 input_report_rel(dev, REL_Y, -acc);
512 else if (time_before(jiffies, ati_remote->acc_jiffies + HZ)) acc = accel[3]; 550 break;
513 else if (time_before(jiffies, ati_remote->acc_jiffies + HZ+(HZ>>1))) acc = accel[4]; 551 case KIND_RU:
514 else if (time_before(jiffies, ati_remote->acc_jiffies + (HZ << 1))) acc = accel[5]; 552 input_report_rel(dev, REL_X, acc);
515 else acc = accel[6]; 553 input_report_rel(dev, REL_Y, -acc);
516 554 break;
517 input_regs(dev, regs); 555 case KIND_LD:
518 switch (ati_remote_tbl[index].kind) { 556 input_report_rel(dev, REL_X, -acc);
519 case KIND_ACCEL: 557 input_report_rel(dev, REL_Y, acc);
520 input_event(dev, ati_remote_tbl[index].type, 558 break;
521 ati_remote_tbl[index].code, 559 case KIND_RD:
522 ati_remote_tbl[index].value * acc); 560 input_report_rel(dev, REL_X, acc);
523 break; 561 input_report_rel(dev, REL_Y, acc);
524 case KIND_LU: 562 break;
525 input_report_rel(dev, REL_X, -acc); 563 default:
526 input_report_rel(dev, REL_Y, -acc); 564 dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n",
527 break; 565 ati_remote_tbl[index].kind);
528 case KIND_RU: 566 }
529 input_report_rel(dev, REL_X, acc); 567 input_sync(dev);
530 input_report_rel(dev, REL_Y, -acc);
531 break;
532 case KIND_LD:
533 input_report_rel(dev, REL_X, -acc);
534 input_report_rel(dev, REL_Y, acc);
535 break;
536 case KIND_RD:
537 input_report_rel(dev, REL_X, acc);
538 input_report_rel(dev, REL_Y, acc);
539 break;
540 default:
541 dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n",
542 ati_remote_tbl[index].kind);
543 }
544 input_sync(dev);
545 568
546 ati_remote->old_jiffies = jiffies; 569 ati_remote->old_jiffies = jiffies;
547 ati_remote->old_data[0] = data[1]; 570 ati_remote->old_data[0] = data[1];
548 ati_remote->old_data[1] = data[2]; 571 ati_remote->old_data[1] = data[2];
572 }
549} 573}
550 574
551/* 575/*
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index b9fb9687f926..a2c56b2de589 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -1411,17 +1411,54 @@ void hid_init_reports(struct hid_device *hid)
1411 warn("timeout initializing reports"); 1411 warn("timeout initializing reports");
1412} 1412}
1413 1413
1414#define USB_VENDOR_ID_GTCO 0x078c
1415#define USB_DEVICE_ID_GTCO_90 0x0090
1416#define USB_DEVICE_ID_GTCO_100 0x0100
1417#define USB_DEVICE_ID_GTCO_101 0x0101
1418#define USB_DEVICE_ID_GTCO_103 0x0103
1419#define USB_DEVICE_ID_GTCO_104 0x0104
1420#define USB_DEVICE_ID_GTCO_105 0x0105
1421#define USB_DEVICE_ID_GTCO_106 0x0106
1422#define USB_DEVICE_ID_GTCO_107 0x0107
1423#define USB_DEVICE_ID_GTCO_108 0x0108
1424#define USB_DEVICE_ID_GTCO_200 0x0200
1425#define USB_DEVICE_ID_GTCO_201 0x0201
1426#define USB_DEVICE_ID_GTCO_202 0x0202
1427#define USB_DEVICE_ID_GTCO_203 0x0203
1428#define USB_DEVICE_ID_GTCO_204 0x0204
1429#define USB_DEVICE_ID_GTCO_205 0x0205
1430#define USB_DEVICE_ID_GTCO_206 0x0206
1431#define USB_DEVICE_ID_GTCO_207 0x0207
1432#define USB_DEVICE_ID_GTCO_300 0x0300
1433#define USB_DEVICE_ID_GTCO_301 0x0301
1434#define USB_DEVICE_ID_GTCO_302 0x0302
1435#define USB_DEVICE_ID_GTCO_303 0x0303
1436#define USB_DEVICE_ID_GTCO_304 0x0304
1437#define USB_DEVICE_ID_GTCO_305 0x0305
1438#define USB_DEVICE_ID_GTCO_306 0x0306
1439#define USB_DEVICE_ID_GTCO_307 0x0307
1440#define USB_DEVICE_ID_GTCO_308 0x0308
1441#define USB_DEVICE_ID_GTCO_309 0x0309
1442#define USB_DEVICE_ID_GTCO_400 0x0400
1443#define USB_DEVICE_ID_GTCO_401 0x0401
1444#define USB_DEVICE_ID_GTCO_402 0x0402
1445#define USB_DEVICE_ID_GTCO_403 0x0403
1446#define USB_DEVICE_ID_GTCO_404 0x0404
1447#define USB_DEVICE_ID_GTCO_405 0x0405
1448#define USB_DEVICE_ID_GTCO_500 0x0500
1449#define USB_DEVICE_ID_GTCO_501 0x0501
1450#define USB_DEVICE_ID_GTCO_502 0x0502
1451#define USB_DEVICE_ID_GTCO_503 0x0503
1452#define USB_DEVICE_ID_GTCO_504 0x0504
1453#define USB_DEVICE_ID_GTCO_1000 0x1000
1454#define USB_DEVICE_ID_GTCO_1001 0x1001
1455#define USB_DEVICE_ID_GTCO_1002 0x1002
1456#define USB_DEVICE_ID_GTCO_1003 0x1003
1457#define USB_DEVICE_ID_GTCO_1004 0x1004
1458#define USB_DEVICE_ID_GTCO_1005 0x1005
1459#define USB_DEVICE_ID_GTCO_1006 0x1006
1460
1414#define USB_VENDOR_ID_WACOM 0x056a 1461#define USB_VENDOR_ID_WACOM 0x056a
1415#define USB_DEVICE_ID_WACOM_PENPARTNER 0x0000
1416#define USB_DEVICE_ID_WACOM_GRAPHIRE 0x0010
1417#define USB_DEVICE_ID_WACOM_INTUOS 0x0020
1418#define USB_DEVICE_ID_WACOM_PL 0x0030
1419#define USB_DEVICE_ID_WACOM_INTUOS2 0x0040
1420#define USB_DEVICE_ID_WACOM_VOLITO 0x0060
1421#define USB_DEVICE_ID_WACOM_PTU 0x0003
1422#define USB_DEVICE_ID_WACOM_INTUOS3 0x00B0
1423#define USB_DEVICE_ID_WACOM_CINTIQ 0x003F
1424#define USB_DEVICE_ID_WACOM_DTF 0x00C0
1425 1462
1426#define USB_VENDOR_ID_ACECAD 0x0460 1463#define USB_VENDOR_ID_ACECAD 0x0460
1427#define USB_DEVICE_ID_ACECAD_FLAIR 0x0004 1464#define USB_DEVICE_ID_ACECAD_FLAIR 0x0004
@@ -1507,6 +1544,9 @@ void hid_init_reports(struct hid_device *hid)
1507#define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104 1544#define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104
1508#define USB_DEVICE_ID_DUAL_USB_JOYPAD 0x8866 1545#define USB_DEVICE_ID_DUAL_USB_JOYPAD 0x8866
1509 1546
1547#define USB_VENDOR_ID_WISEGROUP_LTD 0x6677
1548#define USB_DEVICE_ID_SMARTJOY_DUAL_PLUS 0x8802
1549
1510#define USB_VENDOR_ID_CODEMERCS 0x07c0 1550#define USB_VENDOR_ID_CODEMERCS 0x07c0
1511#define USB_DEVICE_ID_CODEMERCS_IOW40 0x1500 1551#define USB_DEVICE_ID_CODEMERCS_IOW40 0x1500
1512#define USB_DEVICE_ID_CODEMERCS_IOW24 0x1501 1552#define USB_DEVICE_ID_CODEMERCS_IOW24 0x1501
@@ -1585,6 +1625,51 @@ static const struct hid_blacklist {
1585 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT, HID_QUIRK_IGNORE }, 1625 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT, HID_QUIRK_IGNORE },
1586 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE }, 1626 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE },
1587 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE }, 1627 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE },
1628 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90, HID_QUIRK_IGNORE },
1629 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100, HID_QUIRK_IGNORE },
1630 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101, HID_QUIRK_IGNORE },
1631 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103, HID_QUIRK_IGNORE },
1632 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104, HID_QUIRK_IGNORE },
1633 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105, HID_QUIRK_IGNORE },
1634 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106, HID_QUIRK_IGNORE },
1635 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107, HID_QUIRK_IGNORE },
1636 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108, HID_QUIRK_IGNORE },
1637 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200, HID_QUIRK_IGNORE },
1638 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201, HID_QUIRK_IGNORE },
1639 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202, HID_QUIRK_IGNORE },
1640 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203, HID_QUIRK_IGNORE },
1641 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204, HID_QUIRK_IGNORE },
1642 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205, HID_QUIRK_IGNORE },
1643 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206, HID_QUIRK_IGNORE },
1644 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207, HID_QUIRK_IGNORE },
1645 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300, HID_QUIRK_IGNORE },
1646 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301, HID_QUIRK_IGNORE },
1647 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302, HID_QUIRK_IGNORE },
1648 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303, HID_QUIRK_IGNORE },
1649 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304, HID_QUIRK_IGNORE },
1650 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305, HID_QUIRK_IGNORE },
1651 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306, HID_QUIRK_IGNORE },
1652 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307, HID_QUIRK_IGNORE },
1653 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308, HID_QUIRK_IGNORE },
1654 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309, HID_QUIRK_IGNORE },
1655 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400, HID_QUIRK_IGNORE },
1656 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401, HID_QUIRK_IGNORE },
1657 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402, HID_QUIRK_IGNORE },
1658 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403, HID_QUIRK_IGNORE },
1659 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404, HID_QUIRK_IGNORE },
1660 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405, HID_QUIRK_IGNORE },
1661 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500, HID_QUIRK_IGNORE },
1662 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501, HID_QUIRK_IGNORE },
1663 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502, HID_QUIRK_IGNORE },
1664 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503, HID_QUIRK_IGNORE },
1665 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504, HID_QUIRK_IGNORE },
1666 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000, HID_QUIRK_IGNORE },
1667 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001, HID_QUIRK_IGNORE },
1668 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002, HID_QUIRK_IGNORE },
1669 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003, HID_QUIRK_IGNORE },
1670 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE },
1671 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE },
1672 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE },
1588 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE }, 1673 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE },
1589 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE }, 1674 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE },
1590 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE }, 1675 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE },
@@ -1614,49 +1699,6 @@ static const struct hid_blacklist {
1614 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP, HID_QUIRK_IGNORE }, 1699 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP, HID_QUIRK_IGNORE },
1615 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP, HID_QUIRK_IGNORE }, 1700 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP, HID_QUIRK_IGNORE },
1616 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS, HID_QUIRK_IGNORE }, 1701 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS, HID_QUIRK_IGNORE },
1617 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PENPARTNER, HID_QUIRK_IGNORE },
1618 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE, HID_QUIRK_IGNORE },
1619 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE + 1, HID_QUIRK_IGNORE },
1620 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE + 2, HID_QUIRK_IGNORE },
1621 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE + 3, HID_QUIRK_IGNORE },
1622 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE + 4, HID_QUIRK_IGNORE },
1623 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS, HID_QUIRK_IGNORE },
1624 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS + 1, HID_QUIRK_IGNORE },
1625 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS + 2, HID_QUIRK_IGNORE },
1626 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS + 3, HID_QUIRK_IGNORE },
1627 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS + 4, HID_QUIRK_IGNORE },
1628 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PL, HID_QUIRK_IGNORE },
1629 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PL + 1, HID_QUIRK_IGNORE },
1630 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PL + 2, HID_QUIRK_IGNORE },
1631 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PL + 3, HID_QUIRK_IGNORE },
1632 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PL + 4, HID_QUIRK_IGNORE },
1633 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PL + 5, HID_QUIRK_IGNORE },
1634 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PL + 7, HID_QUIRK_IGNORE },
1635 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PL + 8, HID_QUIRK_IGNORE },
1636 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PL + 9, HID_QUIRK_IGNORE },
1637 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS2 + 1, HID_QUIRK_IGNORE },
1638 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS2 + 2, HID_QUIRK_IGNORE },
1639 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS2 + 3, HID_QUIRK_IGNORE },
1640 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS2 + 4, HID_QUIRK_IGNORE },
1641 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS2 + 5, HID_QUIRK_IGNORE },
1642 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS2 + 7, HID_QUIRK_IGNORE },
1643 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_VOLITO, HID_QUIRK_IGNORE },
1644 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_VOLITO + 1, HID_QUIRK_IGNORE },
1645 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_VOLITO + 2, HID_QUIRK_IGNORE },
1646 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_VOLITO + 3, HID_QUIRK_IGNORE },
1647 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_VOLITO + 4, HID_QUIRK_IGNORE },
1648 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE + 5, HID_QUIRK_IGNORE },
1649 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE + 6, HID_QUIRK_IGNORE },
1650 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PTU, HID_QUIRK_IGNORE },
1651 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3, HID_QUIRK_IGNORE },
1652 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 1, HID_QUIRK_IGNORE },
1653 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 2, HID_QUIRK_IGNORE },
1654 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 3, HID_QUIRK_IGNORE },
1655 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 4, HID_QUIRK_IGNORE },
1656 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 5, HID_QUIRK_IGNORE },
1657 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_CINTIQ, HID_QUIRK_IGNORE },
1658 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_DTF, HID_QUIRK_IGNORE },
1659 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_DTF + 3, HID_QUIRK_IGNORE },
1660 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, 1702 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1661 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, 1703 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1662 { USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K, HID_QUIRK_IGNORE }, 1704 { USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K, HID_QUIRK_IGNORE },
@@ -1670,6 +1712,7 @@ static const struct hid_blacklist {
1670 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET }, 1712 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET },
1671 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, 1713 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
1672 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 1714 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
1715 { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
1673 1716
1674 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE, HID_QUIRK_MIGHTYMOUSE | HID_QUIRK_INVERT_HWHEEL }, 1717 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE, HID_QUIRK_MIGHTYMOUSE | HID_QUIRK_INVERT_HWHEEL },
1675 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 }, 1718 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 },
@@ -1774,6 +1817,10 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1774 char *rdesc; 1817 char *rdesc;
1775 int n, len, insize = 0; 1818 int n, len, insize = 0;
1776 1819
1820 /* Ignore all Wacom devices */
1821 if (dev->descriptor.idVendor == USB_VENDOR_ID_WACOM)
1822 return NULL;
1823
1777 for (n = 0; hid_blacklist[n].idVendor; n++) 1824 for (n = 0; hid_blacklist[n].idVendor; n++)
1778 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) && 1825 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) &&
1779 (hid_blacklist[n].idProduct == le16_to_cpu(dev->descriptor.idProduct))) 1826 (hid_blacklist[n].idProduct == le16_to_cpu(dev->descriptor.idProduct)))
diff --git a/drivers/usb/input/hid-input.c b/drivers/usb/input/hid-input.c
index 028e1ad89f5d..7208839f2dbf 100644
--- a/drivers/usb/input/hid-input.c
+++ b/drivers/usb/input/hid-input.c
@@ -607,7 +607,8 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
607 607
608 } 608 }
609 609
610 if (usage->hat_min < usage->hat_max || usage->hat_dir) { 610 if (usage->type == EV_ABS &&
611 (usage->hat_min < usage->hat_max || usage->hat_dir)) {
611 int i; 612 int i;
612 for (i = usage->code; i < usage->code + 2 && i <= max; i++) { 613 for (i = usage->code; i < usage->code + 2 && i <= max; i++) {
613 input_set_abs_params(input, i, -1, 1, 0, 0); 614 input_set_abs_params(input, i, -1, 1, 0, 0);
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
index 70477f02cc29..f6b839c257a7 100644
--- a/drivers/usb/input/hiddev.c
+++ b/drivers/usb/input/hiddev.c
@@ -49,7 +49,7 @@ struct hiddev {
49 int open; 49 int open;
50 wait_queue_head_t wait; 50 wait_queue_head_t wait;
51 struct hid_device *hid; 51 struct hid_device *hid;
52 struct hiddev_list *list; 52 struct list_head list;
53}; 53};
54 54
55struct hiddev_list { 55struct hiddev_list {
@@ -59,7 +59,7 @@ struct hiddev_list {
59 unsigned flags; 59 unsigned flags;
60 struct fasync_struct *fasync; 60 struct fasync_struct *fasync;
61 struct hiddev *hiddev; 61 struct hiddev *hiddev;
62 struct hiddev_list *next; 62 struct list_head node;
63}; 63};
64 64
65static struct hiddev *hiddev_table[HIDDEV_MINORS]; 65static struct hiddev *hiddev_table[HIDDEV_MINORS];
@@ -73,12 +73,15 @@ static struct hiddev *hiddev_table[HIDDEV_MINORS];
73static struct hid_report * 73static struct hid_report *
74hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo) 74hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo)
75{ 75{
76 unsigned flags = rinfo->report_id & ~HID_REPORT_ID_MASK; 76 unsigned int flags = rinfo->report_id & ~HID_REPORT_ID_MASK;
77 unsigned int rid = rinfo->report_id & HID_REPORT_ID_MASK;
77 struct hid_report_enum *report_enum; 78 struct hid_report_enum *report_enum;
79 struct hid_report *report;
78 struct list_head *list; 80 struct list_head *list;
79 81
80 if (rinfo->report_type < HID_REPORT_TYPE_MIN || 82 if (rinfo->report_type < HID_REPORT_TYPE_MIN ||
81 rinfo->report_type > HID_REPORT_TYPE_MAX) return NULL; 83 rinfo->report_type > HID_REPORT_TYPE_MAX)
84 return NULL;
82 85
83 report_enum = hid->report_enum + 86 report_enum = hid->report_enum +
84 (rinfo->report_type - HID_REPORT_TYPE_MIN); 87 (rinfo->report_type - HID_REPORT_TYPE_MIN);
@@ -88,21 +91,25 @@ hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo)
88 break; 91 break;
89 92
90 case HID_REPORT_ID_FIRST: 93 case HID_REPORT_ID_FIRST:
91 list = report_enum->report_list.next; 94 if (list_empty(&report_enum->report_list))
92 if (list == &report_enum->report_list)
93 return NULL; 95 return NULL;
94 rinfo->report_id = ((struct hid_report *) list)->id; 96
97 list = report_enum->report_list.next;
98 report = list_entry(list, struct hid_report, list);
99 rinfo->report_id = report->id;
95 break; 100 break;
96 101
97 case HID_REPORT_ID_NEXT: 102 case HID_REPORT_ID_NEXT:
98 list = (struct list_head *) 103 report = report_enum->report_id_hash[rid];
99 report_enum->report_id_hash[rinfo->report_id & HID_REPORT_ID_MASK]; 104 if (!report)
100 if (list == NULL)
101 return NULL; 105 return NULL;
102 list = list->next; 106
107 list = report->list.next;
103 if (list == &report_enum->report_list) 108 if (list == &report_enum->report_list)
104 return NULL; 109 return NULL;
105 rinfo->report_id = ((struct hid_report *) list)->id; 110
111 report = list_entry(list, struct hid_report, list);
112 rinfo->report_id = report->id;
106 break; 113 break;
107 114
108 default: 115 default:
@@ -125,12 +132,13 @@ hiddev_lookup_usage(struct hid_device *hid, struct hiddev_usage_ref *uref)
125 struct hid_field *field; 132 struct hid_field *field;
126 133
127 if (uref->report_type < HID_REPORT_TYPE_MIN || 134 if (uref->report_type < HID_REPORT_TYPE_MIN ||
128 uref->report_type > HID_REPORT_TYPE_MAX) return NULL; 135 uref->report_type > HID_REPORT_TYPE_MAX)
136 return NULL;
129 137
130 report_enum = hid->report_enum + 138 report_enum = hid->report_enum +
131 (uref->report_type - HID_REPORT_TYPE_MIN); 139 (uref->report_type - HID_REPORT_TYPE_MIN);
132 140
133 list_for_each_entry(report, &report_enum->report_list, list) 141 list_for_each_entry(report, &report_enum->report_list, list) {
134 for (i = 0; i < report->maxfield; i++) { 142 for (i = 0; i < report->maxfield; i++) {
135 field = report->field[i]; 143 field = report->field[i];
136 for (j = 0; j < field->maxusage; j++) { 144 for (j = 0; j < field->maxusage; j++) {
@@ -142,6 +150,7 @@ hiddev_lookup_usage(struct hid_device *hid, struct hiddev_usage_ref *uref)
142 } 150 }
143 } 151 }
144 } 152 }
153 }
145 154
146 return NULL; 155 return NULL;
147} 156}
@@ -150,9 +159,9 @@ static void hiddev_send_event(struct hid_device *hid,
150 struct hiddev_usage_ref *uref) 159 struct hiddev_usage_ref *uref)
151{ 160{
152 struct hiddev *hiddev = hid->hiddev; 161 struct hiddev *hiddev = hid->hiddev;
153 struct hiddev_list *list = hiddev->list; 162 struct hiddev_list *list;
154 163
155 while (list) { 164 list_for_each_entry(list, &hiddev->list, node) {
156 if (uref->field_index != HID_FIELD_INDEX_NONE || 165 if (uref->field_index != HID_FIELD_INDEX_NONE ||
157 (list->flags & HIDDEV_FLAG_REPORT) != 0) { 166 (list->flags & HIDDEV_FLAG_REPORT) != 0) {
158 list->buffer[list->head] = *uref; 167 list->buffer[list->head] = *uref;
@@ -160,8 +169,6 @@ static void hiddev_send_event(struct hid_device *hid,
160 (HIDDEV_BUFFER_SIZE - 1); 169 (HIDDEV_BUFFER_SIZE - 1);
161 kill_fasync(&list->fasync, SIGIO, POLL_IN); 170 kill_fasync(&list->fasync, SIGIO, POLL_IN);
162 } 171 }
163
164 list = list->next;
165 } 172 }
166 173
167 wake_up_interruptible(&hiddev->wait); 174 wake_up_interruptible(&hiddev->wait);
@@ -180,7 +187,7 @@ void hiddev_hid_event(struct hid_device *hid, struct hid_field *field,
180 uref.report_type = 187 uref.report_type =
181 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : 188 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT :
182 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : 189 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT :
183 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE:0)); 190 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE : 0));
184 uref.report_id = field->report->id; 191 uref.report_id = field->report->id;
185 uref.field_index = field->index; 192 uref.field_index = field->index;
186 uref.usage_index = (usage - field->usage); 193 uref.usage_index = (usage - field->usage);
@@ -200,7 +207,7 @@ void hiddev_report_event(struct hid_device *hid, struct hid_report *report)
200 uref.report_type = 207 uref.report_type =
201 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : 208 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT :
202 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : 209 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT :
203 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE:0)); 210 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE : 0));
204 uref.report_id = report->id; 211 uref.report_id = report->id;
205 uref.field_index = HID_FIELD_INDEX_NONE; 212 uref.field_index = HID_FIELD_INDEX_NONE;
206 213
@@ -213,7 +220,9 @@ static int hiddev_fasync(int fd, struct file *file, int on)
213{ 220{
214 int retval; 221 int retval;
215 struct hiddev_list *list = file->private_data; 222 struct hiddev_list *list = file->private_data;
223
216 retval = fasync_helper(fd, file, on, &list->fasync); 224 retval = fasync_helper(fd, file, on, &list->fasync);
225
217 return retval < 0 ? retval : 0; 226 return retval < 0 ? retval : 0;
218} 227}
219 228
@@ -224,14 +233,9 @@ static int hiddev_fasync(int fd, struct file *file, int on)
224static int hiddev_release(struct inode * inode, struct file * file) 233static int hiddev_release(struct inode * inode, struct file * file)
225{ 234{
226 struct hiddev_list *list = file->private_data; 235 struct hiddev_list *list = file->private_data;
227 struct hiddev_list **listptr;
228 236
229 listptr = &list->hiddev->list;
230 hiddev_fasync(-1, file, 0); 237 hiddev_fasync(-1, file, 0);
231 238 list_del(&list->node);
232 while (*listptr && (*listptr != list))
233 listptr = &((*listptr)->next);
234 *listptr = (*listptr)->next;
235 239
236 if (!--list->hiddev->open) { 240 if (!--list->hiddev->open) {
237 if (list->hiddev->exist) 241 if (list->hiddev->exist)
@@ -248,7 +252,8 @@ static int hiddev_release(struct inode * inode, struct file * file)
248/* 252/*
249 * open file op 253 * open file op
250 */ 254 */
251static int hiddev_open(struct inode * inode, struct file * file) { 255static int hiddev_open(struct inode *inode, struct file *file)
256{
252 struct hiddev_list *list; 257 struct hiddev_list *list;
253 258
254 int i = iminor(inode) - HIDDEV_MINOR_BASE; 259 int i = iminor(inode) - HIDDEV_MINOR_BASE;
@@ -260,9 +265,7 @@ static int hiddev_open(struct inode * inode, struct file * file) {
260 return -ENOMEM; 265 return -ENOMEM;
261 266
262 list->hiddev = hiddev_table[i]; 267 list->hiddev = hiddev_table[i];
263 list->next = hiddev_table[i]->list; 268 list_add_tail(&list->node, &hiddev_table[i]->list);
264 hiddev_table[i]->list = list;
265
266 file->private_data = list; 269 file->private_data = list;
267 270
268 if (!list->hiddev->open++) 271 if (!list->hiddev->open++)
@@ -362,6 +365,7 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
362static unsigned int hiddev_poll(struct file *file, poll_table *wait) 365static unsigned int hiddev_poll(struct file *file, poll_table *wait)
363{ 366{
364 struct hiddev_list *list = file->private_data; 367 struct hiddev_list *list = file->private_data;
368
365 poll_wait(file, &list->hiddev->wait, wait); 369 poll_wait(file, &list->hiddev->wait, wait);
366 if (list->head != list->tail) 370 if (list->head != list->tail)
367 return POLLIN | POLLRDNORM; 371 return POLLIN | POLLRDNORM;
@@ -382,7 +386,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
382 struct hiddev_collection_info cinfo; 386 struct hiddev_collection_info cinfo;
383 struct hiddev_report_info rinfo; 387 struct hiddev_report_info rinfo;
384 struct hiddev_field_info finfo; 388 struct hiddev_field_info finfo;
385 struct hiddev_usage_ref_multi *uref_multi=NULL; 389 struct hiddev_usage_ref_multi *uref_multi = NULL;
386 struct hiddev_usage_ref *uref; 390 struct hiddev_usage_ref *uref;
387 struct hiddev_devinfo dinfo; 391 struct hiddev_devinfo dinfo;
388 struct hid_report *report; 392 struct hid_report *report;
@@ -764,15 +768,15 @@ int hiddev_connect(struct hid_device *hid)
764 } 768 }
765 769
766 init_waitqueue_head(&hiddev->wait); 770 init_waitqueue_head(&hiddev->wait);
767 771 INIT_LIST_HEAD(&hiddev->list);
768 hiddev_table[hid->intf->minor - HIDDEV_MINOR_BASE] = hiddev;
769
770 hiddev->hid = hid; 772 hiddev->hid = hid;
771 hiddev->exist = 1; 773 hiddev->exist = 1;
772 774
773 hid->minor = hid->intf->minor; 775 hid->minor = hid->intf->minor;
774 hid->hiddev = hiddev; 776 hid->hiddev = hiddev;
775 777
778 hiddev_table[hid->intf->minor - HIDDEV_MINOR_BASE] = hiddev;
779
776 return 0; 780 return 0;
777} 781}
778 782
diff --git a/drivers/usb/input/usbtouchscreen.c b/drivers/usb/input/usbtouchscreen.c
index 3b175aa482cd..a338bf4c2d78 100644
--- a/drivers/usb/input/usbtouchscreen.c
+++ b/drivers/usb/input/usbtouchscreen.c
@@ -286,7 +286,7 @@ static int mtouch_init(struct usbtouch_usb *usbtouch)
286static int itm_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 286static int itm_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
287{ 287{
288 *x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F); 288 *x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
289 *x = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F); 289 *y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
290 *press = ((pkt[2] & 0x1F) << 7) | (pkt[5] & 0x7F); 290 *press = ((pkt[2] & 0x1F) << 7) | (pkt[5] & 0x7F);
291 *touch = ~pkt[7] & 0x20; 291 *touch = ~pkt[7] & 0x20;
292 292
diff --git a/drivers/usb/input/yealink.c b/drivers/usb/input/yealink.c
index 575a4e672e96..7b45fd3de911 100644
--- a/drivers/usb/input/yealink.c
+++ b/drivers/usb/input/yealink.c
@@ -810,12 +810,9 @@ static int usb_cleanup(struct yealink_dev *yld, int err)
810 if (yld == NULL) 810 if (yld == NULL)
811 return err; 811 return err;
812 812
813 if (yld->urb_irq) { 813 usb_kill_urb(yld->urb_irq); /* parameter validation in core/urb */
814 usb_kill_urb(yld->urb_irq); 814 usb_kill_urb(yld->urb_ctl); /* parameter validation in core/urb */
815 usb_free_urb(yld->urb_irq); 815
816 }
817 if (yld->urb_ctl)
818 usb_free_urb(yld->urb_ctl);
819 if (yld->idev) { 816 if (yld->idev) {
820 if (err) 817 if (err)
821 input_free_device(yld->idev); 818 input_free_device(yld->idev);
@@ -831,6 +828,9 @@ static int usb_cleanup(struct yealink_dev *yld, int err)
831 if (yld->irq_data) 828 if (yld->irq_data)
832 usb_buffer_free(yld->udev, USB_PKT_LEN, 829 usb_buffer_free(yld->udev, USB_PKT_LEN,
833 yld->irq_data, yld->irq_dma); 830 yld->irq_data, yld->irq_dma);
831
832 usb_free_urb(yld->urb_irq); /* parameter validation in core/urb */
833 usb_free_urb(yld->urb_ctl); /* parameter validation in core/urb */
834 kfree(yld); 834 kfree(yld);
835 return err; 835 return err;
836} 836}
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index daa486dde8cf..88928a4be805 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -88,19 +88,19 @@ config USB_LED
88 To compile this driver as a module, choose M here: the 88 To compile this driver as a module, choose M here: the
89 module will be called usbled. 89 module will be called usbled.
90 90
91config USB_CY7C63 91config USB_CYPRESS_CY7C63
92 tristate "Cypress CY7C63xxx USB driver support" 92 tristate "Cypress CY7C63xxx USB driver support"
93 depends on USB 93 depends on USB
94 help 94 help
95 Say Y here if you want to connect a Cypress CY7C63xxx 95 Say Y here if you want to connect a Cypress CY7C63xxx
96 micro controller to your computer's USB port. This driver 96 micro controller to your computer's USB port. Currently this
97 supports the pre-programmed devices (incl. firmware) by 97 driver supports the pre-programmed devices (incl. firmware)
98 AK Modul-Bus Computer GmbH. 98 by AK Modul-Bus Computer GmbH.
99 99
100 Please see: http://www.ak-modul-bus.de/stat/mikrocontroller.html 100 Please see: http://www.ak-modul-bus.de/stat/mikrocontroller.html
101 101
102 To compile this driver as a module, choose M here: the 102 To compile this driver as a module, choose M here: the
103 module will be called cy7c63. 103 module will be called cypress_cy7c63.
104 104
105config USB_CYTHERM 105config USB_CYTHERM
106 tristate "Cypress USB thermometer driver support" 106 tristate "Cypress USB thermometer driver support"
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index f25a97227297..2927260c5812 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -4,7 +4,7 @@
4# 4#
5 5
6obj-$(CONFIG_USB_AUERSWALD) += auerswald.o 6obj-$(CONFIG_USB_AUERSWALD) += auerswald.o
7obj-$(CONFIG_USB_CY7C63) += cy7c63.o 7obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o
8obj-$(CONFIG_USB_CYTHERM) += cytherm.o 8obj-$(CONFIG_USB_CYTHERM) += cytherm.o
9obj-$(CONFIG_USB_EMI26) += emi26.o 9obj-$(CONFIG_USB_EMI26) += emi26.o
10obj-$(CONFIG_USB_EMI62) += emi62.o 10obj-$(CONFIG_USB_EMI62) += emi62.o
diff --git a/drivers/usb/misc/cy7c63.c b/drivers/usb/misc/cy7c63.c
deleted file mode 100644
index 8a1c10b89b76..000000000000
--- a/drivers/usb/misc/cy7c63.c
+++ /dev/null
@@ -1,244 +0,0 @@
1/*
2* cy7c63.c
3*
4* Copyright (c) 2006 Oliver Bock (bock@fh-wolfenbuettel.de)
5*
6* This driver is based on the Cypress Thermometer USB Driver by
7* Marcus Maul and the 2.0 version of Greg Kroah-Hartman's
8* USB Skeleton driver.
9*
10* Is is a generic driver for the Cypress CY7C63000 family.
11* For the time being it enables you to toggle the single I/O ports
12* of the device.
13*
14* Supported vendors: AK Modul-Bus Computer GmbH
15* Supported devices: CY7C63001A-PC (to be continued...)
16* Supported functions: Read/Write Ports (to be continued...)
17*
18* Chipsets families: CY7C63000, CY7C63001, CY7C63100, CY7C63101
19*
20*
21* This program is free software; you can redistribute it and/or
22* modify it under the terms of the GNU General Public License as
23* published by the Free Software Foundation, version 2.
24*/
25
26#include <linux/init.h>
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/usb.h>
30
31#define DRIVER_AUTHOR "Oliver Bock (bock@fh-wolfenbuettel.de)"
32#define DRIVER_DESC "Cypress CY7C63xxx USB driver"
33
34#define CY7C63_VENDOR_ID 0xa2c
35#define CY7C63_PRODUCT_ID 0x8
36
37#define CY7C63_READ_PORT 0x4
38#define CY7C63_WRITE_PORT 0x5
39#define CY7C63_READ_RAM 0x2
40#define CY7C63_WRITE_RAM 0x3
41#define CY7C63_READ_ROM 0x1
42
43#define CY7C63_READ_PORT_ID0 0
44#define CY7C63_WRITE_PORT_ID0 0
45#define CY7C63_READ_PORT_ID1 0x2
46#define CY7C63_WRITE_PORT_ID1 1
47
48#define CY7C63_MAX_REQSIZE 8
49
50
51/* table of devices that work with this driver */
52static struct usb_device_id cy7c63_table [] = {
53 { USB_DEVICE(CY7C63_VENDOR_ID, CY7C63_PRODUCT_ID) },
54 { }
55};
56MODULE_DEVICE_TABLE(usb, cy7c63_table);
57
58/* structure to hold all of our device specific stuff */
59struct cy7c63 {
60 struct usb_device * udev;
61 char port0;
62 char port1;
63};
64
65/* used to send usb control messages to device */
66int vendor_command(struct cy7c63 *dev, unsigned char request,
67 unsigned char address, unsigned char data) {
68
69 int retval = 0;
70 unsigned int pipe;
71 unsigned char *iobuf;
72
73 /* allocate some memory for the i/o buffer*/
74 iobuf = kzalloc(CY7C63_MAX_REQSIZE, GFP_KERNEL);
75 if (!iobuf) {
76 dev_err(&dev->udev->dev, "Out of memory!\n");
77 retval = -ENOMEM;
78 goto error;
79 }
80
81 dev_dbg(&dev->udev->dev, "Sending usb_control_msg (data: %d)\n", data);
82
83 /* prepare usb control message and send it upstream */
84 pipe = usb_rcvctrlpipe(dev->udev, 0);
85 retval = usb_control_msg(dev->udev, pipe, request,
86 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
87 address, data, iobuf, CY7C63_MAX_REQSIZE,
88 USB_CTRL_GET_TIMEOUT);
89
90 /* store returned data (more READs to be added!) */
91 switch (request) {
92 case CY7C63_READ_PORT:
93 if (address == CY7C63_READ_PORT_ID0) {
94 dev->port0 = iobuf[1];
95 dev_dbg(&dev->udev->dev,
96 "READ_PORT0 returned: %d\n",dev->port0);
97 }
98 else if (address == CY7C63_READ_PORT_ID1) {
99 dev->port1 = iobuf[1];
100 dev_dbg(&dev->udev->dev,
101 "READ_PORT1 returned: %d\n",dev->port1);
102 }
103 break;
104 }
105
106 kfree(iobuf);
107error:
108 return retval;
109}
110
111#define get_set_port(num,read_id,write_id) \
112static ssize_t set_port##num(struct device *dev, struct device_attribute *attr, \
113 const char *buf, size_t count) { \
114 \
115 int value; \
116 int result = 0; \
117 \
118 struct usb_interface *intf = to_usb_interface(dev); \
119 struct cy7c63 *cyp = usb_get_intfdata(intf); \
120 \
121 dev_dbg(&cyp->udev->dev, "WRITE_PORT%d called\n", num); \
122 \
123 /* validate input data */ \
124 if (sscanf(buf, "%d", &value) < 1) { \
125 result = -EINVAL; \
126 goto error; \
127 } \
128 if (value>255 || value<0) { \
129 result = -EINVAL; \
130 goto error; \
131 } \
132 \
133 result = vendor_command(cyp, CY7C63_WRITE_PORT, write_id, \
134 (unsigned char)value); \
135 \
136 dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n",result); \
137error: \
138 return result < 0 ? result : count; \
139} \
140 \
141static ssize_t get_port##num(struct device *dev, \
142 struct device_attribute *attr, char *buf) { \
143 \
144 int result = 0; \
145 \
146 struct usb_interface *intf = to_usb_interface(dev); \
147 struct cy7c63 *cyp = usb_get_intfdata(intf); \
148 \
149 dev_dbg(&cyp->udev->dev, "READ_PORT%d called\n", num); \
150 \
151 result = vendor_command(cyp, CY7C63_READ_PORT, read_id, 0); \
152 \
153 dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result); \
154 \
155 return sprintf(buf, "%d", cyp->port##num); \
156} \
157static DEVICE_ATTR(port##num, S_IWUGO | S_IRUGO, get_port##num, set_port##num);
158
159get_set_port(0, CY7C63_READ_PORT_ID0, CY7C63_WRITE_PORT_ID0);
160get_set_port(1, CY7C63_READ_PORT_ID1, CY7C63_WRITE_PORT_ID1);
161
162static int cy7c63_probe(struct usb_interface *interface,
163 const struct usb_device_id *id) {
164
165 struct cy7c63 *dev = NULL;
166 int retval = -ENOMEM;
167
168 /* allocate memory for our device state and initialize it */
169 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
170 if (dev == NULL) {
171 dev_err(&dev->udev->dev, "Out of memory!\n");
172 goto error;
173 }
174
175 dev->udev = usb_get_dev(interface_to_usbdev(interface));
176
177 /* save our data pointer in this interface device */
178 usb_set_intfdata(interface, dev);
179
180 /* create device attribute files */
181 device_create_file(&interface->dev, &dev_attr_port0);
182 device_create_file(&interface->dev, &dev_attr_port1);
183
184 /* let the user know what node this device is now attached to */
185 dev_info(&interface->dev,
186 "Cypress CY7C63xxx device now attached\n");
187
188 retval = 0;
189error:
190 return retval;
191}
192
193static void cy7c63_disconnect(struct usb_interface *interface) {
194
195 struct cy7c63 *dev;
196
197 dev = usb_get_intfdata(interface);
198 usb_set_intfdata(interface, NULL);
199
200 /* remove device attribute files */
201 device_remove_file(&interface->dev, &dev_attr_port0);
202 device_remove_file(&interface->dev, &dev_attr_port1);
203
204 usb_put_dev(dev->udev);
205
206 dev_info(&interface->dev,
207 "Cypress CY7C63xxx device now disconnected\n");
208
209 kfree(dev);
210}
211
212static struct usb_driver cy7c63_driver = {
213 .name = "cy7c63",
214 .probe = cy7c63_probe,
215 .disconnect = cy7c63_disconnect,
216 .id_table = cy7c63_table,
217};
218
219static int __init cy7c63_init(void) {
220
221 int result;
222
223 /* register this driver with the USB subsystem */
224 result = usb_register(&cy7c63_driver);
225 if (result) {
226 err("Function usb_register failed! Error number: %d\n", result);
227 }
228
229 return result;
230}
231
232static void __exit cy7c63_exit(void) {
233
234 /* deregister this driver with the USB subsystem */
235 usb_deregister(&cy7c63_driver);
236}
237
238module_init(cy7c63_init);
239module_exit(cy7c63_exit);
240
241MODULE_AUTHOR(DRIVER_AUTHOR);
242MODULE_DESCRIPTION(DRIVER_DESC);
243
244MODULE_LICENSE("GPL");
diff --git a/drivers/usb/misc/cypress_cy7c63.c b/drivers/usb/misc/cypress_cy7c63.c
new file mode 100644
index 000000000000..9c46746d5d00
--- /dev/null
+++ b/drivers/usb/misc/cypress_cy7c63.c
@@ -0,0 +1,284 @@
1/*
2* cypress_cy7c63.c
3*
4* Copyright (c) 2006 Oliver Bock (o.bock@fh-wolfenbuettel.de)
5*
6* This driver is based on the Cypress USB Driver by Marcus Maul
7* (cyport) and the 2.0 version of Greg Kroah-Hartman's
8* USB Skeleton driver.
9*
10* This is a generic driver for the Cypress CY7C63xxx family.
11* For the time being it enables you to read from and write to
12* the single I/O ports of the device.
13*
14* Supported vendors: AK Modul-Bus Computer GmbH
15* (Firmware "Port-Chip")
16*
17* Supported devices: CY7C63001A-PC
18* CY7C63001C-PXC
19* CY7C63001C-SXC
20*
21* Supported functions: Read/Write Ports
22*
23*
24* This program is free software; you can redistribute it and/or
25* modify it under the terms of the GNU General Public License as
26* published by the Free Software Foundation, version 2.
27*/
28
29#include <linux/init.h>
30#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/usb.h>
33
34#define DRIVER_AUTHOR "Oliver Bock (o.bock@fh-wolfenbuettel.de)"
35#define DRIVER_DESC "Cypress CY7C63xxx USB driver"
36
37#define CYPRESS_VENDOR_ID 0xa2c
38#define CYPRESS_PRODUCT_ID 0x8
39
40#define CYPRESS_READ_PORT 0x4
41#define CYPRESS_WRITE_PORT 0x5
42
43#define CYPRESS_READ_RAM 0x2
44#define CYPRESS_WRITE_RAM 0x3
45#define CYPRESS_READ_ROM 0x1
46
47#define CYPRESS_READ_PORT_ID0 0
48#define CYPRESS_WRITE_PORT_ID0 0
49#define CYPRESS_READ_PORT_ID1 0x2
50#define CYPRESS_WRITE_PORT_ID1 1
51
52#define CYPRESS_MAX_REQSIZE 8
53
54
55/* table of devices that work with this driver */
56static struct usb_device_id cypress_table [] = {
57 { USB_DEVICE(CYPRESS_VENDOR_ID, CYPRESS_PRODUCT_ID) },
58 { }
59};
60MODULE_DEVICE_TABLE(usb, cypress_table);
61
62/* structure to hold all of our device specific stuff */
63struct cypress {
64 struct usb_device * udev;
65 unsigned char port[2];
66};
67
68/* used to send usb control messages to device */
69static int vendor_command(struct cypress *dev, unsigned char request,
70 unsigned char address, unsigned char data)
71{
72 int retval = 0;
73 unsigned int pipe;
74 unsigned char *iobuf;
75
76 /* allocate some memory for the i/o buffer*/
77 iobuf = kzalloc(CYPRESS_MAX_REQSIZE, GFP_KERNEL);
78 if (!iobuf) {
79 dev_err(&dev->udev->dev, "Out of memory!\n");
80 retval = -ENOMEM;
81 goto error;
82 }
83
84 dev_dbg(&dev->udev->dev, "Sending usb_control_msg (data: %d)\n", data);
85
86 /* prepare usb control message and send it upstream */
87 pipe = usb_rcvctrlpipe(dev->udev, 0);
88 retval = usb_control_msg(dev->udev, pipe, request,
89 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
90 address, data, iobuf, CYPRESS_MAX_REQSIZE,
91 USB_CTRL_GET_TIMEOUT);
92
93 /* store returned data (more READs to be added) */
94 switch (request) {
95 case CYPRESS_READ_PORT:
96 if (address == CYPRESS_READ_PORT_ID0) {
97 dev->port[0] = iobuf[1];
98 dev_dbg(&dev->udev->dev,
99 "READ_PORT0 returned: %d\n",
100 dev->port[0]);
101 }
102 else if (address == CYPRESS_READ_PORT_ID1) {
103 dev->port[1] = iobuf[1];
104 dev_dbg(&dev->udev->dev,
105 "READ_PORT1 returned: %d\n",
106 dev->port[1]);
107 }
108 break;
109 }
110
111 kfree(iobuf);
112error:
113 return retval;
114}
115
116/* write port value */
117static ssize_t write_port(struct device *dev, struct device_attribute *attr,
118 const char *buf, size_t count,
119 int port_num, int write_id)
120{
121 int value = -1;
122 int result = 0;
123
124 struct usb_interface *intf = to_usb_interface(dev);
125 struct cypress *cyp = usb_get_intfdata(intf);
126
127 dev_dbg(&cyp->udev->dev, "WRITE_PORT%d called\n", port_num);
128
129 /* validate input data */
130 if (sscanf(buf, "%d", &value) < 1) {
131 result = -EINVAL;
132 goto error;
133 }
134 if (value < 0 || value > 255) {
135 result = -EINVAL;
136 goto error;
137 }
138
139 result = vendor_command(cyp, CYPRESS_WRITE_PORT, write_id,
140 (unsigned char)value);
141
142 dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result);
143error:
144 return result < 0 ? result : count;
145}
146
147/* attribute callback handler (write) */
148static ssize_t set_port0_handler(struct device *dev,
149 struct device_attribute *attr,
150 const char *buf, size_t count)
151{
152 return write_port(dev, attr, buf, count, 0, CYPRESS_WRITE_PORT_ID0);
153}
154
155/* attribute callback handler (write) */
156static ssize_t set_port1_handler(struct device *dev,
157 struct device_attribute *attr,
158 const char *buf, size_t count)
159{
160 return write_port(dev, attr, buf, count, 1, CYPRESS_WRITE_PORT_ID1);
161}
162
163/* read port value */
164static ssize_t read_port(struct device *dev, struct device_attribute *attr,
165 char *buf, int port_num, int read_id)
166{
167 int result = 0;
168
169 struct usb_interface *intf = to_usb_interface(dev);
170 struct cypress *cyp = usb_get_intfdata(intf);
171
172 dev_dbg(&cyp->udev->dev, "READ_PORT%d called\n", port_num);
173
174 result = vendor_command(cyp, CYPRESS_READ_PORT, read_id, 0);
175
176 dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result);
177
178 return sprintf(buf, "%d", cyp->port[port_num]);
179}
180
181/* attribute callback handler (read) */
182static ssize_t get_port0_handler(struct device *dev,
183 struct device_attribute *attr, char *buf)
184{
185 return read_port(dev, attr, buf, 0, CYPRESS_READ_PORT_ID0);
186}
187
188/* attribute callback handler (read) */
189static ssize_t get_port1_handler(struct device *dev,
190 struct device_attribute *attr, char *buf)
191{
192 return read_port(dev, attr, buf, 1, CYPRESS_READ_PORT_ID1);
193}
194
195static DEVICE_ATTR(port0, S_IWUGO | S_IRUGO,
196 get_port0_handler, set_port0_handler);
197
198static DEVICE_ATTR(port1, S_IWUGO | S_IRUGO,
199 get_port1_handler, set_port1_handler);
200
201
202static int cypress_probe(struct usb_interface *interface,
203 const struct usb_device_id *id)
204{
205 struct cypress *dev = NULL;
206 int retval = -ENOMEM;
207
208 /* allocate memory for our device state and initialize it */
209 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
210 if (dev == NULL) {
211 dev_err(&interface->dev, "Out of memory!\n");
212 goto error;
213 }
214
215 dev->udev = usb_get_dev(interface_to_usbdev(interface));
216
217 /* save our data pointer in this interface device */
218 usb_set_intfdata(interface, dev);
219
220 /* create device attribute files */
221 device_create_file(&interface->dev, &dev_attr_port0);
222 device_create_file(&interface->dev, &dev_attr_port1);
223
224 /* let the user know that the device is now attached */
225 dev_info(&interface->dev,
226 "Cypress CY7C63xxx device now attached\n");
227
228 retval = 0;
229error:
230 return retval;
231}
232
233static void cypress_disconnect(struct usb_interface *interface)
234{
235 struct cypress *dev;
236
237 dev = usb_get_intfdata(interface);
238 usb_set_intfdata(interface, NULL);
239
240 /* remove device attribute files */
241 device_remove_file(&interface->dev, &dev_attr_port0);
242 device_remove_file(&interface->dev, &dev_attr_port1);
243
244 usb_put_dev(dev->udev);
245
246 dev_info(&interface->dev,
247 "Cypress CY7C63xxx device now disconnected\n");
248
249 kfree(dev);
250}
251
252static struct usb_driver cypress_driver = {
253 .name = "cypress_cy7c63",
254 .probe = cypress_probe,
255 .disconnect = cypress_disconnect,
256 .id_table = cypress_table,
257};
258
259static int __init cypress_init(void)
260{
261 int result;
262
263 /* register this driver with the USB subsystem */
264 result = usb_register(&cypress_driver);
265 if (result) {
266 err("Function usb_register failed! Error number: %d\n", result);
267 }
268
269 return result;
270}
271
272static void __exit cypress_exit(void)
273{
274 /* deregister this driver with the USB subsystem */
275 usb_deregister(&cypress_driver);
276}
277
278module_init(cypress_init);
279module_exit(cypress_exit);
280
281MODULE_AUTHOR(DRIVER_AUTHOR);
282MODULE_DESCRIPTION(DRIVER_DESC);
283
284MODULE_LICENSE("GPL");
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index 738bd7c7451f..e16582f3733c 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -3435,6 +3435,8 @@ static void sisusb_disconnect(struct usb_interface *intf)
3435 3435
3436static struct usb_device_id sisusb_table [] = { 3436static struct usb_device_id sisusb_table [] = {
3437 { USB_DEVICE(0x0711, 0x0900) }, 3437 { USB_DEVICE(0x0711, 0x0900) },
3438 { USB_DEVICE(0x0711, 0x0901) },
3439 { USB_DEVICE(0x0711, 0x0902) },
3438 { USB_DEVICE(0x182d, 0x021c) }, 3440 { USB_DEVICE(0x182d, 0x021c) },
3439 { USB_DEVICE(0x182d, 0x0269) }, 3441 { USB_DEVICE(0x182d, 0x0269) },
3440 { } 3442 { }
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index c82c402285a0..e095772dd8e9 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -200,10 +200,8 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz
200 200
201 /* create a urb, and a buffer for it, and copy the data to the urb */ 201 /* create a urb, and a buffer for it, and copy the data to the urb */
202 urb = usb_alloc_urb(0, GFP_KERNEL); 202 urb = usb_alloc_urb(0, GFP_KERNEL);
203 if (!urb) { 203 if (!urb)
204 retval = -ENOMEM; 204 return -ENOMEM;
205 goto error;
206 }
207 205
208 buf = usb_buffer_alloc(dev->udev, count, GFP_KERNEL, &urb->transfer_dma); 206 buf = usb_buffer_alloc(dev->udev, count, GFP_KERNEL, &urb->transfer_dma);
209 if (!buf) { 207 if (!buf) {
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 786e1dbe88ec..983e104dd452 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -1242,11 +1242,12 @@ done:
1242static int ctrl_out (struct usbtest_dev *dev, 1242static int ctrl_out (struct usbtest_dev *dev,
1243 unsigned count, unsigned length, unsigned vary) 1243 unsigned count, unsigned length, unsigned vary)
1244{ 1244{
1245 unsigned i, j, len, retval; 1245 unsigned i, j, len;
1246 int retval;
1246 u8 *buf; 1247 u8 *buf;
1247 char *what = "?"; 1248 char *what = "?";
1248 struct usb_device *udev; 1249 struct usb_device *udev;
1249 1250
1250 if (length < 1 || length > 0xffff || vary >= length) 1251 if (length < 1 || length > 0xffff || vary >= length)
1251 return -EINVAL; 1252 return -EINVAL;
1252 1253
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index e02c1a30c4cd..f961a770cee2 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -64,7 +64,6 @@ struct mon_reader_text {
64}; 64};
65 65
66static void mon_text_ctor(void *, kmem_cache_t *, unsigned long); 66static void mon_text_ctor(void *, kmem_cache_t *, unsigned long);
67static void mon_text_dtor(void *, kmem_cache_t *, unsigned long);
68 67
69/* 68/*
70 * mon_text_submit 69 * mon_text_submit
@@ -268,7 +267,7 @@ static int mon_text_open(struct inode *inode, struct file *file)
268 (long)rp); 267 (long)rp);
269 rp->e_slab = kmem_cache_create(rp->slab_name, 268 rp->e_slab = kmem_cache_create(rp->slab_name,
270 sizeof(struct mon_event_text), sizeof(long), 0, 269 sizeof(struct mon_event_text), sizeof(long), 0,
271 mon_text_ctor, mon_text_dtor); 270 mon_text_ctor, NULL);
272 if (rp->e_slab == NULL) { 271 if (rp->e_slab == NULL) {
273 rc = -ENOMEM; 272 rc = -ENOMEM;
274 goto err_slab; 273 goto err_slab;
@@ -459,7 +458,3 @@ static void mon_text_ctor(void *mem, kmem_cache_t *slab, unsigned long sflags)
459 memset(mem, 0xe5, sizeof(struct mon_event_text)); 458 memset(mem, 0xe5, sizeof(struct mon_event_text));
460} 459}
461 460
462static void mon_text_dtor(void *mem, kmem_cache_t *slab, unsigned long sflags)
463{
464 ;
465}
diff --git a/drivers/usb/net/pegasus.h b/drivers/usb/net/pegasus.h
index a54752ce1493..006438069b66 100644
--- a/drivers/usb/net/pegasus.h
+++ b/drivers/usb/net/pegasus.h
@@ -131,6 +131,7 @@ struct usb_eth_dev {
131#define VENDOR_COREGA 0x07aa 131#define VENDOR_COREGA 0x07aa
132#define VENDOR_DLINK 0x2001 132#define VENDOR_DLINK 0x2001
133#define VENDOR_ELCON 0x0db7 133#define VENDOR_ELCON 0x0db7
134#define VENDOR_ELECOM 0x056e
134#define VENDOR_ELSA 0x05cc 135#define VENDOR_ELSA 0x05cc
135#define VENDOR_GIGABYTE 0x1044 136#define VENDOR_GIGABYTE 0x1044
136#define VENDOR_HAWKING 0x0e66 137#define VENDOR_HAWKING 0x0e66
@@ -233,6 +234,8 @@ PEGASUS_DEV( "D-Link DSB-650", VENDOR_DLINK, 0xabc1,
233 DEFAULT_GPIO_RESET ) 234 DEFAULT_GPIO_RESET )
234PEGASUS_DEV( "GOLDPFEIL USB Adapter", VENDOR_ELCON, 0x0002, 235PEGASUS_DEV( "GOLDPFEIL USB Adapter", VENDOR_ELCON, 0x0002,
235 DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA ) 236 DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA )
237PEGASUS_DEV( "ELECOM USB Ethernet LD-USB20", VENDOR_ELECOM, 0x4010,
238 DEFAULT_GPIO_RESET | PEGASUS_II )
236PEGASUS_DEV( "EasiDock Ethernet", VENDOR_MOBILITY, 0x0304, 239PEGASUS_DEV( "EasiDock Ethernet", VENDOR_MOBILITY, 0x0304,
237 DEFAULT_GPIO_RESET ) 240 DEFAULT_GPIO_RESET )
238PEGASUS_DEV( "Elsa Micolink USB2Ethernet", VENDOR_ELSA, 0x3000, 241PEGASUS_DEV( "Elsa Micolink USB2Ethernet", VENDOR_ELSA, 0x3000,
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c
index 718f8e2b552b..a72685b96061 100644
--- a/drivers/usb/net/rtl8150.c
+++ b/drivers/usb/net/rtl8150.c
@@ -128,11 +128,13 @@
128#define VENDOR_ID_MELCO 0x0411 128#define VENDOR_ID_MELCO 0x0411
129#define VENDOR_ID_MICRONET 0x3980 129#define VENDOR_ID_MICRONET 0x3980
130#define VENDOR_ID_LONGSHINE 0x07b8 130#define VENDOR_ID_LONGSHINE 0x07b8
131#define VENDOR_ID_ZYXEL 0x0586
131 132
132#define PRODUCT_ID_RTL8150 0x8150 133#define PRODUCT_ID_RTL8150 0x8150
133#define PRODUCT_ID_LUAKTX 0x0012 134#define PRODUCT_ID_LUAKTX 0x0012
134#define PRODUCT_ID_LCS8138TX 0x401a 135#define PRODUCT_ID_LCS8138TX 0x401a
135#define PRODUCT_ID_SP128AR 0x0003 136#define PRODUCT_ID_SP128AR 0x0003
137#define PRODUCT_ID_PRESTIGE 0x401a
136 138
137#undef EEPROM_WRITE 139#undef EEPROM_WRITE
138 140
@@ -142,6 +144,7 @@ static struct usb_device_id rtl8150_table[] = {
142 {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)}, 144 {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)},
143 {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)}, 145 {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)},
144 {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)}, 146 {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)},
147 {USB_DEVICE(VENDOR_ID_ZYXEL, PRODUCT_ID_PRESTIGE)},
145 {} 148 {}
146}; 149};
147 150
@@ -172,6 +175,8 @@ static inline struct sk_buff *pull_skb(rtl8150_t *);
172static void rtl8150_disconnect(struct usb_interface *intf); 175static void rtl8150_disconnect(struct usb_interface *intf);
173static int rtl8150_probe(struct usb_interface *intf, 176static int rtl8150_probe(struct usb_interface *intf,
174 const struct usb_device_id *id); 177 const struct usb_device_id *id);
178static int rtl8150_suspend(struct usb_interface *intf, pm_message_t message);
179static int rtl8150_resume(struct usb_interface *intf);
175 180
176static const char driver_name [] = "rtl8150"; 181static const char driver_name [] = "rtl8150";
177 182
@@ -180,6 +185,8 @@ static struct usb_driver rtl8150_driver = {
180 .probe = rtl8150_probe, 185 .probe = rtl8150_probe,
181 .disconnect = rtl8150_disconnect, 186 .disconnect = rtl8150_disconnect,
182 .id_table = rtl8150_table, 187 .id_table = rtl8150_table,
188 .suspend = rtl8150_suspend,
189 .resume = rtl8150_resume
183}; 190};
184 191
185/* 192/*
@@ -235,9 +242,11 @@ static int async_set_registers(rtl8150_t * dev, u16 indx, u16 size)
235 usb_fill_control_urb(dev->ctrl_urb, dev->udev, 242 usb_fill_control_urb(dev->ctrl_urb, dev->udev,
236 usb_sndctrlpipe(dev->udev, 0), (char *) &dev->dr, 243 usb_sndctrlpipe(dev->udev, 0), (char *) &dev->dr,
237 &dev->rx_creg, size, ctrl_callback, dev); 244 &dev->rx_creg, size, ctrl_callback, dev);
238 if ((ret = usb_submit_urb(dev->ctrl_urb, GFP_ATOMIC))) 245 if ((ret = usb_submit_urb(dev->ctrl_urb, GFP_ATOMIC))) {
246 if (ret == -ENODEV)
247 netif_device_detach(dev->netdev);
239 err("control request submission failed: %d", ret); 248 err("control request submission failed: %d", ret);
240 else 249 } else
241 set_bit(RX_REG_SET, &dev->flags); 250 set_bit(RX_REG_SET, &dev->flags);
242 251
243 return ret; 252 return ret;
@@ -413,6 +422,7 @@ static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
413 struct sk_buff *skb; 422 struct sk_buff *skb;
414 struct net_device *netdev; 423 struct net_device *netdev;
415 u16 rx_stat; 424 u16 rx_stat;
425 int status;
416 426
417 dev = urb->context; 427 dev = urb->context;
418 if (!dev) 428 if (!dev)
@@ -462,7 +472,10 @@ static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
462goon: 472goon:
463 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), 473 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
464 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev); 474 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
465 if (usb_submit_urb(dev->rx_urb, GFP_ATOMIC)) { 475 status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
476 if (status == -ENODEV)
477 netif_device_detach(dev->netdev);
478 else if (status) {
466 set_bit(RX_URB_FAIL, &dev->flags); 479 set_bit(RX_URB_FAIL, &dev->flags);
467 goto resched; 480 goto resched;
468 } else { 481 } else {
@@ -478,6 +491,7 @@ static void rx_fixup(unsigned long data)
478{ 491{
479 rtl8150_t *dev; 492 rtl8150_t *dev;
480 struct sk_buff *skb; 493 struct sk_buff *skb;
494 int status;
481 495
482 dev = (rtl8150_t *)data; 496 dev = (rtl8150_t *)data;
483 497
@@ -496,10 +510,13 @@ static void rx_fixup(unsigned long data)
496 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), 510 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
497 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev); 511 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
498try_again: 512try_again:
499 if (usb_submit_urb(dev->rx_urb, GFP_ATOMIC)) { 513 status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
514 if (status == -ENODEV) {
515 netif_device_detach(dev->netdev);
516 } else if (status) {
500 set_bit(RX_URB_FAIL, &dev->flags); 517 set_bit(RX_URB_FAIL, &dev->flags);
501 goto tlsched; 518 goto tlsched;
502 } else { 519 } else {
503 clear_bit(RX_URB_FAIL, &dev->flags); 520 clear_bit(RX_URB_FAIL, &dev->flags);
504 } 521 }
505 522
@@ -571,12 +588,43 @@ static void intr_callback(struct urb *urb, struct pt_regs *regs)
571 588
572resubmit: 589resubmit:
573 status = usb_submit_urb (urb, SLAB_ATOMIC); 590 status = usb_submit_urb (urb, SLAB_ATOMIC);
574 if (status) 591 if (status == -ENODEV)
592 netif_device_detach(dev->netdev);
593 else if (status)
575 err ("can't resubmit intr, %s-%s/input0, status %d", 594 err ("can't resubmit intr, %s-%s/input0, status %d",
576 dev->udev->bus->bus_name, 595 dev->udev->bus->bus_name,
577 dev->udev->devpath, status); 596 dev->udev->devpath, status);
578} 597}
579 598
599static int rtl8150_suspend(struct usb_interface *intf, pm_message_t message)
600{
601 rtl8150_t *dev = usb_get_intfdata(intf);
602
603 netif_device_detach(dev->netdev);
604
605 if (netif_running(dev->netdev)) {
606 usb_kill_urb(dev->rx_urb);
607 usb_kill_urb(dev->intr_urb);
608 }
609 return 0;
610}
611
612static int rtl8150_resume(struct usb_interface *intf)
613{
614 rtl8150_t *dev = usb_get_intfdata(intf);
615
616 netif_device_attach(dev->netdev);
617 if (netif_running(dev->netdev)) {
618 dev->rx_urb->status = 0;
619 dev->rx_urb->actual_length = 0;
620 read_bulk_callback(dev->rx_urb, NULL);
621
622 dev->intr_urb->status = 0;
623 dev->intr_urb->actual_length = 0;
624 intr_callback(dev->intr_urb, NULL);
625 }
626 return 0;
627}
580 628
581/* 629/*
582** 630**
@@ -687,9 +735,14 @@ static int rtl8150_start_xmit(struct sk_buff *skb, struct net_device *netdev)
687 usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), 735 usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2),
688 skb->data, count, write_bulk_callback, dev); 736 skb->data, count, write_bulk_callback, dev);
689 if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) { 737 if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) {
690 warn("failed tx_urb %d\n", res); 738 /* Can we get/handle EPIPE here? */
691 dev->stats.tx_errors++; 739 if (res == -ENODEV)
692 netif_start_queue(netdev); 740 netif_device_detach(dev->netdev);
741 else {
742 warn("failed tx_urb %d\n", res);
743 dev->stats.tx_errors++;
744 netif_start_queue(netdev);
745 }
693 } else { 746 } else {
694 dev->stats.tx_packets++; 747 dev->stats.tx_packets++;
695 dev->stats.tx_bytes += skb->len; 748 dev->stats.tx_bytes += skb->len;
@@ -726,16 +779,25 @@ static int rtl8150_open(struct net_device *netdev)
726 779
727 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), 780 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
728 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev); 781 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
729 if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL))) 782 if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL))) {
783 if (res == -ENODEV)
784 netif_device_detach(dev->netdev);
730 warn("%s: rx_urb submit failed: %d", __FUNCTION__, res); 785 warn("%s: rx_urb submit failed: %d", __FUNCTION__, res);
786 return res;
787 }
731 usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3), 788 usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3),
732 dev->intr_buff, INTBUFSIZE, intr_callback, 789 dev->intr_buff, INTBUFSIZE, intr_callback,
733 dev, dev->intr_interval); 790 dev, dev->intr_interval);
734 if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL))) 791 if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL))) {
792 if (res == -ENODEV)
793 netif_device_detach(dev->netdev);
735 warn("%s: intr_urb submit failed: %d", __FUNCTION__, res); 794 warn("%s: intr_urb submit failed: %d", __FUNCTION__, res);
736 netif_start_queue(netdev); 795 usb_kill_urb(dev->rx_urb);
796 return res;
797 }
737 enable_net_traffic(dev); 798 enable_net_traffic(dev);
738 set_carrier(netdev); 799 set_carrier(netdev);
800 netif_start_queue(netdev);
739 801
740 return res; 802 return res;
741} 803}
@@ -910,6 +972,7 @@ static void rtl8150_disconnect(struct usb_interface *intf)
910 if (dev) { 972 if (dev) {
911 set_bit(RTL8150_UNPLUG, &dev->flags); 973 set_bit(RTL8150_UNPLUG, &dev->flags);
912 tasklet_disable(&dev->tl); 974 tasklet_disable(&dev->tl);
975 tasklet_kill(&dev->tl);
913 unregister_netdev(dev->netdev); 976 unregister_netdev(dev->netdev);
914 unlink_all_urbs(dev); 977 unlink_all_urbs(dev);
915 free_all_urbs(dev); 978 free_all_urbs(dev);
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 8bd44fda5eaf..f5b9438c94f0 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -62,15 +62,6 @@ config USB_SERIAL_AIRPRIME
62 To compile this driver as a module, choose M here: the 62 To compile this driver as a module, choose M here: the
63 module will be called airprime. 63 module will be called airprime.
64 64
65config USB_SERIAL_ANYDATA
66 tristate "USB AnyData CDMA Wireless Driver"
67 depends on USB_SERIAL
68 help
69 Say Y here if you want to use a AnyData CDMA device.
70
71 To compile this driver as a module, choose M here: the
72 module will be called anydata.
73
74config USB_SERIAL_ARK3116 65config USB_SERIAL_ARK3116
75 tristate "USB ARK Micro 3116 USB Serial Driver (EXPERIMENTAL)" 66 tristate "USB ARK Micro 3116 USB Serial Driver (EXPERIMENTAL)"
76 depends on USB_SERIAL && EXPERIMENTAL 67 depends on USB_SERIAL && EXPERIMENTAL
@@ -456,6 +447,17 @@ config USB_SERIAL_SAFE_PADDED
456 bool "USB Secure Encapsulated Driver - Padded" 447 bool "USB Secure Encapsulated Driver - Padded"
457 depends on USB_SERIAL_SAFE 448 depends on USB_SERIAL_SAFE
458 449
450config USB_SERIAL_SIERRAWIRELESS
451 tristate "USB Sierra Wireless Driver"
452 depends on USB_SERIAL
453 help
454 Say M here if you want to use a Sierra Wireless device (if
455 using an PC 5220 or AC580 please use the Airprime driver
456 instead).
457
458 To compile this driver as a module, choose M here: the
459 module will be called sierra.
460
459config USB_SERIAL_TI 461config USB_SERIAL_TI
460 tristate "USB TI 3410/5052 Serial Driver" 462 tristate "USB TI 3410/5052 Serial Driver"
461 depends on USB_SERIAL 463 depends on USB_SERIAL
@@ -491,15 +493,18 @@ config USB_SERIAL_XIRCOM
491 module will be called keyspan_pda. 493 module will be called keyspan_pda.
492 494
493config USB_SERIAL_OPTION 495config USB_SERIAL_OPTION
494 tristate "USB driver for GSM modems" 496 tristate "USB driver for GSM and CDMA modems"
495 depends on USB_SERIAL 497 depends on USB_SERIAL
496 help 498 help
497 Say Y here if you have an "Option" GSM PCMCIA card 499 Say Y here if you have a GSM or CDMA modem that's connected to USB.
498 (or an OEM version: branded Huawei, Audiovox, or Novatel). 500
501 This driver also supports several PCMCIA cards which have a
502 built-in OHCI-USB adapter and an internally-connected GSM modem.
503 The USB bus on these cards is not accessible externally.
499 504
500 These cards feature a built-in OHCI-USB adapter and an 505 Supported devices include (some of?) those made by:
501 internally-connected GSM modem. The USB bus is not 506 Option, Huawei, Audiovox, Sierra Wireless, Novatel Wireless, or
502 accessible externally. 507 Anydata.
503 508
504 To compile this driver as a module, choose M here: the 509 To compile this driver as a module, choose M here: the
505 module will be called option. 510 module will be called option.
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index 5a0960fc9d3e..8efed2ce1ba3 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -12,7 +12,6 @@ usbserial-obj-$(CONFIG_USB_EZUSB) += ezusb.o
12usbserial-objs := usb-serial.o generic.o bus.o $(usbserial-obj-y) 12usbserial-objs := usb-serial.o generic.o bus.o $(usbserial-obj-y)
13 13
14obj-$(CONFIG_USB_SERIAL_AIRPRIME) += airprime.o 14obj-$(CONFIG_USB_SERIAL_AIRPRIME) += airprime.o
15obj-$(CONFIG_USB_SERIAL_ANYDATA) += anydata.o
16obj-$(CONFIG_USB_SERIAL_ARK3116) += ark3116.o 15obj-$(CONFIG_USB_SERIAL_ARK3116) += ark3116.o
17obj-$(CONFIG_USB_SERIAL_BELKIN) += belkin_sa.o 16obj-$(CONFIG_USB_SERIAL_BELKIN) += belkin_sa.o
18obj-$(CONFIG_USB_SERIAL_CP2101) += cp2101.o 17obj-$(CONFIG_USB_SERIAL_CP2101) += cp2101.o
@@ -39,6 +38,7 @@ obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o
39obj-$(CONFIG_USB_SERIAL_OPTION) += option.o 38obj-$(CONFIG_USB_SERIAL_OPTION) += option.o
40obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o 39obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o
41obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o 40obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o
41obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o
42obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o 42obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o
43obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o 43obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o
44obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o 44obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
index 94b9ba0ff875..62082532a8b3 100644
--- a/drivers/usb/serial/airprime.c
+++ b/drivers/usb/serial/airprime.c
@@ -13,7 +13,7 @@
13#include <linux/tty.h> 13#include <linux/tty.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include "usb-serial.h" 16#include <linux/usb/serial.h>
17 17
18static struct usb_device_id id_table [] = { 18static struct usb_device_id id_table [] = {
19 { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */ 19 { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */
diff --git a/drivers/usb/serial/anydata.c b/drivers/usb/serial/anydata.c
deleted file mode 100644
index 343f6f228220..000000000000
--- a/drivers/usb/serial/anydata.c
+++ /dev/null
@@ -1,123 +0,0 @@
1/*
2 * AnyData CDMA Serial USB driver
3 *
4 * Copyright (C) 2005 Greg Kroah-Hartman <gregkh@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/tty.h>
14#include <linux/module.h>
15#include <linux/usb.h>
16#include "usb-serial.h"
17
18static struct usb_device_id id_table [] = {
19 { USB_DEVICE(0x16d5, 0x6501) }, /* AirData CDMA device */
20 { },
21};
22MODULE_DEVICE_TABLE(usb, id_table);
23
24/* if overridden by the user, then use their value for the size of the
25 * read and write urbs */
26static int buffer_size;
27static int debug;
28
29static struct usb_driver anydata_driver = {
30 .name = "anydata",
31 .probe = usb_serial_probe,
32 .disconnect = usb_serial_disconnect,
33 .id_table = id_table,
34 .no_dynamic_id = 1,
35};
36
37static int anydata_open(struct usb_serial_port *port, struct file *filp)
38{
39 char *buffer;
40 int result = 0;
41
42 dbg("%s - port %d", __FUNCTION__, port->number);
43
44 if (buffer_size) {
45 /* override the default buffer sizes */
46 buffer = kmalloc(buffer_size, GFP_KERNEL);
47 if (!buffer) {
48 dev_err(&port->dev, "%s - out of memory.\n",
49 __FUNCTION__);
50 return -ENOMEM;
51 }
52 kfree (port->read_urb->transfer_buffer);
53 port->read_urb->transfer_buffer = buffer;
54 port->read_urb->transfer_buffer_length = buffer_size;
55
56 buffer = kmalloc(buffer_size, GFP_KERNEL);
57 if (!buffer) {
58 dev_err(&port->dev, "%s - out of memory.\n",
59 __FUNCTION__);
60 return -ENOMEM;
61 }
62 kfree (port->write_urb->transfer_buffer);
63 port->write_urb->transfer_buffer = buffer;
64 port->write_urb->transfer_buffer_length = buffer_size;
65 port->bulk_out_size = buffer_size;
66 }
67
68 /* Start reading from the device */
69 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
70 usb_rcvbulkpipe(port->serial->dev,
71 port->bulk_in_endpointAddress),
72 port->read_urb->transfer_buffer,
73 port->read_urb->transfer_buffer_length,
74 usb_serial_generic_write_bulk_callback, port);
75 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
76 if (result)
77 dev_err(&port->dev,
78 "%s - failed submitting read urb, error %d\n",
79 __FUNCTION__, result);
80
81 return result;
82}
83
84static struct usb_serial_driver anydata_device = {
85 .driver = {
86 .owner = THIS_MODULE,
87 .name = "anydata",
88 },
89 .id_table = id_table,
90 .num_interrupt_in = NUM_DONT_CARE,
91 .num_bulk_in = NUM_DONT_CARE,
92 .num_bulk_out = NUM_DONT_CARE,
93 .num_ports = 1,
94 .open = anydata_open,
95};
96
97static int __init anydata_init(void)
98{
99 int retval;
100
101 retval = usb_serial_register(&anydata_device);
102 if (retval)
103 return retval;
104 retval = usb_register(&anydata_driver);
105 if (retval)
106 usb_serial_deregister(&anydata_device);
107 return retval;
108}
109
110static void __exit anydata_exit(void)
111{
112 usb_deregister(&anydata_driver);
113 usb_serial_deregister(&anydata_device);
114}
115
116module_init(anydata_init);
117module_exit(anydata_exit);
118MODULE_LICENSE("GPL");
119
120module_param(debug, bool, S_IRUGO | S_IWUSR);
121MODULE_PARM_DESC(debug, "Debug enabled or not");
122module_param(buffer_size, int, 0);
123MODULE_PARM_DESC(buffer_size, "Size of the transfer buffers");
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 8dec796222a0..970d9ef0a7a5 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -21,7 +21,7 @@
21#include <linux/tty.h> 21#include <linux/tty.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/usb.h> 23#include <linux/usb.h>
24#include "usb-serial.h" 24#include <linux/usb/serial.h>
25 25
26 26
27static int debug; 27static int debug;
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index 3faa7aa0111a..70ece9e01ce4 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -74,7 +74,7 @@
74#include <linux/spinlock.h> 74#include <linux/spinlock.h>
75#include <asm/uaccess.h> 75#include <asm/uaccess.h>
76#include <linux/usb.h> 76#include <linux/usb.h>
77#include "usb-serial.h" 77#include <linux/usb/serial.h>
78#include "belkin_sa.h" 78#include "belkin_sa.h"
79 79
80static int debug; 80static int debug;
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c
index f2d993b70c18..6542f220468f 100644
--- a/drivers/usb/serial/bus.c
+++ b/drivers/usb/serial/bus.c
@@ -13,7 +13,7 @@
13#include <linux/tty.h> 13#include <linux/tty.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include "usb-serial.h" 16#include <linux/usb/serial.h>
17 17
18static int usb_serial_device_match (struct device *dev, struct device_driver *drv) 18static int usb_serial_device_match (struct device *dev, struct device_driver *drv)
19{ 19{
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index 3d456b32c316..3a9073dbfe6a 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -17,11 +17,10 @@
17#include <linux/tty.h> 17#include <linux/tty.h>
18#include <linux/console.h> 18#include <linux/console.h>
19#include <linux/usb.h> 19#include <linux/usb.h>
20#include <linux/usb/serial.h>
20 21
21static int debug; 22static int debug;
22 23
23#include "usb-serial.h"
24
25struct usbcons_info { 24struct usbcons_info {
26 int magic; 25 int magic;
27 int break_flag; 26 int break_flag;
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index df0a4f98b4ae..486c7411b9a7 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -26,7 +26,7 @@
26#include <linux/moduleparam.h> 26#include <linux/moduleparam.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <asm/uaccess.h> 28#include <asm/uaccess.h>
29#include "usb-serial.h" 29#include <linux/usb/serial.h>
30 30
31/* 31/*
32 * Version Information 32 * Version Information
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 49b51ab0d4cb..6286aba86fae 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -39,7 +39,7 @@
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <asm/uaccess.h> 40#include <asm/uaccess.h>
41#include <linux/usb.h> 41#include <linux/usb.h>
42#include "usb-serial.h" 42#include <linux/usb/serial.h>
43 43
44#define CYBERJACK_LOCAL_BUF_SIZE 32 44#define CYBERJACK_LOCAL_BUF_SIZE 32
45 45
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 4ff2dfb299bd..ee70fddcab60 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -59,11 +59,11 @@
59#include <linux/moduleparam.h> 59#include <linux/moduleparam.h>
60#include <linux/spinlock.h> 60#include <linux/spinlock.h>
61#include <linux/usb.h> 61#include <linux/usb.h>
62#include <linux/usb/serial.h>
62#include <linux/serial.h> 63#include <linux/serial.h>
63#include <linux/delay.h> 64#include <linux/delay.h>
64#include <asm/uaccess.h> 65#include <asm/uaccess.h>
65 66
66#include "usb-serial.h"
67#include "cypress_m8.h" 67#include "cypress_m8.h"
68 68
69 69
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 6953d3ef5738..9b225183fc7a 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -246,7 +246,7 @@
246#include <asm/uaccess.h> 246#include <asm/uaccess.h>
247#include <linux/usb.h> 247#include <linux/usb.h>
248#include <linux/wait.h> 248#include <linux/wait.h>
249#include "usb-serial.h" 249#include <linux/usb/serial.h>
250 250
251/* Defines */ 251/* Defines */
252 252
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c
index 1e2b31eeb497..daafe405d86d 100644
--- a/drivers/usb/serial/empeg.c
+++ b/drivers/usb/serial/empeg.c
@@ -62,7 +62,7 @@
62#include <linux/spinlock.h> 62#include <linux/spinlock.h>
63#include <asm/uaccess.h> 63#include <asm/uaccess.h>
64#include <linux/usb.h> 64#include <linux/usb.h>
65#include "usb-serial.h" 65#include <linux/usb/serial.h>
66 66
67static int debug; 67static int debug;
68 68
diff --git a/drivers/usb/serial/ezusb.c b/drivers/usb/serial/ezusb.c
index debc3b0f9662..5169c2d154ab 100644
--- a/drivers/usb/serial/ezusb.c
+++ b/drivers/usb/serial/ezusb.c
@@ -15,7 +15,7 @@
15#include <linux/tty.h> 15#include <linux/tty.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/usb.h> 17#include <linux/usb.h>
18#include "usb-serial.h" 18#include <linux/usb/serial.h>
19 19
20/* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */ 20/* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */
21#define CPUCS_REG 0x7F92 21#define CPUCS_REG 0x7F92
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 8a74b19f1283..c6115aa1b445 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -257,7 +257,7 @@
257#include <asm/uaccess.h> 257#include <asm/uaccess.h>
258#include <linux/usb.h> 258#include <linux/usb.h>
259#include <linux/serial.h> 259#include <linux/serial.h>
260#include "usb-serial.h" 260#include <linux/usb/serial.h>
261#include "ftdi_sio.h" 261#include "ftdi_sio.h"
262 262
263/* 263/*
@@ -306,6 +306,8 @@ static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
306 306
307 307
308static struct usb_device_id id_table_combined [] = { 308static struct usb_device_id id_table_combined [] = {
309 { USB_DEVICE(FTDI_VID, FTDI_AMC232_PID) },
310 { USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) },
309 { USB_DEVICE(FTDI_VID, FTDI_ACTZWAVE_PID) }, 311 { USB_DEVICE(FTDI_VID, FTDI_ACTZWAVE_PID) },
310 { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) }, 312 { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) },
311 { USB_DEVICE(FTDI_VID, FTDI_IPLUS_PID) }, 313 { USB_DEVICE(FTDI_VID, FTDI_IPLUS_PID) },
@@ -313,6 +315,7 @@ static struct usb_device_id id_table_combined [] = {
313 { USB_DEVICE(FTDI_VID, FTDI_8U232AM_PID) }, 315 { USB_DEVICE(FTDI_VID, FTDI_8U232AM_PID) },
314 { USB_DEVICE(FTDI_VID, FTDI_8U232AM_ALT_PID) }, 316 { USB_DEVICE(FTDI_VID, FTDI_8U232AM_ALT_PID) },
315 { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) }, 317 { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) },
318 { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) },
316 { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) }, 319 { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) },
317 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) }, 320 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) },
318 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) }, 321 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) },
@@ -336,6 +339,7 @@ static struct usb_device_id id_table_combined [] = {
336 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) }, 339 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) },
337 { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) }, 340 { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) },
338 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) }, 341 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) },
342 { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) },
339 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2101_PID) }, 343 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2101_PID) },
340 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) }, 344 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) },
341 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2103_PID) }, 345 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2103_PID) },
@@ -500,6 +504,9 @@ static struct usb_device_id id_table_combined [] = {
500 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_TMU_PID) }, 504 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_TMU_PID) },
501 { USB_DEVICE(FTDI_VID, FTDI_ACG_HFDUAL_PID) }, 505 { USB_DEVICE(FTDI_VID, FTDI_ACG_HFDUAL_PID) },
502 { USB_DEVICE(FTDI_VID, FTDI_YEI_SERVOCENTER31_PID) }, 506 { USB_DEVICE(FTDI_VID, FTDI_YEI_SERVOCENTER31_PID) },
507 { USB_DEVICE(FTDI_VID, FTDI_THORLABS_PID) },
508 { USB_DEVICE(TESTO_VID, TESTO_USB_INTERFACE_PID) },
509 { USB_DEVICE(FTDI_VID, FTDI_GAMMA_SCOUT_PID) },
503 { }, /* Optional parameter entry */ 510 { }, /* Optional parameter entry */
504 { } /* Terminating entry */ 511 { } /* Terminating entry */
505}; 512};
@@ -548,11 +555,17 @@ struct ftdi_private {
548 spinlock_t rx_lock; /* spinlock for receive state */ 555 spinlock_t rx_lock; /* spinlock for receive state */
549 struct work_struct rx_work; 556 struct work_struct rx_work;
550 int rx_processed; 557 int rx_processed;
558 unsigned long rx_bytes;
551 559
552 __u16 interface; /* FT2232C port interface (0 for FT232/245) */ 560 __u16 interface; /* FT2232C port interface (0 for FT232/245) */
553 561
554 int force_baud; /* if non-zero, force the baud rate to this value */ 562 int force_baud; /* if non-zero, force the baud rate to this value */
555 int force_rtscts; /* if non-zero, force RTS-CTS to always be enabled */ 563 int force_rtscts; /* if non-zero, force RTS-CTS to always be enabled */
564
565 spinlock_t tx_lock; /* spinlock for transmit state */
566 unsigned long tx_bytes;
567 unsigned long tx_outstanding_bytes;
568 unsigned long tx_outstanding_urbs;
556}; 569};
557 570
558/* Used for TIOCMIWAIT */ 571/* Used for TIOCMIWAIT */
@@ -626,6 +639,9 @@ static struct usb_serial_driver ftdi_sio_device = {
626#define HIGH 1 639#define HIGH 1
627#define LOW 0 640#define LOW 0
628 641
642/* number of outstanding urbs to prevent userspace DoS from happening */
643#define URB_UPPER_LIMIT 42
644
629/* 645/*
630 * *************************************************************************** 646 * ***************************************************************************
631 * Utlity functions 647 * Utlity functions
@@ -1156,6 +1172,7 @@ static int ftdi_sio_attach (struct usb_serial *serial)
1156 } 1172 }
1157 1173
1158 spin_lock_init(&priv->rx_lock); 1174 spin_lock_init(&priv->rx_lock);
1175 spin_lock_init(&priv->tx_lock);
1159 init_waitqueue_head(&priv->delta_msr_wait); 1176 init_waitqueue_head(&priv->delta_msr_wait);
1160 /* This will push the characters through immediately rather 1177 /* This will push the characters through immediately rather
1161 than queue a task to deliver them */ 1178 than queue a task to deliver them */
@@ -1270,6 +1287,13 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1270 1287
1271 dbg("%s", __FUNCTION__); 1288 dbg("%s", __FUNCTION__);
1272 1289
1290 spin_lock_irqsave(&priv->tx_lock, flags);
1291 priv->tx_bytes = 0;
1292 spin_unlock_irqrestore(&priv->tx_lock, flags);
1293 spin_lock_irqsave(&priv->rx_lock, flags);
1294 priv->rx_bytes = 0;
1295 spin_unlock_irqrestore(&priv->rx_lock, flags);
1296
1273 if (port->tty) 1297 if (port->tty)
1274 port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1298 port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1275 1299
@@ -1372,6 +1396,7 @@ static int ftdi_write (struct usb_serial_port *port,
1372 int data_offset ; /* will be 1 for the SIO and 0 otherwise */ 1396 int data_offset ; /* will be 1 for the SIO and 0 otherwise */
1373 int status; 1397 int status;
1374 int transfer_size; 1398 int transfer_size;
1399 unsigned long flags;
1375 1400
1376 dbg("%s port %d, %d bytes", __FUNCTION__, port->number, count); 1401 dbg("%s port %d, %d bytes", __FUNCTION__, port->number, count);
1377 1402
@@ -1379,6 +1404,13 @@ static int ftdi_write (struct usb_serial_port *port,
1379 dbg("write request of 0 bytes"); 1404 dbg("write request of 0 bytes");
1380 return 0; 1405 return 0;
1381 } 1406 }
1407 spin_lock_irqsave(&priv->tx_lock, flags);
1408 if (priv->tx_outstanding_urbs > URB_UPPER_LIMIT) {
1409 spin_unlock_irqrestore(&priv->tx_lock, flags);
1410 dbg("%s - write limit hit\n", __FUNCTION__);
1411 return 0;
1412 }
1413 spin_unlock_irqrestore(&priv->tx_lock, flags);
1382 1414
1383 data_offset = priv->write_offset; 1415 data_offset = priv->write_offset;
1384 dbg("data_offset set to %d",data_offset); 1416 dbg("data_offset set to %d",data_offset);
@@ -1445,6 +1477,12 @@ static int ftdi_write (struct usb_serial_port *port,
1445 err("%s - failed submitting write urb, error %d", __FUNCTION__, status); 1477 err("%s - failed submitting write urb, error %d", __FUNCTION__, status);
1446 count = status; 1478 count = status;
1447 kfree (buffer); 1479 kfree (buffer);
1480 } else {
1481 spin_lock_irqsave(&priv->tx_lock, flags);
1482 ++priv->tx_outstanding_urbs;
1483 priv->tx_outstanding_bytes += count;
1484 priv->tx_bytes += count;
1485 spin_unlock_irqrestore(&priv->tx_lock, flags);
1448 } 1486 }
1449 1487
1450 /* we are done with this urb, so let the host driver 1488 /* we are done with this urb, so let the host driver
@@ -1460,7 +1498,11 @@ static int ftdi_write (struct usb_serial_port *port,
1460 1498
1461static void ftdi_write_bulk_callback (struct urb *urb, struct pt_regs *regs) 1499static void ftdi_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
1462{ 1500{
1501 unsigned long flags;
1463 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1502 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1503 struct ftdi_private *priv;
1504 int data_offset; /* will be 1 for the SIO and 0 otherwise */
1505 unsigned long countback;
1464 1506
1465 /* free up the transfer buffer, as usb_free_urb() does not do this */ 1507 /* free up the transfer buffer, as usb_free_urb() does not do this */
1466 kfree (urb->transfer_buffer); 1508 kfree (urb->transfer_buffer);
@@ -1472,34 +1514,67 @@ static void ftdi_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
1472 return; 1514 return;
1473 } 1515 }
1474 1516
1517 priv = usb_get_serial_port_data(port);
1518 if (!priv) {
1519 dbg("%s - bad port private data pointer - exiting", __FUNCTION__);
1520 return;
1521 }
1522 /* account for transferred data */
1523 countback = urb->actual_length;
1524 data_offset = priv->write_offset;
1525 if (data_offset > 0) {
1526 /* Subtract the control bytes */
1527 countback -= (data_offset * ((countback + (PKTSZ - 1)) / PKTSZ));
1528 }
1529 spin_lock_irqsave(&priv->tx_lock, flags);
1530 --priv->tx_outstanding_urbs;
1531 priv->tx_outstanding_bytes -= countback;
1532 spin_unlock_irqrestore(&priv->tx_lock, flags);
1533
1475 usb_serial_port_softint(port); 1534 usb_serial_port_softint(port);
1476} /* ftdi_write_bulk_callback */ 1535} /* ftdi_write_bulk_callback */
1477 1536
1478 1537
1479static int ftdi_write_room( struct usb_serial_port *port ) 1538static int ftdi_write_room( struct usb_serial_port *port )
1480{ 1539{
1540 struct ftdi_private *priv = usb_get_serial_port_data(port);
1541 int room;
1542 unsigned long flags;
1543
1481 dbg("%s - port %d", __FUNCTION__, port->number); 1544 dbg("%s - port %d", __FUNCTION__, port->number);
1482 1545
1483 /* 1546 spin_lock_irqsave(&priv->tx_lock, flags);
1484 * We really can take anything the user throws at us 1547 if (priv->tx_outstanding_urbs < URB_UPPER_LIMIT) {
1485 * but let's pick a nice big number to tell the tty 1548 /*
1486 * layer that we have lots of free space 1549 * We really can take anything the user throws at us
1487 */ 1550 * but let's pick a nice big number to tell the tty
1488 return 2048; 1551 * layer that we have lots of free space
1552 */
1553 room = 2048;
1554 } else {
1555 room = 0;
1556 }
1557 spin_unlock_irqrestore(&priv->tx_lock, flags);
1558 return room;
1489} /* ftdi_write_room */ 1559} /* ftdi_write_room */
1490 1560
1491 1561
1492static int ftdi_chars_in_buffer (struct usb_serial_port *port) 1562static int ftdi_chars_in_buffer (struct usb_serial_port *port)
1493{ /* ftdi_chars_in_buffer */ 1563{ /* ftdi_chars_in_buffer */
1564 struct ftdi_private *priv = usb_get_serial_port_data(port);
1565 int buffered;
1566 unsigned long flags;
1567
1494 dbg("%s - port %d", __FUNCTION__, port->number); 1568 dbg("%s - port %d", __FUNCTION__, port->number);
1495 1569
1496 /* 1570 spin_lock_irqsave(&priv->tx_lock, flags);
1497 * We can't really account for how much data we 1571 buffered = (int)priv->tx_outstanding_bytes;
1498 * have sent out, but hasn't made it through to the 1572 spin_unlock_irqrestore(&priv->tx_lock, flags);
1499 * device, so just tell the tty layer that everything 1573 if (buffered < 0) {
1500 * is flushed. 1574 err("%s outstanding tx bytes is negative!", __FUNCTION__);
1501 */ 1575 buffered = 0;
1502 return 0; 1576 }
1577 return buffered;
1503} /* ftdi_chars_in_buffer */ 1578} /* ftdi_chars_in_buffer */
1504 1579
1505 1580
@@ -1509,6 +1584,8 @@ static void ftdi_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
1509 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1584 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1510 struct tty_struct *tty; 1585 struct tty_struct *tty;
1511 struct ftdi_private *priv; 1586 struct ftdi_private *priv;
1587 unsigned long countread;
1588 unsigned long flags;
1512 1589
1513 if (urb->number_of_packets > 0) { 1590 if (urb->number_of_packets > 0) {
1514 err("%s transfer_buffer_length %d actual_length %d number of packets %d",__FUNCTION__, 1591 err("%s transfer_buffer_length %d actual_length %d number of packets %d",__FUNCTION__,
@@ -1543,6 +1620,13 @@ static void ftdi_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
1543 return; 1620 return;
1544 } 1621 }
1545 1622
1623 /* count data bytes, but not status bytes */
1624 countread = urb->actual_length;
1625 countread -= 2 * ((countread + (PKTSZ - 1)) / PKTSZ);
1626 spin_lock_irqsave(&priv->rx_lock, flags);
1627 priv->rx_bytes += countread;
1628 spin_unlock_irqrestore(&priv->rx_lock, flags);
1629
1546 ftdi_process_read(port); 1630 ftdi_process_read(port);
1547 1631
1548} /* ftdi_read_bulk_callback */ 1632} /* ftdi_read_bulk_callback */
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 6ab2ac845bd7..77299996f7ee 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -32,10 +32,19 @@
32#define FTDI_NF_RIC_PID 0x0001 /* Product Id */ 32#define FTDI_NF_RIC_PID 0x0001 /* Product Id */
33 33
34 34
35/* www.canusb.com Lawicel CANUSB device */
36#define FTDI_CANUSB_PID 0xFFA8 /* Product Id */
37
38/* AlphaMicro Components AMC-232USB01 device */
39#define FTDI_AMC232_PID 0xFF00 /* Product Id */
40
35/* ACT Solutions HomePro ZWave interface (http://www.act-solutions.com/HomePro.htm) */ 41/* ACT Solutions HomePro ZWave interface (http://www.act-solutions.com/HomePro.htm) */
36#define FTDI_ACTZWAVE_PID 0xF2D0 42#define FTDI_ACTZWAVE_PID 0xF2D0
37 43
38 44
45/* www.starting-point-systems.com µChameleon device */
46#define FTDI_MICRO_CHAMELEON_PID 0xCAA0 /* Product Id */
47
39/* www.irtrans.de device */ 48/* www.irtrans.de device */
40#define FTDI_IRTRANS_PID 0xFC60 /* Product Id */ 49#define FTDI_IRTRANS_PID 0xFC60 /* Product Id */
41 50
@@ -179,6 +188,10 @@
179/* http://home.earthlink.net/~jrhees/USBUIRT/index.htm */ 188/* http://home.earthlink.net/~jrhees/USBUIRT/index.htm */
180#define FTDI_USB_UIRT_PID 0xF850 /* Product Id */ 189#define FTDI_USB_UIRT_PID 0xF850 /* Product Id */
181 190
191/* TNC-X USB-to-packet-radio adapter, versions prior to 3.0 (DLP module) */
192
193#define FTDI_TNC_X_PID 0xEBE0
194
182/* 195/*
183 * ELV USB devices submitted by Christian Abt of ELV (www.elv.de). 196 * ELV USB devices submitted by Christian Abt of ELV (www.elv.de).
184 * All of these devices use FTDI's vendor ID (0x0403). 197 * All of these devices use FTDI's vendor ID (0x0403).
@@ -442,6 +455,23 @@
442 */ 455 */
443#define FTDI_YEI_SERVOCENTER31_PID 0xE050 /* YEI ServoCenter3.1 USB */ 456#define FTDI_YEI_SERVOCENTER31_PID 0xE050 /* YEI ServoCenter3.1 USB */
444 457
458/*
459 * ThorLabs USB motor drivers
460 */
461#define FTDI_THORLABS_PID 0xfaf0 /* ThorLabs USB motor drivers */
462
463/*
464 * Testo products (http://www.testo.com/)
465 * Submitted by Colin Leroy
466 */
467#define TESTO_VID 0x128D
468#define TESTO_USB_INTERFACE_PID 0x0001
469
470/*
471 * Gamma Scout (http://gamma-scout.com/). Submitted by rsc@runtux.com.
472 */
473#define FTDI_GAMMA_SCOUT_PID 0xD678 /* Gamma Scout online */
474
445/* Commands */ 475/* Commands */
446#define FTDI_SIO_RESET 0 /* Reset the port */ 476#define FTDI_SIO_RESET 0 /* Reset the port */
447#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */ 477#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */
diff --git a/drivers/usb/serial/funsoft.c b/drivers/usb/serial/funsoft.c
index 803721b97e2e..77b977206a8c 100644
--- a/drivers/usb/serial/funsoft.c
+++ b/drivers/usb/serial/funsoft.c
@@ -13,7 +13,7 @@
13#include <linux/tty.h> 13#include <linux/tty.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include "usb-serial.h" 16#include <linux/usb/serial.h>
17 17
18static struct usb_device_id id_table [] = { 18static struct usb_device_id id_table [] = {
19 { USB_DEVICE(0x1404, 0xcddc) }, 19 { USB_DEVICE(0x1404, 0xcddc) },
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 1f5d1620baa1..727852634be9 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -35,6 +35,7 @@
35#include <linux/spinlock.h> 35#include <linux/spinlock.h>
36#include <asm/uaccess.h> 36#include <asm/uaccess.h>
37#include <linux/usb.h> 37#include <linux/usb.h>
38#include <linux/usb/serial.h>
38 39
39/* the mode to be set when the port ist opened */ 40/* the mode to be set when the port ist opened */
40static int initial_mode = 1; 41static int initial_mode = 1;
@@ -42,8 +43,6 @@ static int initial_mode = 1;
42/* debug flag */ 43/* debug flag */
43static int debug = 0; 44static int debug = 0;
44 45
45#include "usb-serial.h"
46
47#define GARMIN_VENDOR_ID 0x091E 46#define GARMIN_VENDOR_ID 0x091E
48 47
49/* 48/*
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 945b8bb38c92..172713556393 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -17,8 +17,8 @@
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/moduleparam.h> 18#include <linux/moduleparam.h>
19#include <linux/usb.h> 19#include <linux/usb.h>
20#include <linux/usb/serial.h>
20#include <asm/uaccess.h> 21#include <asm/uaccess.h>
21#include "usb-serial.h"
22 22
23static int debug; 23static int debug;
24 24
@@ -285,6 +285,7 @@ void usb_serial_generic_read_bulk_callback (struct urb *urb, struct pt_regs *reg
285 if (result) 285 if (result)
286 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 286 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
287} 287}
288EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
288 289
289void usb_serial_generic_write_bulk_callback (struct urb *urb, struct pt_regs *regs) 290void usb_serial_generic_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
290{ 291{
diff --git a/drivers/usb/serial/hp4x.c b/drivers/usb/serial/hp4x.c
index 7e06358b0310..ebcac701b069 100644
--- a/drivers/usb/serial/hp4x.c
+++ b/drivers/usb/serial/hp4x.c
@@ -17,7 +17,7 @@
17#include <linux/tty.h> 17#include <linux/tty.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/usb.h> 19#include <linux/usb.h>
20#include "usb-serial.h" 20#include <linux/usb/serial.h>
21 21
22/* 22/*
23 * Version Information 23 * Version Information
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index bd2c05dac2a9..c49976c3ad52 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -44,7 +44,7 @@
44#include <linux/wait.h> 44#include <linux/wait.h>
45#include <asm/uaccess.h> 45#include <asm/uaccess.h>
46#include <linux/usb.h> 46#include <linux/usb.h>
47#include "usb-serial.h" 47#include <linux/usb/serial.h>
48#include "io_edgeport.h" 48#include "io_edgeport.h"
49#include "io_ionsp.h" /* info for the iosp messages */ 49#include "io_ionsp.h" /* info for the iosp messages */
50#include "io_16654.h" /* 16654 UART defines */ 50#include "io_16654.h" /* 16654 UART defines */
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 723a12ae87b5..17c5b1d2311a 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -39,8 +39,8 @@
39#include <asm/uaccess.h> 39#include <asm/uaccess.h>
40#include <asm/semaphore.h> 40#include <asm/semaphore.h>
41#include <linux/usb.h> 41#include <linux/usb.h>
42#include <linux/usb/serial.h>
42 43
43#include "usb-serial.h"
44#include "io_16654.h" 44#include "io_16654.h"
45#include "io_usbvend.h" 45#include "io_usbvend.h"
46#include "io_ti.h" 46#include "io_ti.h"
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index dbcfe172a5cc..9840bade79f9 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -55,7 +55,7 @@
55#include <linux/spinlock.h> 55#include <linux/spinlock.h>
56#include <asm/uaccess.h> 56#include <asm/uaccess.h>
57#include <linux/usb.h> 57#include <linux/usb.h>
58#include "usb-serial.h" 58#include <linux/usb/serial.h>
59#include "ipaq.h" 59#include "ipaq.h"
60 60
61#define KP_RETRIES 100 61#define KP_RETRIES 100
@@ -70,6 +70,8 @@
70 70
71static __u16 product, vendor; 71static __u16 product, vendor;
72static int debug; 72static int debug;
73static int connect_retries = KP_RETRIES;
74static int initial_wait;
73 75
74/* Function prototypes for an ipaq */ 76/* Function prototypes for an ipaq */
75static int ipaq_open (struct usb_serial_port *port, struct file *filp); 77static int ipaq_open (struct usb_serial_port *port, struct file *filp);
@@ -248,6 +250,9 @@ static struct usb_device_id ipaq_id_table [] = {
248 { USB_DEVICE(0x04C5, 0x1058) }, /* FUJITSU USB Sync */ 250 { USB_DEVICE(0x04C5, 0x1058) }, /* FUJITSU USB Sync */
249 { USB_DEVICE(0x04C5, 0x1079) }, /* FUJITSU USB Sync */ 251 { USB_DEVICE(0x04C5, 0x1079) }, /* FUJITSU USB Sync */
250 { USB_DEVICE(0x04DA, 0x2500) }, /* Panasonic USB Sync */ 252 { USB_DEVICE(0x04DA, 0x2500) }, /* Panasonic USB Sync */
253 { USB_DEVICE(0x04DD, 0x9102) }, /* SHARP WS003SH USB Modem */
254 { USB_DEVICE(0x04DD, 0x9121) }, /* SHARP WS004SH USB Modem */
255 { USB_DEVICE(0x04DD, 0x9123) }, /* SHARP WS007SH USB Modem */
251 { USB_DEVICE(0x04E8, 0x5F00) }, /* Samsung NEXiO USB Sync */ 256 { USB_DEVICE(0x04E8, 0x5F00) }, /* Samsung NEXiO USB Sync */
252 { USB_DEVICE(0x04E8, 0x5F01) }, /* Samsung NEXiO USB Sync */ 257 { USB_DEVICE(0x04E8, 0x5F01) }, /* Samsung NEXiO USB Sync */
253 { USB_DEVICE(0x04E8, 0x5F02) }, /* Samsung NEXiO USB Sync */ 258 { USB_DEVICE(0x04E8, 0x5F02) }, /* Samsung NEXiO USB Sync */
@@ -582,7 +587,7 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
582 struct ipaq_private *priv; 587 struct ipaq_private *priv;
583 struct ipaq_packet *pkt; 588 struct ipaq_packet *pkt;
584 int i, result = 0; 589 int i, result = 0;
585 int retries = KP_RETRIES; 590 int retries = connect_retries;
586 591
587 dbg("%s - port %d", __FUNCTION__, port->number); 592 dbg("%s - port %d", __FUNCTION__, port->number);
588 593
@@ -646,16 +651,12 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
646 port->read_urb->transfer_buffer_length = URBDATA_SIZE; 651 port->read_urb->transfer_buffer_length = URBDATA_SIZE;
647 port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE; 652 port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE;
648 653
654 msleep(1000*initial_wait);
649 /* Start reading from the device */ 655 /* Start reading from the device */
650 usb_fill_bulk_urb(port->read_urb, serial->dev, 656 usb_fill_bulk_urb(port->read_urb, serial->dev,
651 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), 657 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
652 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 658 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
653 ipaq_read_bulk_callback, port); 659 ipaq_read_bulk_callback, port);
654 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
655 if (result) {
656 err("%s - failed submitting read urb, error %d", __FUNCTION__, result);
657 goto error;
658 }
659 660
660 /* 661 /*
661 * Send out control message observed in win98 sniffs. Not sure what 662 * Send out control message observed in win98 sniffs. Not sure what
@@ -670,8 +671,14 @@ static int ipaq_open(struct usb_serial_port *port, struct file *filp)
670 usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21, 671 usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21,
671 0x1, 0, NULL, 0, 100); 672 0x1, 0, NULL, 0, 100);
672 if (result == 0) { 673 if (result == 0) {
674 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
675 if (result) {
676 err("%s - failed submitting read urb, error %d", __FUNCTION__, result);
677 goto error;
678 }
673 return 0; 679 return 0;
674 } 680 }
681 msleep(1000);
675 } 682 }
676 err("%s - failed doing control urb, error %d", __FUNCTION__, result); 683 err("%s - failed doing control urb, error %d", __FUNCTION__, result);
677 goto error; 684 goto error;
@@ -854,6 +861,7 @@ static void ipaq_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
854 861
855 if (urb->status) { 862 if (urb->status) {
856 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 863 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
864 return;
857 } 865 }
858 866
859 spin_lock_irqsave(&write_list_lock, flags); 867 spin_lock_irqsave(&write_list_lock, flags);
@@ -966,3 +974,9 @@ MODULE_PARM_DESC(vendor, "User specified USB idVendor");
966 974
967module_param(product, ushort, 0); 975module_param(product, ushort, 0);
968MODULE_PARM_DESC(product, "User specified USB idProduct"); 976MODULE_PARM_DESC(product, "User specified USB idProduct");
977
978module_param(connect_retries, int, S_IRUGO|S_IWUSR);
979MODULE_PARM_DESC(connect_retries, "Maximum number of connect retries (one second each)");
980
981module_param(initial_wait, int, S_IRUGO|S_IWUSR);
982MODULE_PARM_DESC(initial_wait, "Time to wait before attempting a connection (in seconds)");
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index a4a0bfeaab00..87306cb6f9f5 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -46,8 +46,8 @@
46#include <linux/module.h> 46#include <linux/module.h>
47#include <linux/spinlock.h> 47#include <linux/spinlock.h>
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include <linux/usb/serial.h>
49#include <asm/uaccess.h> 50#include <asm/uaccess.h>
50#include "usb-serial.h"
51 51
52/* 52/*
53 * Version Information 53 * Version Information
@@ -373,6 +373,8 @@ static void ipw_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
373 373
374 dbg("%s", __FUNCTION__); 374 dbg("%s", __FUNCTION__);
375 375
376 port->write_urb_busy = 0;
377
376 if (urb->status) 378 if (urb->status)
377 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 379 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
378 380
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 2cf1fed3de43..1738b0b6a376 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -57,7 +57,7 @@
57#include <linux/spinlock.h> 57#include <linux/spinlock.h>
58#include <asm/uaccess.h> 58#include <asm/uaccess.h>
59#include <linux/usb.h> 59#include <linux/usb.h>
60#include "usb-serial.h" 60#include <linux/usb/serial.h>
61 61
62/* 62/*
63 * Version Information 63 * Version Information
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index d7c58f1bc960..015ad6cc1bbb 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -107,7 +107,7 @@
107#include <linux/spinlock.h> 107#include <linux/spinlock.h>
108#include <asm/uaccess.h> 108#include <asm/uaccess.h>
109#include <linux/usb.h> 109#include <linux/usb.h>
110#include "usb-serial.h" 110#include <linux/usb/serial.h>
111#include "keyspan.h" 111#include "keyspan.h"
112 112
113static int debug; 113static int debug;
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 03ab3c0f3cce..49b8dc039d1f 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -78,6 +78,7 @@
78#include <linux/workqueue.h> 78#include <linux/workqueue.h>
79#include <asm/uaccess.h> 79#include <asm/uaccess.h>
80#include <linux/usb.h> 80#include <linux/usb.h>
81#include <linux/usb/serial.h>
81 82
82static int debug; 83static int debug;
83 84
@@ -107,8 +108,6 @@ struct ezusb_hex_record {
107#include "xircom_pgs_fw.h" 108#include "xircom_pgs_fw.h"
108#endif 109#endif
109 110
110#include "usb-serial.h"
111
112/* 111/*
113 * Version Information 112 * Version Information
114 */ 113 */
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index b45ff3e7ab40..2a2f3e2da055 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -55,7 +55,7 @@
55#include <linux/module.h> 55#include <linux/module.h>
56#include <asm/uaccess.h> 56#include <asm/uaccess.h>
57#include <linux/usb.h> 57#include <linux/usb.h>
58#include "usb-serial.h" 58#include <linux/usb/serial.h>
59#include "kl5kusb105.h" 59#include "kl5kusb105.h"
60 60
61static int debug; 61static int debug;
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 457733374772..d50dce034958 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -46,8 +46,8 @@
46#include <linux/spinlock.h> 46#include <linux/spinlock.h>
47#include <asm/uaccess.h> 47#include <asm/uaccess.h>
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include <linux/usb/serial.h>
49#include <linux/ioctl.h> 50#include <linux/ioctl.h>
50#include "usb-serial.h"
51#include "kobil_sct.h" 51#include "kobil_sct.h"
52 52
53static int debug; 53static int debug;
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index ca05d3275f3e..f4d4305c2c02 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -75,7 +75,7 @@
75#include <linux/spinlock.h> 75#include <linux/spinlock.h>
76#include <asm/uaccess.h> 76#include <asm/uaccess.h>
77#include <linux/usb.h> 77#include <linux/usb.h>
78#include "usb-serial.h" 78#include <linux/usb/serial.h>
79#include "mct_u232.h" 79#include "mct_u232.h"
80 80
81/* 81/*
diff --git a/drivers/usb/serial/navman.c b/drivers/usb/serial/navman.c
index 7f544081032e..ac3f8b5d2c49 100644
--- a/drivers/usb/serial/navman.c
+++ b/drivers/usb/serial/navman.c
@@ -14,7 +14,7 @@
14#include <linux/tty_flip.h> 14#include <linux/tty_flip.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/usb.h> 16#include <linux/usb.h>
17#include "usb-serial.h" 17#include <linux/usb/serial.h>
18 18
19static int debug; 19static int debug;
20 20
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index cfb711a21a45..e49f40913c27 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -46,7 +46,7 @@
46#include <linux/spinlock.h> 46#include <linux/spinlock.h>
47#include <asm/uaccess.h> 47#include <asm/uaccess.h>
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include "usb-serial.h" 49#include <linux/usb/serial.h>
50 50
51static int debug; 51static int debug;
52 52
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 78ad4b3126a6..c856e6f40e22 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -9,39 +9,14 @@
9 9
10 Portions copied from the Keyspan driver by Hugh Blemings <hugh@blemings.org> 10 Portions copied from the Keyspan driver by Hugh Blemings <hugh@blemings.org>
11 11
12 History: 12 History: see the git log.
13
14 2005-05-19 v0.1 Initial version, based on incomplete docs
15 and analysis of misbehavior with the standard driver
16 2005-05-20 v0.2 Extended the input buffer to avoid losing
17 random 64-byte chunks of data
18 2005-05-21 v0.3 implemented chars_in_buffer()
19 turned on low_latency
20 simplified the code somewhat
21 2005-05-24 v0.4 option_write() sometimes deadlocked under heavy load
22 removed some dead code
23 added sponsor notice
24 coding style clean-up
25 2005-06-20 v0.4.1 add missing braces :-/
26 killed end-of-line whitespace
27 2005-07-15 v0.4.2 rename WLAN product to FUSION, add FUSION2
28 2005-09-10 v0.4.3 added HUAWEI E600 card and Audiovox AirCard
29 2005-09-20 v0.4.4 increased recv buffer size: the card sometimes
30 wants to send >2000 bytes.
31 2006-04-10 v0.5 fixed two array overrun errors :-/
32 2006-04-21 v0.5.1 added support for Sierra Wireless MC8755
33 2006-05-15 v0.6 re-enable multi-port support
34 2006-06-01 v0.6.1 add COBRA
35 2006-06-01 v0.6.2 add backwards-compatibility stuff
36 2006-06-01 v0.6.3 add Novatel Wireless
37 2006-06-01 v0.7 Option => GSM
38 13
39 Work sponsored by: Sigos GmbH, Germany <info@sigos.de> 14 Work sponsored by: Sigos GmbH, Germany <info@sigos.de>
40 15
41 This driver exists because the "normal" serial driver doesn't work too well 16 This driver exists because the "normal" serial driver doesn't work too well
42 with GSM modems. Issues: 17 with GSM modems. Issues:
43 - data loss -- one single Receive URB is not nearly enough 18 - data loss -- one single Receive URB is not nearly enough
44 - nonstandard flow (Option devices) and multiplex (Sierra) control 19 - nonstandard flow (Option devices) control
45 - controlling the baud rate doesn't make sense 20 - controlling the baud rate doesn't make sense
46 21
47 This driver is named "option" because the most common device it's 22 This driver is named "option" because the most common device it's
@@ -53,7 +28,7 @@
53 device features. 28 device features.
54*/ 29*/
55 30
56#define DRIVER_VERSION "v0.7.0" 31#define DRIVER_VERSION "v0.7.1"
57#define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>" 32#define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>"
58#define DRIVER_DESC "USB Driver for GSM modems" 33#define DRIVER_DESC "USB Driver for GSM modems"
59 34
@@ -64,7 +39,7 @@
64#include <linux/tty_flip.h> 39#include <linux/tty_flip.h>
65#include <linux/module.h> 40#include <linux/module.h>
66#include <linux/usb.h> 41#include <linux/usb.h>
67#include "usb-serial.h" 42#include <linux/usb/serial.h>
68 43
69/* Function prototypes */ 44/* Function prototypes */
70static int option_open(struct usb_serial_port *port, struct file *filp); 45static int option_open(struct usb_serial_port *port, struct file *filp);
@@ -95,27 +70,29 @@ static int option_send_setup(struct usb_serial_port *port);
95#define OPTION_VENDOR_ID 0x0AF0 70#define OPTION_VENDOR_ID 0x0AF0
96#define HUAWEI_VENDOR_ID 0x12D1 71#define HUAWEI_VENDOR_ID 0x12D1
97#define AUDIOVOX_VENDOR_ID 0x0F3D 72#define AUDIOVOX_VENDOR_ID 0x0F3D
98#define SIERRAWIRELESS_VENDOR_ID 0x1199
99#define NOVATELWIRELESS_VENDOR_ID 0x1410 73#define NOVATELWIRELESS_VENDOR_ID 0x1410
74#define ANYDATA_VENDOR_ID 0x16d5
100 75
101#define OPTION_PRODUCT_OLD 0x5000 76#define OPTION_PRODUCT_OLD 0x5000
102#define OPTION_PRODUCT_FUSION 0x6000 77#define OPTION_PRODUCT_FUSION 0x6000
103#define OPTION_PRODUCT_FUSION2 0x6300 78#define OPTION_PRODUCT_FUSION2 0x6300
104#define OPTION_PRODUCT_COBRA 0x6500 79#define OPTION_PRODUCT_COBRA 0x6500
80#define OPTION_PRODUCT_COBRA2 0x6600
105#define HUAWEI_PRODUCT_E600 0x1001 81#define HUAWEI_PRODUCT_E600 0x1001
106#define AUDIOVOX_PRODUCT_AIRCARD 0x0112 82#define AUDIOVOX_PRODUCT_AIRCARD 0x0112
107#define SIERRAWIRELESS_PRODUCT_MC8755 0x6802
108#define NOVATELWIRELESS_PRODUCT_U740 0x1400 83#define NOVATELWIRELESS_PRODUCT_U740 0x1400
84#define ANYDATA_PRODUCT_ID 0x6501
109 85
110static struct usb_device_id option_ids[] = { 86static struct usb_device_id option_ids[] = {
111 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) }, 87 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) },
112 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) }, 88 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) },
113 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) }, 89 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
114 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) }, 90 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) },
91 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) },
115 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 92 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
116 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) }, 93 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
117 { USB_DEVICE(SIERRAWIRELESS_VENDOR_ID, SIERRAWIRELESS_PRODUCT_MC8755) },
118 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, 94 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
95 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
119 { } /* Terminating entry */ 96 { } /* Terminating entry */
120}; 97};
121 98
@@ -124,13 +101,11 @@ static struct usb_device_id option_ids1[] = {
124 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) }, 101 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) },
125 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) }, 102 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
126 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) }, 103 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) },
104 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) },
127 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 105 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
128 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) }, 106 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
129 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, 107 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
130 { } /* Terminating entry */ 108 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
131};
132static struct usb_device_id option_ids3[] = {
133 { USB_DEVICE(SIERRAWIRELESS_VENDOR_ID, SIERRAWIRELESS_PRODUCT_MC8755) },
134 { } /* Terminating entry */ 109 { } /* Terminating entry */
135}; 110};
136 111
@@ -147,37 +122,11 @@ static struct usb_driver option_driver = {
147/* The card has three separate interfaces, which the serial driver 122/* The card has three separate interfaces, which the serial driver
148 * recognizes separately, thus num_port=1. 123 * recognizes separately, thus num_port=1.
149 */ 124 */
150static struct usb_serial_driver option_3port_device = {
151 .driver = {
152 .owner = THIS_MODULE,
153 .name = "option",
154 },
155 .description = "GSM modem (3-port)",
156 .id_table = option_ids3,
157 .num_interrupt_in = NUM_DONT_CARE,
158 .num_bulk_in = NUM_DONT_CARE,
159 .num_bulk_out = NUM_DONT_CARE,
160 .num_ports = 3,
161 .open = option_open,
162 .close = option_close,
163 .write = option_write,
164 .write_room = option_write_room,
165 .chars_in_buffer = option_chars_in_buffer,
166 .throttle = option_rx_throttle,
167 .unthrottle = option_rx_unthrottle,
168 .set_termios = option_set_termios,
169 .break_ctl = option_break_ctl,
170 .tiocmget = option_tiocmget,
171 .tiocmset = option_tiocmset,
172 .attach = option_startup,
173 .shutdown = option_shutdown,
174 .read_int_callback = option_instat_callback,
175};
176 125
177static struct usb_serial_driver option_1port_device = { 126static struct usb_serial_driver option_1port_device = {
178 .driver = { 127 .driver = {
179 .owner = THIS_MODULE, 128 .owner = THIS_MODULE,
180 .name = "option", 129 .name = "option1",
181 }, 130 },
182 .description = "GSM modem (1-port)", 131 .description = "GSM modem (1-port)",
183 .id_table = option_ids1, 132 .id_table = option_ids1,
@@ -241,9 +190,6 @@ static int __init option_init(void)
241 retval = usb_serial_register(&option_1port_device); 190 retval = usb_serial_register(&option_1port_device);
242 if (retval) 191 if (retval)
243 goto failed_1port_device_register; 192 goto failed_1port_device_register;
244 retval = usb_serial_register(&option_3port_device);
245 if (retval)
246 goto failed_3port_device_register;
247 retval = usb_register(&option_driver); 193 retval = usb_register(&option_driver);
248 if (retval) 194 if (retval)
249 goto failed_driver_register; 195 goto failed_driver_register;
@@ -253,8 +199,6 @@ static int __init option_init(void)
253 return 0; 199 return 0;
254 200
255failed_driver_register: 201failed_driver_register:
256 usb_serial_deregister (&option_3port_device);
257failed_3port_device_register:
258 usb_serial_deregister (&option_1port_device); 202 usb_serial_deregister (&option_1port_device);
259failed_1port_device_register: 203failed_1port_device_register:
260 return retval; 204 return retval;
@@ -263,7 +207,6 @@ failed_1port_device_register:
263static void __exit option_exit(void) 207static void __exit option_exit(void)
264{ 208{
265 usb_deregister (&option_driver); 209 usb_deregister (&option_driver);
266 usb_serial_deregister (&option_3port_device);
267 usb_serial_deregister (&option_1port_device); 210 usb_serial_deregister (&option_1port_device);
268} 211}
269 212
@@ -652,7 +595,6 @@ static void option_setup_urbs(struct usb_serial *serial)
652 595
653 dbg("%s", __FUNCTION__); 596 dbg("%s", __FUNCTION__);
654 597
655
656 for (i = 0; i < serial->num_ports; i++) { 598 for (i = 0; i < serial->num_ports; i++) {
657 port = serial->port[i]; 599 port = serial->port[i];
658 portdata = usb_get_serial_port_data(port); 600 portdata = usb_get_serial_port_data(port);
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index de93a2b909e7..65e4d046951a 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -27,7 +27,7 @@
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <asm/uaccess.h> 28#include <asm/uaccess.h>
29#include <linux/usb.h> 29#include <linux/usb.h>
30#include "usb-serial.h" 30#include <linux/usb/serial.h>
31#include "pl2303.h" 31#include "pl2303.h"
32 32
33/* 33/*
@@ -52,6 +52,7 @@ struct pl2303_buf {
52static struct usb_device_id id_table [] = { 52static struct usb_device_id id_table [] = {
53 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) }, 53 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) },
54 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) }, 54 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) },
55 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_DCU11) },
55 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ3) }, 56 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ3) },
56 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_PHAROS) }, 57 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_PHAROS) },
57 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) }, 58 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
@@ -78,7 +79,8 @@ static struct usb_device_id id_table [] = {
78 { USB_DEVICE(SAGEM_VENDOR_ID, SAGEM_PRODUCT_ID) }, 79 { USB_DEVICE(SAGEM_VENDOR_ID, SAGEM_PRODUCT_ID) },
79 { USB_DEVICE(LEADTEK_VENDOR_ID, LEADTEK_9531_PRODUCT_ID) }, 80 { USB_DEVICE(LEADTEK_VENDOR_ID, LEADTEK_9531_PRODUCT_ID) },
80 { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) }, 81 { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) },
81 { USB_DEVICE(OTI_VENDOR_ID, OTI_PRODUCT_ID) }, 82 { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) },
83 { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) },
82 { } /* Terminating entry */ 84 { } /* Terminating entry */
83}; 85};
84 86
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 7f29e81d3e35..55195e76eb6f 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -10,6 +10,7 @@
10#define PL2303_VENDOR_ID 0x067b 10#define PL2303_VENDOR_ID 0x067b
11#define PL2303_PRODUCT_ID 0x2303 11#define PL2303_PRODUCT_ID 0x2303
12#define PL2303_PRODUCT_ID_RSAQ2 0x04bb 12#define PL2303_PRODUCT_ID_RSAQ2 0x04bb
13#define PL2303_PRODUCT_ID_DCU11 0x1234
13#define PL2303_PRODUCT_ID_PHAROS 0xaaa0 14#define PL2303_PRODUCT_ID_PHAROS 0xaaa0
14#define PL2303_PRODUCT_ID_RSAQ3 0xaaa2 15#define PL2303_PRODUCT_ID_RSAQ3 0xaaa2
15 16
@@ -81,6 +82,10 @@
81#define SPEEDDRAGON_VENDOR_ID 0x0e55 82#define SPEEDDRAGON_VENDOR_ID 0x0e55
82#define SPEEDDRAGON_PRODUCT_ID 0x110b 83#define SPEEDDRAGON_PRODUCT_ID 0x110b
83 84
84/* Ours Technology Inc DKU-5 clone, chipset: Prolific Technology Inc */ 85/* DATAPILOT Universal-2 Phone Cable */
85#define OTI_VENDOR_ID 0x0ea0 86#define DATAPILOT_U2_VENDOR_ID 0x0731
86#define OTI_PRODUCT_ID 0x6858 87#define DATAPILOT_U2_PRODUCT_ID 0x2003
88
89/* Belkin "F5U257" Serial Adapter */
90#define BELKIN_VENDOR_ID 0x050d
91#define BELKIN_PRODUCT_ID 0x0257
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 897d8447252b..789771ecdb11 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -71,7 +71,7 @@
71#include <linux/spinlock.h> 71#include <linux/spinlock.h>
72#include <asm/uaccess.h> 72#include <asm/uaccess.h>
73#include <linux/usb.h> 73#include <linux/usb.h>
74#include "usb-serial.h" 74#include <linux/usb/serial.h>
75 75
76 76
77#ifndef CONFIG_USB_SAFE_PADDED 77#ifndef CONFIG_USB_SAFE_PADDED
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
new file mode 100644
index 000000000000..d29638daa987
--- /dev/null
+++ b/drivers/usb/serial/sierra.c
@@ -0,0 +1,75 @@
1/*
2 * Sierra Wireless CDMA Wireless Serial USB driver
3 *
4 * Current Copy modified by: Kevin Lloyd <linux@sierrawireless.com>
5 * Original Copyright (C) 2005-2006 Greg Kroah-Hartman <gregkh@suse.de>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/tty.h>
15#include <linux/module.h>
16#include <linux/usb.h>
17#include <linux/usb/serial.h>
18
19static struct usb_device_id id_table [] = {
20 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
21 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
22 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
23 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
24 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
25 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
26 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */
27 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
28 /* Following devices are supported in the airprime.c driver */
29 /* { USB_DEVICE(0x1199, 0x0112) }, */ /* Sierra Wireless AirCard 580 */
30 /* { USB_DEVICE(0x0F3D, 0x0112) }, */ /* AirPrime/Sierra PC 5220 */
31 { }
32};
33MODULE_DEVICE_TABLE(usb, id_table);
34
35static struct usb_driver sierra_driver = {
36 .name = "sierra_wireless",
37 .probe = usb_serial_probe,
38 .disconnect = usb_serial_disconnect,
39 .id_table = id_table,
40};
41
42static struct usb_serial_driver sierra_device = {
43 .driver = {
44 .owner = THIS_MODULE,
45 .name = "Sierra_Wireless",
46 },
47 .id_table = id_table,
48 .num_interrupt_in = NUM_DONT_CARE,
49 .num_bulk_in = NUM_DONT_CARE,
50 .num_bulk_out = NUM_DONT_CARE,
51 .num_ports = 3,
52};
53
54static int __init sierra_init(void)
55{
56 int retval;
57
58 retval = usb_serial_register(&sierra_device);
59 if (retval)
60 return retval;
61 retval = usb_register(&sierra_driver);
62 if (retval)
63 usb_serial_deregister(&sierra_device);
64 return retval;
65}
66
67static void __exit sierra_exit(void)
68{
69 usb_deregister(&sierra_driver);
70 usb_serial_deregister(&sierra_device);
71}
72
73module_init(sierra_init);
74module_exit(sierra_exit);
75MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index a9afff31a921..ac9b8ee52d44 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -83,8 +83,8 @@
83#include <asm/uaccess.h> 83#include <asm/uaccess.h>
84#include <asm/semaphore.h> 84#include <asm/semaphore.h>
85#include <linux/usb.h> 85#include <linux/usb.h>
86#include <linux/usb/serial.h>
86 87
87#include "usb-serial.h"
88#include "ti_usb_3410_5052.h" 88#include "ti_usb_3410_5052.h"
89#include "ti_fw_3410.h" /* firmware image for 3410 */ 89#include "ti_fw_3410.h" /* firmware image for 3410 */
90#include "ti_fw_5052.h" /* firmware image for 5052 */ 90#include "ti_fw_5052.h" /* firmware image for 5052 */
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index b59a0536ea5c..e06a41bd0f3b 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -31,7 +31,7 @@
31#include <linux/smp_lock.h> 31#include <linux/smp_lock.h>
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33#include <linux/usb.h> 33#include <linux/usb.h>
34#include "usb-serial.h" 34#include <linux/usb/serial.h>
35#include "pl2303.h" 35#include "pl2303.h"
36 36
37/* 37/*
@@ -40,6 +40,8 @@
40#define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux/" 40#define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux/"
41#define DRIVER_DESC "USB Serial Driver core" 41#define DRIVER_DESC "USB Serial Driver core"
42 42
43static void port_free(struct usb_serial_port *port);
44
43/* Driver structure we register with the USB core */ 45/* Driver structure we register with the USB core */
44static struct usb_driver usb_serial_driver = { 46static struct usb_driver usb_serial_driver = {
45 .name = "usbserial", 47 .name = "usbserial",
@@ -146,23 +148,10 @@ static void destroy_serial(struct kref *kref)
146 port = serial->port[i]; 148 port = serial->port[i];
147 if (!port) 149 if (!port)
148 continue; 150 continue;
149 usb_kill_urb(port->read_urb); 151 port_free(port);
150 usb_free_urb(port->read_urb);
151 usb_kill_urb(port->write_urb);
152 usb_free_urb(port->write_urb);
153 usb_kill_urb(port->interrupt_in_urb);
154 usb_free_urb(port->interrupt_in_urb);
155 usb_kill_urb(port->interrupt_out_urb);
156 usb_free_urb(port->interrupt_out_urb);
157 kfree(port->bulk_in_buffer);
158 kfree(port->bulk_out_buffer);
159 kfree(port->interrupt_in_buffer);
160 kfree(port->interrupt_out_buffer);
161 } 152 }
162 } 153 }
163 154
164 flush_scheduled_work(); /* port->work */
165
166 usb_put_dev(serial->dev); 155 usb_put_dev(serial->dev);
167 156
168 /* free up any memory that we allocated */ 157 /* free up any memory that we allocated */
@@ -475,8 +464,10 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
475 length += sprintf (page+length, " path:%s", tmp); 464 length += sprintf (page+length, " path:%s", tmp);
476 465
477 length += sprintf (page+length, "\n"); 466 length += sprintf (page+length, "\n");
478 if ((length + begin) > (off + count)) 467 if ((length + begin) > (off + count)) {
468 usb_serial_put(serial);
479 goto done; 469 goto done;
470 }
480 if ((length + begin) < off) { 471 if ((length + begin) < off) {
481 begin += length; 472 begin += length;
482 length = 0; 473 length = 0;
@@ -564,6 +555,11 @@ static void port_release(struct device *dev)
564 struct usb_serial_port *port = to_usb_serial_port(dev); 555 struct usb_serial_port *port = to_usb_serial_port(dev);
565 556
566 dbg ("%s - %s", __FUNCTION__, dev->bus_id); 557 dbg ("%s - %s", __FUNCTION__, dev->bus_id);
558 port_free(port);
559}
560
561static void port_free(struct usb_serial_port *port)
562{
567 usb_kill_urb(port->read_urb); 563 usb_kill_urb(port->read_urb);
568 usb_free_urb(port->read_urb); 564 usb_free_urb(port->read_urb);
569 usb_kill_urb(port->write_urb); 565 usb_kill_urb(port->write_urb);
@@ -576,6 +572,7 @@ static void port_release(struct device *dev)
576 kfree(port->bulk_out_buffer); 572 kfree(port->bulk_out_buffer);
577 kfree(port->interrupt_in_buffer); 573 kfree(port->interrupt_in_buffer);
578 kfree(port->interrupt_out_buffer); 574 kfree(port->interrupt_out_buffer);
575 flush_scheduled_work(); /* port->work */
579 kfree(port); 576 kfree(port);
580} 577}
581 578
diff --git a/drivers/usb/serial/usb-serial.h b/drivers/usb/serial/usb-serial.h
deleted file mode 100644
index 0f2802a60194..000000000000
--- a/drivers/usb/serial/usb-serial.h
+++ /dev/null
@@ -1,300 +0,0 @@
1/*
2 * USB Serial Converter driver
3 *
4 * Copyright (C) 1999 - 2005
5 * Greg Kroah-Hartman (greg@kroah.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License.
10 *
11 */
12
13
14#ifndef __LINUX_USB_SERIAL_H
15#define __LINUX_USB_SERIAL_H
16
17#include <linux/kref.h>
18#include <linux/mutex.h>
19
20#define SERIAL_TTY_MAJOR 188 /* Nice legal number now */
21#define SERIAL_TTY_MINORS 255 /* loads of devices :) */
22
23#define MAX_NUM_PORTS 8 /* The maximum number of ports one device can grab at once */
24
25/* parity check flag */
26#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
27
28/**
29 * usb_serial_port: structure for the specific ports of a device.
30 * @serial: pointer back to the struct usb_serial owner of this port.
31 * @tty: pointer to the corresponding tty for this port.
32 * @lock: spinlock to grab when updating portions of this structure.
33 * @mutex: mutex used to synchronize serial_open() and serial_close()
34 * access for this port.
35 * @number: the number of the port (the minor number).
36 * @interrupt_in_buffer: pointer to the interrupt in buffer for this port.
37 * @interrupt_in_urb: pointer to the interrupt in struct urb for this port.
38 * @interrupt_in_endpointAddress: endpoint address for the interrupt in pipe
39 * for this port.
40 * @interrupt_out_buffer: pointer to the interrupt out buffer for this port.
41 * @interrupt_out_size: the size of the interrupt_out_buffer, in bytes.
42 * @interrupt_out_urb: pointer to the interrupt out struct urb for this port.
43 * @interrupt_out_endpointAddress: endpoint address for the interrupt out pipe
44 * for this port.
45 * @bulk_in_buffer: pointer to the bulk in buffer for this port.
46 * @read_urb: pointer to the bulk in struct urb for this port.
47 * @bulk_in_endpointAddress: endpoint address for the bulk in pipe for this
48 * port.
49 * @bulk_out_buffer: pointer to the bulk out buffer for this port.
50 * @bulk_out_size: the size of the bulk_out_buffer, in bytes.
51 * @write_urb: pointer to the bulk out struct urb for this port.
52 * @bulk_out_endpointAddress: endpoint address for the bulk out pipe for this
53 * port.
54 * @write_wait: a wait_queue_head_t used by the port.
55 * @work: work queue entry for the line discipline waking up.
56 * @open_count: number of times this port has been opened.
57 *
58 * This structure is used by the usb-serial core and drivers for the specific
59 * ports of a device.
60 */
61struct usb_serial_port {
62 struct usb_serial * serial;
63 struct tty_struct * tty;
64 spinlock_t lock;
65 struct mutex mutex;
66 unsigned char number;
67
68 unsigned char * interrupt_in_buffer;
69 struct urb * interrupt_in_urb;
70 __u8 interrupt_in_endpointAddress;
71
72 unsigned char * interrupt_out_buffer;
73 int interrupt_out_size;
74 struct urb * interrupt_out_urb;
75 __u8 interrupt_out_endpointAddress;
76
77 unsigned char * bulk_in_buffer;
78 int bulk_in_size;
79 struct urb * read_urb;
80 __u8 bulk_in_endpointAddress;
81
82 unsigned char * bulk_out_buffer;
83 int bulk_out_size;
84 struct urb * write_urb;
85 int write_urb_busy;
86 __u8 bulk_out_endpointAddress;
87
88 wait_queue_head_t write_wait;
89 struct work_struct work;
90 int open_count;
91 struct device dev;
92};
93#define to_usb_serial_port(d) container_of(d, struct usb_serial_port, dev)
94
95/* get and set the port private data pointer helper functions */
96static inline void *usb_get_serial_port_data (struct usb_serial_port *port)
97{
98 return dev_get_drvdata(&port->dev);
99}
100
101static inline void usb_set_serial_port_data (struct usb_serial_port *port, void *data)
102{
103 dev_set_drvdata(&port->dev, data);
104}
105
106/**
107 * usb_serial - structure used by the usb-serial core for a device
108 * @dev: pointer to the struct usb_device for this device
109 * @type: pointer to the struct usb_serial_driver for this device
110 * @interface: pointer to the struct usb_interface for this device
111 * @minor: the starting minor number for this device
112 * @num_ports: the number of ports this device has
113 * @num_interrupt_in: number of interrupt in endpoints we have
114 * @num_interrupt_out: number of interrupt out endpoints we have
115 * @num_bulk_in: number of bulk in endpoints we have
116 * @num_bulk_out: number of bulk out endpoints we have
117 * @port: array of struct usb_serial_port structures for the different ports.
118 * @private: place to put any driver specific information that is needed. The
119 * usb-serial driver is required to manage this data, the usb-serial core
120 * will not touch this. Use usb_get_serial_data() and
121 * usb_set_serial_data() to access this.
122 */
123struct usb_serial {
124 struct usb_device * dev;
125 struct usb_serial_driver * type;
126 struct usb_interface * interface;
127 unsigned char minor;
128 unsigned char num_ports;
129 unsigned char num_port_pointers;
130 char num_interrupt_in;
131 char num_interrupt_out;
132 char num_bulk_in;
133 char num_bulk_out;
134 struct usb_serial_port * port[MAX_NUM_PORTS];
135 struct kref kref;
136 void * private;
137};
138#define to_usb_serial(d) container_of(d, struct usb_serial, kref)
139
140#define NUM_DONT_CARE (-1)
141
142/* get and set the serial private data pointer helper functions */
143static inline void *usb_get_serial_data (struct usb_serial *serial)
144{
145 return serial->private;
146}
147
148static inline void usb_set_serial_data (struct usb_serial *serial, void *data)
149{
150 serial->private = data;
151}
152
153/**
154 * usb_serial_driver - describes a usb serial driver
155 * @description: pointer to a string that describes this driver. This string used
156 * in the syslog messages when a device is inserted or removed.
157 * @id_table: pointer to a list of usb_device_id structures that define all
158 * of the devices this structure can support.
159 * @num_interrupt_in: the number of interrupt in endpoints this device will
160 * have.
161 * @num_interrupt_out: the number of interrupt out endpoints this device will
162 * have.
163 * @num_bulk_in: the number of bulk in endpoints this device will have.
164 * @num_bulk_out: the number of bulk out endpoints this device will have.
165 * @num_ports: the number of different ports this device will have.
166 * @calc_num_ports: pointer to a function to determine how many ports this
167 * device has dynamically. It will be called after the probe()
168 * callback is called, but before attach()
169 * @probe: pointer to the driver's probe function.
170 * This will be called when the device is inserted into the system,
171 * but before the device has been fully initialized by the usb_serial
172 * subsystem. Use this function to download any firmware to the device,
173 * or any other early initialization that might be needed.
174 * Return 0 to continue on with the initialization sequence. Anything
175 * else will abort it.
176 * @attach: pointer to the driver's attach function.
177 * This will be called when the struct usb_serial structure is fully set
178 * set up. Do any local initialization of the device, or any private
179 * memory structure allocation at this point in time.
180 * @shutdown: pointer to the driver's shutdown function. This will be
181 * called when the device is removed from the system.
182 *
183 * This structure is defines a USB Serial driver. It provides all of
184 * the information that the USB serial core code needs. If the function
185 * pointers are defined, then the USB serial core code will call them when
186 * the corresponding tty port functions are called. If they are not
187 * called, the generic serial function will be used instead.
188 *
189 * The driver.owner field should be set to the module owner of this driver.
190 * The driver.name field should be set to the name of this driver (remember
191 * it will show up in sysfs, so it needs to be short and to the point.
192 * Useing the module name is a good idea.)
193 */
194struct usb_serial_driver {
195 const char *description;
196 const struct usb_device_id *id_table;
197 char num_interrupt_in;
198 char num_interrupt_out;
199 char num_bulk_in;
200 char num_bulk_out;
201 char num_ports;
202
203 struct list_head driver_list;
204 struct device_driver driver;
205
206 int (*probe) (struct usb_serial *serial, const struct usb_device_id *id);
207 int (*attach) (struct usb_serial *serial);
208 int (*calc_num_ports) (struct usb_serial *serial);
209
210 void (*shutdown) (struct usb_serial *serial);
211
212 int (*port_probe) (struct usb_serial_port *port);
213 int (*port_remove) (struct usb_serial_port *port);
214
215 /* serial function calls */
216 int (*open) (struct usb_serial_port *port, struct file * filp);
217 void (*close) (struct usb_serial_port *port, struct file * filp);
218 int (*write) (struct usb_serial_port *port, const unsigned char *buf, int count);
219 int (*write_room) (struct usb_serial_port *port);
220 int (*ioctl) (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
221 void (*set_termios) (struct usb_serial_port *port, struct termios * old);
222 void (*break_ctl) (struct usb_serial_port *port, int break_state);
223 int (*chars_in_buffer) (struct usb_serial_port *port);
224 void (*throttle) (struct usb_serial_port *port);
225 void (*unthrottle) (struct usb_serial_port *port);
226 int (*tiocmget) (struct usb_serial_port *port, struct file *file);
227 int (*tiocmset) (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear);
228
229 void (*read_int_callback)(struct urb *urb, struct pt_regs *regs);
230 void (*write_int_callback)(struct urb *urb, struct pt_regs *regs);
231 void (*read_bulk_callback)(struct urb *urb, struct pt_regs *regs);
232 void (*write_bulk_callback)(struct urb *urb, struct pt_regs *regs);
233};
234#define to_usb_serial_driver(d) container_of(d, struct usb_serial_driver, driver)
235
236extern int usb_serial_register(struct usb_serial_driver *driver);
237extern void usb_serial_deregister(struct usb_serial_driver *driver);
238extern void usb_serial_port_softint(struct usb_serial_port *port);
239
240extern int usb_serial_probe(struct usb_interface *iface, const struct usb_device_id *id);
241extern void usb_serial_disconnect(struct usb_interface *iface);
242
243extern int ezusb_writememory (struct usb_serial *serial, int address, unsigned char *data, int length, __u8 bRequest);
244extern int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit);
245
246/* USB Serial console functions */
247#ifdef CONFIG_USB_SERIAL_CONSOLE
248extern void usb_serial_console_init (int debug, int minor);
249extern void usb_serial_console_exit (void);
250extern void usb_serial_console_disconnect(struct usb_serial *serial);
251#else
252static inline void usb_serial_console_init (int debug, int minor) { }
253static inline void usb_serial_console_exit (void) { }
254static inline void usb_serial_console_disconnect(struct usb_serial *serial) {}
255#endif
256
257/* Functions needed by other parts of the usbserial core */
258extern struct usb_serial *usb_serial_get_by_index (unsigned int minor);
259extern void usb_serial_put(struct usb_serial *serial);
260extern int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp);
261extern int usb_serial_generic_write (struct usb_serial_port *port, const unsigned char *buf, int count);
262extern void usb_serial_generic_close (struct usb_serial_port *port, struct file *filp);
263extern int usb_serial_generic_write_room (struct usb_serial_port *port);
264extern int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port);
265extern void usb_serial_generic_read_bulk_callback (struct urb *urb, struct pt_regs *regs);
266extern void usb_serial_generic_write_bulk_callback (struct urb *urb, struct pt_regs *regs);
267extern void usb_serial_generic_shutdown (struct usb_serial *serial);
268extern int usb_serial_generic_register (int debug);
269extern void usb_serial_generic_deregister (void);
270
271extern int usb_serial_bus_register (struct usb_serial_driver *device);
272extern void usb_serial_bus_deregister (struct usb_serial_driver *device);
273
274extern struct usb_serial_driver usb_serial_generic_device;
275extern struct bus_type usb_serial_bus_type;
276extern struct tty_driver *usb_serial_tty_driver;
277
278static inline void usb_serial_debug_data(int debug,
279 struct device *dev,
280 const char *function, int size,
281 const unsigned char *data)
282{
283 int i;
284
285 if (debug) {
286 dev_printk(KERN_DEBUG, dev, "%s - length = %d, data = ", function, size);
287 for (i = 0; i < size; ++i)
288 printk ("%.2x ", data[i]);
289 printk ("\n");
290 }
291}
292
293/* Use our own dbg macro */
294#undef dbg
295#define dbg(format, arg...) do { if (debug) printk(KERN_DEBUG "%s: " format "\n" , __FILE__ , ## arg); } while (0)
296
297
298
299#endif /* ifdef __LINUX_USB_SERIAL_H */
300
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index 95a2936e902e..88949f7884ca 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -25,7 +25,7 @@
25#include <linux/spinlock.h> 25#include <linux/spinlock.h>
26#include <asm/uaccess.h> 26#include <asm/uaccess.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include "usb-serial.h" 28#include <linux/usb/serial.h>
29#include "visor.h" 29#include "visor.h"
30 30
31/* 31/*
@@ -302,7 +302,6 @@ static int visor_open (struct usb_serial_port *port, struct file *filp)
302 spin_lock_irqsave(&priv->lock, flags); 302 spin_lock_irqsave(&priv->lock, flags);
303 priv->bytes_in = 0; 303 priv->bytes_in = 0;
304 priv->bytes_out = 0; 304 priv->bytes_out = 0;
305 priv->outstanding_urbs = 0;
306 priv->throttled = 0; 305 priv->throttled = 0;
307 spin_unlock_irqrestore(&priv->lock, flags); 306 spin_unlock_irqrestore(&priv->lock, flags);
308 307
@@ -435,13 +434,25 @@ static int visor_write (struct usb_serial_port *port, const unsigned char *buf,
435 434
436static int visor_write_room (struct usb_serial_port *port) 435static int visor_write_room (struct usb_serial_port *port)
437{ 436{
437 struct visor_private *priv = usb_get_serial_port_data(port);
438 unsigned long flags;
439
438 dbg("%s - port %d", __FUNCTION__, port->number); 440 dbg("%s - port %d", __FUNCTION__, port->number);
439 441
440 /* 442 /*
441 * We really can take anything the user throws at us 443 * We really can take anything the user throws at us
442 * but let's pick a nice big number to tell the tty 444 * but let's pick a nice big number to tell the tty
443 * layer that we have lots of free space 445 * layer that we have lots of free space, unless we don't.
444 */ 446 */
447
448 spin_lock_irqsave(&priv->lock, flags);
449 if (priv->outstanding_urbs > URB_UPPER_LIMIT * 2 / 3) {
450 spin_unlock_irqrestore(&priv->lock, flags);
451 dbg("%s - write limit hit\n", __FUNCTION__);
452 return 0;
453 }
454 spin_unlock_irqrestore(&priv->lock, flags);
455
445 return 2048; 456 return 2048;
446} 457}
447 458
@@ -758,15 +769,22 @@ static int visor_calc_num_ports (struct usb_serial *serial)
758 769
759static int generic_startup(struct usb_serial *serial) 770static int generic_startup(struct usb_serial *serial)
760{ 771{
772 struct usb_serial_port **ports = serial->port;
761 struct visor_private *priv; 773 struct visor_private *priv;
762 int i; 774 int i;
763 775
764 for (i = 0; i < serial->num_ports; ++i) { 776 for (i = 0; i < serial->num_ports; ++i) {
765 priv = kzalloc (sizeof(*priv), GFP_KERNEL); 777 priv = kzalloc (sizeof(*priv), GFP_KERNEL);
766 if (!priv) 778 if (!priv) {
779 while (i-- != 0) {
780 priv = usb_get_serial_port_data(ports[i]);
781 usb_set_serial_port_data(ports[i], NULL);
782 kfree(priv);
783 }
767 return -ENOMEM; 784 return -ENOMEM;
785 }
768 spin_lock_init(&priv->lock); 786 spin_lock_init(&priv->lock);
769 usb_set_serial_port_data(serial->port[i], priv); 787 usb_set_serial_port_data(ports[i], priv);
770 } 788 }
771 return 0; 789 return 0;
772} 790}
@@ -876,7 +894,18 @@ static int clie_5_attach (struct usb_serial *serial)
876 894
877static void visor_shutdown (struct usb_serial *serial) 895static void visor_shutdown (struct usb_serial *serial)
878{ 896{
897 struct visor_private *priv;
898 int i;
899
879 dbg("%s", __FUNCTION__); 900 dbg("%s", __FUNCTION__);
901
902 for (i = 0; i < serial->num_ports; i++) {
903 priv = usb_get_serial_port_data(serial->port[i]);
904 if (priv) {
905 usb_set_serial_port_data(serial->port[i], NULL);
906 kfree(priv);
907 }
908 }
880} 909}
881 910
882static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 911static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index 540438c3f381..6e6c7934be32 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -79,7 +79,7 @@
79#include <linux/usb.h> 79#include <linux/usb.h>
80#include <linux/serial_reg.h> 80#include <linux/serial_reg.h>
81#include <linux/serial.h> 81#include <linux/serial.h>
82#include "usb-serial.h" 82#include <linux/usb/serial.h>
83#include "whiteheat_fw.h" /* firmware for the ConnectTech WhiteHEAT device */ 83#include "whiteheat_fw.h" /* firmware for the ConnectTech WhiteHEAT device */
84#include "whiteheat.h" /* WhiteHEAT specific commands */ 84#include "whiteheat.h" /* WhiteHEAT specific commands */
85 85
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 5715291ba540..a4b7df9ff8c1 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -112,13 +112,11 @@ static int slave_configure(struct scsi_device *sdev)
112 if (sdev->scsi_level < SCSI_2) 112 if (sdev->scsi_level < SCSI_2)
113 sdev->scsi_level = sdev->sdev_target->scsi_level = SCSI_2; 113 sdev->scsi_level = sdev->sdev_target->scsi_level = SCSI_2;
114 114
115 /* According to the technical support people at Genesys Logic, 115 /* Many devices have trouble transfering more than 32KB at a time,
116 * devices using their chips have problems transferring more than 116 * while others have trouble with more than 64K. At this time we
117 * 32 KB at a time. In practice people have found that 64 KB 117 * are limiting both to 32K (64 sectores).
118 * works okay and that's what Windows does. But we'll be 118 */
119 * conservative; people can always use the sysfs interface to 119 if ((us->flags & US_FL_MAX_SECTORS_64) &&
120 * increase max_sectors. */
121 if (le16_to_cpu(us->pusb_dev->descriptor.idVendor) == USB_VENDOR_ID_GENESYS &&
122 sdev->request_queue->max_sectors > 64) 120 sdev->request_queue->max_sectors > 64)
123 blk_queue_max_sectors(sdev->request_queue, 64); 121 blk_queue_max_sectors(sdev->request_queue, 64);
124 122
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index eb7188b3565c..d6acc92a4ae3 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -180,7 +180,7 @@ static int usb_stor_msg_common(struct us_data *us, int timeout)
180 if (timeleft <= 0) { 180 if (timeleft <= 0) {
181 US_DEBUGP("%s -- cancelling URB\n", 181 US_DEBUGP("%s -- cancelling URB\n",
182 timeleft == 0 ? "Timeout" : "Signal"); 182 timeleft == 0 ? "Timeout" : "Signal");
183 usb_unlink_urb(us->current_urb); 183 usb_kill_urb(us->current_urb);
184 } 184 }
185 185
186 /* return the URB status */ 186 /* return the URB status */
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index c7e84e653df9..b130e170b4a8 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -112,6 +112,19 @@ UNUSUAL_DEV( 0x0411, 0x001c, 0x0113, 0x0113,
112 US_SC_DEVICE, US_PR_DEVICE, NULL, 112 US_SC_DEVICE, US_PR_DEVICE, NULL,
113 US_FL_FIX_INQUIRY ), 113 US_FL_FIX_INQUIRY ),
114 114
115/* Submitted by Ernestas Vaiciukevicius <ernisv@gmail.com> */
116UNUSUAL_DEV( 0x0419, 0x0100, 0x0100, 0x0100,
117 "Samsung Info. Systems America, Inc.",
118 "MP3 Player",
119 US_SC_DEVICE, US_PR_DEVICE, NULL,
120 US_FL_IGNORE_RESIDUE ),
121
122/* Reported by Orgad Shaneh <orgads@gmail.com> */
123UNUSUAL_DEV( 0x0419, 0xaace, 0x0100, 0x0100,
124 "Samsung", "MP3 Player",
125 US_SC_DEVICE, US_PR_DEVICE, NULL,
126 US_FL_IGNORE_RESIDUE ),
127
115/* Reported by Christian Leber <christian@leber.de> */ 128/* Reported by Christian Leber <christian@leber.de> */
116UNUSUAL_DEV( 0x0419, 0xaaf5, 0x0100, 0x0100, 129UNUSUAL_DEV( 0x0419, 0xaaf5, 0x0100, 0x0100,
117 "TrekStor", 130 "TrekStor",
@@ -132,6 +145,21 @@ UNUSUAL_DEV( 0x0420, 0x0001, 0x0100, 0x0100,
132 US_SC_DEVICE, US_PR_DEVICE, NULL, 145 US_SC_DEVICE, US_PR_DEVICE, NULL,
133 US_FL_IGNORE_RESIDUE ), 146 US_FL_IGNORE_RESIDUE ),
134 147
148/* Reported by Mario Rettig <mariorettig@web.de> */
149UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100,
150 "Nokia",
151 "Nokia 3250",
152 US_SC_DEVICE, US_PR_DEVICE, NULL,
153 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
154
155/* Reported by Sumedha Swamy <sumedhaswamy@gmail.com> and
156 * Einar Th. Einarsson <einarthered@gmail.com> */
157UNUSUAL_DEV( 0x0421, 0x0444, 0x0100, 0x0100,
158 "Nokia",
159 "N91",
160 US_SC_DEVICE, US_PR_DEVICE, NULL,
161 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
162
135/* Reported by Jiri Slaby <jirislaby@gmail.com> and 163/* Reported by Jiri Slaby <jirislaby@gmail.com> and
136 * Rene C. Castberg <Rene@Castberg.org> */ 164 * Rene C. Castberg <Rene@Castberg.org> */
137UNUSUAL_DEV( 0x0421, 0x0446, 0x0100, 0x0100, 165UNUSUAL_DEV( 0x0421, 0x0446, 0x0100, 0x0100,
@@ -140,6 +168,13 @@ UNUSUAL_DEV( 0x0421, 0x0446, 0x0100, 0x0100,
140 US_SC_DEVICE, US_PR_DEVICE, NULL, 168 US_SC_DEVICE, US_PR_DEVICE, NULL,
141 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), 169 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
142 170
171/* Reported by Matthew Bloch <matthew@bytemark.co.uk> */
172UNUSUAL_DEV( 0x0421, 0x044e, 0x0100, 0x0100,
173 "Nokia",
174 "E61",
175 US_SC_DEVICE, US_PR_DEVICE, NULL,
176 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
177
143/* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */ 178/* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */
144UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210, 179UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210,
145 "SMSC", 180 "SMSC",
@@ -206,16 +241,6 @@ UNUSUAL_DEV( 0x0482, 0x0103, 0x0100, 0x0100,
206 "Finecam S5", 241 "Finecam S5",
207 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_FIX_INQUIRY), 242 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_FIX_INQUIRY),
208 243
209/* Patch for Kyocera Finecam L3
210 * Submitted by Michael Krauth <michael.krauth@web.de>
211 * and Alessandro Fracchetti <al.fracchetti@tin.it>
212 */
213UNUSUAL_DEV( 0x0482, 0x0105, 0x0100, 0x0100,
214 "Kyocera",
215 "Finecam L3",
216 US_SC_SCSI, US_PR_BULK, NULL,
217 US_FL_FIX_INQUIRY),
218
219/* Reported by Paul Stewart <stewart@wetlogic.net> 244/* Reported by Paul Stewart <stewart@wetlogic.net>
220 * This entry is needed because the device reports Sub=ff */ 245 * This entry is needed because the device reports Sub=ff */
221UNUSUAL_DEV( 0x04a4, 0x0004, 0x0001, 0x0001, 246UNUSUAL_DEV( 0x04a4, 0x0004, 0x0001, 0x0001,
@@ -473,10 +498,11 @@ UNUSUAL_DEV( 0x054c, 0x0010, 0x0106, 0x0450,
473 US_SC_SCSI, US_PR_DEVICE, NULL, 498 US_SC_SCSI, US_PR_DEVICE, NULL,
474 US_FL_SINGLE_LUN | US_FL_NOT_LOCKABLE | US_FL_NO_WP_DETECT ), 499 US_FL_SINGLE_LUN | US_FL_NOT_LOCKABLE | US_FL_NO_WP_DETECT ),
475 500
476/* This entry is needed because the device reports Sub=ff */ 501/* Submitted by Lars Jacob <jacob.lars@googlemail.com>
477UNUSUAL_DEV( 0x054c, 0x0010, 0x0500, 0x0600, 502 * This entry is needed because the device reports Sub=ff */
503UNUSUAL_DEV( 0x054c, 0x0010, 0x0500, 0x0610,
478 "Sony", 504 "Sony",
479 "DSC-T1/T5", 505 "DSC-T1/T5/H5",
480 US_SC_8070, US_PR_DEVICE, NULL, 506 US_SC_8070, US_PR_DEVICE, NULL,
481 US_FL_SINGLE_LUN ), 507 US_FL_SINGLE_LUN ),
482 508
@@ -563,6 +589,13 @@ UNUSUAL_DEV( 0x054c, 0x0099, 0x0000, 0x9999,
563 US_SC_DEVICE, US_PR_DEVICE, NULL, 589 US_SC_DEVICE, US_PR_DEVICE, NULL,
564 US_FL_FIX_INQUIRY ), 590 US_FL_FIX_INQUIRY ),
565 591
592/* floppy reports multiple luns */
593UNUSUAL_DEV( 0x055d, 0x2020, 0x0000, 0x0210,
594 "SAMSUNG",
595 "SFD-321U [FW 0C]",
596 US_SC_DEVICE, US_PR_DEVICE, NULL,
597 US_FL_SINGLE_LUN ),
598
566 599
567UNUSUAL_DEV( 0x057b, 0x0000, 0x0000, 0x0299, 600UNUSUAL_DEV( 0x057b, 0x0000, 0x0000, 0x0299,
568 "Y-E Data", 601 "Y-E Data",
@@ -598,18 +631,6 @@ UNUSUAL_DEV( 0x0595, 0x4343, 0x0000, 0x2210,
598 "Digital Camera EX-20 DSC", 631 "Digital Camera EX-20 DSC",
599 US_SC_8070, US_PR_DEVICE, NULL, 0 ), 632 US_SC_8070, US_PR_DEVICE, NULL, 0 ),
600 633
601/* The entry was here before I took over, and had US_SC_RBC. It turns
602 * out that isn't needed. Additionally, Torsten Eriksson
603 * <Torsten.Eriksson@bergianska.se> is able to use his device fine
604 * without this entry at all - but I don't suspect that will be true
605 * for all users (the protocol is likely needed), so is staying at
606 * this time. - Phil Dibowitz <phil@ipom.com>
607 */
608UNUSUAL_DEV( 0x059f, 0xa601, 0x0200, 0x0200,
609 "LaCie",
610 "USB Hard Disk",
611 US_SC_DEVICE, US_PR_CB, NULL, 0 ),
612
613/* Submitted by Joel Bourquard <numlock@freesurf.ch> 634/* Submitted by Joel Bourquard <numlock@freesurf.ch>
614 * Some versions of this device need the SubClass and Protocol overrides 635 * Some versions of this device need the SubClass and Protocol overrides
615 * while others don't. 636 * while others don't.
@@ -708,18 +729,22 @@ UNUSUAL_DEV( 0x05dc, 0xb002, 0x0000, 0x0113,
708 * They were originally reported by Alexander Oltu 729 * They were originally reported by Alexander Oltu
709 * <alexander@all-2.com> and Peter Marks <peter.marks@turner.com> 730 * <alexander@all-2.com> and Peter Marks <peter.marks@turner.com>
710 * respectively. 731 * respectively.
732 *
733 * US_FL_GO_SLOW and US_FL_MAX_SECTORS_64 added by Phil Dibowitz
734 * <phil@ipom.com> as these flags were made and hard-coded
735 * special-cases were pulled from scsiglue.c.
711 */ 736 */
712UNUSUAL_DEV( 0x05e3, 0x0701, 0x0000, 0xffff, 737UNUSUAL_DEV( 0x05e3, 0x0701, 0x0000, 0xffff,
713 "Genesys Logic", 738 "Genesys Logic",
714 "USB to IDE Optical", 739 "USB to IDE Optical",
715 US_SC_DEVICE, US_PR_DEVICE, NULL, 740 US_SC_DEVICE, US_PR_DEVICE, NULL,
716 US_FL_GO_SLOW ), 741 US_FL_GO_SLOW | US_FL_MAX_SECTORS_64 ),
717 742
718UNUSUAL_DEV( 0x05e3, 0x0702, 0x0000, 0xffff, 743UNUSUAL_DEV( 0x05e3, 0x0702, 0x0000, 0xffff,
719 "Genesys Logic", 744 "Genesys Logic",
720 "USB to IDE Disk", 745 "USB to IDE Disk",
721 US_SC_DEVICE, US_PR_DEVICE, NULL, 746 US_SC_DEVICE, US_PR_DEVICE, NULL,
722 US_FL_GO_SLOW ), 747 US_FL_GO_SLOW | US_FL_MAX_SECTORS_64 ),
723 748
724/* Reported by Hanno Boeck <hanno@gmx.de> 749/* Reported by Hanno Boeck <hanno@gmx.de>
725 * Taken from the Lycoris Kernel */ 750 * Taken from the Lycoris Kernel */
@@ -1073,7 +1098,15 @@ UNUSUAL_DEV( 0x0a17, 0x006, 0x0000, 0xffff,
1073 "Optio S/S4", 1098 "Optio S/S4",
1074 US_SC_DEVICE, US_PR_DEVICE, NULL, 1099 US_SC_DEVICE, US_PR_DEVICE, NULL,
1075 US_FL_FIX_INQUIRY ), 1100 US_FL_FIX_INQUIRY ),
1076 1101
1102/* This is a virtual windows driver CD, which the zd1211rw driver automatically
1103 * converts into a WLAN device. */
1104UNUSUAL_DEV( 0x0ace, 0x2011, 0x0101, 0x0101,
1105 "ZyXEL",
1106 "G-220F USB-WLAN Install",
1107 US_SC_DEVICE, US_PR_DEVICE, NULL,
1108 US_FL_IGNORE_DEVICE ),
1109
1077#ifdef CONFIG_USB_STORAGE_ISD200 1110#ifdef CONFIG_USB_STORAGE_ISD200
1078UNUSUAL_DEV( 0x0bf6, 0xa001, 0x0100, 0x0110, 1111UNUSUAL_DEV( 0x0bf6, 0xa001, 0x0100, 0x0110,
1079 "ATI", 1112 "ATI",
@@ -1196,6 +1229,24 @@ UNUSUAL_DEV( 0x0ea0, 0x6828, 0x0110, 0x0110,
1196 US_SC_DEVICE, US_PR_DEVICE, NULL, 1229 US_SC_DEVICE, US_PR_DEVICE, NULL,
1197 US_FL_IGNORE_RESIDUE ), 1230 US_FL_IGNORE_RESIDUE ),
1198 1231
1232/* Reported by Benjamin Schiller <sbenni@gmx.de>
1233 * It is also sold by Easylite as DJ 20 */
1234UNUSUAL_DEV( 0x0ed1, 0x7636, 0x0103, 0x0103,
1235 "Typhoon",
1236 "My DJ 1820",
1237 US_SC_DEVICE, US_PR_DEVICE, NULL,
1238 US_FL_IGNORE_RESIDUE | US_FL_GO_SLOW | US_FL_MAX_SECTORS_64),
1239
1240/* David Kuehling <dvdkhlng@gmx.de>:
1241 * for MP3-Player AVOX WSX-300ER (bought in Japan). Reports lots of SCSI
1242 * errors when trying to write.
1243 */
1244UNUSUAL_DEV( 0x0f19, 0x0105, 0x0100, 0x0100,
1245 "C-MEX",
1246 "A-VOX",
1247 US_SC_DEVICE, US_PR_DEVICE, NULL,
1248 US_FL_IGNORE_RESIDUE ),
1249
1199/* Reported by Michael Stattmann <michael@stattmann.com> */ 1250/* Reported by Michael Stattmann <michael@stattmann.com> */
1200UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000, 1251UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000,
1201 "Sony Ericsson", 1252 "Sony Ericsson",
@@ -1203,11 +1254,18 @@ UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000,
1203 US_SC_DEVICE, US_PR_DEVICE, NULL, 1254 US_SC_DEVICE, US_PR_DEVICE, NULL,
1204 US_FL_NO_WP_DETECT ), 1255 US_FL_NO_WP_DETECT ),
1205 1256
1257/* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */
1258UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000,
1259 "Sony Ericsson",
1260 "M600i",
1261 US_SC_DEVICE, US_PR_DEVICE, NULL,
1262 US_FL_FIX_CAPACITY ),
1263
1206/* Reported by Kevin Cernekee <kpc-usbdev@gelato.uiuc.edu> 1264/* Reported by Kevin Cernekee <kpc-usbdev@gelato.uiuc.edu>
1207 * Tested on hardware version 1.10. 1265 * Tested on hardware version 1.10.
1208 * Entry is needed only for the initializer function override. 1266 * Entry is needed only for the initializer function override.
1209 */ 1267 */
1210UNUSUAL_DEV( 0x1019, 0x0c55, 0x0000, 0x9999, 1268UNUSUAL_DEV( 0x1019, 0x0c55, 0x0110, 0x0110,
1211 "Desknote", 1269 "Desknote",
1212 "UCR-61S2B", 1270 "UCR-61S2B",
1213 US_SC_DEVICE, US_PR_DEVICE, usb_stor_ucr61s2b_init, 1271 US_SC_DEVICE, US_PR_DEVICE, usb_stor_ucr61s2b_init,
@@ -1227,6 +1285,15 @@ UNUSUAL_DEV( 0x1370, 0x6828, 0x0110, 0x0110,
1227 US_SC_DEVICE, US_PR_DEVICE, NULL, 1285 US_SC_DEVICE, US_PR_DEVICE, NULL,
1228 US_FL_IGNORE_RESIDUE ), 1286 US_FL_IGNORE_RESIDUE ),
1229 1287
1288/* patch submitted by Davide Perini <perini.davide@dpsoftware.org>
1289 * and Renato Perini <rperini@email.it>
1290 */
1291UNUSUAL_DEV( 0x22b8, 0x3010, 0x0001, 0x0001,
1292 "Motorola",
1293 "RAZR V3x",
1294 US_SC_DEVICE, US_PR_DEVICE, NULL,
1295 US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ),
1296
1230/* Reported by Radovan Garabik <garabik@kassiopeia.juls.savba.sk> */ 1297/* Reported by Radovan Garabik <garabik@kassiopeia.juls.savba.sk> */
1231UNUSUAL_DEV( 0x2735, 0x100b, 0x0000, 0x9999, 1298UNUSUAL_DEV( 0x2735, 0x100b, 0x0000, 0x9999,
1232 "MPIO", 1299 "MPIO",
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 1185acac4b21..8d7bdcb5924d 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -55,6 +55,7 @@
55#include <linux/slab.h> 55#include <linux/slab.h>
56#include <linux/kthread.h> 56#include <linux/kthread.h>
57#include <linux/mutex.h> 57#include <linux/mutex.h>
58#include <linux/utsrelease.h>
58 59
59#include <scsi/scsi.h> 60#include <scsi/scsi.h>
60#include <scsi/scsi_cmnd.h> 61#include <scsi/scsi_cmnd.h>
@@ -373,8 +374,12 @@ static int usb_stor_control_thread(void * __us)
373 /* lock access to the state */ 374 /* lock access to the state */
374 scsi_lock(host); 375 scsi_lock(host);
375 376
377 /* did the command already complete because of a disconnect? */
378 if (!us->srb)
379 ; /* nothing to do */
380
376 /* indicate that the command is done */ 381 /* indicate that the command is done */
377 if (us->srb->result != DID_ABORT << 16) { 382 else if (us->srb->result != DID_ABORT << 16) {
378 US_DEBUGP("scsi cmd done, result=0x%x\n", 383 US_DEBUGP("scsi cmd done, result=0x%x\n",
379 us->srb->result); 384 us->srb->result);
380 us->srb->scsi_done(us->srb); 385 us->srb->scsi_done(us->srb);
@@ -478,7 +483,7 @@ static struct us_unusual_dev *find_unusual(const struct usb_device_id *id)
478} 483}
479 484
480/* Get the unusual_devs entries and the string descriptors */ 485/* Get the unusual_devs entries and the string descriptors */
481static void get_device_info(struct us_data *us, const struct usb_device_id *id) 486static int get_device_info(struct us_data *us, const struct usb_device_id *id)
482{ 487{
483 struct usb_device *dev = us->pusb_dev; 488 struct usb_device *dev = us->pusb_dev;
484 struct usb_interface_descriptor *idesc = 489 struct usb_interface_descriptor *idesc =
@@ -495,6 +500,11 @@ static void get_device_info(struct us_data *us, const struct usb_device_id *id)
495 unusual_dev->useTransport; 500 unusual_dev->useTransport;
496 us->flags = USB_US_ORIG_FLAGS(id->driver_info); 501 us->flags = USB_US_ORIG_FLAGS(id->driver_info);
497 502
503 if (us->flags & US_FL_IGNORE_DEVICE) {
504 printk(KERN_INFO USB_STORAGE "device ignored\n");
505 return -ENODEV;
506 }
507
498 /* 508 /*
499 * This flag is only needed when we're in high-speed, so let's 509 * This flag is only needed when we're in high-speed, so let's
500 * disable it if we're in full-speed 510 * disable it if we're in full-speed
@@ -524,7 +534,8 @@ static void get_device_info(struct us_data *us, const struct usb_device_id *id)
524 if (msg >= 0 && !(us->flags & US_FL_NEED_OVERRIDE)) 534 if (msg >= 0 && !(us->flags & US_FL_NEED_OVERRIDE))
525 printk(KERN_NOTICE USB_STORAGE "This device " 535 printk(KERN_NOTICE USB_STORAGE "This device "
526 "(%04x,%04x,%04x S %02x P %02x)" 536 "(%04x,%04x,%04x S %02x P %02x)"
527 " has %s in unusual_devs.h\n" 537 " has %s in unusual_devs.h (kernel"
538 " %s)\n"
528 " Please send a copy of this message to " 539 " Please send a copy of this message to "
529 "<linux-usb-devel@lists.sourceforge.net>\n", 540 "<linux-usb-devel@lists.sourceforge.net>\n",
530 le16_to_cpu(ddesc->idVendor), 541 le16_to_cpu(ddesc->idVendor),
@@ -532,8 +543,11 @@ static void get_device_info(struct us_data *us, const struct usb_device_id *id)
532 le16_to_cpu(ddesc->bcdDevice), 543 le16_to_cpu(ddesc->bcdDevice),
533 idesc->bInterfaceSubClass, 544 idesc->bInterfaceSubClass,
534 idesc->bInterfaceProtocol, 545 idesc->bInterfaceProtocol,
535 msgs[msg]); 546 msgs[msg],
547 UTS_RELEASE);
536 } 548 }
549
550 return 0;
537} 551}
538 552
539/* Get the transport settings */ 553/* Get the transport settings */
@@ -836,32 +850,34 @@ static void dissociate_dev(struct us_data *us)
836 * the host */ 850 * the host */
837static void quiesce_and_remove_host(struct us_data *us) 851static void quiesce_and_remove_host(struct us_data *us)
838{ 852{
853 struct Scsi_Host *host = us_to_host(us);
854
839 /* Prevent new USB transfers, stop the current command, and 855 /* Prevent new USB transfers, stop the current command, and
840 * interrupt a SCSI-scan or device-reset delay */ 856 * interrupt a SCSI-scan or device-reset delay */
857 scsi_lock(host);
841 set_bit(US_FLIDX_DISCONNECTING, &us->flags); 858 set_bit(US_FLIDX_DISCONNECTING, &us->flags);
859 scsi_unlock(host);
842 usb_stor_stop_transport(us); 860 usb_stor_stop_transport(us);
843 wake_up(&us->delay_wait); 861 wake_up(&us->delay_wait);
844 862
845 /* It doesn't matter if the SCSI-scanning thread is still running. 863 /* It doesn't matter if the SCSI-scanning thread is still running.
846 * The thread will exit when it sees the DISCONNECTING flag. */ 864 * The thread will exit when it sees the DISCONNECTING flag. */
847 865
848 /* Wait for the current command to finish, then remove the host */
849 mutex_lock(&us->dev_mutex);
850 mutex_unlock(&us->dev_mutex);
851
852 /* queuecommand won't accept any new commands and the control 866 /* queuecommand won't accept any new commands and the control
853 * thread won't execute a previously-queued command. If there 867 * thread won't execute a previously-queued command. If there
854 * is such a command pending, complete it with an error. */ 868 * is such a command pending, complete it with an error. */
869 mutex_lock(&us->dev_mutex);
855 if (us->srb) { 870 if (us->srb) {
856 us->srb->result = DID_NO_CONNECT << 16; 871 us->srb->result = DID_NO_CONNECT << 16;
857 scsi_lock(us_to_host(us)); 872 scsi_lock(host);
858 us->srb->scsi_done(us->srb); 873 us->srb->scsi_done(us->srb);
859 us->srb = NULL; 874 us->srb = NULL;
860 scsi_unlock(us_to_host(us)); 875 scsi_unlock(host);
861 } 876 }
877 mutex_unlock(&us->dev_mutex);
862 878
863 /* Now we own no commands so it's safe to remove the SCSI host */ 879 /* Now we own no commands so it's safe to remove the SCSI host */
864 scsi_remove_host(us_to_host(us)); 880 scsi_remove_host(host);
865} 881}
866 882
867/* Second stage of disconnect processing: deallocate all resources */ 883/* Second stage of disconnect processing: deallocate all resources */
@@ -960,7 +976,9 @@ static int storage_probe(struct usb_interface *intf,
960 * of the match from the usb_device_id table, so we can find the 976 * of the match from the usb_device_id table, so we can find the
961 * corresponding entry in the private table. 977 * corresponding entry in the private table.
962 */ 978 */
963 get_device_info(us, id); 979 result = get_device_info(us, id);
980 if (result)
981 goto BadDevice;
964 982
965 /* Get the transport, protocol, and pipe settings */ 983 /* Get the transport, protocol, and pipe settings */
966 result = get_transport(us); 984 result = get_transport(us);
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index 5284abe1b5eb..21f3ddbc9080 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -176,8 +176,4 @@ extern void fill_inquiry_response(struct us_data *us,
176#define scsi_unlock(host) spin_unlock_irq(host->host_lock) 176#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
177#define scsi_lock(host) spin_lock_irq(host->host_lock) 177#define scsi_lock(host) spin_lock_irq(host->host_lock)
178 178
179
180/* Vendor ID list for devices that require special handling */
181#define USB_VENDOR_ID_GENESYS 0x05e3 /* Genesys Logic */
182
183#endif 179#endif
diff --git a/drivers/video/68328fb.c b/drivers/video/68328fb.c
index 78488bb41aeb..0dda73da8628 100644
--- a/drivers/video/68328fb.c
+++ b/drivers/video/68328fb.c
@@ -32,7 +32,6 @@
32#include <linux/errno.h> 32#include <linux/errno.h>
33#include <linux/string.h> 33#include <linux/string.h>
34#include <linux/mm.h> 34#include <linux/mm.h>
35#include <linux/tty.h>
36#include <linux/slab.h> 35#include <linux/slab.h>
37#include <linux/vmalloc.h> 36#include <linux/vmalloc.h>
38#include <linux/delay.h> 37#include <linux/delay.h>
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 17de4c84db69..702eb933cf88 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -86,9 +86,11 @@ config FB_MACMODES
86 default n 86 default n
87 87
88config FB_BACKLIGHT 88config FB_BACKLIGHT
89 bool 89 bool
90 depends on FB 90 depends on FB
91 default n 91 select BACKLIGHT_LCD_SUPPORT
92 select BACKLIGHT_CLASS_DEVICE
93 default n
92 94
93config FB_MODE_HELPERS 95config FB_MODE_HELPERS
94 bool "Enable Video Mode Handling Helpers" 96 bool "Enable Video Mode Handling Helpers"
@@ -420,7 +422,7 @@ config FB_OF
420 422
421config FB_CONTROL 423config FB_CONTROL
422 bool "Apple \"control\" display support" 424 bool "Apple \"control\" display support"
423 depends on (FB = y) && PPC_PMAC 425 depends on (FB = y) && PPC_PMAC && PPC32
424 select FB_CFB_FILLRECT 426 select FB_CFB_FILLRECT
425 select FB_CFB_COPYAREA 427 select FB_CFB_COPYAREA
426 select FB_CFB_IMAGEBLIT 428 select FB_CFB_IMAGEBLIT
@@ -431,7 +433,7 @@ config FB_CONTROL
431 433
432config FB_PLATINUM 434config FB_PLATINUM
433 bool "Apple \"platinum\" display support" 435 bool "Apple \"platinum\" display support"
434 depends on (FB = y) && PPC_PMAC 436 depends on (FB = y) && PPC_PMAC && PPC32
435 select FB_CFB_FILLRECT 437 select FB_CFB_FILLRECT
436 select FB_CFB_COPYAREA 438 select FB_CFB_COPYAREA
437 select FB_CFB_IMAGEBLIT 439 select FB_CFB_IMAGEBLIT
@@ -442,7 +444,7 @@ config FB_PLATINUM
442 444
443config FB_VALKYRIE 445config FB_VALKYRIE
444 bool "Apple \"valkyrie\" display support" 446 bool "Apple \"valkyrie\" display support"
445 depends on (FB = y) && (MAC || PPC_PMAC) 447 depends on (FB = y) && (MAC || (PPC_PMAC && PPC32))
446 select FB_CFB_FILLRECT 448 select FB_CFB_FILLRECT
447 select FB_CFB_COPYAREA 449 select FB_CFB_COPYAREA
448 select FB_CFB_IMAGEBLIT 450 select FB_CFB_IMAGEBLIT
@@ -453,7 +455,7 @@ config FB_VALKYRIE
453 455
454config FB_CT65550 456config FB_CT65550
455 bool "Chips 65550 display support" 457 bool "Chips 65550 display support"
456 depends on (FB = y) && PPC 458 depends on (FB = y) && PPC32
457 select FB_CFB_FILLRECT 459 select FB_CFB_FILLRECT
458 select FB_CFB_COPYAREA 460 select FB_CFB_COPYAREA
459 select FB_CFB_IMAGEBLIT 461 select FB_CFB_IMAGEBLIT
@@ -552,7 +554,7 @@ config FB_VESA
552 554
553config FB_IMAC 555config FB_IMAC
554 bool "Intel-based Macintosh Framebuffer Support" 556 bool "Intel-based Macintosh Framebuffer Support"
555 depends on (FB = y) && X86 557 depends on (FB = y) && X86 && EFI
556 select FB_CFB_FILLRECT 558 select FB_CFB_FILLRECT
557 select FB_CFB_COPYAREA 559 select FB_CFB_COPYAREA
558 select FB_CFB_IMAGEBLIT 560 select FB_CFB_IMAGEBLIT
@@ -721,10 +723,8 @@ config FB_NVIDIA_I2C
721 723
722config FB_NVIDIA_BACKLIGHT 724config FB_NVIDIA_BACKLIGHT
723 bool "Support for backlight control" 725 bool "Support for backlight control"
724 depends on FB_NVIDIA && PPC_PMAC 726 depends on FB_NVIDIA && PMAC_BACKLIGHT
725 select FB_BACKLIGHT 727 select FB_BACKLIGHT
726 select BACKLIGHT_LCD_SUPPORT
727 select BACKLIGHT_CLASS_DEVICE
728 default y 728 default y
729 help 729 help
730 Say Y here if you want to control the backlight of your display. 730 Say Y here if you want to control the backlight of your display.
@@ -769,10 +769,8 @@ config FB_RIVA_DEBUG
769 769
770config FB_RIVA_BACKLIGHT 770config FB_RIVA_BACKLIGHT
771 bool "Support for backlight control" 771 bool "Support for backlight control"
772 depends on FB_RIVA && PPC_PMAC 772 depends on FB_RIVA && PMAC_BACKLIGHT
773 select FB_BACKLIGHT 773 select FB_BACKLIGHT
774 select BACKLIGHT_LCD_SUPPORT
775 select BACKLIGHT_CLASS_DEVICE
776 default y 774 default y
777 help 775 help
778 Say Y here if you want to control the backlight of your display. 776 Say Y here if you want to control the backlight of your display.
@@ -1025,10 +1023,8 @@ config FB_RADEON_I2C
1025 1023
1026config FB_RADEON_BACKLIGHT 1024config FB_RADEON_BACKLIGHT
1027 bool "Support for backlight control" 1025 bool "Support for backlight control"
1028 depends on FB_RADEON && PPC_PMAC 1026 depends on FB_RADEON && PMAC_BACKLIGHT
1029 select FB_BACKLIGHT 1027 select FB_BACKLIGHT
1030 select BACKLIGHT_LCD_SUPPORT
1031 select BACKLIGHT_CLASS_DEVICE
1032 default y 1028 default y
1033 help 1029 help
1034 Say Y here if you want to control the backlight of your display. 1030 Say Y here if you want to control the backlight of your display.
@@ -1059,10 +1055,8 @@ config FB_ATY128
1059 1055
1060config FB_ATY128_BACKLIGHT 1056config FB_ATY128_BACKLIGHT
1061 bool "Support for backlight control" 1057 bool "Support for backlight control"
1062 depends on FB_ATY128 && PPC_PMAC 1058 depends on FB_ATY128 && PMAC_BACKLIGHT
1063 select FB_BACKLIGHT 1059 select FB_BACKLIGHT
1064 select BACKLIGHT_LCD_SUPPORT
1065 select BACKLIGHT_CLASS_DEVICE
1066 default y 1060 default y
1067 help 1061 help
1068 Say Y here if you want to control the backlight of your display. 1062 Say Y here if you want to control the backlight of your display.
@@ -1111,10 +1105,8 @@ config FB_ATY_GX
1111 1105
1112config FB_ATY_BACKLIGHT 1106config FB_ATY_BACKLIGHT
1113 bool "Support for backlight control" 1107 bool "Support for backlight control"
1114 depends on FB_ATY && PPC_PMAC 1108 depends on FB_ATY && PMAC_BACKLIGHT
1115 select FB_BACKLIGHT 1109 select FB_BACKLIGHT
1116 select BACKLIGHT_LCD_SUPPORT
1117 select BACKLIGHT_CLASS_DEVICE
1118 default y 1110 default y
1119 help 1111 help
1120 Say Y here if you want to control the backlight of your display. 1112 Say Y here if you want to control the backlight of your display.
@@ -1518,6 +1510,26 @@ config FB_PXA_PARAMETERS
1518 1510
1519 <file:Documentation/fb/pxafb.txt> describes the available parameters. 1511 <file:Documentation/fb/pxafb.txt> describes the available parameters.
1520 1512
1513config FB_MBX
1514 tristate "2700G LCD framebuffer support"
1515 depends on FB && ARCH_PXA
1516 select FB_CFB_FILLRECT
1517 select FB_CFB_COPYAREA
1518 select FB_CFB_IMAGEBLIT
1519 ---help---
1520 Framebuffer driver for the Intel 2700G (Marathon) Graphics
1521 Accelerator
1522
1523config FB_MBX_DEBUG
1524 bool "Enable debugging info via debugfs"
1525 depends on FB_MBX && DEBUG_FS
1526 default n
1527 ---help---
1528 Enable this if you want debugging information using the debug
1529 filesystem (debugfs)
1530
1531 If unsure, say N.
1532
1521config FB_W100 1533config FB_W100
1522 tristate "W100 frame buffer support" 1534 tristate "W100 frame buffer support"
1523 depends on FB && PXA_SHARPSL 1535 depends on FB && PXA_SHARPSL
@@ -1557,6 +1569,21 @@ config FB_S3C2410_DEBUG
1557 Turn on debugging messages. Note that you can set/unset at run time 1569 Turn on debugging messages. Note that you can set/unset at run time
1558 through sysfs 1570 through sysfs
1559 1571
1572config FB_PNX4008_DUM
1573 tristate "Display Update Module support on Philips PNX4008 board"
1574 depends on FB && ARCH_PNX4008
1575 ---help---
1576 Say Y here to enable support for PNX4008 Display Update Module (DUM)
1577
1578config FB_PNX4008_DUM_RGB
1579 tristate "RGB Framebuffer support on Philips PNX4008 board"
1580 depends on FB_PNX4008_DUM
1581 select FB_CFB_FILLRECT
1582 select FB_CFB_COPYAREA
1583 select FB_CFB_IMAGEBLIT
1584 ---help---
1585 Say Y here to enable support for PNX4008 RGB Framebuffer
1586
1560config FB_VIRTUAL 1587config FB_VIRTUAL
1561 tristate "Virtual Frame Buffer support (ONLY FOR TESTING!)" 1588 tristate "Virtual Frame Buffer support (ONLY FOR TESTING!)"
1562 depends on FB 1589 depends on FB
@@ -1585,7 +1612,7 @@ if FB || SGI_NEWPORT_CONSOLE
1585 source "drivers/video/logo/Kconfig" 1612 source "drivers/video/logo/Kconfig"
1586endif 1613endif
1587 1614
1588if FB && SYSFS 1615if SYSFS
1589 source "drivers/video/backlight/Kconfig" 1616 source "drivers/video/backlight/Kconfig"
1590endif 1617endif
1591 1618
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index c335e9bc3b20..481c6c9695f8 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -4,6 +4,7 @@
4 4
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-y += fb_notify.o
7obj-$(CONFIG_FB) += fb.o 8obj-$(CONFIG_FB) += fb.o
8fb-y := fbmem.o fbmon.o fbcmap.o fbsysfs.o \ 9fb-y := fbmem.o fbmon.o fbcmap.o fbsysfs.o \
9 modedb.o fbcvt.o 10 modedb.o fbcvt.o
@@ -38,6 +39,7 @@ obj-$(CONFIG_FB_SIS) += sis/
38obj-$(CONFIG_FB_KYRO) += kyro/ 39obj-$(CONFIG_FB_KYRO) += kyro/
39obj-$(CONFIG_FB_SAVAGE) += savage/ 40obj-$(CONFIG_FB_SAVAGE) += savage/
40obj-$(CONFIG_FB_GEODE) += geode/ 41obj-$(CONFIG_FB_GEODE) += geode/
42obj-$(CONFIG_FB_MBX) += mbx/
41obj-$(CONFIG_FB_I810) += vgastate.o 43obj-$(CONFIG_FB_I810) += vgastate.o
42obj-$(CONFIG_FB_NEOMAGIC) += neofb.o vgastate.o 44obj-$(CONFIG_FB_NEOMAGIC) += neofb.o vgastate.o
43obj-$(CONFIG_FB_VIRGE) += virgefb.o 45obj-$(CONFIG_FB_VIRGE) += virgefb.o
@@ -94,6 +96,8 @@ obj-$(CONFIG_FB_TX3912) += tx3912fb.o
94obj-$(CONFIG_FB_S1D13XXX) += s1d13xxxfb.o 96obj-$(CONFIG_FB_S1D13XXX) += s1d13xxxfb.o
95obj-$(CONFIG_FB_IMX) += imxfb.o 97obj-$(CONFIG_FB_IMX) += imxfb.o
96obj-$(CONFIG_FB_S3C2410) += s3c2410fb.o 98obj-$(CONFIG_FB_S3C2410) += s3c2410fb.o
99obj-$(CONFIG_FB_PNX4008_DUM) += pnx4008/
100obj-$(CONFIG_FB_PNX4008_DUM_RGB) += pnx4008/
97 101
98# Platform or fallback drivers go here 102# Platform or fallback drivers go here
99obj-$(CONFIG_FB_VESA) += vesafb.o 103obj-$(CONFIG_FB_VESA) += vesafb.o
diff --git a/drivers/video/S3triofb.c b/drivers/video/S3triofb.c
index e714e8449c1d..afd146f5f683 100644
--- a/drivers/video/S3triofb.c
+++ b/drivers/video/S3triofb.c
@@ -28,7 +28,6 @@
28#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/string.h> 29#include <linux/string.h>
30#include <linux/mm.h> 30#include <linux/mm.h>
31#include <linux/tty.h>
32#include <linux/slab.h> 31#include <linux/slab.h>
33#include <linux/vmalloc.h> 32#include <linux/vmalloc.h>
34#include <linux/delay.h> 33#include <linux/delay.h>
diff --git a/drivers/video/amifb.c b/drivers/video/amifb.c
index f9bc9f777e75..f1ba54f4fc39 100644
--- a/drivers/video/amifb.c
+++ b/drivers/video/amifb.c
@@ -45,7 +45,6 @@
45#include <linux/errno.h> 45#include <linux/errno.h>
46#include <linux/string.h> 46#include <linux/string.h>
47#include <linux/mm.h> 47#include <linux/mm.h>
48#include <linux/tty.h>
49#include <linux/slab.h> 48#include <linux/slab.h>
50#include <linux/delay.h> 49#include <linux/delay.h>
51#include <linux/interrupt.h> 50#include <linux/interrupt.h>
diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
index fd95c2dbd4f7..70dd8115a4d8 100644
--- a/drivers/video/arcfb.c
+++ b/drivers/video/arcfb.c
@@ -39,7 +39,6 @@
39#include <linux/errno.h> 39#include <linux/errno.h>
40#include <linux/string.h> 40#include <linux/string.h>
41#include <linux/mm.h> 41#include <linux/mm.h>
42#include <linux/tty.h>
43#include <linux/slab.h> 42#include <linux/slab.h>
44#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
45#include <linux/delay.h> 44#include <linux/delay.h>
diff --git a/drivers/video/asiliantfb.c b/drivers/video/asiliantfb.c
index eaeaf4d1a094..1fd22f460b0f 100644
--- a/drivers/video/asiliantfb.c
+++ b/drivers/video/asiliantfb.c
@@ -34,7 +34,6 @@
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/string.h> 35#include <linux/string.h>
36#include <linux/mm.h> 36#include <linux/mm.h>
37#include <linux/tty.h>
38#include <linux/slab.h> 37#include <linux/slab.h>
39#include <linux/vmalloc.h> 38#include <linux/vmalloc.h>
40#include <linux/delay.h> 39#include <linux/delay.h>
diff --git a/drivers/video/atafb.c b/drivers/video/atafb.c
index e69ab65f7843..5831893bf7a0 100644
--- a/drivers/video/atafb.c
+++ b/drivers/video/atafb.c
@@ -53,7 +53,6 @@
53#include <linux/errno.h> 53#include <linux/errno.h>
54#include <linux/string.h> 54#include <linux/string.h>
55#include <linux/mm.h> 55#include <linux/mm.h>
56#include <linux/tty.h>
57#include <linux/slab.h> 56#include <linux/slab.h>
58#include <linux/delay.h> 57#include <linux/delay.h>
59#include <linux/init.h> 58#include <linux/init.h>
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 72c589109471..276a21530b95 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -52,7 +52,6 @@
52#include <linux/errno.h> 52#include <linux/errno.h>
53#include <linux/string.h> 53#include <linux/string.h>
54#include <linux/mm.h> 54#include <linux/mm.h>
55#include <linux/tty.h>
56#include <linux/slab.h> 55#include <linux/slab.h>
57#include <linux/vmalloc.h> 56#include <linux/vmalloc.h>
58#include <linux/delay.h> 57#include <linux/delay.h>
@@ -457,6 +456,10 @@ static void wait_for_fifo(u16 entries, struct aty128fb_par *par);
457static void wait_for_idle(struct aty128fb_par *par); 456static void wait_for_idle(struct aty128fb_par *par);
458static u32 depth_to_dst(u32 depth); 457static u32 depth_to_dst(u32 depth);
459 458
459#ifdef CONFIG_FB_ATY128_BACKLIGHT
460static void aty128_bl_set_power(struct fb_info *info, int power);
461#endif
462
460#define BIOS_IN8(v) (readb(bios + (v))) 463#define BIOS_IN8(v) (readb(bios + (v)))
461#define BIOS_IN16(v) (readb(bios + (v)) | \ 464#define BIOS_IN16(v) (readb(bios + (v)) | \
462 (readb(bios + (v) + 1) << 8)) 465 (readb(bios + (v) + 1) << 8))
@@ -1258,25 +1261,11 @@ static void aty128_set_lcd_enable(struct aty128fb_par *par, int on)
1258 reg &= ~LVDS_DISPLAY_DIS; 1261 reg &= ~LVDS_DISPLAY_DIS;
1259 aty_st_le32(LVDS_GEN_CNTL, reg); 1262 aty_st_le32(LVDS_GEN_CNTL, reg);
1260#ifdef CONFIG_FB_ATY128_BACKLIGHT 1263#ifdef CONFIG_FB_ATY128_BACKLIGHT
1261 mutex_lock(&info->bl_mutex); 1264 aty128_bl_set_power(info, FB_BLANK_UNBLANK);
1262 if (info->bl_dev) {
1263 down(&info->bl_dev->sem);
1264 info->bl_dev->props->update_status(info->bl_dev);
1265 up(&info->bl_dev->sem);
1266 }
1267 mutex_unlock(&info->bl_mutex);
1268#endif 1265#endif
1269 } else { 1266 } else {
1270#ifdef CONFIG_FB_ATY128_BACKLIGHT 1267#ifdef CONFIG_FB_ATY128_BACKLIGHT
1271 mutex_lock(&info->bl_mutex); 1268 aty128_bl_set_power(info, FB_BLANK_POWERDOWN);
1272 if (info->bl_dev) {
1273 down(&info->bl_dev->sem);
1274 info->bl_dev->props->brightness = 0;
1275 info->bl_dev->props->power = FB_BLANK_POWERDOWN;
1276 info->bl_dev->props->update_status(info->bl_dev);
1277 up(&info->bl_dev->sem);
1278 }
1279 mutex_unlock(&info->bl_mutex);
1280#endif 1269#endif
1281 reg = aty_ld_le32(LVDS_GEN_CNTL); 1270 reg = aty_ld_le32(LVDS_GEN_CNTL);
1282 reg |= LVDS_DISPLAY_DIS; 1271 reg |= LVDS_DISPLAY_DIS;
@@ -1703,6 +1692,7 @@ static int __devinit aty128fb_setup(char *options)
1703 1692
1704static struct backlight_properties aty128_bl_data; 1693static struct backlight_properties aty128_bl_data;
1705 1694
1695/* Call with fb_info->bl_mutex held */
1706static int aty128_bl_get_level_brightness(struct aty128fb_par *par, 1696static int aty128_bl_get_level_brightness(struct aty128fb_par *par,
1707 int level) 1697 int level)
1708{ 1698{
@@ -1710,10 +1700,8 @@ static int aty128_bl_get_level_brightness(struct aty128fb_par *par,
1710 int atylevel; 1700 int atylevel;
1711 1701
1712 /* Get and convert the value */ 1702 /* Get and convert the value */
1713 mutex_lock(&info->bl_mutex);
1714 atylevel = MAX_LEVEL - 1703 atylevel = MAX_LEVEL -
1715 (info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL); 1704 (info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL);
1716 mutex_unlock(&info->bl_mutex);
1717 1705
1718 if (atylevel < 0) 1706 if (atylevel < 0)
1719 atylevel = 0; 1707 atylevel = 0;
@@ -1731,7 +1719,8 @@ static int aty128_bl_get_level_brightness(struct aty128fb_par *par,
1731/* That one prevents proper CRT output with LCD off */ 1719/* That one prevents proper CRT output with LCD off */
1732#undef BACKLIGHT_DAC_OFF 1720#undef BACKLIGHT_DAC_OFF
1733 1721
1734static int aty128_bl_update_status(struct backlight_device *bd) 1722/* Call with fb_info->bl_mutex held */
1723static int __aty128_bl_update_status(struct backlight_device *bd)
1735{ 1724{
1736 struct aty128fb_par *par = class_get_devdata(&bd->class_dev); 1725 struct aty128fb_par *par = class_get_devdata(&bd->class_dev);
1737 unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL); 1726 unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL);
@@ -1784,6 +1773,19 @@ static int aty128_bl_update_status(struct backlight_device *bd)
1784 return 0; 1773 return 0;
1785} 1774}
1786 1775
1776static int aty128_bl_update_status(struct backlight_device *bd)
1777{
1778 struct aty128fb_par *par = class_get_devdata(&bd->class_dev);
1779 struct fb_info *info = pci_get_drvdata(par->pdev);
1780 int ret;
1781
1782 mutex_lock(&info->bl_mutex);
1783 ret = __aty128_bl_update_status(bd);
1784 mutex_unlock(&info->bl_mutex);
1785
1786 return ret;
1787}
1788
1787static int aty128_bl_get_brightness(struct backlight_device *bd) 1789static int aty128_bl_get_brightness(struct backlight_device *bd)
1788{ 1790{
1789 return bd->props->brightness; 1791 return bd->props->brightness;
@@ -1796,6 +1798,20 @@ static struct backlight_properties aty128_bl_data = {
1796 .max_brightness = (FB_BACKLIGHT_LEVELS - 1), 1798 .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
1797}; 1799};
1798 1800
1801static void aty128_bl_set_power(struct fb_info *info, int power)
1802{
1803 mutex_lock(&info->bl_mutex);
1804
1805 if (info->bl_dev) {
1806 down(&info->bl_dev->sem);
1807 info->bl_dev->props->power = power;
1808 __aty128_bl_update_status(info->bl_dev);
1809 up(&info->bl_dev->sem);
1810 }
1811
1812 mutex_unlock(&info->bl_mutex);
1813}
1814
1799static void aty128_bl_init(struct aty128fb_par *par) 1815static void aty128_bl_init(struct aty128fb_par *par)
1800{ 1816{
1801 struct fb_info *info = pci_get_drvdata(par->pdev); 1817 struct fb_info *info = pci_get_drvdata(par->pdev);
@@ -1816,7 +1832,7 @@ static void aty128_bl_init(struct aty128fb_par *par)
1816 bd = backlight_device_register(name, par, &aty128_bl_data); 1832 bd = backlight_device_register(name, par, &aty128_bl_data);
1817 if (IS_ERR(bd)) { 1833 if (IS_ERR(bd)) {
1818 info->bl_dev = NULL; 1834 info->bl_dev = NULL;
1819 printk("aty128: Backlight registration failed\n"); 1835 printk(KERN_WARNING "aty128: Backlight registration failed\n");
1820 goto error; 1836 goto error;
1821 } 1837 }
1822 1838
@@ -1827,11 +1843,11 @@ static void aty128_bl_init(struct aty128fb_par *par)
1827 219 * FB_BACKLIGHT_MAX / MAX_LEVEL); 1843 219 * FB_BACKLIGHT_MAX / MAX_LEVEL);
1828 mutex_unlock(&info->bl_mutex); 1844 mutex_unlock(&info->bl_mutex);
1829 1845
1830 up(&bd->sem); 1846 down(&bd->sem);
1831 bd->props->brightness = aty128_bl_data.max_brightness; 1847 bd->props->brightness = aty128_bl_data.max_brightness;
1832 bd->props->power = FB_BLANK_UNBLANK; 1848 bd->props->power = FB_BLANK_UNBLANK;
1833 bd->props->update_status(bd); 1849 bd->props->update_status(bd);
1834 down(&bd->sem); 1850 up(&bd->sem);
1835 1851
1836#ifdef CONFIG_PMAC_BACKLIGHT 1852#ifdef CONFIG_PMAC_BACKLIGHT
1837 mutex_lock(&pmac_backlight_mutex); 1853 mutex_lock(&pmac_backlight_mutex);
@@ -1901,9 +1917,6 @@ static int __devinit aty128_init(struct pci_dev *pdev, const struct pci_device_i
1901 u8 chip_rev; 1917 u8 chip_rev;
1902 u32 dac; 1918 u32 dac;
1903 1919
1904 if (!par->vram_size) /* may have already been probed */
1905 par->vram_size = aty_ld_le32(CONFIG_MEMSIZE) & 0x03FFFFFF;
1906
1907 /* Get the chip revision */ 1920 /* Get the chip revision */
1908 chip_rev = (aty_ld_le32(CONFIG_CNTL) >> 16) & 0x1F; 1921 chip_rev = (aty_ld_le32(CONFIG_CNTL) >> 16) & 0x1F;
1909 1922
@@ -2016,9 +2029,6 @@ static int __devinit aty128_init(struct pci_dev *pdev, const struct pci_device_i
2016 2029
2017 aty128_init_engine(par); 2030 aty128_init_engine(par);
2018 2031
2019 if (register_framebuffer(info) < 0)
2020 return 0;
2021
2022 par->pm_reg = pci_find_capability(pdev, PCI_CAP_ID_PM); 2032 par->pm_reg = pci_find_capability(pdev, PCI_CAP_ID_PM);
2023 par->pdev = pdev; 2033 par->pdev = pdev;
2024 par->asleep = 0; 2034 par->asleep = 0;
@@ -2028,6 +2038,9 @@ static int __devinit aty128_init(struct pci_dev *pdev, const struct pci_device_i
2028 aty128_bl_init(par); 2038 aty128_bl_init(par);
2029#endif 2039#endif
2030 2040
2041 if (register_framebuffer(info) < 0)
2042 return 0;
2043
2031 printk(KERN_INFO "fb%d: %s frame buffer device on %s\n", 2044 printk(KERN_INFO "fb%d: %s frame buffer device on %s\n",
2032 info->node, info->fix.id, video_card); 2045 info->node, info->fix.id, video_card);
2033 2046
@@ -2077,7 +2090,6 @@ static int __devinit aty128_probe(struct pci_dev *pdev, const struct pci_device_
2077 par = info->par; 2090 par = info->par;
2078 2091
2079 info->pseudo_palette = par->pseudo_palette; 2092 info->pseudo_palette = par->pseudo_palette;
2080 info->fix = aty128fb_fix;
2081 2093
2082 /* Virtualize mmio region */ 2094 /* Virtualize mmio region */
2083 info->fix.mmio_start = reg_addr; 2095 info->fix.mmio_start = reg_addr;
@@ -2198,12 +2210,8 @@ static int aty128fb_blank(int blank, struct fb_info *fb)
2198 return 0; 2210 return 0;
2199 2211
2200#ifdef CONFIG_FB_ATY128_BACKLIGHT 2212#ifdef CONFIG_FB_ATY128_BACKLIGHT
2201 if (machine_is(powermac) && blank) { 2213 if (machine_is(powermac) && blank)
2202 down(&fb->bl_dev->sem); 2214 aty128_bl_set_power(fb, FB_BLANK_POWERDOWN);
2203 fb->bl_dev->props->power = FB_BLANK_POWERDOWN;
2204 fb->bl_dev->props->update_status(fb->bl_dev);
2205 up(&fb->bl_dev->sem);
2206 }
2207#endif 2215#endif
2208 2216
2209 if (blank & FB_BLANK_VSYNC_SUSPEND) 2217 if (blank & FB_BLANK_VSYNC_SUSPEND)
@@ -2219,14 +2227,12 @@ static int aty128fb_blank(int blank, struct fb_info *fb)
2219 aty128_set_crt_enable(par, par->crt_on && !blank); 2227 aty128_set_crt_enable(par, par->crt_on && !blank);
2220 aty128_set_lcd_enable(par, par->lcd_on && !blank); 2228 aty128_set_lcd_enable(par, par->lcd_on && !blank);
2221 } 2229 }
2230
2222#ifdef CONFIG_FB_ATY128_BACKLIGHT 2231#ifdef CONFIG_FB_ATY128_BACKLIGHT
2223 if (machine_is(powermac) && !blank) { 2232 if (machine_is(powermac) && !blank)
2224 down(&fb->bl_dev->sem); 2233 aty128_bl_set_power(fb, FB_BLANK_UNBLANK);
2225 fb->bl_dev->props->power = FB_BLANK_UNBLANK;
2226 fb->bl_dev->props->update_status(fb->bl_dev);
2227 up(&fb->bl_dev->sem);
2228 }
2229#endif 2234#endif
2235
2230 return 0; 2236 return 0;
2231} 2237}
2232 2238
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 0c9706746d79..19a71f045784 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -2129,15 +2129,14 @@ static int atyfb_pci_resume(struct pci_dev *pdev)
2129 2129
2130static struct backlight_properties aty_bl_data; 2130static struct backlight_properties aty_bl_data;
2131 2131
2132/* Call with fb_info->bl_mutex held */
2132static int aty_bl_get_level_brightness(struct atyfb_par *par, int level) 2133static int aty_bl_get_level_brightness(struct atyfb_par *par, int level)
2133{ 2134{
2134 struct fb_info *info = pci_get_drvdata(par->pdev); 2135 struct fb_info *info = pci_get_drvdata(par->pdev);
2135 int atylevel; 2136 int atylevel;
2136 2137
2137 /* Get and convert the value */ 2138 /* Get and convert the value */
2138 mutex_lock(&info->bl_mutex);
2139 atylevel = info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL; 2139 atylevel = info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL;
2140 mutex_unlock(&info->bl_mutex);
2141 2140
2142 if (atylevel < 0) 2141 if (atylevel < 0)
2143 atylevel = 0; 2142 atylevel = 0;
@@ -2147,7 +2146,8 @@ static int aty_bl_get_level_brightness(struct atyfb_par *par, int level)
2147 return atylevel; 2146 return atylevel;
2148} 2147}
2149 2148
2150static int aty_bl_update_status(struct backlight_device *bd) 2149/* Call with fb_info->bl_mutex held */
2150static int __aty_bl_update_status(struct backlight_device *bd)
2151{ 2151{
2152 struct atyfb_par *par = class_get_devdata(&bd->class_dev); 2152 struct atyfb_par *par = class_get_devdata(&bd->class_dev);
2153 unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par); 2153 unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par);
@@ -2172,6 +2172,19 @@ static int aty_bl_update_status(struct backlight_device *bd)
2172 return 0; 2172 return 0;
2173} 2173}
2174 2174
2175static int aty_bl_update_status(struct backlight_device *bd)
2176{
2177 struct atyfb_par *par = class_get_devdata(&bd->class_dev);
2178 struct fb_info *info = pci_get_drvdata(par->pdev);
2179 int ret;
2180
2181 mutex_lock(&info->bl_mutex);
2182 ret = __aty_bl_update_status(bd);
2183 mutex_unlock(&info->bl_mutex);
2184
2185 return ret;
2186}
2187
2175static int aty_bl_get_brightness(struct backlight_device *bd) 2188static int aty_bl_get_brightness(struct backlight_device *bd)
2176{ 2189{
2177 return bd->props->brightness; 2190 return bd->props->brightness;
@@ -2184,6 +2197,20 @@ static struct backlight_properties aty_bl_data = {
2184 .max_brightness = (FB_BACKLIGHT_LEVELS - 1), 2197 .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
2185}; 2198};
2186 2199
2200static void aty_bl_set_power(struct fb_info *info, int power)
2201{
2202 mutex_lock(&info->bl_mutex);
2203
2204 if (info->bl_dev) {
2205 down(&info->bl_dev->sem);
2206 info->bl_dev->props->power = power;
2207 __aty_bl_update_status(info->bl_dev);
2208 up(&info->bl_dev->sem);
2209 }
2210
2211 mutex_unlock(&info->bl_mutex);
2212}
2213
2187static void aty_bl_init(struct atyfb_par *par) 2214static void aty_bl_init(struct atyfb_par *par)
2188{ 2215{
2189 struct fb_info *info = pci_get_drvdata(par->pdev); 2216 struct fb_info *info = pci_get_drvdata(par->pdev);
@@ -2200,7 +2227,7 @@ static void aty_bl_init(struct atyfb_par *par)
2200 bd = backlight_device_register(name, par, &aty_bl_data); 2227 bd = backlight_device_register(name, par, &aty_bl_data);
2201 if (IS_ERR(bd)) { 2228 if (IS_ERR(bd)) {
2202 info->bl_dev = NULL; 2229 info->bl_dev = NULL;
2203 printk("aty: Backlight registration failed\n"); 2230 printk(KERN_WARNING "aty: Backlight registration failed\n");
2204 goto error; 2231 goto error;
2205 } 2232 }
2206 2233
@@ -2211,11 +2238,11 @@ static void aty_bl_init(struct atyfb_par *par)
2211 0xFF * FB_BACKLIGHT_MAX / MAX_LEVEL); 2238 0xFF * FB_BACKLIGHT_MAX / MAX_LEVEL);
2212 mutex_unlock(&info->bl_mutex); 2239 mutex_unlock(&info->bl_mutex);
2213 2240
2214 up(&bd->sem); 2241 down(&bd->sem);
2215 bd->props->brightness = aty_bl_data.max_brightness; 2242 bd->props->brightness = aty_bl_data.max_brightness;
2216 bd->props->power = FB_BLANK_UNBLANK; 2243 bd->props->power = FB_BLANK_UNBLANK;
2217 bd->props->update_status(bd); 2244 bd->props->update_status(bd);
2218 down(&bd->sem); 2245 up(&bd->sem);
2219 2246
2220#ifdef CONFIG_PMAC_BACKLIGHT 2247#ifdef CONFIG_PMAC_BACKLIGHT
2221 mutex_lock(&pmac_backlight_mutex); 2248 mutex_lock(&pmac_backlight_mutex);
@@ -2789,17 +2816,9 @@ static int atyfb_blank(int blank, struct fb_info *info)
2789 if (par->lock_blank || par->asleep) 2816 if (par->lock_blank || par->asleep)
2790 return 0; 2817 return 0;
2791 2818
2792#ifdef CONFIG_PMAC_BACKLIGHT 2819#ifdef CONFIG_FB_ATY_BACKLIGHT
2793 if (machine_is(powermac) && blank > FB_BLANK_NORMAL) { 2820 if (machine_is(powermac) && blank > FB_BLANK_NORMAL)
2794 mutex_lock(&info->bl_mutex); 2821 aty_bl_set_power(info, FB_BLANK_POWERDOWN);
2795 if (info->bl_dev) {
2796 down(&info->bl_dev->sem);
2797 info->bl_dev->props->power = FB_BLANK_POWERDOWN;
2798 info->bl_dev->props->update_status(info->bl_dev);
2799 up(&info->bl_dev->sem);
2800 }
2801 mutex_unlock(&info->bl_mutex);
2802 }
2803#elif defined(CONFIG_FB_ATY_GENERIC_LCD) 2822#elif defined(CONFIG_FB_ATY_GENERIC_LCD)
2804 if (par->lcd_table && blank > FB_BLANK_NORMAL && 2823 if (par->lcd_table && blank > FB_BLANK_NORMAL &&
2805 (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) { 2824 (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
@@ -2829,17 +2848,9 @@ static int atyfb_blank(int blank, struct fb_info *info)
2829 } 2848 }
2830 aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par); 2849 aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par);
2831 2850
2832#ifdef CONFIG_PMAC_BACKLIGHT 2851#ifdef CONFIG_FB_ATY_BACKLIGHT
2833 if (machine_is(powermac) && blank <= FB_BLANK_NORMAL) { 2852 if (machine_is(powermac) && blank <= FB_BLANK_NORMAL)
2834 mutex_lock(&info->bl_mutex); 2853 aty_bl_set_power(info, FB_BLANK_UNBLANK);
2835 if (info->bl_dev) {
2836 down(&info->bl_dev->sem);
2837 info->bl_dev->props->power = FB_BLANK_UNBLANK;
2838 info->bl_dev->props->update_status(info->bl_dev);
2839 up(&info->bl_dev->sem);
2840 }
2841 mutex_unlock(&info->bl_mutex);
2842 }
2843#elif defined(CONFIG_FB_ATY_GENERIC_LCD) 2854#elif defined(CONFIG_FB_ATY_GENERIC_LCD)
2844 if (par->lcd_table && blank <= FB_BLANK_NORMAL && 2855 if (par->lcd_table && blank <= FB_BLANK_NORMAL &&
2845 (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) { 2856 (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
index 1755dddf1899..585eb7b9e636 100644
--- a/drivers/video/aty/radeon_backlight.c
+++ b/drivers/video/aty/radeon_backlight.c
@@ -195,11 +195,11 @@ void radeonfb_bl_init(struct radeonfb_info *rinfo)
195 217 * FB_BACKLIGHT_MAX / MAX_RADEON_LEVEL); 195 217 * FB_BACKLIGHT_MAX / MAX_RADEON_LEVEL);
196 mutex_unlock(&rinfo->info->bl_mutex); 196 mutex_unlock(&rinfo->info->bl_mutex);
197 197
198 up(&bd->sem); 198 down(&bd->sem);
199 bd->props->brightness = radeon_bl_data.max_brightness; 199 bd->props->brightness = radeon_bl_data.max_brightness;
200 bd->props->power = FB_BLANK_UNBLANK; 200 bd->props->power = FB_BLANK_UNBLANK;
201 bd->props->update_status(bd); 201 bd->props->update_status(bd);
202 down(&bd->sem); 202 up(&bd->sem);
203 203
204#ifdef CONFIG_PMAC_BACKLIGHT 204#ifdef CONFIG_PMAC_BACKLIGHT
205 mutex_lock(&pmac_backlight_mutex); 205 mutex_lock(&pmac_backlight_mutex);
diff --git a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
index 51b78f8de949..8e3400d5dd21 100644
--- a/drivers/video/aty/radeon_base.c
+++ b/drivers/video/aty/radeon_base.c
@@ -58,7 +58,6 @@
58#include <linux/errno.h> 58#include <linux/errno.h>
59#include <linux/string.h> 59#include <linux/string.h>
60#include <linux/mm.h> 60#include <linux/mm.h>
61#include <linux/tty.h>
62#include <linux/slab.h> 61#include <linux/slab.h>
63#include <linux/delay.h> 62#include <linux/delay.h>
64#include <linux/time.h> 63#include <linux/time.h>
@@ -267,6 +266,8 @@ static int force_measure_pll = 0;
267#ifdef CONFIG_MTRR 266#ifdef CONFIG_MTRR
268static int nomtrr = 0; 267static int nomtrr = 0;
269#endif 268#endif
269static int force_sleep;
270static int ignore_devlist;
270 271
271/* 272/*
272 * prototypes 273 * prototypes
@@ -2328,9 +2329,9 @@ static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
2328 /* -2 is special: means ON on mobility chips and do not 2329 /* -2 is special: means ON on mobility chips and do not
2329 * change on others 2330 * change on others
2330 */ 2331 */
2331 radeonfb_pm_init(rinfo, rinfo->is_mobility ? 1 : -1); 2332 radeonfb_pm_init(rinfo, rinfo->is_mobility ? 1 : -1, ignore_devlist, force_sleep);
2332 } else 2333 } else
2333 radeonfb_pm_init(rinfo, default_dynclk); 2334 radeonfb_pm_init(rinfo, default_dynclk, ignore_devlist, force_sleep);
2334 2335
2335 pci_set_drvdata(pdev, info); 2336 pci_set_drvdata(pdev, info);
2336 2337
@@ -2478,6 +2479,12 @@ static int __init radeonfb_setup (char *options)
2478 force_measure_pll = 1; 2479 force_measure_pll = 1;
2479 } else if (!strncmp(this_opt, "ignore_edid", 11)) { 2480 } else if (!strncmp(this_opt, "ignore_edid", 11)) {
2480 ignore_edid = 1; 2481 ignore_edid = 1;
2482#if defined(CONFIG_PM) && defined(CONFIG_X86)
2483 } else if (!strncmp(this_opt, "force_sleep", 11)) {
2484 force_sleep = 1;
2485 } else if (!strncmp(this_opt, "ignore_devlist", 14)) {
2486 ignore_devlist = 1;
2487#endif
2481 } else 2488 } else
2482 mode_option = this_opt; 2489 mode_option = this_opt;
2483 } 2490 }
@@ -2533,3 +2540,9 @@ module_param(panel_yres, int, 0);
2533MODULE_PARM_DESC(panel_yres, "int: set panel yres"); 2540MODULE_PARM_DESC(panel_yres, "int: set panel yres");
2534module_param(mode_option, charp, 0); 2541module_param(mode_option, charp, 0);
2535MODULE_PARM_DESC(mode_option, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" "); 2542MODULE_PARM_DESC(mode_option, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
2543#if defined(CONFIG_PM) && defined(CONFIG_X86)
2544module_param(force_sleep, bool, 0);
2545MODULE_PARM_DESC(force_sleep, "bool: force D2 sleep mode on all hardware");
2546module_param(ignore_devlist, bool, 0);
2547MODULE_PARM_DESC(ignore_devlist, "bool: ignore workarounds for bugs in specific laptops");
2548#endif
diff --git a/drivers/video/aty/radeon_pm.c b/drivers/video/aty/radeon_pm.c
index c7091761cef4..f31e606a2ded 100644
--- a/drivers/video/aty/radeon_pm.c
+++ b/drivers/video/aty/radeon_pm.c
@@ -27,6 +27,99 @@
27 27
28#include "ati_ids.h" 28#include "ati_ids.h"
29 29
30static void radeon_reinitialize_M10(struct radeonfb_info *rinfo);
31
32/*
33 * Workarounds for bugs in PC laptops:
34 * - enable D2 sleep in some IBM Thinkpads
35 * - special case for Samsung P35
36 *
37 * Whitelist by subsystem vendor/device because
38 * its the subsystem vendor's fault!
39 */
40
41#if defined(CONFIG_PM) && defined(CONFIG_X86)
42struct radeon_device_id {
43 const char *ident; /* (arbitrary) Name */
44 const unsigned short subsystem_vendor; /* Subsystem Vendor ID */
45 const unsigned short subsystem_device; /* Subsystem Device ID */
46 const enum radeon_pm_mode pm_mode_modifier; /* modify pm_mode */
47 const reinit_function_ptr new_reinit_func; /* changed reinit_func */
48};
49
50#define BUGFIX(model, sv, sd, pm, fn) { \
51 .ident = model, \
52 .subsystem_vendor = sv, \
53 .subsystem_device = sd, \
54 .pm_mode_modifier = pm, \
55 .new_reinit_func = fn \
56}
57
58static struct radeon_device_id radeon_workaround_list[] = {
59 BUGFIX("IBM Thinkpad R32",
60 PCI_VENDOR_ID_IBM, 0x1905,
61 radeon_pm_d2, NULL),
62 BUGFIX("IBM Thinkpad R40",
63 PCI_VENDOR_ID_IBM, 0x0526,
64 radeon_pm_d2, NULL),
65 BUGFIX("IBM Thinkpad R40",
66 PCI_VENDOR_ID_IBM, 0x0527,
67 radeon_pm_d2, NULL),
68 BUGFIX("IBM Thinkpad R50/R51/T40/T41",
69 PCI_VENDOR_ID_IBM, 0x0531,
70 radeon_pm_d2, NULL),
71 BUGFIX("IBM Thinkpad R51/T40/T41/T42",
72 PCI_VENDOR_ID_IBM, 0x0530,
73 radeon_pm_d2, NULL),
74 BUGFIX("IBM Thinkpad T30",
75 PCI_VENDOR_ID_IBM, 0x0517,
76 radeon_pm_d2, NULL),
77 BUGFIX("IBM Thinkpad T40p",
78 PCI_VENDOR_ID_IBM, 0x054d,
79 radeon_pm_d2, NULL),
80 BUGFIX("IBM Thinkpad T42",
81 PCI_VENDOR_ID_IBM, 0x0550,
82 radeon_pm_d2, NULL),
83 BUGFIX("IBM Thinkpad X31/X32",
84 PCI_VENDOR_ID_IBM, 0x052f,
85 radeon_pm_d2, NULL),
86 BUGFIX("Samsung P35",
87 PCI_VENDOR_ID_SAMSUNG, 0xc00c,
88 radeon_pm_off, radeon_reinitialize_M10),
89 { .ident = NULL }
90};
91
92static int radeon_apply_workarounds(struct radeonfb_info *rinfo)
93{
94 struct radeon_device_id *id;
95
96 for (id = radeon_workaround_list; id->ident != NULL; id++ )
97 if ((id->subsystem_vendor == rinfo->pdev->subsystem_vendor ) &&
98 (id->subsystem_device == rinfo->pdev->subsystem_device )) {
99
100 /* we found a device that requires workaround */
101 printk(KERN_DEBUG "radeonfb: %s detected"
102 ", enabling workaround\n", id->ident);
103
104 rinfo->pm_mode |= id->pm_mode_modifier;
105
106 if (id->new_reinit_func != NULL)
107 rinfo->reinit_func = id->new_reinit_func;
108
109 return 1;
110 }
111 return 0; /* not found */
112}
113
114#else /* defined(CONFIG_PM) && defined(CONFIG_X86) */
115static inline int radeon_apply_workarounds(struct radeonfb_info *rinfo)
116{
117 return 0;
118}
119#endif /* defined(CONFIG_PM) && defined(CONFIG_X86) */
120
121
122
30static void radeon_pm_disable_dynamic_mode(struct radeonfb_info *rinfo) 123static void radeon_pm_disable_dynamic_mode(struct radeonfb_info *rinfo)
31{ 124{
32 u32 tmp; 125 u32 tmp;
@@ -852,18 +945,26 @@ static void radeon_pm_setup_for_suspend(struct radeonfb_info *rinfo)
852 /* because both INPLL and OUTPLL take the same lock, that's why. */ 945 /* because both INPLL and OUTPLL take the same lock, that's why. */
853 tmp = INPLL( pllMCLK_MISC) | MCLK_MISC__EN_MCLK_TRISTATE_IN_SUSPEND; 946 tmp = INPLL( pllMCLK_MISC) | MCLK_MISC__EN_MCLK_TRISTATE_IN_SUSPEND;
854 OUTPLL( pllMCLK_MISC, tmp); 947 OUTPLL( pllMCLK_MISC, tmp);
855
856 /* AGP PLL control */
857 if (rinfo->family <= CHIP_FAMILY_RV280) {
858 OUTREG(BUS_CNTL1, INREG(BUS_CNTL1) | BUS_CNTL1__AGPCLK_VALID);
859 948
860 OUTREG(BUS_CNTL1, 949 /* BUS_CNTL1__MOBILE_PLATORM_SEL setting is northbridge chipset
861 (INREG(BUS_CNTL1) & ~BUS_CNTL1__MOBILE_PLATFORM_SEL_MASK) 950 * and radeon chip dependent. Thus we only enable it on Mac for
862 | (2<<BUS_CNTL1__MOBILE_PLATFORM_SEL__SHIFT)); // 440BX 951 * now (until we get more info on how to compute the correct
863 } else { 952 * value for various X86 bridges).
864 OUTREG(BUS_CNTL1, INREG(BUS_CNTL1)); 953 */
865 OUTREG(BUS_CNTL1, (INREG(BUS_CNTL1) & ~0x4000) | 0x8000); 954#ifdef CONFIG_PPC_PMAC
955 if (machine_is(powermac)) {
956 /* AGP PLL control */
957 if (rinfo->family <= CHIP_FAMILY_RV280) {
958 OUTREG(BUS_CNTL1, INREG(BUS_CNTL1) | BUS_CNTL1__AGPCLK_VALID);
959 OUTREG(BUS_CNTL1,
960 (INREG(BUS_CNTL1) & ~BUS_CNTL1__MOBILE_PLATFORM_SEL_MASK)
961 | (2<<BUS_CNTL1__MOBILE_PLATFORM_SEL__SHIFT)); // 440BX
962 } else {
963 OUTREG(BUS_CNTL1, INREG(BUS_CNTL1));
964 OUTREG(BUS_CNTL1, (INREG(BUS_CNTL1) & ~0x4000) | 0x8000);
965 }
866 } 966 }
967#endif
867 968
868 OUTREG(CRTC_OFFSET_CNTL, (INREG(CRTC_OFFSET_CNTL) 969 OUTREG(CRTC_OFFSET_CNTL, (INREG(CRTC_OFFSET_CNTL)
869 & ~CRTC_OFFSET_CNTL__CRTC_STEREO_SYNC_OUT_EN)); 970 & ~CRTC_OFFSET_CNTL__CRTC_STEREO_SYNC_OUT_EN));
@@ -2713,7 +2814,7 @@ static void radeonfb_early_resume(void *data)
2713 2814
2714#endif /* CONFIG_PM */ 2815#endif /* CONFIG_PM */
2715 2816
2716void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk) 2817void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk, int ignore_devlist, int force_sleep)
2717{ 2818{
2718 /* Find PM registers in config space if any*/ 2819 /* Find PM registers in config space if any*/
2719 rinfo->pm_reg = pci_find_capability(rinfo->pdev, PCI_CAP_ID_PM); 2820 rinfo->pm_reg = pci_find_capability(rinfo->pdev, PCI_CAP_ID_PM);
@@ -2729,22 +2830,13 @@ void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk)
2729 } 2830 }
2730 2831
2731#if defined(CONFIG_PM) 2832#if defined(CONFIG_PM)
2833#if defined(CONFIG_PPC_PMAC)
2732 /* Check if we can power manage on suspend/resume. We can do 2834 /* Check if we can power manage on suspend/resume. We can do
2733 * D2 on M6, M7 and M9, and we can resume from D3 cold a few other 2835 * D2 on M6, M7 and M9, and we can resume from D3 cold a few other
2734 * "Mac" cards, but that's all. We need more infos about what the 2836 * "Mac" cards, but that's all. We need more infos about what the
2735 * BIOS does tho. Right now, all this PM stuff is pmac-only for that 2837 * BIOS does tho. Right now, all this PM stuff is pmac-only for that
2736 * reason. --BenH 2838 * reason. --BenH
2737 */ 2839 */
2738 /* Special case for Samsung P35 laptops
2739 */
2740 if ((rinfo->pdev->vendor == PCI_VENDOR_ID_ATI) &&
2741 (rinfo->pdev->device == PCI_CHIP_RV350_NP) &&
2742 (rinfo->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG) &&
2743 (rinfo->pdev->subsystem_device == 0xc00c)) {
2744 rinfo->reinit_func = radeon_reinitialize_M10;
2745 rinfo->pm_mode |= radeon_pm_off;
2746 }
2747#if defined(CONFIG_PPC_PMAC)
2748 if (machine_is(powermac) && rinfo->of_node) { 2840 if (machine_is(powermac) && rinfo->of_node) {
2749 if (rinfo->is_mobility && rinfo->pm_reg && 2841 if (rinfo->is_mobility && rinfo->pm_reg &&
2750 rinfo->family <= CHIP_FAMILY_RV250) 2842 rinfo->family <= CHIP_FAMILY_RV250)
@@ -2790,6 +2882,18 @@ void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk)
2790 } 2882 }
2791#endif /* defined(CONFIG_PPC_PMAC) */ 2883#endif /* defined(CONFIG_PPC_PMAC) */
2792#endif /* defined(CONFIG_PM) */ 2884#endif /* defined(CONFIG_PM) */
2885
2886 if (ignore_devlist)
2887 printk(KERN_DEBUG
2888 "radeonfb: skipping test for device workarounds\n");
2889 else
2890 radeon_apply_workarounds(rinfo);
2891
2892 if (force_sleep) {
2893 printk(KERN_DEBUG
2894 "radeonfb: forcefully enabling D2 sleep mode\n");
2895 rinfo->pm_mode |= radeon_pm_d2;
2896 }
2793} 2897}
2794 2898
2795void radeonfb_pm_exit(struct radeonfb_info *rinfo) 2899void radeonfb_pm_exit(struct radeonfb_info *rinfo)
diff --git a/drivers/video/aty/radeonfb.h b/drivers/video/aty/radeonfb.h
index 38657b2d10eb..d5ff224a6258 100644
--- a/drivers/video/aty/radeonfb.h
+++ b/drivers/video/aty/radeonfb.h
@@ -273,6 +273,8 @@ enum radeon_pm_mode {
273 radeon_pm_off = 0x00000002, /* Can resume from D3 cold */ 273 radeon_pm_off = 0x00000002, /* Can resume from D3 cold */
274}; 274};
275 275
276typedef void (*reinit_function_ptr)(struct radeonfb_info *rinfo);
277
276struct radeonfb_info { 278struct radeonfb_info {
277 struct fb_info *info; 279 struct fb_info *info;
278 280
@@ -338,7 +340,7 @@ struct radeonfb_info {
338 int dynclk; 340 int dynclk;
339 int no_schedule; 341 int no_schedule;
340 enum radeon_pm_mode pm_mode; 342 enum radeon_pm_mode pm_mode;
341 void (*reinit_func)(struct radeonfb_info *rinfo); 343 reinit_function_ptr reinit_func;
342 344
343 /* Lock on register access */ 345 /* Lock on register access */
344 spinlock_t reg_lock; 346 spinlock_t reg_lock;
@@ -600,7 +602,7 @@ extern int radeon_probe_i2c_connector(struct radeonfb_info *rinfo, int conn, u8
600/* PM Functions */ 602/* PM Functions */
601extern int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state); 603extern int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state);
602extern int radeonfb_pci_resume(struct pci_dev *pdev); 604extern int radeonfb_pci_resume(struct pci_dev *pdev);
603extern void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk); 605extern void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk, int ignore_devlist, int force_sleep);
604extern void radeonfb_pm_exit(struct radeonfb_info *rinfo); 606extern void radeonfb_pm_exit(struct radeonfb_info *rinfo);
605 607
606/* Monitor probe functions */ 608/* Monitor probe functions */
diff --git a/drivers/video/au1100fb.c b/drivers/video/au1100fb.c
index a92a91fef16f..f25d5d648333 100644
--- a/drivers/video/au1100fb.c
+++ b/drivers/video/au1100fb.c
@@ -156,7 +156,7 @@ int au1100fb_setmode(struct au1100fb_device *fbdev)
156 156
157 info->fix.visual = FB_VISUAL_TRUECOLOR; 157 info->fix.visual = FB_VISUAL_TRUECOLOR;
158 info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */ 158 info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */
159 } 159 }
160 } else { 160 } else {
161 /* mono */ 161 /* mono */
162 info->fix.visual = FB_VISUAL_MONO10; 162 info->fix.visual = FB_VISUAL_MONO10;
@@ -164,20 +164,16 @@ int au1100fb_setmode(struct au1100fb_device *fbdev)
164 } 164 }
165 165
166 info->screen_size = info->fix.line_length * info->var.yres_virtual; 166 info->screen_size = info->fix.line_length * info->var.yres_virtual;
167 info->var.rotate = ((fbdev->panel->control_base&LCD_CONTROL_SM_MASK) \
168 >> LCD_CONTROL_SM_BIT) * 90;
167 169
168 /* Determine BPP mode and format */ 170 /* Determine BPP mode and format */
169 fbdev->regs->lcd_control = fbdev->panel->control_base | 171 fbdev->regs->lcd_control = fbdev->panel->control_base;
170 ((info->var.rotate/90) << LCD_CONTROL_SM_BIT);
171
172 fbdev->regs->lcd_intenable = 0;
173 fbdev->regs->lcd_intstatus = 0;
174
175 fbdev->regs->lcd_horztiming = fbdev->panel->horztiming; 172 fbdev->regs->lcd_horztiming = fbdev->panel->horztiming;
176
177 fbdev->regs->lcd_verttiming = fbdev->panel->verttiming; 173 fbdev->regs->lcd_verttiming = fbdev->panel->verttiming;
178
179 fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base; 174 fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base;
180 175 fbdev->regs->lcd_intenable = 0;
176 fbdev->regs->lcd_intstatus = 0;
181 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys); 177 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys);
182 178
183 if (panel_is_dual(fbdev->panel)) { 179 if (panel_is_dual(fbdev->panel)) {
@@ -206,6 +202,8 @@ int au1100fb_setmode(struct au1100fb_device *fbdev)
206 202
207 /* Resume controller */ 203 /* Resume controller */
208 fbdev->regs->lcd_control |= LCD_CONTROL_GO; 204 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
205 mdelay(10);
206 au1100fb_fb_blank(VESA_NO_BLANKING, info);
209 207
210 return 0; 208 return 0;
211} 209}
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 022f9d3473f5..02f15297a021 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -10,7 +10,7 @@ menuconfig BACKLIGHT_LCD_SUPPORT
10 10
11config BACKLIGHT_CLASS_DEVICE 11config BACKLIGHT_CLASS_DEVICE
12 tristate "Lowlevel Backlight controls" 12 tristate "Lowlevel Backlight controls"
13 depends on BACKLIGHT_LCD_SUPPORT && FB 13 depends on BACKLIGHT_LCD_SUPPORT
14 default m 14 default m
15 help 15 help
16 This framework adds support for low-level control of the LCD 16 This framework adds support for low-level control of the LCD
@@ -26,7 +26,7 @@ config BACKLIGHT_DEVICE
26 26
27config LCD_CLASS_DEVICE 27config LCD_CLASS_DEVICE
28 tristate "Lowlevel LCD controls" 28 tristate "Lowlevel LCD controls"
29 depends on BACKLIGHT_LCD_SUPPORT && FB 29 depends on BACKLIGHT_LCD_SUPPORT
30 default m 30 default m
31 help 31 help
32 This framework adds support for low-level control of LCD. 32 This framework adds support for low-level control of LCD.
diff --git a/drivers/video/chipsfb.c b/drivers/video/chipsfb.c
index 0e465c80ef24..73cb426bf2d7 100644
--- a/drivers/video/chipsfb.c
+++ b/drivers/video/chipsfb.c
@@ -19,7 +19,6 @@
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/string.h> 20#include <linux/string.h>
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <linux/tty.h>
23#include <linux/slab.h> 22#include <linux/slab.h>
24#include <linux/vmalloc.h> 23#include <linux/vmalloc.h>
25#include <linux/delay.h> 24#include <linux/delay.h>
@@ -150,12 +149,11 @@ static int chipsfb_blank(int blank, struct fb_info *info)
150 mutex_lock(&pmac_backlight_mutex); 149 mutex_lock(&pmac_backlight_mutex);
151 150
152 if (pmac_backlight) { 151 if (pmac_backlight) {
153 down(&pmac_backlight->sem);
154
155 /* used to disable backlight only for blank > 1, but it seems 152 /* used to disable backlight only for blank > 1, but it seems
156 * useful at blank = 1 too (saves battery, extends backlight 153 * useful at blank = 1 too (saves battery, extends backlight
157 * life) 154 * life)
158 */ 155 */
156 down(&pmac_backlight->sem);
159 if (blank) 157 if (blank)
160 pmac_backlight->props->power = FB_BLANK_POWERDOWN; 158 pmac_backlight->props->power = FB_BLANK_POWERDOWN;
161 else 159 else
diff --git a/drivers/video/cirrusfb.c b/drivers/video/cirrusfb.c
index 7355da09c721..daf43f535a0b 100644
--- a/drivers/video/cirrusfb.c
+++ b/drivers/video/cirrusfb.c
@@ -41,7 +41,6 @@
41#include <linux/errno.h> 41#include <linux/errno.h>
42#include <linux/string.h> 42#include <linux/string.h>
43#include <linux/mm.h> 43#include <linux/mm.h>
44#include <linux/tty.h>
45#include <linux/slab.h> 44#include <linux/slab.h>
46#include <linux/delay.h> 45#include <linux/delay.h>
47#include <linux/fb.h> 46#include <linux/fb.h>
diff --git a/drivers/video/console/dummycon.c b/drivers/video/console/dummycon.c
index 878707a04398..d9315d99445f 100644
--- a/drivers/video/console/dummycon.c
+++ b/drivers/video/console/dummycon.c
@@ -7,9 +7,9 @@
7 7
8#include <linux/types.h> 8#include <linux/types.h>
9#include <linux/kdev_t.h> 9#include <linux/kdev_t.h>
10#include <linux/tty.h>
11#include <linux/console.h> 10#include <linux/console.h>
12#include <linux/vt_kern.h> 11#include <linux/vt_kern.h>
12#include <linux/screen_info.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/module.h> 14#include <linux/module.h>
15 15
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 94e9f7069bef..390439b3d899 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -64,7 +64,6 @@
64#include <linux/fs.h> 64#include <linux/fs.h>
65#include <linux/kernel.h> 65#include <linux/kernel.h>
66#include <linux/delay.h> /* MSch: for IRQ probe */ 66#include <linux/delay.h> /* MSch: for IRQ probe */
67#include <linux/tty.h>
68#include <linux/console.h> 67#include <linux/console.h>
69#include <linux/string.h> 68#include <linux/string.h>
70#include <linux/kd.h> 69#include <linux/kd.h>
diff --git a/drivers/video/console/mdacon.c b/drivers/video/console/mdacon.c
index c89f90edf8ac..eb4d03fa5391 100644
--- a/drivers/video/console/mdacon.c
+++ b/drivers/video/console/mdacon.c
@@ -31,7 +31,6 @@
31#include <linux/fs.h> 31#include <linux/fs.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/tty.h>
35#include <linux/console.h> 34#include <linux/console.h>
36#include <linux/string.h> 35#include <linux/string.h>
37#include <linux/kd.h> 36#include <linux/kd.h>
@@ -198,7 +197,7 @@ static int __init mdacon_setup(char *str)
198__setup("mdacon=", mdacon_setup); 197__setup("mdacon=", mdacon_setup);
199#endif 198#endif
200 199
201static int __init mda_detect(void) 200static int mda_detect(void)
202{ 201{
203 int count=0; 202 int count=0;
204 u16 *p, p_save; 203 u16 *p, p_save;
@@ -283,7 +282,7 @@ static int __init mda_detect(void)
283 return 1; 282 return 1;
284} 283}
285 284
286static void __init mda_initialize(void) 285static void mda_initialize(void)
287{ 286{
288 write_mda_b(97, 0x00); /* horizontal total */ 287 write_mda_b(97, 0x00); /* horizontal total */
289 write_mda_b(80, 0x01); /* horizontal displayed */ 288 write_mda_b(80, 0x01); /* horizontal displayed */
diff --git a/drivers/video/console/newport_con.c b/drivers/video/console/newport_con.c
index 03041311711b..7fa1afeae8dc 100644
--- a/drivers/video/console/newport_con.c
+++ b/drivers/video/console/newport_con.c
@@ -12,7 +12,6 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/errno.h> 14#include <linux/errno.h>
15#include <linux/tty.h>
16#include <linux/kd.h> 15#include <linux/kd.h>
17#include <linux/selection.h> 16#include <linux/selection.h>
18#include <linux/console.h> 17#include <linux/console.h>
diff --git a/drivers/video/console/promcon.c b/drivers/video/console/promcon.c
index 5cd5e114d1e6..b78eac63459f 100644
--- a/drivers/video/console/promcon.c
+++ b/drivers/video/console/promcon.c
@@ -10,7 +10,6 @@
10#include <linux/errno.h> 10#include <linux/errno.h>
11#include <linux/string.h> 11#include <linux/string.h>
12#include <linux/mm.h> 12#include <linux/mm.h>
13#include <linux/tty.h>
14#include <linux/slab.h> 13#include <linux/slab.h>
15#include <linux/delay.h> 14#include <linux/delay.h>
16#include <linux/console.h> 15#include <linux/console.h>
diff --git a/drivers/video/console/softcursor.c b/drivers/video/console/softcursor.c
index 3957fc7523e2..557c563e4aed 100644
--- a/drivers/video/console/softcursor.c
+++ b/drivers/video/console/softcursor.c
@@ -10,7 +10,6 @@
10 10
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/string.h> 12#include <linux/string.h>
13#include <linux/tty.h>
14#include <linux/fb.h> 13#include <linux/fb.h>
15#include <linux/slab.h> 14#include <linux/slab.h>
16 15
diff --git a/drivers/video/console/sticon.c b/drivers/video/console/sticon.c
index 45c4f227e56e..45586aaabd1e 100644
--- a/drivers/video/console/sticon.c
+++ b/drivers/video/console/sticon.c
@@ -37,7 +37,6 @@
37 37
38#include <linux/init.h> 38#include <linux/init.h>
39#include <linux/kernel.h> 39#include <linux/kernel.h>
40#include <linux/tty.h>
41#include <linux/console.h> 40#include <linux/console.h>
42#include <linux/errno.h> 41#include <linux/errno.h>
43#include <linux/vt_kern.h> 42#include <linux/vt_kern.h>
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index 05735ff4e9c5..0a2c10a1abf8 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -38,7 +38,6 @@
38#include <linux/sched.h> 38#include <linux/sched.h>
39#include <linux/fs.h> 39#include <linux/fs.h>
40#include <linux/kernel.h> 40#include <linux/kernel.h>
41#include <linux/tty.h>
42#include <linux/console.h> 41#include <linux/console.h>
43#include <linux/string.h> 42#include <linux/string.h>
44#include <linux/kd.h> 43#include <linux/kd.h>
@@ -48,6 +47,7 @@
48#include <linux/spinlock.h> 47#include <linux/spinlock.h>
49#include <linux/ioport.h> 48#include <linux/ioport.h>
50#include <linux/init.h> 49#include <linux/init.h>
50#include <linux/screen_info.h>
51#include <linux/smp_lock.h> 51#include <linux/smp_lock.h>
52#include <video/vga.h> 52#include <video/vga.h>
53#include <asm/io.h> 53#include <asm/io.h>
diff --git a/drivers/video/controlfb.c b/drivers/video/controlfb.c
index acdd6a103dbb..8cc6c0e2d27a 100644
--- a/drivers/video/controlfb.c
+++ b/drivers/video/controlfb.c
@@ -36,7 +36,6 @@
36#include <linux/errno.h> 36#include <linux/errno.h>
37#include <linux/string.h> 37#include <linux/string.h>
38#include <linux/mm.h> 38#include <linux/mm.h>
39#include <linux/tty.h>
40#include <linux/slab.h> 39#include <linux/slab.h>
41#include <linux/vmalloc.h> 40#include <linux/vmalloc.h>
42#include <linux/delay.h> 41#include <linux/delay.h>
diff --git a/drivers/video/cyber2000fb.c b/drivers/video/cyber2000fb.c
index 2e2924957d8f..aae6d9c26e88 100644
--- a/drivers/video/cyber2000fb.c
+++ b/drivers/video/cyber2000fb.c
@@ -41,7 +41,6 @@
41#include <linux/errno.h> 41#include <linux/errno.h>
42#include <linux/string.h> 42#include <linux/string.h>
43#include <linux/mm.h> 43#include <linux/mm.h>
44#include <linux/tty.h>
45#include <linux/slab.h> 44#include <linux/slab.h>
46#include <linux/delay.h> 45#include <linux/delay.h>
47#include <linux/fb.h> 46#include <linux/fb.h>
diff --git a/drivers/video/cyberfb.c b/drivers/video/cyberfb.c
index a3e189f90a7d..c40e72dafb0e 100644
--- a/drivers/video/cyberfb.c
+++ b/drivers/video/cyberfb.c
@@ -81,7 +81,6 @@
81#include <linux/errno.h> 81#include <linux/errno.h>
82#include <linux/string.h> 82#include <linux/string.h>
83#include <linux/mm.h> 83#include <linux/mm.h>
84#include <linux/tty.h>
85#include <linux/slab.h> 84#include <linux/slab.h>
86#include <linux/delay.h> 85#include <linux/delay.h>
87#include <linux/zorro.h> 86#include <linux/zorro.h>
diff --git a/drivers/video/dnfb.c b/drivers/video/dnfb.c
index 5abd3cb00671..b083ea7e9c69 100644
--- a/drivers/video/dnfb.c
+++ b/drivers/video/dnfb.c
@@ -2,7 +2,6 @@
2#include <linux/errno.h> 2#include <linux/errno.h>
3#include <linux/string.h> 3#include <linux/string.h>
4#include <linux/mm.h> 4#include <linux/mm.h>
5#include <linux/tty.h>
6#include <linux/slab.h> 5#include <linux/slab.h>
7#include <linux/delay.h> 6#include <linux/delay.h>
8#include <linux/interrupt.h> 7#include <linux/interrupt.h>
diff --git a/drivers/video/epson1355fb.c b/drivers/video/epson1355fb.c
index f0a621ecc288..737257d278f0 100644
--- a/drivers/video/epson1355fb.c
+++ b/drivers/video/epson1355fb.c
@@ -48,7 +48,6 @@
48#include <linux/errno.h> 48#include <linux/errno.h>
49#include <linux/string.h> 49#include <linux/string.h>
50#include <linux/mm.h> 50#include <linux/mm.h>
51#include <linux/tty.h>
52#include <linux/slab.h> 51#include <linux/slab.h>
53#include <linux/delay.h> 52#include <linux/delay.h>
54#include <linux/fb.h> 53#include <linux/fb.h>
diff --git a/drivers/video/fb_notify.c b/drivers/video/fb_notify.c
new file mode 100644
index 000000000000..8c020389e4fa
--- /dev/null
+++ b/drivers/video/fb_notify.c
@@ -0,0 +1,46 @@
1/*
2 * linux/drivers/video/fb_notify.c
3 *
4 * Copyright (C) 2006 Antonino Daplas <adaplas@pol.net>
5 *
6 * 2001 - Documented with DocBook
7 * - Brad Douglas <brad@neruo.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive
11 * for more details.
12 */
13#include <linux/fb.h>
14#include <linux/notifier.h>
15
16static BLOCKING_NOTIFIER_HEAD(fb_notifier_list);
17
18/**
19 * fb_register_client - register a client notifier
20 * @nb: notifier block to callback on events
21 */
22int fb_register_client(struct notifier_block *nb)
23{
24 return blocking_notifier_chain_register(&fb_notifier_list, nb);
25}
26EXPORT_SYMBOL(fb_register_client);
27
28/**
29 * fb_unregister_client - unregister a client notifier
30 * @nb: notifier block to callback on events
31 */
32int fb_unregister_client(struct notifier_block *nb)
33{
34 return blocking_notifier_chain_unregister(&fb_notifier_list, nb);
35}
36EXPORT_SYMBOL(fb_unregister_client);
37
38/**
39 * fb_notifier_call_chain - notify clients of fb_events
40 *
41 */
42int fb_notifier_call_chain(unsigned long val, void *v)
43{
44 return blocking_notifier_call_chain(&fb_notifier_list, val, v);
45}
46EXPORT_SYMBOL_GPL(fb_notifier_call_chain);
diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
index 1f98392a43b3..e8b135f3d80d 100644
--- a/drivers/video/fbcmap.c
+++ b/drivers/video/fbcmap.c
@@ -13,7 +13,6 @@
13 13
14#include <linux/string.h> 14#include <linux/string.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/tty.h>
17#include <linux/fb.h> 16#include <linux/fb.h>
18#include <linux/slab.h> 17#include <linux/slab.h>
19 18
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 33034f81114d..17961e3ecaa0 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -23,7 +23,7 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/mm.h> 24#include <linux/mm.h>
25#include <linux/mman.h> 25#include <linux/mman.h>
26#include <linux/tty.h> 26#include <linux/vt.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/linux_logo.h> 28#include <linux/linux_logo.h>
29#include <linux/proc_fs.h> 29#include <linux/proc_fs.h>
@@ -52,7 +52,6 @@
52 52
53#define FBPIXMAPSIZE (1024 * 8) 53#define FBPIXMAPSIZE (1024 * 8)
54 54
55static BLOCKING_NOTIFIER_HEAD(fb_notifier_list);
56struct fb_info *registered_fb[FB_MAX]; 55struct fb_info *registered_fb[FB_MAX];
57int num_registered_fb; 56int num_registered_fb;
58 57
@@ -791,8 +790,7 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
791 790
792 event.info = info; 791 event.info = info;
793 event.data = &mode1; 792 event.data = &mode1;
794 ret = blocking_notifier_call_chain(&fb_notifier_list, 793 ret = fb_notifier_call_chain(FB_EVENT_MODE_DELETE, &event);
795 FB_EVENT_MODE_DELETE, &event);
796 } 794 }
797 795
798 if (!ret) 796 if (!ret)
@@ -837,8 +835,7 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
837 835
838 info->flags &= ~FBINFO_MISC_USEREVENT; 836 info->flags &= ~FBINFO_MISC_USEREVENT;
839 event.info = info; 837 event.info = info;
840 blocking_notifier_call_chain(&fb_notifier_list, 838 fb_notifier_call_chain(evnt, &event);
841 evnt, &event);
842 } 839 }
843 } 840 }
844 } 841 }
@@ -861,8 +858,7 @@ fb_blank(struct fb_info *info, int blank)
861 858
862 event.info = info; 859 event.info = info;
863 event.data = &blank; 860 event.data = &blank;
864 blocking_notifier_call_chain(&fb_notifier_list, 861 fb_notifier_call_chain(FB_EVENT_BLANK, &event);
865 FB_EVENT_BLANK, &event);
866 } 862 }
867 863
868 return ret; 864 return ret;
@@ -933,8 +929,7 @@ fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
933 con2fb.framebuffer = -1; 929 con2fb.framebuffer = -1;
934 event.info = info; 930 event.info = info;
935 event.data = &con2fb; 931 event.data = &con2fb;
936 blocking_notifier_call_chain(&fb_notifier_list, 932 fb_notifier_call_chain(FB_EVENT_GET_CONSOLE_MAP, &event);
937 FB_EVENT_GET_CONSOLE_MAP, &event);
938 return copy_to_user(argp, &con2fb, 933 return copy_to_user(argp, &con2fb,
939 sizeof(con2fb)) ? -EFAULT : 0; 934 sizeof(con2fb)) ? -EFAULT : 0;
940 case FBIOPUT_CON2FBMAP: 935 case FBIOPUT_CON2FBMAP:
@@ -952,9 +947,8 @@ fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
952 return -EINVAL; 947 return -EINVAL;
953 event.info = info; 948 event.info = info;
954 event.data = &con2fb; 949 event.data = &con2fb;
955 return blocking_notifier_call_chain(&fb_notifier_list, 950 return fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP,
956 FB_EVENT_SET_CONSOLE_MAP, 951 &event);
957 &event);
958 case FBIOBLANK: 952 case FBIOBLANK:
959 acquire_console_sem(); 953 acquire_console_sem();
960 info->flags |= FBINFO_MISC_USEREVENT; 954 info->flags |= FBINFO_MISC_USEREVENT;
@@ -1330,8 +1324,7 @@ register_framebuffer(struct fb_info *fb_info)
1330 registered_fb[i] = fb_info; 1324 registered_fb[i] = fb_info;
1331 1325
1332 event.info = fb_info; 1326 event.info = fb_info;
1333 blocking_notifier_call_chain(&fb_notifier_list, 1327 fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
1334 FB_EVENT_FB_REGISTERED, &event);
1335 return 0; 1328 return 0;
1336} 1329}
1337 1330
@@ -1365,30 +1358,11 @@ unregister_framebuffer(struct fb_info *fb_info)
1365 fb_cleanup_class_device(fb_info); 1358 fb_cleanup_class_device(fb_info);
1366 class_device_destroy(fb_class, MKDEV(FB_MAJOR, i)); 1359 class_device_destroy(fb_class, MKDEV(FB_MAJOR, i));
1367 event.info = fb_info; 1360 event.info = fb_info;
1368 blocking_notifier_call_chain(&fb_notifier_list, 1361 fb_notifier_call_chain(FB_EVENT_FB_UNREGISTERED, &event);
1369 FB_EVENT_FB_UNREGISTERED, &event);
1370 return 0; 1362 return 0;
1371} 1363}
1372 1364
1373/** 1365/**
1374 * fb_register_client - register a client notifier
1375 * @nb: notifier block to callback on events
1376 */
1377int fb_register_client(struct notifier_block *nb)
1378{
1379 return blocking_notifier_chain_register(&fb_notifier_list, nb);
1380}
1381
1382/**
1383 * fb_unregister_client - unregister a client notifier
1384 * @nb: notifier block to callback on events
1385 */
1386int fb_unregister_client(struct notifier_block *nb)
1387{
1388 return blocking_notifier_chain_unregister(&fb_notifier_list, nb);
1389}
1390
1391/**
1392 * fb_set_suspend - low level driver signals suspend 1366 * fb_set_suspend - low level driver signals suspend
1393 * @info: framebuffer affected 1367 * @info: framebuffer affected
1394 * @state: 0 = resuming, !=0 = suspending 1368 * @state: 0 = resuming, !=0 = suspending
@@ -1403,13 +1377,11 @@ void fb_set_suspend(struct fb_info *info, int state)
1403 1377
1404 event.info = info; 1378 event.info = info;
1405 if (state) { 1379 if (state) {
1406 blocking_notifier_call_chain(&fb_notifier_list, 1380 fb_notifier_call_chain(FB_EVENT_SUSPEND, &event);
1407 FB_EVENT_SUSPEND, &event);
1408 info->state = FBINFO_STATE_SUSPENDED; 1381 info->state = FBINFO_STATE_SUSPENDED;
1409 } else { 1382 } else {
1410 info->state = FBINFO_STATE_RUNNING; 1383 info->state = FBINFO_STATE_RUNNING;
1411 blocking_notifier_call_chain(&fb_notifier_list, 1384 fb_notifier_call_chain(FB_EVENT_RESUME, &event);
1412 FB_EVENT_RESUME, &event);
1413 } 1385 }
1414} 1386}
1415 1387
@@ -1480,9 +1452,7 @@ int fb_new_modelist(struct fb_info *info)
1480 1452
1481 if (!list_empty(&info->modelist)) { 1453 if (!list_empty(&info->modelist)) {
1482 event.info = info; 1454 event.info = info;
1483 err = blocking_notifier_call_chain(&fb_notifier_list, 1455 err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event);
1484 FB_EVENT_NEW_MODELIST,
1485 &event);
1486 } 1456 }
1487 1457
1488 return err; 1458 return err;
@@ -1594,8 +1564,6 @@ EXPORT_SYMBOL(fb_blank);
1594EXPORT_SYMBOL(fb_pan_display); 1564EXPORT_SYMBOL(fb_pan_display);
1595EXPORT_SYMBOL(fb_get_buffer_offset); 1565EXPORT_SYMBOL(fb_get_buffer_offset);
1596EXPORT_SYMBOL(fb_set_suspend); 1566EXPORT_SYMBOL(fb_set_suspend);
1597EXPORT_SYMBOL(fb_register_client);
1598EXPORT_SYMBOL(fb_unregister_client);
1599EXPORT_SYMBOL(fb_get_options); 1567EXPORT_SYMBOL(fb_get_options);
1600 1568
1601MODULE_LICENSE("GPL"); 1569MODULE_LICENSE("GPL");
diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 3ccfff715a51..de93139ccbb5 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -26,7 +26,6 @@
26 * for more details. 26 * for more details.
27 * 27 *
28 */ 28 */
29#include <linux/tty.h>
30#include <linux/fb.h> 29#include <linux/fb.h>
31#include <linux/module.h> 30#include <linux/module.h>
32#include <linux/pci.h> 31#include <linux/pci.h>
diff --git a/drivers/video/g364fb.c b/drivers/video/g364fb.c
index 605d1a132020..1b981b635675 100644
--- a/drivers/video/g364fb.c
+++ b/drivers/video/g364fb.c
@@ -21,7 +21,6 @@
21#include <linux/errno.h> 21#include <linux/errno.h>
22#include <linux/string.h> 22#include <linux/string.h>
23#include <linux/mm.h> 23#include <linux/mm.h>
24#include <linux/tty.h>
25#include <linux/slab.h> 24#include <linux/slab.h>
26#include <linux/vmalloc.h> 25#include <linux/vmalloc.h>
27#include <linux/delay.h> 26#include <linux/delay.h>
diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
index 4d3a8871d3d1..bcf9cea54d8b 100644
--- a/drivers/video/geode/gx1fb_core.c
+++ b/drivers/video/geode/gx1fb_core.c
@@ -15,7 +15,6 @@
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <linux/tty.h>
19#include <linux/slab.h> 18#include <linux/slab.h>
20#include <linux/delay.h> 19#include <linux/delay.h>
21#include <linux/fb.h> 20#include <linux/fb.h>
diff --git a/drivers/video/geode/gxfb_core.c b/drivers/video/geode/gxfb_core.c
index 5ef12a3dfa50..0d3643fc6293 100644
--- a/drivers/video/geode/gxfb_core.c
+++ b/drivers/video/geode/gxfb_core.c
@@ -25,7 +25,6 @@
25#include <linux/errno.h> 25#include <linux/errno.h>
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/mm.h> 27#include <linux/mm.h>
28#include <linux/tty.h>
29#include <linux/slab.h> 28#include <linux/slab.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
31#include <linux/fb.h> 30#include <linux/fb.h>
diff --git a/drivers/video/hgafb.c b/drivers/video/hgafb.c
index 4e39035cf335..fb9e67228543 100644
--- a/drivers/video/hgafb.c
+++ b/drivers/video/hgafb.c
@@ -36,7 +36,6 @@
36#include <linux/spinlock.h> 36#include <linux/spinlock.h>
37#include <linux/string.h> 37#include <linux/string.h>
38#include <linux/mm.h> 38#include <linux/mm.h>
39#include <linux/tty.h>
40#include <linux/slab.h> 39#include <linux/slab.h>
41#include <linux/delay.h> 40#include <linux/delay.h>
42#include <linux/fb.h> 41#include <linux/fb.h>
diff --git a/drivers/video/hitfb.c b/drivers/video/hitfb.c
index 01864767450d..4cc6b454265e 100644
--- a/drivers/video/hitfb.c
+++ b/drivers/video/hitfb.c
@@ -17,7 +17,6 @@
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/mm.h> 19#include <linux/mm.h>
20#include <linux/tty.h>
21#include <linux/slab.h> 20#include <linux/slab.h>
22#include <linux/delay.h> 21#include <linux/delay.h>
23#include <linux/init.h> 22#include <linux/init.h>
diff --git a/drivers/video/hpfb.c b/drivers/video/hpfb.c
index abd920a663a0..91cf3b577d15 100644
--- a/drivers/video/hpfb.c
+++ b/drivers/video/hpfb.c
@@ -11,7 +11,6 @@
11#include <linux/errno.h> 11#include <linux/errno.h>
12#include <linux/string.h> 12#include <linux/string.h>
13#include <linux/mm.h> 13#include <linux/mm.h>
14#include <linux/tty.h>
15#include <linux/slab.h> 14#include <linux/slab.h>
16#include <linux/delay.h> 15#include <linux/delay.h>
17#include <linux/init.h> 16#include <linux/init.h>
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index fbe8a2c4b04c..a6ca02f2156a 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -33,7 +33,6 @@
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/string.h> 34#include <linux/string.h>
35#include <linux/mm.h> 35#include <linux/mm.h>
36#include <linux/tty.h>
37#include <linux/slab.h> 36#include <linux/slab.h>
38#include <linux/fb.h> 37#include <linux/fb.h>
39#include <linux/init.h> 38#include <linux/init.h>
diff --git a/drivers/video/igafb.c b/drivers/video/igafb.c
index 8a0c2d3d3805..67f384f86758 100644
--- a/drivers/video/igafb.c
+++ b/drivers/video/igafb.c
@@ -33,7 +33,6 @@
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/string.h> 34#include <linux/string.h>
35#include <linux/mm.h> 35#include <linux/mm.h>
36#include <linux/tty.h>
37#include <linux/slab.h> 36#include <linux/slab.h>
38#include <linux/vmalloc.h> 37#include <linux/vmalloc.h>
39#include <linux/delay.h> 38#include <linux/delay.h>
diff --git a/drivers/video/imacfb.c b/drivers/video/imacfb.c
index cdbae173d69a..18ea4a549105 100644
--- a/drivers/video/imacfb.c
+++ b/drivers/video/imacfb.c
@@ -15,9 +15,11 @@
15#include <linux/mm.h> 15#include <linux/mm.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/screen_info.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19#include <linux/string.h> 20#include <linux/string.h>
20#include <linux/tty.h> 21#include <linux/dmi.h>
22#include <linux/efi.h>
21 23
22#include <asm/io.h> 24#include <asm/io.h>
23 25
@@ -28,7 +30,7 @@ typedef enum _MAC_TYPE {
28 M_I20, 30 M_I20,
29 M_MINI, 31 M_MINI,
30 M_MACBOOK, 32 M_MACBOOK,
31 M_NEW 33 M_UNKNOWN
32} MAC_TYPE; 34} MAC_TYPE;
33 35
34/* --------------------------------------------------------------------- */ 36/* --------------------------------------------------------------------- */
@@ -52,10 +54,36 @@ static struct fb_fix_screeninfo imacfb_fix __initdata = {
52}; 54};
53 55
54static int inverse; 56static int inverse;
55static int model = M_NEW; 57static int model = M_UNKNOWN;
56static int manual_height; 58static int manual_height;
57static int manual_width; 59static int manual_width;
58 60
61static int set_system(struct dmi_system_id *id)
62{
63 printk(KERN_INFO "imacfb: %s detected - set system to %ld\n",
64 id->ident, (long)id->driver_data);
65
66 model = (long)id->driver_data;
67
68 return 0;
69}
70
71static struct dmi_system_id __initdata dmi_system_table[] = {
72 { set_system, "iMac4,1", {
73 DMI_MATCH(DMI_BIOS_VENDOR,"Apple Computer, Inc."),
74 DMI_MATCH(DMI_PRODUCT_NAME,"iMac4,1") }, (void*)M_I17},
75 { set_system, "MacBookPro1,1", {
76 DMI_MATCH(DMI_BIOS_VENDOR,"Apple Computer, Inc."),
77 DMI_MATCH(DMI_PRODUCT_NAME,"MacBookPro1,1") }, (void*)M_I17},
78 { set_system, "MacBook1,1", {
79 DMI_MATCH(DMI_BIOS_VENDOR,"Apple Computer, Inc."),
80 DMI_MATCH(DMI_PRODUCT_NAME,"MacBook1,1")}, (void *)M_MACBOOK},
81 { set_system, "Macmini1,1", {
82 DMI_MATCH(DMI_BIOS_VENDOR,"Apple Computer, Inc."),
83 DMI_MATCH(DMI_PRODUCT_NAME,"Macmini1,1")}, (void *)M_MINI},
84 {},
85};
86
59#define DEFAULT_FB_MEM 1024*1024*16 87#define DEFAULT_FB_MEM 1024*1024*16
60 88
61/* --------------------------------------------------------------------- */ 89/* --------------------------------------------------------------------- */
@@ -149,7 +177,6 @@ static int __init imacfb_probe(struct platform_device *dev)
149 screen_info.lfb_linelength = 1472 * 4; 177 screen_info.lfb_linelength = 1472 * 4;
150 screen_info.lfb_base = 0x80010000; 178 screen_info.lfb_base = 0x80010000;
151 break; 179 break;
152 case M_NEW:
153 case M_I20: 180 case M_I20:
154 screen_info.lfb_width = 1680; 181 screen_info.lfb_width = 1680;
155 screen_info.lfb_height = 1050; 182 screen_info.lfb_height = 1050;
@@ -207,6 +234,10 @@ static int __init imacfb_probe(struct platform_device *dev)
207 size_remap = size_total; 234 size_remap = size_total;
208 imacfb_fix.smem_len = size_remap; 235 imacfb_fix.smem_len = size_remap;
209 236
237#ifndef __i386__
238 screen_info.imacpm_seg = 0;
239#endif
240
210 if (!request_mem_region(imacfb_fix.smem_start, size_total, "imacfb")) { 241 if (!request_mem_region(imacfb_fix.smem_start, size_total, "imacfb")) {
211 printk(KERN_WARNING 242 printk(KERN_WARNING
212 "imacfb: cannot reserve video memory at 0x%lx\n", 243 "imacfb: cannot reserve video memory at 0x%lx\n",
@@ -324,8 +355,16 @@ static int __init imacfb_init(void)
324 int ret; 355 int ret;
325 char *option = NULL; 356 char *option = NULL;
326 357
327 /* ignore error return of fb_get_options */ 358 if (!efi_enabled)
328 fb_get_options("imacfb", &option); 359 return -ENODEV;
360 if (!dmi_check_system(dmi_system_table))
361 return -ENODEV;
362 if (model == M_UNKNOWN)
363 return -ENODEV;
364
365 if (fb_get_options("imacfb", &option))
366 return -ENODEV;
367
329 imacfb_setup(option); 368 imacfb_setup(option);
330 ret = platform_driver_register(&imacfb_driver); 369 ret = platform_driver_register(&imacfb_driver);
331 370
diff --git a/drivers/video/imsttfb.c b/drivers/video/imsttfb.c
index 5f393d985b11..5715b8ad0ddc 100644
--- a/drivers/video/imsttfb.c
+++ b/drivers/video/imsttfb.c
@@ -21,7 +21,6 @@
21#include <linux/errno.h> 21#include <linux/errno.h>
22#include <linux/string.h> 22#include <linux/string.h>
23#include <linux/mm.h> 23#include <linux/mm.h>
24#include <linux/tty.h>
25#include <linux/slab.h> 24#include <linux/slab.h>
26#include <linux/vmalloc.h> 25#include <linux/vmalloc.h>
27#include <linux/delay.h> 26#include <linux/delay.h>
diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c
index 3f39d84015f1..06af89d44a0d 100644
--- a/drivers/video/intelfb/intelfbdrv.c
+++ b/drivers/video/intelfb/intelfbdrv.c
@@ -113,7 +113,6 @@
113#include <linux/errno.h> 113#include <linux/errno.h>
114#include <linux/string.h> 114#include <linux/string.h>
115#include <linux/mm.h> 115#include <linux/mm.h>
116#include <linux/tty.h>
117#include <linux/slab.h> 116#include <linux/slab.h>
118#include <linux/delay.h> 117#include <linux/delay.h>
119#include <linux/fb.h> 118#include <linux/fb.h>
@@ -122,6 +121,7 @@
122#include <linux/pci.h> 121#include <linux/pci.h>
123#include <linux/vmalloc.h> 122#include <linux/vmalloc.h>
124#include <linux/pagemap.h> 123#include <linux/pagemap.h>
124#include <linux/screen_info.h>
125 125
126#include <asm/io.h> 126#include <asm/io.h>
127 127
diff --git a/drivers/video/intelfb/intelfbhw.c b/drivers/video/intelfb/intelfbhw.c
index 3b78a57924f0..2a9322f9cfdc 100644
--- a/drivers/video/intelfb/intelfbhw.c
+++ b/drivers/video/intelfb/intelfbhw.c
@@ -24,7 +24,6 @@
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/string.h> 25#include <linux/string.h>
26#include <linux/mm.h> 26#include <linux/mm.h>
27#include <linux/tty.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29#include <linux/delay.h> 28#include <linux/delay.h>
30#include <linux/fb.h> 29#include <linux/fb.h>
diff --git a/drivers/video/kyro/fbdev.c b/drivers/video/kyro/fbdev.c
index 2fdbe9b2b04b..f0d614a80f1f 100644
--- a/drivers/video/kyro/fbdev.c
+++ b/drivers/video/kyro/fbdev.c
@@ -16,7 +16,6 @@
16#include <linux/mm.h> 16#include <linux/mm.h>
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/tty.h>
20#include <linux/delay.h> 19#include <linux/delay.h>
21#include <linux/fb.h> 20#include <linux/fb.h>
22#include <linux/ioctl.h> 21#include <linux/ioctl.h>
diff --git a/drivers/video/macfb.c b/drivers/video/macfb.c
index e6cbd9de944a..80a043807161 100644
--- a/drivers/video/macfb.c
+++ b/drivers/video/macfb.c
@@ -24,7 +24,6 @@
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/string.h> 25#include <linux/string.h>
26#include <linux/mm.h> 26#include <linux/mm.h>
27#include <linux/tty.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29#include <linux/delay.h> 28#include <linux/delay.h>
30#include <linux/nubus.h> 29#include <linux/nubus.h>
diff --git a/drivers/video/matrox/g450_pll.c b/drivers/video/matrox/g450_pll.c
index 440272ad10e7..7c76e079ca7d 100644
--- a/drivers/video/matrox/g450_pll.c
+++ b/drivers/video/matrox/g450_pll.c
@@ -331,7 +331,15 @@ static int __g450_setclk(WPMINFO unsigned int fout, unsigned int pll,
331 tmp |= M1064_XPIXCLKCTRL_PLL_UP; 331 tmp |= M1064_XPIXCLKCTRL_PLL_UP;
332 } 332 }
333 matroxfb_DAC_out(PMINFO M1064_XPIXCLKCTRL, tmp); 333 matroxfb_DAC_out(PMINFO M1064_XPIXCLKCTRL, tmp);
334#ifdef __powerpc__
335 /* This is necessary to avoid jitter on PowerPC
336 * (OpenFirmware) systems, but apparently
337 * introduces jitter, at least on a x86-64
338 * using DVI.
339 * A simple workaround is disable for non-PPC.
340 */
334 matroxfb_DAC_out(PMINFO M1064_XDVICLKCTRL, 0); 341 matroxfb_DAC_out(PMINFO M1064_XDVICLKCTRL, 0);
342#endif /* __powerpc__ */
335 matroxfb_DAC_out(PMINFO M1064_XPWRCTRL, xpwrctrl); 343 matroxfb_DAC_out(PMINFO M1064_XPWRCTRL, xpwrctrl);
336 344
337 matroxfb_DAC_unlock_irqrestore(flags); 345 matroxfb_DAC_unlock_irqrestore(flags);
diff --git a/drivers/video/matrox/matroxfb_base.h b/drivers/video/matrox/matroxfb_base.h
index b95779b57c06..9c25c2f7966b 100644
--- a/drivers/video/matrox/matroxfb_base.h
+++ b/drivers/video/matrox/matroxfb_base.h
@@ -30,7 +30,6 @@
30#include <linux/errno.h> 30#include <linux/errno.h>
31#include <linux/string.h> 31#include <linux/string.h>
32#include <linux/mm.h> 32#include <linux/mm.h>
33#include <linux/tty.h>
34#include <linux/slab.h> 33#include <linux/slab.h>
35#include <linux/delay.h> 34#include <linux/delay.h>
36#include <linux/fb.h> 35#include <linux/fb.h>
diff --git a/drivers/video/maxinefb.c b/drivers/video/maxinefb.c
index f85421bf7cb5..38c8d38de4fd 100644
--- a/drivers/video/maxinefb.c
+++ b/drivers/video/maxinefb.c
@@ -29,7 +29,6 @@
29#include <linux/errno.h> 29#include <linux/errno.h>
30#include <linux/string.h> 30#include <linux/string.h>
31#include <linux/mm.h> 31#include <linux/mm.h>
32#include <linux/tty.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
34#include <linux/delay.h> 33#include <linux/delay.h>
35#include <linux/init.h> 34#include <linux/init.h>
diff --git a/drivers/video/mbx/Makefile b/drivers/video/mbx/Makefile
new file mode 100644
index 000000000000..16c1165cf9c7
--- /dev/null
+++ b/drivers/video/mbx/Makefile
@@ -0,0 +1,4 @@
1# Makefile for the 2700G controller driver.
2
3obj-$(CONFIG_FB_MBX) += mbxfb.o
4obj-$(CONFIG_FB_MBX_DEBUG) += mbxfbdebugfs.o
diff --git a/drivers/video/mbx/mbxdebugfs.c b/drivers/video/mbx/mbxdebugfs.c
new file mode 100644
index 000000000000..84aab3ad024e
--- /dev/null
+++ b/drivers/video/mbx/mbxdebugfs.c
@@ -0,0 +1,188 @@
1#include <linux/debugfs.h>
2
3#define BIG_BUFFER_SIZE (1024)
4
5static char big_buffer[BIG_BUFFER_SIZE];
6
7struct mbxfb_debugfs_data {
8 struct dentry *dir;
9 struct dentry *sysconf;
10 struct dentry *clock;
11 struct dentry *display;
12 struct dentry *gsctl;
13};
14
15static int open_file_generic(struct inode *inode, struct file *file)
16{
17 file->private_data = inode->u.generic_ip;
18 return 0;
19}
20
21static ssize_t write_file_dummy(struct file *file, const char __user *buf,
22 size_t count, loff_t *ppos)
23{
24 return count;
25}
26
27static ssize_t sysconf_read_file(struct file *file, char __user *userbuf,
28 size_t count, loff_t *ppos)
29{
30 char * s = big_buffer;
31
32 s += sprintf(s, "SYSCFG = %08lx\n", SYSCFG);
33 s += sprintf(s, "PFBASE = %08lx\n", PFBASE);
34 s += sprintf(s, "PFCEIL = %08lx\n", PFCEIL);
35 s += sprintf(s, "POLLFLAG = %08lx\n", POLLFLAG);
36 s += sprintf(s, "SYSRST = %08lx\n", SYSRST);
37
38 return simple_read_from_buffer(userbuf, count, ppos,
39 big_buffer, s-big_buffer);
40}
41
42
43static ssize_t gsctl_read_file(struct file *file, char __user *userbuf,
44 size_t count, loff_t *ppos)
45{
46 char * s = big_buffer;
47
48 s += sprintf(s, "GSCTRL = %08lx\n", GSCTRL);
49 s += sprintf(s, "VSCTRL = %08lx\n", VSCTRL);
50 s += sprintf(s, "GBBASE = %08lx\n", GBBASE);
51 s += sprintf(s, "VBBASE = %08lx\n", VBBASE);
52 s += sprintf(s, "GDRCTRL = %08lx\n", GDRCTRL);
53 s += sprintf(s, "VCMSK = %08lx\n", VCMSK);
54 s += sprintf(s, "GSCADR = %08lx\n", GSCADR);
55 s += sprintf(s, "VSCADR = %08lx\n", VSCADR);
56 s += sprintf(s, "VUBASE = %08lx\n", VUBASE);
57 s += sprintf(s, "VVBASE = %08lx\n", VVBASE);
58 s += sprintf(s, "GSADR = %08lx\n", GSADR);
59 s += sprintf(s, "VSADR = %08lx\n", VSADR);
60 s += sprintf(s, "HCCTRL = %08lx\n", HCCTRL);
61 s += sprintf(s, "HCSIZE = %08lx\n", HCSIZE);
62 s += sprintf(s, "HCPOS = %08lx\n", HCPOS);
63 s += sprintf(s, "HCBADR = %08lx\n", HCBADR);
64 s += sprintf(s, "HCCKMSK = %08lx\n", HCCKMSK);
65 s += sprintf(s, "GPLUT = %08lx\n", GPLUT);
66
67 return simple_read_from_buffer(userbuf, count, ppos,
68 big_buffer, s-big_buffer);
69}
70
71static ssize_t display_read_file(struct file *file, char __user *userbuf,
72 size_t count, loff_t *ppos)
73{
74 char * s = big_buffer;
75
76 s += sprintf(s, "DSCTRL = %08lx\n", DSCTRL);
77 s += sprintf(s, "DHT01 = %08lx\n", DHT01);
78 s += sprintf(s, "DHT02 = %08lx\n", DHT02);
79 s += sprintf(s, "DHT03 = %08lx\n", DHT03);
80 s += sprintf(s, "DVT01 = %08lx\n", DVT01);
81 s += sprintf(s, "DVT02 = %08lx\n", DVT02);
82 s += sprintf(s, "DVT03 = %08lx\n", DVT03);
83 s += sprintf(s, "DBCOL = %08lx\n", DBCOL);
84 s += sprintf(s, "BGCOLOR = %08lx\n", BGCOLOR);
85 s += sprintf(s, "DINTRS = %08lx\n", DINTRS);
86 s += sprintf(s, "DINTRE = %08lx\n", DINTRE);
87 s += sprintf(s, "DINTRCNT = %08lx\n", DINTRCNT);
88 s += sprintf(s, "DSIG = %08lx\n", DSIG);
89 s += sprintf(s, "DMCTRL = %08lx\n", DMCTRL);
90 s += sprintf(s, "CLIPCTRL = %08lx\n", CLIPCTRL);
91 s += sprintf(s, "SPOCTRL = %08lx\n", SPOCTRL);
92 s += sprintf(s, "SVCTRL = %08lx\n", SVCTRL);
93 s += sprintf(s, "DLSTS = %08lx\n", DLSTS);
94 s += sprintf(s, "DLLCTRL = %08lx\n", DLLCTRL);
95 s += sprintf(s, "DVLNUM = %08lx\n", DVLNUM);
96 s += sprintf(s, "DUCTRL = %08lx\n", DUCTRL);
97 s += sprintf(s, "DVECTRL = %08lx\n", DVECTRL);
98 s += sprintf(s, "DHDET = %08lx\n", DHDET);
99 s += sprintf(s, "DVDET = %08lx\n", DVDET);
100 s += sprintf(s, "DODMSK = %08lx\n", DODMSK);
101 s += sprintf(s, "CSC01 = %08lx\n", CSC01);
102 s += sprintf(s, "CSC02 = %08lx\n", CSC02);
103 s += sprintf(s, "CSC03 = %08lx\n", CSC03);
104 s += sprintf(s, "CSC04 = %08lx\n", CSC04);
105 s += sprintf(s, "CSC05 = %08lx\n", CSC05);
106
107 return simple_read_from_buffer(userbuf, count, ppos,
108 big_buffer, s-big_buffer);
109}
110
111static ssize_t clock_read_file(struct file *file, char __user *userbuf,
112 size_t count, loff_t *ppos)
113{
114 char * s = big_buffer;
115
116 s += sprintf(s, "SYSCLKSRC = %08lx\n", SYSCLKSRC);
117 s += sprintf(s, "PIXCLKSRC = %08lx\n", PIXCLKSRC);
118 s += sprintf(s, "CLKSLEEP = %08lx\n", CLKSLEEP);
119 s += sprintf(s, "COREPLL = %08lx\n", COREPLL);
120 s += sprintf(s, "DISPPLL = %08lx\n", DISPPLL);
121 s += sprintf(s, "PLLSTAT = %08lx\n", PLLSTAT);
122 s += sprintf(s, "VOVRCLK = %08lx\n", VOVRCLK);
123 s += sprintf(s, "PIXCLK = %08lx\n", PIXCLK);
124 s += sprintf(s, "MEMCLK = %08lx\n", MEMCLK);
125 s += sprintf(s, "M24CLK = %08lx\n", M24CLK);
126 s += sprintf(s, "MBXCLK = %08lx\n", MBXCLK);
127 s += sprintf(s, "SDCLK = %08lx\n", SDCLK);
128 s += sprintf(s, "PIXCLKDIV = %08lx\n", PIXCLKDIV);
129
130 return simple_read_from_buffer(userbuf, count, ppos,
131 big_buffer, s-big_buffer);
132}
133
134static struct file_operations sysconf_fops = {
135 .read = sysconf_read_file,
136 .write = write_file_dummy,
137 .open = open_file_generic,
138};
139
140static struct file_operations clock_fops = {
141 .read = clock_read_file,
142 .write = write_file_dummy,
143 .open = open_file_generic,
144};
145
146static struct file_operations display_fops = {
147 .read = display_read_file,
148 .write = write_file_dummy,
149 .open = open_file_generic,
150};
151
152static struct file_operations gsctl_fops = {
153 .read = gsctl_read_file,
154 .write = write_file_dummy,
155 .open = open_file_generic,
156};
157
158
159static void __devinit mbxfb_debugfs_init(struct fb_info *fbi)
160{
161 struct mbxfb_info *mfbi = fbi->par;
162 struct mbxfb_debugfs_data *dbg;
163
164 dbg = kzalloc(sizeof(struct mbxfb_debugfs_data), GFP_KERNEL);
165 mfbi->debugfs_data = dbg;
166
167 dbg->dir = debugfs_create_dir("mbxfb", NULL);
168 dbg->sysconf = debugfs_create_file("sysconf", 0444, dbg->dir,
169 fbi, &sysconf_fops);
170 dbg->clock = debugfs_create_file("clock", 0444, dbg->dir,
171 fbi, &clock_fops);
172 dbg->display = debugfs_create_file("display", 0444, dbg->dir,
173 fbi, &display_fops);
174 dbg->gsctl = debugfs_create_file("gsctl", 0444, dbg->dir,
175 fbi, &gsctl_fops);
176}
177
178static void __devexit mbxfb_debugfs_remove(struct fb_info *fbi)
179{
180 struct mbxfb_info *mfbi = fbi->par;
181 struct mbxfb_debugfs_data *dbg = mfbi->debugfs_data;
182
183 debugfs_remove(dbg->gsctl);
184 debugfs_remove(dbg->display);
185 debugfs_remove(dbg->clock);
186 debugfs_remove(dbg->sysconf);
187 debugfs_remove(dbg->dir);
188}
diff --git a/drivers/video/mbx/mbxfb.c b/drivers/video/mbx/mbxfb.c
new file mode 100644
index 000000000000..6849ab75d403
--- /dev/null
+++ b/drivers/video/mbx/mbxfb.c
@@ -0,0 +1,683 @@
1/*
2 * linux/drivers/video/mbx/mbxfb.c
3 *
4 * Copyright (C) 2006 Compulab, Ltd.
5 * Mike Rapoport <mike@compulab.co.il>
6 *
7 * Based on pxafb.c
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive for
11 * more details.
12 *
13 * Intel 2700G (Marathon) Graphics Accelerator Frame Buffer Driver
14 *
15 */
16
17#include <linux/delay.h>
18#include <linux/fb.h>
19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/platform_device.h>
22
23#include <asm/io.h>
24
25#include <video/mbxfb.h>
26
27#include "regs.h"
28#include "reg_bits.h"
29
30static unsigned long virt_base_2700;
31
32#define MIN_XRES 16
33#define MIN_YRES 16
34#define MAX_XRES 2048
35#define MAX_YRES 2048
36
37#define MAX_PALETTES 16
38
39/* FIXME: take care of different chip revisions with different sizes
40 of ODFB */
41#define MEMORY_OFFSET 0x60000
42
43struct mbxfb_info {
44 struct device *dev;
45
46 struct resource *fb_res;
47 struct resource *fb_req;
48
49 struct resource *reg_res;
50 struct resource *reg_req;
51
52 void __iomem *fb_virt_addr;
53 unsigned long fb_phys_addr;
54
55 void __iomem *reg_virt_addr;
56 unsigned long reg_phys_addr;
57
58 int (*platform_probe) (struct fb_info * fb);
59 int (*platform_remove) (struct fb_info * fb);
60
61 u32 pseudo_palette[MAX_PALETTES];
62#ifdef CONFIG_FB_MBX_DEBUG
63 void *debugfs_data;
64#endif
65
66};
67
68static struct fb_var_screeninfo mbxfb_default __devinitdata = {
69 .xres = 640,
70 .yres = 480,
71 .xres_virtual = 640,
72 .yres_virtual = 480,
73 .bits_per_pixel = 16,
74 .red = {11, 5, 0},
75 .green = {5, 6, 0},
76 .blue = {0, 5, 0},
77 .activate = FB_ACTIVATE_TEST,
78 .height = -1,
79 .width = -1,
80 .pixclock = 40000,
81 .left_margin = 48,
82 .right_margin = 16,
83 .upper_margin = 33,
84 .lower_margin = 10,
85 .hsync_len = 96,
86 .vsync_len = 2,
87 .vmode = FB_VMODE_NONINTERLACED,
88 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
89};
90
91static struct fb_fix_screeninfo mbxfb_fix __devinitdata = {
92 .id = "MBX",
93 .type = FB_TYPE_PACKED_PIXELS,
94 .visual = FB_VISUAL_TRUECOLOR,
95 .xpanstep = 0,
96 .ypanstep = 0,
97 .ywrapstep = 0,
98 .accel = FB_ACCEL_NONE,
99};
100
101struct pixclock_div {
102 u8 m;
103 u8 n;
104 u8 p;
105};
106
107static unsigned int mbxfb_get_pixclock(unsigned int pixclock_ps,
108 struct pixclock_div *div)
109{
110 u8 m, n, p;
111 unsigned int err = 0;
112 unsigned int min_err = ~0x0;
113 unsigned int clk;
114 unsigned int best_clk = 0;
115 unsigned int ref_clk = 13000; /* FIXME: take from platform data */
116 unsigned int pixclock;
117
118 /* convert pixclock to KHz */
119 pixclock = PICOS2KHZ(pixclock_ps);
120
121 for (m = 1; m < 64; m++) {
122 for (n = 1; n < 8; n++) {
123 for (p = 0; p < 8; p++) {
124 clk = (ref_clk * m) / (n * (1 << p));
125 err = (clk > pixclock) ? (clk - pixclock) :
126 (pixclock - clk);
127 if (err < min_err) {
128 min_err = err;
129 best_clk = clk;
130 div->m = m;
131 div->n = n;
132 div->p = p;
133 }
134 }
135 }
136 }
137 return KHZ2PICOS(best_clk);
138}
139
140static int mbxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
141 u_int trans, struct fb_info *info)
142{
143 u32 val, ret = 1;
144
145 if (regno < MAX_PALETTES) {
146 u32 *pal = info->pseudo_palette;
147
148 val = (red & 0xf800) | ((green & 0xfc00) >> 5) |
149 ((blue & 0xf800) >> 11);
150 pal[regno] = val;
151 ret = 0;
152 }
153
154 return ret;
155}
156
157static int mbxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
158{
159 struct pixclock_div div;
160
161 var->pixclock = mbxfb_get_pixclock(var->pixclock, &div);
162
163 if (var->xres < MIN_XRES)
164 var->xres = MIN_XRES;
165 if (var->yres < MIN_YRES)
166 var->yres = MIN_YRES;
167 if (var->xres > MAX_XRES)
168 return -EINVAL;
169 if (var->yres > MAX_YRES)
170 return -EINVAL;
171 var->xres_virtual = max(var->xres_virtual, var->xres);
172 var->yres_virtual = max(var->yres_virtual, var->yres);
173
174 switch (var->bits_per_pixel) {
175 /* 8 bits-per-pixel is not supported yet */
176 case 8:
177 return -EINVAL;
178 case 16:
179 var->green.length = (var->green.length == 5) ? 5 : 6;
180 var->red.length = 5;
181 var->blue.length = 5;
182 var->transp.length = 6 - var->green.length;
183 var->blue.offset = 0;
184 var->green.offset = 5;
185 var->red.offset = 5 + var->green.length;
186 var->transp.offset = (5 + var->red.offset) & 15;
187 break;
188 case 24: /* RGB 888 */
189 case 32: /* RGBA 8888 */
190 var->red.offset = 16;
191 var->red.length = 8;
192 var->green.offset = 8;
193 var->green.length = 8;
194 var->blue.offset = 0;
195 var->blue.length = 8;
196 var->transp.length = var->bits_per_pixel - 24;
197 var->transp.offset = (var->transp.length) ? 24 : 0;
198 break;
199 }
200 var->red.msb_right = 0;
201 var->green.msb_right = 0;
202 var->blue.msb_right = 0;
203 var->transp.msb_right = 0;
204
205 return 0;
206}
207
208static int mbxfb_set_par(struct fb_info *info)
209{
210 struct fb_var_screeninfo *var = &info->var;
211 struct pixclock_div div;
212 ushort hbps, ht, hfps, has;
213 ushort vbps, vt, vfps, vas;
214 u32 gsctrl = readl(GSCTRL);
215 u32 gsadr = readl(GSADR);
216
217 info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;
218
219 /* setup color mode */
220 gsctrl &= ~(FMsk(GSCTRL_GPIXFMT));
221 /* FIXME: add *WORKING* support for 8-bits per color */
222 if (info->var.bits_per_pixel == 8) {
223 return -EINVAL;
224 } else {
225 fb_dealloc_cmap(&info->cmap);
226 gsctrl &= ~GSCTRL_LUT_EN;
227
228 info->fix.visual = FB_VISUAL_TRUECOLOR;
229 switch (info->var.bits_per_pixel) {
230 case 16:
231 if (info->var.green.length == 5)
232 gsctrl |= GSCTRL_GPIXFMT_ARGB1555;
233 else
234 gsctrl |= GSCTRL_GPIXFMT_RGB565;
235 break;
236 case 24:
237 gsctrl |= GSCTRL_GPIXFMT_RGB888;
238 break;
239 case 32:
240 gsctrl |= GSCTRL_GPIXFMT_ARGB8888;
241 break;
242 }
243 }
244
245 /* setup resolution */
246 gsctrl &= ~(FMsk(GSCTRL_GSWIDTH) | FMsk(GSCTRL_GSHEIGHT));
247 gsctrl |= Gsctrl_Width(info->var.xres - 1) |
248 Gsctrl_Height(info->var.yres - 1);
249 writel(gsctrl, GSCTRL);
250 udelay(1000);
251
252 gsadr &= ~(FMsk(GSADR_SRCSTRIDE));
253 gsadr |= Gsadr_Srcstride(info->var.xres * info->var.bits_per_pixel /
254 (8 * 16) - 1);
255 writel(gsadr, GSADR);
256 udelay(1000);
257
258 /* setup timings */
259 var->pixclock = mbxfb_get_pixclock(info->var.pixclock, &div);
260
261 writel((Disp_Pll_M(div.m) | Disp_Pll_N(div.n) |
262 Disp_Pll_P(div.p) | DISP_PLL_EN), DISPPLL);
263
264 hbps = var->hsync_len;
265 has = hbps + var->left_margin;
266 hfps = has + var->xres;
267 ht = hfps + var->right_margin;
268
269 vbps = var->vsync_len;
270 vas = vbps + var->upper_margin;
271 vfps = vas + var->yres;
272 vt = vfps + var->lower_margin;
273
274 writel((Dht01_Hbps(hbps) | Dht01_Ht(ht)), DHT01);
275 writel((Dht02_Hlbs(has) | Dht02_Has(has)), DHT02);
276 writel((Dht03_Hfps(hfps) | Dht03_Hrbs(hfps)), DHT03);
277 writel((Dhdet_Hdes(has) | Dhdet_Hdef(hfps)), DHDET);
278
279 writel((Dvt01_Vbps(vbps) | Dvt01_Vt(vt)), DVT01);
280 writel((Dvt02_Vtbs(vas) | Dvt02_Vas(vas)), DVT02);
281 writel((Dvt03_Vfps(vfps) | Dvt03_Vbbs(vfps)), DVT03);
282 writel((Dvdet_Vdes(vas) | Dvdet_Vdef(vfps)), DVDET);
283 writel((Dvectrl_Vevent(vfps) | Dvectrl_Vfetch(vbps)), DVECTRL);
284
285 writel((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
286
287 return 0;
288}
289
290static int mbxfb_blank(int blank, struct fb_info *info)
291{
292 switch (blank) {
293 case FB_BLANK_POWERDOWN:
294 case FB_BLANK_VSYNC_SUSPEND:
295 case FB_BLANK_HSYNC_SUSPEND:
296 case FB_BLANK_NORMAL:
297 writel((readl(DSCTRL) & ~DSCTRL_SYNCGEN_EN), DSCTRL);
298 udelay(1000);
299 writel((readl(PIXCLK) & ~PIXCLK_EN), PIXCLK);
300 udelay(1000);
301 writel((readl(VOVRCLK) & ~VOVRCLK_EN), VOVRCLK);
302 udelay(1000);
303 break;
304 case FB_BLANK_UNBLANK:
305 writel((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
306 udelay(1000);
307 writel((readl(PIXCLK) | PIXCLK_EN), PIXCLK);
308 udelay(1000);
309 break;
310 }
311 return 0;
312}
313
314static struct fb_ops mbxfb_ops = {
315 .owner = THIS_MODULE,
316 .fb_check_var = mbxfb_check_var,
317 .fb_set_par = mbxfb_set_par,
318 .fb_setcolreg = mbxfb_setcolreg,
319 .fb_fillrect = cfb_fillrect,
320 .fb_copyarea = cfb_copyarea,
321 .fb_imageblit = cfb_imageblit,
322 .fb_blank = mbxfb_blank,
323};
324
325/*
326 Enable external SDRAM controller. Assume that all clocks are active
327 by now.
328*/
329static void __devinit setup_memc(struct fb_info *fbi)
330{
331 struct mbxfb_info *mfbi = fbi->par;
332 unsigned long tmp;
333 int i;
334
335 /* FIXME: use platfrom specific parameters */
336 /* setup SDRAM controller */
337 writel((LMCFG_LMC_DS | LMCFG_LMC_TS | LMCFG_LMD_TS |
338 LMCFG_LMA_TS),
339 LMCFG);
340 udelay(1000);
341
342 writel(LMPWR_MC_PWR_ACT, LMPWR);
343 udelay(1000);
344
345 /* setup SDRAM timings */
346 writel((Lmtim_Tras(7) | Lmtim_Trp(3) | Lmtim_Trcd(3) |
347 Lmtim_Trc(9) | Lmtim_Tdpl(2)),
348 LMTIM);
349 udelay(1000);
350 /* setup SDRAM refresh rate */
351 writel(0xc2b, LMREFRESH);
352 udelay(1000);
353 /* setup SDRAM type parameters */
354 writel((LMTYPE_CASLAT_3 | LMTYPE_BKSZ_2 | LMTYPE_ROWSZ_11 |
355 LMTYPE_COLSZ_8),
356 LMTYPE);
357 udelay(1000);
358 /* enable memory controller */
359 writel(LMPWR_MC_PWR_ACT, LMPWR);
360 udelay(1000);
361
362 /* perform dummy reads */
363 for ( i = 0; i < 16; i++ ) {
364 tmp = readl(fbi->screen_base);
365 }
366}
367
368static void enable_clocks(struct fb_info *fbi)
369{
370 /* enable clocks */
371 writel(SYSCLKSRC_PLL_2, SYSCLKSRC);
372 udelay(1000);
373 writel(PIXCLKSRC_PLL_1, PIXCLKSRC);
374 udelay(1000);
375 writel(0x00000000, CLKSLEEP);
376 udelay(1000);
377 writel((Core_Pll_M(0x17) | Core_Pll_N(0x3) | Core_Pll_P(0x0) |
378 CORE_PLL_EN),
379 COREPLL);
380 udelay(1000);
381 writel((Disp_Pll_M(0x1b) | Disp_Pll_N(0x7) | Disp_Pll_P(0x1) |
382 DISP_PLL_EN),
383 DISPPLL);
384
385 writel(0x00000000, VOVRCLK);
386 udelay(1000);
387 writel(PIXCLK_EN, PIXCLK);
388 udelay(1000);
389 writel(MEMCLK_EN, MEMCLK);
390 udelay(1000);
391 writel(0x00000006, M24CLK);
392 udelay(1000);
393 writel(0x00000006, MBXCLK);
394 udelay(1000);
395 writel(SDCLK_EN, SDCLK);
396 udelay(1000);
397 writel(0x00000001, PIXCLKDIV);
398 udelay(1000);
399}
400
401static void __devinit setup_graphics(struct fb_info *fbi)
402{
403 unsigned long gsctrl;
404
405 gsctrl = GSCTRL_GAMMA_EN | Gsctrl_Width(fbi->var.xres - 1) |
406 Gsctrl_Height(fbi->var.yres - 1);
407 switch (fbi->var.bits_per_pixel) {
408 case 16:
409 if (fbi->var.green.length == 5)
410 gsctrl |= GSCTRL_GPIXFMT_ARGB1555;
411 else
412 gsctrl |= GSCTRL_GPIXFMT_RGB565;
413 break;
414 case 24:
415 gsctrl |= GSCTRL_GPIXFMT_RGB888;
416 break;
417 case 32:
418 gsctrl |= GSCTRL_GPIXFMT_ARGB8888;
419 break;
420 }
421
422 writel(gsctrl, GSCTRL);
423 udelay(1000);
424 writel(0x00000000, GBBASE);
425 udelay(1000);
426 writel(0x00ffffff, GDRCTRL);
427 udelay(1000);
428 writel((GSCADR_STR_EN | Gscadr_Gbase_Adr(0x6000)), GSCADR);
429 udelay(1000);
430 writel(0x00000000, GPLUT);
431 udelay(1000);
432}
433
434static void __devinit setup_display(struct fb_info *fbi)
435{
436 unsigned long dsctrl = 0;
437
438 dsctrl = DSCTRL_BLNK_POL;
439 if (fbi->var.sync & FB_SYNC_HOR_HIGH_ACT)
440 dsctrl |= DSCTRL_HS_POL;
441 if (fbi->var.sync & FB_SYNC_VERT_HIGH_ACT)
442 dsctrl |= DSCTRL_VS_POL;
443 writel(dsctrl, DSCTRL);
444 udelay(1000);
445 writel(0xd0303010, DMCTRL);
446 udelay(1000);
447 writel((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
448}
449
450static void __devinit enable_controller(struct fb_info *fbi)
451{
452 writel(SYSRST_RST, SYSRST);
453 udelay(1000);
454
455
456 enable_clocks(fbi);
457 setup_memc(fbi);
458 setup_graphics(fbi);
459 setup_display(fbi);
460}
461
462#ifdef CONFIG_PM
463/*
464 * Power management hooks. Note that we won't be called from IRQ context,
465 * unlike the blank functions above, so we may sleep.
466 */
467static int mbxfb_suspend(struct platform_device *dev, pm_message_t state)
468{
469 /* make frame buffer memory enter self-refresh mode */
470 writel(LMPWR_MC_PWR_SRM, LMPWR);
471 while (LMPWRSTAT != LMPWRSTAT_MC_PWR_SRM)
472 ; /* empty statement */
473
474 /* reset the device, since it's initial state is 'mostly sleeping' */
475 writel(SYSRST_RST, SYSRST);
476 return 0;
477}
478
479static int mbxfb_resume(struct platform_device *dev)
480{
481 struct fb_info *fbi = platform_get_drvdata(dev);
482
483 enable_clocks(fbi);
484/* setup_graphics(fbi); */
485/* setup_display(fbi); */
486
487 writel((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
488 return 0;
489}
490#else
491#define mbxfb_suspend NULL
492#define mbxfb_resume NULL
493#endif
494
495/* debugfs entries */
496#ifndef CONFIG_FB_MBX_DEBUG
497#define mbxfb_debugfs_init(x) do {} while(0)
498#define mbxfb_debugfs_remove(x) do {} while(0)
499#endif
500
501#define res_size(_r) (((_r)->end - (_r)->start) + 1)
502
503static int __devinit mbxfb_probe(struct platform_device *dev)
504{
505 int ret;
506 struct fb_info *fbi;
507 struct mbxfb_info *mfbi;
508 struct mbxfb_platform_data *pdata;
509
510 dev_dbg(dev, "mbxfb_probe\n");
511
512 fbi = framebuffer_alloc(sizeof(struct mbxfb_info), &dev->dev);
513 if (fbi == NULL) {
514 dev_err(&dev->dev, "framebuffer_alloc failed\n");
515 return -ENOMEM;
516 }
517
518 mfbi = fbi->par;
519 fbi->pseudo_palette = mfbi->pseudo_palette;
520 pdata = dev->dev.platform_data;
521 if (pdata->probe)
522 mfbi->platform_probe = pdata->probe;
523 if (pdata->remove)
524 mfbi->platform_remove = pdata->remove;
525
526 mfbi->fb_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
527 mfbi->reg_res = platform_get_resource(dev, IORESOURCE_MEM, 1);
528
529 if (!mfbi->fb_res || !mfbi->reg_res) {
530 dev_err(&dev->dev, "no resources found\n");
531 ret = -ENODEV;
532 goto err1;
533 }
534
535 mfbi->fb_req = request_mem_region(mfbi->fb_res->start,
536 res_size(mfbi->fb_res), dev->name);
537 if (mfbi->fb_req == NULL) {
538 dev_err(&dev->dev, "failed to claim framebuffer memory\n");
539 ret = -EINVAL;
540 goto err1;
541 }
542 mfbi->fb_phys_addr = mfbi->fb_res->start;
543
544 mfbi->reg_req = request_mem_region(mfbi->reg_res->start,
545 res_size(mfbi->reg_res), dev->name);
546 if (mfbi->reg_req == NULL) {
547 dev_err(&dev->dev, "failed to claim Marathon registers\n");
548 ret = -EINVAL;
549 goto err2;
550 }
551 mfbi->reg_phys_addr = mfbi->reg_res->start;
552
553 mfbi->reg_virt_addr = ioremap_nocache(mfbi->reg_phys_addr,
554 res_size(mfbi->reg_req));
555 if (!mfbi->reg_virt_addr) {
556 dev_err(&dev->dev, "failed to ioremap Marathon registers\n");
557 ret = -EINVAL;
558 goto err3;
559 }
560 virt_base_2700 = (unsigned long)mfbi->reg_virt_addr;
561
562 mfbi->fb_virt_addr = ioremap_nocache(mfbi->fb_phys_addr,
563 res_size(mfbi->fb_req));
564 if (!mfbi->reg_virt_addr) {
565 dev_err(&dev->dev, "failed to ioremap frame buffer\n");
566 ret = -EINVAL;
567 goto err4;
568 }
569
570 /* FIXME: get from platform */
571 fbi->screen_base = (char __iomem *)(mfbi->fb_virt_addr + 0x60000);
572 fbi->screen_size = 8 * 1024 * 1024; /* 8 Megs */
573 fbi->fbops = &mbxfb_ops;
574
575 fbi->var = mbxfb_default;
576 fbi->fix = mbxfb_fix;
577 fbi->fix.smem_start = mfbi->fb_phys_addr + 0x60000;
578 fbi->fix.smem_len = 8 * 1024 * 1024;
579 fbi->fix.line_length = 640 * 2;
580
581 ret = fb_alloc_cmap(&fbi->cmap, 256, 0);
582 if (ret < 0) {
583 dev_err(&dev->dev, "fb_alloc_cmap failed\n");
584 ret = -EINVAL;
585 goto err5;
586 }
587
588 platform_set_drvdata(dev, fbi);
589
590 printk(KERN_INFO "fb%d: mbx frame buffer device\n", fbi->node);
591
592 if (mfbi->platform_probe)
593 mfbi->platform_probe(fbi);
594
595 enable_controller(fbi);
596
597 mbxfb_debugfs_init(fbi);
598
599 ret = register_framebuffer(fbi);
600 if (ret < 0) {
601 dev_err(&dev->dev, "register_framebuffer failed\n");
602 ret = -EINVAL;
603 goto err6;
604 }
605
606 return 0;
607
608err6:
609 fb_dealloc_cmap(&fbi->cmap);
610err5:
611 iounmap(mfbi->fb_virt_addr);
612err4:
613 iounmap(mfbi->reg_virt_addr);
614err3:
615 release_mem_region(mfbi->reg_res->start, res_size(mfbi->reg_res));
616err2:
617 release_mem_region(mfbi->fb_res->start, res_size(mfbi->fb_res));
618err1:
619 framebuffer_release(fbi);
620
621 return ret;
622}
623
624static int __devexit mbxfb_remove(struct platform_device *dev)
625{
626 struct fb_info *fbi = platform_get_drvdata(dev);
627
628 writel(SYSRST_RST, SYSRST);
629 udelay(1000);
630
631 mbxfb_debugfs_remove(fbi);
632
633 if (fbi) {
634 struct mbxfb_info *mfbi = fbi->par;
635
636 unregister_framebuffer(fbi);
637 if (mfbi) {
638 if (mfbi->platform_remove)
639 mfbi->platform_remove(fbi);
640
641 if (mfbi->fb_virt_addr)
642 iounmap(mfbi->fb_virt_addr);
643 if (mfbi->reg_virt_addr)
644 iounmap(mfbi->reg_virt_addr);
645 if (mfbi->reg_req)
646 release_mem_region(mfbi->reg_req->start,
647 res_size(mfbi->reg_req));
648 if (mfbi->fb_req)
649 release_mem_region(mfbi->fb_req->start,
650 res_size(mfbi->fb_req));
651 }
652 framebuffer_release(fbi);
653 }
654
655 return 0;
656}
657
658static struct platform_driver mbxfb_driver = {
659 .probe = mbxfb_probe,
660 .remove = mbxfb_remove,
661 .suspend = mbxfb_suspend,
662 .resume = mbxfb_resume,
663 .driver = {
664 .name = "mbx-fb",
665 },
666};
667
668int __devinit mbxfb_init(void)
669{
670 return platform_driver_register(&mbxfb_driver);
671}
672
673static void __devexit mbxfb_exit(void)
674{
675 platform_driver_unregister(&mbxfb_driver);
676}
677
678module_init(mbxfb_init);
679module_exit(mbxfb_exit);
680
681MODULE_DESCRIPTION("loadable framebuffer driver for Marathon device");
682MODULE_AUTHOR("Mike Rapoport, Compulab");
683MODULE_LICENSE("GPL");
diff --git a/drivers/video/mbx/reg_bits.h b/drivers/video/mbx/reg_bits.h
new file mode 100644
index 000000000000..c226a8e45312
--- /dev/null
+++ b/drivers/video/mbx/reg_bits.h
@@ -0,0 +1,418 @@
1#ifndef __REG_BITS_2700G_
2#define __REG_BITS_2700G_
3
4/* use defines from asm-arm/arch-pxa/bitfields.h for bit fields access */
5#define UData(Data) ((unsigned long) (Data))
6#define Fld(Size, Shft) (((Size) << 16) + (Shft))
7#define FSize(Field) ((Field) >> 16)
8#define FShft(Field) ((Field) & 0x0000FFFF)
9#define FMsk(Field) (((UData (1) << FSize (Field)) - 1) << FShft (Field))
10#define FAlnMsk(Field) ((UData (1) << FSize (Field)) - 1)
11#define F1stBit(Field) (UData (1) << FShft (Field))
12
13#define SYSRST_RST (1 << 0)
14
15/* SYSCLKSRC - SYSCLK Source Control Register */
16#define SYSCLKSRC_SEL Fld(2,0)
17#define SYSCLKSRC_REF ((0x0) << FShft(SYSCLKSRC_SEL))
18#define SYSCLKSRC_PLL_1 ((0x1) << FShft(SYSCLKSRC_SEL))
19#define SYSCLKSRC_PLL_2 ((0x2) << FShft(SYSCLKSRC_SEL))
20
21/* PIXCLKSRC - PIXCLK Source Control Register */
22#define PIXCLKSRC_SEL Fld(2,0)
23#define PIXCLKSRC_REF ((0x0) << FShft(PIXCLKSRC_SEL))
24#define PIXCLKSRC_PLL_1 ((0x1) << FShft(PIXCLKSRC_SEL))
25#define PIXCLKSRC_PLL_2 ((0x2) << FShft(PIXCLKSRC_SEL))
26
27/* Clock Disable Register */
28#define CLKSLEEP_SLP (1 << 0)
29
30/* Core PLL Control Register */
31#define CORE_PLL_M Fld(6,7)
32#define Core_Pll_M(x) ((x) << FShft(CORE_PLL_M))
33#define CORE_PLL_N Fld(3,4)
34#define Core_Pll_N(x) ((x) << FShft(CORE_PLL_N))
35#define CORE_PLL_P Fld(3,1)
36#define Core_Pll_P(x) ((x) << FShft(CORE_PLL_P))
37#define CORE_PLL_EN (1 << 0)
38
39/* Display PLL Control Register */
40#define DISP_PLL_M Fld(6,7)
41#define Disp_Pll_M(x) ((x) << FShft(DISP_PLL_M))
42#define DISP_PLL_N Fld(3,4)
43#define Disp_Pll_N(x) ((x) << FShft(DISP_PLL_N))
44#define DISP_PLL_P Fld(3,1)
45#define Disp_Pll_P(x) ((x) << FShft(DISP_PLL_P))
46#define DISP_PLL_EN (1 << 0)
47
48/* PLL status register */
49#define PLLSTAT_CORE_PLL_LOST_L (1 << 3)
50#define PLLSTAT_CORE_PLL_LSTS (1 << 2)
51#define PLLSTAT_DISP_PLL_LOST_L (1 << 1)
52#define PLLSTAT_DISP_PLL_LSTS (1 << 0)
53
54/* Video and scale clock control register */
55#define VOVRCLK_EN (1 << 0)
56
57/* Pixel clock control register */
58#define PIXCLK_EN (1 << 0)
59
60/* Memory clock control register */
61#define MEMCLK_EN (1 << 0)
62
63/* MBX clock control register */
64#define MBXCLK_DIV Fld(2,2)
65#define MBXCLK_DIV_1 ((0x0) << FShft(MBXCLK_DIV))
66#define MBXCLK_DIV_2 ((0x1) << FShft(MBXCLK_DIV))
67#define MBXCLK_DIV_3 ((0x2) << FShft(MBXCLK_DIV))
68#define MBXCLK_DIV_4 ((0x3) << FShft(MBXCLK_DIV))
69#define MBXCLK_EN Fld(2,0)
70#define MBXCLK_EN_NONE ((0x0) << FShft(MBXCLK_EN))
71#define MBXCLK_EN_2D ((0x1) << FShft(MBXCLK_EN))
72#define MBXCLK_EN_BOTH ((0x2) << FShft(MBXCLK_EN))
73
74/* M24 clock control register */
75#define M24CLK_DIV Fld(2,1)
76#define M24CLK_DIV_1 ((0x0) << FShft(M24CLK_DIV))
77#define M24CLK_DIV_2 ((0x1) << FShft(M24CLK_DIV))
78#define M24CLK_DIV_3 ((0x2) << FShft(M24CLK_DIV))
79#define M24CLK_DIV_4 ((0x3) << FShft(M24CLK_DIV))
80#define M24CLK_EN (1 << 0)
81
82/* SDRAM clock control register */
83#define SDCLK_EN (1 << 0)
84
85/* PixClk Divisor Register */
86#define PIXCLKDIV_PD Fld(9,0)
87#define Pixclkdiv_Pd(x) ((x) << FShft(PIXCLKDIV_PD))
88
89/* LCD Config control register */
90#define LCDCFG_IN_FMT Fld(3,28)
91#define Lcdcfg_In_Fmt(x) ((x) << FShft(LCDCFG_IN_FMT))
92#define LCDCFG_LCD1DEN_POL (1 << 27)
93#define LCDCFG_LCD1FCLK_POL (1 << 26)
94#define LCDCFG_LCD1LCLK_POL (1 << 25)
95#define LCDCFG_LCD1D_POL (1 << 24)
96#define LCDCFG_LCD2DEN_POL (1 << 23)
97#define LCDCFG_LCD2FCLK_POL (1 << 22)
98#define LCDCFG_LCD2LCLK_POL (1 << 21)
99#define LCDCFG_LCD2D_POL (1 << 20)
100#define LCDCFG_LCD1_TS (1 << 19)
101#define LCDCFG_LCD1D_DS (1 << 18)
102#define LCDCFG_LCD1C_DS (1 << 17)
103#define LCDCFG_LCD1_IS_IN (1 << 16)
104#define LCDCFG_LCD2_TS (1 << 3)
105#define LCDCFG_LCD2D_DS (1 << 2)
106#define LCDCFG_LCD2C_DS (1 << 1)
107#define LCDCFG_LCD2_IS_IN (1 << 0)
108
109/* On-Die Frame Buffer Power Control Register */
110#define ODFBPWR_SLOW (1 << 2)
111#define ODFBPWR_MODE Fld(2,0)
112#define ODFBPWR_MODE_ACT ((0x0) << FShft(ODFBPWR_MODE))
113#define ODFBPWR_MODE_ACT_LP ((0x1) << FShft(ODFBPWR_MODE))
114#define ODFBPWR_MODE_SLEEP ((0x2) << FShft(ODFBPWR_MODE))
115#define ODFBPWR_MODE_SHUTD ((0x3) << FShft(ODFBPWR_MODE))
116
117/* On-Die Frame Buffer Power State Status Register */
118#define ODFBSTAT_ACT (1 << 2)
119#define ODFBSTAT_SLP (1 << 1)
120#define ODFBSTAT_SDN (1 << 0)
121
122/* LMRST - Local Memory (SDRAM) Reset */
123#define LMRST_MC_RST (1 << 0)
124
125/* LMCFG - Local Memory (SDRAM) Configuration Register */
126#define LMCFG_LMC_DS (1 << 5)
127#define LMCFG_LMD_DS (1 << 4)
128#define LMCFG_LMA_DS (1 << 3)
129#define LMCFG_LMC_TS (1 << 2)
130#define LMCFG_LMD_TS (1 << 1)
131#define LMCFG_LMA_TS (1 << 0)
132
133/* LMPWR - Local Memory (SDRAM) Power Control Register */
134#define LMPWR_MC_PWR_CNT Fld(2,0)
135#define LMPWR_MC_PWR_ACT ((0x0) << FShft(LMPWR_MC_PWR_CNT)) /* Active */
136#define LMPWR_MC_PWR_SRM ((0x1) << FShft(LMPWR_MC_PWR_CNT)) /* Self-refresh */
137#define LMPWR_MC_PWR_DPD ((0x3) << FShft(LMPWR_MC_PWR_CNT)) /* deep power down */
138
139/* LMPWRSTAT - Local Memory (SDRAM) Power Status Register */
140#define LMPWRSTAT_MC_PWR_CNT Fld(2,0)
141#define LMPWRSTAT_MC_PWR_ACT ((0x0) << FShft(LMPWRSTAT_MC_PWR_CNT)) /* Active */
142#define LMPWRSTAT_MC_PWR_SRM ((0x1) << FShft(LMPWRSTAT_MC_PWR_CNT)) /* Self-refresh */
143#define LMPWRSTAT_MC_PWR_DPD ((0x3) << FShft(LMPWRSTAT_MC_PWR_CNT)) /* deep power down */
144
145/* LMTYPE - Local Memory (SDRAM) Type Register */
146#define LMTYPE_CASLAT Fld(3,10)
147#define LMTYPE_CASLAT_1 ((0x1) << FShft(LMTYPE_CASLAT))
148#define LMTYPE_CASLAT_2 ((0x2) << FShft(LMTYPE_CASLAT))
149#define LMTYPE_CASLAT_3 ((0x3) << FShft(LMTYPE_CASLAT))
150#define LMTYPE_BKSZ Fld(2,8)
151#define LMTYPE_BKSZ_1 ((0x1) << FShft(LMTYPE_BKSZ))
152#define LMTYPE_BKSZ_2 ((0x2) << FShft(LMTYPE_BKSZ))
153#define LMTYPE_ROWSZ Fld(4,4)
154#define LMTYPE_ROWSZ_11 ((0xb) << FShft(LMTYPE_ROWSZ))
155#define LMTYPE_ROWSZ_12 ((0xc) << FShft(LMTYPE_ROWSZ))
156#define LMTYPE_ROWSZ_13 ((0xd) << FShft(LMTYPE_ROWSZ))
157#define LMTYPE_COLSZ Fld(4,0)
158#define LMTYPE_COLSZ_7 ((0x7) << FShft(LMTYPE_COLSZ))
159#define LMTYPE_COLSZ_8 ((0x8) << FShft(LMTYPE_COLSZ))
160#define LMTYPE_COLSZ_9 ((0x9) << FShft(LMTYPE_COLSZ))
161#define LMTYPE_COLSZ_10 ((0xa) << FShft(LMTYPE_COLSZ))
162#define LMTYPE_COLSZ_11 ((0xb) << FShft(LMTYPE_COLSZ))
163#define LMTYPE_COLSZ_12 ((0xc) << FShft(LMTYPE_COLSZ))
164
165/* LMTIM - Local Memory (SDRAM) Timing Register */
166#define LMTIM_TRAS Fld(4,16)
167#define Lmtim_Tras(x) ((x) << FShft(LMTIM_TRAS))
168#define LMTIM_TRP Fld(4,12)
169#define Lmtim_Trp(x) ((x) << FShft(LMTIM_TRP))
170#define LMTIM_TRCD Fld(4,8)
171#define Lmtim_Trcd(x) ((x) << FShft(LMTIM_TRCD))
172#define LMTIM_TRC Fld(4,4)
173#define Lmtim_Trc(x) ((x) << FShft(LMTIM_TRC))
174#define LMTIM_TDPL Fld(4,0)
175#define Lmtim_Tdpl(x) ((x) << FShft(LMTIM_TDPL))
176
177/* LMREFRESH - Local Memory (SDRAM) tREF Control Register */
178#define LMREFRESH_TREF Fld(2,0)
179#define Lmrefresh_Tref(x) ((x) << FShft(LMREFRESH_TREF))
180
181/* GSCTRL - Graphics surface control register */
182#define GSCTRL_LUT_EN (1 << 31)
183#define GSCTRL_GPIXFMT Fld(4,27)
184#define GSCTRL_GPIXFMT_INDEXED ((0x0) << FShft(GSCTRL_GPIXFMT))
185#define GSCTRL_GPIXFMT_ARGB4444 ((0x4) << FShft(GSCTRL_GPIXFMT))
186#define GSCTRL_GPIXFMT_ARGB1555 ((0x5) << FShft(GSCTRL_GPIXFMT))
187#define GSCTRL_GPIXFMT_RGB888 ((0x6) << FShft(GSCTRL_GPIXFMT))
188#define GSCTRL_GPIXFMT_RGB565 ((0x7) << FShft(GSCTRL_GPIXFMT))
189#define GSCTRL_GPIXFMT_ARGB8888 ((0x8) << FShft(GSCTRL_GPIXFMT))
190#define GSCTRL_GAMMA_EN (1 << 26)
191
192#define GSCTRL_GSWIDTH Fld(11,11)
193#define Gsctrl_Width(Pixel) /* Display Width [1..2048 pix.] */ \
194 (((Pixel) - 1) << FShft(GSCTRL_GSWIDTH))
195
196#define GSCTRL_GSHEIGHT Fld(11,0)
197#define Gsctrl_Height(Pixel) /* Display Height [1..2048 pix.] */ \
198 (((Pixel) - 1) << FShft(GSCTRL_GSHEIGHT))
199
200/* GBBASE fileds */
201#define GBBASE_GLALPHA Fld(8,24)
202#define Gbbase_Glalpha(x) ((x) << FShft(GBBASE_GLALPHA))
203
204#define GBBASE_COLKEY Fld(24,0)
205#define Gbbase_Colkey(x) ((x) << FShft(GBBASE_COLKEY))
206
207/* GDRCTRL fields */
208#define GDRCTRL_PIXDBL (1 << 31)
209#define GDRCTRL_PIXHLV (1 << 30)
210#define GDRCTRL_LNDBL (1 << 29)
211#define GDRCTRL_LNHLV (1 << 28)
212#define GDRCTRL_COLKEYM Fld(24,0)
213#define Gdrctrl_Colkeym(x) ((x) << FShft(GDRCTRL_COLKEYM))
214
215/* GSCADR graphics stream control address register fields */
216#define GSCADR_STR_EN (1 << 31)
217#define GSCADR_COLKEY_EN (1 << 30)
218#define GSCADR_COLKEYSCR (1 << 29)
219#define GSCADR_BLEND_M Fld(2,27)
220#define GSCADR_BLEND_NONE ((0x0) << FShft(GSCADR_BLEND_M))
221#define GSCADR_BLEND_INV ((0x1) << FShft(GSCADR_BLEND_M))
222#define GSCADR_BLEND_GLOB ((0x2) << FShft(GSCADR_BLEND_M))
223#define GSCADR_BLEND_PIX ((0x3) << FShft(GSCADR_BLEND_M))
224#define GSCADR_BLEND_POS Fld(2,24)
225#define GSCADR_BLEND_GFX ((0x0) << FShft(GSCADR_BLEND_POS))
226#define GSCADR_BLEND_VID ((0x1) << FShft(GSCADR_BLEND_POS))
227#define GSCADR_BLEND_CUR ((0x2) << FShft(GSCADR_BLEND_POS))
228#define GSCADR_GBASE_ADR Fld(23,0)
229#define Gscadr_Gbase_Adr(x) ((x) << FShft(GSCADR_GBASE_ADR))
230
231/* GSADR graphics stride address register fields */
232#define GSADR_SRCSTRIDE Fld(10,22)
233#define Gsadr_Srcstride(x) ((x) << FShft(GSADR_SRCSTRIDE))
234#define GSADR_XSTART Fld(11,11)
235#define Gsadr_Xstart(x) ((x) << FShft(GSADR_XSTART))
236#define GSADR_YSTART Fld(11,0)
237#define Gsadr_Ystart(y) ((y) << FShft(GSADR_YSTART))
238
239/* GPLUT graphics palette register fields */
240#define GPLUT_LUTADR Fld(8,24)
241#define Gplut_Lutadr(x) ((x) << FShft(GPLUT_LUTADR))
242#define GPLUT_LUTDATA Fld(24,0)
243#define Gplut_Lutdata(x) ((x) << FShft(GPLUT_LUTDATA))
244
245/* HCCTRL - Hardware Cursor Register fields */
246#define HCCTRL_CUR_EN (1 << 31)
247#define HCCTRL_COLKEY_EN (1 << 29)
248#define HCCTRL_COLKEYSRC (1 << 28)
249#define HCCTRL_BLEND_M Fld(2,26)
250#define HCCTRL_BLEND_NONE ((0x0) << FShft(HCCTRL_BLEND_M))
251#define HCCTRL_BLEND_INV ((0x1) << FShft(HCCTRL_BLEND_M))
252#define HCCTRL_BLEND_GLOB ((0x2) << FShft(HCCTRL_BLEND_M))
253#define HCCTRL_BLEND_PIX ((0x3) << FShft(HCCTRL_BLEND_M))
254#define HCCTRL_CPIXFMT Fld(3,23)
255#define HCCTRL_CPIXFMT_RGB332 ((0x3) << FShft(HCCTRL_CPIXFMT))
256#define HCCTRL_CPIXFMT_ARGB4444 ((0x4) << FShft(HCCTRL_CPIXFMT))
257#define HCCTRL_CPIXFMT_ARGB1555 ((0x5) << FShft(HCCTRL_CPIXFMT))
258#define HCCTRL_CBASE_ADR Fld(23,0)
259#define Hcctrl_Cbase_Adr(x) ((x) << FShft(HCCTRL_CBASE_ADR))
260
261/* HCSIZE Hardware Cursor Size Register fields */
262#define HCSIZE_BLEND_POS Fld(2,29)
263#define HCSIZE_BLEND_GFX ((0x0) << FShft(HCSIZE_BLEND_POS))
264#define HCSIZE_BLEND_VID ((0x1) << FShft(HCSIZE_BLEND_POS))
265#define HCSIZE_BLEND_CUR ((0x2) << FShft(HCSIZE_BLEND_POS))
266#define HCSIZE_CWIDTH Fld(3,16)
267#define Hcsize_Cwidth(x) ((x) << FShft(HCSIZE_CWIDTH))
268#define HCSIZE_CHEIGHT Fld(3,0)
269#define Hcsize_Cheight(x) ((x) << FShft(HCSIZE_CHEIGHT))
270
271/* HCPOS Hardware Cursor Position Register fields */
272#define HCPOS_SWITCHSRC (1 << 30)
273#define HCPOS_CURBLINK Fld(6,24)
274#define Hcpos_Curblink(x) ((x) << FShft(HCPOS_CURBLINK))
275#define HCPOS_XSTART Fld(12,12)
276#define Hcpos_Xstart(x) ((x) << FShft(HCPOS_XSTART))
277#define HCPOS_YSTART Fld(12,0)
278#define Hcpos_Ystart(y) ((y) << FShft(HCPOS_YSTART))
279
280/* HCBADR Hardware Cursor Blend Address Register */
281#define HCBADR_GLALPHA Fld(8,24)
282#define Hcbadr_Glalpha(x) ((x) << FShft(HCBADR_GLALPHA))
283#define HCBADR_COLKEY Fld(24,0)
284#define Hcbadr_Colkey(x) ((x) << FShft(HCBADR_COLKEY))
285
286/* HCCKMSK - Hardware Cursor Color Key Mask Register */
287#define HCCKMSK_COLKEY_M Fld(24,0)
288#define Hcckmsk_Colkey_M(x) ((x) << FShft(HCCKMSK_COLKEY_M))
289
290/* DSCTRL - Display sync control register */
291#define DSCTRL_SYNCGEN_EN (1 << 31)
292#define DSCTRL_DPL_RST (1 << 29)
293#define DSCTRL_PWRDN_M (1 << 28)
294#define DSCTRL_UPDSYNCCNT (1 << 26)
295#define DSCTRL_UPDINTCNT (1 << 25)
296#define DSCTRL_UPDCNT (1 << 24)
297#define DSCTRL_UPDWAIT Fld(4,16)
298#define Dsctrl_Updwait(x) ((x) << FShft(DSCTRL_UPDWAIT))
299#define DSCTRL_CLKPOL (1 << 11)
300#define DSCTRL_CSYNC_EN (1 << 10)
301#define DSCTRL_VS_SLAVE (1 << 7)
302#define DSCTRL_HS_SLAVE (1 << 6)
303#define DSCTRL_BLNK_POL (1 << 5)
304#define DSCTRL_BLNK_DIS (1 << 4)
305#define DSCTRL_VS_POL (1 << 3)
306#define DSCTRL_VS_DIS (1 << 2)
307#define DSCTRL_HS_POL (1 << 1)
308#define DSCTRL_HS_DIS (1 << 0)
309
310/* DHT01 - Display horizontal timing register 01 */
311#define DHT01_HBPS Fld(12,16)
312#define Dht01_Hbps(x) ((x) << FShft(DHT01_HBPS))
313#define DHT01_HT Fld(12,0)
314#define Dht01_Ht(x) ((x) << FShft(DHT01_HT))
315
316/* DHT02 - Display horizontal timing register 02 */
317#define DHT02_HAS Fld(12,16)
318#define Dht02_Has(x) ((x) << FShft(DHT02_HAS))
319#define DHT02_HLBS Fld(12,0)
320#define Dht02_Hlbs(x) ((x) << FShft(DHT02_HLBS))
321
322/* DHT03 - Display horizontal timing register 03 */
323#define DHT03_HFPS Fld(12,16)
324#define Dht03_Hfps(x) ((x) << FShft(DHT03_HFPS))
325#define DHT03_HRBS Fld(12,0)
326#define Dht03_Hrbs(x) ((x) << FShft(DHT03_HRBS))
327
328/* DVT01 - Display vertical timing register 01 */
329#define DVT01_VBPS Fld(12,16)
330#define Dvt01_Vbps(x) ((x) << FShft(DVT01_VBPS))
331#define DVT01_VT Fld(12,0)
332#define Dvt01_Vt(x) ((x) << FShft(DVT01_VT))
333
334/* DVT02 - Display vertical timing register 02 */
335#define DVT02_VAS Fld(12,16)
336#define Dvt02_Vas(x) ((x) << FShft(DVT02_VAS))
337#define DVT02_VTBS Fld(12,0)
338#define Dvt02_Vtbs(x) ((x) << FShft(DVT02_VTBS))
339
340/* DVT03 - Display vertical timing register 03 */
341#define DVT03_VFPS Fld(12,16)
342#define Dvt03_Vfps(x) ((x) << FShft(DVT03_VFPS))
343#define DVT03_VBBS Fld(12,0)
344#define Dvt03_Vbbs(x) ((x) << FShft(DVT03_VBBS))
345
346/* DVECTRL - display vertical event control register */
347#define DVECTRL_VEVENT Fld(12,16)
348#define Dvectrl_Vevent(x) ((x) << FShft(DVECTRL_VEVENT))
349#define DVECTRL_VFETCH Fld(12,0)
350#define Dvectrl_Vfetch(x) ((x) << FShft(DVECTRL_VFETCH))
351
352/* DHDET - display horizontal DE timing register */
353#define DHDET_HDES Fld(12,16)
354#define Dhdet_Hdes(x) ((x) << FShft(DHDET_HDES))
355#define DHDET_HDEF Fld(12,0)
356#define Dhdet_Hdef(x) ((x) << FShft(DHDET_HDEF))
357
358/* DVDET - display vertical DE timing register */
359#define DVDET_VDES Fld(12,16)
360#define Dvdet_Vdes(x) ((x) << FShft(DVDET_VDES))
361#define DVDET_VDEF Fld(12,0)
362#define Dvdet_Vdef(x) ((x) << FShft(DVDET_VDEF))
363
364/* DODMSK - display output data mask register */
365#define DODMSK_MASK_LVL (1 << 31)
366#define DODMSK_BLNK_LVL (1 << 30)
367#define DODMSK_MASK_B Fld(8,16)
368#define Dodmsk_Mask_B(x) ((x) << FShft(DODMSK_MASK_B))
369#define DODMSK_MASK_G Fld(8,8)
370#define Dodmsk_Mask_G(x) ((x) << FShft(DODMSK_MASK_G))
371#define DODMSK_MASK_R Fld(8,0)
372#define Dodmsk_Mask_R(x) ((x) << FShft(DODMSK_MASK_R))
373
374/* DBCOL - display border color control register */
375#define DBCOL_BORDCOL Fld(24,0)
376#define Dbcol_Bordcol(x) ((x) << FShft(DBCOL_BORDCOL))
377
378/* DVLNUM - display vertical line number register */
379#define DVLNUM_VLINE Fld(12,0)
380#define Dvlnum_Vline(x) ((x) << FShft(DVLNUM_VLINE))
381
382/* DMCTRL - Display Memory Control Register */
383#define DMCTRL_MEM_REF Fld(2,30)
384#define DMCTRL_MEM_REF_ACT ((0x0) << FShft(DMCTRL_MEM_REF))
385#define DMCTRL_MEM_REF_HB ((0x1) << FShft(DMCTRL_MEM_REF))
386#define DMCTRL_MEM_REF_VB ((0x2) << FShft(DMCTRL_MEM_REF))
387#define DMCTRL_MEM_REF_BOTH ((0x3) << FShft(DMCTRL_MEM_REF))
388#define DMCTRL_UV_THRHLD Fld(6,24)
389#define Dmctrl_Uv_Thrhld(x) ((x) << FShft(DMCTRL_UV_THRHLD))
390#define DMCTRL_V_THRHLD Fld(7,16)
391#define Dmctrl_V_Thrhld(x) ((x) << FShft(DMCTRL_V_THRHLD))
392#define DMCTRL_D_THRHLD Fld(7,8)
393#define Dmctrl_D_Thrhld(x) ((x) << FShft(DMCTRL_D_THRHLD))
394#define DMCTRL_BURSTLEN Fld(6,0)
395#define Dmctrl_Burstlen(x) ((x) << FShft(DMCTRL_BURSTLEN))
396
397
398/* DLSTS - display load status register */
399#define DLSTS_RLD_ADONE (1 << 23)
400/* #define DLSTS_RLD_ADOUT Fld(23,0) */
401
402/* DLLCTRL - display list load control register */
403#define DLLCTRL_RLD_ADRLN Fld(8,24)
404#define Dllctrl_Rld_Adrln(x) ((x) << FShft(DLLCTRL_RLD_ADRLN))
405
406/* SPOCTRL - Scale Pitch/Order Control Register */
407#define SPOCTRL_H_SC_BP (1 << 31)
408#define SPOCTRL_V_SC_BP (1 << 30)
409#define SPOCTRL_HV_SC_OR (1 << 29)
410#define SPOCTRL_VS_UR_C (1 << 27)
411#define SPOCTRL_VORDER Fld(2,16)
412#define SPOCTRL_VORDER_1TAP ((0x0) << FShft(SPOCTRL_VORDER))
413#define SPOCTRL_VORDER_2TAP ((0x1) << FShft(SPOCTRL_VORDER))
414#define SPOCTRL_VORDER_4TAP ((0x3) << FShft(SPOCTRL_VORDER))
415#define SPOCTRL_VPITCH Fld(16,0)
416#define Spoctrl_Vpitch(x) ((x) << FShft(SPOCTRL_VPITCH))
417
418#endif /* __REG_BITS_2700G_ */
diff --git a/drivers/video/mbx/regs.h b/drivers/video/mbx/regs.h
new file mode 100644
index 000000000000..ad20be07666b
--- /dev/null
+++ b/drivers/video/mbx/regs.h
@@ -0,0 +1,195 @@
1#ifndef __REGS_2700G_
2#define __REGS_2700G_
3
4/* extern unsigned long virt_base_2700; */
5/* #define __REG_2700G(x) (*(volatile unsigned long*)((x)+virt_base_2700)) */
6#define __REG_2700G(x) ((x)+virt_base_2700)
7
8/* System Configuration Registers (0x0000_0000 0x0000_0010) */
9#define SYSCFG __REG_2700G(0x00000000)
10#define PFBASE __REG_2700G(0x00000004)
11#define PFCEIL __REG_2700G(0x00000008)
12#define POLLFLAG __REG_2700G(0x0000000c)
13#define SYSRST __REG_2700G(0x00000010)
14
15/* Interrupt Control Registers (0x0000_0014 0x0000_002F) */
16#define NINTPW __REG_2700G(0x00000014)
17#define MINTENABLE __REG_2700G(0x00000018)
18#define MINTSTAT __REG_2700G(0x0000001c)
19#define SINTENABLE __REG_2700G(0x00000020)
20#define SINTSTAT __REG_2700G(0x00000024)
21#define SINTCLR __REG_2700G(0x00000028)
22
23/* Clock Control Registers (0x0000_002C 0x0000_005F) */
24#define SYSCLKSRC __REG_2700G(0x0000002c)
25#define PIXCLKSRC __REG_2700G(0x00000030)
26#define CLKSLEEP __REG_2700G(0x00000034)
27#define COREPLL __REG_2700G(0x00000038)
28#define DISPPLL __REG_2700G(0x0000003c)
29#define PLLSTAT __REG_2700G(0x00000040)
30#define VOVRCLK __REG_2700G(0x00000044)
31#define PIXCLK __REG_2700G(0x00000048)
32#define MEMCLK __REG_2700G(0x0000004c)
33#define M24CLK __REG_2700G(0x00000054)
34#define MBXCLK __REG_2700G(0x00000054)
35#define SDCLK __REG_2700G(0x00000058)
36#define PIXCLKDIV __REG_2700G(0x0000005c)
37
38/* LCD Port Control Register (0x0000_0060 0x0000_006F) */
39#define LCD_CONFIG __REG_2700G(0x00000060)
40
41/* On-Die Frame Buffer Registers (0x0000_0064 0x0000_006B) */
42#define ODFBPWR __REG_2700G(0x00000064)
43#define ODFBSTAT __REG_2700G(0x00000068)
44
45/* GPIO Registers (0x0000_006C 0x0000_007F) */
46#define GPIOCGF __REG_2700G(0x0000006c)
47#define GPIOHI __REG_2700G(0x00000070)
48#define GPIOLO __REG_2700G(0x00000074)
49#define GPIOSTAT __REG_2700G(0x00000078)
50
51/* Pulse Width Modulator (PWM) Registers (0x0000_0200 0x0000_02FF) */
52#define PWMRST __REG_2700G(0x00000200)
53#define PWMCFG __REG_2700G(0x00000204)
54#define PWM0DIV __REG_2700G(0x00000210)
55#define PWM0DUTY __REG_2700G(0x00000214)
56#define PWM0PER __REG_2700G(0x00000218)
57#define PWM1DIV __REG_2700G(0x00000220)
58#define PWM1DUTY __REG_2700G(0x00000224)
59#define PWM1PER __REG_2700G(0x00000228)
60
61/* Identification (ID) Registers (0x0000_0300 0x0000_0FFF) */
62#define ID __REG_2700G(0x00000FF0)
63
64/* Local Memory (SDRAM) Interface Registers (0x0000_1000 0x0000_1FFF) */
65#define LMRST __REG_2700G(0x00001000)
66#define LMCFG __REG_2700G(0x00001004)
67#define LMPWR __REG_2700G(0x00001008)
68#define LMPWRSTAT __REG_2700G(0x0000100c)
69#define LMCEMR __REG_2700G(0x00001010)
70#define LMTYPE __REG_2700G(0x00001014)
71#define LMTIM __REG_2700G(0x00001018)
72#define LMREFRESH __REG_2700G(0x0000101c)
73#define LMPROTMIN __REG_2700G(0x00001020)
74#define LMPROTMAX __REG_2700G(0x00001024)
75#define LMPROTCFG __REG_2700G(0x00001028)
76#define LMPROTERR __REG_2700G(0x0000102c)
77
78/* Plane Controller Registers (0x0000_2000 0x0000_2FFF) */
79#define GSCTRL __REG_2700G(0x00002000)
80#define VSCTRL __REG_2700G(0x00002004)
81#define GBBASE __REG_2700G(0x00002020)
82#define VBBASE __REG_2700G(0x00002024)
83#define GDRCTRL __REG_2700G(0x00002040)
84#define VCMSK __REG_2700G(0x00002044)
85#define GSCADR __REG_2700G(0x00002060)
86#define VSCADR __REG_2700G(0x00002064)
87#define VUBASE __REG_2700G(0x00002084)
88#define VVBASE __REG_2700G(0x000020a4)
89#define GSADR __REG_2700G(0x000020c0)
90#define VSADR __REG_2700G(0x000020c4)
91#define HCCTRL __REG_2700G(0x00002100)
92#define HCSIZE __REG_2700G(0x00002110)
93#define HCPOS __REG_2700G(0x00002120)
94#define HCBADR __REG_2700G(0x00002130)
95#define HCCKMSK __REG_2700G(0x00002140)
96#define GPLUT __REG_2700G(0x00002150)
97#define DSCTRL __REG_2700G(0x00002154)
98#define DHT01 __REG_2700G(0x00002158)
99#define DHT02 __REG_2700G(0x0000215c)
100#define DHT03 __REG_2700G(0x00002160)
101#define DVT01 __REG_2700G(0x00002164)
102#define DVT02 __REG_2700G(0x00002168)
103#define DVT03 __REG_2700G(0x0000216c)
104#define DBCOL __REG_2700G(0x00002170)
105#define BGCOLOR __REG_2700G(0x00002174)
106#define DINTRS __REG_2700G(0x00002178)
107#define DINTRE __REG_2700G(0x0000217c)
108#define DINTRCNT __REG_2700G(0x00002180)
109#define DSIG __REG_2700G(0x00002184)
110#define DMCTRL __REG_2700G(0x00002188)
111#define CLIPCTRL __REG_2700G(0x0000218c)
112#define SPOCTRL __REG_2700G(0x00002190)
113#define SVCTRL __REG_2700G(0x00002194)
114
115/* 0x0000_2198 */
116/* 0x0000_21A8 VSCOEFF[0:4] Video Scalar Vertical Coefficient [0:4] 4.14.5 */
117#define VSCOEFF0 __REG_2700G(0x00002198)
118#define VSCOEFF1 __REG_2700G(0x0000219c)
119#define VSCOEFF2 __REG_2700G(0x000021a0)
120#define VSCOEFF3 __REG_2700G(0x000021a4)
121#define VSCOEFF4 __REG_2700G(0x000021a8)
122
123#define SHCTRL __REG_2700G(0x000021b0)
124
125/* 0x0000_21B4 */
126/* 0x0000_21D4 HSCOEFF[0:8] Video Scalar Horizontal Coefficient [0:8] 4.14.7 */
127#define HSCOEFF0 __REG_2700G(0x000021b4)
128#define HSCOEFF1 __REG_2700G(0x000021b8)
129#define HSCOEFF2 __REG_2700G(0x000021bc)
130#define HSCOEFF3 __REG_2700G(0x000021b0)
131#define HSCOEFF4 __REG_2700G(0x000021c4)
132#define HSCOEFF5 __REG_2700G(0x000021c8)
133#define HSCOEFF6 __REG_2700G(0x000021cc)
134#define HSCOEFF7 __REG_2700G(0x000021d0)
135#define HSCOEFF8 __REG_2700G(0x000021d4)
136
137#define SSSIZE __REG_2700G(0x000021D8)
138
139/* 0x0000_2200 */
140/* 0x0000_2240 VIDGAM[0:16] Video Gamma LUT Index [0:16] 4.15.2 */
141#define VIDGAM0 __REG_2700G(0x00002200)
142#define VIDGAM1 __REG_2700G(0x00002204)
143#define VIDGAM2 __REG_2700G(0x00002208)
144#define VIDGAM3 __REG_2700G(0x0000220c)
145#define VIDGAM4 __REG_2700G(0x00002210)
146#define VIDGAM5 __REG_2700G(0x00002214)
147#define VIDGAM6 __REG_2700G(0x00002218)
148#define VIDGAM7 __REG_2700G(0x0000221c)
149#define VIDGAM8 __REG_2700G(0x00002220)
150#define VIDGAM9 __REG_2700G(0x00002224)
151#define VIDGAM10 __REG_2700G(0x00002228)
152#define VIDGAM11 __REG_2700G(0x0000222c)
153#define VIDGAM12 __REG_2700G(0x00002230)
154#define VIDGAM13 __REG_2700G(0x00002234)
155#define VIDGAM14 __REG_2700G(0x00002238)
156#define VIDGAM15 __REG_2700G(0x0000223c)
157#define VIDGAM16 __REG_2700G(0x00002240)
158
159/* 0x0000_2250 */
160/* 0x0000_2290 GFXGAM[0:16] Graphics Gamma LUT Index [0:16] 4.15.3 */
161#define GFXGAM0 __REG_2700G(0x00002250)
162#define GFXGAM1 __REG_2700G(0x00002254)
163#define GFXGAM2 __REG_2700G(0x00002258)
164#define GFXGAM3 __REG_2700G(0x0000225c)
165#define GFXGAM4 __REG_2700G(0x00002260)
166#define GFXGAM5 __REG_2700G(0x00002264)
167#define GFXGAM6 __REG_2700G(0x00002268)
168#define GFXGAM7 __REG_2700G(0x0000226c)
169#define GFXGAM8 __REG_2700G(0x00002270)
170#define GFXGAM9 __REG_2700G(0x00002274)
171#define GFXGAM10 __REG_2700G(0x00002278)
172#define GFXGAM11 __REG_2700G(0x0000227c)
173#define GFXGAM12 __REG_2700G(0x00002280)
174#define GFXGAM13 __REG_2700G(0x00002284)
175#define GFXGAM14 __REG_2700G(0x00002288)
176#define GFXGAM15 __REG_2700G(0x0000228c)
177#define GFXGAM16 __REG_2700G(0x00002290)
178
179#define DLSTS __REG_2700G(0x00002300)
180#define DLLCTRL __REG_2700G(0x00002304)
181#define DVLNUM __REG_2700G(0x00002308)
182#define DUCTRL __REG_2700G(0x0000230c)
183#define DVECTRL __REG_2700G(0x00002310)
184#define DHDET __REG_2700G(0x00002314)
185#define DVDET __REG_2700G(0x00002318)
186#define DODMSK __REG_2700G(0x0000231c)
187#define CSC01 __REG_2700G(0x00002330)
188#define CSC02 __REG_2700G(0x00002334)
189#define CSC03 __REG_2700G(0x00002338)
190#define CSC04 __REG_2700G(0x0000233c)
191#define CSC05 __REG_2700G(0x00002340)
192
193#define FB_MEMORY_START __REG_2700G(0x00060000)
194
195#endif /* __REGS_2700G_ */
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index ff5454601e22..d1267904c280 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -12,7 +12,6 @@
12 */ 12 */
13 13
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/tty.h>
16#include <linux/fb.h> 15#include <linux/fb.h>
17#include <linux/sched.h> 16#include <linux/sched.h>
18 17
diff --git a/drivers/video/neofb.c b/drivers/video/neofb.c
index 773855a311e8..59a6f5fa5ae6 100644
--- a/drivers/video/neofb.c
+++ b/drivers/video/neofb.c
@@ -59,7 +59,6 @@
59#include <linux/errno.h> 59#include <linux/errno.h>
60#include <linux/string.h> 60#include <linux/string.h>
61#include <linux/mm.h> 61#include <linux/mm.h>
62#include <linux/tty.h>
63#include <linux/slab.h> 62#include <linux/slab.h>
64#include <linux/delay.h> 63#include <linux/delay.h>
65#include <linux/fb.h> 64#include <linux/fb.h>
diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c
index 1c1c10c699c5..5b75ae4e9457 100644
--- a/drivers/video/nvidia/nv_backlight.c
+++ b/drivers/video/nvidia/nv_backlight.c
@@ -26,9 +26,11 @@
26 */ 26 */
27#define MIN_LEVEL 0x158 27#define MIN_LEVEL 0x158
28#define MAX_LEVEL 0x534 28#define MAX_LEVEL 0x534
29#define LEVEL_STEP ((MAX_LEVEL - MIN_LEVEL) / FB_BACKLIGHT_MAX)
29 30
30static struct backlight_properties nvidia_bl_data; 31static struct backlight_properties nvidia_bl_data;
31 32
33/* Call with fb_info->bl_mutex held */
32static int nvidia_bl_get_level_brightness(struct nvidia_par *par, 34static int nvidia_bl_get_level_brightness(struct nvidia_par *par,
33 int level) 35 int level)
34{ 36{
@@ -36,9 +38,7 @@ static int nvidia_bl_get_level_brightness(struct nvidia_par *par,
36 int nlevel; 38 int nlevel;
37 39
38 /* Get and convert the value */ 40 /* Get and convert the value */
39 mutex_lock(&info->bl_mutex); 41 nlevel = MIN_LEVEL + info->bl_curve[level] * LEVEL_STEP;
40 nlevel = info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL;
41 mutex_unlock(&info->bl_mutex);
42 42
43 if (nlevel < 0) 43 if (nlevel < 0)
44 nlevel = 0; 44 nlevel = 0;
@@ -50,7 +50,8 @@ static int nvidia_bl_get_level_brightness(struct nvidia_par *par,
50 return nlevel; 50 return nlevel;
51} 51}
52 52
53static int nvidia_bl_update_status(struct backlight_device *bd) 53/* Call with fb_info->bl_mutex held */
54static int __nvidia_bl_update_status(struct backlight_device *bd)
54{ 55{
55 struct nvidia_par *par = class_get_devdata(&bd->class_dev); 56 struct nvidia_par *par = class_get_devdata(&bd->class_dev);
56 u32 tmp_pcrt, tmp_pmc, fpcontrol; 57 u32 tmp_pcrt, tmp_pmc, fpcontrol;
@@ -84,6 +85,19 @@ static int nvidia_bl_update_status(struct backlight_device *bd)
84 return 0; 85 return 0;
85} 86}
86 87
88static int nvidia_bl_update_status(struct backlight_device *bd)
89{
90 struct nvidia_par *par = class_get_devdata(&bd->class_dev);
91 struct fb_info *info = pci_get_drvdata(par->pci_dev);
92 int ret;
93
94 mutex_lock(&info->bl_mutex);
95 ret = __nvidia_bl_update_status(bd);
96 mutex_unlock(&info->bl_mutex);
97
98 return ret;
99}
100
87static int nvidia_bl_get_brightness(struct backlight_device *bd) 101static int nvidia_bl_get_brightness(struct backlight_device *bd)
88{ 102{
89 return bd->props->brightness; 103 return bd->props->brightness;
@@ -96,6 +110,20 @@ static struct backlight_properties nvidia_bl_data = {
96 .max_brightness = (FB_BACKLIGHT_LEVELS - 1), 110 .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
97}; 111};
98 112
113void nvidia_bl_set_power(struct fb_info *info, int power)
114{
115 mutex_lock(&info->bl_mutex);
116
117 if (info->bl_dev) {
118 down(&info->bl_dev->sem);
119 info->bl_dev->props->power = power;
120 __nvidia_bl_update_status(info->bl_dev);
121 up(&info->bl_dev->sem);
122 }
123
124 mutex_unlock(&info->bl_mutex);
125}
126
99void nvidia_bl_init(struct nvidia_par *par) 127void nvidia_bl_init(struct nvidia_par *par)
100{ 128{
101 struct fb_info *info = pci_get_drvdata(par->pci_dev); 129 struct fb_info *info = pci_get_drvdata(par->pci_dev);
@@ -116,7 +144,7 @@ void nvidia_bl_init(struct nvidia_par *par)
116 bd = backlight_device_register(name, par, &nvidia_bl_data); 144 bd = backlight_device_register(name, par, &nvidia_bl_data);
117 if (IS_ERR(bd)) { 145 if (IS_ERR(bd)) {
118 info->bl_dev = NULL; 146 info->bl_dev = NULL;
119 printk("nvidia: Backlight registration failed\n"); 147 printk(KERN_WARNING "nvidia: Backlight registration failed\n");
120 goto error; 148 goto error;
121 } 149 }
122 150
@@ -127,11 +155,11 @@ void nvidia_bl_init(struct nvidia_par *par)
127 0x534 * FB_BACKLIGHT_MAX / MAX_LEVEL); 155 0x534 * FB_BACKLIGHT_MAX / MAX_LEVEL);
128 mutex_unlock(&info->bl_mutex); 156 mutex_unlock(&info->bl_mutex);
129 157
130 up(&bd->sem); 158 down(&bd->sem);
131 bd->props->brightness = nvidia_bl_data.max_brightness; 159 bd->props->brightness = nvidia_bl_data.max_brightness;
132 bd->props->power = FB_BLANK_UNBLANK; 160 bd->props->power = FB_BLANK_UNBLANK;
133 bd->props->update_status(bd); 161 bd->props->update_status(bd);
134 down(&bd->sem); 162 up(&bd->sem);
135 163
136#ifdef CONFIG_PMAC_BACKLIGHT 164#ifdef CONFIG_PMAC_BACKLIGHT
137 mutex_lock(&pmac_backlight_mutex); 165 mutex_lock(&pmac_backlight_mutex);
diff --git a/drivers/video/nvidia/nv_proto.h b/drivers/video/nvidia/nv_proto.h
index 6fba656cd56b..861271017655 100644
--- a/drivers/video/nvidia/nv_proto.h
+++ b/drivers/video/nvidia/nv_proto.h
@@ -68,9 +68,11 @@ extern u8 byte_rev[256];
68#ifdef CONFIG_FB_NVIDIA_BACKLIGHT 68#ifdef CONFIG_FB_NVIDIA_BACKLIGHT
69extern void nvidia_bl_init(struct nvidia_par *par); 69extern void nvidia_bl_init(struct nvidia_par *par);
70extern void nvidia_bl_exit(struct nvidia_par *par); 70extern void nvidia_bl_exit(struct nvidia_par *par);
71extern void nvidia_bl_set_power(struct fb_info *info, int power);
71#else 72#else
72static inline void nvidia_bl_init(struct nvidia_par *par) {} 73static inline void nvidia_bl_init(struct nvidia_par *par) {}
73static inline void nvidia_bl_exit(struct nvidia_par *par) {} 74static inline void nvidia_bl_exit(struct nvidia_par *par) {}
75static inline void nvidia_bl_set_power(struct fb_info *info, int power) {}
74#endif 76#endif
75 77
76#endif /* __NV_PROTO_H__ */ 78#endif /* __NV_PROTO_H__ */
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index b02d6033cc0c..d4f850117874 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -14,7 +14,6 @@
14#include <linux/errno.h> 14#include <linux/errno.h>
15#include <linux/string.h> 15#include <linux/string.h>
16#include <linux/mm.h> 16#include <linux/mm.h>
17#include <linux/tty.h>
18#include <linux/slab.h> 17#include <linux/slab.h>
19#include <linux/delay.h> 18#include <linux/delay.h>
20#include <linux/fb.h> 19#include <linux/fb.h>
@@ -35,10 +34,6 @@
35#include "nv_proto.h" 34#include "nv_proto.h"
36#include "nv_dma.h" 35#include "nv_dma.h"
37 36
38#ifndef CONFIG_PCI /* sanity check */
39#error This driver requires PCI support.
40#endif
41
42#undef CONFIG_FB_NVIDIA_DEBUG 37#undef CONFIG_FB_NVIDIA_DEBUG
43#ifdef CONFIG_FB_NVIDIA_DEBUG 38#ifdef CONFIG_FB_NVIDIA_DEBUG
44#define NVTRACE printk 39#define NVTRACE printk
@@ -933,16 +928,7 @@ static int nvidiafb_blank(int blank, struct fb_info *info)
933 NVWriteSeq(par, 0x01, tmp); 928 NVWriteSeq(par, 0x01, tmp);
934 NVWriteCrtc(par, 0x1a, vesa); 929 NVWriteCrtc(par, 0x1a, vesa);
935 930
936#ifdef CONFIG_FB_NVIDIA_BACKLIGHT 931 nvidia_bl_set_power(info, blank);
937 mutex_lock(&info->bl_mutex);
938 if (info->bl_dev) {
939 down(&info->bl_dev->sem);
940 info->bl_dev->props->power = blank;
941 info->bl_dev->props->update_status(info->bl_dev);
942 up(&info->bl_dev->sem);
943 }
944 mutex_unlock(&info->bl_mutex);
945#endif
946 932
947 NVTRACE_LEAVE(); 933 NVTRACE_LEAVE();
948 934
@@ -1313,20 +1299,19 @@ static int __devinit nvidiafb_probe(struct pci_dev *pd,
1313 1299
1314 nvidia_save_vga(par, &par->SavedReg); 1300 nvidia_save_vga(par, &par->SavedReg);
1315 1301
1302 pci_set_drvdata(pd, info);
1303 nvidia_bl_init(par);
1316 if (register_framebuffer(info) < 0) { 1304 if (register_framebuffer(info) < 0) {
1317 printk(KERN_ERR PFX "error registering nVidia framebuffer\n"); 1305 printk(KERN_ERR PFX "error registering nVidia framebuffer\n");
1318 goto err_out_iounmap_fb; 1306 goto err_out_iounmap_fb;
1319 } 1307 }
1320 1308
1321 pci_set_drvdata(pd, info);
1322 1309
1323 printk(KERN_INFO PFX 1310 printk(KERN_INFO PFX
1324 "PCI nVidia %s framebuffer (%dMB @ 0x%lX)\n", 1311 "PCI nVidia %s framebuffer (%dMB @ 0x%lX)\n",
1325 info->fix.id, 1312 info->fix.id,
1326 par->FbMapSize / (1024 * 1024), info->fix.smem_start); 1313 par->FbMapSize / (1024 * 1024), info->fix.smem_start);
1327 1314
1328 nvidia_bl_init(par);
1329
1330 NVTRACE_LEAVE(); 1315 NVTRACE_LEAVE();
1331 return 0; 1316 return 0;
1332 1317
diff --git a/drivers/video/offb.c b/drivers/video/offb.c
index bfeb11bd4712..0013311e0564 100644
--- a/drivers/video/offb.c
+++ b/drivers/video/offb.c
@@ -17,7 +17,6 @@
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/mm.h> 19#include <linux/mm.h>
20#include <linux/tty.h>
21#include <linux/slab.h> 20#include <linux/slab.h>
22#include <linux/vmalloc.h> 21#include <linux/vmalloc.h>
23#include <linux/delay.h> 22#include <linux/delay.h>
@@ -63,8 +62,6 @@ struct offb_par default_par;
63 * Interface used by the world 62 * Interface used by the world
64 */ 63 */
65 64
66int offb_init(void);
67
68static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, 65static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
69 u_int transp, struct fb_info *info); 66 u_int transp, struct fb_info *info);
70static int offb_blank(int blank, struct fb_info *info); 67static int offb_blank(int blank, struct fb_info *info);
@@ -73,11 +70,6 @@ static int offb_blank(int blank, struct fb_info *info);
73extern boot_infos_t *boot_infos; 70extern boot_infos_t *boot_infos;
74#endif 71#endif
75 72
76static void offb_init_nodriver(struct device_node *);
77static void offb_init_fb(const char *name, const char *full_name,
78 int width, int height, int depth, int pitch,
79 unsigned long address, struct device_node *dp);
80
81static struct fb_ops offb_ops = { 73static struct fb_ops offb_ops = {
82 .owner = THIS_MODULE, 74 .owner = THIS_MODULE,
83 .fb_setcolreg = offb_setcolreg, 75 .fb_setcolreg = offb_setcolreg,
@@ -97,14 +89,43 @@ static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
97 u_int transp, struct fb_info *info) 89 u_int transp, struct fb_info *info)
98{ 90{
99 struct offb_par *par = (struct offb_par *) info->par; 91 struct offb_par *par = (struct offb_par *) info->par;
92 int i, depth;
93 u32 *pal = info->pseudo_palette;
100 94
101 if (!par->cmap_adr || regno > 255) 95 depth = info->var.bits_per_pixel;
96 if (depth == 16)
97 depth = (info->var.green.length == 5) ? 15 : 16;
98
99 if (regno > 255 ||
100 (depth == 16 && regno > 63) ||
101 (depth == 15 && regno > 31))
102 return 1; 102 return 1;
103 103
104 if (regno < 16) {
105 switch (depth) {
106 case 15:
107 pal[regno] = (regno << 10) | (regno << 5) | regno;
108 break;
109 case 16:
110 pal[regno] = (regno << 11) | (regno << 5) | regno;
111 break;
112 case 24:
113 pal[regno] = (regno << 16) | (regno << 8) | regno;
114 break;
115 case 32:
116 i = (regno << 8) | regno;
117 pal[regno] = (i << 16) | i;
118 break;
119 }
120 }
121
104 red >>= 8; 122 red >>= 8;
105 green >>= 8; 123 green >>= 8;
106 blue >>= 8; 124 blue >>= 8;
107 125
126 if (!par->cmap_adr)
127 return 0;
128
108 switch (par->cmap_type) { 129 switch (par->cmap_type) {
109 case cmap_m64: 130 case cmap_m64:
110 writeb(regno, par->cmap_adr); 131 writeb(regno, par->cmap_adr);
@@ -141,20 +162,6 @@ static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
141 break; 162 break;
142 } 163 }
143 164
144 if (regno < 16)
145 switch (info->var.bits_per_pixel) {
146 case 16:
147 ((u16 *) (info->pseudo_palette))[regno] =
148 (regno << 10) | (regno << 5) | regno;
149 break;
150 case 32:
151 {
152 int i = (regno << 8) | regno;
153 ((u32 *) (info->pseudo_palette))[regno] =
154 (i << 16) | i;
155 break;
156 }
157 }
158 return 0; 165 return 0;
159} 166}
160 167
@@ -215,196 +222,17 @@ static int offb_blank(int blank, struct fb_info *info)
215 return 0; 222 return 0;
216} 223}
217 224
218 /*
219 * Initialisation
220 */
221 225
222int __init offb_init(void) 226static void __iomem *offb_map_reg(struct device_node *np, int index,
227 unsigned long offset, unsigned long size)
223{ 228{
224 struct device_node *dp = NULL, *boot_disp = NULL; 229 struct resource r;
225
226#if defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32)
227 struct device_node *macos_display = NULL;
228#endif
229 if (fb_get_options("offb", NULL))
230 return -ENODEV;
231
232#if defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32)
233 /* If we're booted from BootX... */
234 if (boot_infos != 0) {
235 unsigned long addr =
236 (unsigned long) boot_infos->dispDeviceBase;
237 u32 *addrp;
238 u64 daddr, dsize;
239 unsigned int flags;
240
241 /* find the device node corresponding to the macos display */
242 while ((dp = of_find_node_by_type(dp, "display"))) {
243 int i;
244
245 /*
246 * Look for an AAPL,address property first.
247 */
248 unsigned int na;
249 unsigned int *ap =
250 (unsigned int *)get_property(dp, "AAPL,address",
251 &na);
252 if (ap != 0) {
253 for (na /= sizeof(unsigned int); na > 0;
254 --na, ++ap)
255 if (*ap <= addr &&
256 addr < *ap + 0x1000000) {
257 macos_display = dp;
258 goto foundit;
259 }
260 }
261
262 /*
263 * See if the display address is in one of the address
264 * ranges for this display.
265 */
266 i = 0;
267 for (;;) {
268 addrp = of_get_address(dp, i++, &dsize, &flags);
269 if (addrp == NULL)
270 break;
271 if (!(flags & IORESOURCE_MEM))
272 continue;
273 daddr = of_translate_address(dp, addrp);
274 if (daddr == OF_BAD_ADDR)
275 continue;
276 if (daddr <= addr && addr < (daddr + dsize)) {
277 macos_display = dp;
278 goto foundit;
279 }
280 }
281 foundit:
282 if (macos_display) {
283 printk(KERN_INFO "MacOS display is %s\n",
284 dp->full_name);
285 break;
286 }
287 }
288
289 /* initialize it */
290 offb_init_fb(macos_display ? macos_display->
291 name : "MacOS display",
292 macos_display ? macos_display->
293 full_name : "MacOS display",
294 boot_infos->dispDeviceRect[2],
295 boot_infos->dispDeviceRect[3],
296 boot_infos->dispDeviceDepth,
297 boot_infos->dispDeviceRowBytes, addr, NULL);
298 }
299#endif /* defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32) */
300
301 for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
302 if (get_property(dp, "linux,opened", NULL) &&
303 get_property(dp, "linux,boot-display", NULL)) {
304 boot_disp = dp;
305 offb_init_nodriver(dp);
306 }
307 }
308 for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
309 if (get_property(dp, "linux,opened", NULL) &&
310 dp != boot_disp)
311 offb_init_nodriver(dp);
312 }
313
314 return 0;
315}
316
317
318static void __init offb_init_nodriver(struct device_node *dp)
319{
320 int *pp, i;
321 unsigned int len;
322 int width = 640, height = 480, depth = 8, pitch;
323 unsigned int flags, rsize, *up;
324 u64 address = OF_BAD_ADDR;
325 u32 *addrp;
326 u64 asize;
327
328 if ((pp = (int *) get_property(dp, "depth", &len)) != NULL
329 && len == sizeof(int))
330 depth = *pp;
331 if ((pp = (int *) get_property(dp, "width", &len)) != NULL
332 && len == sizeof(int))
333 width = *pp;
334 if ((pp = (int *) get_property(dp, "height", &len)) != NULL
335 && len == sizeof(int))
336 height = *pp;
337 if ((pp = (int *) get_property(dp, "linebytes", &len)) != NULL
338 && len == sizeof(int)) {
339 pitch = *pp;
340 if (pitch == 1)
341 pitch = 0x1000;
342 } else
343 pitch = width;
344
345 rsize = (unsigned long)pitch * (unsigned long)height *
346 (unsigned long)(depth / 8);
347
348 /* Try to match device to a PCI device in order to get a properly
349 * translated address rather then trying to decode the open firmware
350 * stuff in various incorrect ways
351 */
352#ifdef CONFIG_PCI
353 /* First try to locate the PCI device if any */
354 {
355 struct pci_dev *pdev = NULL;
356
357 for_each_pci_dev(pdev) {
358 if (dp == pci_device_to_OF_node(pdev))
359 break;
360 }
361 if (pdev) {
362 for (i = 0; i < 6 && address == OF_BAD_ADDR; i++) {
363 if ((pci_resource_flags(pdev, i) &
364 IORESOURCE_MEM) &&
365 (pci_resource_len(pdev, i) >= rsize))
366 address = pci_resource_start(pdev, i);
367 }
368 pci_dev_put(pdev);
369 }
370 }
371#endif /* CONFIG_PCI */
372
373 /* This one is dodgy, we may drop it ... */
374 if (address == OF_BAD_ADDR &&
375 (up = (unsigned *) get_property(dp, "address", &len)) != NULL &&
376 len == sizeof(unsigned int))
377 address = (u64) * up;
378
379 if (address == OF_BAD_ADDR) {
380 for (i = 0; (addrp = of_get_address(dp, i, &asize, &flags))
381 != NULL; i++) {
382 if (!(flags & IORESOURCE_MEM))
383 continue;
384 if (asize >= pitch * height * depth / 8)
385 break;
386 }
387 if (addrp == NULL) {
388 printk(KERN_ERR
389 "no framebuffer address found for %s\n",
390 dp->full_name);
391 return;
392 }
393 address = of_translate_address(dp, addrp);
394 if (address == OF_BAD_ADDR) {
395 printk(KERN_ERR
396 "can't translate framebuffer address for %s\n",
397 dp->full_name);
398 return;
399 }
400
401 /* kludge for valkyrie */
402 if (strcmp(dp->name, "valkyrie") == 0)
403 address += 0x1000;
404 }
405 offb_init_fb(dp->name, dp->full_name, width, height, depth,
406 pitch, address, dp);
407 230
231 if (of_address_to_resource(np, index, &r))
232 return 0;
233 if ((r.start + offset + size) > r.end)
234 return 0;
235 return ioremap(r.start + offset, size);
408} 236}
409 237
410static void __init offb_init_fb(const char *name, const char *full_name, 238static void __init offb_init_fb(const char *name, const char *full_name,
@@ -412,7 +240,7 @@ static void __init offb_init_fb(const char *name, const char *full_name,
412 int pitch, unsigned long address, 240 int pitch, unsigned long address,
413 struct device_node *dp) 241 struct device_node *dp)
414{ 242{
415 unsigned long res_size = pitch * height * depth / 8; 243 unsigned long res_size = pitch * height * (depth + 7) / 8;
416 struct offb_par *par = &default_par; 244 struct offb_par *par = &default_par;
417 unsigned long res_start = address; 245 unsigned long res_start = address;
418 struct fb_fix_screeninfo *fix; 246 struct fb_fix_screeninfo *fix;
@@ -426,7 +254,7 @@ static void __init offb_init_fb(const char *name, const char *full_name,
426 printk(KERN_INFO 254 printk(KERN_INFO
427 "Using unsupported %dx%d %s at %lx, depth=%d, pitch=%d\n", 255 "Using unsupported %dx%d %s at %lx, depth=%d, pitch=%d\n",
428 width, height, name, address, depth, pitch); 256 width, height, name, address, depth, pitch);
429 if (depth != 8 && depth != 16 && depth != 32) { 257 if (depth != 8 && depth != 15 && depth != 16 && depth != 32) {
430 printk(KERN_ERR "%s: can't use depth = %d\n", full_name, 258 printk(KERN_ERR "%s: can't use depth = %d\n", full_name,
431 depth); 259 depth);
432 release_mem_region(res_start, res_size); 260 release_mem_region(res_start, res_size);
@@ -461,48 +289,41 @@ static void __init offb_init_fb(const char *name, const char *full_name,
461 289
462 par->cmap_type = cmap_unknown; 290 par->cmap_type = cmap_unknown;
463 if (depth == 8) { 291 if (depth == 8) {
464
465 /* Palette hacks disabled for now */ 292 /* Palette hacks disabled for now */
466#if 0
467 if (dp && !strncmp(name, "ATY,Rage128", 11)) { 293 if (dp && !strncmp(name, "ATY,Rage128", 11)) {
468 unsigned long regbase = dp->addrs[2].address; 294 par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
469 par->cmap_adr = ioremap(regbase, 0x1FFF); 295 if (par->cmap_adr)
470 par->cmap_type = cmap_r128; 296 par->cmap_type = cmap_r128;
471 } else if (dp && (!strncmp(name, "ATY,RageM3pA", 12) 297 } else if (dp && (!strncmp(name, "ATY,RageM3pA", 12)
472 || !strncmp(name, "ATY,RageM3p12A", 14))) { 298 || !strncmp(name, "ATY,RageM3p12A", 14))) {
473 unsigned long regbase = 299 par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
474 dp->parent->addrs[2].address; 300 if (par->cmap_adr)
475 par->cmap_adr = ioremap(regbase, 0x1FFF); 301 par->cmap_type = cmap_M3A;
476 par->cmap_type = cmap_M3A;
477 } else if (dp && !strncmp(name, "ATY,RageM3pB", 12)) { 302 } else if (dp && !strncmp(name, "ATY,RageM3pB", 12)) {
478 unsigned long regbase = 303 par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
479 dp->parent->addrs[2].address; 304 if (par->cmap_adr)
480 par->cmap_adr = ioremap(regbase, 0x1FFF); 305 par->cmap_type = cmap_M3B;
481 par->cmap_type = cmap_M3B;
482 } else if (dp && !strncmp(name, "ATY,Rage6", 9)) { 306 } else if (dp && !strncmp(name, "ATY,Rage6", 9)) {
483 unsigned long regbase = dp->addrs[1].address; 307 par->cmap_adr = offb_map_reg(dp, 1, 0, 0x1fff);
484 par->cmap_adr = ioremap(regbase, 0x1FFF); 308 if (par->cmap_adr)
485 par->cmap_type = cmap_radeon; 309 par->cmap_type = cmap_radeon;
486 } else if (!strncmp(name, "ATY,", 4)) { 310 } else if (!strncmp(name, "ATY,", 4)) {
487 unsigned long base = address & 0xff000000UL; 311 unsigned long base = address & 0xff000000UL;
488 par->cmap_adr = 312 par->cmap_adr =
489 ioremap(base + 0x7ff000, 0x1000) + 0xcc0; 313 ioremap(base + 0x7ff000, 0x1000) + 0xcc0;
490 par->cmap_data = par->cmap_adr + 1; 314 par->cmap_data = par->cmap_adr + 1;
491 par->cmap_type = cmap_m64; 315 par->cmap_type = cmap_m64;
492 } else if (device_is_compatible(dp, "pci1014,b7")) { 316 } else if (dp && device_is_compatible(dp, "pci1014,b7")) {
493 unsigned long regbase = dp->addrs[0].address; 317 par->cmap_adr = offb_map_reg(dp, 0, 0x6000, 0x1000);
494 par->cmap_adr = ioremap(regbase + 0x6000, 0x1000); 318 if (par->cmap_adr)
495 par->cmap_type = cmap_gxt2000; 319 par->cmap_type = cmap_gxt2000;
496 } 320 }
497#endif 321 fix->visual = (par->cmap_type != cmap_unknown) ?
498 fix->visual = par->cmap_adr ? FB_VISUAL_PSEUDOCOLOR 322 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_STATIC_PSEUDOCOLOR;
499 : FB_VISUAL_STATIC_PSEUDOCOLOR;
500 } else 323 } else
501 fix->visual = /* par->cmap_adr ? FB_VISUAL_DIRECTCOLOR 324 fix->visual = FB_VISUAL_TRUECOLOR;
502 : */ FB_VISUAL_TRUECOLOR;
503 325
504 var->xoffset = var->yoffset = 0; 326 var->xoffset = var->yoffset = 0;
505 var->bits_per_pixel = depth;
506 switch (depth) { 327 switch (depth) {
507 case 8: 328 case 8:
508 var->bits_per_pixel = 8; 329 var->bits_per_pixel = 8;
@@ -515,7 +336,7 @@ static void __init offb_init_fb(const char *name, const char *full_name,
515 var->transp.offset = 0; 336 var->transp.offset = 0;
516 var->transp.length = 0; 337 var->transp.length = 0;
517 break; 338 break;
518 case 16: /* RGB 555 */ 339 case 15: /* RGB 555 */
519 var->bits_per_pixel = 16; 340 var->bits_per_pixel = 16;
520 var->red.offset = 10; 341 var->red.offset = 10;
521 var->red.length = 5; 342 var->red.length = 5;
@@ -526,6 +347,17 @@ static void __init offb_init_fb(const char *name, const char *full_name,
526 var->transp.offset = 0; 347 var->transp.offset = 0;
527 var->transp.length = 0; 348 var->transp.length = 0;
528 break; 349 break;
350 case 16: /* RGB 565 */
351 var->bits_per_pixel = 16;
352 var->red.offset = 11;
353 var->red.length = 5;
354 var->green.offset = 5;
355 var->green.length = 6;
356 var->blue.offset = 0;
357 var->blue.length = 5;
358 var->transp.offset = 0;
359 var->transp.length = 0;
360 break;
529 case 32: /* RGB 888 */ 361 case 32: /* RGB 888 */
530 var->bits_per_pixel = 32; 362 var->bits_per_pixel = 32;
531 var->red.offset = 16; 363 var->red.offset = 16;
@@ -569,5 +401,139 @@ static void __init offb_init_fb(const char *name, const char *full_name,
569 info->node, full_name); 401 info->node, full_name);
570} 402}
571 403
404
405static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
406{
407 unsigned int len;
408 int i, width = 640, height = 480, depth = 8, pitch = 640;
409 unsigned int flags, rsize, addr_prop = 0;
410 unsigned long max_size = 0;
411 u64 rstart, address = OF_BAD_ADDR;
412 u32 *pp, *addrp, *up;
413 u64 asize;
414
415 pp = (u32 *)get_property(dp, "linux,bootx-depth", &len);
416 if (pp == NULL)
417 pp = (u32 *)get_property(dp, "depth", &len);
418 if (pp && len == sizeof(u32))
419 depth = *pp;
420
421 pp = (u32 *)get_property(dp, "linux,bootx-width", &len);
422 if (pp == NULL)
423 pp = (u32 *)get_property(dp, "width", &len);
424 if (pp && len == sizeof(u32))
425 width = *pp;
426
427 pp = (u32 *)get_property(dp, "linux,bootx-height", &len);
428 if (pp == NULL)
429 pp = (u32 *)get_property(dp, "height", &len);
430 if (pp && len == sizeof(u32))
431 height = *pp;
432
433 pp = (u32 *)get_property(dp, "linux,bootx-linebytes", &len);
434 if (pp == NULL)
435 pp = (u32 *)get_property(dp, "linebytes", &len);
436 if (pp && len == sizeof(u32))
437 pitch = *pp;
438 else
439 pitch = width * ((depth + 7) / 8);
440
441 rsize = (unsigned long)pitch * (unsigned long)height;
442
443 /* Ok, now we try to figure out the address of the framebuffer.
444 *
445 * Unfortunately, Open Firmware doesn't provide a standard way to do
446 * so. All we can do is a dodgy heuristic that happens to work in
447 * practice. On most machines, the "address" property contains what
448 * we need, though not on Matrox cards found in IBM machines. What I've
449 * found that appears to give good results is to go through the PCI
450 * ranges and pick one that is both big enough and if possible encloses
451 * the "address" property. If none match, we pick the biggest
452 */
453 up = (u32 *)get_property(dp, "linux,bootx-addr", &len);
454 if (up == NULL)
455 up = (u32 *)get_property(dp, "address", &len);
456 if (up && len == sizeof(u32))
457 addr_prop = *up;
458
459 /* Hack for when BootX is passing us */
460 if (no_real_node)
461 goto skip_addr;
462
463 for (i = 0; (addrp = of_get_address(dp, i, &asize, &flags))
464 != NULL; i++) {
465 int match_addrp = 0;
466
467 if (!(flags & IORESOURCE_MEM))
468 continue;
469 if (asize < rsize)
470 continue;
471 rstart = of_translate_address(dp, addrp);
472 if (rstart == OF_BAD_ADDR)
473 continue;
474 if (addr_prop && (rstart <= addr_prop) &&
475 ((rstart + asize) >= (addr_prop + rsize)))
476 match_addrp = 1;
477 if (match_addrp) {
478 address = addr_prop;
479 break;
480 }
481 if (rsize > max_size) {
482 max_size = rsize;
483 address = OF_BAD_ADDR;
484 }
485
486 if (address == OF_BAD_ADDR)
487 address = rstart;
488 }
489 skip_addr:
490 if (address == OF_BAD_ADDR && addr_prop)
491 address = (u64)addr_prop;
492 if (address != OF_BAD_ADDR) {
493 /* kludge for valkyrie */
494 if (strcmp(dp->name, "valkyrie") == 0)
495 address += 0x1000;
496 offb_init_fb(no_real_node ? "bootx" : dp->name,
497 no_real_node ? "display" : dp->full_name,
498 width, height, depth, pitch, address,
499 no_real_node ? dp : NULL);
500 }
501}
502
503static int __init offb_init(void)
504{
505 struct device_node *dp = NULL, *boot_disp = NULL;
506
507 if (fb_get_options("offb", NULL))
508 return -ENODEV;
509
510 /* Check if we have a MacOS display without a node spec */
511 if (get_property(of_chosen, "linux,bootx-noscreen", NULL) != NULL) {
512 /* The old code tried to work out which node was the MacOS
513 * display based on the address. I'm dropping that since the
514 * lack of a node spec only happens with old BootX versions
515 * (users can update) and with this code, they'll still get
516 * a display (just not the palette hacks).
517 */
518 offb_init_nodriver(of_chosen, 1);
519 }
520
521 for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
522 if (get_property(dp, "linux,opened", NULL) &&
523 get_property(dp, "linux,boot-display", NULL)) {
524 boot_disp = dp;
525 offb_init_nodriver(dp, 0);
526 }
527 }
528 for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
529 if (get_property(dp, "linux,opened", NULL) &&
530 dp != boot_disp)
531 offb_init_nodriver(dp, 0);
532 }
533
534 return 0;
535}
536
537
572module_init(offb_init); 538module_init(offb_init);
573MODULE_LICENSE("GPL"); 539MODULE_LICENSE("GPL");
diff --git a/drivers/video/platinumfb.c b/drivers/video/platinumfb.c
index 450e802e0aa8..983be3ec2345 100644
--- a/drivers/video/platinumfb.c
+++ b/drivers/video/platinumfb.c
@@ -22,7 +22,6 @@
22#include <linux/errno.h> 22#include <linux/errno.h>
23#include <linux/string.h> 23#include <linux/string.h>
24#include <linux/mm.h> 24#include <linux/mm.h>
25#include <linux/tty.h>
26#include <linux/slab.h> 25#include <linux/slab.h>
27#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
28#include <linux/delay.h> 27#include <linux/delay.h>
diff --git a/drivers/video/pm2fb.c b/drivers/video/pm2fb.c
index 49a203e1591c..a560a2223825 100644
--- a/drivers/video/pm2fb.c
+++ b/drivers/video/pm2fb.c
@@ -33,7 +33,6 @@
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/string.h> 34#include <linux/string.h>
35#include <linux/mm.h> 35#include <linux/mm.h>
36#include <linux/tty.h>
37#include <linux/slab.h> 36#include <linux/slab.h>
38#include <linux/delay.h> 37#include <linux/delay.h>
39#include <linux/fb.h> 38#include <linux/fb.h>
diff --git a/drivers/video/pm3fb.c b/drivers/video/pm3fb.c
index 0e0f977b05ee..1d81ef47efd3 100644
--- a/drivers/video/pm3fb.c
+++ b/drivers/video/pm3fb.c
@@ -57,7 +57,6 @@
57#include <linux/errno.h> 57#include <linux/errno.h>
58#include <linux/string.h> 58#include <linux/string.h>
59#include <linux/mm.h> 59#include <linux/mm.h>
60#include <linux/tty.h>
61#include <linux/slab.h> 60#include <linux/slab.h>
62#include <linux/vmalloc.h> 61#include <linux/vmalloc.h>
63#include <linux/delay.h> 62#include <linux/delay.h>
diff --git a/drivers/video/pmag-aa-fb.c b/drivers/video/pmag-aa-fb.c
index d92f352211ef..68ca3cc40770 100644
--- a/drivers/video/pmag-aa-fb.c
+++ b/drivers/video/pmag-aa-fb.c
@@ -29,7 +29,6 @@
29#include <linux/string.h> 29#include <linux/string.h>
30#include <linux/timer.h> 30#include <linux/timer.h>
31#include <linux/mm.h> 31#include <linux/mm.h>
32#include <linux/tty.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
34#include <linux/delay.h> 33#include <linux/delay.h>
35#include <linux/init.h> 34#include <linux/init.h>
diff --git a/drivers/video/pnx4008/Makefile b/drivers/video/pnx4008/Makefile
new file mode 100644
index 000000000000..636aaccf01fd
--- /dev/null
+++ b/drivers/video/pnx4008/Makefile
@@ -0,0 +1,7 @@
1#
2# Makefile for the new PNX4008 framebuffer device driver
3#
4
5obj-$(CONFIG_FB_PNX4008_DUM) += sdum.o
6obj-$(CONFIG_FB_PNX4008_DUM_RGB) += pnxrgbfb.o
7
diff --git a/drivers/video/pnx4008/dum.h b/drivers/video/pnx4008/dum.h
new file mode 100644
index 000000000000..d80a614d89ed
--- /dev/null
+++ b/drivers/video/pnx4008/dum.h
@@ -0,0 +1,211 @@
1/*
2 * linux/drivers/video/pnx4008/dum.h
3 *
4 * Internal header for SDUM
5 *
6 * 2005 (c) Koninklijke Philips N.V. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 */
11
12#ifndef __PNX008_DUM_H__
13#define __PNX008_DUM_H__
14
15#include <asm/arch/platform.h>
16
17#define PNX4008_DUMCONF_VA_BASE IO_ADDRESS(PNX4008_DUMCONF_BASE)
18#define PNX4008_DUM_MAIN_VA_BASE IO_ADDRESS(PNX4008_DUM_MAINCFG_BASE)
19
20/* DUM CFG ADDRESSES */
21#define DUM_CH_BASE_ADR (PNX4008_DUMCONF_VA_BASE + 0x00)
22#define DUM_CH_MIN_ADR (PNX4008_DUMCONF_VA_BASE + 0x00)
23#define DUM_CH_MAX_ADR (PNX4008_DUMCONF_VA_BASE + 0x04)
24#define DUM_CH_CONF_ADR (PNX4008_DUMCONF_VA_BASE + 0x08)
25#define DUM_CH_STAT_ADR (PNX4008_DUMCONF_VA_BASE + 0x0C)
26#define DUM_CH_CTRL_ADR (PNX4008_DUMCONF_VA_BASE + 0x10)
27
28#define CH_MARG (0x100 / sizeof(u32))
29#define DUM_CH_MIN(i) (*((volatile u32 *)DUM_CH_MIN_ADR + (i) * CH_MARG))
30#define DUM_CH_MAX(i) (*((volatile u32 *)DUM_CH_MAX_ADR + (i) * CH_MARG))
31#define DUM_CH_CONF(i) (*((volatile u32 *)DUM_CH_CONF_ADR + (i) * CH_MARG))
32#define DUM_CH_STAT(i) (*((volatile u32 *)DUM_CH_STAT_ADR + (i) * CH_MARG))
33#define DUM_CH_CTRL(i) (*((volatile u32 *)DUM_CH_CTRL_ADR + (i) * CH_MARG))
34
35#define DUM_CONF_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x00)
36#define DUM_CTRL_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x04)
37#define DUM_STAT_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x08)
38#define DUM_DECODE_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x0C)
39#define DUM_COM_BASE_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x10)
40#define DUM_SYNC_C_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x14)
41#define DUM_CLK_DIV_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x18)
42#define DUM_DIRTY_LOW_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x20)
43#define DUM_DIRTY_HIGH_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x24)
44#define DUM_FORMAT_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x28)
45#define DUM_WTCFG1_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x30)
46#define DUM_RTCFG1_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x34)
47#define DUM_WTCFG2_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x38)
48#define DUM_RTCFG2_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x3C)
49#define DUM_TCFG_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x40)
50#define DUM_OUTP_FORMAT1_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x44)
51#define DUM_OUTP_FORMAT2_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x48)
52#define DUM_SYNC_MODE_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x4C)
53#define DUM_SYNC_OUT_C_ADR (PNX4008_DUM_MAIN_VA_BASE + 0x50)
54
55#define DUM_CONF (*(volatile u32 *)(DUM_CONF_ADR))
56#define DUM_CTRL (*(volatile u32 *)(DUM_CTRL_ADR))
57#define DUM_STAT (*(volatile u32 *)(DUM_STAT_ADR))
58#define DUM_DECODE (*(volatile u32 *)(DUM_DECODE_ADR))
59#define DUM_COM_BASE (*(volatile u32 *)(DUM_COM_BASE_ADR))
60#define DUM_SYNC_C (*(volatile u32 *)(DUM_SYNC_C_ADR))
61#define DUM_CLK_DIV (*(volatile u32 *)(DUM_CLK_DIV_ADR))
62#define DUM_DIRTY_LOW (*(volatile u32 *)(DUM_DIRTY_LOW_ADR))
63#define DUM_DIRTY_HIGH (*(volatile u32 *)(DUM_DIRTY_HIGH_ADR))
64#define DUM_FORMAT (*(volatile u32 *)(DUM_FORMAT_ADR))
65#define DUM_WTCFG1 (*(volatile u32 *)(DUM_WTCFG1_ADR))
66#define DUM_RTCFG1 (*(volatile u32 *)(DUM_RTCFG1_ADR))
67#define DUM_WTCFG2 (*(volatile u32 *)(DUM_WTCFG2_ADR))
68#define DUM_RTCFG2 (*(volatile u32 *)(DUM_RTCFG2_ADR))
69#define DUM_TCFG (*(volatile u32 *)(DUM_TCFG_ADR))
70#define DUM_OUTP_FORMAT1 (*(volatile u32 *)(DUM_OUTP_FORMAT1_ADR))
71#define DUM_OUTP_FORMAT2 (*(volatile u32 *)(DUM_OUTP_FORMAT2_ADR))
72#define DUM_SYNC_MODE (*(volatile u32 *)(DUM_SYNC_MODE_ADR))
73#define DUM_SYNC_OUT_C (*(volatile u32 *)(DUM_SYNC_OUT_C_ADR))
74
75/* DUM SLAVE ADDRESSES */
76#define DUM_SLAVE_WRITE_ADR (PNX4008_DUM_MAINCFG_BASE + 0x0000000)
77#define DUM_SLAVE_READ1_I_ADR (PNX4008_DUM_MAINCFG_BASE + 0x1000000)
78#define DUM_SLAVE_READ1_R_ADR (PNX4008_DUM_MAINCFG_BASE + 0x1000004)
79#define DUM_SLAVE_READ2_I_ADR (PNX4008_DUM_MAINCFG_BASE + 0x1000008)
80#define DUM_SLAVE_READ2_R_ADR (PNX4008_DUM_MAINCFG_BASE + 0x100000C)
81
82#define DUM_SLAVE_WRITE_W ((volatile u32 *)(DUM_SLAVE_WRITE_ADR))
83#define DUM_SLAVE_WRITE_HW ((volatile u16 *)(DUM_SLAVE_WRITE_ADR))
84#define DUM_SLAVE_READ1_I ((volatile u8 *)(DUM_SLAVE_READ1_I_ADR))
85#define DUM_SLAVE_READ1_R ((volatile u16 *)(DUM_SLAVE_READ1_R_ADR))
86#define DUM_SLAVE_READ2_I ((volatile u8 *)(DUM_SLAVE_READ2_I_ADR))
87#define DUM_SLAVE_READ2_R ((volatile u16 *)(DUM_SLAVE_READ2_R_ADR))
88
89/* Sony display register addresses */
90#define DISP_0_REG (0x00)
91#define DISP_1_REG (0x01)
92#define DISP_CAL_REG (0x20)
93#define DISP_ID_REG (0x2A)
94#define DISP_XMIN_L_REG (0x30)
95#define DISP_XMIN_H_REG (0x31)
96#define DISP_YMIN_REG (0x32)
97#define DISP_XMAX_L_REG (0x34)
98#define DISP_XMAX_H_REG (0x35)
99#define DISP_YMAX_REG (0x36)
100#define DISP_SYNC_EN_REG (0x38)
101#define DISP_SYNC_RISE_L_REG (0x3C)
102#define DISP_SYNC_RISE_H_REG (0x3D)
103#define DISP_SYNC_FALL_L_REG (0x3E)
104#define DISP_SYNC_FALL_H_REG (0x3F)
105#define DISP_PIXEL_REG (0x0B)
106#define DISP_DUMMY1_REG (0x28)
107#define DISP_DUMMY2_REG (0x29)
108#define DISP_TIMING_REG (0x98)
109#define DISP_DUMP_REG (0x99)
110
111/* Sony display constants */
112#define SONY_ID1 (0x22)
113#define SONY_ID2 (0x23)
114
115/* Philips display register addresses */
116#define PH_DISP_ORIENT_REG (0x003)
117#define PH_DISP_YPOINT_REG (0x200)
118#define PH_DISP_XPOINT_REG (0x201)
119#define PH_DISP_PIXEL_REG (0x202)
120#define PH_DISP_YMIN_REG (0x406)
121#define PH_DISP_YMAX_REG (0x407)
122#define PH_DISP_XMIN_REG (0x408)
123#define PH_DISP_XMAX_REG (0x409)
124
125/* Misc constants */
126#define NO_VALID_DISPLAY_FOUND (0)
127#define DISPLAY2_IS_NOT_CONNECTED (0)
128
129/* register values */
130#define V_BAC_ENABLE (BIT(0))
131#define V_BAC_DISABLE_IDLE (BIT(1))
132#define V_BAC_DISABLE_TRIG (BIT(2))
133#define V_DUM_RESET (BIT(3))
134#define V_MUX_RESET (BIT(4))
135#define BAC_ENABLED (BIT(0))
136#define BAC_DISABLED 0
137
138/* Sony LCD commands */
139#define V_LCD_STANDBY_OFF ((BIT(25)) | (0 << 16) | DISP_0_REG)
140#define V_LCD_USE_9BIT_BUS ((BIT(25)) | (2 << 16) | DISP_1_REG)
141#define V_LCD_SYNC_RISE_L ((BIT(25)) | (0 << 16) | DISP_SYNC_RISE_L_REG)
142#define V_LCD_SYNC_RISE_H ((BIT(25)) | (0 << 16) | DISP_SYNC_RISE_H_REG)
143#define V_LCD_SYNC_FALL_L ((BIT(25)) | (160 << 16) | DISP_SYNC_FALL_L_REG)
144#define V_LCD_SYNC_FALL_H ((BIT(25)) | (0 << 16) | DISP_SYNC_FALL_H_REG)
145#define V_LCD_SYNC_ENABLE ((BIT(25)) | (128 << 16) | DISP_SYNC_EN_REG)
146#define V_LCD_DISPLAY_ON ((BIT(25)) | (64 << 16) | DISP_0_REG)
147
148enum {
149 PAD_NONE,
150 PAD_512,
151 PAD_1024
152};
153
154enum {
155 RGB888,
156 RGB666,
157 RGB565,
158 BGR565,
159 ARGB1555,
160 ABGR1555,
161 ARGB4444,
162 ABGR4444
163};
164
165struct dum_setup {
166 int sync_neg_edge;
167 int round_robin;
168 int mux_int;
169 int synced_dirty_flag_int;
170 int dirty_flag_int;
171 int error_int;
172 int pf_empty_int;
173 int sf_empty_int;
174 int bac_dis_int;
175 u32 dirty_base_adr;
176 u32 command_base_adr;
177 u32 sync_clk_div;
178 int sync_output;
179 u32 sync_restart_val;
180 u32 set_sync_high;
181 u32 set_sync_low;
182};
183
184struct dum_ch_setup {
185 int disp_no;
186 u32 xmin;
187 u32 ymin;
188 u32 xmax;
189 u32 ymax;
190 int xmirror;
191 int ymirror;
192 int rotate;
193 u32 minadr;
194 u32 maxadr;
195 u32 dirtybuffer;
196 int pad;
197 int format;
198 int hwdirty;
199 int slave_trans;
200};
201
202struct disp_window {
203 u32 xmin_l;
204 u32 xmin_h;
205 u32 ymin;
206 u32 xmax_l;
207 u32 xmax_h;
208 u32 ymax;
209};
210
211#endif /* #ifndef __PNX008_DUM_H__ */
diff --git a/drivers/video/pnx4008/fbcommon.h b/drivers/video/pnx4008/fbcommon.h
new file mode 100644
index 000000000000..4ebc87dafafb
--- /dev/null
+++ b/drivers/video/pnx4008/fbcommon.h
@@ -0,0 +1,43 @@
1/*
2 * Copyright (C) 2005 Philips Semiconductors
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA, or http://www.gnu.org/licenses/gpl.html
18*/
19
20#define QCIF_W (176)
21#define QCIF_H (144)
22
23#define CIF_W (352)
24#define CIF_H (288)
25
26#define LCD_X_RES 208
27#define LCD_Y_RES 320
28#define LCD_X_PAD 256
29#define LCD_BBP 4 /* Bytes Per Pixel */
30
31#define DISP_MAX_X_SIZE (320)
32#define DISP_MAX_Y_SIZE (208)
33
34#define RETURNVAL_BASE (0x400)
35
36enum fb_ioctl_returntype {
37 ENORESOURCESLEFT = RETURNVAL_BASE,
38 ERESOURCESNOTFREED,
39 EPROCNOTOWNER,
40 EFBNOTOWNER,
41 ECOPYFAILED,
42 EIOREMAPFAILED,
43};
diff --git a/drivers/video/pnx4008/pnxrgbfb.c b/drivers/video/pnx4008/pnxrgbfb.c
new file mode 100644
index 000000000000..7d9453c91a42
--- /dev/null
+++ b/drivers/video/pnx4008/pnxrgbfb.c
@@ -0,0 +1,213 @@
1/*
2 * drivers/video/pnx4008/pnxrgbfb.c
3 *
4 * PNX4008's framebuffer support
5 *
6 * Author: Grigory Tolstolytkin <gtolstolytkin@ru.mvista.com>
7 * Based on Philips Semiconductors's code
8 *
9 * Copyrght (c) 2005 MontaVista Software, Inc.
10 * Copyright (c) 2005 Philips Semiconductors
11 * This file is licensed under the terms of the GNU General Public License
12 * version 2. This program is licensed "as is" without any warranty of any
13 * kind, whether express or implied.
14 */
15
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/errno.h>
19#include <linux/string.h>
20#include <linux/mm.h>
21#include <linux/slab.h>
22#include <linux/vmalloc.h>
23#include <linux/delay.h>
24#include <linux/interrupt.h>
25#include <linux/fb.h>
26#include <linux/init.h>
27#include <linux/platform_device.h>
28
29#include <asm/uaccess.h>
30#include "sdum.h"
31#include "fbcommon.h"
32
33static u32 colreg[16];
34
35static struct fb_var_screeninfo rgbfb_var __initdata = {
36 .xres = LCD_X_RES,
37 .yres = LCD_Y_RES,
38 .xres_virtual = LCD_X_RES,
39 .yres_virtual = LCD_Y_RES,
40 .bits_per_pixel = 32,
41 .red.offset = 16,
42 .red.length = 8,
43 .green.offset = 8,
44 .green.length = 8,
45 .blue.offset = 0,
46 .blue.length = 8,
47 .left_margin = 0,
48 .right_margin = 0,
49 .upper_margin = 0,
50 .lower_margin = 0,
51 .vmode = FB_VMODE_NONINTERLACED,
52};
53static struct fb_fix_screeninfo rgbfb_fix __initdata = {
54 .id = "RGBFB",
55 .line_length = LCD_X_RES * LCD_BBP,
56 .type = FB_TYPE_PACKED_PIXELS,
57 .visual = FB_VISUAL_TRUECOLOR,
58 .xpanstep = 0,
59 .ypanstep = 0,
60 .ywrapstep = 0,
61 .accel = FB_ACCEL_NONE,
62};
63
64static int channel_owned;
65
66static int no_cursor(struct fb_info *info, struct fb_cursor *cursor)
67{
68 return 0;
69}
70
71static int rgbfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
72 u_int transp, struct fb_info *info)
73{
74 if (regno > 15)
75 return 1;
76
77 colreg[regno] = ((red & 0xff00) << 8) | (green & 0xff00) |
78 ((blue & 0xff00) >> 8);
79 return 0;
80}
81
82static int rgbfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
83{
84 return pnx4008_sdum_mmap(info, vma, NULL);
85}
86
87static struct fb_ops rgbfb_ops = {
88 .fb_mmap = rgbfb_mmap,
89 .fb_setcolreg = rgbfb_setcolreg,
90 .fb_fillrect = cfb_fillrect,
91 .fb_copyarea = cfb_copyarea,
92 .fb_imageblit = cfb_imageblit,
93};
94
95static int rgbfb_remove(struct platform_device *pdev)
96{
97 struct fb_info *info = platform_get_drvdata(pdev);
98
99 if (info) {
100 unregister_framebuffer(info);
101 fb_dealloc_cmap(&info->cmap);
102 framebuffer_release(info);
103 platform_set_drvdata(pdev, NULL);
104 kfree(info);
105 }
106
107 pnx4008_free_dum_channel(channel_owned, pdev->id);
108 pnx4008_set_dum_exit_notification(pdev->id);
109
110 return 0;
111}
112
113static int __devinit rgbfb_probe(struct platform_device *pdev)
114{
115 struct fb_info *info;
116 struct dumchannel_uf chan_uf;
117 int ret;
118 char *option;
119
120 info = framebuffer_alloc(sizeof(u32) * 16, &pdev->dev);
121 if (!info) {
122 ret = -ENOMEM;
123 goto err;
124 }
125
126 pnx4008_get_fb_addresses(FB_TYPE_RGB, (void **)&info->screen_base,
127 (dma_addr_t *) &rgbfb_fix.smem_start,
128 &rgbfb_fix.smem_len);
129
130 if ((ret = pnx4008_alloc_dum_channel(pdev->id)) < 0)
131 goto err0;
132 else {
133 channel_owned = ret;
134 chan_uf.channelnr = channel_owned;
135 chan_uf.dirty = (u32 *) NULL;
136 chan_uf.source = (u32 *) rgbfb_fix.smem_start;
137 chan_uf.x_offset = 0;
138 chan_uf.y_offset = 0;
139 chan_uf.width = LCD_X_RES;
140 chan_uf.height = LCD_Y_RES;
141
142 if ((ret = pnx4008_put_dum_channel_uf(chan_uf, pdev->id))< 0)
143 goto err1;
144
145 if ((ret =
146 pnx4008_set_dum_channel_sync(channel_owned, CONF_SYNC_ON,
147 pdev->id)) < 0)
148 goto err1;
149
150 if ((ret =
151 pnx4008_set_dum_channel_dirty_detect(channel_owned,
152 CONF_DIRTYDETECTION_ON,
153 pdev->id)) < 0)
154 goto err1;
155 }
156
157 if (!fb_get_options("pnxrgbfb", &option) && !strcmp(option, "nocursor"))
158 rgbfb_ops.fb_cursor = no_cursor;
159
160 info->node = -1;
161 info->flags = FBINFO_FLAG_DEFAULT;
162 info->fbops = &rgbfb_ops;
163 info->fix = rgbfb_fix;
164 info->var = rgbfb_var;
165 info->screen_size = rgbfb_fix.smem_len;
166 info->pseudo_palette = info->par;
167 info->par = NULL;
168
169 ret = fb_alloc_cmap(&info->cmap, 256, 0);
170 if (ret < 0)
171 goto err2;
172
173 ret = register_framebuffer(info);
174 if (ret < 0)
175 goto err3;
176 platform_set_drvdata(pdev, info);
177
178 return 0;
179
180err3:
181 fb_dealloc_cmap(&info->cmap);
182err2:
183 framebuffer_release(info);
184err1:
185 pnx4008_free_dum_channel(channel_owned, pdev->id);
186err0:
187 kfree(info);
188err:
189 return ret;
190}
191
192static struct platform_driver rgbfb_driver = {
193 .driver = {
194 .name = "rgbfb",
195 },
196 .probe = rgbfb_probe,
197 .remove = rgbfb_remove,
198};
199
200static int __init rgbfb_init(void)
201{
202 return platform_driver_register(&rgbfb_driver);
203}
204
205static void __exit rgbfb_exit(void)
206{
207 platform_driver_unregister(&rgbfb_driver);
208}
209
210module_init(rgbfb_init);
211module_exit(rgbfb_exit);
212
213MODULE_LICENSE("GPL");
diff --git a/drivers/video/pnx4008/sdum.c b/drivers/video/pnx4008/sdum.c
new file mode 100644
index 000000000000..51f0ecc2a511
--- /dev/null
+++ b/drivers/video/pnx4008/sdum.c
@@ -0,0 +1,872 @@
1/*
2 * drivers/video/pnx4008/sdum.c
3 *
4 * Display Update Master support
5 *
6 * Authors: Grigory Tolstolytkin <gtolstolytkin@ru.mvista.com>
7 * Vitaly Wool <vitalywool@gmail.com>
8 * Based on Philips Semiconductors's code
9 *
10 * Copyrght (c) 2005-2006 MontaVista Software, Inc.
11 * Copyright (c) 2005 Philips Semiconductors
12 * This file is licensed under the terms of the GNU General Public License
13 * version 2. This program is licensed "as is" without any warranty of any
14 * kind, whether express or implied.
15 */
16
17#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/errno.h>
20#include <linux/string.h>
21#include <linux/mm.h>
22#include <linux/tty.h>
23#include <linux/slab.h>
24#include <linux/vmalloc.h>
25#include <linux/delay.h>
26#include <linux/interrupt.h>
27#include <linux/platform_device.h>
28#include <linux/fb.h>
29#include <linux/init.h>
30#include <linux/dma-mapping.h>
31#include <linux/clk.h>
32#include <asm/uaccess.h>
33#include <asm/arch/gpio.h>
34
35#include "sdum.h"
36#include "fbcommon.h"
37#include "dum.h"
38
39/* Framebuffers we have */
40
41static struct pnx4008_fb_addr {
42 int fb_type;
43 long addr_offset;
44 long fb_length;
45} fb_addr[] = {
46 [0] = {
47 FB_TYPE_YUV, 0, 0xB0000
48 },
49 [1] = {
50 FB_TYPE_RGB, 0xB0000, 0x50000
51 },
52};
53
54static struct dum_data {
55 u32 lcd_phys_start;
56 u32 lcd_virt_start;
57 u32 slave_phys_base;
58 u32 *slave_virt_base;
59 int fb_owning_channel[MAX_DUM_CHANNELS];
60 struct dumchannel_uf chan_uf_store[MAX_DUM_CHANNELS];
61} dum_data;
62
63/* Different local helper functions */
64
65static u32 nof_pixels_dx(struct dum_ch_setup *ch_setup)
66{
67 return (ch_setup->xmax - ch_setup->xmin + 1);
68}
69
70static u32 nof_pixels_dy(struct dum_ch_setup *ch_setup)
71{
72 return (ch_setup->ymax - ch_setup->ymin + 1);
73}
74
75static u32 nof_pixels_dxy(struct dum_ch_setup *ch_setup)
76{
77 return (nof_pixels_dx(ch_setup) * nof_pixels_dy(ch_setup));
78}
79
80static u32 nof_bytes(struct dum_ch_setup *ch_setup)
81{
82 u32 r = nof_pixels_dxy(ch_setup);
83 switch (ch_setup->format) {
84 case RGB888:
85 case RGB666:
86 r *= 4;
87 break;
88
89 default:
90 r *= 2;
91 break;
92 }
93 return r;
94}
95
96static u32 build_command(int disp_no, u32 reg, u32 val)
97{
98 return ((disp_no << 26) | BIT(25) | (val << 16) | (disp_no << 10) |
99 (reg << 0));
100}
101
102static u32 build_double_index(int disp_no, u32 val)
103{
104 return ((disp_no << 26) | (val << 16) | (disp_no << 10) | (val << 0));
105}
106
107static void build_disp_window(struct dum_ch_setup * ch_setup, struct disp_window * dw)
108{
109 dw->ymin = ch_setup->ymin;
110 dw->ymax = ch_setup->ymax;
111 dw->xmin_l = ch_setup->xmin & 0xFF;
112 dw->xmin_h = (ch_setup->xmin & BIT(8)) >> 8;
113 dw->xmax_l = ch_setup->xmax & 0xFF;
114 dw->xmax_h = (ch_setup->xmax & BIT(8)) >> 8;
115}
116
117static int put_channel(struct dumchannel chan)
118{
119 int i = chan.channelnr;
120
121 if (i < 0 || i > MAX_DUM_CHANNELS)
122 return -EINVAL;
123 else {
124 DUM_CH_MIN(i) = chan.dum_ch_min;
125 DUM_CH_MAX(i) = chan.dum_ch_max;
126 DUM_CH_CONF(i) = chan.dum_ch_conf;
127 DUM_CH_CTRL(i) = chan.dum_ch_ctrl;
128 }
129
130 return 0;
131}
132
133static void clear_channel(int channr)
134{
135 struct dumchannel chan;
136
137 chan.channelnr = channr;
138 chan.dum_ch_min = 0;
139 chan.dum_ch_max = 0;
140 chan.dum_ch_conf = 0;
141 chan.dum_ch_ctrl = 0;
142
143 put_channel(chan);
144}
145
146static int put_cmd_string(struct cmdstring cmds)
147{
148 u16 *cmd_str_virtaddr;
149 u32 *cmd_ptr0_virtaddr;
150 u32 cmd_str_physaddr;
151
152 int i = cmds.channelnr;
153
154 if (i < 0 || i > MAX_DUM_CHANNELS)
155 return -EINVAL;
156 else if ((cmd_ptr0_virtaddr =
157 (int *)ioremap_nocache(DUM_COM_BASE,
158 sizeof(int) * MAX_DUM_CHANNELS)) ==
159 NULL)
160 return -EIOREMAPFAILED;
161 else {
162 cmd_str_physaddr = ioread32(&cmd_ptr0_virtaddr[cmds.channelnr]);
163 if ((cmd_str_virtaddr =
164 (u16 *) ioremap_nocache(cmd_str_physaddr,
165 sizeof(cmds))) == NULL) {
166 iounmap(cmd_ptr0_virtaddr);
167 return -EIOREMAPFAILED;
168 } else {
169 int t;
170 for (t = 0; t < 8; t++)
171 iowrite16(*((u16 *)&cmds.prestringlen + t),
172 cmd_str_virtaddr + t);
173
174 for (t = 0; t < cmds.prestringlen / 2; t++)
175 iowrite16(*((u16 *)&cmds.precmd + t),
176 cmd_str_virtaddr + t + 8);
177
178 for (t = 0; t < cmds.poststringlen / 2; t++)
179 iowrite16(*((u16 *)&cmds.postcmd + t),
180 cmd_str_virtaddr + t + 8 +
181 cmds.prestringlen / 2);
182
183 iounmap(cmd_ptr0_virtaddr);
184 iounmap(cmd_str_virtaddr);
185 }
186 }
187
188 return 0;
189}
190
191static u32 dum_ch_setup(int ch_no, struct dum_ch_setup * ch_setup)
192{
193 struct cmdstring cmds_c;
194 struct cmdstring *cmds = &cmds_c;
195 struct disp_window dw;
196 int standard;
197 u32 orientation = 0;
198 struct dumchannel chan = { 0 };
199 int ret;
200
201 if ((ch_setup->xmirror) || (ch_setup->ymirror) || (ch_setup->rotate)) {
202 standard = 0;
203
204 orientation = BIT(1); /* always set 9-bit-bus */
205 if (ch_setup->xmirror)
206 orientation |= BIT(4);
207 if (ch_setup->ymirror)
208 orientation |= BIT(3);
209 if (ch_setup->rotate)
210 orientation |= BIT(0);
211 } else
212 standard = 1;
213
214 cmds->channelnr = ch_no;
215
216 /* build command string header */
217 if (standard) {
218 cmds->prestringlen = 32;
219 cmds->poststringlen = 0;
220 } else {
221 cmds->prestringlen = 48;
222 cmds->poststringlen = 16;
223 }
224
225 cmds->format =
226 (u16) ((ch_setup->disp_no << 4) | (BIT(3)) | (ch_setup->format));
227 cmds->reserved = 0x0;
228 cmds->startaddr_low = (ch_setup->minadr & 0xFFFF);
229 cmds->startaddr_high = (ch_setup->minadr >> 16);
230
231 if ((ch_setup->minadr == 0) && (ch_setup->maxadr == 0)
232 && (ch_setup->xmin == 0)
233 && (ch_setup->ymin == 0) && (ch_setup->xmax == 0)
234 && (ch_setup->ymax == 0)) {
235 cmds->pixdatlen_low = 0;
236 cmds->pixdatlen_high = 0;
237 } else {
238 u32 nbytes = nof_bytes(ch_setup);
239 cmds->pixdatlen_low = (nbytes & 0xFFFF);
240 cmds->pixdatlen_high = (nbytes >> 16);
241 }
242
243 if (ch_setup->slave_trans)
244 cmds->pixdatlen_high |= BIT(15);
245
246 /* build pre-string */
247 build_disp_window(ch_setup, &dw);
248
249 if (standard) {
250 cmds->precmd[0] =
251 build_command(ch_setup->disp_no, DISP_XMIN_L_REG, 0x99);
252 cmds->precmd[1] =
253 build_command(ch_setup->disp_no, DISP_XMIN_L_REG,
254 dw.xmin_l);
255 cmds->precmd[2] =
256 build_command(ch_setup->disp_no, DISP_XMIN_H_REG,
257 dw.xmin_h);
258 cmds->precmd[3] =
259 build_command(ch_setup->disp_no, DISP_YMIN_REG, dw.ymin);
260 cmds->precmd[4] =
261 build_command(ch_setup->disp_no, DISP_XMAX_L_REG,
262 dw.xmax_l);
263 cmds->precmd[5] =
264 build_command(ch_setup->disp_no, DISP_XMAX_H_REG,
265 dw.xmax_h);
266 cmds->precmd[6] =
267 build_command(ch_setup->disp_no, DISP_YMAX_REG, dw.ymax);
268 cmds->precmd[7] =
269 build_double_index(ch_setup->disp_no, DISP_PIXEL_REG);
270 } else {
271 if (dw.xmin_l == ch_no)
272 cmds->precmd[0] =
273 build_command(ch_setup->disp_no, DISP_XMIN_L_REG,
274 0x99);
275 else
276 cmds->precmd[0] =
277 build_command(ch_setup->disp_no, DISP_XMIN_L_REG,
278 ch_no);
279
280 cmds->precmd[1] =
281 build_command(ch_setup->disp_no, DISP_XMIN_L_REG,
282 dw.xmin_l);
283 cmds->precmd[2] =
284 build_command(ch_setup->disp_no, DISP_XMIN_H_REG,
285 dw.xmin_h);
286 cmds->precmd[3] =
287 build_command(ch_setup->disp_no, DISP_YMIN_REG, dw.ymin);
288 cmds->precmd[4] =
289 build_command(ch_setup->disp_no, DISP_XMAX_L_REG,
290 dw.xmax_l);
291 cmds->precmd[5] =
292 build_command(ch_setup->disp_no, DISP_XMAX_H_REG,
293 dw.xmax_h);
294 cmds->precmd[6] =
295 build_command(ch_setup->disp_no, DISP_YMAX_REG, dw.ymax);
296 cmds->precmd[7] =
297 build_command(ch_setup->disp_no, DISP_1_REG, orientation);
298 cmds->precmd[8] =
299 build_double_index(ch_setup->disp_no, DISP_PIXEL_REG);
300 cmds->precmd[9] =
301 build_double_index(ch_setup->disp_no, DISP_PIXEL_REG);
302 cmds->precmd[0xA] =
303 build_double_index(ch_setup->disp_no, DISP_PIXEL_REG);
304 cmds->precmd[0xB] =
305 build_double_index(ch_setup->disp_no, DISP_PIXEL_REG);
306 cmds->postcmd[0] =
307 build_command(ch_setup->disp_no, DISP_1_REG, BIT(1));
308 cmds->postcmd[1] =
309 build_command(ch_setup->disp_no, DISP_DUMMY1_REG, 1);
310 cmds->postcmd[2] =
311 build_command(ch_setup->disp_no, DISP_DUMMY1_REG, 2);
312 cmds->postcmd[3] =
313 build_command(ch_setup->disp_no, DISP_DUMMY1_REG, 3);
314 }
315
316 if ((ret = put_cmd_string(cmds_c)) != 0) {
317 return ret;
318 }
319
320 chan.channelnr = cmds->channelnr;
321 chan.dum_ch_min = ch_setup->dirtybuffer + ch_setup->minadr;
322 chan.dum_ch_max = ch_setup->dirtybuffer + ch_setup->maxadr;
323 chan.dum_ch_conf = 0x002;
324 chan.dum_ch_ctrl = 0x04;
325
326 put_channel(chan);
327
328 return 0;
329}
330
331static u32 display_open(int ch_no, int auto_update, u32 * dirty_buffer,
332 u32 * frame_buffer, u32 xpos, u32 ypos, u32 w, u32 h)
333{
334
335 struct dum_ch_setup k;
336 int ret;
337
338 /* keep width & height within display area */
339 if ((xpos + w) > DISP_MAX_X_SIZE)
340 w = DISP_MAX_X_SIZE - xpos;
341
342 if ((ypos + h) > DISP_MAX_Y_SIZE)
343 h = DISP_MAX_Y_SIZE - ypos;
344
345 /* assume 1 display only */
346 k.disp_no = 0;
347 k.xmin = xpos;
348 k.ymin = ypos;
349 k.xmax = xpos + (w - 1);
350 k.ymax = ypos + (h - 1);
351
352 /* adjust min and max values if necessary */
353 if (k.xmin > DISP_MAX_X_SIZE - 1)
354 k.xmin = DISP_MAX_X_SIZE - 1;
355 if (k.ymin > DISP_MAX_Y_SIZE - 1)
356 k.ymin = DISP_MAX_Y_SIZE - 1;
357
358 if (k.xmax > DISP_MAX_X_SIZE - 1)
359 k.xmax = DISP_MAX_X_SIZE - 1;
360 if (k.ymax > DISP_MAX_Y_SIZE - 1)
361 k.ymax = DISP_MAX_Y_SIZE - 1;
362
363 k.xmirror = 0;
364 k.ymirror = 0;
365 k.rotate = 0;
366 k.minadr = (u32) frame_buffer;
367 k.maxadr = (u32) frame_buffer + (((w - 1) << 10) | ((h << 2) - 2));
368 k.pad = PAD_1024;
369 k.dirtybuffer = (u32) dirty_buffer;
370 k.format = RGB888;
371 k.hwdirty = 0;
372 k.slave_trans = 0;
373
374 ret = dum_ch_setup(ch_no, &k);
375
376 return ret;
377}
378
379static void lcd_reset(void)
380{
381 u32 *dum_pio_base = (u32 *)IO_ADDRESS(PNX4008_PIO_BASE);
382
383 udelay(1);
384 iowrite32(BIT(19), &dum_pio_base[2]);
385 udelay(1);
386 iowrite32(BIT(19), &dum_pio_base[1]);
387 udelay(1);
388}
389
390static int dum_init(struct platform_device *pdev)
391{
392 struct clk *clk;
393
394 /* enable DUM clock */
395 clk = clk_get(&pdev->dev, "dum_ck");
396 if (IS_ERR(clk)) {
397 printk(KERN_ERR "pnx4008_dum: Unable to access DUM clock\n");
398 return PTR_ERR(clk);
399 }
400
401 clk_set_rate(clk, 1);
402 clk_put(clk);
403
404 DUM_CTRL = V_DUM_RESET;
405
406 /* set priority to "round-robin". All other params to "false" */
407 DUM_CONF = BIT(9);
408
409 /* Display 1 */
410 DUM_WTCFG1 = PNX4008_DUM_WT_CFG;
411 DUM_RTCFG1 = PNX4008_DUM_RT_CFG;
412 DUM_TCFG = PNX4008_DUM_T_CFG;
413
414 return 0;
415}
416
417static void dum_chan_init(void)
418{
419 int i = 0, ch = 0;
420 u32 *cmdptrs;
421 u32 *cmdstrings;
422
423 DUM_COM_BASE =
424 CMDSTRING_BASEADDR + BYTES_PER_CMDSTRING * NR_OF_CMDSTRINGS;
425
426 if ((cmdptrs =
427 (u32 *) ioremap_nocache(DUM_COM_BASE,
428 sizeof(u32) * NR_OF_CMDSTRINGS)) == NULL)
429 return;
430
431 for (ch = 0; ch < NR_OF_CMDSTRINGS; ch++)
432 iowrite32(CMDSTRING_BASEADDR + BYTES_PER_CMDSTRING * ch,
433 cmdptrs + ch);
434
435 for (ch = 0; ch < MAX_DUM_CHANNELS; ch++)
436 clear_channel(ch);
437
438 /* Clear the cmdstrings */
439 cmdstrings =
440 (u32 *)ioremap_nocache(*cmdptrs,
441 BYTES_PER_CMDSTRING * NR_OF_CMDSTRINGS);
442
443 if (!cmdstrings)
444 goto out;
445
446 for (i = 0; i < NR_OF_CMDSTRINGS * BYTES_PER_CMDSTRING / sizeof(u32);
447 i++)
448 iowrite32(0, cmdstrings + i);
449
450 iounmap((u32 *)cmdstrings);
451
452out:
453 iounmap((u32 *)cmdptrs);
454}
455
456static void lcd_init(void)
457{
458 lcd_reset();
459
460 DUM_OUTP_FORMAT1 = 0; /* RGB666 */
461
462 udelay(1);
463 iowrite32(V_LCD_STANDBY_OFF, dum_data.slave_virt_base);
464 udelay(1);
465 iowrite32(V_LCD_USE_9BIT_BUS, dum_data.slave_virt_base);
466 udelay(1);
467 iowrite32(V_LCD_SYNC_RISE_L, dum_data.slave_virt_base);
468 udelay(1);
469 iowrite32(V_LCD_SYNC_RISE_H, dum_data.slave_virt_base);
470 udelay(1);
471 iowrite32(V_LCD_SYNC_FALL_L, dum_data.slave_virt_base);
472 udelay(1);
473 iowrite32(V_LCD_SYNC_FALL_H, dum_data.slave_virt_base);
474 udelay(1);
475 iowrite32(V_LCD_SYNC_ENABLE, dum_data.slave_virt_base);
476 udelay(1);
477 iowrite32(V_LCD_DISPLAY_ON, dum_data.slave_virt_base);
478 udelay(1);
479}
480
481/* Interface exported to framebuffer drivers */
482
483int pnx4008_get_fb_addresses(int fb_type, void **virt_addr,
484 dma_addr_t *phys_addr, int *fb_length)
485{
486 int i;
487 int ret = -1;
488 for (i = 0; i < ARRAY_SIZE(fb_addr); i++)
489 if (fb_addr[i].fb_type == fb_type) {
490 *virt_addr = (void *)(dum_data.lcd_virt_start +
491 fb_addr[i].addr_offset);
492 *phys_addr =
493 dum_data.lcd_phys_start + fb_addr[i].addr_offset;
494 *fb_length = fb_addr[i].fb_length;
495 ret = 0;
496 break;
497 }
498
499 return ret;
500}
501
502EXPORT_SYMBOL(pnx4008_get_fb_addresses);
503
504int pnx4008_alloc_dum_channel(int dev_id)
505{
506 int i = 0;
507
508 while ((i < MAX_DUM_CHANNELS) && (dum_data.fb_owning_channel[i] != -1))
509 i++;
510
511 if (i == MAX_DUM_CHANNELS)
512 return -ENORESOURCESLEFT;
513 else {
514 dum_data.fb_owning_channel[i] = dev_id;
515 return i;
516 }
517}
518
519EXPORT_SYMBOL(pnx4008_alloc_dum_channel);
520
521int pnx4008_free_dum_channel(int channr, int dev_id)
522{
523 if (channr < 0 || channr > MAX_DUM_CHANNELS)
524 return -EINVAL;
525 else if (dum_data.fb_owning_channel[channr] != dev_id)
526 return -EFBNOTOWNER;
527 else {
528 clear_channel(channr);
529 dum_data.fb_owning_channel[channr] = -1;
530 }
531
532 return 0;
533}
534
535EXPORT_SYMBOL(pnx4008_free_dum_channel);
536
537int pnx4008_put_dum_channel_uf(struct dumchannel_uf chan_uf, int dev_id)
538{
539 int i = chan_uf.channelnr;
540 int ret;
541
542 if (i < 0 || i > MAX_DUM_CHANNELS)
543 return -EINVAL;
544 else if (dum_data.fb_owning_channel[i] != dev_id)
545 return -EFBNOTOWNER;
546 else if ((ret =
547 display_open(chan_uf.channelnr, 0, chan_uf.dirty,
548 chan_uf.source, chan_uf.y_offset,
549 chan_uf.x_offset, chan_uf.height,
550 chan_uf.width)) != 0)
551 return ret;
552 else {
553 dum_data.chan_uf_store[i].dirty = chan_uf.dirty;
554 dum_data.chan_uf_store[i].source = chan_uf.source;
555 dum_data.chan_uf_store[i].x_offset = chan_uf.x_offset;
556 dum_data.chan_uf_store[i].y_offset = chan_uf.y_offset;
557 dum_data.chan_uf_store[i].width = chan_uf.width;
558 dum_data.chan_uf_store[i].height = chan_uf.height;
559 }
560
561 return 0;
562}
563
564EXPORT_SYMBOL(pnx4008_put_dum_channel_uf);
565
566int pnx4008_set_dum_channel_sync(int channr, int val, int dev_id)
567{
568 if (channr < 0 || channr > MAX_DUM_CHANNELS)
569 return -EINVAL;
570 else if (dum_data.fb_owning_channel[channr] != dev_id)
571 return -EFBNOTOWNER;
572 else {
573 if (val == CONF_SYNC_ON) {
574 DUM_CH_CONF(channr) |= CONF_SYNCENABLE;
575 DUM_CH_CONF(channr) |= DUM_CHANNEL_CFG_SYNC_MASK |
576 DUM_CHANNEL_CFG_SYNC_MASK_SET;
577 } else if (val == CONF_SYNC_OFF)
578 DUM_CH_CONF(channr) &= ~CONF_SYNCENABLE;
579 else
580 return -EINVAL;
581 }
582
583 return 0;
584}
585
586EXPORT_SYMBOL(pnx4008_set_dum_channel_sync);
587
588int pnx4008_set_dum_channel_dirty_detect(int channr, int val, int dev_id)
589{
590 if (channr < 0 || channr > MAX_DUM_CHANNELS)
591 return -EINVAL;
592 else if (dum_data.fb_owning_channel[channr] != dev_id)
593 return -EFBNOTOWNER;
594 else {
595 if (val == CONF_DIRTYDETECTION_ON)
596 DUM_CH_CONF(channr) |= CONF_DIRTYENABLE;
597 else if (val == CONF_DIRTYDETECTION_OFF)
598 DUM_CH_CONF(channr) &= ~CONF_DIRTYENABLE;
599 else
600 return -EINVAL;
601 }
602
603 return 0;
604}
605
606EXPORT_SYMBOL(pnx4008_set_dum_channel_dirty_detect);
607
608#if 0 /* Functions not used currently, but likely to be used in future */
609
610static int get_channel(struct dumchannel *p_chan)
611{
612 int i = p_chan->channelnr;
613
614 if (i < 0 || i > MAX_DUM_CHANNELS)
615 return -EINVAL;
616 else {
617 p_chan->dum_ch_min = DUM_CH_MIN(i);
618 p_chan->dum_ch_max = DUM_CH_MAX(i);
619 p_chan->dum_ch_conf = DUM_CH_CONF(i);
620 p_chan->dum_ch_stat = DUM_CH_STAT(i);
621 p_chan->dum_ch_ctrl = 0; /* WriteOnly control register */
622 }
623
624 return 0;
625}
626
627int pnx4008_get_dum_channel_uf(struct dumchannel_uf *p_chan_uf, int dev_id)
628{
629 int i = p_chan_uf->channelnr;
630
631 if (i < 0 || i > MAX_DUM_CHANNELS)
632 return -EINVAL;
633 else if (dum_data.fb_owning_channel[i] != dev_id)
634 return -EFBNOTOWNER;
635 else {
636 p_chan_uf->dirty = dum_data.chan_uf_store[i].dirty;
637 p_chan_uf->source = dum_data.chan_uf_store[i].source;
638 p_chan_uf->x_offset = dum_data.chan_uf_store[i].x_offset;
639 p_chan_uf->y_offset = dum_data.chan_uf_store[i].y_offset;
640 p_chan_uf->width = dum_data.chan_uf_store[i].width;
641 p_chan_uf->height = dum_data.chan_uf_store[i].height;
642 }
643
644 return 0;
645}
646
647EXPORT_SYMBOL(pnx4008_get_dum_channel_uf);
648
649int pnx4008_get_dum_channel_config(int channr, int dev_id)
650{
651 int ret;
652 struct dumchannel chan;
653
654 if (channr < 0 || channr > MAX_DUM_CHANNELS)
655 return -EINVAL;
656 else if (dum_data.fb_owning_channel[channr] != dev_id)
657 return -EFBNOTOWNER;
658 else {
659 chan.channelnr = channr;
660 if ((ret = get_channel(&chan)) != 0)
661 return ret;
662 }
663
664 return (chan.dum_ch_conf & DUM_CHANNEL_CFG_MASK);
665}
666
667EXPORT_SYMBOL(pnx4008_get_dum_channel_config);
668
669int pnx4008_force_update_dum_channel(int channr, int dev_id)
670{
671 if (channr < 0 || channr > MAX_DUM_CHANNELS)
672 return -EINVAL;
673
674 else if (dum_data.fb_owning_channel[channr] != dev_id)
675 return -EFBNOTOWNER;
676 else
677 DUM_CH_CTRL(channr) = CTRL_SETDIRTY;
678
679 return 0;
680}
681
682EXPORT_SYMBOL(pnx4008_force_update_dum_channel);
683
684#endif
685
686int pnx4008_sdum_mmap(struct fb_info *info, struct vm_area_struct *vma,
687 struct device *dev)
688{
689 unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
690
691 if (off < info->fix.smem_len) {
692 vma->vm_pgoff += 1;
693 return dma_mmap_writecombine(dev, vma,
694 (void *)dum_data.lcd_virt_start,
695 dum_data.lcd_phys_start,
696 FB_DMA_SIZE);
697 }
698 return -EINVAL;
699}
700
701EXPORT_SYMBOL(pnx4008_sdum_mmap);
702
703int pnx4008_set_dum_exit_notification(int dev_id)
704{
705 int i;
706
707 for (i = 0; i < MAX_DUM_CHANNELS; i++)
708 if (dum_data.fb_owning_channel[i] == dev_id)
709 return -ERESOURCESNOTFREED;
710
711 return 0;
712}
713
714EXPORT_SYMBOL(pnx4008_set_dum_exit_notification);
715
716/* Platform device driver for DUM */
717
718static int sdum_suspend(struct platform_device *pdev, pm_message_t state)
719{
720 int retval = 0;
721 struct clk *clk;
722
723 clk = clk_get(0, "dum_ck");
724 if (!IS_ERR(clk)) {
725 clk_set_rate(clk, 0);
726 clk_put(clk);
727 } else
728 retval = PTR_ERR(clk);
729
730 /* disable BAC */
731 DUM_CTRL = V_BAC_DISABLE_IDLE;
732
733 /* LCD standby & turn off display */
734 lcd_reset();
735
736 return retval;
737}
738
739static int sdum_resume(struct platform_device *pdev)
740{
741 int retval = 0;
742 struct clk *clk;
743
744 clk = clk_get(0, "dum_ck");
745 if (!IS_ERR(clk)) {
746 clk_set_rate(clk, 1);
747 clk_put(clk);
748 } else
749 retval = PTR_ERR(clk);
750
751 /* wait for BAC disable */
752 DUM_CTRL = V_BAC_DISABLE_TRIG;
753
754 while (DUM_CTRL & BAC_ENABLED)
755 udelay(10);
756
757 /* re-init LCD */
758 lcd_init();
759
760 /* enable BAC and reset MUX */
761 DUM_CTRL = V_BAC_ENABLE;
762 udelay(1);
763 DUM_CTRL = V_MUX_RESET;
764 return 0;
765}
766
767static int __devinit sdum_probe(struct platform_device *pdev)
768{
769 int ret = 0, i = 0;
770
771 /* map frame buffer */
772 dum_data.lcd_virt_start = (u32) dma_alloc_writecombine(&pdev->dev,
773 FB_DMA_SIZE,
774 &dum_data.lcd_phys_start,
775 GFP_KERNEL);
776
777 if (!dum_data.lcd_virt_start) {
778 ret = -ENOMEM;
779 goto out_3;
780 }
781
782 /* map slave registers */
783 dum_data.slave_phys_base = PNX4008_DUM_SLAVE_BASE;
784 dum_data.slave_virt_base =
785 (u32 *) ioremap_nocache(dum_data.slave_phys_base, sizeof(u32));
786
787 if (dum_data.slave_virt_base == NULL) {
788 ret = -ENOMEM;
789 goto out_2;
790 }
791
792 /* initialize DUM and LCD display */
793 ret = dum_init(pdev);
794 if (ret)
795 goto out_1;
796
797 dum_chan_init();
798 lcd_init();
799
800 DUM_CTRL = V_BAC_ENABLE;
801 udelay(1);
802 DUM_CTRL = V_MUX_RESET;
803
804 /* set decode address and sync clock divider */
805 DUM_DECODE = dum_data.lcd_phys_start & DUM_DECODE_MASK;
806 DUM_CLK_DIV = PNX4008_DUM_CLK_DIV;
807
808 for (i = 0; i < MAX_DUM_CHANNELS; i++)
809 dum_data.fb_owning_channel[i] = -1;
810
811 /*setup wakeup interrupt */
812 start_int_set_rising_edge(SE_DISP_SYNC_INT);
813 start_int_ack(SE_DISP_SYNC_INT);
814 start_int_umask(SE_DISP_SYNC_INT);
815
816 return 0;
817
818out_1:
819 iounmap((void *)dum_data.slave_virt_base);
820out_2:
821 dma_free_writecombine(&pdev->dev, FB_DMA_SIZE,
822 (void *)dum_data.lcd_virt_start,
823 dum_data.lcd_phys_start);
824out_3:
825 return ret;
826}
827
828static int sdum_remove(struct platform_device *pdev)
829{
830 struct clk *clk;
831
832 start_int_mask(SE_DISP_SYNC_INT);
833
834 clk = clk_get(0, "dum_ck");
835 if (!IS_ERR(clk)) {
836 clk_set_rate(clk, 0);
837 clk_put(clk);
838 }
839
840 iounmap((void *)dum_data.slave_virt_base);
841
842 dma_free_writecombine(&pdev->dev, FB_DMA_SIZE,
843 (void *)dum_data.lcd_virt_start,
844 dum_data.lcd_phys_start);
845
846 return 0;
847}
848
849static struct platform_driver sdum_driver = {
850 .driver = {
851 .name = "sdum",
852 },
853 .probe = sdum_probe,
854 .remove = sdum_remove,
855 .suspend = sdum_suspend,
856 .resume = sdum_resume,
857};
858
859int __init sdum_init(void)
860{
861 return platform_driver_register(&sdum_driver);
862}
863
864static void __exit sdum_exit(void)
865{
866 platform_driver_unregister(&sdum_driver);
867};
868
869module_init(sdum_init);
870module_exit(sdum_exit);
871
872MODULE_LICENSE("GPL");
diff --git a/drivers/video/pnx4008/sdum.h b/drivers/video/pnx4008/sdum.h
new file mode 100644
index 000000000000..e8c5dcdd8813
--- /dev/null
+++ b/drivers/video/pnx4008/sdum.h
@@ -0,0 +1,139 @@
1/*
2 * Copyright (C) 2005 Philips Semiconductors
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA, or http://www.gnu.org/licenses/gpl.html
18*/
19
20#define MAX_DUM_CHANNELS 64
21
22#define RGB_MEM_WINDOW(x) (0x10000000 + (x)*0x00100000)
23
24#define QCIF_OFFSET(x) (((x) == 0) ? 0x00000: ((x) == 1) ? 0x30000: -1)
25#define CIF_OFFSET(x) (((x) == 0) ? 0x00000: ((x) == 1) ? 0x60000: -1)
26
27#define CTRL_SETDIRTY (0x00000001)
28#define CONF_DIRTYENABLE (0x00000020)
29#define CONF_SYNCENABLE (0x00000004)
30
31#define DIRTY_ENABLED(conf) ((conf) & 0x0020)
32#define SYNC_ENABLED(conf) ((conf) & 0x0004)
33
34/* Display 1 & 2 Write Timing Configuration */
35#define PNX4008_DUM_WT_CFG 0x00372000
36
37/* Display 1 & 2 Read Timing Configuration */
38#define PNX4008_DUM_RT_CFG 0x00003A47
39
40/* DUM Transit State Timing Configuration */
41#define PNX4008_DUM_T_CFG 0x1D /* 29 HCLK cycles */
42
43/* DUM Sync count clock divider */
44#define PNX4008_DUM_CLK_DIV 0x02DD
45
46/* Memory size for framebuffer, allocated through dma_alloc_writecombine().
47 * Must be PAGE aligned
48 */
49#define FB_DMA_SIZE (PAGE_ALIGN(SZ_1M + PAGE_SIZE))
50
51#define OFFSET_RGBBUFFER (0xB0000)
52#define OFFSET_YUVBUFFER (0x00000)
53
54#define YUVBUFFER (lcd_video_start + OFFSET_YUVBUFFER)
55#define RGBBUFFER (lcd_video_start + OFFSET_RGBBUFFER)
56
57#define CMDSTRING_BASEADDR (0x00C000) /* iram */
58#define BYTES_PER_CMDSTRING (0x80)
59#define NR_OF_CMDSTRINGS (64)
60
61#define MAX_NR_PRESTRINGS (0x40)
62#define MAX_NR_POSTSTRINGS (0x40)
63
64/* various mask definitions */
65#define DUM_CLK_ENABLE 0x01
66#define DUM_CLK_DISABLE 0
67#define DUM_DECODE_MASK 0x1FFFFFFF
68#define DUM_CHANNEL_CFG_MASK 0x01FF
69#define DUM_CHANNEL_CFG_SYNC_MASK 0xFFFE00FF
70#define DUM_CHANNEL_CFG_SYNC_MASK_SET 0x0CA00
71
72#define SDUM_RETURNVAL_BASE (0x500)
73
74#define CONF_SYNC_OFF (0x602)
75#define CONF_SYNC_ON (0x603)
76
77#define CONF_DIRTYDETECTION_OFF (0x600)
78#define CONF_DIRTYDETECTION_ON (0x601)
79
80/* Set the corresponding bit. */
81#define BIT(n) (0x1U << (n))
82
83struct dumchannel_uf {
84 int channelnr;
85 u32 *dirty;
86 u32 *source;
87 u32 x_offset;
88 u32 y_offset;
89 u32 width;
90 u32 height;
91};
92
93enum {
94 FB_TYPE_YUV,
95 FB_TYPE_RGB
96};
97
98struct cmdstring {
99 int channelnr;
100 uint16_t prestringlen;
101 uint16_t poststringlen;
102 uint16_t format;
103 uint16_t reserved;
104 uint16_t startaddr_low;
105 uint16_t startaddr_high;
106 uint16_t pixdatlen_low;
107 uint16_t pixdatlen_high;
108 u32 precmd[MAX_NR_PRESTRINGS];
109 u32 postcmd[MAX_NR_POSTSTRINGS];
110
111};
112
113struct dumchannel {
114 int channelnr;
115 int dum_ch_min;
116 int dum_ch_max;
117 int dum_ch_conf;
118 int dum_ch_stat;
119 int dum_ch_ctrl;
120};
121
122int pnx4008_alloc_dum_channel(int dev_id);
123int pnx4008_free_dum_channel(int channr, int dev_id);
124
125int pnx4008_get_dum_channel_uf(struct dumchannel_uf *pChan_uf, int dev_id);
126int pnx4008_put_dum_channel_uf(struct dumchannel_uf chan_uf, int dev_id);
127
128int pnx4008_set_dum_channel_sync(int channr, int val, int dev_id);
129int pnx4008_set_dum_channel_dirty_detect(int channr, int val, int dev_id);
130
131int pnx4008_force_dum_update_channel(int channr, int dev_id);
132
133int pnx4008_get_dum_channel_config(int channr, int dev_id);
134
135int pnx4008_sdum_mmap(struct fb_info *info, struct vm_area_struct *vma, struct device *dev);
136int pnx4008_set_dum_exit_notification(int dev_id);
137
138int pnx4008_get_fb_addresses(int fb_type, void **virt_addr,
139 dma_addr_t * phys_addr, int *fb_length);
diff --git a/drivers/video/pvr2fb.c b/drivers/video/pvr2fb.c
index 4a1e0e856920..940ba2be55e9 100644
--- a/drivers/video/pvr2fb.c
+++ b/drivers/video/pvr2fb.c
@@ -53,7 +53,6 @@
53#include <linux/errno.h> 53#include <linux/errno.h>
54#include <linux/string.h> 54#include <linux/string.h>
55#include <linux/mm.h> 55#include <linux/mm.h>
56#include <linux/tty.h>
57#include <linux/slab.h> 56#include <linux/slab.h>
58#include <linux/delay.h> 57#include <linux/delay.h>
59#include <linux/interrupt.h> 58#include <linux/interrupt.h>
diff --git a/drivers/video/q40fb.c b/drivers/video/q40fb.c
index fc91dbf896d2..48536c3e58a4 100644
--- a/drivers/video/q40fb.c
+++ b/drivers/video/q40fb.c
@@ -14,7 +14,6 @@
14#include <linux/errno.h> 14#include <linux/errno.h>
15#include <linux/string.h> 15#include <linux/string.h>
16#include <linux/mm.h> 16#include <linux/mm.h>
17#include <linux/tty.h>
18#include <linux/slab.h> 17#include <linux/slab.h>
19#include <linux/delay.h> 18#include <linux/delay.h>
20#include <linux/interrupt.h> 19#include <linux/interrupt.h>
diff --git a/drivers/video/retz3fb.c b/drivers/video/retz3fb.c
index 5e2c64f622cb..cf41ff177644 100644
--- a/drivers/video/retz3fb.c
+++ b/drivers/video/retz3fb.c
@@ -25,7 +25,6 @@
25#include <linux/errno.h> 25#include <linux/errno.h>
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/mm.h> 27#include <linux/mm.h>
28#include <linux/tty.h>
29#include <linux/slab.h> 28#include <linux/slab.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
31#include <linux/fb.h> 30#include <linux/fb.h>
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index 2788655e6e7d..8ddb47a56b07 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -34,7 +34,6 @@
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/string.h> 35#include <linux/string.h>
36#include <linux/mm.h> 36#include <linux/mm.h>
37#include <linux/tty.h>
38#include <linux/slab.h> 37#include <linux/slab.h>
39#include <linux/delay.h> 38#include <linux/delay.h>
40#include <linux/fb.h> 39#include <linux/fb.h>
@@ -278,9 +277,11 @@ static const struct riva_regs reg_template = {
278 */ 277 */
279#define MIN_LEVEL 0x158 278#define MIN_LEVEL 0x158
280#define MAX_LEVEL 0x534 279#define MAX_LEVEL 0x534
280#define LEVEL_STEP ((MAX_LEVEL - MIN_LEVEL) / FB_BACKLIGHT_MAX)
281 281
282static struct backlight_properties riva_bl_data; 282static struct backlight_properties riva_bl_data;
283 283
284/* Call with fb_info->bl_mutex held */
284static int riva_bl_get_level_brightness(struct riva_par *par, 285static int riva_bl_get_level_brightness(struct riva_par *par,
285 int level) 286 int level)
286{ 287{
@@ -288,9 +289,7 @@ static int riva_bl_get_level_brightness(struct riva_par *par,
288 int nlevel; 289 int nlevel;
289 290
290 /* Get and convert the value */ 291 /* Get and convert the value */
291 mutex_lock(&info->bl_mutex); 292 nlevel = MIN_LEVEL + info->bl_curve[level] * LEVEL_STEP;
292 nlevel = info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL;
293 mutex_unlock(&info->bl_mutex);
294 293
295 if (nlevel < 0) 294 if (nlevel < 0)
296 nlevel = 0; 295 nlevel = 0;
@@ -302,7 +301,8 @@ static int riva_bl_get_level_brightness(struct riva_par *par,
302 return nlevel; 301 return nlevel;
303} 302}
304 303
305static int riva_bl_update_status(struct backlight_device *bd) 304/* Call with fb_info->bl_mutex held */
305static int __riva_bl_update_status(struct backlight_device *bd)
306{ 306{
307 struct riva_par *par = class_get_devdata(&bd->class_dev); 307 struct riva_par *par = class_get_devdata(&bd->class_dev);
308 U032 tmp_pcrt, tmp_pmc; 308 U032 tmp_pcrt, tmp_pmc;
@@ -327,6 +327,19 @@ static int riva_bl_update_status(struct backlight_device *bd)
327 return 0; 327 return 0;
328} 328}
329 329
330static int riva_bl_update_status(struct backlight_device *bd)
331{
332 struct riva_par *par = class_get_devdata(&bd->class_dev);
333 struct fb_info *info = pci_get_drvdata(par->pdev);
334 int ret;
335
336 mutex_lock(&info->bl_mutex);
337 ret = __riva_bl_update_status(bd);
338 mutex_unlock(&info->bl_mutex);
339
340 return ret;
341}
342
330static int riva_bl_get_brightness(struct backlight_device *bd) 343static int riva_bl_get_brightness(struct backlight_device *bd)
331{ 344{
332 return bd->props->brightness; 345 return bd->props->brightness;
@@ -339,6 +352,20 @@ static struct backlight_properties riva_bl_data = {
339 .max_brightness = (FB_BACKLIGHT_LEVELS - 1), 352 .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
340}; 353};
341 354
355static void riva_bl_set_power(struct fb_info *info, int power)
356{
357 mutex_lock(&info->bl_mutex);
358
359 if (info->bl_dev) {
360 down(&info->bl_dev->sem);
361 info->bl_dev->props->power = power;
362 __riva_bl_update_status(info->bl_dev);
363 up(&info->bl_dev->sem);
364 }
365
366 mutex_unlock(&info->bl_mutex);
367}
368
342static void riva_bl_init(struct riva_par *par) 369static void riva_bl_init(struct riva_par *par)
343{ 370{
344 struct fb_info *info = pci_get_drvdata(par->pdev); 371 struct fb_info *info = pci_get_drvdata(par->pdev);
@@ -359,7 +386,7 @@ static void riva_bl_init(struct riva_par *par)
359 bd = backlight_device_register(name, par, &riva_bl_data); 386 bd = backlight_device_register(name, par, &riva_bl_data);
360 if (IS_ERR(bd)) { 387 if (IS_ERR(bd)) {
361 info->bl_dev = NULL; 388 info->bl_dev = NULL;
362 printk("riva: Backlight registration failed\n"); 389 printk(KERN_WARNING "riva: Backlight registration failed\n");
363 goto error; 390 goto error;
364 } 391 }
365 392
@@ -370,11 +397,11 @@ static void riva_bl_init(struct riva_par *par)
370 0x534 * FB_BACKLIGHT_MAX / MAX_LEVEL); 397 0x534 * FB_BACKLIGHT_MAX / MAX_LEVEL);
371 mutex_unlock(&info->bl_mutex); 398 mutex_unlock(&info->bl_mutex);
372 399
373 up(&bd->sem); 400 down(&bd->sem);
374 bd->props->brightness = riva_bl_data.max_brightness; 401 bd->props->brightness = riva_bl_data.max_brightness;
375 bd->props->power = FB_BLANK_UNBLANK; 402 bd->props->power = FB_BLANK_UNBLANK;
376 bd->props->update_status(bd); 403 bd->props->update_status(bd);
377 down(&bd->sem); 404 up(&bd->sem);
378 405
379#ifdef CONFIG_PMAC_BACKLIGHT 406#ifdef CONFIG_PMAC_BACKLIGHT
380 mutex_lock(&pmac_backlight_mutex); 407 mutex_lock(&pmac_backlight_mutex);
@@ -419,6 +446,7 @@ static void riva_bl_exit(struct riva_par *par)
419#else 446#else
420static inline void riva_bl_init(struct riva_par *par) {} 447static inline void riva_bl_init(struct riva_par *par) {}
421static inline void riva_bl_exit(struct riva_par *par) {} 448static inline void riva_bl_exit(struct riva_par *par) {}
449static inline void riva_bl_set_power(struct fb_info *info, int power) {}
422#endif /* CONFIG_FB_RIVA_BACKLIGHT */ 450#endif /* CONFIG_FB_RIVA_BACKLIGHT */
423 451
424/* ------------------------------------------------------------------------- * 452/* ------------------------------------------------------------------------- *
@@ -1337,16 +1365,7 @@ static int rivafb_blank(int blank, struct fb_info *info)
1337 SEQout(par, 0x01, tmp); 1365 SEQout(par, 0x01, tmp);
1338 CRTCout(par, 0x1a, vesa); 1366 CRTCout(par, 0x1a, vesa);
1339 1367
1340#ifdef CONFIG_FB_RIVA_BACKLIGHT 1368 riva_bl_set_power(info, blank);
1341 mutex_lock(&info->bl_mutex);
1342 if (info->bl_dev) {
1343 down(&info->bl_dev->sem);
1344 info->bl_dev->props->power = blank;
1345 info->bl_dev->props->update_status(info->bl_dev);
1346 up(&info->bl_dev->sem);
1347 }
1348 mutex_unlock(&info->bl_mutex);
1349#endif
1350 1369
1351 NVTRACE_LEAVE(); 1370 NVTRACE_LEAVE();
1352 1371
@@ -2117,6 +2136,9 @@ static int __devinit rivafb_probe(struct pci_dev *pd,
2117 2136
2118 fb_destroy_modedb(info->monspecs.modedb); 2137 fb_destroy_modedb(info->monspecs.modedb);
2119 info->monspecs.modedb = NULL; 2138 info->monspecs.modedb = NULL;
2139
2140 pci_set_drvdata(pd, info);
2141 riva_bl_init(info->par);
2120 ret = register_framebuffer(info); 2142 ret = register_framebuffer(info);
2121 if (ret < 0) { 2143 if (ret < 0) {
2122 printk(KERN_ERR PFX 2144 printk(KERN_ERR PFX
@@ -2124,8 +2146,6 @@ static int __devinit rivafb_probe(struct pci_dev *pd,
2124 goto err_iounmap_screen_base; 2146 goto err_iounmap_screen_base;
2125 } 2147 }
2126 2148
2127 pci_set_drvdata(pd, info);
2128
2129 printk(KERN_INFO PFX 2149 printk(KERN_INFO PFX
2130 "PCI nVidia %s framebuffer ver %s (%dMB @ 0x%lX)\n", 2150 "PCI nVidia %s framebuffer ver %s (%dMB @ 0x%lX)\n",
2131 info->fix.id, 2151 info->fix.id,
@@ -2133,8 +2153,6 @@ static int __devinit rivafb_probe(struct pci_dev *pd,
2133 info->fix.smem_len / (1024 * 1024), 2153 info->fix.smem_len / (1024 * 1024),
2134 info->fix.smem_start); 2154 info->fix.smem_start);
2135 2155
2136 riva_bl_init(info->par);
2137
2138 NVTRACE_LEAVE(); 2156 NVTRACE_LEAVE();
2139 return 0; 2157 return 0;
2140 2158
diff --git a/drivers/video/s3c2410fb.c b/drivers/video/s3c2410fb.c
index f461eb10cc79..ad3bdd6f1ac1 100644
--- a/drivers/video/s3c2410fb.c
+++ b/drivers/video/s3c2410fb.c
@@ -76,7 +76,6 @@
76#include <linux/errno.h> 76#include <linux/errno.h>
77#include <linux/string.h> 77#include <linux/string.h>
78#include <linux/mm.h> 78#include <linux/mm.h>
79#include <linux/tty.h>
80#include <linux/slab.h> 79#include <linux/slab.h>
81#include <linux/delay.h> 80#include <linux/delay.h>
82#include <linux/fb.h> 81#include <linux/fb.h>
diff --git a/drivers/video/savage/savagefb_driver.c b/drivers/video/savage/savagefb_driver.c
index 4729af477fbf..461e094e7b45 100644
--- a/drivers/video/savage/savagefb_driver.c
+++ b/drivers/video/savage/savagefb_driver.c
@@ -46,7 +46,6 @@
46#include <linux/errno.h> 46#include <linux/errno.h>
47#include <linux/string.h> 47#include <linux/string.h>
48#include <linux/mm.h> 48#include <linux/mm.h>
49#include <linux/tty.h>
50#include <linux/slab.h> 49#include <linux/slab.h>
51#include <linux/delay.h> 50#include <linux/delay.h>
52#include <linux/fb.h> 51#include <linux/fb.h>
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index b848ca7db7f9..895ebda7d9e3 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -44,7 +44,13 @@
44#include <linux/errno.h> 44#include <linux/errno.h>
45#include <linux/string.h> 45#include <linux/string.h>
46#include <linux/mm.h> 46#include <linux/mm.h>
47
48#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
47#include <linux/tty.h> 49#include <linux/tty.h>
50#else
51#include <linux/screen_info.h>
52#endif
53
48#include <linux/slab.h> 54#include <linux/slab.h>
49#include <linux/fb.h> 55#include <linux/fb.h>
50#include <linux/selection.h> 56#include <linux/selection.h>
diff --git a/drivers/video/skeletonfb.c b/drivers/video/skeletonfb.c
index 67f429e93189..bb96cb65fdaa 100644
--- a/drivers/video/skeletonfb.c
+++ b/drivers/video/skeletonfb.c
@@ -47,7 +47,6 @@
47#include <linux/errno.h> 47#include <linux/errno.h>
48#include <linux/string.h> 48#include <linux/string.h>
49#include <linux/mm.h> 49#include <linux/mm.h>
50#include <linux/tty.h>
51#include <linux/slab.h> 50#include <linux/slab.h>
52#include <linux/delay.h> 51#include <linux/delay.h>
53#include <linux/fb.h> 52#include <linux/fb.h>
diff --git a/drivers/video/sun3fb.c b/drivers/video/sun3fb.c
index e046e20f02b9..f80356dfa8e8 100644
--- a/drivers/video/sun3fb.c
+++ b/drivers/video/sun3fb.c
@@ -30,7 +30,6 @@
30#include <linux/errno.h> 30#include <linux/errno.h>
31#include <linux/string.h> 31#include <linux/string.h>
32#include <linux/mm.h> 32#include <linux/mm.h>
33#include <linux/tty.h>
34#include <linux/slab.h> 33#include <linux/slab.h>
35#include <linux/vmalloc.h> 34#include <linux/vmalloc.h>
36#include <linux/delay.h> 35#include <linux/delay.h>
diff --git a/drivers/video/tdfxfb.c b/drivers/video/tdfxfb.c
index 239b1496874b..689ce0270b81 100644
--- a/drivers/video/tdfxfb.c
+++ b/drivers/video/tdfxfb.c
@@ -63,7 +63,6 @@
63#include <linux/errno.h> 63#include <linux/errno.h>
64#include <linux/string.h> 64#include <linux/string.h>
65#include <linux/mm.h> 65#include <linux/mm.h>
66#include <linux/tty.h>
67#include <linux/slab.h> 66#include <linux/slab.h>
68#include <linux/delay.h> 67#include <linux/delay.h>
69#include <linux/interrupt.h> 68#include <linux/interrupt.h>
diff --git a/drivers/video/tgafb.c b/drivers/video/tgafb.c
index 6c2c78ab9827..94fde625a6c0 100644
--- a/drivers/video/tgafb.c
+++ b/drivers/video/tgafb.c
@@ -17,7 +17,6 @@
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/mm.h> 19#include <linux/mm.h>
20#include <linux/tty.h>
21#include <linux/slab.h> 20#include <linux/slab.h>
22#include <linux/delay.h> 21#include <linux/delay.h>
23#include <linux/init.h> 22#include <linux/init.h>
diff --git a/drivers/video/tx3912fb.c b/drivers/video/tx3912fb.c
index d904da44e1aa..07389ba01eff 100644
--- a/drivers/video/tx3912fb.c
+++ b/drivers/video/tx3912fb.c
@@ -14,7 +14,6 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/tty.h>
18#include <linux/delay.h> 17#include <linux/delay.h>
19#include <linux/interrupt.h> 18#include <linux/interrupt.h>
20#include <linux/init.h> 19#include <linux/init.h>
diff --git a/drivers/video/valkyriefb.c b/drivers/video/valkyriefb.c
index 1d76c035050e..47f27924a7d7 100644
--- a/drivers/video/valkyriefb.c
+++ b/drivers/video/valkyriefb.c
@@ -44,7 +44,6 @@
44#include <linux/errno.h> 44#include <linux/errno.h>
45#include <linux/string.h> 45#include <linux/string.h>
46#include <linux/mm.h> 46#include <linux/mm.h>
47#include <linux/tty.h>
48#include <linux/slab.h> 47#include <linux/slab.h>
49#include <linux/vmalloc.h> 48#include <linux/vmalloc.h>
50#include <linux/delay.h> 49#include <linux/delay.h>
diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
index 5718924b677f..2196448396ec 100644
--- a/drivers/video/vesafb.c
+++ b/drivers/video/vesafb.c
@@ -13,13 +13,13 @@
13#include <linux/errno.h> 13#include <linux/errno.h>
14#include <linux/string.h> 14#include <linux/string.h>
15#include <linux/mm.h> 15#include <linux/mm.h>
16#include <linux/tty.h>
17#include <linux/slab.h> 16#include <linux/slab.h>
18#include <linux/delay.h> 17#include <linux/delay.h>
19#include <linux/fb.h> 18#include <linux/fb.h>
20#include <linux/ioport.h> 19#include <linux/ioport.h>
21#include <linux/init.h> 20#include <linux/init.h>
22#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/screen_info.h>
23 23
24#include <video/vga.h> 24#include <video/vga.h>
25#include <asm/io.h> 25#include <asm/io.h>
diff --git a/drivers/video/vfb.c b/drivers/video/vfb.c
index d073ffb6e1f9..a9b99b01bd8e 100644
--- a/drivers/video/vfb.c
+++ b/drivers/video/vfb.c
@@ -15,7 +15,6 @@
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <linux/tty.h>
19#include <linux/slab.h> 18#include <linux/slab.h>
20#include <linux/vmalloc.h> 19#include <linux/vmalloc.h>
21#include <linux/delay.h> 20#include <linux/delay.h>
diff --git a/drivers/video/vga16fb.c b/drivers/video/vga16fb.c
index 3c404c9bd36c..43d5a6d9c4a6 100644
--- a/drivers/video/vga16fb.c
+++ b/drivers/video/vga16fb.c
@@ -15,13 +15,13 @@
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <linux/tty.h>
19#include <linux/slab.h> 18#include <linux/slab.h>
20#include <linux/delay.h> 19#include <linux/delay.h>
21#include <linux/fb.h> 20#include <linux/fb.h>
22#include <linux/ioport.h> 21#include <linux/ioport.h>
23#include <linux/init.h> 22#include <linux/init.h>
24#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/screen_info.h>
25 25
26#include <asm/io.h> 26#include <asm/io.h>
27#include <video/vga.h> 27#include <video/vga.h>
diff --git a/drivers/video/virgefb.c b/drivers/video/virgefb.c
index 5ea2345dab99..64378959dd7b 100644
--- a/drivers/video/virgefb.c
+++ b/drivers/video/virgefb.c
@@ -39,7 +39,6 @@
39#include <linux/errno.h> 39#include <linux/errno.h>
40#include <linux/string.h> 40#include <linux/string.h>
41#include <linux/mm.h> 41#include <linux/mm.h>
42#include <linux/tty.h>
43#include <linux/slab.h> 42#include <linux/slab.h>
44#include <linux/delay.h> 43#include <linux/delay.h>
45#include <linux/zorro.h> 44#include <linux/zorro.h>
diff --git a/drivers/w1/masters/ds2482.c b/drivers/w1/masters/ds2482.c
index af492cc48db2..d93eb626b2f0 100644
--- a/drivers/w1/masters/ds2482.c
+++ b/drivers/w1/masters/ds2482.c
@@ -218,7 +218,7 @@ static int ds2482_wait_1wire_idle(struct ds2482_data *pdev)
218 do { 218 do {
219 temp = i2c_smbus_read_byte(&pdev->client); 219 temp = i2c_smbus_read_byte(&pdev->client);
220 } while ((temp >= 0) && (temp & DS2482_REG_STS_1WB) && 220 } while ((temp >= 0) && (temp & DS2482_REG_STS_1WB) &&
221 (++retries > DS2482_WAIT_IDLE_TIMEOUT)); 221 (++retries < DS2482_WAIT_IDLE_TIMEOUT));
222 } 222 }
223 223
224 if (retries > DS2482_WAIT_IDLE_TIMEOUT) 224 if (retries > DS2482_WAIT_IDLE_TIMEOUT)